Skip to content

Commit

Permalink
Improved(?) debug tracing: use of TRACE/ASSERT/VERIFY macros now no l…
Browse files Browse the repository at this point in the history
…onger require (are now no longer dependent upon) DEBUG (e.g. --enable-debug) builds. See new dbgtrace.h header for details (i.e. define ENABLE_TRACING_STMTS to enable TRACE/ASSERT/VERIFY independently of DEBUG builds, thereby allowing you to use them even on Release (Retail) builds if desired).

Make TRACE/ASSERT/VERIFY macros independent of (but compatible with) DEBUG build setting while still allowing individual source member to override the default setting/handling if so desired. I'm hoping this makes the use of TRACE, ASSERT and VERIFY macros easier for everyone.

git-svn-id: file:///home/jj/hercules.svn/trunk@7302 956126f8-22a0-4046-8f4a-272fa8102e63
  • Loading branch information
Fish (David B Trout) committed Jan 27, 2011
1 parent 5b46cfd commit c485e9c
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 238 deletions.
4 changes: 4 additions & 0 deletions Hercules.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,10 @@
RelativePath=".\dat.h"
>
</File>
<File
RelativePath=".\dbgtrace.h"
>
</File>
<File
RelativePath=".\devtype.h"
>
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ noinst_HEADERS = fishhang.h \
msgenu.h \
wthreads.h \
hdiagf18.h \
dbgtrace.h \
$(extra_dynamic_SRC)

cckd: cckd2ckd$(EXEEXT) \
Expand Down
25 changes: 6 additions & 19 deletions awstape.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,27 @@
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */

// $Id$

/* Original Author: Roger Bowler */
/* Prime Maintainer: Ivan Warren */
/* Secondary Maintainer: "Fish" (David B. Trout) */

// $Id$

/*-------------------------------------------------------------------*/
/* This module contains the AWSTAPE emulated tape format support. */
/* */
/* The subroutines in this module are called by the general tape */
/* device handler (tapedev.c) when the tape format is AWSTAPE. */
/* */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Messages issued by this module are prefixed HHCTA1nn */
/*-------------------------------------------------------------------*/

#include "hstdinc.h"
#include "hercules.h" /* need Hercules control blocks */
#include "tapedev.h" /* Main tape handler header file */

//#define ENABLE_TRACING_STMTS // (Fish: DEBUGGING)

#ifdef ENABLE_TRACING_STMTS
#if !defined(DEBUG)
#warning DEBUG required for ENABLE_TRACING_STMTS
#endif
// (TRACE, ASSERT, and VERIFY macros are #defined in hmacros.h)
#else
#undef TRACE
#undef ASSERT
#undef VERIFY
#define TRACE 1 ? ((void)0) : logmsg
#define ASSERT(a)
#define VERIFY(a) ((void)(a))
#endif
//#define ENABLE_TRACING_STMTS 1 // (Fish: DEBUGGING)
//#include "dbgtrace.h" // (Fish: DEBUGGING)

/*********************************************************************/
/* START OF ORIGINAL AWS FUNCTIONS (ISW Additions) */
Expand Down
113 changes: 113 additions & 0 deletions dbgtrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* DBGTRACE.H (c) Copyright "Fish" (David B. Trout), 2011 */
/* TRACE/ASSERT/VERIFY debugging macros */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */

/*-------------------------------------------------------------------*/
/* This header implements the TRACE, ASSERT and VERIFY debugging */
/* macros. Use TRACE statements during and after developing your */
/* code to display helpful debugging messages. Use ASSERT to test */
/* for a condition which should always be true. Use VERIFY whenever */
/* the condition must always be evaluated even for non-debug builds */
/* such as when the VERIFY conditional itself uses a function call */
/* which must always be called. */
/* */
/* You should #define ENABLE_TRACING_STMTS to either 0 or 1 before */
/* #including this header. If left undefined then the _DEBUG switch */
/* controls if they're enabled or not (default is yes for _DEBUG). */
/* This allows you to enable/disable TRACING separate from _DEBUG */
/* on an individual module by module basis if needed or desired. */
/*-------------------------------------------------------------------*/

// $Id:

/* PROGRAMMING NOTE: this header purposely does not prevent itself */
/* from being #included multiple times. This is so default handling */
/* can be overridden by simply #defining 'ENABLE_TRACING_STMTS' and */
/* then #including this header again to activate the new settings. */

#undef _ENABLE_TRACING_STMTS_IMPL

#if defined( ENABLE_TRACING_STMTS )
#if ENABLE_TRACING_STMTS
#define _ENABLE_TRACING_STMTS_IMPL 1
#else
#define _ENABLE_TRACING_STMTS_IMPL 0
#endif
#else
#if defined(DEBUG) || defined(_DEBUG)
#define _ENABLE_TRACING_STMTS_IMPL 1
#else
#define _ENABLE_TRACING_STMTS_IMPL 0
#endif
#endif

#undef VERIFY
#undef ASSERT
#undef TRACE

/* VERIFY conditions are always evaluated */
/* ASSERT conditions may not be evaluated */

#if !_ENABLE_TRACING_STMTS_IMPL
#ifdef _MSVC_
#define VERIFY(a) ((void)(a))
#define ASSERT __noop
#define TRACE __noop
#else
#define VERIFY(a) ((void)(a))
#define ASSERT(a) /* do nothing */
#define TRACE 1 ? ((void)0) : logmsg
#endif
#else /* _ENABLE_TRACING_STMTS_IMPL */
#if defined( _MSVC_ )
#define TRACE(...) do { \
/* Write to both places */ \
logmsg(__VA_ARGS__); \
if (IsDebuggerPresent()) \
DebuggerTrace (__VA_ARGS__); \
} while (0)
#define ASSERT(a) do { \
if (!(a)) { \
/* Programming Note: message formatted specifically for Visual Studio F4-key "next message" compatibility */ \
TRACE("%s(%d) : warning HHC90999W : *** Assertion Failed! *** function: %s\n",__FILE__,__LINE__,__FUNCTION__); \
if (IsDebuggerPresent()) DebugBreak(); /* break into debugger */ \
} \
} while(0)
#else /* !defined( _MSVC_ ) */
#define TRACE logmsg
#define ASSERT(a) do { \
if (!(a)) { \
TRACE("HHC91999W *** Assertion Failed! *** %s(%d)\n",__FILE__,__LINE__); \
} \
} while(0)
#endif // _MSVC_
#define VERIFY ASSERT
#endif /* !_ENABLE_TRACING_STMTS_IMPL */

#if defined( _MSVC_ ) && _ENABLE_TRACING_STMTS_IMPL
#ifndef _ENABLE_TRACING_STMTS_DEBUGGERTRACE_DEFINED
#define _ENABLE_TRACING_STMTS_DEBUGGERTRACE_DEFINED
/* Windows: also send to debugger window */
inline void DebuggerTrace(char* fmt, ...) {
const int chunksize = 512;
int buffsize = 0;
char* buffer = NULL;
int rc = -1;
va_list args;
va_start( args, fmt );
do {
if (buffer) free( buffer );
buffsize += chunksize;
buffer = malloc( buffsize + 1 );
if (!buffer) __debugbreak();
rc = _vsnprintf_s( buffer, buffsize+1, buffsize, fmt, args);
} while (rc < 0 || rc >= buffsize);
OutputDebugStringA( buffer ); /* send to debugger pane */
if (buffer) free( buffer );
va_end( args );
}
#endif /* _ENABLE_TRACING_STMTS_DEBUGGERTRACE_DEFINED */
#endif /* defined( _MSVC_ ) && _ENABLE_TRACING_STMTS_IMPL */
25 changes: 4 additions & 21 deletions faketape.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,20 @@

/*-------------------------------------------------------------------*/
/* This module contains the FAKETAPE emulated tape format support. */
/* */
/* The subroutines in this module are called by the general tape */
/* device handler (tapedev.c) when the tape format is FAKETAPE. */
/* */
/* Messages issued by this module are prefixed HHCTA5nn */
/* Reference information: FSIMS100 Faketape manual */
/*-------------------------------------------------------------------*/

/*-------------------------------------------------------------------*/
/* Reference information: */
/* FSIMS100 Faketape manual */
/* Messages issued by this module are prefixed HHCTA5nn */
/*-------------------------------------------------------------------*/

#include "hstdinc.h"
#include "hercules.h" /* need Hercules control blocks */
#include "tapedev.h" /* Main tape handler header file */

//#define ENABLE_TRACING_STMTS // (Fish: DEBUGGING)

#ifdef ENABLE_TRACING_STMTS
#if !defined(DEBUG)
#warning DEBUG required for ENABLE_TRACING_STMTS
#endif
// (TRACE, ASSERT, and VERIFY macros are #defined in hmacros.h)
#else
#undef TRACE
#undef ASSERT
#undef VERIFY
#define TRACE 1 ? ((void)0) : logmsg
#define ASSERT(a)
#define VERIFY(a) ((void)(a))
#endif
//#define ENABLE_TRACING_STMTS 1 // (Fish: DEBUGGING)
//#include "dbgtrace.h" // (Fish: DEBUGGING)

/*********************************************************************/
/* START OF ORIGINAL AWS FUNCTIONS (ISW Additions) */
Expand Down
24 changes: 0 additions & 24 deletions hercwind.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,28 +214,4 @@ typedef int mode_t;
#define SIZEOF_SIZE_T 4
#endif

#define DBGTRACE DebugTrace

inline void DebugTrace(char* fmt, ...)
{
const int chunksize = 512;
int buffsize = 0;
char* buffer = NULL;
int rc = -1;
va_list args;
va_start( args, fmt );
do
{
if (buffer) free( buffer );
buffsize += chunksize;
buffer = malloc( buffsize + 1 );
if (!buffer) __debugbreak();
rc = _vsnprintf_s( buffer, buffsize+1, buffsize, fmt, args);
}
while (rc < 0 || rc >= buffsize);
OutputDebugStringA( buffer );
if (buffer) free( buffer );
va_end( args );
}

#endif /*!defined(_HERCWIND_H)*/
18 changes: 2 additions & 16 deletions hettape.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

/*-------------------------------------------------------------------*/
/* This module contains the HET emulated tape format support. */
/* */
/* The subroutines in this module are called by the general tape */
/* device handler (tapedev.c) when the tape format is HETTAPE. */
/*-------------------------------------------------------------------*/
Expand All @@ -22,21 +21,8 @@
#include "hercules.h" /* need Hercules control blocks */
#include "tapedev.h" /* Main tape handler header file */

//#define ENABLE_TRACING_STMTS // (Fish: DEBUGGING)

#ifdef ENABLE_TRACING_STMTS
#if !defined(DEBUG)
#warning DEBUG required for ENABLE_TRACING_STMTS
#endif
// (TRACE, ASSERT, and VERIFY macros are #defined in hmacros.h)
#else
#undef TRACE
#undef ASSERT
#undef VERIFY
#define TRACE 1 ? ((void)0) : logmsg
#define ASSERT(a)
#define VERIFY(a) ((void)(a))
#endif
//#define ENABLE_TRACING_STMTS 1 // (Fish: DEBUGGING)
//#include "dbgtrace.h" // (Fish: DEBUGGING)

/*-------------------------------------------------------------------*/
/* Open an HET format file */
Expand Down
61 changes: 0 additions & 61 deletions hmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,67 +340,6 @@
#define bindtextdomain(_package, _directory)
#endif

#if defined(DEBUG) || defined(_DEBUG)

#ifdef _MSVC_

#define TRACE(...) \
do \
{ \
IsDebuggerPresent() ? DebugTrace (__VA_ARGS__): \
logmsg (__VA_ARGS__); \
} \
while (0)

#undef ASSERT /* For VS9 2008 */
#define ASSERT(a) \
do \
{ \
if (!(a)) \
{ \
TRACE("HHC90999W *** Assertion Failed! *** %s(%d); function: %s\n",__FILE__,__LINE__,__FUNCTION__); \
if (IsDebuggerPresent()) DebugBreak(); /* (break into debugger) */ \
} \
} \
while(0)

#else // ! _MSVC_

#define TRACE logmsg

#define ASSERT(a) \
do \
{ \
if (!(a)) \
{ \
TRACE("HHC91999W *** Assertion Failed! *** %s(%d)\n",__FILE__,__LINE__); \
} \
} \
while(0)

#endif // _MSVC_

#define VERIFY ASSERT

#else // non-debug build...

#ifdef _MSVC_

#define TRACE __noop
#undef ASSERT /* For VS9 2008 */
#define ASSERT(a) __noop
#define VERIFY(a) ((void)(a))

#else // ! _MSVC_

#define TRACE 1 ? ((void)0) : logmsg
#define ASSERT(a)
#define VERIFY(a) ((void)(a))

#endif // _MSVC_

#endif

/* Opcode routing table function pointer */
typedef void (ATTR_REGPARM(2)*FUNC)();

Expand Down
1 change: 1 addition & 0 deletions hstdinc.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,6 @@

#include "hostopts.h" // Must come before htypes.h
#include "htypes.h" // Hercules-wide data types
#include "dbgtrace.h" // Hercules default debugging

#endif // _HSTDINC_H
19 changes: 2 additions & 17 deletions omatape.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

/*-------------------------------------------------------------------*/
/* This module contains the OMATAPE emulated tape format support. */
/* */
/* The subroutines in this module are called by the general tape */
/* device handler (tapedev.c) when the tape format is OMATAPE. */
/*-------------------------------------------------------------------*/

/*-------------------------------------------------------------------*/
/* Reference information: */
/* SC53-1200 S/370 and S/390 Optical Media Attach/2 User's Guide */
Expand All @@ -28,21 +26,8 @@
#include "hercules.h" /* need Hercules control blocks */
#include "tapedev.h" /* Main tape handler header file */

//#define ENABLE_TRACING_STMTS // (Fish: DEBUGGING)

#ifdef ENABLE_TRACING_STMTS
#if !defined(DEBUG)
#warning DEBUG required for ENABLE_TRACING_STMTS
#endif
// (TRACE, ASSERT, and VERIFY macros are #defined in hmacros.h)
#else
#undef TRACE
#undef ASSERT
#undef VERIFY
#define TRACE 1 ? ((void)0) : logmsg
#define ASSERT(a)
#define VERIFY(a) ((void)(a))
#endif
//#define ENABLE_TRACING_STMTS 1 // (Fish: DEBUGGING)
//#include "dbgtrace.h" // (Fish: DEBUGGING)

/*-------------------------------------------------------------------*/
/* Read the OMA tape descriptor file */
Expand Down
Loading

0 comments on commit c485e9c

Please sign in to comment.