From: Duane Ellis <duane@duaneellis.com>
To: 慕冬亮 <mudongliangabcd@gmail.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>, gdb@sourceware.org
Subject: Re: why does assert(0) corrupt the stack trace?
Date: Sun, 05 Nov 2017 22:01:00 -0000 [thread overview]
Message-ID: <B2FB3353-1B27-4C2E-9DC7-CA6B5984AC84@duaneellis.com> (raw)
In-Reply-To: <CAD-N9QX17JssrU=Eo5whDFzLLQVUUb1RidHWwqzUC3ZFY6LGJw@mail.gmail.com>
> On Nov 5, 2017, at 12:05 PM, 慕冬亮 <mudongliangabcd@gmail.com> wrote:
>
> If I compile the program with "-O0", this problem may be solved. Yes?
Often with “-O0” (dash OH zero, turning the optimizer off) helps this is the most direct route to try to determine what went wrong.
However - it depends on what went wrong, for example if your application has a buffer overflow on the stack, and that buffer overflow corrupted the stack - or other memory was corrupted the stack back trace might as a result be corrupt
Or - the problem might change/move when you disable the optimizer the code changes, the number of registers allocated per function changes, etc ...
That said, the most direct and most common thing to do is to disable the optimizer and try again.
If you get desperate and the above does not help you might try unwinding the stack by hand - it takes a while and often you can do what the compiler & debugger cannot do.
This approach trys to understand where the application was, and what it was doing when the crash occurred - sometimes you can inspect memory at or near the stack, and manually unwind the stack by inspecting various values stored on the stack.
For example, on a 32bit machine - dump the stack memory near the stack pointer (ie: +/- 512 bytes) as 32bit values - then look at each value and see if they align with addresses within your application where subroutine calls occur. (Ie: Use “objdump -d MYAPP” to get a disassembly listing of your app)
It is painful but sometimes it is the only way.
-Duane.
prev parent reply other threads:[~2017-11-05 22:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-05 19:13 慕冬亮
2017-11-05 19:46 ` Paul Smith
2017-11-05 19:54 ` Jan Kratochvil
2017-11-05 20:05 ` 慕冬亮
2017-11-05 20:10 ` Jan Kratochvil
2017-11-05 22:01 ` Duane Ellis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=B2FB3353-1B27-4C2E-9DC7-CA6B5984AC84@duaneellis.com \
--to=duane@duaneellis.com \
--cc=gdb@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=mudongliangabcd@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox