?
Solved

How to debug shared objects?

Posted on 2005-03-03
13
Medium Priority
?
616 Views
Last Modified: 2010-04-22
Hello,
I just started using gdb and am having trouble debugging with shared
objects. If I do a 'bt' and gdb shows the following,
--------
......
(gdb) bt
Program received signal SIGINT, Interrupt.
[Switching to Thread 1087287744 (LWP 24850)]
0xffffe410 in ?? ()
Current language:  auto; currently c
(gdb) bt
#0  0xffffe410 in ?? ()
#1  0xbffff47c in ?? ()
#2  0xffffffff in ?? ()
#3  0x00000001 in ?? ()
#4  0x40a02e94 in poll () from /lib/tls/libc.so.6
#5  0x40a329c5 in svc_run () from /lib/tls/libc.so.6
#6  0x08053d79 in core_server () at sxmrpc_svc.cpp:452
#7  0x0804e3d2 in main (argc=1, argv=0xbffff734) at main.cpp:159
(gdb)
--------
I can do a 'frame 4', and then what should I do in order to step into
the source code of libc.so.6 to see which line the app was at in
poll()?
Thanks for any help.
0
Comment
Question by:minjiezen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
13 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13452733
step
0
 

Author Comment

by:minjiezen
ID: 13452854
I did that but I got the following error:
----------
Cannot find bounds of current function
----------
I also did a 'list' (after I did a 'frame 4') and it lists the lines around main.cpp line 159, which is in frame 7. Looks like gdb cannot see the source code for the shared library. How do I make gdb see the source code of a shared library?

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13452919
path /path/to/source/


help
help files
:-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:minjiezen
ID: 13455149
It still does not work. I made up a hang situation in a shared library (say, mylib.so) of my own as follows (note: mylib.so was built from several source files in C++):
    {
        int i = 1;
        for (i=0; i < 1000000000; i++)
            usleep(1000*1000);
     }
And I ran the application as follows:
gdb myapp
The app hung when it reached the above code (because of the loop). So I do the following:
(gdb) Ctrl-c  (my input, to go back to the gdb prompt)
Program received signal SIGINT, Interrupt.
[Switching to Thread 1087287744 (LWP 5077)]
0xffffe410 in ?? ()
Current language:  auto; currently c
(gdb) bt   (my input)
#0  0xffffe410 in ?? ()
#1  0xbffff2c8 in ?? ()
#2  0x40d8ee0c in __JCR_LIST__ () from /usr/lib/mylib.so
(gdb)
It does not show in which file and in which line the application is hung. I set up the source path for the file that has that loop implemented, but gdb cannot find it. The purpose of this test is to try to mimic the real situation where the application is hung and I need to find out in which file and in which line the application got into trouble.
Any info will be greatly appreciated.
 
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13456870
> It does not show in which file and in which line the application is hung.
then gdb is not configured proper with path to the source
see man gdb, or info gdb how to use path command
0
 

Author Comment

by:minjiezen
ID: 13461054
I tried to set path in gdb as follows:
path /path/to/source
and
directory /directory/to/souce
But neither worked. And these two are the only commands to set directory or path in gdb, according to the gdb documents. I also tried 'info line *address', etc., but gdb just couldn't figure out which line and program it was at.
Is there another way to get gdb prompt once the program hangs? Looks like gdb has all the info about the source code (yes, it could see the file that contained the almost-infinite loop implementation), UNTIL I used Ctrl-c command to go to the gdb prompt. It's as if Ctrl-c erased all gdb's rememberance of the application it had before.
0
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 400 total points
ID: 13464797
You can set breakpoints in shared libraries. Does your gdb let you set a breakpoint on the usleep line? (Of course, the code must have been compiled with -g and not subsequently stripped).
As for seeing source lines in glibc - unless gdb complains that it can't find the source files, your library was not built with -g. Build it from the SRPM with -g turned on (man rpmbuild).
If you have trouble setting a breakpoint inside your own shared lib, we should attack that problem first.
0
 

Author Comment

by:minjiezen
ID: 13476884
Hello duncan roe, thanks for your reply. Yes, I can set up a breakpoint in my shared library (on the usleep line), in which case GDB tells me the source info (file name and line number). The problem is that in the real situation, when our application hangs, I would not know where (in which file) it is hung because that shared library is built from quite a few .cpp and .h files, so there is no way for me to set a breakpoint beforehand because I don't know where the problem is. I would like to get the source info after the application has hung, but that's when GDB does not give me any source info except the shared library name (after I use Ctrl-c to get the GDB prompt again).
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 13484546
I can't imagine what is going wrong here. I'bve never had that sort of trouble with gdb myself.
Anyway, there is another way. Gdb your program, set a breakpoint at main. 'n'ext through the mainline until you get to the line that hangs ('n' doesn't comeback with a pronmpt).
Gdb the program again, but this time breakpoint at the "hanging" line. When you get there, do a 's'tep. Then 'n'ext through the called function until you get to the hanging line of *that* function.
Gdb the program again, but this time breakpoint at the "hanging" line you just found. And so on...
Sounds tedious but should get you there fairly quickly. You can use 'u'ntil to get you past loops that don't seem to be the priblem. Good Luck...
0
 

Expert Comment

by:rahul_milo
ID: 13518641
One suggestion:
Try compiling whole of your code with -ggdb option...
It adds extra information in object code during compilation.
And then try to debug.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question