[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);
----------------
kparzysz wrote:
We shouldn't exit here, just not print any symbols and return from the function. You can just do
```
if (char **symbols{...}) {
for (...) {
print symbol[i]
}
free(symbols);
}
```
https://github.com/llvm/llvm-project/pull/117603
More information about the flang-commits
mailing list