This is the mail archive of the
gdb-prs@sources.redhat.com
mailing list for the GDB project.
gdb/342: No symbol "<var>" in current context for C++ variable declared in if block after try/catch
- From: galexander at nc dot rr dot com
- To: gdb-gnats at sources dot redhat dot com
- Cc: gdlxn at us dot ibm dot com
- Date: 6 Feb 2002 05:58:03 -0000
- Subject: gdb/342: No symbol "<var>" in current context for C++ variable declared in if block after try/catch
- Reply-to: galexander at nc dot rr dot com
>Number: 342
>Category: gdb
>Synopsis: No symbol "<var>" in current context for C++ variable declared in if block after try/catch
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Feb 05 22:08:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Geoff Alexander
>Release: GNU gdb 5.1
>Organization:
>Environment:
SuSE Linux for i386 7.1
gcc 2.95.2 as shipped with SuSE 7.1 (gcc-2.95.2-151)
>Description:
When trying to print a variable in a C++ program declared
in a if block which occurs after a try/catch, I get a
No symbol "<var>" in current context.
error.
The following program illustrates the problem:
#include <cstdlib>
#include <exception>
#include <iostream>
#include <string>
int main( int argc, char* argv[] )
{
try
{
string d = "This is d";
}
catch (std::exception& e)
{
cout << "std::exception caught" << endl;
exit(EXIT_FAILURE);
}
string a = "This is a";
if ( a == "" )
{
string b = "This is b";
cout << a << endl;
cout << b << endl;
cout << b.c_str() << endl;
}
else
{
string c = "This is c";
cout << a << endl;
cout << c << endl;
}
exit(EXIT_SUCCESS);
}
I compiled the above program as follows:
g++ -g -o Test2 Test2.cppg
Using gdb to debug, I get a
No symbol "c" in current context.
error as follows:
GNU gdb 5.1
Copyright 2001 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 "i686-pc-linux-gnu"...
(gdb) break 27
Breakpoint 1 at 0x804a14e: file Test2.cpp, line 27.
(gdb) run
Starting program: /home/gdlxn/gdb_bugs/001/Test2
Breakpoint 1, main (argc=1, argv=0xbffff7cc) at Test2.cpp:27
27 cout << a << endl;
(gdb) print c
No symbol "c" in current context.
If I comment out the the try/catch as follows:
#include <cstdlib>
#include <exception>
#include <iostream>
#include <string>
int main( int argc, char* argv[] )
{
// try
// {
// string d = "This is d";
// }
// catch (std::exception& e)
// {
// cout << "std::exception caught" << endl;
// exit(EXIT_FAILURE);
// }
string a = "This is a";
if ( a == "" )
{
string b = "This is b";
cout << a << endl;
cout << b << endl;
cout << b.c_str() << endl;
}
else
{
string c = "This is c";
cout << a << endl;
cout << c << endl;
}
exit(EXIT_SUCCESS);
}
recompile as follows:
g++ -g -o Test3 Test3.cpp
and debug using gdb, I am able to print c:
GNU gdb 5.1
Copyright 2001 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 "i686-pc-linux-gnu"...
(gdb) break 27
Breakpoint 1 at 0x804a01c: file Test3.cpp, line 27.
(gdb) run
Starting program: /home/gdlxn/gdb_bugs/001/Test3
Breakpoint 1, main (argc=1, argv=0xbffff7cc) at Test3.cpp:27
27 cout << a << endl;
(gdb) print c
$1 = {static npos = 4294967295, static nilRep = {len = 0, res = 0, ref = 1,
selfish = false}, dat = 0x804cad8 "This is c"}
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: