[flang-commits] [flang] [flang]Add new intrinsic function backtrace and complete the TODO of abort (PR #117603)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Tue Nov 26 07:52:55 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`.
----------------
kparzysz wrote:
We still need a check for the `-fno-backtrace` option. That can be done in another PR. Will you be able to do that?
https://github.com/llvm/llvm-project/pull/117603
More information about the flang-commits
mailing list