* Cann't print local vars when nesting functions
@ 2005-02-19 1:00 Jeff
2005-02-19 16:25 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Jeff @ 2005-02-19 1:00 UTC (permalink / raw)
To: gdb
I am having problems printing local stack variables when nesting
functions. Here is a test app:
int main(int argc, char *argv[]){
int i,j;
i = 0;
j = 1;
}
Now, run it to break on line:
j = 1;
and then:
(gdb) p i
$2 = 0
and all is ok. but change to this:
int main(int argc, char *argv[]){
int i,j;
int inside(void){
int k,l;
k = 3;
l = 4;
}
i = 0;
j = 1;
}
Now set the break point to the same line, j =1, and this happens:
Breakpoint 1, main () at test.c:25
25 j = 1;
(gdb) p i
No symbol "i" in current context.
(gdb)
What gives? Is there something you need to special when nesting functions?
tj
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Cann't print local vars when nesting functions 2005-02-19 1:00 Cann't print local vars when nesting functions Jeff @ 2005-02-19 16:25 ` Eli Zaretskii 2005-02-19 19:03 ` tj 0 siblings, 1 reply; 5+ messages in thread From: Eli Zaretskii @ 2005-02-19 16:25 UTC (permalink / raw) To: Jeff; +Cc: gdb > Date: Fri, 18 Feb 2005 17:54:17 -0500 > From: Jeff <wd4nmq@comcast.net> > > int main(int argc, char *argv[]){ > int i,j; > > int inside(void){ > int k,l; > k = 3; > l = 4; > } > > i = 0; > j = 1; > } > > Now set the break point to the same line, j =1, and this happens: > Breakpoint 1, main () at test.c:25 > 25 j = 1; > (gdb) p i > No symbol "i" in current context. > (gdb) > > What gives? Is there something you need to special when nesting functions? Please tell the details: what platform is this, what versions of GCC and GDB you use, and how (with what command-line options) you compiled and linked the program. Also, since the line "j = 1;" is not line 25 in the source you posted, could it be that the program you actually compiled was different? FWIW, I tried this with GCC 3.3.3, naive compiler command line, and GDB 6.3, and couldn't reproduce the problem with the source you posted. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Cann't print local vars when nesting functions 2005-02-19 16:25 ` Eli Zaretskii @ 2005-02-19 19:03 ` tj 2005-02-19 22:27 ` Eli Zaretskii 0 siblings, 1 reply; 5+ messages in thread From: tj @ 2005-02-19 19:03 UTC (permalink / raw) To: Eli Zaretskii; +Cc: gdb Eli Zaretskii wrote: >>Date: Fri, 18 Feb 2005 17:54:17 -0500 >>From: Jeff <wd4nmq@comcast.net> >> >>int main(int argc, char *argv[]){ >> int i,j; >> >> int inside(void){ >> int k,l; >> k = 3; >> l = 4; >> } >> >> i = 0; >> j = 1; >>} >> >>Now set the break point to the same line, j =1, and this happens: >>Breakpoint 1, main () at test.c:25 >>25 j = 1; >>(gdb) p i >>No symbol "i" in current context. >>(gdb) >> >>What gives? Is there something you need to special when nesting functions? >> >> > >Please tell the details: what platform is this, what versions of GCC >and GDB you use, and how (with what command-line options) you compiled >and linked the program. Also, since the line "j = 1;" is not line 25 >in the source you posted, could it be that the program you actually >compiled was different? > >FWIW, I tried this with GCC 3.3.3, naive compiler command line, and >GDB 6.3, and couldn't reproduce the problem with the source you >posted. > > > I am on linux, 2.4.26 kernel gcc 3.2.3 gdb 5.3 Source file test.c: #include <stdio.h> int main(int argc, char *argv[]){ int i,j; int inside(void){ int k,l; k = 1; l = k; return 0; } i = 0; j = 1; } test$ cc -g -O0 test.c $ gdb ./a.out GNU gdb 5.3 Copyright 2002 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 "i386-slackware-linux"... (gdb) b test.c:16 Breakpoint 1 at 0x8048340: file test.c, line 16. (gdb) run Starting program: test/a.out Breakpoint 1, main () at test.c:16 16 j = 1; (gdb) p i No symbol "i" in current context. (gdb) As stated, removing the inside() function, breaking on the same source line and printing causes i's value to be printed. No error message. tj ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Cann't print local vars when nesting functions 2005-02-19 19:03 ` tj @ 2005-02-19 22:27 ` Eli Zaretskii 2005-02-20 8:35 ` tj 0 siblings, 1 reply; 5+ messages in thread From: Eli Zaretskii @ 2005-02-19 22:27 UTC (permalink / raw) To: tj; +Cc: gdb > Date: Sat, 19 Feb 2005 11:25:39 -0500 > From: tj <999alfred@comcast.net> > CC: gdb@sources.redhat.com > > I am on linux, 2.4.26 kernel > gcc 3.2.3 > gdb 5.3 > Source file test.c: > #include <stdio.h> > > int main(int argc, char *argv[]){ > > int i,j; > int inside(void){ > int k,l; > > k = 1; > l = k; > return 0; > > } > > i = 0; > j = 1; > } > > test$ cc -g -O0 test.c > $ gdb ./a.out > GNU gdb 5.3 > Copyright 2002 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 "i386-slackware-linux"... > (gdb) b test.c:16 > Breakpoint 1 at 0x8048340: file test.c, line 16. > (gdb) run > Starting program: test/a.out > > Breakpoint 1, main () at test.c:16 > 16 j = 1; > (gdb) p i > No symbol "i" in current context. > (gdb) Well, all I can say that with GDB 6.1 and 6.3 I don't see this problem. Unless someone who knows more than I do about problems specific to GNU/Linux, I'd suggest to upgrade to newer versions of GCC and GDB, and see if the problem goes away. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Cann't print local vars when nesting functions 2005-02-19 22:27 ` Eli Zaretskii @ 2005-02-20 8:35 ` tj 0 siblings, 0 replies; 5+ messages in thread From: tj @ 2005-02-20 8:35 UTC (permalink / raw) To: Eli Zaretskii; +Cc: gdb Eli Zaretskii wrote: >>Date: Sat, 19 Feb 2005 11:25:39 -0500 >>From: tj <999alfred@comcast.net> >>CC: gdb@sources.redhat.com >> >>I am on linux, 2.4.26 kernel >>gcc 3.2.3 >>gdb 5.3 >>Source file test.c: >>#include <stdio.h> >> >>int main(int argc, char *argv[]){ >> >> int i,j; >> int inside(void){ >> int k,l; >> >> k = 1; >> l = k; >> return 0; >> >> } >> >> i = 0; >> j = 1; >>} >> >>test$ cc -g -O0 test.c >>$ gdb ./a.out >>GNU gdb 5.3 >>Copyright 2002 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 "i386-slackware-linux"... >>(gdb) b test.c:16 >>Breakpoint 1 at 0x8048340: file test.c, line 16. >>(gdb) run >>Starting program: test/a.out >> >>Breakpoint 1, main () at test.c:16 >>16 j = 1; >>(gdb) p i >>No symbol "i" in current context. >>(gdb) >> >> > >Well, all I can say that with GDB 6.1 and 6.3 I don't see this >problem. Unless someone who knows more than I do about problems >specific to GNU/Linux, I'd suggest to upgrade to newer versions of GCC >and GDB, and see if the problem goes away. > > > Your right. My system was built from Slackware 9.1. I ssh'ed to a buddy's machine that was built using Slackware 10.0. It has gcc v3.3.4 and gdb 6.1.1. I now display the values and no "not in present context messages". Oh well, wonder why it took so long for that to get fixed/included? Well, guess I need to update my system, heavy sigh. Thank you for getting me pointed in the right direction. tj ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-02-19 23:10 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-02-19 1:00 Cann't print local vars when nesting functions Jeff 2005-02-19 16:25 ` Eli Zaretskii 2005-02-19 19:03 ` tj 2005-02-19 22:27 ` Eli Zaretskii 2005-02-20 8:35 ` tj
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox