diff options
author | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-01-18 06:09:54 +0000 |
---|---|---|
committer | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-01-18 06:09:54 +0000 |
commit | c4aac587234c1eebad7fb400de5486a5ac73cd38 (patch) | |
tree | 29584db5e66272a3e5a39e5fed95c94180f42ef9 /crawl-ref | |
parent | d95060f1e6fa1e397bc95ea43c239b3019e3fb2f (diff) | |
download | crawl-ref-c4aac587234c1eebad7fb400de5486a5ac73cd38.tar.gz crawl-ref-c4aac587234c1eebad7fb400de5486a5ac73cd38.zip |
When dumping info upon a crash:
* For Unix builds, shut down curses in case the crash reporter can't
open up a file and has to dump the crash directly to stderr.
* Include all saved messages in the crash report.
* Use EOL instead of \n or \r\n.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8535 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/debug.cc | 30 | ||||
-rw-r--r-- | crawl-ref/source/libunix.cc | 16 | ||||
-rw-r--r-- | crawl-ref/source/message.cc | 10 | ||||
-rw-r--r-- | crawl-ref/source/state.cc | 41 |
4 files changed, 60 insertions, 37 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc index 2e0572b70e..3dc09a671f 100644 --- a/crawl-ref/source/debug.cc +++ b/crawl-ref/source/debug.cc @@ -5519,12 +5519,12 @@ void do_crash_dump() if (file == NULL) { - fprintf(stderr, "\r\nUnable to open file '%s' for writing: %s\r\n", + fprintf(stderr, EOL "Unable to open file '%s' for writing: %s" EOL, name, strerror(errno)); file = stderr; } else - fprintf(stderr, "\r\nWriting crash info to %s\r\n", name); + fprintf(stderr, EOL "nWriting crash info to %s" EOL, name); set_msg_dump_file(file); @@ -5539,32 +5539,42 @@ void do_crash_dump() if (Generating_Level) { - fprintf(file, "\nCrashed while generating level.\r\n"); - fprintf(file, "your_level = %d, level_type = %d, type_name = %s\r\n", + fprintf(file, EOL "Crashed while generating level." EOL); + fprintf(file, "your_level = %d, level_type = %d, type_name = %s" EOL, you.your_level, you.level_type, you.level_type_name.c_str()); extern std::string dgn_Build_Method; extern bool river_level, lake_level, many_pools_level; - fprintf(file, "dgn_Build_Method = %s\r\n", dgn_Build_Method.c_str()); - fprintf(file, "dgn_Layout_Type = %s\r\n", dgn_Layout_Type.c_str()); + fprintf(file, "dgn_Build_Method = %s" EOL, dgn_Build_Method.c_str()); + fprintf(file, "dgn_Layout_Type = %s" EOL, dgn_Layout_Type.c_str()); extern bool river_level, lake_level, many_pools_level; if (river_level) - fprintf(file, "river level\r\n"); + fprintf(file, "river level" EOL); if (lake_level) - fprintf(file, "lake level\r\n"); + fprintf(file, "lake level" EOL); if (many_pools_level) - fprintf(file, "many pools level\r\n"); + fprintf(file, "many pools level" EOL); - fprintf(file, "\r\n"); + fprintf(file, EOL); } // Dumping the crawl state is least likely to cause another crash, // so do that next. crawl_state.dump(file); + // Dump current messages. + if (file != stderr) + { + fprintf(file, EOL "Messages:" EOL); + fprintf(file, "<<<<<<<<<<<<<<<<<<<<<<" EOL); + std::string messages = get_last_messages(NUM_STORED_MESSAGES); + fprintf(file, messages.c_str()); + fprintf(file, ">>>>>>>>>>>>>>>>>>>>>>" EOL); + } + // Next item and monster scans. Any messages will be sent straight to // the file because of set_msg_dump_file() #if DEBUG_ITEM_SCAN diff --git a/crawl-ref/source/libunix.cc b/crawl-ref/source/libunix.cc index c4ef372837..f8f8acb1a5 100644 --- a/crawl-ref/source/libunix.cc +++ b/crawl-ref/source/libunix.cc @@ -1151,7 +1151,7 @@ static void _crash_signal_handler(int sig_num) { if (crawl_state.game_crashed) { - fprintf(stderr, "Recursive crash.\n"); + fprintf(stderr, "Recursive crash." EOL); std::string dir = (!Options.morgue_dir.empty() ? Options.morgue_dir : !SysEnv.crawl_dir.empty() ? SysEnv.crawl_dir @@ -1180,6 +1180,10 @@ static void _crash_signal_handler(int sig_num) _crash_signal = sig_num; crawl_state.game_crashed = true; + // In case the crash dumper is unable to open a file and has to dump + // to stderr. + unixcurses_shutdown(); + do_crash_dump(); // Now crash for real. @@ -1240,7 +1244,7 @@ void dump_crash_info(FILE* file) if (name == NULL) name = "INVALID"; - fprintf(file, "Crash caused by signal #%d: %s\r\n", _crash_signal, + fprintf(file, "Crash caused by signal #%d: %s" EOL, _crash_signal, name); } @@ -1258,8 +1262,8 @@ void write_stack_trace(FILE* file, int ignore_count) if (symbols == NULL) { - fprintf(stderr, "Out of memroy.\r\n"); - fprintf(file, "Out of memory.\r\n"); + fprintf(stderr, "Out of memroy." EOL); + fprintf(file, "Out of memory." EOL); // backtrace_symbols_fd() can print out the stack trace even if // malloc() can't find any free memory. @@ -1269,7 +1273,7 @@ void write_stack_trace(FILE* file, int ignore_count) for (int i = ignore_count; i < num_frames; i++) { - fprintf(file, "%s\r\n", symbols[i]); + fprintf(file, "%s" EOL, symbols[i]); } free(symbols); @@ -1277,7 +1281,7 @@ void write_stack_trace(FILE* file, int ignore_count) #else // ifdef __GLIBC__ void write_stack_trace(FILE* file, int ignore_count) { - const char* msg = "Unable to get stack trace on this platform.\n"; + const char* msg = "Unable to get stack trace on this platform." EOL; fprintf(stderr, msg); fprintf(file, msg); } diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc index 7bda843e10..30f4f8f341 100644 --- a/crawl-ref/source/message.cc +++ b/crawl-ref/source/message.cc @@ -1010,7 +1010,15 @@ std::string get_last_messages(int mcount) bool full_buffer = (Store_Message[NUM_STORED_MESSAGES - 1].text.empty()); int initial = Next_Message - mcount; if (initial < 0 || initial > NUM_STORED_MESSAGES) - initial = full_buffer ? initial + NUM_STORED_MESSAGES : 0; + { + if (full_buffer) + { + initial = (initial + NUM_STORED_MESSAGES) % NUM_STORED_MESSAGES; + initial++; + } + else + initial = 0; + } std::string text; int count = 0; diff --git a/crawl-ref/source/state.cc b/crawl-ref/source/state.cc index 1b2e1f773e..07bbc589d6 100644 --- a/crawl-ref/source/state.cc +++ b/crawl-ref/source/state.cc @@ -376,73 +376,74 @@ std::vector<god_act_state> game_state::other_gods_acting() const void game_state::dump(FILE* file) { - fprintf(file, "\r\nGame state:\r\n\r\n"); + fprintf(file, EOL "Game state:" EOL EOL); fprintf(file, "mouse_enabled: %d, waiting_for_command: %d " - "terminal_resized: %d\r\n", + "terminal_resized: %d" EOL, mouse_enabled, waiting_for_command, terminal_resized); fprintf(file, "io_inited: %d, need_save: %d, saving_game: %d, " - "updating_scores: %d\r\n:", + "updating_scores: %d:" EOL, io_inited, need_save, saving_game, updating_scores); fprintf(file, "seen_hups: %d, map_stat_gen: %d, arena: %d, " - "arena_suspended: %d, unicode_ok: %d\r\n", + "arena_suspended: %d, unicode_ok: %d" EOL, seen_hups, map_stat_gen, arena, arena_suspended, unicode_ok); - fprintf(file, "\r\n"); + fprintf(file, EOL); if (!startup_errors.empty()) { - fprintf(file, "Startup errors:\r\n"); + fprintf(file, "Startup errors:" EOL); for (unsigned int i = 0; i < startup_errors.size(); i++) - fprintf(file, "%s\n", startup_errors[i].c_str()); - fprintf(file, "\r\n"); + fprintf(file, "%s" EOL, startup_errors[i].c_str()); + fprintf(file, EOL); } - fprintf(file, "prev_cmd = %s\r\n", command_to_name(prev_cmd).c_str()); + fprintf(file, "prev_cmd = %s" EOL, command_to_name(prev_cmd).c_str()); if (doing_prev_cmd_again) { fprintf(file, "Doing prev_cmd again with keys: "); for (unsigned int i = 0; i < prev_cmd_keys.size(); i++) fprintf(file, "%d, ", prev_cmd_keys[i]); - fprintf(file, "\r\n"); + fprintf(file, EOL); fprintf(file, "As ASCII keys: "); for (unsigned int i = 0; i < prev_cmd_keys.size(); i++) fprintf(file, "%c", (char) prev_cmd_keys[i]); - fprintf(file, "\r\n\r\n"); + fprintf(file, EOL EOL); } - fprintf(file, "repeat_cmd = %s\r\n", command_to_name(repeat_cmd).c_str()); + fprintf(file, "repeat_cmd = %s" EOL, command_to_name(repeat_cmd).c_str()); if (cmd_repeat_count > 0 || cmd_repeat_goal > 0) { - fprintf(file, "Doing command repitition: \r\n"); + fprintf(file, "Doing command repitition:" EOL); fprintf(file, "cmd_repeat_start:%d, cmd_repeat_count: %d, " - "cmd_repeat_goal:%d\r\nprev_cmd_repeat_goal: %d\r\n", + "cmd_repeat_goal:%d" EOL + "prev_cmd_repeat_goal: %d" EOL, cmd_repeat_start, cmd_repeat_count, cmd_repeat_goal, prev_cmd_repeat_goal); fprintf(file, "Keys being repeated: "); for (unsigned int i = 0; i < repeat_cmd_keys.size(); i++) fprintf(file, "%d, ", repeat_cmd_keys[i]); - fprintf(file, "\r\n"); + fprintf(file, EOL); fprintf(file, "As ASCII keys: "); for (unsigned int i = 0; i < repeat_cmd_keys.size(); i++) fprintf(file, "%c", (char) repeat_cmd_keys[i]); - fprintf(file, "\r\n\r\n"); + fprintf(file, EOL EOL); } if (god_act.which_god != GOD_NO_GOD || god_act.depth != 0) { - fprintf(file, "God %s currently acting with depth %d\r\n\r\n", + fprintf(file, "God %s currently acting with depth %d" EOL EOL, god_name(god_act.which_god).c_str(), god_act.depth); } if (god_act_stack.size() != 0) { - fprintf(file, "Other gods acting: \r\n"); + fprintf(file, "Other gods acting:" EOL); for (unsigned int i = 0; i < god_act_stack.size(); i++) - fprintf(file, "God %s with depth %d\r\n", + fprintf(file, "God %s with depth %d" EOL, god_name(god_act_stack[i].which_god).c_str(), god_act_stack[i].depth); - fprintf(file, "\r\n"); + fprintf(file, EOL); } } |