From: Daniel Jacobowitz <drow@false.org>
To: Greg Watson <g.watson@computer.org>
Cc: gcc@gcc.gnu.org, gdb@sources.redhat.com
Subject: Re: main(), registers and gdb
Date: Wed, 10 Jan 2007 23:39:00 -0000 [thread overview]
Message-ID: <20070110233854.GA21874@nevyn.them.org> (raw)
In-Reply-To: <7E9915AE-D47F-45B0-A922-D0C0C3A1D39A@computer.org>
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.
> 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.
> 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.
--
Daniel Jacobowitz
CodeSourcery
next prev parent reply other threads:[~2007-01-10 23:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-10 23:33 Greg Watson
2007-01-10 23:39 ` Daniel Jacobowitz [this message]
2007-01-10 23:51 ` Greg Watson
2007-01-11 2:01 ` Daniel Jacobowitz
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=20070110233854.GA21874@nevyn.them.org \
--to=drow@false.org \
--cc=g.watson@computer.org \
--cc=gcc@gcc.gnu.org \
--cc=gdb@sources.redhat.com \
/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