2

I compiled a dynamic lib named libsuperdmgr.so. When I debug this lib using gdb, it cannot link to the source file. Like the following: In frame 3 and 4 it can show the detailed line of source file, but when it come to my lib in frame 2 and frame 1, it does not show the detailed line number.

#0  std::operator<< <char, std::char_traits<char>, std::allocator<char> > (__os=..., __str=...)
at /root/gcc/gcc-4.5.1/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/basic_string.h:2605
#1  0x00007fffc9ba67db in DmgrWrapper::AddDataStorage(NIODataStorage*, int) () from /home/shawu/infra/wqsim/arch/x86_64_Linux/wqsim_shawu/infra/libsuperdmgr.so
#2  0x00007fffc9ba6eb0 in NIODataStorageTester::Initialize(int, char const*, WQSim_Config::Element const*) ()
from /home/shawu/infra/wqsim/arch/x86_64_Linux/wqsim_shawu/infra/libsuperdmgr.so
#3  0x00007ffff543f527 in WQSim_DataRegistry::Handle (this=<value optimized out>, handle=<value optimized out>, cfg=<value optimized out>)
at wqsim/framework/WQSim_dataregistry.cc:618
#4  0x00007ffff588eea1 in WQSim_ModuleHandler::LoadModules (this=<value optimized out>) at wqsim/framework/WQSim_modulehandler.cc:125
#5  0x00007ffff7593586 in wqsim_main_init (argc=<value optimized out>, argv=<value optimized out>) at wqsim/modules/WQSim_main.cc:1016

Why is this??? Do I lost something in compile?

1 Answer 1

2

The most probable reason is... Was the shared library compiled/linked with debugging support? if not, you don't have the pointers in the binary code to the source points in the library, so gdb(1) cannot follow them and cannot show you where in the source code you are. Also, are the library sources available (if not, it will be difficult to access the source ---i know this assertion is ridiculous, but who knows :))o

If you can, use -g option recompiling the shared object library and link it also with that option to conserve the debug info in the final shared object.

Gdb(1) has commands to indicate where in the filesystem to locate module info, but if you don't have the pointers in the binary to locate the source code points you cannot access it.

Suppose you have a program made of two files: a.c and b.c

a.c has the main() function and is going to be a normal application module. b.c is going to be a shared library.

To compile your application you compile a.c normally (with debug info generation):

cc -g -c a.c -o a.o

To compile b.c as a shared object you use:

cc -fPIC -g -c b.c -o b.so

but this is not our final loadable shared object. We have only compiled it to an object file (sorry for the conflicting suffix) Now construct the shared object:

cc -g -o libb.so.1.1 -shared -Wl,-soname=b.so.1 b.so

see how I have included -g option in compiling b.c and linking b.so into libb.so.1.1.

Now, link the program with the following command line:

cc -o a.out -g a.o libb.so.1.1

and a.out will have the debug info received from a.o and b.so.1.1 (but you need to have it in b.so.1.1 if you want to be able to use it)

Note

I don't know at this moment if the debug info of b.so.1.1 is included into a.out in the linking phase of a.out or it must be gathered from the libb.so.1.1 at run time when gdb(1) accesses the shared library. The most probable thing if for it to have to be present in the library, as it is data belonging to the library (you can after program construction feed your program with a different implementation of the shared object and the debugging info will vary)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.