From df52ba17ec7a6a92914668cae8798314372e6b83 Mon Sep 17 00:00:00 2001 From: "Derek S. Ray" Date: Wed, 15 Apr 2015 18:19:16 -0400 Subject: [PATCH] add debugger window support via _RPT*; add regex currently it's locked behind _MSC_VER, but anything that runs on Win32 should be able to use those functions as long as it has something that can pass as a debug window. also, add a non-wildcard-accepting version of showdebug for the dumpit() functions in dungeon.c and questpgr.c; this makes DEBUGFILES=* workable without being excruciatingly painful --- include/extern.h | 4 ++-- include/hack.h | 40 +++++++++++++++++++++---------- src/dungeon.c | 4 ++-- src/files.c | 16 +++++++++---- src/questpgr.c | 4 ++-- sys/share/pcmain.c | 13 +++++++++- win/win32/vs2013/NetHack.vcxproj | 6 ++--- win/win32/vs2013/NetHackW.vcxproj | 1 + 8 files changed, 60 insertions(+), 28 deletions(-) diff --git a/include/extern.h b/include/extern.h index 997885882..bec672979 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.5 extern.h $NHDT-Date: 1428806395 2015/04/12 02:39:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.455 $ */ +/* NetHack 3.5 extern.h $NHDT-Date: 1429135323 2015/04/15 22:02:03 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.464 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -749,7 +749,7 @@ E int FDECL(nhclose, (int)); E void NDECL(really_close); #endif #ifdef DEBUG -E boolean FDECL(showdebug, (const char *)); +E boolean FDECL(debugcore, (const char *, boolean)); #endif E void FDECL(read_tribute, (const char *,const char *,int)); diff --git a/include/hack.h b/include/hack.h index 0b5feb501..7b530e0a7 100644 --- a/include/hack.h +++ b/include/hack.h @@ -1,4 +1,4 @@ -/* NetHack 3.5 hack.h $NHDT-Date: 1426465431 2015/03/16 00:23:51 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.52 $ */ +/* NetHack 3.5 hack.h $NHDT-Date: 1429136301 2015/04/15 22:18:21 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.59 $ */ /* SCCS Id: @(#)hack.h 3.5 2008/03/19 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -12,20 +12,34 @@ /* [DEBUG shouldn't be defined unless you know what you're doing...] */ #ifdef DEBUG -# define ifdebug(stmt) do { if (showdebug(__FILE__)) stmt; } while (0) +# define showdebug(file) debugcore(file, TRUE) +# define explicitdebug(file) debugcore(file, FALSE) +# define ifdebug(stmt) do { if (showdebug(__FILE__)) stmt; } while (0) +# ifdef _MSC_VER + /* if we have microsoft's C runtime we can use these instead */ +# include +# define crtdebug(stmt) do { if (showdebug(__FILE__)) stmt; \ + _RPT0(_CRT_WARN,"\n"); } while (0) +# define debugpline0(str) crtdebug(_RPT0(_CRT_WARN,str)) +# define debugpline1(fmt,arg) crtdebug(_RPT1(_CRT_WARN,fmt,arg)) +# define debugpline2(fmt,a1,a2) crtdebug(_RPT2(_CRT_WARN,fmt,a1,a2)) +# define debugpline3(fmt,a1,a2,a3) crtdebug(_RPT3(_CRT_WARN,fmt,a1,a2,a3)) +# define debugpline4(fmt,a1,a2,a3,a4) crtdebug(_RPT4(_CRT_WARN,fmt,a1,a2,a3,a4)) +# else /* these don't require compiler support for C99 variadic macros */ -# define debugpline0(str) ifdebug(pline(str)) -# define debugpline1(fmt,arg) ifdebug(pline(fmt,arg)) -# define debugpline2(fmt,a1,a2) ifdebug(pline(fmt,a1,a2)) -# define debugpline3(fmt,a1,a2,a3) ifdebug(pline(fmt,a1,a2,a3)) -# define debugpline4(fmt,a1,a2,a3,a4) ifdebug(pline(fmt,a1,a2,a3,a4)) +# define debugpline0(str) ifdebug(pline(str)) +# define debugpline1(fmt,arg) ifdebug(pline(fmt,arg)) +# define debugpline2(fmt,a1,a2) ifdebug(pline(fmt,a1,a2)) +# define debugpline3(fmt,a1,a2,a3) ifdebug(pline(fmt,a1,a2,a3)) +# define debugpline4(fmt,a1,a2,a3,a4) ifdebug(pline(fmt,a1,a2,a3,a4)) +# endif #else -# define debugpline0(str) /*empty*/ -# define debugpline1(fmt,arg) /*empty*/ -# define debugpline2(fmt,a1,a2) /*empty*/ -# define debugpline3(fmt,a1,a2,a3) /*empty*/ -# define debugpline4(fmt,a1,a2,a3,a4) /*empty*/ -#endif /*DEBUG*/ +# define debugpline0(str) /*empty*/ +# define debugpline1(fmt,arg) /*empty*/ +# define debugpline2(fmt,a1,a2) /*empty*/ +# define debugpline3(fmt,a1,a2,a3) /*empty*/ +# define debugpline4(fmt,a1,a2,a3,a4) /*empty*/ +#endif /*DEBUG*/ #define TELL 1 #define NOTELL 0 diff --git a/src/dungeon.c b/src/dungeon.c index 58f83eed7..5fd42f3de 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 dungeon.c $NHDT-Date: 1426465434 2015/03/16 00:23:54 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.39 $ */ +/* NetHack 3.5 dungeon.c $NHDT-Date: 1429135381 2015/04/15 22:03:01 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.49 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -80,7 +80,7 @@ dumpit() s_level *x; branch *br; - if (!showdebug(__FILE__)) return; + if (!explicitdebug(__FILE__)) return; for(i = 0; i < n_dgns; i++) { fprintf(stderr, "\n#%d \"%s\" (%s):\n", i, diff --git a/src/files.c b/src/files.c index 952737275..5ac1e67a0 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 files.c $NHDT-Date: 1427337311 2015/03/26 02:35:11 $ $NHDT-Branch: derek-farming $:$NHDT-Revision: 1.141 $ */ +/* NetHack 3.5 files.c $NHDT-Date: 1429136302 2015/04/15 22:18:22 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.166 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -3267,11 +3267,16 @@ assure_syscf_file() { #ifdef DEBUG /* used by debugpline() to decide whether to issue a message - from a partiular source file; caller passes __FILE__ and we check - whether it is in the source file list supplied by SYSCF's DEBUGFILES */ + * from a partiular source file; caller passes __FILE__ and we check + * whether it is in the source file list supplied by SYSCF's DEBUGFILES + * + * pass FALSE to override wildcard matching; useful for files + * like dungeon.c and questpgr.c, which generate a ridiculous amount of + * output if DEBUG is defined and effectively block the use of a wildcard */ boolean -showdebug(filename) +debugcore(filename, wildcards) const char *filename; +boolean wildcards; { const char *debugfiles, *p; @@ -3314,7 +3319,7 @@ const char *filename; * attempt a wildcard match against each element, but that would be * overkill for the intended usage.] */ - if (pmatch(debugfiles, filename)) + if (wildcards && pmatch(debugfiles, filename)) return TRUE; /* check whether filename is an element of the list */ @@ -3327,6 +3332,7 @@ const char *filename; } return FALSE; } + #endif /*DEBUG*/ /* ---------- BEGIN TRIBUTE ----------- */ diff --git a/src/questpgr.c b/src/questpgr.c index a52cc4a1d..e30ca5406 100644 --- a/src/questpgr.c +++ b/src/questpgr.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 questpgr.c $NHDT-Date: 1426465439 2015/03/16 00:23:59 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.18 $ */ +/* NetHack 3.5 questpgr.c $NHDT-Date: 1429135390 2015/04/15 22:03:10 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.26 $ */ /* Copyright 1991, M. Stephenson */ /* NetHack may be freely redistributed. See license for details. */ @@ -46,7 +46,7 @@ dump_qtlist() /* dump the character msg list to check appearance */ { struct qtmsg *msg; - if (!showdebug(__FILE__)) return; + if (!explicitdebug(__FILE__)) return; for (msg = qt_list.chrole; msg->msgnum > 0; msg++) { pline("msgnum %d: delivery %c", diff --git a/sys/share/pcmain.c b/sys/share/pcmain.c index 48cbae029..8e54f078a 100644 --- a/sys/share/pcmain.c +++ b/sys/share/pcmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 pcmain.c $NHDT-Date: 1427337317 2015/03/26 02:35:17 $ $NHDT-Branch: derek-farming $:$NHDT-Revision: 1.52 $ */ +/* NetHack 3.5 pcmain.c $NHDT-Date: 1429135416 2015/04/15 22:03:36 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.60 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -118,6 +118,17 @@ char *argv[]; #endif boolean resuming = FALSE; /* assume new game */ +#ifdef _MSC_VER + /* set these appropriately for VS debugging */ + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG); + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); /* | _CRTDBG_MODE_FILE);*/ + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); + /*| _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW);*/ + /* use STDERR by default + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ +#endif + #if defined(__BORLANDC__) && !defined(_WIN32) startup(); #endif diff --git a/win/win32/vs2013/NetHack.vcxproj b/win/win32/vs2013/NetHack.vcxproj index 09ca8b8a1..9ed7463cd 100644 --- a/win/win32/vs2013/NetHack.vcxproj +++ b/win/win32/vs2013/NetHack.vcxproj @@ -211,7 +211,7 @@ NDEBUG;WIN32;WIN32CON;DLB;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) true true - MultiThreaded + MultiThreadedDebug true .\Debug/NetHack.pch .\$(ConfigurationName)\$(ProjectName)\ @@ -261,7 +261,7 @@ WIN32;WIN32CON;DLB;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) true true - MultiThreaded + MultiThreadedDebug true .\Debug/NetHack.pch .\$(ConfigurationName)\$(ProjectName)\ @@ -410,6 +410,7 @@ + @@ -418,7 +419,6 @@ - diff --git a/win/win32/vs2013/NetHackW.vcxproj b/win/win32/vs2013/NetHackW.vcxproj index ae9c1d42f..88ed645a3 100644 --- a/win/win32/vs2013/NetHackW.vcxproj +++ b/win/win32/vs2013/NetHackW.vcxproj @@ -650,6 +650,7 @@ copy ..\sys\winnt\defaults.nh ..\binary\defaults.nh %(PreprocessorDefinitions) %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) %(AdditionalIncludeDirectories) -- 2.40.0