From: Sheng-Liang Song <ssl@baymicrosystems.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: Eran Ifrah <eran.ifrah@gmail.com>, gdb@sourceware.org
Subject: Re: Manipulating memory
Date: Tue, 05 Aug 2008 19:37:00 -0000 [thread overview]
Message-ID: <4898ABB2.3080902@baymicrosystems.com> (raw)
In-Reply-To: <20080805191204.GB4323@adacore.com>
Here is an example: (if and if only the memory can be accessed by your
CPU directly).
char mac[20]; (a memory on stack)
(gdb) p mac
$23 = "\0050:1b:21:01:b2:71\000\000"
(gdb) p /x mac
$24 = {0x5, 0x30, 0x3a, 0x31, 0x62, 0x3a, 0x32, 0x31, 0x3a, 0x30, 0x31,
0x3a,
0x62, 0x32, 0x3a, 0x37, 0x31, 0x0, 0x0, 0x0}
(gdb) p &mac
$25 = (char (*)[20]) 0x7fbfffe940
(gdb) p *((char*) 0x7fbfffe940)
$26 = 5 '\005'
(gdb) set *((char*) 0x7fbfffe940)=208
(gdb) p *((char*) 0x7fbfffe940)
$27 = -48 ''
(gdb) set *((char*) 0x7fbfffe940)=11
(gdb) p *((char*) 0x7fbfffe940)
$28 = 11 '\v'
Note: For some CPUs, some memories can only be only accessed with
word-aligned (addr%4==0) addresses.
If you try to cast a random memory address to a (char*), it may not work
(or crash!).
Sheng-Liang Song
Joel Brobecker wrote:
>> I have read the GDB manual, and I could not find a way to manipulate a
>> memory, for example: set values at given address. I only found a way
>> to view it using '-data-read-memory' command,
>> is this true or did I miss something?
>>
>
> To view memory at a given address, I usually use the "x" command.
> To write memory, I use "set {TYPE}ADDRESS := VALUE" (or something
> like that, I'm completely jetlagged right now). For instance, to
> set a byte at 0xdeadbeef to 0x48, I would do:
>
> (gdb) set {char} 0xdeadbeef = 0x48
>
> (This assume that the current language is C)
>
>
next prev parent reply other threads:[~2008-08-05 19:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-05 19:04 Eran Ifrah
2008-08-05 19:12 ` Joel Brobecker
2008-08-05 19:37 ` Sheng-Liang Song [this message]
2008-08-06 6:36 ` André Pönitz
2008-08-06 8:15 ` Nick Roberts
[not found] ` <d557d0790808060122x67edceb8h559caa8d2670316b@mail.gmail.com>
[not found] ` <18586.41219.18256.847372@kahikatea.snap.net.nz>
2008-08-07 7:43 ` Eran Ifrah
2008-08-07 9:12 ` André Pönitz
2008-08-07 18:15 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4898ABB2.3080902@baymicrosystems.com \
--to=ssl@baymicrosystems.com \
--cc=brobecker@adacore.com \
--cc=eran.ifrah@gmail.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox