Author Topic: Debug a shared library  (Read 8576 times)

Offline ifeelfree

  • Single posting newcomer
  • *
  • Posts: 8
Debug a shared library
« on: July 30, 2013, 03:19:24 pm »
I have a question related to debugging a shared library with codeblocks in Ubuntu. I have no problem when I run a C++ program with a shared library. The main problem, however, is that when I debug the program, I cannot go into the source codes of the shared library. The source codes of the shared library is provided, and I build the shared library first before I build the program. I guess that I need to set some parameters for the program's codeblocks project before running the debugging, but I have no idea where I should do the setting. Many thanks.

Some additional information is as follows:
1. My project structure is something like that:

(1)./program the running application program that will invoke run_test.so

(2) run_test.so the test dynamic library that will invoke basic_library.so

(3) basic_library.so the library called by run_test.so

When I debug ./program project I can go into the source codes of run_test.so , but when I want to step into the functions coming from basic_library.so in the source code of run_test.so, I have problems. It just ignore the step into command.

2. The version of the codeblock is 12.11, and I am running it in Ubuntu.

3. The compile I have chosen is GCC 4.6.

4. The codeblock project is created by CMake scripts.
« Last Edit: July 30, 2013, 03:21:21 pm by ifeelfree »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debug a shared library
« Reply #1 on: July 30, 2013, 03:44:00 pm »
Make sure that basic_library.so has been built with debugging symbols (-g option) and no stripping (no -s option or explicit strip command).
You case is no special, so if you can debug one lib you can debug the other if there are symbols. If there are no symbols you can't.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ifeelfree

  • Single posting newcomer
  • *
  • Posts: 8
Re: Debug a shared library
« Reply #2 on: July 30, 2013, 03:51:02 pm »
Thanks for the comments. basic_library.so and run_test.so are compiled with the same compilation options as both libraries are created by CMake script. In the run_test.so project, I can go to the functions of basic_library.so very easily by using the "Find the implementation of ' ' " operation. However, when I debug, I just cannot step into these functions.

Make sure that basic_library.so has been built with debugging symbols (-g option) and no stripping (no -s option or explicit strip command).
You case is no special, so if you can debug one lib you can debug the other if there are symbols. If there are no symbols you can't.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debug a shared library
« Reply #3 on: July 30, 2013, 04:09:18 pm »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ifeelfree

  • Single posting newcomer
  • *
  • Posts: 8
Re: Debug a shared library
« Reply #4 on: July 30, 2013, 04:32:54 pm »
I have read the documents you have suggested, but still I cannot figure it out. Thanks anyway.

Find implementation has nothing to do with the debugger!

Start reading here: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29
And here: http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Debug a shared library
« Reply #5 on: July 30, 2013, 04:36:29 pm »
you have to check if your library is build with the -g compiler switch... i don't know if your CMake skript allows adding compiler options, but if so, add -g and try again...

greetins

Offline ifeelfree

  • Single posting newcomer
  • *
  • Posts: 8
Re: Debug a shared library
« Reply #6 on: July 30, 2013, 04:50:19 pm »
Thanks, I have double-checked. Some build log messages are as follows:
[ 89%] Building CXX object src/abc/CMakeFiles/abcimp.dir/__/ImageProc/abc.cpp.o
cd /home/aaa/Desktop/branch/aaa_branch/build/src/test && /usr/bin/c++   -Dtest_EXPORTS -DVERBOSE -fPIC -fvisibility=hidden -g -std=c++0x -g -fPIC -     -o CMakeFiles/abcimp.dir/__/ImageProc/abc.cpp.o -c /home/aaa/Desktop/branch/irisimp_branch/src/ImageProc/abc.pp
/usr/bin/cmake -E cmake_progress_report /home/aaa/Desktop/branch/aaa_branch/build/CMakeFiles

As you can see, I use two '-g' this time in order to make sure that I am using the right compilation option.

you have to check if your library is build with the -g compiler switch... i don't know if your CMake skript allows adding compiler options, but if so, add -g and try again...

greetins
« Last Edit: July 30, 2013, 04:54:30 pm by ifeelfree »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debug a shared library
« Reply #7 on: July 30, 2013, 05:08:54 pm »
Try debugging this project with command line gdb, if it works there it is a problem with C::B.
If it doesn't (which will be the case), you have two options:
1. inspecting you build to ensure the proper thing is built in the proper place with the proper options.
2. report the problem to the provider of your gdb
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ifeelfree

  • Single posting newcomer
  • *
  • Posts: 8
Re: Debug a shared library
« Reply #8 on: July 31, 2013, 01:08:30 pm »
After a careful examination, I found the reason why I cannot debug the shared library, in CMAKE scrip I have the following code:
set_target_properties(basic_library PROPERTIES LINK_FLAGS "-W1 --strip-all".

After I remove --strip-all, I can debug now.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debug a shared library
« Reply #9 on: July 31, 2013, 01:16:59 pm »
 ;D
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]