Remote debug shared library (.so) problem

已回答

Hello!

I can not remotely debug the .so library.The situation is as follows.
The executable is built without debugging symbols. It starts (dlopen + dlsym + call) an external library that needs to be debugged. It is built with debugging symbols.

On the remote system I call the executable, get the process PID and execute

gdbserver --attach: 8080 <pid>

On the host system, I connect from the Clion GBD Remote Debug to a remote GDB server. At the same time on the remote machine I get "Remote debugging from host ...", in the CLion Console "Debugger connected to tcp: ...: 8080".That's all. The breakpoints set before and after the connection do not work. After calling in the CLion Run->Pause Program, I get "Command timed out" in the CLion console and "Detaching from process ..." on the remote machine.

I tried to connect from gdb ("gdb <...>.so", then "set solib-search-path ...", then "target remote ...:8080") - debug works fine.

 Library code:

//callMe.cpp
extern "C" int callMe(){
volatile bool continueLoop{true};

while (continueLoop) {
}
return 1;
};

 Library build:

#CMakeLists.txt
...
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_library(callMe SHARED callMe.cpp)

 Executable code:

//main.cpp
...
int (*callMe)();
void *ext_library = dlopen(..., RTLD_LAZY);
auto callMeFn = reinterpret_cast<int (*)()>(dlsym(ext_library, "callMe"));
std::cout << callMeFn() << std::endl;

 Executable build:

g++ main.cpp -o caller -ldl


I hope for your advice :)

Best regards, Andrey.

0

Hello! I see that you've used "set solib-search-path ..." when you've tried to debug outside CLion. Have you used it when you've tried to debug in CLion? You can set solib-search-path in .gdbinit. By default the gdb in CLion uses default ~/.gdbinit so specifying it there should be enough.

1
Avatar
Permanently deleted user

This is solution to the problem. (As a result, I put the .gdbinit in the root of the project).

Thank you for your help!

0

I'm glad it helped! Also feel free to comment or upvote the related issue: https://youtrack.jetbrains.com/issue/CPP-8236.

0

请先登录再写评论。