From 3f5d1d3a36292df84eea5426a228fa813f07a423 Mon Sep 17 00:00:00 2001 From: nhkeni Date: Tue, 20 Feb 2024 21:37:06 -0500 Subject: [PATCH] split DUMPLOG DUMPLOG requests the DUMPLOG feature as it does now DUMPLOG_CORE requests the internal buffering only (used for CRASHREPORT) This allows CRASHREPORT to access recent messages without performing any file I/O. --- azure-pipelines.yml | 1 + include/config.h | 13 ++++++++----- include/decl.h | 2 +- include/extern.h | 2 +- src/cmd.c | 4 ++-- src/decl.c | 2 +- src/end.c | 4 ++-- src/pager.c | 2 +- src/pline.c | 4 ++-- src/save.c | 2 +- win/Qt/qt_bind.cpp | 4 ++-- win/curses/cursmesg.c | 6 +++--- win/tty/getline.c | 2 +- win/tty/topl.c | 8 ++++---- 14 files changed, 30 insertions(+), 26 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6d0b52606..6cbf92311 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -199,6 +199,7 @@ steps: sed -i '/^#[ ]*define CRASHREPORT/d' include/config.h #sed -i '/^#[ ]*define DOAGAIN/d' include/config.h sed -i '/^#[ ]*define DUMPLOG/d' include/config.h + sed -i '/^#[ ]*define DUMPLOG_CORE/d' include/config.h #sed -i '/^#[ ]*define GDBPATH/d' include/config.h #sed -i '/^#[ ]*define GREPPATH/d' include/config.h sed -i '/^#[ ]*define INSURANCE/d' include/config.h diff --git a/include/config.h b/include/config.h index b777121a8..6ea2ec8d5 100644 --- a/include/config.h +++ b/include/config.h @@ -262,8 +262,8 @@ #endif #ifdef CRASHREPORT -# ifndef DUMPLOG -# define DUMPLOG // required to get ^P info +# ifndef DUMPLOG_CORE +# define DUMPLOG_CORE // required to get ^P info # endif # ifdef MACOS # define PANICTRACE @@ -726,9 +726,7 @@ typedef unsigned char uchar; #endif /* LIVELOG */ #ifdef DUMPLOG -#ifndef DUMPLOG_MSG_COUNT -#define DUMPLOG_MSG_COUNT 50 -#endif /* DUMPLOG_MSG_COUNT */ +#define DUMPLOG_CORE #ifndef DUMPLOG_FILE #define DUMPLOG_FILE "/tmp/nethack.%n.%d.log" /* DUMPLOG_FILE allows following placeholders: @@ -745,5 +743,10 @@ typedef unsigned char uchar; */ #endif /* DUMPLOG_FILE */ #endif /* DUMPLOG */ +#ifdef DUMPLOG_CORE +#ifndef DUMPLOG_MSG_COUNT +#define DUMPLOG_MSG_COUNT 50 +#endif /* DUMPLOG_MSG_COUNT */ +#endif #endif /* CONFIG_H */ diff --git a/include/decl.h b/include/decl.h index 31c030b1c..0e14e18f1 100644 --- a/include/decl.h +++ b/include/decl.h @@ -917,7 +917,7 @@ struct instance_globals_s { boolean shop_filter; /* pline.c */ -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE unsigned saved_pline_index; /* slot in saved_plines[] to use next */ char *saved_plines[DUMPLOG_MSG_COUNT]; #endif diff --git a/include/extern.h b/include/extern.h index de46c15c2..f03e0e0f5 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2356,7 +2356,7 @@ extern boolean autopick_testobj(struct obj *, boolean) NONNULLARG1; /* ### pline.c ### */ -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE extern void dumplogmsg(const char *); extern void dumplogfreemessages(void); #endif diff --git a/src/cmd.c b/src/cmd.c index 5b0fd2c93..19a32fb3d 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -6611,7 +6611,7 @@ yn_function( { char res = '\033', qbuf[QBUFSZ]; struct _cmd_queue cq, *cmdq; -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE unsigned idx = gs.saved_pline_index; /* buffer to hold query+space+formatted_single_char_response */ char dumplog_buf[QBUFSZ + 1 + 15]; /* [QBUFSZ+1+7] should suffice */ @@ -6653,7 +6653,7 @@ yn_function( cmdq_add_key(CQ_REPEAT, res); } -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE if (idx == gs.saved_pline_index) { /* when idx is still the same as gs.saved_pline_index, the interface didn't put the prompt into gs.saved_plines[]; we put a simplified diff --git a/src/decl.c b/src/decl.c index db80503d9..a7fff02eb 100644 --- a/src/decl.c +++ b/src/decl.c @@ -775,7 +775,7 @@ const struct instance_globals_s g_init_s = { /* pickup.c */ FALSE, /* shop_filter */ /* pline.c */ -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE 0U, /* saved_pline_index */ { NULL }, /* saved_plines */ #endif diff --git a/src/end.c b/src/end.c index b0ccd8053..0e7561666 100644 --- a/src/end.c +++ b/src/end.c @@ -537,7 +537,7 @@ submit_web_report(int cos, const char *msg, const char *why){ #endif // !WIN32 } -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE // config.h turns this on, but make it easy to turn off if needed if(cos==1) { int k; @@ -1191,6 +1191,7 @@ dump_plines(void) } } } +#endif /* DUMPLOG */ #ifdef CRASHREPORT // lineno==0 gives the most recent message (e.g. "Do you want to call panic..." @@ -1214,7 +1215,6 @@ get_saved_pline(int lineno){ return NULL; } #endif /* CRASHREPORT */ -#endif /* DUMPLOG */ /*ARGSUSED*/ static void diff --git a/src/pager.c b/src/pager.c index 7e8496dc6..2b2c051be 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1787,7 +1787,7 @@ do_look(int mode, coord *click_cc) if (found) { /* use putmixed() because there may be an encoded glyph present */ putmixed(WIN_MESSAGE, 0, out_str); -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE { char dmpbuf[BUFSZ]; diff --git a/src/pline.c b/src/pline.c index f64cd6742..7abba3bf0 100644 --- a/src/pline.c +++ b/src/pline.c @@ -17,7 +17,7 @@ static void execplinehandler(const char *); #ifdef USER_SOUNDS extern void maybe_play_sound(const char *); #endif -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE /* keep the most recent DUMPLOG_MSG_COUNT messages */ void @@ -205,7 +205,7 @@ vpline(const char *line, va_list the_args) } msgtyp = MSGTYP_NORMAL; -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE /* We hook here early to have options-agnostic output. * Unfortunately, that means Norep() isn't honored (general issue) and * that short lines aren't combined into one longer one (tty behavior). diff --git a/src/save.c b/src/save.c index d4456c8bf..7c800b2f9 100644 --- a/src/save.c +++ b/src/save.c @@ -1233,7 +1233,7 @@ freedynamicdata(void) #ifdef USER_SOUNDS release_sound_mappings(); #endif -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE dumplogfreemessages(); #endif discard_gamelog(); diff --git a/win/Qt/qt_bind.cpp b/win/Qt/qt_bind.cpp index db40217ef..2b297a085 100644 --- a/win/Qt/qt_bind.cpp +++ b/win/Qt/qt_bind.cpp @@ -962,7 +962,7 @@ void NetHackQtBind::qt_putmsghistory(const char *msg, boolean is_restoring) if (msg) { //raw_printf("msg='%s'", msg); window->PutStr(ATR_NONE, QString::fromLatin1(msg)); -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE dumplogmsg(msg); #endif } else if (msgs_saved) { @@ -970,7 +970,7 @@ void NetHackQtBind::qt_putmsghistory(const char *msg, boolean is_restoring) for (int i = 0; i < msgs_strings->size(); ++i) { const QString &nxtmsg = msgs_strings->at(i); window->PutStr(ATR_NONE, nxtmsg); -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE dumplogmsg(nxtmsg.toLatin1().constData()); #endif } diff --git a/win/curses/cursmesg.c b/win/curses/cursmesg.c index f241384ef..01f3eec08 100644 --- a/win/curses/cursmesg.c +++ b/win/curses/cursmesg.c @@ -1044,7 +1044,7 @@ curses_putmsghistory(const char *msg, boolean restoring_msghist) stash_head = first_mesg, first_mesg = (nhprev_mesg *) 0; last_mesg = (nhprev_mesg *) 0; /* no need to remember the tail */ initd = TRUE; -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE /* this suffices; there's no need to scrub g.saved_pline[] pointers */ gs.saved_pline_index = 0; #endif @@ -1058,7 +1058,7 @@ curses_putmsghistory(const char *msg, boolean restoring_msghist) and those messages should have a normal turn value */ if (last_mesg) /* appease static analyzer */ last_mesg->turn = restoring_msghist ? (1L << 3) : gh.hero_seq; -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE dumplogmsg(last_mesg->str); #endif } else if (stash_count) { @@ -1081,7 +1081,7 @@ curses_putmsghistory(const char *msg, boolean restoring_msghist) /* added line became new tail */ if (last_mesg) /* appease static analyzer */ last_mesg->turn = mesg_turn; -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE dumplogmsg(mesg->str); #endif free((genericptr_t) mesg->str); diff --git a/win/tty/getline.c b/win/tty/getline.c index d7013f7f8..b95f85f4d 100644 --- a/win/tty/getline.c +++ b/win/tty/getline.c @@ -214,7 +214,7 @@ hooked_tty_getlin( /* prevent next message from pushing current query+answer into tty message history */ *gt.toplines = '\0'; -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE } else { /* needed because we've bypassed pline() */ dumplogmsg(gt.toplines); diff --git a/win/tty/topl.c b/win/tty/topl.c index 9aaf9d29d..c1e93cd41 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -534,7 +534,7 @@ tty_yn_function( (void) key2txt(q, rtmp); /* addtopl(rtmp); -- rewrite gt.toplines instead */ Sprintf(gt.toplines, "%s%s", prompt, rtmp); -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE dumplogmsg(gt.toplines); #endif ttyDisplay->inread--; @@ -684,7 +684,7 @@ tty_putmsghistory(const char *msg, boolean restoring_msghist) restored ones are being put into place */ msghistory_snapshot(TRUE); initd = TRUE; -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE /* this suffices; there's no need to scrub saved_pline[] pointers */ gs.saved_pline_index = 0; #endif @@ -701,7 +701,7 @@ tty_putmsghistory(const char *msg, boolean restoring_msghist) /* move most recent message to history, make this become most recent */ remember_topl(); Strcpy(gt.toplines, msg); -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE dumplogmsg(gt.toplines); #endif } else if (snapshot_mesgs) { @@ -712,7 +712,7 @@ tty_putmsghistory(const char *msg, boolean restoring_msghist) for (idx = 0; snapshot_mesgs[idx]; ++idx) { remember_topl(); Strcpy(gt.toplines, snapshot_mesgs[idx]); -#ifdef DUMPLOG +#ifdef DUMPLOG_CORE dumplogmsg(gt.toplines); #endif }