1

when gcc/g++ encounters an ICE (internal compiler error), then recent versions of the compiler will print a neat stack trace before exiting.

Questions: What technology is used to implement that? GCC is written in C++, afaik some conservative revision like C++03.

Does it require exceptions, signals or even interpretation of debug-info? Is there host/OS dependence?

Playing around with own C/C++ code, all I found is __builtin_return_address which allows to print code address that can be used to display locations by piping them through an external tool like addr2line...

Note:

Unfortunately, this question has been prematurely closed... In particular, the linked thread does not address the following points:

  • GCC does not use Boost.

  • GCC does not use external libraries like linunwind or libexcept to all of my knowledge.

  • GCC does not necessarily use glibc. For example I can cross-compile GCC on linux for host mingw32, and stack traces work just fine.

2
  • If I'm not using a debugger (gdb, lldb) which provides a backtrace facility, you can programmatically view the stacktrace with Boost Stacktrace.
    – Eljay
    Commented May 7, 2020 at 16:39
  • "GCC does not use external libraries like libunwind" - I am not sure, but googling and gcc source code reveals the opposite: gcc uses libunwind. E.g. gcc contains libbacktrace library, which seems to be used for printing gcc backtraces (you may find "libbacktrace could not find executable to open" message on some compiler internal errors). And libbacktrace/nounwind.c has following message: "no stack trace because unwind library not available". From my understanding this means that gcc uses libunwind for print traces.
    – Tsyvarev
    Commented May 9, 2020 at 11:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.