-1

Recently, I want to add some breakpoints and debug some ROS libraries step by step to learn how these functions are called. These ROS libraries have been built from source.

However, I found that all the member functions of libraries are linked to .h files and I cannot see what's inside these functions and the breakpoint inside the member functions are useless.

Is there any way to add breakpoints inside a library member function and observe how the library member function is running?

KKKmelody
  • 31
  • 4
  • If you're able to debug your source code, you should also be able to debug included header files. Can you elaborate? – jabaa Jul 15 '23 at 01:59
  • Hi! @jabaa, I include some libraries which are installed by command order and not created by me. The member functions of these libraries can be checked with Ctrl + left click and jump into header files, e.g., /opt/ros/noetic/include/moveit/move_group_interface/move_group_interface.h. It seems that I cannot find the source code and add breakpoints inside these functions. – KKKmelody Jul 15 '23 at 02:45
  • If you don't have the source code, you can't see it while you debug your program. You can try to install the source code and the debug versions of the libraries. I can only guess without a [mcve]. – jabaa Jul 15 '23 at 12:27
  • Thanks, I will try to install the library from source. – KKKmelody Jul 17 '23 at 01:42
  • If you mean to build it from source, remember to build it as debug build with debug symbols. What I meant was to install the source code and the compiled debug binaries. – jabaa Jul 17 '23 at 02:48
  • After your last edit: First, you have to get the source files. Many packages have an additional `packagename-src` package for the source files. Sometimes these packages are in source repositories. Then, you have to link these source files to the executable in the debugger. Here is a link for GDB: https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_48.html. It should be obvious, that you can't enter the source file, if you don't have the source file or the debugger doesn't know where the source file is. `*.so` files don't contain source code. – jabaa Jul 28 '23 at 14:21
  • @jabba Thanks for your patience. Currently, I'm just debugging through IDE and am not too familiar with the gdb operation. According to your description, if I want to add valid breakpoints in the source files of the library, I have to add all these source files in add_executable() in CMakeList.txt? – KKKmelody Jul 29 '23 at 02:14
  • No, you have to configure your debugger and add the source files there. Most IDEs use an external debugger, e.g. gdb. – jabaa Jul 29 '23 at 11:53
  • Taking VS Code as an example, could you give an hint about how to set launch.json in order to make breakpoints inside dynamic library member functions valid? I've got configuration in launch.json pointing to the executable with settings of set(CMAKE_BUILD_TYPE Debug) and set (CMAKE_CXX_FLAGS " -g") in CMakeList, but the breakpoint is still useless. – KKKmelody Jul 31 '23 at 12:38
  • Do you use library files with debug symbols? – jabaa Jul 31 '23 at 12:59
  • Oh! You have given me a very important hint! Thanks for your patience and response, I have solved my problem. I have built the lib with debug symbol. – KKKmelody Jul 31 '23 at 14:15

1 Answers1

0

Following the instructions from @jabba, I built the current main.cpp and the third-party library with -DCMAKE_BUILD_TYPE=Debug, and the breakpoints worked.

KKKmelody
  • 31
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 03 '23 at 21:00