How do I convert a disassembled instruction to be shown in binary in gdb?

0

I've got a binary that I've disassembled into viewable assembly in gdb. However, I'd like to see the actual binary of each instruction (i.e. the actual instruction in whatever instruction format it is actually issued to the CPU in). Is there a way to input the address of an instruction and see that instruction in binary?

I tried p /t 0x-------- for whatever address, but it decoded the address itself into binary. I tried the same, but with $0x--------, this produced a "Value can't be converted to integer" error.

I'd just like to be able to see an instruction such as lwi or ori at a given address, such as 0x00000300, in binary as gdb is seeing it.

binary
gdb
asked on Stack Overflow Jul 2, 2019 by FairtimeIA

2 Answers

0

You are looking for disassemble/r 0x....

From the manual:

print the raw instructions in hex as well as in symbolic
form by specifying the /r modifier. 

Update:

I can see, in layout asm, the assembly instructions obtained from my binary. But running the disassemble command on its own does not allow me to see anything, as it says "No function contains specified address."

So your binary is stripped (or at least GDB doesn't know where the nearest function is).

The solution is to disassemble just the instruction you are interested in. For example:

(gdb) disas 0x0000555555556d60
No function contains specified address.

(gdb) disas 0x0000555555556d60,+1
Dump of assembler code from 0x555555556d60 to 0x555555556d61:
   0x0000555555556d60:  mov    %edi,%eax
End of assembler dump.

(gdb) disas/r 0x0000555555556d60,+1
Dump of assembler code from 0x555555556d60 to 0x555555556d61:
   0x0000555555556d60:  89 f8   mov    %edi,%eax
End of assembler dump.
answered on Stack Overflow Jul 3, 2019 by Employed Russian • edited Jul 3, 2019 by Employed Russian
0

I found the solution, it was to write the following command:

p /x *[hex address]

So for example:

p /x *0x00000300

answered on Stack Overflow Jul 10, 2019 by FairtimeIA

User contributions licensed under CC BY-SA 3.0