* 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* Re: scope in nested function
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
1 sibling, 1 reply; 4+ messages in thread
From: Jim Blandy @ 2006-03-31 7:54 UTC (permalink / raw)
To: Bill Pursell; +Cc: gdb
On 3/30/06, Bill Pursell <bill.pursell@gmail.com> wrote:
> 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)
Have you tried calling it main::foo?
> 2) when I'm in foo, how do I reference i?
Have you tried calling it main::i?
I'm not sure these will work, but I think they're supposed to.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: scope in nested function
2006-03-31 7:54 ` Jim Blandy
@ 2006-03-31 8:19 ` Bill Pursell
0 siblings, 0 replies; 4+ messages in thread
From: Bill Pursell @ 2006-03-31 8:19 UTC (permalink / raw)
To: Jim Blandy; +Cc: gdb
Jim Blandy wrote:
> On 3/30/06, Bill Pursell <bill.pursell@gmail.com> wrote:
>
>>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)
>
>
> Have you tried calling it main::foo?
>
>
>>2) when I'm in foo, how do I reference i?
>
>
> Have you tried calling it main::i?
>
> I'm not sure these will work, but I think they're supposed to.
>
I get the error:
Can't find member of namespace, class, struct, or union named "main::foo"
Same for main::i
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: scope in nested function
2006-03-31 7:36 scope in nested function Bill Pursell
2006-03-31 7:54 ` Jim Blandy
@ 2006-03-31 13:59 ` Ramana Radhakrishnan
1 sibling, 0 replies; 4+ messages in thread
From: Ramana Radhakrishnan @ 2006-03-31 13:59 UTC (permalink / raw)
To: Bill Pursell; +Cc: gdb, jimb
Is this something gdb was never designed to do ? A quick search in the
doco didn't reveal anything for me . The only reference is that of
Pascal programs not supporting debug for nested functions.
ramana@arnor:~$ arm-none-eabi-gcc -v
Using built-in specs.
Target: arm-none-eabi
Configured
with: /mnt/tools/fsf/build/combined-arm-none-eabi-svn-4-1-branch-2006-03-30/configure --target=arm-none-eabi --prefix=/mnt/tools/fsf/install/arm-none-eabi-svn-4-1-branch-2006-03-30 --enable-languages=c --disable-nls --with-newlib --disable-gdbtk --disable-libssp
Thread model: single
gcc version 4.1.1 20060330 (prerelease)
ramana@arnor:~$ arm-none-eabi-gcc -g nestedfns.c
ramana@arnor:~$ arm-none-eabi-gdb a.out
GNU gdb 6.4.50.20060103-cvs
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "--host=i686-pc-linux-gnu
--target=arm-none-eabi".../home/ramana/.gdbinit:1: Error in sourced
command file:
Junk in argument list: " brkoninsnraw"
(gdb) b main::foo
Can't find member of namespace, class, struct, or union named
"main::foo"
Hint: try 'main::foo<TAB> or 'main::foo<ESC-?>
(Note leading single quote.)
(gdb) b foo
Function "foo" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) b foo.1958
Can't find member of namespace, class, struct, or union named "foo.1958"
Hint: try 'foo.1958<TAB> or 'foo.1958<ESC-?>
(Note leading single quote.)
(gdb)
Is gdb even designed to do this. ? A google reveals this thread where a
user has mentioned problems with nested functions . The mechanism though
which is used is only using line numbers .... so .... we don't really
know if it was ever designed to work !
http://sourceware.org/ml/gdb/2005-02/msg00141.html
cheers
Ramana
On Fri, 2006-03-31 at 06:57 +0100, Bill Pursell wrote:
> 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.
--
Ramana Radhakrishnan
GNU Tools
codito ergo sum (http://www.codito.com)
^ 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