Topic with GNU debugger

Hi,

I was trying to debug some code with GNU debugger:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  // more things before
  unsigned int size( coll_ets.size() );
  unsigned int inner_size( 0 );
  unsigned int i( 0 );
  unsigned int j( 1 );
  for(
//    unsigned int i( 0 );
    ;
    i < size;
    ++i
  ) {
    inner_size = (coll_ets.at(i)).size();
    for(
//      unsigned int j( 1 );
      ;
      j < inner_size;
      ++j
    ) {
       // more things here
    }
  }


So I place a breakpoint at the inner_size = (coll_ets.at(i)).size();.
When reaching the breakpoint, I try to see the value of both i and j, but I get this:

(gdb) p i
No symbol "i" in current context.
(gdb) p j
No symbol "j" in current context.


I get the same thing if i and j are declared inside the for-loop declaration instead of outside.
When the breakpoint is reached, both i and j have been initialized and are in use, so my thought was that they were in context, but it seems that they're not.

So, how can I access those variables?

Thanks!
They should be in scope. It looks as if you did not break where you thought you did.
They should be in scope

That's what I thought.

It looks as if you did not break where you thought you did.

Mmmm, well. When the breakpoint is reached, I can see inner_size's value. So, in theory, the breakpoint is well reached...
Ok. I got that to work. However, I've got another problem when executing the program in parallel with Intel TBB.

I have some child classes that will simulate the events between particles in a particle system and compute the next event for each particle in parallel. Once the child classes have finished, a continuation class will check if there are conflicts between them and update the global system.

The problem is in the code of the child class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
HitEventAux* ParticleTask::LocalZoneEvent(
  Particle* restrict P,
  const Zone* z
) throw (
   NotEnoughMemoryException
) {
  try {
    return new HitEventAux( z->PossibleEvent( P ) );
  } catch( const std::bad_alloc& e ) {
   throw NotEnoughMemoryException( "Auxiliar event", __FILE__, __LINE__ );
  }
}

void ParticleTask::CheckNextEvent(
  Particle* owner,
  Particle* partner,
  const Zone* z,
  HitEventAux* &toret
) {
  toret = LocalZoneEvent( owner, z );
  
  unsigned int partner_index( ETERNITY );
  if( partner ) {
    partner_index = partner->Index();
  }  
  const Zone::iterator end_it(z->end());
  for(Zone::iterator
    it(z->whereIs( owner->Index() ) );
    it!=end_it;
    ++it
  ) {
    Hitable* restrict N=*it;
    if(
      N->Index() != owner->Index()
      && N->Index() != partner_index
    ) { // neither hit yourself, nor your last partner
      const HitEvent next_event( N->PossibleEvent( owner, *z, it ) );
      if( next_event.Time() <= toret->Time() ) {
        toret->SetOwner( next_event.Owner()->Index() );
        toret->SetType( next_event.Type() );
        toret->SetTime( next_event.Time() );
        if( next_event.Partner() ) {
          toret->SetPartner( next_event.Partner()->Index() );
        } else {
          toret->SetPartner( ETERNITY );
        }
      }
    }
  }


The line where the segfault occurs is const HitEvent next_event( N->PossibleEvent( owner, *z, it ) ).
When debugging, I wanted to check the value of N, to see if it was a null pointer; but ended with this:
warning: can't find linker symbol for virtual table for `Hitable' value

In Google I couldn't find anything useful and that warning only occurs when the program segfaults, which is always when checking the 2006th and 2007th events.
Before those two, when placing a breakpoint at that line and checking the contents of N, everything goes well(the other args: owner, z and it are fine).

The thing is that I need to check the content of N to debug the code, but with that warning is impossible. Any help?.

Thanks!

PS: I have tried to run the program using the TBB library, simulating only one event at a time and using only one thread(basically, a serial execution) and it goes perfectly. No warnings, no segfaults.

PS2: A particle is derived form Hitable and toret is declared before calling the method as a NULL pointer. It is intended to be initialized by the LocalZoneEvent method. Don't know if that helps...
Are you compiling with the right flags? In particular optimization must be turned off -O0 and debugging info on-g3.
Hi!

I was compiling with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
CXXFLAGS = \
  -D_GNU_SOURCE \
  -DCPLUSPLUS \
  -Wall \
  -Wconversion -Wpointer-arith \
  -Wcast-align -Wno-non-template-friend \
  -ffloat-store \
  -lMagick++ \
  -lm -lpng -lglut -ltbb -ltbbmalloc \
  -lboost_thread -lpthread -lboost_filesystem-mt
  $(GTKINC) \
  $(OPT) \

GTKINC = \
  `pkg-config --cflags glib-2.0` \
  `pkg-config --cflags gtkglextmm-1.2`

GTKLIB = \
  `pkg-config --libs gthread-2.0` \
  -Wl,--export-dynamic \
  -lgtkglextmm-x11-1.2 -lgdkglextmm-x11-1.2 -lgtkglext-x11-1.0 \
  -lgtkmm-2.4 -lgdkglext-x11-1.0 -lXt -lSM -lICE \
  -lpangox-1.0 -lX11 -lgdkmm-2.4 -latkmm-1.6 -lgtk-x11-2.0 \
  -lpangomm-1.4 -lcairomm-1.0 -lglibmm-2.4 -lsigc-2.0 -lgdk-x11-2.0 \
  -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 \
  -lcairo -lpango-1.0 -lfreetype -lz -lfontconfig \
  -lgobject-2.0 -lgmodule-2.0 -lglib-2.0

OPT      = \
 -g \ 
 -DDEBUG \
 -DNO_PROCESS \
 -DTBB_DO_ASSERT \
 -DTBB_DO_THREADING_TOOLS \
 -Wno-deprecated


Now, everything is the same except for OPT, which was changed to what Galik suggested:
1
2
3
4
5
6
7
8
OPT     =\
  -O0 \
  -g3 \ 
  -DDEBUG \
  -DNO_PROCESS \
  -DTBB_DO_ASSERT \
  -DTBB_DO_THREADING_TOOLS \
  -Wno-deprecated


But the problem persists. I post the gdb backtrace(which I forgot the last time) for if it helps:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#0  0x012fe43d in main_arena () from /lib/tls/i686/cmov/libc.so.6
#1  0x08104373 in ParticleTask::CheckNextEvent (this=0xb7fb3920, owner=0x8200958, partner=0x0, zone=0x81fc680, toret=@0xbfffea78) at ParticleTask.cpp:255
#2  0x081045a0 in ParticleTask::CheckZoneChange (this=0xb7fb3920, owner=0x8200958, zone=0x81fc680, ref=@0xb7fb3480) at ParticleTask.cpp:356
#3  0x08104852 in ParticleTask::HandleLocalEvent (this=0xb7fb3920, col=0x8200908, ref=...) at ParticleTask.cpp:144
#4  0x08104a91 in ParticleTask::execute (this=0xb7fb3920) at ParticleTask.cpp:80
#5  0x01032741 in tbb::internal::CustomScheduler<tbb::internal::IntelSchedulerTraits>::local_wait_for_all (this=0xb7fb7e00, parent=@0xb7fb3aa0, child=0xb7fb3620)
    at ../../src/tbb/task.cpp:2761
#6  0x01032f8c in tbb::internal::CustomScheduler<tbb::internal::IntelSchedulerTraits>::wait_for_all (this=0xb7fb7e00, parent=@0xb7fb3aa0, child=0xb7fb3620)
    at ../../src/tbb/task.cpp:1794
#7  0x01031503 in tbb::internal::GenericScheduler::local_spawn_root_and_wait (this=0xb7fb7e00, first=@0xb7fb3620, next=@0xb7fb361c) at ../../src/tbb/task.cpp:2532
#8  0x01031a9c in tbb::internal::GenericScheduler::spawn_root_and_wait (this=0xb7fb7e00, first=@0xb7fb3620, next=@0xb7fb361c) at ../../src/tbb/task.cpp:1485
#9  0x08154eab in tbb::task::spawn_root_and_wait (root=@0xb7fb3620) at /usr/include/tbb/task.h:579
#10 0x08153332 in Parsystem::Simulate (this=0x81fc5e0, maxCollisions_=100) at Parsystem.cpp:521
#11 0x08119089 in Hitter::Run (this=0xbffff244, cnf=@0x81efca0) at Hitter.cpp:417
#12 0x0816a16e in main (argc=2, argv=0xbffff384) at hmain.cpp:80 


ref (in frame 2) is a reference to tbb::enumerable_thread_specific< std::vector<CollEventAux> > CollEventEts

Thanks all of you for your help!

EDIT: SO is Ubuntu 10.04.3 LTS ** Kernel version is 2.6.32-38-generic ** g++ version is 4.1.3 ** gdb version is 7.1-ubuntu
Last edited on
Topic archived. No new replies allowed.