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.

emacs drives me nuts
  • 2,785
  • 13
  • 23
  • If I'm not using a debugger (gdb, lldb) which provides a backtrace facility, you can programmatically view the stacktrace with [Boost Stacktrace](https://www.boost.org/doc/libs/1_73_0/doc/html/stacktrace.html). – Eljay May 07 '20 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](https://github.com/gcc-mirror/gcc/blob/master/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 May 09 '20 at 11:30

0 Answers0