I'm looking for someone who has some experience using gdb (or another
linux de*) to debug .so code.
My application loads "plug-in" .so files at run-time using dlopen(...).
The libraries load and execute as they should, but I can't seem to
convince kdbg (or gdb, for that matter) to let me step through the
source code of the loaded module. I've even gone so far as creating a
bare bones test case where the executable and library are each build
from cpp files in the same directory, but gdb doesn't recognize the
library's cpp file.
I've included more details below. Any ideas or helpful links would be
rather, well, er, helpful.
thanks,
Lee Jenkins
Corporate Diagnostic Software
Compaq Computer Corporation
I've reduced this problem to such a simple example that either I must be
missing some crucial but perhaps badly documented option, or else gdb
does not support the type of operation I desire. The code is very short,
and both files are located (and both targets built) in the same
directory:
------------------------------ [ testso.cpp ]
------------------------------
extern "C"
{
int soAdd( int a, int b )
{
return( a + b );
}
------------------------------ [ tsx.cpp ]Quote:}
------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
extern "C"
{
typedef int (*intmathsofun)( int a, int b );
intmathsofun Add;
int main( int argc, char* argv[] )Quote:}
{
char* soname = "./testso.so";
void* tso = dlopen( soname, RTLD_LAZY );
if( tso == NULL )
printf( "unable to open %s.\n", soname );
else
{
if( (Add=(intmathsofun)dlsym( tso, "soAdd" )) == NULL )
printf( "unable to get function address for soAdd().\n" );
else
{
int a = 7, b = 2;
int s = Add( a, b );
printf( "a: %d b: %d a + b: %d\n", a, b, s );
}
dlclose( tso );
}
return( 0 );
------------------------------ [ EOF ] ------------------------------Quote:}
Compiling the above code (with -g for debug) and loading it into gdb, I
have observed the following:
1st Run
* start the debug session and set a breakpoint at line 23 of tsx.cpp
(the call to the Add ( ) function)
* I run the program, and it stops at line 23.
* if I try to step into the function call, gdb tells me that the
execution point is in eval.c, which it cannot find.
* I tell gdb to continue, and the program runs correctly and exits.
2nd Run
* this time I try a more direct route, and gdb happily accepts a
breakpoint in testso.cpp (at the return statement) with this command:
break testso.cpp:5
* if I run the program with the above breakpoint, gdb runs, then claims
to stop in function soAdd ( ), but (again) in a file named eval.c, which
it cannot find.
* the disassemble command shows that gdb really did stop in the middle
of the soAdd ( ) function. however, the list command doesn't seem to
know which source code file it should use. it's looking for eval.c here,
too.
On the other hand, if I add testso.so to the link command for creating
tsx and change the Add= statement to assign directly from the
"statically" linked testso.so, gdb will step into the soAdd ( ) function
with no problem (and no recompile required for testso.so).
The problem is obviously with how (or if) gdb recognizes source code
files for .so files loaded using the dlopen ( ) function.
I would sincerely appreciate any insight from someone who can tell me
"no, gdb can't do that", or, "yes, gdb can, but first..."