ataraxes
Posts: 4
Joined: Sun Nov 10, 2013 3:59 pm

gdb stack trace unavailable [obsolete info]

Sun Nov 10, 2013 4:22 pm

This is probably very simple, but I'm stumped.
On my brand-new Raspbian Pi I just wrote a version of hello, world in ANSI C that has two printf() lines and an abort() between them:
int main (int argc, char ** argv)
{
printf("Hello world.\n");
abort();
printf("Goodbye world.\n");
}
This compiled using gcc with -Wall and -g flags. I don't recall if it whined about no return value, but that (shouldn't?) matter.

Running it under gdb it gets to the crash and dies correctly, but then when I try to backtrace the stack gdb tells me it thinks the stack is corrupt and it cannot help me. I see similar problems with backtracing when I crash other programs (though I have not yet tried a willful segfault).

This strikes me as either an issue with (1) the library whence I got abort() isn't armigerous, (2) something different about stack management (I mostly use Mac and Ubuntu and RedHat, on none of which have I seen this kind of thing), or (3) something not quite right in gdb. Or (4) maybe it's normal.

Can somebody offer me words of wisdom?

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: gdb stack trace unavailable

Sun Nov 10, 2013 9:08 pm

It works for me! Perhaps something is corrupt on your system?

Using code:

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int main (int argc, char ** argv)
{
    printf("Hello world.\n");
    abort();
    printf("Goodbye world.\n");
}
compiling with

Code: Select all

gcc -Wall -g crash.c -o crash
then when I run it

Code: Select all

./crash 
Hello world.
Abort (core dumped)
Exit 134
And gdb

Code: Select all

gdb crash core 
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 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 "arm-linux-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/andrew/investigations/crash...done.
[New LWP 2895]
Core was generated by `./crash'.
Program terminated with signal 6, Aborted.
#0  0xb6e36bfc in __GI_raise (sig=6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:67
67      ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) where
#0  0xb6e36bfc in __GI_raise (sig=6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:67
#1  0xb6e3a97c in __GI_abort () at abort.c:92
#2  0x000083e8 in main (argc=1, argv=0xbea66bf4) at crash.c:7
(gdb) backtrace 
#0  0xb6e36bfc in __GI_raise (sig=6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:67
#1  0xb6e3a97c in __GI_abort () at abort.c:92
#2  0x000083e8 in main (argc=1, argv=0xbea66bf4) at crash.c:7

User avatar
joan
Posts: 14374
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: gdb stack trace unavailable

Sun Nov 10, 2013 10:15 pm

I think the OP is complaining about the

Code: Select all

#0  0xb6ec0bfc in raise () from /lib/arm-linux-gnueabihf/libc.so.6
#1  0xb6ec497c in abort () from /lib/arm-linux-gnueabihf/libc.so.6
#2  0x00008256 in ?? ()
#3  0x00008256 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) 
message from gdb.

The OP doesn't seem to be getting a core dump. That doesn't seem to be the issue (presumably the OP's core dump max size is 0).

ataraxes
Posts: 4
Joined: Sun Nov 10, 2013 3:59 pm

Re: gdb stack trace unavailable

Sun Nov 10, 2013 10:27 pm

Thanks all, yes, I am in fact stumped at this output.
#0 0xb6ec0bfc in raise () from /lib/arm-linux-gnueabihf/libc.so.6
#1 0xb6ec497c in abort () from /lib/arm-linux-gnueabihf/libc.so.6
#2 0x00008256 in ?? ()
#3 0x00008256 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)

I will try to dump a core file (you are right about the coredumpsize 0), but why would that affect gdb running in the foreground with hello as its sub-process? Nothing like this happens on Mac or my other linux boxes. Is this a known issue?

User avatar
joan
Posts: 14374
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: gdb stack trace unavailable

Sun Nov 10, 2013 10:31 pm

I get the same result as you. I don't know enough about gdb to say if it's a problem or not.

ataraxes
Posts: 4
Joined: Sun Nov 10, 2013 3:59 pm

Re: gdb stack trace unavailable

Sun Nov 10, 2013 11:03 pm

Aaugh! I get the same corrupt-stack message when I "gdb hello core" per AndyD.

Might it be the case that I am using a dynamic library that is somehow not debuggable? What I've got is absolutely vanilla raspbian from a brand-new NOOBS chip.

Hmm, after a little messing around it appears that abort() is the problem. If I use kill(getpid(), SIGILL) gdb reports the stack correctly. But then why AndyD's uneventful adventure? I am still stumped but care a lot less now that I've got a workaround.

Thank you everybody!

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: gdb stack trace unavailable

Sun Nov 10, 2013 11:14 pm

joan wrote:I think the OP is complaining about the

Code: Select all

#0  0xb6ec0bfc in raise () from /lib/arm-linux-gnueabihf/libc.so.6
#1  0xb6ec497c in abort () from /lib/arm-linux-gnueabihf/libc.so.6
#2  0x00008256 in ?? ()
#3  0x00008256 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) 
message from gdb.

The OP doesn't seem to be getting a core dump. That doesn't seem to be the issue (presumably the OP's core dump max size is 0).
Yes, I understand. I was trying to reproduce the issue, but was unable to reproduce it.
joan wrote:I get the same result as you. I don't know enough about gdb to say if it's a problem or not.
That is interesting. The only way I can reproduce the behavior is by stripping the executable (using the strip command) before I run it through gdb. I am using Raspbian with latest firmware/kernel updated about an hour ago. I wonder if that would make a difference?

OK. I have another Raspberry Pi that is running as a webserver. I just tried the same on it and got the same result as the OP. So I would suggest that you make sure everything is up to date.
Last edited by AndyD on Sun Nov 10, 2013 11:31 pm, edited 1 time in total.

User avatar
joan
Posts: 14374
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: gdb stack trace unavailable

Sun Nov 10, 2013 11:21 pm

Packages updated and rpi-update run earlier today.

Code: Select all

hard ~ $ cat b.c
#include <stdio.h>
#include <stdlib.h>

int nested (int argc, char ** argv)
{
   printf("Hello world.\n");
   abort();
   printf("Goodbye world.\n");
}

int main(int argc, char *argv[])
{
   nested(argc, argv);
}

hard ~ $ gcc -Wall -g b.c
b.c: In function ‘main’:
b.c:14:1: warning: control reaches end of non-void function [-Wreturn-type]
hard ~ $ gdb a.out
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 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 "arm-linux-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/joan/a.out...done.
(gdb) r
Starting program: /home/joan/a.out 
Hello world.

Program received signal SIGABRT, Aborted.
0xb6ec0bfc in raise () from /lib/arm-linux-gnueabihf/libc.so.6
(gdb) bt
#0  0xb6ec0bfc in raise () from /lib/arm-linux-gnueabihf/libc.so.6
#1  0xb6ec497c in abort () from /lib/arm-linux-gnueabihf/libc.so.6
#2  0x00008256 in ?? ()
#3  0x00008256 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) 

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: gdb stack trace unavailable

Sun Nov 10, 2013 11:33 pm

joan wrote:Packages updated and rpi-update run earlier today...
I am just updating my webserver now. If there is no change I will try and work out what is different on my other Raspberry Pi.

Edit: OK now my webserver is up to date and yes I still see the behavior as described in the original post. I will try to work what is different on my other Raspberry Pi.

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: gdb stack trace unavailable

Sun Nov 10, 2013 11:58 pm

OK I think I have worked it out. If you install the libc6-dbg package you can see the stack in gdb.

Code: Select all

sudo apt-get install libc6-dbg

ataraxes
Posts: 4
Joined: Sun Nov 10, 2013 3:59 pm

Re: gdb stack trace unavailable

Mon Nov 11, 2013 12:44 am

Kudos. libc6-dbg indeed fixes the problem.

Case closed. I can see I need to read up on apt packages. Thank you.

Return to “C/C++”