Ruslan
Ruslan

Reputation: 19130

How to tell GDB to disassemble N instructions at given address, also showing the raw bytes?

I know two modes of GDB disassembly:

  1. First command be used to show instructions as well as raw byte, but it seems to not accept number of instructions to disassemble — only memory range:

    disas/r $pc,+30

  2. Second command can disassemble exactly N instructions, like follows, but without raw bytes:

    x/10i $pc

I'd like to have a hybrid of these two modes: make the raw bytes visible as in disas/r and be able to specify exact number of instructions to disassemble as in x/10i. Can I do it with GDB?

Upvotes: 0

Views: 932

Answers (1)

Tom Tromey
Tom Tromey

Reputation: 22539

There's no built-in way to do this. (As an aside, it seems to me that this is a bit of an oversight and perhaps a bug report requesting that x/i be able to show the bytes would be good.)]

If you really need this, there is a way to implement it yourself. The basic idea is to write a new command in Python. This command could wrap the disassemble command (using gdb.execute with the to_string parameter), and then limit its output to N instructions.

Upvotes: 1

Related Questions