dvadura@watdragon.waterloo.edu (Dennis Vadura) (05/10/91)
Submitted-by: Dennis Vadura <dvadura@watdragon.waterloo.edu> Posting-number: Volume 19, Issue 23 Archive-name: dmake/part02 Supersedes: dmake-3.6: Volume 15, Issue 52-77 ---- Cut Here and feed the following to sh ---- #!/bin/sh # this is dmake.shar.02 (part 2 of a multipart archive) # do not concatenate these parts, unpack them in order with /bin/sh # file dmake/dag.c continued # if test ! -r _shar_seq_.tmp; then echo 'Please unpack part 1 first!' exit 1 fi (read Scheck if test "$Scheck" != 2; then echo Please unpack part "$Scheck" next! exit 1 else exit 0 fi ) < _shar_seq_.tmp || exit 1 if test -f _shar_wnt_.tmp; then sed 's/^X//' << 'SHAR_EOF' >> 'dmake/dag.c' && X switch( *rp++ ) X { X case '@' : flag |= A_SILENT; break; X case '-' : flag |= A_IGNORE; break; X case '+' : flag |= A_SHELL; break; X case '%' : flag |= A_SWAP; break; X X case ' ' : X case '\t': break; X X default: done = TRUE; break; X } X X return(flag); } SHAR_EOF chmod 0640 dmake/dag.c || echo 'restore of dmake/dag.c failed' Wc_c="`wc -c < 'dmake/dag.c'`" test 13797 -eq "$Wc_c" || echo 'dmake/dag.c: original size 13797, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= dmake/db.h ============== if test -f 'dmake/db.h' -a X"$1" != X"-c"; then echo 'x - skipping dmake/db.h (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp sed 's/^X//' << 'SHAR_EOF' > 'dmake/db.h' && /* RCS -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/db.h,v 1.1 91/05/06 15:23:05 dvadura Exp $ -- SYNOPSIS -- front end to DBUG macros. -- -- DESCRIPTION -- This is a front end to Fred Fish's DBUG macros. The intent was -- to provide an interface so that if you don't have the DBUG code -- you can still compile dmake, by undefining DBUG, if you do have -- the code then you can use Fred Fish's DBUG package. Originally -- the DBUG stuff was copyrighted, it is now in the public domain -- so the need for this is not as apparent. -- -- AUTHOR -- Dennis Vadura, dvadura@watdragon.uwaterloo.ca -- CS DEPT, University of Waterloo, Waterloo, Ont., Canada -- -- COPYRIGHT -- Copyright (c) 1990 by Dennis Vadura. All rights reserved. -- -- This program is free software; you can redistribute it and/or -- modify it under the terms of the GNU General Public License -- (version 1), as published by the Free Software Foundation, and -- found in the file 'LICENSE' included with this distribution. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warrant of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -- -- LOG -- $Log: db.h,v $ X * Revision 1.1 91/05/06 15:23:05 dvadura X * dmake Release Version 3.7 X * */ X #ifndef DB_h #define DB_h X #ifdef DBUG X # include "dbug.h" X # define DB_ENTER(a1) DBUG_ENTER(a1) # define DB_RETURN(a1) DBUG_RETURN(a1) # define DB_VOID_RETURN DBUG_VOID_RETURN # define DB_EXECUTE(keyword, a1) DBUG_EXECUTE(keyword,a1) # define DB_PRINT(keyword,arglist) DBUG_PRINT(keyword,arglist) # define DB_PUSH(a1) DBUG_PUSH(a1) # define DB_POP() DBUG_POP() # define DB_PROCESS(a1) DBUG_PROCESS(a1) # define DB_FILE (stderr) DBUG_FILE(stderr) # define DB_SETJMP DBUG_SETJMP # define DB_LONGJMP DBUG_LONGJMP X #else X # define DB_ENTER(a1) # define DB_RETURN(a1) return (a1) # define DB_VOID_RETURN return # define DB_EXECUTE(keyword, a1) # define DB_PRINT(keyword,arglist) # define DB_PUSH(a1) # define DB_POP() # define DB_PROCESS(a1) # define DB_FILE(stderr) # define DB_SETJMP setjmp # define DB_LONGJMP longjmp X #endif #endif X SHAR_EOF chmod 0640 dmake/db.h || echo 'restore of dmake/db.h failed' Wc_c="`wc -c < 'dmake/db.h'`" test 2696 -eq "$Wc_c" || echo 'dmake/db.h: original size 2696, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= dmake/dbug/README ============== if test ! -d 'dmake/dbug'; then mkdir 'dmake/dbug' fi if test -f 'dmake/dbug/README' -a X"$1" != X"-c"; then echo 'x - skipping dmake/dbug/README (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/README' && This directory contains two public domain debugging packages. X X 1. Fred Fishes DEBUG macros. X 2. Connor P. Cahills malloc library. X Descriptions of both can be found in their respective sub-directories. dbug for the DEBUG macros and malloc for the malloc library. I have left the malloc distribution intact as it comes from the net except for the changes noted in the _changes file. X I thank the authors for making them available for others to use. X -dennis SHAR_EOF chmod 0640 dmake/dbug/README || echo 'restore of dmake/dbug/README failed' Wc_c="`wc -c < 'dmake/dbug/README'`" test 460 -eq "$Wc_c" || echo 'dmake/dbug/README: original size 460, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= dmake/dbug/dbug.mk ============== if test -f 'dmake/dbug/dbug.mk' -a X"$1" != X"-c"; then echo 'x - skipping dmake/dbug/dbug.mk (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/dbug.mk' && # Set the proper macros based on whether we are making the debugging version # or not. The valid parameters to this file are: # # DEBUG=1 ==> enable the making of the DBUG version # DBMALLOC=1 ==> enable DBUG version with extensive MALLOC checking # # DB_CFLAGS ==> CFLAGS is set to this value at the end if DEBUG=1 # DB_LDFLAGS ==> LDFLAGS is set to this at the end if DEBUG=1 # DB_LDLIBS ==> LDLIBS is set to this at end if DEBUG=1 # # The non debug versions of the above three macros are: # # NDB_CFLAGS # NDB_LDFLAGS # NDB_LDLIBS # # One of the set of three should have values set appropriately prior to # sourcing this file. X .IF $(DEBUG) X DBUG_SRC += dbug.c X DB_CFLAGS += -Idbug/dbug X X .SETDIR=dbug/dbug : $(DBUG_SRC) X X # If DBMALLOC is requested (ie non-NULL) then include the sources for X # compilation. BSD 4.3 needs the getwd.c source compiled in due to a bug X # in the clib getwd routine. X .IF $(DBMALLOC) X # Serious bug in bsd43 getwd.c would free a string and then use its X # value. The DBMALLOC code clears a string when it is free'd so the X # value was no longer valid and the returned path for the current X # directory was now completely wrong. X .IF $(OSRELEASE) == bsd43 X GETWD_SRC += getwd.c X .SETDIR=dbug : $(GETWD_SRC) X .END X X MLC_SRC += malloc.c free.c realloc.c calloc.c string.c\ X mlc_chk.c mlc_chn.c memory.c tostring.c m_perror.c\ X m_init.c mallopt.c dump.c X X .SETDIR=dbug/malloc : $(MLC_SRC) X X DB_CFLAGS += -Idbug/malloc X .END X X SRC += $(DBUG_SRC) $(MLC_SRC) $(GETWD_SRC) X HDR += db.h X X LDFLAGS += $(DB_LDFLAGS) X LDLIBS += $(DB_LDLIBS) X X SILENT := $(.SILENT) X .SILENT := yes X TARGET := db$(TARGET) X OBJDIR := $(OBJDIR).dbg X .SILENT := $(SILENT) X X CFLAGS += $(DB_CFLAGS) X .KEEP_STATE := _dbstate.mk .ELSE X CFLAGS += $(NDB_CFLAGS) X LDFLAGS += $(NDB_LDFLAGS) X LDLIBS += $(NDB_LDLIBS) .END SHAR_EOF chmod 0640 dmake/dbug/dbug.mk || echo 'restore of dmake/dbug/dbug.mk failed' Wc_c="`wc -c < 'dmake/dbug/dbug.mk'`" test 1955 -eq "$Wc_c" || echo 'dmake/dbug/dbug.mk: original size 1955, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= dmake/dbug/dbug/dbug.c ============== if test ! -d 'dmake/dbug/dbug'; then mkdir 'dmake/dbug/dbug' fi if test -f 'dmake/dbug/dbug/dbug.c' -a X"$1" != X"-c"; then echo 'x - skipping dmake/dbug/dbug/dbug.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/dbug/dbug.c' && /****************************************************************************** X * * X * N O T I C E * X * * X * Copyright Abandoned, 1987, Fred Fish * X * * X * * X * This previously copyrighted work has been placed into the public * X * domain by the author and may be freely used for any purpose, * X * private or commercial. * X * * X * Because of the number of inquiries I was receiving about the use * X * of this product in commercially developed works I have decided to * X * simply make it public domain to further its unrestricted use. I * X * specifically would be most happy to see this material become a * X * part of the standard Unix distributions by AT&T and the Berkeley * X * Computer Science Research Group, and a standard part of the GNU * X * system from the Free Software Foundation. * X * * X * I would appreciate it, as a courtesy, if this notice is left in * X * all copies and derivative works. Thank you. * X * * X * The author makes no warranty of any kind with respect to this * X * product and explicitly disclaims any implied warranties of mer- * X * chantability or fitness for any particular purpose. * X * * X ****************************************************************************** X */ X X /* X * FILE X * X * dbug.c runtime support routines for dbug package X * X * SCCS X * X * @(#)dbug.c 1.19 9/5/87 X * X * DESCRIPTION X * X * These are the runtime support routines for the dbug package. X * The dbug package has two main components; the user include X * file containing various macro definitions, and the runtime X * support routines which are called from the macro expansions. X * X * Externally visible functions in the runtime support module X * use the naming convention pattern "_db_xx...xx_", thus X * they are unlikely to collide with user defined function names. X * X * AUTHOR(S) X * X * Fred Fish (base code) X * (Currently at Motorola Computer Division, Tempe, Az.) X * hao!noao!mcdsun!fnf X * (602) 438-3614 X * X * Binayak Banerjee (profiling enhancements) X * seismo!bpa!sjuvax!bbanerje X */ X X #include <stdio.h> #ifdef amiga #define AMIGA #endif X #ifdef AMIGA #define HZ (50) /* Probably in some header somewhere */ #endif X /* X * Manifest constants that should not require any changes. X */ X #define FALSE 0 /* Boolean FALSE */ #define TRUE 1 /* Boolean TRUE */ #define EOS '\000' /* End Of String marker */ X /* X * Manifest constants which may be "tuned" if desired. X */ X #define PRINTBUF 1024 /* Print buffer size */ #define INDENT 4 /* Indentation per trace level */ #define MAXDEPTH 200 /* Maximum trace depth default */ X /* X * The following flags are used to determine which X * capabilities the user has enabled with the state X * push macro. X */ X #define TRACE_ON 000001 /* Trace enabled */ #define DEBUG_ON 000002 /* Debug enabled */ #define FILE_ON 000004 /* File name print enabled */ #define LINE_ON 000010 /* Line number print enabled */ #define DEPTH_ON 000020 /* Function nest level print enabled */ #define PROCESS_ON 000040 /* Process name print enabled */ #define NUMBER_ON 000100 /* Number each line of output */ #define PROFILE_ON 000200 /* Print out profiling code */ X #define TRACING (stack -> flags & TRACE_ON) #define DEBUGGING (stack -> flags & DEBUG_ON) #define PROFILING (stack -> flags & PROFILE_ON) #define STREQ(a,b) (strcmp(a,b) == 0) X /* X * Typedefs to make things more obvious. X */ X #define VOID void /* Can't use typedef for most compilers */ typedef int BOOLEAN; X /* X * Make it easy to change storage classes if necessary. X */ X #define LOCAL static /* Names not needed by outside world */ #define IMPORT extern /* Names defined externally */ #define EXPORT /* Allocated here, available globally */ #define AUTO auto /* Names to be allocated on stack */ #define REGISTER register /* Names to be placed in registers */ X /* X * The following define is for the variable arguments kluge, see X * the comments in _db_doprnt_(). X * X * Also note that the longer this list, the less prone to failing X * on long argument lists, but the more stuff that must be moved X * around for each call to the runtime support routines. The X * length may really be critical if the machine convention is X * to pass arguments in registers. X * X * Note that the default define allows up to 16 integral arguments, X * or 8 floating point arguments (doubles), on most machines. X * X * Someday this may be replaced with true varargs support, when X * ANSI C has had time to take root. X */ X #define ARGLIST a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15 X /* X * The default file for profiling. Could also add another flag X * (G?) which allowed the user to specify this. X */ X #define PROF_FILE "dbugmon.out" X /* X * Variables which are available externally but should only X * be accessed via the macro package facilities. X */ X EXPORT FILE *_db_fp_ = stderr; /* Output stream, default stderr */ EXPORT FILE *_db_pfp_ = (FILE *)0; /* Profile stream, 'dbugmon.out' */ EXPORT char *_db_process_ = "dbug"; /* Pointer to process name; argv[0] */ EXPORT BOOLEAN _db_on_ = FALSE; /* TRUE if debugging currently on */ EXPORT BOOLEAN _db_pon_ = FALSE; /* TRUE if debugging currently on */ X /* X * Externally supplied functions. X */ X #ifdef unix /* Only needed for unix */ IMPORT VOID perror (); /* Print system/library error */ IMPORT int chown (); /* Change owner of a file */ IMPORT int getgid (); /* Get real group id */ IMPORT int getuid (); /* Get real user id */ IMPORT int access (); /* Test file for access */ #else #if !(AMIGA || LATTICE || __TURBOC__) LOCAL VOID perror (); /* Fake system/library error print routine */ #endif #endif X # if BSD4_3 || sun IMPORT int getrusage (); #endif X IMPORT int atoi (); /* Convert ascii to integer */ IMPORT VOID exit (); /* Terminate execution */ IMPORT int fclose (); /* Close a stream */ IMPORT FILE *fopen (); /* Open a stream */ #if !defined(__BORLANDC__) IMPORT int fprintf (); /* Formatted print on file */ #endif IMPORT VOID free (); IMPORT char *malloc (); /* Allocate memory */ IMPORT int strcmp (); /* Compare strings */ IMPORT char *strcpy (); /* Copy strings around */ IMPORT int strlen (); /* Find length of string */ X #ifndef fflush /* This is sometimes a macro */ IMPORT int fflush (); /* Flush output for stream */ #endif X X /* X * The user may specify a list of functions to trace or X * debug. These lists are kept in a linear linked list, X * a very simple implementation. X */ X struct link { X char *string; /* Pointer to link's contents */ X struct link *next_link; /* Pointer to the next link */ }; X X /* X * Debugging states can be pushed or popped off of a X * stack which is implemented as a linked list. Note X * that the head of the list is the current state and the X * stack is pushed by adding a new state to the head of the X * list or popped by removing the first link. X */ X struct state { X int flags; /* Current state flags */ X int maxdepth; /* Current maximum trace depth */ X unsigned int delay; /* Delay after each output line */ X int level; /* Current function nesting level */ X FILE *out_file; /* Current output stream */ X FILE *prof_file; /* Current profiling stream */ X struct link *functions; /* List of functions */ X struct link *p_functions; /* List of profiled functions */ X struct link *keywords; /* List of debug keywords */ X struct link *processes; /* List of process names */ X struct state *next_state; /* Next state in the list */ }; X LOCAL struct state *stack = NULL; /* Linked list of stacked states */ X /* X * Local variables not seen by user. X */ X LOCAL int lineno = 0; /* Current debugger output line number */ LOCAL char *func = "?func"; /* Name of current user function */ LOCAL char *file = "?file"; /* Name of current user file */ LOCAL BOOLEAN init_done = FALSE;/* Set to TRUE when initialization done */ X /*#if unix || AMIGA || M_I86*/ LOCAL int jmplevel; /* Remember nesting level at setjmp () */ LOCAL char *jmpfunc; /* Remember current function for setjmp */ LOCAL char *jmpfile; /* Remember current file for setjmp */ /*#endif*/ X LOCAL struct link *ListParse ();/* Parse a debug command string */ LOCAL char *StrDup (); /* Make a fresh copy of a string */ LOCAL VOID OpenFile (); /* Open debug output stream */ LOCAL VOID OpenProfile (); /* Open profile output stream */ LOCAL VOID CloseFile (); /* Close debug output stream */ LOCAL VOID PushState (); /* Push current debug state */ LOCAL VOID ChangeOwner (); /* Change file owner and group */ LOCAL BOOLEAN DoTrace (); /* Test for tracing enabled */ LOCAL BOOLEAN Writable (); /* Test to see if file is writable */ LOCAL unsigned long Clock (); /* Return current user time (ms) */ LOCAL char *DbugMalloc (); /* Allocate memory for runtime support */ LOCAL char *BaseName (); /* Remove leading pathname components */ LOCAL VOID DoPrefix (); /* Print debugger line prefix */ LOCAL VOID FreeList (); /* Free memory from linked list */ LOCAL VOID Indent (); /* Indent line to specified indent */ X X /* Supplied in Sys V runtime environ */ LOCAL char *strtok (); /* Break string into tokens */ LOCAL char *strrchr (); /* Find last occurance of char */ X /* X * The following local variables are used to hold the state information X * between the call to _db_pargs_() and _db_doprnt_(), during X * expansion of the DBUG_PRINT macro. This is the only macro X * that currently uses these variables. The DBUG_PRINT macro X * and the new _db_doprnt_() routine replace the older DBUG_N macros X * and their corresponding runtime support routine _db_printf_(). X * X * These variables are currently used only by _db_pargs_() and X * _db_doprnt_(). X */ X LOCAL int u_line = 0; /* User source code line number */ LOCAL char *u_keyword = "?"; /* Keyword for current macro */ X /* X * Miscellaneous printf format strings. X */ X #define ERR_MISSING_RETURN "%s: missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n" #define ERR_OPEN "%s: can't open debug output stream \"%s\": " #define ERR_CLOSE "%s: can't close debug file: " #define ERR_ABORT "%s: debugger aborting because %s\n" #define ERR_CHOWN "%s: can't change owner/group of \"%s\": " #define ERR_PRINTF "%s: obsolete object file for '%s', please recompile!\n" X /* X * Macros and defines for testing file accessibility under UNIX. X */ X #ifdef unix # define A_EXISTS 00 /* Test for file existance */ # define A_EXECUTE 01 /* Test for execute permission */ # define A_WRITE 02 /* Test for write access */ # define A_READ 03 /* Test for read access */ # define EXISTS(pathname) (access (pathname, A_EXISTS) == 0) # define WRITABLE(pathname) (access (pathname, A_WRITE) == 0) #else # define EXISTS(pathname) (FALSE) /* Assume no existance */ #endif X /* X * Translate some calls among different systems. X */ X #ifdef unix # define XDelay sleep IMPORT unsigned int sleep (); /* Pause for given number of seconds */ #endif X #ifdef AMIGA IMPORT int XDelay (); /* Pause for given number of ticks */ #endif X X /* X * FUNCTION X * X * _db_push_ push current debugger state and set up new one X * X * SYNOPSIS X * X * VOID _db_push_ (control) X * char *control; X * X * DESCRIPTION X * X * Given pointer to a debug control string in "control", pushes X * the current debug state, parses the control string, and sets X * up a new debug state. X * X * The only attribute of the new state inherited from the previous X * state is the current function nesting level. This can be X * overridden by using the "r" flag in the control string. X * X * The debug control string is a sequence of colon separated fields X * as follows: X * X * <field_1>:<field_2>:...:<field_N> X * X * Each field consists of a mandatory flag character followed by X * an optional "," and comma separated list of modifiers: X * X * flag[,modifier,modifier,...,modifier] X * X * The currently recognized flag characters are: X * X * d Enable output from DBUG_<N> macros for X * for the current state. May be followed X * by a list of keywords which selects output X * only for the DBUG macros with that keyword. X * A null list of keywords implies output for X * all macros. X * X * D Delay after each debugger output line. X * The argument is the number of tenths of seconds X * to delay, subject to machine capabilities. X * I.E. -#D,20 is delay two seconds. X * X * f Limit debugging and/or tracing, and profiling to the X * list of named functions. Note that a null list will X * disable all functions. The appropriate "d" or "t" X * flags must still be given, this flag only limits their X * actions if they are enabled. X * X * F Identify the source file name for each X * line of debug or trace output. X * X * g Enable profiling. Create a file called 'dbugmon.out' X * containing information that can be used to profile X * the program. May be followed by a list of keywords X * that select profiling only for the functions in that X * list. A null list implies that all functions are X * considered. X * X * L Identify the source file line number for X * each line of debug or trace output. X * X * n Print the current function nesting depth for X * each line of debug or trace output. X * X * N Number each line of dbug output. X * X * p Limit debugger actions to specified processes. X * A process must be identified with the X * DBUG_PROCESS macro and match one in the list X * for debugger actions to occur. X * X * P Print the current process name for each X * line of debug or trace output. X * X * r When pushing a new state, do not inherit X * the previous state's function nesting level. X * Useful when the output is to start at the X * left margin. X * X * t Enable function call/exit trace lines. X * May be followed by a list (containing only X * one modifier) giving a numeric maximum X * trace level, beyond which no output will X * occur for either debugging or tracing X * macros. The default is a compile time X * option. X * X * Some examples of debug control strings which might appear X * on a shell command line (the "-#" is typically used to X * introduce a control string to an application program) are: X * X * -#d:t X * -#d:f,main,subr1:F:L:t,20 X * -#d,input,output,files:n X * X * For convenience, any leading "-#" is stripped off. X * X */ X X VOID _db_push_ (control) char *control; { X REGISTER char *scan; X REGISTER struct link *temp; X X if (control && *control == '-') { X if (*++control == '#') { X control++; X } X } X control = StrDup (control); X PushState (); X scan = strtok (control, ":"); X for (; scan != NULL; scan = strtok ((char *)NULL, ":")) { X switch (*scan++) { X case 'd': X _db_on_ = TRUE; X stack -> flags |= DEBUG_ON; X if (*scan++ == ',') { X stack -> keywords = ListParse (scan); X } X break; X case 'D': X stack -> delay = 0; X if (*scan++ == ',') { X temp = ListParse (scan); X stack -> delay = DelayArg (atoi (temp -> string)); X FreeList (temp); X } X break; X case 'f': X if (*scan++ == ',') { X stack -> functions = ListParse (scan); X } X break; X case 'F': X stack -> flags |= FILE_ON; X break; X case 'g': X _db_pon_ = TRUE; X OpenProfile(PROF_FILE); X stack -> flags |= PROFILE_ON; X if (*scan++ == ',') { X stack -> p_functions = ListParse (scan); X } X break; X case 'L': X stack -> flags |= LINE_ON; X break; X case 'n': X stack -> flags |= DEPTH_ON; X break; X case 'N': X stack -> flags |= NUMBER_ON; X break; X case 'o': X if (*scan++ == ',') { X temp = ListParse (scan); X OpenFile (temp -> string); X FreeList (temp); X } else { X OpenFile ("-"); X } X break; X case 'p': X if (*scan++ == ',') { X stack -> processes = ListParse (scan); X } X break; X case 'P': X stack -> flags |= PROCESS_ON; X break; X case 'r': X stack -> level = 0; X break; X case 't': X stack -> flags |= TRACE_ON; X if (*scan++ == ',') { X temp = ListParse (scan); X stack -> maxdepth = atoi (temp -> string); X FreeList (temp); X } X break; X } X } X free (control); } X X X /* X * FUNCTION X * X * _db_pop_ pop the debug stack X * X * DESCRIPTION X * X * Pops the debug stack, returning the debug state to its X * condition prior to the most recent _db_push_ invocation. X * Note that the pop will fail if it would remove the last X * valid state from the stack. This prevents user errors X * in the push/pop sequence from screwing up the debugger. X * Maybe there should be some kind of warning printed if the X * user tries to pop too many states. X * X */ X VOID _db_pop_ () { X REGISTER struct state *discard; X X discard = stack; X if (discard != NULL && discard -> next_state != NULL) { X stack = discard -> next_state; X _db_fp_ = stack -> out_file; X _db_pfp_ = stack -> prof_file; X if (discard -> keywords != NULL) { X FreeList (discard -> keywords); X } X if (discard -> functions != NULL) { X FreeList (discard -> functions); X } X if (discard -> processes != NULL) { X FreeList (discard -> processes); X } X if (discard -> p_functions != NULL) { X FreeList (discard -> p_functions); X } X CloseFile (discard -> out_file); X CloseFile (discard -> prof_file); X free ((char *) discard); X } } X X /* X * FUNCTION X * X * _db_enter_ process entry point to user function X * X * SYNOPSIS X * X * VOID _db_enter_ (_func_, _file_, _line_, _sfunc_, _sfile_, _slevel_) X * char *_func_; points to current function name X * char *_file_; points to current file name X * int _line_; called from source line number X * char **_sfunc_; save previous _func_ X * char **_sfile_; save previous _file_ X * int *_slevel_; save previous nesting level X * X * DESCRIPTION X * X * Called at the beginning of each user function to tell X * the debugger that a new function has been entered. X * Note that the pointers to the previous user function X * name and previous user file name are stored on the X * caller's stack (this is why the ENTER macro must be X * the first "executable" code in a function, since it X * allocates these storage locations). The previous nesting X * level is also stored on the callers stack for internal X * self consistency checks. X * X * Also prints a trace line if tracing is enabled and X * increments the current function nesting depth. X * X * Note that this mechanism allows the debugger to know X * what the current user function is at all times, without X * maintaining an internal stack for the function names. X * X */ X VOID _db_enter_ (_func_, _file_, _line_, _sfunc_, _sfile_, _slevel_) char *_func_; char *_file_; int _line_; char **_sfunc_; char **_sfile_; int *_slevel_; { X if (!init_done) { X _db_push_ (""); X } X *_sfunc_ = func; X *_sfile_ = file; X func = _func_; X file = BaseName (_file_); X stack -> level++; X *_slevel_ = stack -> level; X if (DoProfile ()) { X (VOID) fprintf (_db_pfp_, "%s\tE\t%ld\n",func, Clock()); X (VOID) fflush (_db_pfp_); X } X if (DoTrace ()) { X DoPrefix (_line_); X Indent (stack -> level); X (VOID) fprintf (_db_fp_, ">%s\n", func); X (VOID) fflush (_db_fp_); X (VOID) XDelay (stack -> delay); X } } X X /* X * FUNCTION X * X * _db_return_ process exit from user function X * X * SYNOPSIS X * X * VOID _db_return_ (_line_, _sfunc_, _sfile_, _slevel_) X * int _line_; current source line number X * char **_sfunc_; where previous _func_ is to be retrieved X * char **_sfile_; where previous _file_ is to be retrieved X * int *_slevel_; where previous level was stashed X * X * DESCRIPTION X * X * Called just before user function executes an explicit or implicit X * return. Prints a trace line if trace is enabled, decrements X * the current nesting level, and restores the current function and X * file names from the defunct function's stack. X * X */ X VOID _db_return_ (_line_, _sfunc_, _sfile_, _slevel_) int _line_; char **_sfunc_; char **_sfile_; int *_slevel_; { X if (!init_done) { X _db_push_ (""); X } X if (stack -> level != *_slevel_ && (TRACING || DEBUGGING || PROFILING)) { X (VOID) fprintf (_db_fp_, ERR_MISSING_RETURN, _db_process_, func); X (VOID) XDelay (stack -> delay); X } else if (DoProfile ()) { X (VOID) fprintf (_db_pfp_, "%s\tX\t%ld\n", func, Clock()); X (VOID) XDelay (stack -> delay); X } else if (DoTrace ()) { X DoPrefix (_line_); X Indent (stack -> level); X (VOID) fprintf (_db_fp_, "<%s\n", func); X (VOID) XDelay (stack -> delay); X } X (VOID) fflush (_db_fp_); X stack -> level = *_slevel_ - 1; X func = *_sfunc_; X file = *_sfile_; } X X /* X * FUNCTION X * X * _db_pargs_ log arguments for subsequent use by _db_doprnt_() X * X * SYNOPSIS X * X * VOID _db_pargs_ (_line_, keyword) X * int _line_; X * char *keyword; X * X * DESCRIPTION X * X * The new universal printing macro DBUG_PRINT, which replaces X * all forms of the DBUG_N macros, needs two calls to runtime X * support routines. The first, this function, remembers arguments X * that are used by the subsequent call to _db_doprnt_(). * X */ X VOID _db_pargs_ (_line_, keyword) int _line_; char *keyword; { X u_line = _line_; X u_keyword = keyword; } X X /* X * FUNCTION X * X * _db_doprnt_ handle print of debug lines X * X * SYNOPSIS X * X * VOID _db_doprnt_ (format, ARGLIST) X * char *format; X * long ARGLIST; X * X * DESCRIPTION X * X * When invoked via one of the DBUG macros, tests the current keyword X * set by calling _db_pargs_() to see if that macro has been selected X * for processing via the debugger control string, and if so, handles X * printing of the arguments via the format string. The line number X * of the DBUG macro in the source is found in u_line. X * X * Note that the format string SHOULD NOT include a terminating X * newline, this is supplied automatically. X * X * NOTES X * X * This runtime support routine replaces the older _db_printf_() X * routine which is temporarily kept around for compatibility. X * X * The rather ugly argument declaration is to handle some X * magic with respect to the number of arguments passed X * via the DBUG macros. The current maximum is 3 arguments X * (not including the keyword and format strings). X * X * The new <varargs.h> facility is not yet common enough to X * convert to it quite yet... X * X */ X /*VARARGS1*/ VOID _db_doprnt_ (format, ARGLIST) char *format; long ARGLIST; { X if (_db_keyword_ (u_keyword)) { X DoPrefix (u_line); X if (TRACING) { X Indent (stack -> level + 1); X } else { X (VOID) fprintf (_db_fp_, "%s: ", func); X } X (VOID) fprintf (_db_fp_, "%s: ", u_keyword); X (VOID) fprintf (_db_fp_, format, ARGLIST); X (VOID) fprintf (_db_fp_, "\n"); X (VOID) fflush (_db_fp_); X (VOID) XDelay (stack -> delay); X } } X /* X * The following routine is kept around temporarily for compatibility X * with older objects that were compiled with the DBUG_N macro form X * of the print routine. It will print a warning message on first X * usage. It will go away in subsequent releases... X */ X /*VARARGS3*/ VOID _db_printf_ (_line_, keyword, format, ARGLIST) int _line_; char *keyword, *format; long ARGLIST; { X static BOOLEAN firsttime = TRUE; X X if (firsttime) { X (VOID) fprintf (stderr, ERR_PRINTF, _db_process_, file); X firsttime = FALSE; X } X _db_pargs_ (_line_, keyword); X _db_doprnt_ (format, ARGLIST); } X X /* X * FUNCTION X * X * ListParse parse list of modifiers in debug control string X * X * SYNOPSIS X * X * LOCAL struct link *ListParse (ctlp) X * char *ctlp; X * X * DESCRIPTION X * X * Given pointer to a comma separated list of strings in "cltp", X * parses the list, building a list and returning a pointer to it. X * The original comma separated list is destroyed in the process of X * building the linked list, thus it had better be a duplicate X * if it is important. X * X * Note that since each link is added at the head of the list, X * the final list will be in "reverse order", which is not X * significant for our usage here. X * X */ X LOCAL struct link *ListParse (ctlp) char *ctlp; { X REGISTER char *start; X REGISTER struct link *new; X REGISTER struct link *head; X X head = NULL; X while (*ctlp != EOS) { X start = ctlp; X while (*ctlp != EOS && *ctlp != ',') { X ctlp++; X } X if (*ctlp == ',') { X *ctlp++ = EOS; X } X new = (struct link *) DbugMalloc (sizeof (struct link)); X new -> string = StrDup (start); X new -> next_link = head; X head = new; X } X return (head); } X X /* X * FUNCTION X * X * InList test a given string for member of a given list X * X * SYNOPSIS X * X * LOCAL BOOLEAN InList (linkp, cp) X * struct link *linkp; X * char *cp; X * X * DESCRIPTION X * X * Tests the string pointed to by "cp" to determine if it is in X * the list pointed to by "linkp". Linkp points to the first X * link in the list. If linkp is NULL then the string is treated X * as if it is in the list (I.E all strings are in the null list). X * This may seem rather strange at first but leads to the desired X * operation if no list is given. The net effect is that all X * strings will be accepted when there is no list, and when there X * is a list, only those strings in the list will be accepted. X * X */ X LOCAL BOOLEAN InList (linkp, cp) struct link *linkp; char *cp; { X REGISTER struct link *scan; X REGISTER BOOLEAN accept; X X if (linkp == NULL) { X accept = TRUE; X } else { X accept = FALSE; X for (scan = linkp; scan != NULL; scan = scan -> next_link) { X if (STREQ (scan -> string, cp)) { X accept = TRUE; X break; X } X } X } X return (accept); } X X /* X * FUNCTION X * X * PushState push current state onto stack and set up new one X * X * SYNOPSIS X * X * LOCAL VOID PushState () X * X * DESCRIPTION X * X * Pushes the current state on the state stack, and initializes X * a new state. The only parameter inherited from the previous X * state is the function nesting level. This action can be X * inhibited if desired, via the "r" flag. X * X * The state stack is a linked list of states, with the new X * state added at the head. This allows the stack to grow X * to the limits of memory if necessary. X * X */ X LOCAL VOID PushState () { X REGISTER struct state *new; X X new = (struct state *) DbugMalloc (sizeof (struct state)); X new -> flags = 0; X new -> delay = 0; X new -> maxdepth = MAXDEPTH; X if (stack != NULL) { X new -> level = stack -> level; X } else { X new -> level = 0; X } X new -> out_file = stderr; X new -> functions = NULL; X new -> p_functions = NULL; X new -> keywords = NULL; X new -> processes = NULL; X new -> next_state = stack; X stack = new; X init_done = TRUE; } X X /* X * FUNCTION X * X * DoTrace check to see if tracing is current enabled X * X * SYNOPSIS X * X * LOCAL BOOLEAN DoTrace () X * X * DESCRIPTION X * X * Checks to see if tracing is enabled based on whether the X * user has specified tracing, the maximum trace depth has X * not yet been reached, the current function is selected, X * and the current process is selected. Returns TRUE if X * tracing is enabled, FALSE otherwise. X * X */ X LOCAL BOOLEAN DoTrace () { X REGISTER BOOLEAN trace; X X trace = FALSE; X if (TRACING) { X if (stack -> level <= stack -> maxdepth) { X if (InList (stack -> functions, func)) { X if (InList (stack -> processes, _db_process_)) { X trace = TRUE; X } X } X } X } X return (trace); } X X /* X * FUNCTION X * X * DoProfile check to see if profiling is current enabled X * X * SYNOPSIS X * X * LOCAL BOOLEAN DoProfile () X * X * DESCRIPTION X * X * Checks to see if profiling is enabled based on whether the X * user has specified profiling, the maximum trace depth has X * not yet been reached, the current function is selected, X * and the current process is selected. Returns TRUE if X * profiling is enabled, FALSE otherwise. X * X */ X LOCAL BOOLEAN DoProfile () { X REGISTER BOOLEAN profile; X X profile = FALSE; X if (PROFILING) { X if (stack -> level <= stack -> maxdepth) { X if (InList (stack -> p_functions, func)) { X if (InList (stack -> processes, _db_process_)) { X profile = TRUE; X } X } X } X } X return (profile); } X X /* X * FUNCTION X * X * _db_keyword_ test keyword for member of keyword list X * X * SYNOPSIS X * X * BOOLEAN _db_keyword_ (keyword) X * char *keyword; X * X * DESCRIPTION X * X * Test a keyword to determine if it is in the currently active X * keyword list. As with the function list, a keyword is accepted X * if the list is null, otherwise it must match one of the list X * members. When debugging is not on, no keywords are accepted. X * After the maximum trace level is exceeded, no keywords are X * accepted (this behavior subject to change). Additionally, X * the current function and process must be accepted based on X * their respective lists. X * X * Returns TRUE if keyword accepted, FALSE otherwise. X * X */ X BOOLEAN _db_keyword_ (keyword) char *keyword; { X REGISTER BOOLEAN accept; X X if (!init_done) { X _db_push_ (""); X } X accept = FALSE; X if (DEBUGGING) { X if (stack -> level <= stack -> maxdepth) { X if (InList (stack -> functions, func)) { X if (InList (stack -> keywords, keyword)) { X if (InList (stack -> processes, _db_process_)) { X accept = TRUE; X } X } X } X } X } X return (accept); } X X /* X * FUNCTION X * X * Indent indent a line to the given indentation level X * X * SYNOPSIS X * X * LOCAL VOID Indent (indent) X * int indent; X * X * DESCRIPTION X * X * Indent a line to the given level. Note that this is X * a simple minded but portable implementation. X * There are better ways. X * X * Also, the indent must be scaled by the compile time option X * of character positions per nesting level. X * X */ X LOCAL VOID Indent (indent) int indent; { X REGISTER int count; X AUTO char buffer[PRINTBUF]; X X indent *= INDENT; X for (count = 0; (count < (indent - INDENT)) && (count < (PRINTBUF - 1)); count++) { X if ((count % INDENT) == 0) { X buffer[count] = '|'; X } else { X buffer[count] = ' '; X } X } X buffer[count] = EOS; X (VOID) fprintf (_db_fp_, buffer); X (VOID) fflush (_db_fp_); } X X /* X * FUNCTION X * X * FreeList free all memory associated with a linked list X * X * SYNOPSIS X * X * LOCAL VOID FreeList (linkp) X * struct link *linkp; X * X * DESCRIPTION X * X * Given pointer to the head of a linked list, frees all X * memory held by the list and the members of the list. X * X */ X LOCAL VOID FreeList (linkp) struct link *linkp; { X REGISTER struct link *old; X X while (linkp != NULL) { X old = linkp; X linkp = linkp -> next_link; X if (old -> string != NULL) { X free (old -> string); X } X free ((char *) old); X } } X X /* X * FUNCTION X * X * StrDup make a duplicate of a string in new memory X * X * SYNOPSIS X * X * LOCAL char *StrDup (string) X * char *string; X * X * DESCRIPTION X * X * Given pointer to a string, allocates sufficient memory to make X * a duplicate copy, and copies the string to the newly allocated X * memory. Failure to allocated sufficient memory is immediately X * fatal. X * X */ X X LOCAL char *StrDup (string) char *string; { X REGISTER char *new; X X new = DbugMalloc (strlen (string) + 1); X (VOID) strcpy (new, string); X return (new); } X X /* X * FUNCTION X * X * DoPrefix print debugger line prefix prior to indentation X * X * SYNOPSIS X * X * LOCAL VOID DoPrefix (_line_) X * int _line_; X * X * DESCRIPTION X * X * Print prefix common to all debugger output lines, prior to X * doing indentation if necessary. Print such information as SHAR_EOF true || echo 'restore of dmake/dbug/dbug/dbug.c failed' fi echo 'End of part 2, continue with part 3' echo 3 > _shar_seq_.tmp exit 0 exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.