سؤال

I have a program comparing two values and I would like to print them for debug :

   0x00000000004005cd <+73>:    mov    DWORD PTR [rbp-0x4],eax
   0x00000000004005d0 <+76>:    mov    eax,DWORD PTR [rbp-0x4]
=> 0x00000000004005d3 <+79>:    cmp    eax,0x1e240
   0x00000000004005d8 <+84>:    jne    0x4005e6 <main+98>

So i placed a breakpoint on main+79 and I would like to print the values being compared by the cmp call.

How can I achieve that with gdb?

Thanks for your help.

هل كانت مفيدة؟

المحلول

CMP is not a call - it's a single instruction. To see the current value of EAX, use the following command:

info registers eax

The other comparand is the hex value 0x1e240. It's not an address, it's an integer constant.

نصائح أخرى

Using the print and/or x (examine) commands you can print the values being compared, you can also just print the registers in this case.

print $eax
info registers

The formats for the examine command are specified by entering help x:

Formats: o(octal), x(hex), d(decimal), u(unsigned decimal), t(binary), f(float), a(address), i(instruction), c(char) and s(string).
Size letters: b(byte), h(halfword), w(word), g(giant, 8 bytes).

I'll assume 0x1e240 is an address in this case (though its clearly not), and let's say I want to print 4 hex words starting at this base address. It would be:

x[count]{format}{size} 0x1e240
x/4xw 0x1e240

Also, keep in mind the print can also use the format specifiers:

print/{format} $eax
print/x $eax

Check out other interesting commands like display as well.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top