This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: why does assert(0) corrupt the stack trace?
- From: 慕冬亮 <mudongliangabcd at gmail dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- Cc: gdb at sourceware dot org
- Date: Sun, 5 Nov 2017 15:05:04 -0500
- Subject: Re: why does assert(0) corrupt the stack trace?
- Authentication-results: sourceware.org; auth=none
- References: <CAD-N9QVbDJNJXrnsS3PNTvRXvvUK=pB6f+Gpj4WGTSjMoYR9pg@mail.gmail.com> <20171105195410.GA29185@host1.jankratochvil.net>
--
My best regards to you.
No System Is Safe!
Dongliang Mu
2017-11-05 14:54 GMT-05:00 Jan Kratochvil <jan.kratochvil@redhat.com>:
> On Sun, 05 Nov 2017 20:13:20 +0100, 慕冬亮 wrote:
>> I have a question about debugging assert in gdb. When one program
>> crash at one assert statement, the stack trace shown in the gdb is
>> corrupted. Is it normal?
>
> It was happening in the past as when assert() detects a failure it calls
> abort() which does never return - using GCC attribute noreturn. Then GCC
> optimizer does not save enough registers to make the backtrace possible
> because the code will just abort anyway, the code does not need to know where
> to return.
>
If I compile the program with "-O0", this problem may be solved. Yes?
> It was some intermediate development phase where such optimization was created
> and before an exception has been made to make the backtracing by debuggers
> possible.
>
> Sorry for not looking up the Bugs/commits.
>
> As usual you should update your compiler + debugger to latest versions.
>
>
> Jan