Bug 37245 - GDB reports "No definition of "var1" in current context." for an existing variable
Summary: GDB reports "No definition of "var1" in current context." for an existing var...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.3.1
: P3 normal
Target Milestone: 4.6.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-26 17:41 UTC by Ludovic Brenta
Modified: 2011-09-08 08:06 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.2.3
Known to fail: 4.1.2, 4.3.1, 4.4.0
Last reconfirmed:


Attachments
Source file that reproduces the problem (241 bytes, text/plain)
2008-08-26 17:43 UTC, Ludovic Brenta
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ludovic Brenta 2008-08-26 17:41:34 UTC
Initially reported as a GDB bug: http://sourceware.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gdb&pr=2512

but changing the compiler to GCC 4.2 eliminates the problem, so this is a GCC bug.  Bug description reproduced here for convenience:

Steps to reproduce:
1) Save the attached file "gdb_bug_2.adb"
2) gnatmake -ggdb3 -O0 gdb_bug_2
3) gdb ./gdb_bug_2
4) break breakpoint
5) run
6) print var1
7) print var2

Expected results:
6) gdb prints 42 as the value of var1
7) gdb prints 43 as the value of var2

Actual results
6) gdb prints "No definition of "var1" in current context."
7) gdb prints 43 as the value of var2

More info:
1) Fun2 is not called at all. However, if I remove fun2 from the program gdb is able to print the value of var1 correctly.
2) Fitg5 does not use its arguments. However, if I change the type of argument from real_vector to natural gdb is again able to print the value of var1 correctly.
3) Versions of relevant debian packages are

ii  gcc-4.3                           4.3.1-9                           The GNU C compiler
ii  gdb                               6.8-3                             The GNU Debugger
ii  gnat-4.3                          4.3.1-2                           The GNU Ada compiler

4) Please let me know if you can't reproduce the problem, I am happy to provide more info!


From: Rod Kay <rodkay@dodo.com.au>
To: gdb-gnats@sources.redhat.com
Cc:  
Subject: Re: ada/2512: can not find definition of an ada variable with gdb
Date: Tue, 26 Aug 2008 14:02:42 +1000

 Results on Ubuntu 'Hardy' (up-to-date):
 
 - Linux orth 2.6.24-19-generic #1 SMP Fri Jul 11 23:41:49 UTC 2008 i686 
 GNU/Linux
 - gcc version 4.1.3 20080522 for GNAT GPL 2008 (20080521)
 - GNU gdb 6.6 for GNAT GPL 2008 (20080521) [rev:131253]
 
 
 (gdb) print var1
 $1 = 42
  (gdb) print var2
 $2 = 43
 
 
 
    Hope this helps ...
 
 
 cheers,
 Charlie.

From: Timo Juhani Lindfors <timo.lindfors@iki.fi>
To: gdb-gnats@sources.redhat.com
Cc:  
Subject: Re: ada/2512: can not find definition of an ada variable with gdb
Date: Tue, 26 Aug 2008 09:42:25 +0300

 ubuntu hardy
 ii  gcc-4.2                              4.2.3-2ubuntu7                       The GNU C compiler
 ii  gdb                                  6.8-1ubuntu2                         The GNU Debugger
 ii  gnat                                 4.2.3-1ubuntu6                       The GNU Ada compiler
 
 => "$1 = 42"
 
 ubuntu hardy
 ii  gcc-4.1                              4.1.2-21ubuntu1                      The GNU C compiler
 ii  gdb                                  6.8-1ubuntu2                         The GNU Debugger
 ii  gnat-4.1                             4.1.2-16ubuntu3                      The GNU Ada compiler
 
 => "$1 = 1"
 
 debian unstable
 ii  gcc-4.1                              4.1.2-23                             The GNU C compiler
 ii  gdb                                  6.8-3                                The GNU Debugger
 ii  gnat-4.1                             4.1.2-20                             The GNU Ada compiler
 
 => "$1 = 1"
 
 debian unstable
 ii  gcc-snapshot                         20080802-1                           A SNAPSHOT of the GNU Compiler Collection
 
 => "No definition of "var1" in current context."
Comment 1 Ludovic Brenta 2008-08-26 17:43:07 UTC
Created attachment 16151 [details]
Source file that reproduces the problem
Comment 2 Ludovic Brenta 2008-08-26 17:49:32 UTC
Note that 4.1.2 fails in a different way than 4.3.1 and trunk.
Comment 3 Nicolas Boulenguez 2011-08-31 23:59:48 UTC
Linux 3.0.0-1-amd64 x86_64 gcc 4.6.1 (-5 in debian) and gdb 7.2 (-debian)
gdb reports the correct answer $1 = 42
Comment 4 Timo Lindfors 2011-09-01 00:31:16 UTC
The bug still occurs for me on debian testing:

lindi2:~/tmp$ gnatmake -ggdb3 -O0 gdb_bug_2
gcc-4.4 -c -ggdb3 -O0 gdb_bug_2.adb
gdb_bug_2.adb:25:07: warning: variable "gs" is read but never assigned
gnatbind -x gdb_bug_2.ali
gnatlink gdb_bug_2.ali -ggdb3
lindi2:~/tmp$ gdb ./gdb_bug_2
GNU gdb (GDB) 7.2-debian
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/lindi/tmp/gdb_bug_2...done.
(gdb) break breakpoint
Breakpoint 1 at 0x401322: file gdb_bug_2.adb, line 16.
(gdb) run
Starting program: /home/lindi/tmp/gdb_bug_2 

Breakpoint 1, gdb_bug_2.fitg5.breakpoint () at gdb_bug_2.adb:16
16	      end Breakpoint;
(gdb) print var1
No definition of "var1" in current context.
(gdb) print var2
$1 = 43
(gdb) quit
A debugging session is active.

	Inferior 1 [process 11766] will be killed.

Quit anyway? (y or n) y
lindi2:~/tmp$ dpkg-query -W gdb
gdb	7.2-1
lindi2:~/tmp$ dpkg-query -W gcc
gcc	4:4.6.1-2
lindi2:~/tmp$ cat /proc/version 
Linux version 3.0.0-1-amd64 (Debian 3.0.0-1) (ben@decadent.org.uk) (gcc version 4.5.3 (Debian 4.5.3-4) ) #1 SMP Sun Jul 24 02:24:44 UTC 2011
lindi2:~/tmp$ md5sum gdb_bug_2.adb 
58638c361f25465b7a6288d0a69c7964  gdb_bug_2.adb


and unstable:


(sid)lindi1:~/tmp$ gnatmake -ggdb3 -O0 gdb_bug_2
gcc-4.4 -c -ggdb3 -O0 gdb_bug_2.adb
gdb_bug_2.adb:25:07: warning: variable "gs" is read but never assigned
gnatbind -x gdb_bug_2.ali
gnatlink gdb_bug_2.ali -ggdb3
(sid)lindi1:~/tmp$ gdb ./gdb_bug_2
GNU gdb (GDB) 7.3-debian
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/lindi/tmp/gdb_bug_2...done.
(gdb) break breakpoint
Breakpoint 1 at 0x401322: file gdb_bug_2.adb, line 16.
(gdb) run
Starting program: /home/lindi/tmp/gdb_bug_2 

Breakpoint 1, gdb_bug_2.fitg5.breakpoint () at gdb_bug_2.adb:16
16	      end Breakpoint;
(gdb) print var1
No definition of "var1" in current context.
(gdb) print var2
$1 = 43
(gdb) quit
A debugging session is active.

	Inferior 1 [process 16208] will be killed.

Quit anyway? (y or n) y
(sid)lindi1:~/tmp$ dpkg-query -W gdb
gdb	7.3-1
(sid)lindi1:~/tmp$ dpkg-query -W gcc
gcc	4:4.6.1-2
(sid)lindi1:~/tmp$ cat /proc/version 
Linux version 2.6.32-5-amd64 (Debian 2.6.32-35) (dannf@debian.org) (gcc version 4.3.5 (Debian 4.3.5-4) ) #1 SMP Tue Jun 14 09:42:28 UTC 2011

(the unstable one is in a chroot so it is running older kernel in case you wonder.)
Comment 5 Nicolas Boulenguez 2011-09-01 01:15:04 UTC
During the Debian transition, the default gnat (4.4.6) uses its own gcc instead of the default gcc (4.6.1), as you can see in line 2 of your log.
Summary of our results so far:
4.1.2 reports 1
4.1.3 ok
4.2.3 ok
4.3.1 no definition
4.4.6 no definition
4.6.1 ok
Comment 6 Arnaud Charlet 2011-09-01 06:33:31 UTC
Closing then, thanks for checking
Comment 7 Timo Lindfors 2011-09-08 08:06:42 UTC
Great news! I can verify that this indeed was fixed in debian (amd64 unstable) too:

$ gnatmake -ggdb3 -O0 gdb_bug_2
gcc-4.6 -c -ggdb3 -O0 gdb_bug_2.adb
gdb_bug_2.adb:25:07: warning: variable "gs" is read but never assigned
gnatbind -x gdb_bug_2.ali
gnatlink gdb_bug_2.ali -ggdb3 -O0
(sid)lindi1:~/tmp$ gdb ./gdb_bug_2
GNU gdb (GDB) 7.3-debian
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/lindi/tmp/gdb_bug_2...done.
(gdb) break breakpoint
Breakpoint 1 at 0x401295: file gdb_bug_2.adb, line 15.
(gdb) run
Starting program: /home/lindi/tmp/gdb_bug_2 

Breakpoint 1, gdb_bug_2.fitg5.breakpoint () at gdb_bug_2.adb:15
15	         null;
(gdb) print var1
$1 = 42
(gdb) print var2
$2 = 43
(gdb) quit
A debugging session is active.

	Inferior 1 [process 12502] will be killed.

Quit anyway? (y or n) y   
(sid)lindi1:~/tmp$ dpkg-query -W gnat-4.6
gnat-4.6	4.6.1-5