0

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

Korcan Karaokçu
  • 467
  • 4
  • 18
  • 1
    `hook-x` and `hookpost-x` work for me in gdb 7.7.1. What version are you having this problem with? It may be a bug in old versions that has been fixed. Also note that `if $pince_debugging_mode = 0` will always be false; you probably want `if $pince_debugging_mode == 0`. The lack of an `end` statement to terminate the `if` might also result in the command not working. – Mark Plotnick May 23 '16 at 00:39
  • My version is 7.7.1 as well. I just tried doing `define hook-x` in gdb session instead of using .gdbinit file and it works! What could be wrong with the .gdbinit file? Edit: Oh, also thanks for the if statement tip Edit2: I tried to write a minimalistic version of gdbinit like this: `define hook-x echo 1 end` And it also didn't work – Korcan Karaokçu May 23 '16 at 00:42
  • 1
    Can you add an `echo` command as the first line and last line of your .gdbinit file just to check whether gdb is reading it in? – Mark Plotnick May 23 '16 at 00:46
  • Tried it, it works – Korcan Karaokçu May 23 '16 at 00:48
  • 1
    Can you type `show user` in gdb to check what got defined? The second define may have been moved into the body of the first define because of the missing `end`. – Mark Plotnick May 23 '16 at 00:54
  • I got it! Seems like it was my fault. I found out that there was a function that has a misplaced end, so all functions comes after that function got ignored by gdb naturally. I'll close this question tomorrow. Thanks again for sparing your time! Good to know this fact about `end` – Korcan Karaokçu May 23 '16 at 00:56

1 Answers1

0

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

Korcan Karaokçu
  • 467
  • 4
  • 18