GDB command to write to memory

View: New views
4 Messages — Rating Filter:   Alert me  

GDB command to write to memory

by Guillaume MENANT :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The command x is used to examine memory but i don't find the command to write directly a value in memory. I've tried X but it is not recognized.

Thanks

Re: GDB command to write to memory

by Guillaume MENANT :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Guillaume MENANT wrote:
The command x is used to examine memory but i don't find the command to write directly a value in memory. I've tried X but it is not recognized.

Thanks
The only solution i've found is the "set var" command but it's limited in use. Is there a more flexible command ?

Re: GDB command to write to memory

by Andreas Schwab :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Guillaume MENANT <guillaume.menant@...> writes:

> The only solution i've found is the "set var" command but it's limited in
> use. Is there a more flexible command ?

(gdb) set {int}0xdeadbeef = 42

Andreas.

--
Andreas Schwab, SuSE Labs, schwab@...
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

Re: GDB command to write to memory

by Michael Snyder-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 2008-02-27 at 22:38 -0800, Guillaume MENANT wrote:
> The command x is used to examine memory but i don't find the command to write
> directly a value in memory. I've tried X but it is not recognized.

There's no such command.  The general method is to use
an assignment expression.  You use a cast to determine
the size of memory (byte, word...) you want to write.

(gdb) set *(char *) 0xabcd = -1

You can do tricky things by using or omitting "signed",
and usually write up to an 8-byte word by using "long long".