From fd585a58c23fba020d463acf3e68fd0e7486ce94 Mon Sep 17 00:00:00 2001 From: nhmall Date: Mon, 3 Jun 2019 18:37:45 -0400 Subject: [PATCH] add some debugging BREADCRUMBS to identify caller of some functions Only takes effect if a developer uncomments BREADCRUMBS in config.h --- doc/fixes36.3 | 4 ++- include/config.h | 8 +++++- include/decl.h | 8 +++++- include/extern.h | 9 ++++++- src/ball.c | 69 +++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 90 insertions(+), 8 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 82ada4627..7aef2fdf8 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.31 $ $NHDT-Date: 1559422205 2019/06/01 20:50:05 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.33 $ $NHDT-Date: 1559601004 2019/06/03 22:30:04 $ This fixes36.3 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.2 in May 2019. Please note, however, @@ -91,4 +91,6 @@ add a couple of engraving suggestions in pull request #79 Code Cleanup and Reorganization ------------------------------- +began to add some function caller BREADCRUMBS to aid debugging + diff --git a/include/config.h b/include/config.h index 1fa760d90..d12576f9d 100644 --- a/include/config.h +++ b/include/config.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 config.h $NHDT-Date: 1558248715 2019/05/19 06:51:55 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.122 $ */ +/* NetHack 3.6 config.h $NHDT-Date: 1559601008 2019/06/03 22:30:08 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.123 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2016. */ /* NetHack may be freely redistributed. See license for details. */ @@ -526,6 +526,12 @@ typedef unsigned char uchar; * probably not useful for normal play */ /* #define EXTRA_SANITY_CHECKS */ +/* BREADCRUMBS employs the use of predefined compiler macros + * __FUNCTION__ and __LINE__ to store some caller breadcrumbs + * for use during heavy debugging sessions. Only define if your + * compiler supports those predefined macros and you are debugging */ +/* #define BREADCRUMBS */ + /* EDIT_GETLIN makes the string input in TTY, curses, Qt4, and X11 for some prompts be pre-loaded with previously input text (from a previous instance of the same prompt) as the default response. diff --git a/include/decl.h b/include/decl.h index eb3c904c4..0b7a929a1 100644 --- a/include/decl.h +++ b/include/decl.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 decl.h $NHDT-Date: 1547025154 2019/01/09 09:12:34 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.147 $ */ +/* NetHack 3.6 decl.h $NHDT-Date: 1559601011 2019/06/03 22:30:11 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.150 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2007. */ /* NetHack may be freely redistributed. See license for details. */ @@ -431,6 +431,12 @@ struct plinemsg_type { E struct plinemsg_type *plinemsg_types; +struct breadcrumbs { + const char *funcnm; + int linenum; + boolean in_effect; +}; + #ifdef PANICTRACE E const char *ARGV0; #endif diff --git a/include/extern.h b/include/extern.h index dd4ce99d5..cc62a61b5 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 extern.h $NHDT-Date: 1559422206 2019/06/01 20:50:06 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.707 $ */ +/* NetHack 3.6 extern.h $NHDT-Date: 1559601014 2019/06/03 22:30:14 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.708 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -127,8 +127,15 @@ E void FDECL(uchangealign, (int, int)); E void FDECL(ballrelease, (BOOLEAN_P)); E void NDECL(ballfall); +#ifndef BREADCRUMBS E void NDECL(placebc); E void NDECL(unplacebc); +#else +E void FDECL(Placebc, (const char *, int)); +E void FDECL(Unplacebc, (const char *, int)); +#define placebc() Placebc(__FUNCTION__, __LINE__) +#define unplacebc() Unplacebc(__FUNCTION__, __LINE__) +#endif E void FDECL(set_bc, (int)); E void FDECL(move_bc, (int, int, XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P)); E boolean FDECL(drag_ball, (XCHAR_P, XCHAR_P, int *, xchar *, xchar *, diff --git a/src/ball.c b/src/ball.c index ab1024a9a..75822f88b 100644 --- a/src/ball.c +++ b/src/ball.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 ball.c $NHDT-Date: 1559554598 2019/06/03 09:36:38 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.39 $ */ +/* NetHack 3.6 ball.c $NHDT-Date: 1559601027 2019/06/03 22:30:27 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.40 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) David Cohrs, 2006. */ /* NetHack may be freely redistributed. See license for details. */ @@ -10,6 +10,13 @@ STATIC_DCL int NDECL(bc_order); STATIC_DCL void NDECL(litter); +STATIC_OVL void NDECL(placebc_core); +STATIC_OVL void NDECL(unplacebc_core); + +#ifdef BREADCRUMBS +static struct breadcrumbs bcpbreadcrumbs = { (const char *) 0, 0, FALSE}, + bcubreadcrumbs = { (const char *) 0, 0, FALSE}; +#endif void ballrelease(showmsg) @@ -106,8 +113,8 @@ ballfall() * * Should not be called while swallowed except on waterlevel. */ -void -placebc() +STATIC_OVL void +placebc_core() { if (!uchain || !uball) { impossible("Where are your ball and chain?"); @@ -132,8 +139,34 @@ placebc() newsym(u.ux, u.uy); } +#ifdef BREADCRUMBS void -unplacebc() +Placebc(funcnm, linenum) +const char *funcnm; +int linenum; +{ + if (uball && bcpbreadcrumbs.in_effect && uball->where == OBJ_FLOOR) { + impossible("placebc collision from %s:%d, already placed by %s:%d", + funcnm, linenum, + bcpbreadcrumbs.funcnm, bcpbreadcrumbs.linenum); + return; + } + bcpbreadcrumbs.in_effect = TRUE; + bcubreadcrumbs.in_effect = FALSE; + bcpbreadcrumbs.funcnm = funcnm; + bcpbreadcrumbs.linenum = linenum; + placebc_core(); +} +#else +void +placebc() +{ + placebc_core(); +} +#endif + +STATIC_OVL void +unplacebc_core() { if (u.uswallow) { if (Is_waterlevel(&u.uz)) { @@ -164,6 +197,34 @@ unplacebc() u.bc_felt = 0; /* feel nothing */ } +#ifdef BREADCRUMBS +void +Unplacebc(funcnm, linenum) +const char *funcnm; +int linenum; +{ +#if 0 + if (uball && bcubreadcrumbs.in_effect && uball->where == OBJ_FREE) { + impossible("placebc collision from %s:%d, already placed by %s:%d", + funcnm, linenum, + bcpbreadcrumbs.funcnm, bcpbreadcrumbs.linenum); + return; + } +#endif + bcpbreadcrumbs.in_effect = FALSE; + bcubreadcrumbs.in_effect = TRUE; + bcubreadcrumbs.funcnm = funcnm; + bcubreadcrumbs.linenum = linenum; + unplacebc_core(); +} +#else +void +unplacebc() +{ + unplacebc_core(); +} +#endif + /* * Return the stacking of the hero's ball & chain. This assumes that the * hero is being punished. -- 2.40.0