Debugging strategies for libraries open with dlmopen

南笙酒味 提交于 2020-01-15 06:10:35

问题


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?

来源:https://stackoverflow.com/questions/51592455/debugging-strategies-for-libraries-open-with-dlmopen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!