Recursive SIGSEGV question
Jonathan Wakely
jwakely.gcc@gmail.com
Wed Mar 27 23:43:00 GMT 2019
On Wed, 27 Mar 2019 at 21:27, Jonny Grant wrote:
> Hi!
>
> Thank you for your reply and input.
>
> Maybe GCC's "libbacktrace" module could be used?
>
> I was wondering if -fsanitize=address would output a backtrace for the
> C++ exception, but it doesn't seem to. Also it actually prevents the
> core being dumped - that's probably not intended?
>
> Compile without Sanitizer, and it does dump the core to a file at least!
>
> $ export UBSAN_OPTIONS=print_stacktrace=1
This is a UBsan option.
> // g++-8 -fsanitize=address -Wall -o exception exception.cpp
But you're not using UBsan.
> #include <vector>
> int main()
> {
> std::vector<int> v;
> return v.at(0);
> }
>
>
> $ ./exception
> terminate called after throwing an instance of 'std::out_of_range'
> what(): vector::_M_range_check: __n (which is 0) >= this->size()
> (which is 0)
> Aborted
There's no undefined behaviour or memory corruption here, so it's not
surprising that UBsan and Asan don't print anything.
If you want a stack trace for exceptions that terminate the process
then you could install a custom terminate handler which does that.
Libstdc++'s default terminate handler just prints the message above,
which includes the type of the exception and if it's a type derived
from std::exception, the what() string stored in it.
More information about the Gcc-help
mailing list