GDB READ WRITE

Posted by Mudassir on Wed 08 Nov 2006 06:12 AM — 6 posts, 22,158 views.

#0
Hi,

Can you can tell me the GDB command to do following:

1. Read a register
2. Read a memory location
3. Write a register
4. Write a memory location

It would so nice if you could help me!

thanks,
mudassir.
USA #1
I don't know about registers, but you can probably read a memory address by converting a numerical value (the address) to whatever type you want to print. For example:
print ((int*)1234)
should print the integer stored at address 1234.
I'm not sure about writing, I've never tried it. I'm assuming the gdb documentation would give more information on this, if it's possible.
#2
hello,

I don't know for sure but i think it is not working. This happens when i want to read location 0x01008844:

(gdb) print ((int*)0x01008844)
$3 = (int *) 0x1008844

thanks,
mudassir.
#3
No, sorry i got that; i need to dereference it. thanks.

Can anyone tell me how to read/write registers??

regards,
mudassir.
#4
Hi,
I got the answer of how to read/write registers. i am writing it here for anyone else's use. it is as follows

to read:
gdb> print $<register name>
e.g:
gdb> print $PC

and to write
gdb> print $<register name>=<value>
e.g:
gdb> print $PC=0x01000ffc4


But i am still interesting in knowing, how to read a chunk of memory say 100 bytes. I should specify a range with address somewhere.

thanks,
mudassir shabbir.
Australia Forum Administrator #5
See my post on using gdb, the last entry (at present) is about examining memory:

http://www.gammon.com.au/forum/?id=3653