From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28840 invoked by alias); 10 Jan 2007 23:51:27 -0000 Received: (qmail 28641 invoked by uid 22791); 10 Jan 2007 23:51:24 -0000 X-Spam-Check-By: sourceware.org Received: from elasmtp-dupuy.atl.sa.earthlink.net (HELO elasmtp-dupuy.atl.sa.earthlink.net) (209.86.89.62) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 10 Jan 2007 23:51:18 +0000 Received: from [68.166.114.35] (helo=[ZJ?_??IPv6:::1]) by elasmtp-dupuy.atl.sa.earthlink.net with asmtp (Exim 4.34) id 1H4nDk-0001FJ-9d; Wed, 10 Jan 2007 18:51:04 -0500 In-Reply-To: <20070110233854.GA21874@nevyn.them.org> References: <7E9915AE-D47F-45B0-A922-D0C0C3A1D39A@computer.org> <20070110233854.GA21874@nevyn.them.org> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <79E7E700-FE56-4481-9AAC-A91EA9D4F4F0@computer.org> Cc: gcc@gcc.gnu.org, gdb@sources.redhat.com Content-Transfer-Encoding: 7bit From: Greg Watson Subject: Re: main(), registers and gdb Date: Wed, 10 Jan 2007 23:51:00 -0000 To: Daniel Jacobowitz X-Mailer: Apple Mail (2.752.3) X-ELNK-Trace: b18dadd04c208faa1aa676d7e74259b7b3291a7d08dfec796e0a32b3d92d77684db671e46ffeb8b3350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c 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: 2007-01/txt/msg00186.txt.bz2 On Jan 10, 2007, at 4:38 PM, Daniel Jacobowitz wrote: > On Wed, Jan 10, 2007 at 04:32:48PM -0700, Greg Watson wrote: >> If the following code is compiled with 'gcc -g -O0 -o test test.c', >> the address of argc is passed into func() in the ecx register. Since >> ecx is not preserved after the call to printf(), the address of argc >> is corrupted on return from func(). Normally this would not be a >> problem, since argc is never used in the code. > > This is a typical problem. There is not much that can be done about > it, although I remember once hearing a proposal that GCC should > forcibly extend the live ranges of local variables (or at least > arguments) at -O0 to improve debugging. That seems sensible to me. That would be nice. Although this seems like a trivial issue, it can potentially effect debugging all MPI programs since they always start with 'MPI_Init(&argc, &argv)'. > >> However, when run under gdb, commands that view the stack frame >> produce strange results, and some commands (e.g. -var-update) >> actually crash the debugger. > > A crash is always a bug. I believe it's gdb bug #2188. > >> Breakpoint 1, main (argc=1, argv=0xbffcef14) at test.c:14 >> 12 func(&argc); >> (gdb) n >> in func >> 14 printf("hello\n"); >> (gdb) where >> #0 main (argc=Cannot access memory at address 0x4 >> ) at test.c:16 > > And honestly, I have no idea how that happened. Does it happen > with a current GDB? I suspect from the error message that this > one is not too recent. It's gdb 6.5, so reasonably recent. Greg