From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3747 invoked by alias); 5 Aug 2008 19:37:02 -0000 Received: (qmail 3738 invoked by uid 22791); 5 Aug 2008 19:37:02 -0000 X-Spam-Check-By: sourceware.org Received: from mail.baymicrosystems.com (HELO mail.baymicrosystems.com) (65.174.40.133) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 05 Aug 2008 19:36:27 +0000 Received: from [10.10.7.50] (ssl-pc.baymicrosystems.com [10.10.7.50]) (authenticated bits=0) by mail.baymicrosystems.com (8.13.5/8.13.5) with ESMTP id m75JaIBL009175; Tue, 5 Aug 2008 12:36:18 -0700 Message-ID: <4898ABB2.3080902@baymicrosystems.com> Date: Tue, 05 Aug 2008 19:37:00 -0000 From: Sheng-Liang Song User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: Joel Brobecker CC: Eran Ifrah , gdb@sourceware.org Subject: Re: Manipulating memory References: <20080805191204.GB4323@adacore.com> In-Reply-To: <20080805191204.GB4323@adacore.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-08/txt/msg00079.txt.bz2 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) > >