Don't know if anyone is still working on this problem (i.e. corrupt
stack on arm in gdb), but I've found a solution.  Any code that is
compiled with -g seems to work fine with gdb, as far as generating a
backtrace.  The problem is that most system library code is built
without -g, so gdb doesn't have whatever information is necessary to
unwind the stack properly.

It seems that gcc, with the -g option, adds .cfi directives into the
assembler code, and gdb needs that info.  Remove the .cfi directives and
you get the "Backtrace stopped: previous frame identical to this frame
(corrupt stack?)" error.

Even a very simple program with subroutine calls (similar to below) will
exhibit this problem:

void foo(int i)
{
    if (i < 100) foo(i+1);
    printf("i=%d\n", i);
}

main()
{
    foo(0);
}

When compiled without -g each time the program calls foo the stack looks
to gdb like it's corrupted, and only the topmost level is shown, along
with the error.  Compile with -g and everything works, at least until
you step into printf, which wasn't compiled with -g.

Once you step out of printf you'll get your stack back.

This feels like a compiler bug to me, i.e. gcc __SHOULD__ generate at
least the minimal set of .cfi directives that are needed for gdb to
generate a backtrace, regardless of whether -g is specified or not.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1325503

Title:
  gdb reports 'corrupt stack' on armhf without symbols

To manage notifications about this bug go to:
https://bugs.launchpad.net/gdb-linaro/+bug/1325503/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to