[flang-commits] [flang] [flang]Add new intrinsic function backtrace and complete the TODO of abort (PR #117603)
via flang-commits
flang-commits at lists.llvm.org
Tue Nov 26 09:11:03 PST 2024
================
@@ -152,11 +156,39 @@ void RTNAME(PauseStatementText)(const char *code, std::size_t length) {
std::exit(status);
}
+static void PrintBacktrace() {
+#ifdef __linux__
+ // 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)};
+ char **symbols{backtrace_symbols(buffer, nptrs)};
+
+ if (symbols == nullptr) {
+ Fortran::runtime::Terminator{}.Crash("no symbols");
+ std::exit(EXIT_FAILURE);
+ }
+
+ for (int i = 0; i < nptrs; i++) {
+ Fortran::runtime::Terminator{}.PrintCrashArgs("#%d %s\n", i, symbols[i]);
+ }
+
+ free(symbols);
+
+#else
+
+ // TODO: Windows platform implemention
+
+#endif
+}
+
[[noreturn]] void RTNAME(Abort)() {
- // TODO: Add backtrace call, unless with `-fno-backtrace`.
----------------
dty2 wrote:
Yes, I will try to implement it.
https://github.com/llvm/llvm-project/pull/117603
More information about the flang-commits
mailing list