0

I use gdbinit file to run few commands when gdb is init.

How can I use there python command? Instead using x/x $pc I want to print with binascii 10 bytes after $PC register.

How can I do that?

2
  • Does this help? stackoverflow.com/a/16553345/4885321 Commented Nov 2, 2021 at 8:39
  • @alagner . No because I didn't understand how to take the value from python to gdb Commented Nov 2, 2021 at 15:38

1 Answer 1

2

Combining this answer with this one we end up with:

(gdb) x/10x $pc
0x55555555515d <main+8>:        0x48    0x8d    0x35    0xa0    0x0e    0x00    0x00    0x48
0x555555555165 <main+16>:       0x8d    0x3d

(gdb) source .gdbinit.py
488d35a00e0000488d3d

where .gdbinit.py contains:

import binascii
import gdb

i = gdb.inferiors()[0]
pc = gdb.parse_and_eval("$pc")
m = i.read_memory(pc, 10)
print binascii.hexlify(m)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.