Using GDB to do a hex dump of memory

3 posts / 0 new
Last post
AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 3 months ago
Joined: 2011-11-14 16:18
Using GDB to do a hex dump of memory

Hi,

I am debugging a problem in a program and have read the GDB tutorials available here. Thanks everyone for your work putting those together! They help a lot!
Quick question though....is there a command in GDB that allows me to view, in hex, a group of bytes or words - say 256 bytes worth... something similar to the display command that updates with each step?

Or do I need to use some other tool to examine memory in hexidecimal while running GDB, and if so, what tool would work?

Thanks!

kas1e
kas1e's picture
Offline
Last seen: 1 year 5 months ago
Joined: 2010-11-30 15:30
x /20xb expr This gives you

x /20xb expr

This gives you the hex values for an arbitrary range of bytes. it also works with /xh /xw /xg for other data sizes. I.e.:

7/0.RAM Disk:> cat 1.c
#include <stdio.h>
 
main()
{
printf("aaaa\n");
exit(0);
}
7/0.RAM Disk:> gcc -gstabs 1.c -o 1
1.c: In function 'main':
1.c:6: warning: incompatible implicit declaration of built-in function 'exit'
7/0.RAM Disk:> gdb -q 1
(gdb) break main
Breakpoint 1 at 0x7fbd6208: file 1.c, line 4.
(gdb) r
Starting program: /RAM Disk/1 
BS 6555f748
Current action: 2
 
Breakpoint 1, main () at 1.c:4
4	{
(gdb) disas main
Dump of assembler code for function main:
0x7fbd6208 <main+0>:	stwu    r1,-16(r1)
0x7fbd620c <main+4>:	mflr    r0
0x7fbd6210 <main+8>:	stw     r31,12(r1)
0x7fbd6214 <main+12>:	stw     r0,20(r1)
0x7fbd6218 <main+16>:	mr      r31,r1
0x7fbd621c <main+20>:	lis     r9,25951
0x7fbd6220 <main+24>:	addi    r3,r9,12344
0x7fbd6224 <main+28>:	bl      0x7fbd6238 <puts>
0x7fbd6228 <main+32>:	li      r3,0
0x7fbd622c <main+36>:	bl      0x7fbd6230 <exit>
End of assembler dump.
 
 
(gdb) x /20xb 0x7fbd6208
0x7fbd6208 <main>:	0x94	0x21	0xff	0xf0	0x7c	0x08	0x02	0xa6
0x7fbd6210 <main+8>:	0x93	0xe1	0x00	0x0c	0x90	0x01	0x00	0x14
0x7fbd6218 <main+16>:	0x7c	0x3f	0x0b	0x78
 
 
(gdb) x /20xh 0x7fbd6208
0x7fbd6208 <main>:	0x9421	0xfff0	0x7c08	0x02a6	0x93e1	0x000c	0x9001	0x0014
0x7fbd6218 <main+16>:	0x7c3f	0x0b78	0x3d20	0x655f	0x3869	0x3038	0x4800	0x0015
0x7fbd6228 <main+32>:	0x3860	0x0000	0x4800	0x0005
 
 
(gdb) x /20xw 0x7fbd6208
0x7fbd6208 <main>:	0x9421fff0	0x7c0802a6	0x93e1000c	0x90010014
0x7fbd6218 <main+16>:	0x7c3f0b78	0x3d20655f	0x38693038	0x48000015
0x7fbd6228 <main+32>:	0x38600000	0x48000005	0x39800654	0x4800000c
0x7fbd6238 <puts>:	0x398004ec	0x48000004	0x3d606589	0x800bcd44
0x7fbd6248 <__NewlibCall+8>:	0x7d6c002e	0x7d6903a6	0x4e800420	0x00000000
 
(gdb) x /20xg 0x7fbd6208
0x7fbd6208 <main>:	0x9421fff07c0802a6	0x93e1000c90010014
0x7fbd6218 <main+16>:	0x7c3f0b783d20655f	0x3869303848000015
0x7fbd6228 <main+32>:	0x3860000048000005	0x398006544800000c
0x7fbd6238 <puts>:	0x398004ec48000004	0x3d606589800bcd44
0x7fbd6248 <__NewlibCall+8>:	0x7d6c002e7d6903a6	0x4e80042000000000
0x7fbd6258:	0x0000000000000000	0x0000000000000000
0x7fbd6268:	0x0000000000000000	0x0000000000000000
0x7fbd6278:	0x0000000000000000	0x0000000000000000
0x7fbd6288:	0x0000000000000000	0x0000000000000000
0x7fbd6298:	0x0000000000000000	0x0000000000000000
(gdb) 
AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 3 months ago
Joined: 2011-11-14 16:18
Perfect! Exactly what I was

Perfect! Exactly what I was looking for!

Thanks

Log in or register to post comments