Search code examples
debuggingscriptinggdbhookgdbinit

How can I hook to the command x in gdb?


I've tried hooking to other commands such as echo and it works well. But when it comes to hooking the x command, it fails. Here's the codes inside of my .gdbinit file.

set $pince_injection_failed = 1
set $pince_debugging_mode = 0
define hook-x
  if $pince_injection_failed = 1
    echo asdf
end

define hookpost-x
  if $pince_debugging_mode = 0
    echo zxcv
end

I'm aware that gdb doesn't accept aliases of a function for hooking. But x is already a full function isn't it? I couldn't find any aliases for it. I'm also doubting about it because a single character is too short for a command to be


Solution

  • I found the solution thanks to the Mark Plotnick. It seems like another fault of mine, I found out that there was a function that had a misplaced end, so all functions came after that function got ignored by gdb naturally.

    define keks
      set $lel=0
      while($lel<10)
        x/x 0x00400000
        set $lel = $lel+1
    end
    

    Notice the missing end at the end of while loop