Hello.

I and my colleagues here at Lincoln Laboratory have been writing a lot
of C++ software for the last couple of years and we use g++/gcc and gdb
extensively.  Occassionally, when debugging with gdb and stepping into a
function, we are unable to print information about the contents of any
variables within that function.  Gdb gets confused and reports:

      No symbol "<var>" in current context.

I am hoping you can shed some light as to what causes this loss of
context and what we can do about it.  To narrow down the problem as best
as possible, I stripped down one of my problem source files to just
three simple functions and am supplying it to you as an exhibit.  I am
also supplying excerpts from the compilation and debugging sessions in
case that helps.

In the exhibit, the first function (Process) simply calls the other two
functions, myfunc1 and myfunc2.  If I place the code for myfunc2()
*before* the code for myfunc1() in this file, then I can step into
myfunc2() and print variables without any problem.  However, if I
reverse the placement of the code for those two functions, then I get
the context problem.

Thank you.

Seth Troxel

************************************************************************
  Seth Troxel                      E-mail:    [EMAIL PROTECTED]
  MIT Lincoln Laboratory           Office:    (781) 981-3658
  Group 95 (Weather Sensing)
************************************************************************



//==============================================================================
===
// File: process_gdbbug.C
//==============================================================================
===

#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <malloc.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#include <LLNIDList.h>

#include <skarray.h>
#include <skmath.h>
#include <LLTime.h>

#include <configAndParams.h>
#include <gfBaseImages.h>
#include <gfrefdata.h>
#include <gfevent.h>
#include <objectsCOMMON.h>

#include <gfm.h>

void myfunc1( int var );
void myfunc2( int var );


void Process()
{
  int  testVar = 1;

  myfunc1( testVar );
  myfunc2( testVar );
}


void myfunc1( int var )
{
  int  cnt;
  
  cnt = var;
}

void myfunc2( int var )
{
  int cnt;
  
  cnt = var;
}



================================================================================
=
Compilation
================================================================================
=
>gcc --version
2.7.2.3
>g++ --version
2.7.2.3

g++ -c -g -Dsolaris -fno-implicit-templates -Wall -I../../inc -I../../tdwr/inc 
-I../../nextdwr/inc -I../../detectors/inc -I/ll/sw/share/imgsh/inc 
-I/ll/sw/migfa/inc -I/ll/sw/migfa/tdwr/inc -I/ll/sw/migfa/nextdwr/inc 
-I/ll/sw/migfa/detectors/inc -I/ll/sw/csketch/inc -I/usr/openwin/include 
-I/ll/sw/share/inc -I/ll/sw/share/wxobj/inc -I/usr/local/include 
-I/usr/local/include -o ../objdbg/solaris/process_gdbbug.o process_gdbbug.C 
/ll/sw/migfa/inc/configAndParams.h:36: warning: `char * radarSystems' defined 
but not used
g++  -o ../objdbg/solaris/gfmosaic ../objdbg/solaris/driver.o 
../objdbg/solaris/init.o ../objdbg/solaris/process_gdbbug.o 
-L../../libdbg/solaris -L../../lib/solaris -L/ll/sw/migfa/libdbg/solaris 
-L/ll/sw/migfa/lib/solaris -L/ll/sw/csketch/libdbg/solaris 
-L/ll/sw/csketch/lib/solaris -L/ll/sw/share/libdbg/solaris 
-L/ll/sw/share/lib/solaris -L/usr/ucblib -L/usr/openwin/lib -lgfmio -ltdwr 
-lnextdwr -lgfext -lgfan -lgfpred -lgfio -lgfcom -lgfwind -ldetect -ldetbase 
-lbaseobj -lgfdeb -lskarr -lskutil -lio -ldisp -lalgutils -lshare -lWxObj 
-limgsh -lsclite -ltk -ltcl -lX11 -lcftlite -ldl -lllutil -lparamTcl -lmem -llog 
-lsocket -lnsl -ldl -lposix4 -lm -lc -lz 
gmake[1]: Leaving directory 
`/home/romeo/1/setht/migfa/mosaic/sw/gfmosaic/driver/src'

Compilation finished at Fri Mar 24 14:25:18


================================================================================
====
GDB Session log:
================================================================================
====

Current directory is 
/home/romeo/1/setht/migfa/mosaic/sw/gfmosaic/driver/objdbg/solaris/
GNU gdb 4.17
Copyright 1998 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 "sparc-sun-solaris2.6"...
(gdb) source gdb.env
(gdb) break process_gdbbug.C:95
Breakpoint 1 at 0x354dc: file process_gdbbug.C, line 95.
(gdb) run -i /SC/MIGFA.TDWR_DAL -i /SC/MIGFA.TDWR_DFW -o /SC/MIGFA_GF_Detections
Starting program: 
/home/romeo/1/setht/migfa/mosaic/sw/gfmosaic/driver/objdbg/solaris/gfmosaic -i 
/SC/MIGFA.TDWR_DAL -i /SC/MIGFA.TDWR_DFW -o /SC/MIGFA_GF_Detections
Mar 24 14:23:26 [INFO] Initializing...
Reading GFParams parameters from file: /ll/sw/migfa/params/paramsTDWR
Reading GFParams parameters from file: /ll/sw/migfa/params/paramsTDWR
GFLoadDefaultConfig: Loading...
Reading GFIntGenConfig parameters from file: /ll/sw/migfa/params/configOBTDWR
Reading GFIntGenConfig parameters from file: /ll/sw/migfa/params/configOBTDWR
Initializing client for stream /SC/MIGFA.TDWR_DAL
[SC9035:scSetSignalHandlers:3] Handlers installed:  - SIGINT, SIGKILL, SIGTERM, 
SIGUSR2 
(SCGetService) Located "MIGFA.TDWR_DAL" (TCP) service in 
/ll/migfa/mosaic/params/alg_service.local, line 7


[SC9035:TCPBuildSocketAddr:2]  - Defining client address 129.55.53.40, port 7043

Initializing client for stream /SC/MIGFA.TDWR_DFW
(SCGetService) Located "MIGFA.TDWR_DFW" (TCP) service in 
/ll/migfa/mosaic/params/alg_service.local, line 8


[SC9035:TCPBuildSocketAddr:2]  - Defining client address 129.55.53.40, port 7044

Mar 24 14:23:32 [INFO] ProcessStreams: Timeout waiting for data
Mar 24 14:23:37 [INFO] ProcessStreams: Timeout waiting for data
Mar 24 14:23:42 [INFO] ProcessStreams: Timeout waiting for data
In FrameStartHandler
Mar 24 14:23:45 [INFO] ProcessStreams: No control data present
In SKArrayHandler: stream num = 0

Breakpoint 1, Process () at process_gdbbug.C:95
(gdb) step
myfunc2 (var=1) at process_gdbbug.C:103
(gdb) p var
$1 = 1
(gdb) kill
Kill the program being debugged? (y or n) y
(gdb) run
`/home/romeo/1/setht/migfa/mosaic/sw/gfmosaic/driver/objdbg/solaris/gfmosaic' 
has changed; re-reading symbols.
Starting program: 
/home/romeo/1/setht/migfa/mosaic/sw/gfmosaic/driver/objdbg/solaris/gfmosaic -i 
/SC/MIGFA.TDWR_DAL -i /SC/MIGFA.TDWR_DFW -o /SC/MIGFA_GF_Detections
Mar 24 14:26:01 [INFO] Initializing...
Reading GFParams parameters from file: /ll/sw/migfa/params/paramsTDWR
Reading GFParams parameters from file: /ll/sw/migfa/params/paramsTDWR
GFLoadDefaultConfig: Loading...
Reading GFIntGenConfig parameters from file: /ll/sw/migfa/params/configOBTDWR
Reading GFIntGenConfig parameters from file: /ll/sw/migfa/params/configOBTDWR
Initializing client for stream /SC/MIGFA.TDWR_DAL
[SC9063:scSetSignalHandlers:3] Handlers installed:  - SIGINT, SIGKILL, SIGTERM, 
SIGUSR2 
(SCGetService) Located "MIGFA.TDWR_DAL" (TCP) service in 
/ll/migfa/mosaic/params/alg_service.local, line 7


[SC9063:TCPBuildSocketAddr:2]  - Defining client address 129.55.53.40, port 7043

Initializing client for stream /SC/MIGFA.TDWR_DFW
(SCGetService) Located "MIGFA.TDWR_DFW" (TCP) service in 
/ll/migfa/mosaic/params/alg_service.local, line 8


[SC9063:TCPBuildSocketAddr:2]  - Defining client address 129.55.53.40, port 7044

Mar 24 14:26:08 [INFO] ProcessStreams: Timeout waiting for data
Mar 24 14:26:13 [INFO] ProcessStreams: Timeout waiting for data
Mar 24 14:26:18 [INFO] ProcessStreams: Timeout waiting for data
In FrameStartHandler
In SKArrayHandler: stream num = 0

Breakpoint 1, Process () at process_gdbbug.C:95
(gdb) step
myfunc2 () at process_gdbbug.C:111
(gdb) p var
No symbol "var" in current context.
(gdb) p cnt
No symbol "cnt" in current context.
(gdb) kill
Kill the program being debugged? (y or n) y
(gdb) 

Reply via email to