I have an executable that loads a shared library with dlmopen
.
Here is the main.cpp:
int main(int argc, char* argv[]) {
void* h=dlmopen(LM_ID_NEWLM,"libA.so", RTLD_LOCAL | RTLD_NOW);
if(h != 0) {
void (*pPrint)() = (void (*)())dlsym(h, "printA");
if (pPrint != 0)
pPrint();
else
std::cerr << "Did not find function\n";
} else {
std::cerr << "Cannot load shared library\n";
return 100;
}
return 0;
}
And here is A.cpp
producing the library:
extern "C" void printA() {
std::cout << "Hello world!\n";
return;
}
I compiled this code with g++ 6.3.1.
If you try to follow the execution of that code with GDB (I tried with 8.1.0) or DBX, you will notice that you cannot dive into printA()
. Researching the web for ways of debugging this piece of code, I found comments here and there that this is expected. It seems some people did some work some time ago (around 2011) to get this to work, but this is not obvious to me how far they went.
Apart from print statements, which is not really an option on my real case, does anyone see a debugging strategy I could follow?