Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* scope in nested function
@ 2006-03-31  7:36 Bill Pursell
  2006-03-31  7:54 ` Jim Blandy
  2006-03-31 13:59 ` Ramana Radhakrishnan
  0 siblings, 2 replies; 4+ messages in thread
From: Bill Pursell @ 2006-03-31  7:36 UTC (permalink / raw)
  To: gdb

I'm not sure how to reference a variable in a nested function from gdb.
In the gdb session below, there are 2 things I don't understand
how to do:

1) how do I set a breakpoint in foo? (other than by referencing a line
      	number)
2) when I'm in foo, how do I reference i?


#include <stdio.h>

int
main()
{
      auto void foo(void);
      int i = 0;
      foo();
      return 0;

      void foo(void) {
          i += 1;
      }
}




(gdb) b main
Breakpoint 1 at 0x8048361: file d.c, line 7.
(gdb) run
Starting program: /home/bill/tmp/a.out

Breakpoint 1, main () at d.c:7
7           int i = 0;
(gdb) b foo
Function "foo" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) n
8           foo();
(gdb) s
foo.0 () at d.c:11
11          void foo(void) {
(gdb) p i
No symbol "i" in current context.
(gdb) n
12              i += 1;
(gdb) cont
Continuing.

Program exited normally.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-03-31  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-31  7:36 scope in nested function Bill Pursell
2006-03-31  7:54 ` Jim Blandy
2006-03-31  8:19   ` Bill Pursell
2006-03-31 13:59 ` Ramana Radhakrishnan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox