Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Eli Zaretskii" <eliz@gnu.org>
To: tj <999alfred@comcast.net>
Cc: gdb@sources.redhat.com
Subject: Re: Still problems with gdb and nested functions.
Date: Tue, 22 Feb 2005 20:50:00 -0000	[thread overview]
Message-ID: <01c5191f$Blat.v2.4$6b7c0e60@zahav.net.il> (raw)
In-Reply-To: <421B8556.6070905@comcast.net> (message from tj on Tue, 22 Feb 2005 14:17:42 -0500)

> Date: Tue, 22 Feb 2005 14:17:42 -0500
> From: tj <999alfred@comcast.net>
> 
> Breakpoint 1, inside.0 () at test.c:12
> 12          printf("inside, k = %d, l = %d\n", k,l);
> (gdb) p k
> No symbol "k" in current context.
> (gdb) continue
> Continuing.
> inside, k = 1, l = 1

I can confirm this, but it looks like this is either a GCC problem, or
perhaps GCC generates DWARF-2 debug info that confuses GDB.  Observe:

  $ gcc -O0 -ggdb3 -o test test.c
  $ gdb ./test
  ...
  (gdb) break 12
  Breakpoint 1 at 0x16de: file test.c, line 12.
  (gdb) info address k
  No symbol "k" in current context.
  (gdb) disassemble
  Dump of assembler code for function inside.0:
  0x000016c8 <inside.0+0>:        push   %ebp
  0x000016c9 <inside.0+1>:        mov    %esp,%ebp
  0x000016cb <inside.0+3>:        sub    $0x18,%esp
  0x000016ce <inside.0+6>:        mov    %ecx,0xfffffffc(%ebp)
  0x000016d1 <inside.0+9>:        movl   $0x1,0xfffffff8(%ebp)
  0x000016d8 <inside.0+16>:       mov    0xfffffff8(%ebp),%eax
  0x000016db <inside.0+19>:       mov    %eax,0xfffffff4(%ebp)
  0x000016de <inside.0+22>:       sub    $0x4,%esp
  0x000016e1 <inside.0+25>:       pushl  0xfffffff4(%ebp)
  0x000016e4 <inside.0+28>:       pushl  0xfffffff8(%ebp)
  0x000016e7 <inside.0+31>:       push   $0x16b0
  0x000016ec <inside.0+36>:       call   0x3360 <printf>
  0x000016f1 <inside.0+41>:       add    $0x10,%esp
  0x000016f4 <inside.0+44>:       mov    $0x0,%eax
  0x000016f9 <inside.0+49>:       leave
  0x000016fa <inside.0+50>:       ret
  End of assembler dump.
  (gdb) info locals
  No locals.

The disassembly clearly shows that GDB is wrong: the variable k is
stored at 0xfffffff8(%ebp).

Now watch what happens with stabs debug info:

  gcc -O0 -gstabs3 -o test test.c
  $ gdb ./test
  ...
  (gdb) break 12
  Breakpoint 1 at 0x160e: file test.c, line 12.
  (gdb) info address k
  Symbol "k" is a local variable at frame offset -8.
  (gdb) print k
  $1 = 1
  (gdb) info locals
  k = 1
  l = 1
  (gdb)

So with stabs debug info, GDB works correctly, but with the default
DWARF-2 debug info, it gets confused.

(Strangely, the code location corresponding to breakpoint at line 12
is also different in these two builds: 0x160e vs 0x16de.  Why would
debug info affect code locations? anyone?)


      parent reply	other threads:[~2005-02-22 20:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-22 19:31 tj
2005-02-22 20:27 ` Paul Hilfinger
2005-02-22 20:45   ` Cal Erickson
2005-02-22 20:53     ` Eli Zaretskii
2005-02-22 21:02       ` Cal Erickson
2005-02-22 21:43       ` Cal Erickson
2005-02-22 20:56   ` Eli Zaretskii
2005-02-22 20:50 ` Eli Zaretskii [this message]

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='01c5191f$Blat.v2.4$6b7c0e60@zahav.net.il' \
    --to=eliz@gnu.org \
    --cc=999alfred@comcast.net \
    --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