gdb doesn't show segfault line, Wikipedia example does
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
gdb doesn't show segfault line, Wikipedia example does
I started to learn gdb today, and I came across a problem right away. Here https://en.wikipedia.org/wiki/Gdb#An_example_session gdb is shown to print the line, where the segfault happens, specifically "0x0000000000400527 in foo_len (s=0x0) at example.c:8". But when I do the same on my own computer, output is a bit different:
Code:
Starting program: /home/avg/c/debug
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7833ac1 in __strlen_sse2 () from /lib64/libc.so.6
Only when I type 'where', I see:
Code:
#0 0x00007ffff7833ac1 in __strlen_sse2 () from /lib64/libc.so.6
#1 0x00000000004005ab in foo_len (argc=<value optimized out>, argv=<value optimized out>)
at debug.c:8
#2 main (argc=<value optimized out>, argv=<value optimized out>) at debug.c:16
~/c $ gdb ./debug
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-slackware-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/avg/c/debug...done.
(gdb) run
Starting program: /home/avg/c/debug
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7ab8ac1 in __strlen_sse2 () from /lib64/libc.so.6
Could you check please what output do you get? Maybe it has something to do with x64.
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400527 in foo_len (s=0x0) at example.c:8
8 return strlen (s);
while my gdb shows this:
Code:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7ab8ac1 in __strlen_sse2 () from /lib64/libc.so.6
The last line is different. It would be nice if the particular line where segfault occurred was shown, as in Wikipedia example, instead of '0x00007ffff7ab8ac1 in __strlen_sse2 () from /lib64/libc.so.6'
So the segfault occurs in libc.so.6, your result is perfect, there is no problem with it. The confusion is coming from the fact that it is not your code, but an external library. In the example (what you linked) the same error occured, but the source code is displayed instead of __strlen_sse2() from libc. In general when you debug you need to know what was the last "known" line of code, that is the line: return strlen(s). At this moment I cannot tell you how they produced that result (what was the trick to skip libc), but you can use the command "where" to see similar result.
I see. I am very curious how they did it at Wikipedia. I hope somebody will put on the right track here. If not, I will may ask at gdb discusion group or even directly at Wikipedia, because I cannot get along with this.
Yes but you didn't exactly explain what I need to do to have the same result as at Wikipedia. I will try to install glibc-debug, but it says "To use these libraries, set LD_LIBRARY_PATH when calling the debugger: LD_LIBRARY_PATH=/usr/lib/debug gdb <executable>" in the package description. I didn't see it done at Wikipedia.
You're getting into a *deep* rabbit-hole if you're wanting to bring in the debug info for glibc. That's what people who work on glibc itself do, not us mere mortals. Just accept that wikipedia isn't always 100% correct about every single detail and go work on getting learning stuff that's.. a bit more practical.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.