Skip to content

Commit da3306a

Browse files
committed
If there's no assert message on crash, put signal into the noun
This includes the signal information in the crash milestone if there's no assert message; before, the milestone would just be empty (which I guess translates to "?"). It also will give the signal info on the first line of the crash dump in these circumstances so that any non-windows crash dump always has a cause on the first line.
1 parent 548d406 commit da3306a

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

crawl-ref/source/crash.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void init_crash_handler()
271271
#endif // if defined(USE_UNIX_SIGNALS)
272272
}
273273

274-
void dump_crash_info(FILE* file)
274+
string crash_signal_info()
275275
{
276276
#if defined(UNIX)
277277
#ifdef TARGET_OS_FREEBSD
@@ -288,9 +288,11 @@ void dump_crash_info(FILE* file)
288288

289289
if (name == nullptr)
290290
name = "INVALID";
291-
292-
fprintf(file, "Crash caused by signal #%d: %s\n\n", _crash_signal, name);
291+
return make_stringf("Crash caused by signal #%d: %s", _crash_signal, name);
292+
#else
293+
return "";
293294
#endif
295+
294296
}
295297

296298
#if defined(BACKTRACE_SUPPORTED)

crawl-ref/source/crash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <cstdio>
99

1010
void init_crash_handler();
11-
void dump_crash_info(FILE* file);
11+
string crash_signal_info();
1212
void write_stack_trace(FILE* file, int ignore_count);
1313
void call_gdb(FILE *file);
1414
void disable_other_crashes();

crawl-ref/source/dbg-asrt.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ void do_crash_dump()
601601

602602
_dump_ver_stuff(stderr);
603603

604-
dump_crash_info(stderr);
604+
fprintf(stderr, "%s\n\n", crash_signal_info().c_str());
605605
write_stack_trace(stderr, 0);
606606
call_gdb(stderr);
607607

@@ -623,8 +623,11 @@ void do_crash_dump()
623623
snprintf(name, sizeof(name), "%scrash-%s-%s.txt", dir.c_str(),
624624
you.your_name.c_str(), make_file_time(t).c_str());
625625

626-
if (!crawl_state.test && !_assert_msg.empty())
627-
fprintf(stderr, "\n%s", _assert_msg.c_str());
626+
const string signal_info = crash_signal_info();
627+
const string cause_msg = _assert_msg.empty() ? signal_info : _assert_msg;
628+
629+
if (!crawl_state.test && !cause_msg.empty())
630+
fprintf(stderr, "\n%s", cause_msg.c_str());
628631
// This message is parsed by the WebTiles server.
629632
fprintf(stderr,
630633
"\n\nWe crashed! This is likely due to a bug in Crawl. "
@@ -653,8 +656,8 @@ void do_crash_dump()
653656

654657
set_msg_dump_file(file);
655658

656-
if (!_assert_msg.empty())
657-
fprintf(file, "%s\n\n", _assert_msg.c_str());
659+
if (!cause_msg.empty())
660+
fprintf(file, "%s\n\n", cause_msg.c_str());
658661

659662
_dump_ver_stuff(file);
660663

@@ -665,7 +668,8 @@ void do_crash_dump()
665668
// First get the immediate cause of the crash and the stack trace,
666669
// since that's most important and later attempts to get more information
667670
// might themselves cause crashes.
668-
dump_crash_info(file);
671+
if (!signal_info.empty())
672+
fprintf(file, "%s\n\n", signal_info.c_str());
669673
write_stack_trace(file, 0);
670674
fprintf(file, "\n");
671675

@@ -750,7 +754,7 @@ void do_crash_dump()
750754

751755
set_msg_dump_file(nullptr);
752756

753-
mark_milestone("crash", _assert_msg, "", t);
757+
mark_milestone("crash", cause_msg, "", t);
754758

755759
if (file != stderr)
756760
fclose(file);

0 commit comments

Comments
 (0)