Skip to content

Commit 5687f5c

Browse files
committed
Make a failure to obtain relevant crash backtrace obvious
1 parent d6eaea1 commit 5687f5c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

library/Crashlog.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ std::filesystem::path get_crashlog_path() {
111111

112112
void dfhack_save_crashlog() {
113113
char** backtrace_strings = backtrace_symbols(crash_info.backtrace, crash_info.backtrace_entries);
114-
if (!backtrace_strings) {
115-
// Allocation failed, give up
116-
return;
117-
}
118114
try {
119115
std::filesystem::path crashlog_path = get_crashlog_path();
120116
std::ofstream crashlog(crashlog_path);
@@ -128,9 +124,14 @@ void dfhack_save_crashlog() {
128124
crashlog << "Signal " << signal << "\n";
129125
}
130126

131-
// Skip the first backtrace entry as it will always be dfhack_crashlog_handle_(signal|terminate)
132-
for (int i = 1; i < crash_info.backtrace_entries; i++) {
133-
crashlog << i - 1 << "> " << backtrace_strings[i] << "\n";
127+
if (crash_info.backtrace_entries >= 2 && backtrace_strings != nullptr) {
128+
// Skip the first backtrace entry as it will always be dfhack_crashlog_handle_(signal|terminate)
129+
for (int i = 1; i < crash_info.backtrace_entries; i++) {
130+
crashlog << i - 1 << "> " << backtrace_strings[i] << "\n";
131+
}
132+
} else {
133+
// Make it clear if no relevant backtrace was able to be obtained
134+
crashlog << "Failed to obtain relevant backtrace\n";
134135
}
135136
} catch (...) {}
136137

0 commit comments

Comments
 (0)