[flang-commits] [flang] [flang]Add new intrinsic function backtrace and complete the TODO of abort (PR #117603)
Tarun Prabhu via flang-commits
flang-commits at lists.llvm.org
Tue Nov 26 16:12:05 PST 2024
================
@@ -152,11 +157,34 @@ void RTNAME(PauseStatementText)(const char *code, std::size_t length) {
std::exit(status);
}
+static void PrintBacktrace() {
+#ifdef HAVE_BACKTRACE
+ // TODO: Need to parse DWARF information to print function line numbers
+ constexpr int MAX_CALL_STACK{999};
+ void *buffer[MAX_CALL_STACK];
+ int nptrs{backtrace(buffer, MAX_CALL_STACK)};
+
+ if (char **symbols{backtrace_symbols(buffer, nptrs)}) {
+ for (int i = 0; i < nptrs; i++) {
+ Fortran::runtime::Terminator{}.PrintCrashArgs("#%d %s\n", i, symbols[i]);
+ }
+ free(symbols);
+ }
+
+#else
+
+ // TODO: Windows platform implementation
----------------
tarunprabhu wrote:
Is this comment still accurate? Should it instead say "Handle the case when a backtrace is not available", or something along those lines?
Does it makes sense to print a message saying that a backtrace was not available instead? It probably does not matter in the case of `abort`, but if the non-standard `backtrace` extension is used, it may be confusing if, it doesn't print anything on some platform".
https://github.com/llvm/llvm-project/pull/117603
More information about the flang-commits
mailing list