* Manipulating memory @ 2008-08-05 19:04 Eran Ifrah 2008-08-05 19:12 ` Joel Brobecker 2008-08-06 6:36 ` André Pönitz 0 siblings, 2 replies; 8+ messages in thread From: Eran Ifrah @ 2008-08-05 19:04 UTC (permalink / raw) To: gdb Hi, 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? -- Eran Ifrah eran.ifrah@gmail.com ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Manipulating memory 2008-08-05 19:04 Manipulating memory Eran Ifrah @ 2008-08-05 19:12 ` Joel Brobecker 2008-08-05 19:37 ` Sheng-Liang Song 2008-08-06 6:36 ` André Pönitz 1 sibling, 1 reply; 8+ messages in thread From: Joel Brobecker @ 2008-08-05 19:12 UTC (permalink / raw) To: Eran Ifrah; +Cc: gdb > 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) -- Joel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Manipulating memory 2008-08-05 19:12 ` Joel Brobecker @ 2008-08-05 19:37 ` Sheng-Liang Song 0 siblings, 0 replies; 8+ messages in thread From: Sheng-Liang Song @ 2008-08-05 19:37 UTC (permalink / raw) To: Joel Brobecker; +Cc: Eran Ifrah, gdb 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) > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Manipulating memory 2008-08-05 19:04 Manipulating memory Eran Ifrah 2008-08-05 19:12 ` Joel Brobecker @ 2008-08-06 6:36 ` André Pönitz 2008-08-06 8:15 ` Nick Roberts 1 sibling, 1 reply; 8+ messages in thread From: André Pönitz @ 2008-08-06 6:36 UTC (permalink / raw) To: gdb On Tuesday 05 August 2008 21:03:38 Eran Ifrah wrote: > Hi, > > 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? I'd be glad if someone had a real solution for that task, too. So far I used something along the lines of call sprintf(address, "%d %s ..", token, ... ) to write something to target memory, but I am looking for an alternative too, as this gets mis-parsed in some cases. Maybe restore filename [binary] bias start end as described in section 8.16 of the manual would help, but that seems to require the contents to be put in a file first. Not really convenient either... Regards, André ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Manipulating memory 2008-08-06 6:36 ` André Pönitz @ 2008-08-06 8:15 ` Nick Roberts [not found] ` <d557d0790808060122x67edceb8h559caa8d2670316b@mail.gmail.com> 0 siblings, 1 reply; 8+ messages in thread From: Nick Roberts @ 2008-08-06 8:15 UTC (permalink / raw) To: André Pönitz; +Cc: gdb > > 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? > > I'd be glad if someone had a real solution for that task, too. > > So far I used something along the lines of > > call sprintf(address, "%d %s ..", token, ... ) > > to write something to target memory, but I am looking for an alternative > too, as this gets mis-parsed in some cases. > > Maybe > > restore filename [binary] bias start end > > as described in section 8.16 of the manual would help, but that seems to > require the contents to be put in a file first. Not really convenient either. GDB has an undocumented MI command called -data-write-memory. I've not used it though, and don't know if it works or does what you want. -- Nick http://www.inet.net.nz/~nickrob ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <d557d0790808060122x67edceb8h559caa8d2670316b@mail.gmail.com>]
[parent not found: <18586.41219.18256.847372@kahikatea.snap.net.nz>]
* Re: Manipulating memory [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 0 siblings, 2 replies; 8+ messages in thread From: Eran Ifrah @ 2008-08-07 7:43 UTC (permalink / raw) To: Nick Roberts, gdb On Thu, Aug 7, 2008 at 10:15 AM, Nick Roberts <nickrob@snap.net.nz> wrote: > > > GDB has an undocumented MI command called -data-write-memory. I've not > > > used it though, and don't know if it works or does what you want. > > > > > > > Thanks ! this is exactly what I was looking for: the sibling function > > of -data-read-memory. > > > > Any ideas why this command is undocumented? > > Not really. If it works for you, perhaps you could documentation. I was not referring to the actual documentation, but maybe there is a reason for that? unsupported? But, I will document it once I will explore all its options. > > -- > Nick http://www.inet.net.nz/~nickrob > -- Eran Ifrah eran.ifrah@gmail.com ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Manipulating memory 2008-08-07 7:43 ` Eran Ifrah @ 2008-08-07 9:12 ` André Pönitz 2008-08-07 18:15 ` Eli Zaretskii 1 sibling, 0 replies; 8+ messages in thread From: André Pönitz @ 2008-08-07 9:12 UTC (permalink / raw) To: gdb On Thursday 07 August 2008 09:42:23 Eran Ifrah wrote: > On Thu, Aug 7, 2008 at 10:15 AM, Nick Roberts <nickrob@snap.net.nz> wrote: > > > > GDB has an undocumented MI command called -data-write-memory. I've not > > > > used it though, and don't know if it works or does what you want. > > > > > > > > > > Thanks ! this is exactly what I was looking for: the sibling function > > > of -data-read-memory. > > > > > > Any ideas why this command is undocumented? > > > > Not really. If it works for you, perhaps you could documentation. > I was not referring to the actual documentation, but maybe there is a > reason for that? unsupported? > > But, I will document it once I will explore all its options. As side note: And maybe documentation for non-implemented features could be removed. For the original problem: looks like set {char[100]} buffer_in_debuggee = { 's','o','m','e',' ','d','a','t','a',0 } works. André ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Manipulating memory 2008-08-07 7:43 ` Eran Ifrah 2008-08-07 9:12 ` André Pönitz @ 2008-08-07 18:15 ` Eli Zaretskii 1 sibling, 0 replies; 8+ messages in thread From: Eli Zaretskii @ 2008-08-07 18:15 UTC (permalink / raw) To: Eran Ifrah; +Cc: nickrob, gdb > Date: Thu, 7 Aug 2008 10:42:23 +0300 > From: "Eran Ifrah" <eran.ifrah@gmail.com> > > But, I will document it once I will explore all its options. Thanks! ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-08-07 18:15 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-05 19:04 Manipulating memory Eran Ifrah
2008-08-05 19:12 ` Joel Brobecker
2008-08-05 19:37 ` Sheng-Liang Song
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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox