Breakpoint not hit because of function pointers or something similar

Anton MOUKHARSKI anton.moukharski@cea.fr
Tue May 4 13:23:00 GMT 2010


Hello,
I am trying to hit a breakpoint that appears early in the code, but gdb 
(ddd) misses it each time. At first I thought it was because of 
templates, but gdb seems to cope with that. I have a code similar to 
this one (C++, don't read it in detail at first) :

int main(int argc,const char **argv)

{

    ABM proc(params...);

    proc.execute(fileinr);

  return EXIT_SUCCESS;

}



And the main code where I want my breakpoint is :

template <class T>
bool doit( Process & process, const string & fileinr, Finder & )
{
	//stuff
	return(1);
}


The link between the two is somewhere here :

ABM, which is a child of Process, contains the following code in it's 
(only) constructor :

registerProcessType( "Volume", "S8", &doit<int8_t> );
  registerProcessType( "Volume", "U8", &doit<uint8_t> );
  registerProcessType( "Volume", "S16", &doit<int16_t> );
  registerProcessType( "Volume", "U16", &doit<uint16_t> );
  registerProcessType( "Volume", "S32", &doit<int32_t> );
  registerProcessType( "Volume", "U32", &doit<uint32_t> );
  registerProcessType( "Volume", "FLOAT", &doit<float> );
  registerProcessType( "Volume", "DOUBLE", &doit<double> );
  registerProcessType( "Volume", "RGB", &doit<int16_t> );
  registerProcessType( "Volume", "RGBA", &doit<int16_t> );



Process' execute function is given below :

bool Process::execute( const string & filename )
{
  Finder	f;
  if( !f.check( filename ) )
    {
      f.launchException();
      throw format_error( filename );
      return( false );
    }
  return( execute( f, filename ) );
}


bool Process::execute( Finder & f, const string & filename )
{
  string	otype = f.objectType();
  string	dtype = f.dataType();

  map<string, map<string, ProcFunc> >::const_iterator	
    ip = _execs.find( otype );
  if( ip == _execs.end() )
    {
      throw datatype_format_error( string( "unsupported data type " ) 
					  + otype + " / " + dtype, filename );
      return( false );
    }
  map<string, ProcFunc>::const_iterator  ip2 = (*ip).second.find( dtype );
  if( ip2 == (*ip).second.end() )
    {
      // Try alternate data types
      vector<string>	posstypes = f.possibleDataTypes();
      unsigned		i, n = posstypes.size();

      for( i=0; i<n; ++i )
	if( posstypes[i] != dtype )
	  {
	    ip2 = (*ip).second.find( posstypes[i] );
	    if( ip2 != (*ip).second.end() )
	      {
		// force new datatype into finder
		f.setDataType( posstypes[i] );
		break;
	      }
	  }
      if( i == n )
	{
	  throw datatype_format_error( string( "unsupported data type " ) 
				       + otype + " / " + dtype, filename );
	  return( false );
	}
    }

  //	execute process function
  return( (*ip2).second( *this, filename, f ) );
}

I know I haven't given all usefull code snippets but I'm guessing the 
problem is that the choice of which function to execute (here, "doit"), 
is only known at execution time ("function pointers").
So is there anyway to tell gdb that I don't wan't a breakpoint relative 
to a linenumber in a source file or a simple function name but to the 
instance of the right function, or maybe to use brutal memory 
addresses.... anyway something to avoid stepping into the code 50000 times.
Any ideas?

Thanks,
If you need more info/I have missed some rules please don't hesitate to ask,
Anton Moukharski



More information about the Gdb mailing list