v14i029: dmake version 3.5 part 19/21
Dennis Vadura
dvadura at watdragon.waterloo.edu
Fri Jul 27 09:48:30 AEST 1990
Posting-number: Volume 14, Issue 29
Submitted-by: dvadura at watdragon.waterloo.edu (Dennis Vadura)
Archive-name: dmake/part19
#!/bin/sh
# this is part 19 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file common/malloc.c continued
#
CurArch=19
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
exit 1; fi
( read Scheck
if test "$Scheck" != $CurArch
then echo "Please unpack part $Scheck next!"
exit 1;
else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file common/malloc.c"
sed 's/^X//' << 'SHAR_EOF' >> common/malloc.c
X }
X for (blk = _fab; blk != (struct _Dmi *) 0; blk = blk->m_next) {
X if ((char *) blk + sizeof *blk + blk->m_size - 1 > send) {
X _malldstr("(brk = ");
X _malldptr(send);
X _malldstr(", eblk = ");
X _malldptr((char *) blk + sizeof *blk + blk->m_size - 1);
X _malldstr(")\n");
X _mallerr(fn, "allocated block extends past brk: ", blk);
X }
X cnt = 0;
X for (cblk = _fab; cblk != (struct _Dmi *) 0; cblk = cblk->m_next) {
X if (blk == cblk)
X if (cnt++ == 0)
X continue;
X else
X _mallerr(fn, "block allocated twice: ", blk);
X if (blk > cblk && (char *) blk < (char *) cblk + sizeof *cblk + cblk->m_size - 1) {
X _malldstr("(blk = ");
X _malldptr(blk);
X _malldstr(", cblk = ");
X _malldptr((char *) cblk + sizeof *cblk + cblk->m_size - 1);
X _malldstr(")\n");
X _mallerr(fn, "nested block in allocated list: ", blk);
X }
X }
X for (cblk = _ffb; cblk != (struct _Dmi *) 0; cblk = cblk->m_next) {
X if (blk == cblk)
X _mallerr(fn, "block on allocated and free lists: ", blk);
X if (blk > cblk && (char *) blk < (char *) cblk + sizeof *cblk + cblk->m_size - 1) {
X _malldstr("(blk = ");
X _malldptr(blk);
X _malldstr(", cblk = ");
X _malldptr((char *) cblk + sizeof *cblk + cblk->m_size - 1);
X _malldstr(")\n");
X _mallerr(fn, "allocated block nested in free block: ", blk);
X }
X }
X }
X for (blk = _ffb; blk != (struct _Dmi *) 0; blk = blk->m_next) {
X if ((char *) blk + sizeof *blk + blk->m_size - 1 > send) {
X _malldstr("(brk = ");
X _malldptr(send);
X _malldstr(", eblk = ");
X _malldptr((char *) blk + sizeof *blk + blk->m_size - 1);
X _malldstr(")\n");
X _mallerr(fn, "free block extends past brk: ", blk);
X }
X cnt = 0;
X for (cblk = _ffb; cblk != (struct _Dmi *) 0; cblk = cblk->m_next) {
X if (blk == cblk)
X if (cnt++ == 0)
X continue;
X else
X _mallerr(fn, "block freed twice: ", blk);
X if (blk > cblk && (char *) blk < (char *) cblk + sizeof *cblk + cblk->m_size - 1) {
X _malldstr("(blk = ");
X _malldptr(blk);
X _malldstr(", cblk = ");
X _malldptr((char *) cblk + sizeof *cblk + cblk->m_size - 1);
X _malldstr(")\n");
X _mallerr(fn, "nested block in free list: ", blk);
X }
X }
X for (cblk = _fab; cblk != (struct _Dmi *) 0; cblk = cblk->m_next) {
X if (blk == cblk)
X _mallerr(fn, "block on allocated and free lists: ", blk);
X if (blk > cblk && (char *) blk < (char *) cblk + sizeof *cblk + cblk->m_size - 1) {
X _malldstr("(blk = ");
X _malldptr(blk);
X _malldstr(", cblk = ");
X _malldptr((char *) cblk + sizeof *cblk + cblk->m_size - 1);
X _malldstr(")\n");
X _mallerr(fn, "free block nested in allocated block: ", blk);
X }
X }
X }
X}
X
X/*
X * malloc objects and zero storage
X */
X
Xchar *calloc(n, size )
Xregister unsigned n, size;
X{
X register char *s, *s1;
X
X if (_mall_opt)
X {
X _malldstr("calloc: num: ");
X _malldptr(n);
X _malldstr( " size: " );
X _malldptr(size);
X _malldstr("\n");
X }
X n *= size;
X if ((s = malloc(n)) == (char *) 0)
X return (char *) 0;
X for (s1 = s; n != 0; n--)
X *s1++ = 0;
X return s;
X}
X
X/*
X * for some reason this is in /lib/libc.a(calloc.o)
X */
X
Xcfree(s)
Xchar *s; {
X free(s);
X}
X#endif
X#endif
X
SHAR_EOF
echo "File common/malloc.c is complete"
chmod 0440 common/malloc.c || echo "restore of common/malloc.c fails"
echo "x - extracting common/macros.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > common/macros.h &&
X/* RCS -- $Header: /u2/dvadura/src/generic/dmake/src/common/RCS/macros.h,v 1.1 90/07/19 13:30:46 dvadura Exp $
X-- SYNOPSIS -- general use macros.
X--
X-- DESCRIPTION
X-- ANSI macro relies on the fact that it can be replaced by (), or by
X-- its value, where the value is one value due to the preprocessors
X-- handling of arguments that are surrounded by ()'s as a single
X-- argument.
X--
X-- AUTHOR
X-- Dennis Vadura, dvadura at watdragon.uwaterloo.ca
X-- CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X-- Copyright (c) 1990 by Dennis Vadura. All rights reserved.
X--
X-- This program is free software; you can redistribute it and/or
X-- modify it under the terms of the GNU General Public License
X-- (version 1), as published by the Free Software Foundation, and
X-- found in the file 'LICENSE' included with this distribution.
X--
X-- This program is distributed in the hope that it will be useful,
X-- but WITHOUT ANY WARRANTY; without even the implied warrant of
X-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X-- GNU General Public License for more details.
X--
X-- You should have received a copy of the GNU General Public License
X-- along with this program; if not, write to the Free Software
X-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X-- $Log: macros.h,v $
X * Revision 1.1 90/07/19 13:30:46 dvadura
X * Initial Revision of Version 3.5
X *
X*/
X
X#ifndef MACROS_h
X#define MACROS_h
X
X#if defined(__STDC__) || defined(__TURBOC__)
X#define ANSI(x) x
X#else
X#define ANSI(x) ()
X#endif
X
X#define NIL(p) ((p*)NULL)
X#define offsetof(type,id) ((size_t)&((type*)NULL)->id)
X
X#define FALSE 0
X#define TRUE 1
X
X#endif
X
SHAR_EOF
chmod 0440 common/macros.h || echo "restore of common/macros.h fails"
echo "x - extracting common/itypes.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > common/itypes.h &&
X/* RCS -- $Header: /u2/dvadura/src/generic/dmake/src/common/RCS/itypes.h,v 1.1 90/07/19 13:30:45 dvadura Exp $
X-- SYNOPSIS -- type declarations for common types
X--
X-- DESCRIPTION
X-- portable type declarations.
X--
X-- AUTHOR
X-- Dennis Vadura, dvadura at watdragon.uwaterloo.ca
X-- CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X-- Copyright (c) 1990 by Dennis Vadura. All rights reserved.
X--
X-- This program is free software; you can redistribute it and/or
X-- modify it under the terms of the GNU General Public License
X-- (version 1), as published by the Free Software Foundation, and
X-- found in the file 'LICENSE' included with this distribution.
X--
X-- This program is distributed in the hope that it will be useful,
X-- but WITHOUT ANY WARRANTY; without even the implied warrant of
X-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X-- GNU General Public License for more details.
X--
X-- You should have received a copy of the GNU General Public License
X-- along with this program; if not, write to the Free Software
X-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X-- $Log: itypes.h,v $
X * Revision 1.1 90/07/19 13:30:45 dvadura
X * Initial Revision of Version 3.5
X *
X*/
X
X
X#ifndef ITYPES_h
X#define ITYPES_h
X
X#if defined(M_I86) || defined(MC68000)
Xtypedef char int8; /* typedefs for right size ints */
Xtypedef int int16;
Xtypedef long int32;
Xtypedef unsigned char uint8;
Xtypedef unsigned int uint16;
Xtypedef unsigned long uint32;
X#else
Xtypedef char int8; /* typedefs for right size ints */
Xtypedef short int16;
Xtypedef long int32;
Xtypedef unsigned char uint8;
Xtypedef unsigned short uint16;
Xtypedef unsigned long uint32;
X#endif
X
X#endif
X
SHAR_EOF
chmod 0440 common/itypes.h || echo "restore of common/itypes.h fails"
echo "x - extracting common/dbug.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > common/dbug.h &&
X/******************************************************************************
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/*
X * FILE
X *
X * dbug.h user include file for programs using the dbug package
X *
X * SYNOPSIS
X *
X * #include <local/dbug.h>
X *
X * SCCS ID
X *
X * @(#)dbug.h 1.11 9/5/87
X *
X * DESCRIPTION
X *
X * Programs which use the dbug package must include this file.
X * It contains the appropriate macros to call support routines
X * in the dbug runtime library.
X *
X * To disable compilation of the macro expansions define the
X * preprocessor symbol "DBUG_OFF". This will result in null
X * macros expansions so that the resulting code will be smaller
X * and faster. (The difference may be smaller than you think
X * so this step is recommended only when absolutely necessary).
X * In general, tradeoffs between space and efficiency are
X * decided in favor of efficiency since space is seldom a
X * problem on the new machines).
X *
X * All externally visible symbol names follow the pattern
X * "_db_xxx..xx_" to minimize the possibility of a dbug package
X * symbol colliding with a user defined symbol.
X *
X * The DBUG_<N> style macros are obsolete and should not be used
X * in new code. Macros to map them to instances of DBUG_PRINT
X * are provided for compatibility with older code. They may go
X * away completely in subsequent releases.
X *
X * AUTHOR
X *
X * Fred Fish
X * (Currently employed by Motorola Computer Division, Tempe, Az.)
X * hao!noao!mcdsun!fnf
X * (602) 438-3614
X *
X */
X
X
X/*
X * Internally used dbug variables which must be global.
X */
X
X#ifndef DBUG_OFF
X extern int _db_on_; /* TRUE if debug currently enabled */
X extern FILE *_db_fp_; /* Current debug output stream */
X extern char *_db_process_; /* Name of current process */
X extern int _db_keyword_ (); /* Accept/reject keyword */
X extern void _db_push_ (); /* Push state, set up new state */
X extern void _db_pop_ (); /* Pop previous debug state */
X extern void _db_enter_ (); /* New user function entered */
X extern void _db_return_ (); /* User function return */
X extern void _db_pargs_ (); /* Remember args for line */
X extern void _db_doprnt_ (); /* Print debug output */
X extern void _db_setjmp_ (); /* Save debugger environment */
X extern void _db_longjmp_ (); /* Restore debugger environment */
X# endif
X
X
X/*
X * These macros provide a user interface into functions in the
X * dbug runtime support library. They isolate users from changes
X * in the MACROS and/or runtime support.
X *
X * The symbols "__LINE__" and "__FILE__" are expanded by the
X * preprocessor to the current source file line number and file
X * name respectively.
X *
X * WARNING --- Because the DBUG_ENTER macro allocates space on
X * the user function's stack, it must precede any executable
X * statements in the user function.
X *
X */
X
X# ifdef DBUG_OFF
X# define DBUG_ENTER(a1)
X# define DBUG_RETURN(a1) return(a1)
X# define DBUG_VOID_RETURN return
X# define DBUG_EXECUTE(keyword,a1)
X# define DBUG_PRINT(keyword,arglist)
X# define DBUG_2(keyword,format) /* Obsolete */
X# define DBUG_3(keyword,format,a1) /* Obsolete */
X# define DBUG_4(keyword,format,a1,a2) /* Obsolete */
X# define DBUG_5(keyword,format,a1,a2,a3) /* Obsolete */
X# define DBUG_PUSH(a1)
X# define DBUG_POP()
X# define DBUG_PROCESS(a1)
X# define DBUG_FILE (stderr)
X# define DBUG_SETJMP setjmp
X# define DBUG_LONGJMP longjmp
X# else
X# define DBUG_ENTER(a) \
X auto char *_db_func_, *_db_file_; \
X int _db_level_; \
X _db_enter_ (a,__FILE__,__LINE__,&_db_func_,&_db_file_,&_db_level_)
X# define DBUG_LEAVE \
X (_db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_))
X# define DBUG_RETURN(a1) return (DBUG_LEAVE, (a1))
X/* define DBUG_RETURN(a1) {DBUG_LEAVE; return(a1);} Alternate form */
X# define DBUG_VOID_RETURN DBUG_LEAVE; return
X# define DBUG_EXECUTE(keyword,a1) \
X {if (_db_on_) {if (_db_keyword_ (keyword)) { a1 }}}
X# define DBUG_PRINT(keyword,arglist) \
X {if (_db_on_) {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;}}
X# define DBUG_2(keyword,format) \
X DBUG_PRINT(keyword,(format)) /* Obsolete */
X# define DBUG_3(keyword,format,a1) \
X DBUG_PRINT(keyword,(format,a1)) /* Obsolete */
X# define DBUG_4(keyword,format,a1,a2) \
X DBUG_PRINT(keyword,(format,a1,a2)) /* Obsolete */
X# define DBUG_5(keyword,format,a1,a2,a3) \
X DBUG_PRINT(keyword,(format,a1,a2,a3)) /* Obsolete */
X# define DBUG_PUSH(a1) _db_push_ (a1)
X# define DBUG_POP() _db_pop_ ()
X# define DBUG_PROCESS(a1) (_db_process_ = a1)
X# define DBUG_FILE (_db_fp_)
X# define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1))
X# define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2))
X# endif
X
SHAR_EOF
chmod 0440 common/dbug.h || echo "restore of common/dbug.h fails"
echo "x - extracting common/dbug.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > common/dbug.c &&
X/******************************************************************************
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/*
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
X#include <stdio.h>
X#ifdef amiga
X#define AMIGA
X#endif
X
X#ifdef AMIGA
X#define HZ (50) /* Probably in some header somewhere */
X#endif
X
X/*
X * Manifest constants that should not require any changes.
X */
X
X#define FALSE 0 /* Boolean FALSE */
X#define TRUE 1 /* Boolean TRUE */
X#define EOS '\000' /* End Of String marker */
X
X/*
X * Manifest constants which may be "tuned" if desired.
X */
X
X#define PRINTBUF 1024 /* Print buffer size */
X#define INDENT 4 /* Indentation per trace level */
X#define MAXDEPTH 200 /* Maximum trace depth default */
X
X/*
X * The following flags are used to determine which
X * capabilities the user has enabled with the state
X * push macro.
X */
X
X#define TRACE_ON 000001 /* Trace enabled */
X#define DEBUG_ON 000002 /* Debug enabled */
X#define FILE_ON 000004 /* File name print enabled */
X#define LINE_ON 000010 /* Line number print enabled */
X#define DEPTH_ON 000020 /* Function nest level print enabled */
X#define PROCESS_ON 000040 /* Process name print enabled */
X#define NUMBER_ON 000100 /* Number each line of output */
X#define PROFILE_ON 000200 /* Print out profiling code */
X
X#define TRACING (stack -> flags & TRACE_ON)
X#define DEBUGGING (stack -> flags & DEBUG_ON)
X#define PROFILING (stack -> flags & PROFILE_ON)
X#define STREQ(a,b) (strcmp(a,b) == 0)
X
X/*
X * Typedefs to make things more obvious.
X */
X
X#define VOID void /* Can't use typedef for most compilers */
Xtypedef int BOOLEAN;
X
X/*
X * Make it easy to change storage classes if necessary.
X */
X
X#define LOCAL static /* Names not needed by outside world */
X#define IMPORT extern /* Names defined externally */
X#define EXPORT /* Allocated here, available globally */
X#define AUTO auto /* Names to be allocated on stack */
X#define REGISTER register /* Names to be placed in registers */
X
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
X#define ARGLIST a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15
X
X/*
X * The default file for profiling. Could also add another flag
X * (G?) which allowed the user to specify this.
X */
X
X#define PROF_FILE "dbugmon.out"
X
X/*
X * Variables which are available externally but should only
X * be accessed via the macro package facilities.
X */
X
XEXPORT FILE *_db_fp_ = stderr; /* Output stream, default stderr */
XEXPORT FILE *_db_pfp_ = (FILE *)0; /* Profile stream, 'dbugmon.out' */
XEXPORT char *_db_process_ = "dbug"; /* Pointer to process name; argv[0] */
XEXPORT BOOLEAN _db_on_ = FALSE; /* TRUE if debugging currently on */
XEXPORT BOOLEAN _db_pon_ = FALSE; /* TRUE if debugging currently on */
X
X/*
X * Externally supplied functions.
X */
X
X#ifdef unix /* Only needed for unix */
XIMPORT VOID perror (); /* Print system/library error */
XIMPORT int chown (); /* Change owner of a file */
XIMPORT int getgid (); /* Get real group id */
XIMPORT int getuid (); /* Get real user id */
XIMPORT int access (); /* Test file for access */
X#else
X#if !(AMIGA && LATTICE)
XLOCAL VOID perror (); /* Fake system/library error print routine */
X#endif
X#endif
X
X# if BSD4_3 || sun
XIMPORT int getrusage ();
X#endif
X
XIMPORT int atoi (); /* Convert ascii to integer */
XIMPORT VOID exit (); /* Terminate execution */
XIMPORT int fclose (); /* Close a stream */
XIMPORT FILE *fopen (); /* Open a stream */
XIMPORT int fprintf (); /* Formatted print on file */
XIMPORT VOID free ();
XIMPORT char *malloc (); /* Allocate memory */
XIMPORT int strcmp (); /* Compare strings */
XIMPORT char *strcpy (); /* Copy strings around */
XIMPORT int strlen (); /* Find length of string */
X
X#ifndef fflush /* This is sometimes a macro */
XIMPORT int fflush (); /* Flush output for stream */
X#endif
X
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
Xstruct link {
X char *string; /* Pointer to link's contents */
X struct link *next_link; /* Pointer to the next link */
X};
X
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
Xstruct 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};
X
XLOCAL struct state *stack = NULL; /* Linked list of stacked states */
X
X/*
X * Local variables not seen by user.
X */
X
XLOCAL int lineno = 0; /* Current debugger output line number */
XLOCAL char *func = "?func"; /* Name of current user function */
XLOCAL char *file = "?file"; /* Name of current user file */
XLOCAL BOOLEAN init_done = FALSE;/* Set to TRUE when initialization done */
X
X/*#if unix || AMIGA || M_I86*/
XLOCAL int jmplevel; /* Remember nesting level at setjmp () */
XLOCAL char *jmpfunc; /* Remember current function for setjmp */
XLOCAL char *jmpfile; /* Remember current file for setjmp */
X/*#endif*/
X
XLOCAL struct link *ListParse ();/* Parse a debug command string */
XLOCAL char *StrDup (); /* Make a fresh copy of a string */
XLOCAL VOID OpenFile (); /* Open debug output stream */
XLOCAL VOID OpenProfile (); /* Open profile output stream */
XLOCAL VOID CloseFile (); /* Close debug output stream */
XLOCAL VOID PushState (); /* Push current debug state */
XLOCAL VOID ChangeOwner (); /* Change file owner and group */
XLOCAL BOOLEAN DoTrace (); /* Test for tracing enabled */
XLOCAL BOOLEAN Writable (); /* Test to see if file is writable */
XLOCAL unsigned long Clock (); /* Return current user time (ms) */
XLOCAL char *DbugMalloc (); /* Allocate memory for runtime support */
XLOCAL char *BaseName (); /* Remove leading pathname components */
XLOCAL VOID DoPrefix (); /* Print debugger line prefix */
XLOCAL VOID FreeList (); /* Free memory from linked list */
XLOCAL VOID Indent (); /* Indent line to specified indent */
X
X /* Supplied in Sys V runtime environ */
XLOCAL char *strtok (); /* Break string into tokens */
XLOCAL char *strrchr (); /* Find last occurance of char */
X
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
XLOCAL int u_line = 0; /* User source code line number */
XLOCAL char *u_keyword = "?"; /* Keyword for current macro */
X
X/*
X * Miscellaneous printf format strings.
X */
X
X#define ERR_MISSING_RETURN "%s: missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n"
X#define ERR_OPEN "%s: can't open debug output stream \"%s\": "
X#define ERR_CLOSE "%s: can't close debug file: "
X#define ERR_ABORT "%s: debugger aborting because %s\n"
X#define ERR_CHOWN "%s: can't change owner/group of \"%s\": "
X#define ERR_PRINTF "%s: obsolete object file for '%s', please recompile!\n"
X
X/*
X * Macros and defines for testing file accessibility under UNIX.
X */
X
X#ifdef unix
X# define A_EXISTS 00 /* Test for file existance */
X# define A_EXECUTE 01 /* Test for execute permission */
X# define A_WRITE 02 /* Test for write access */
X# define A_READ 03 /* Test for read access */
X# define EXISTS(pathname) (access (pathname, A_EXISTS) == 0)
X# define WRITABLE(pathname) (access (pathname, A_WRITE) == 0)
X#else
X# define EXISTS(pathname) (FALSE) /* Assume no existance */
X#endif
X
X/*
X * Translate some calls among different systems.
X */
X
X#ifdef unix
X# define XDelay sleep
XIMPORT unsigned int sleep (); /* Pause for given number of seconds */
X#endif
X
X#ifdef AMIGA
XIMPORT int XDelay (); /* Pause for given number of ticks */
X#endif
X
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
XVOID _db_push_ (control)
Xchar *control;
X{
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
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
XVOID _db_pop_ ()
X{
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
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
XVOID _db_enter_ (_func_, _file_, _line_, _sfunc_, _sfile_, _slevel_)
Xchar *_func_;
Xchar *_file_;
Xint _line_;
Xchar **_sfunc_;
Xchar **_sfile_;
Xint *_slevel_;
X{
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
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
XVOID _db_return_ (_line_, _sfunc_, _sfile_, _slevel_)
Xint _line_;
Xchar **_sfunc_;
Xchar **_sfile_;
Xint *_slevel_;
X{
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
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 */
X
XVOID _db_pargs_ (_line_, keyword)
Xint _line_;
Xchar *keyword;
X{
X u_line = _line_;
X u_keyword = keyword;
X}
X
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
X/*VARARGS1*/
XVOID _db_doprnt_ (format, ARGLIST)
Xchar *format;
Xlong ARGLIST;
X{
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
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
X/*VARARGS3*/
XVOID _db_printf_ (_line_, keyword, format, ARGLIST)
Xint _line_;
Xchar *keyword, *format;
Xlong ARGLIST;
X{
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
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
XLOCAL struct link *ListParse (ctlp)
Xchar *ctlp;
X{
X REGISTER char *start;
X REGISTER struct link *new;
X REGISTER struct link *head;
X
X head = NULL;
SHAR_EOF
echo "End of part 19"
echo "File common/dbug.c is continued in part 20"
echo "20" > s2_seq_.tmp
exit 0
More information about the Comp.sources.misc
mailing list