1
/******************************************************************************
5
* Copyright Abandoned, 1987, Fred Fish *
8
* This previously copyrighted work has been placed into the public *
9
* domain by the author and may be freely used for any purpose, *
10
* private or commercial. *
12
* Because of the number of inquiries I was receiving about the use *
13
* of this product in commercially developed works I have decided to *
14
* simply make it public domain to further its unrestricted use. I *
15
* specifically would be most happy to see this material become a *
16
* part of the standard Unix distributions by AT&T and the Berkeley *
17
* Computer Science Research Group, and a standard part of the GNU *
18
* system from the Free Software Foundation. *
20
* I would appreciate it, as a courtesy, if this notice is left in *
21
* all copies and derivative works. Thank you. *
23
* The author makes no warranty of any kind with respect to this *
24
* product and explicitly disclaims any implied warranties of mer- *
25
* chantability or fitness for any particular purpose. *
27
******************************************************************************
33
* dbug.c runtime support routines for dbug package
37
* @(#)dbug.c 1.25 7/25/89
41
* These are the runtime support routines for the dbug package.
42
* The dbug package has two main components; the user include
43
* file containing various macro definitions, and the runtime
44
* support routines which are called from the macro expansions.
46
* Externally visible functions in the runtime support module
47
* use the naming convention pattern "_db_xx...xx_", thus
48
* they are unlikely to collide with user defined function names.
52
* Fred Fish (base code)
53
* Enhanced Software Technologies, Tempe, AZ
54
* asuvax!mcdphx!estinc!fnf
56
* Binayak Banerjee (profiling enhancements)
57
* seismo!bpa!sjuvax!bbanerje
60
* DBUG_DUMP - To dump a block of memory.
61
* PUSH_FLAG "O" - To be used insted of "o" if we
62
* want flushing after each write
63
* PUSH_FLAG "A" - as 'O', but we will append to the out file instead
64
* of creating a new one.
65
* Check of malloc on entry/exit (option "S")
68
* incremental mode (-#+t:-d,info ...)
69
* DBUG_SET, _db_explain_
70
* thread-local settings
75
#include <my_global.h>
78
#if defined(MSDOS) || defined(__WIN__)
87
* Manifest constants which may be "tuned" if desired.
90
#define PRINTBUF 1024 /* Print buffer size */
91
#define INDENT 2 /* Indentation per trace level */
92
#define MAXDEPTH 200 /* Maximum trace depth default */
95
* The following flags are used to determine which
96
* capabilities the user has enabled with the settings
100
#define TRACE_ON 000001 /* Trace enabled */
101
#define DEBUG_ON 000002 /* Debug enabled */
102
#define FILE_ON 000004 /* File name print enabled */
103
#define LINE_ON 000010 /* Line number print enabled */
104
#define DEPTH_ON 000020 /* Function nest level print enabled */
105
#define PROCESS_ON 000040 /* Process name print enabled */
106
#define NUMBER_ON 000100 /* Number each line of output */
107
#define PROFILE_ON 000200 /* Print out profiling code */
108
#define PID_ON 000400 /* Identify each line with process id */
109
#define TIMESTAMP_ON 001000 /* timestamp every line of output */
110
#define SANITY_CHECK_ON 002000 /* Check safemalloc on DBUG_ENTER */
111
#define FLUSH_ON_WRITE 004000 /* Flush on every write */
112
#define OPEN_APPEND 010000 /* Open for append */
114
#define TRACING (cs->stack->flags & TRACE_ON)
115
#define DEBUGGING (cs->stack->flags & DEBUG_ON)
116
#define PROFILING (cs->stack->flags & PROFILE_ON)
119
* Typedefs to make things more obvious.
129
* Make it easy to change storage classes if necessary.
132
#define IMPORT extern /* Names defined externally */
133
#define EXPORT /* Allocated here, available globally */
134
#define AUTO auto /* Names to be allocated on stack */
135
#define REGISTER register /* Names to be placed in registers */
138
* The default file for profiling. Could also add another flag
139
* (G?) which allowed the user to specify this.
141
* If the automatic variables get allocated on the stack in
142
* reverse order from their declarations, then define AUTOS_REVERSE.
143
* This is used by the code that keeps track of stack usage. For
144
* forward allocation, the difference in the dbug frame pointers
145
* represents stack used by the callee function. For reverse allocation,
146
* the difference represents stack used by the caller function.
150
#define PROF_FILE "dbugmon.out"
151
#define PROF_EFMT "E\t%ld\t%s\n"
152
#define PROF_SFMT "S\t%lx\t%lx\t%s\n"
153
#define PROF_XFMT "X\t%ld\t%s\n"
155
#ifdef M_I386 /* predefined by xenix 386 compiler */
156
#define AUTOS_REVERSE 1
160
* Externally supplied functions.
164
static void perror(); /* Fake system/library error print routine */
167
IMPORT int _sanity(const char *file,uint line); /* safemalloc sanity checker */
170
* The user may specify a list of functions to trace or
171
* debug. These lists are kept in a linear linked list,
172
* a very simple implementation.
176
struct link *next_link; /* Pointer to the next link */
177
char str[1]; /* Pointer to link's contents */
181
* Debugging settings can be pushed or popped off of a
182
* stack which is implemented as a linked list. Note
183
* that the head of the list is the current settings and the
184
* stack is pushed by adding a new settings to the head of the
185
* list or popped by removing the first link.
187
* Note: if out_file is NULL, the other fields are not initialized at all!
191
int flags; /* Current settings flags */
192
int maxdepth; /* Current maximum trace depth */
193
uint delay; /* Delay after each output line */
194
int sub_level; /* Sub this from code_state->level */
195
FILE *out_file; /* Current output stream */
196
FILE *prof_file; /* Current profiling stream */
197
char name[FN_REFLEN]; /* Name of output file */
198
struct link *functions; /* List of functions */
199
struct link *p_functions; /* List of profiled functions */
200
struct link *keywords; /* List of debug keywords */
201
struct link *processes; /* List of process names */
202
struct settings *next; /* Next settings in the list */
205
#define is_shared(S, V) ((S)->next && (S)->next->V == (S)->V)
208
* Local variables not seen by user.
212
static BOOLEAN init_done= FALSE; /* Set to TRUE when initialization done */
213
static struct settings init_settings;
214
static const char *db_process= 0;/* Pointer to process name; argv[0] */
216
typedef struct _db_code_state_ {
217
const char *process; /* Pointer to process name; usually argv[0] */
218
const char *func; /* Name of current user function */
219
const char *file; /* Name of current user file */
220
char **framep; /* Pointer to current frame */
221
struct settings *stack; /* debugging settings */
222
const char *jmpfunc; /* Remember current function for setjmp */
223
const char *jmpfile; /* Remember current file for setjmp */
224
int lineno; /* Current debugger output line number */
225
int level; /* Current function nesting level */
226
int jmplevel; /* Remember nesting level at setjmp() */
229
* The following variables are used to hold the state information
230
* between the call to _db_pargs_() and _db_doprnt_(), during
231
* expansion of the DBUG_PRINT macro. This is the only macro
232
* that currently uses these variables.
234
* These variables are currently used only by _db_pargs_() and
238
uint u_line; /* User source code line number */
239
int locked; /* If locked with _db_lock_file_ */
240
const char *u_keyword; /* Keyword for current macro */
244
The test below is so we could call functions with DBUG_ENTER before
247
#define get_code_state_or_return if (!cs && !((cs=code_state()))) return
250
static struct link *ListAdd(struct link *, const char *, const char *);
251
static struct link *ListDel(struct link *, const char *, const char *);
252
static struct link *ListCopy(struct link *);
253
static void FreeList(struct link *linkp);
255
/* OpenClose debug output stream */
256
static void DBUGOpenFile(CODE_STATE *,const char *, const char *, int);
257
static void DBUGCloseFile(CODE_STATE *cs, FILE *fp);
258
/* Push current debug settings */
259
static void PushState(CODE_STATE *cs);
260
/* Free memory associated with debug state. */
261
static void FreeState (CODE_STATE *cs, struct settings *state, int free_state);
262
/* Test for tracing enabled */
263
static BOOLEAN DoTrace(CODE_STATE *cs);
265
/* Test to see if file is writable */
266
#if !(!defined(HAVE_ACCESS) || defined(MSDOS))
267
static BOOLEAN Writable(const char *pathname);
268
/* Change file owner and group */
269
static void ChangeOwner(CODE_STATE *cs, char *pathname);
270
/* Allocate memory for runtime support */
273
static void DoPrefix(CODE_STATE *cs, uint line);
275
static char *DbugMalloc(size_t size);
276
static const char *BaseName(const char *pathname);
277
static void Indent(CODE_STATE *cs, int indent);
278
static BOOLEAN InList(struct link *linkp,const char *cp);
279
static void dbug_flush(CODE_STATE *);
280
static void DbugExit(const char *why);
281
static const char *DbugStrTok(const char *s);
284
/* Open profile output stream */
285
static FILE *OpenProfile(CODE_STATE *cs, const char *name);
286
/* Profile if asked for it */
287
static BOOLEAN DoProfile(CODE_STATE *);
288
/* Return current user time (ms) */
289
static unsigned long Clock(void);
293
* Miscellaneous printf format strings.
296
#define ERR_MISSING_RETURN "%s: missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n"
297
#define ERR_OPEN "%s: can't open debug output stream \"%s\": "
298
#define ERR_CLOSE "%s: can't close debug file: "
299
#define ERR_ABORT "%s: debugger aborting because %s\n"
300
#define ERR_CHOWN "%s: can't change owner/group of \"%s\": "
303
* Macros and defines for testing file accessibility under UNIX and MSDOS.
307
#if !defined(HAVE_ACCESS) || defined(MSDOS)
308
#define EXISTS(pathname) (FALSE) /* Assume no existance */
309
#define Writable(name) (TRUE)
311
#define EXISTS(pathname) (access(pathname, F_OK) == 0)
312
#define WRITABLE(pathname) (access(pathname, W_OK) == 0)
315
#define ChangeOwner(cs,name)
320
** Macros to allow dbugging with threads
324
#include <my_pthread.h>
325
pthread_mutex_t THR_LOCK_dbug;
327
static CODE_STATE *code_state(void)
330
struct st_my_thread_var *tmp;
334
pthread_mutex_init(&THR_LOCK_dbug,MY_MUTEX_INIT_FAST);
335
bzero(&init_settings, sizeof(init_settings));
336
init_settings.out_file=stderr;
337
init_settings.flags=OPEN_APPEND;
341
if ((tmp=my_thread_var))
343
if (!(cs=(CODE_STATE *) tmp->dbug))
345
cs=(CODE_STATE*) DbugMalloc(sizeof(*cs));
346
bzero((uchar*) cs,sizeof(*cs));
347
cs->process= db_process ? db_process : "dbug";
350
cs->stack=&init_settings;
351
tmp->dbug= (void*) cs;
359
static CODE_STATE static_code_state=
361
"dbug", "?func", "?file", NULL, &init_settings,
362
NullS, NullS, 0,0,0,0,0,NullS
365
static CODE_STATE *code_state(void)
369
bzero(&init_settings, sizeof(init_settings));
370
init_settings.out_file=stderr;
371
init_settings.flags=OPEN_APPEND;
374
return &static_code_state;
377
#define pthread_mutex_lock(A) {}
378
#define pthread_mutex_unlock(A) {}
382
* Translate some calls among different systems.
386
/* sleep() wants seconds */
387
#define Delay(A) sleep(((uint) A)/10)
395
* _db_process_ give the name to the current process/thread
399
* VOID _process_(name)
404
void _db_process_(const char *name)
411
get_code_state_or_return;
419
* DbugParse parse control string and set current debugger setting
423
* Given pointer to a debug control string in "control",
424
* parses the control string, and sets
425
* up a current debug settings.
427
* The debug control string is a sequence of colon separated fields
430
* [+]<field_1>:<field_2>:...:<field_N>
432
* Each field consists of a mandatory flag character followed by
433
* an optional "," and comma separated list of modifiers:
435
* [sign]flag[,modifier,modifier,...,modifier]
437
* See the manual for the list of supported signs, flags, and modifiers
439
* For convenience, any leading "-#" is stripped off.
443
static void DbugParse(CODE_STATE *cs, const char *control)
447
struct settings *stack;
449
get_code_state_or_return;
452
if (control[0] == '-' && control[1] == '#')
455
rel= control[0] == '+' || control[0] == '-';
456
if ((!rel || (!stack->out_file && !stack->next)))
462
stack->out_file= stderr;
463
stack->prof_file= NULL;
464
stack->functions= NULL;
465
stack->p_functions= NULL;
466
stack->keywords= NULL;
467
stack->processes= NULL;
469
else if (!stack->out_file)
471
stack->flags= stack->next->flags;
472
stack->delay= stack->next->delay;
473
stack->maxdepth= stack->next->maxdepth;
474
stack->sub_level= stack->next->sub_level;
475
strcpy(stack->name, stack->next->name);
476
stack->out_file= stack->next->out_file;
477
stack->prof_file= stack->next->prof_file;
478
if (stack->next == &init_settings)
480
/* never share with the global parent - it can change under your feet */
481
stack->functions= ListCopy(init_settings.functions);
482
stack->p_functions= ListCopy(init_settings.p_functions);
483
stack->keywords= ListCopy(init_settings.keywords);
484
stack->processes= ListCopy(init_settings.processes);
488
stack->functions= stack->next->functions;
489
stack->p_functions= stack->next->p_functions;
490
stack->keywords= stack->next->keywords;
491
stack->processes= stack->next->processes;
495
end= DbugStrTok(control);
498
int c, sign= (*control == '+') ? 1 : (*control == '-') ? -1 : 0;
502
if (*control == ',') control++;
503
/* XXX when adding new cases here, don't forget _db_explain_ ! */
506
if (sign < 0 && control == end)
508
if (!is_shared(stack, keywords))
509
FreeList(stack->keywords);
510
stack->keywords=NULL;
511
stack->flags &= ~DEBUG_ON;
514
if (rel && is_shared(stack, keywords))
515
stack->keywords= ListCopy(stack->keywords);
519
stack->keywords= ListDel(stack->keywords, control, end);
522
stack->keywords= ListAdd(stack->keywords, control, end);
523
stack->flags |= DEBUG_ON;
526
stack->delay= atoi(control);
529
if (sign < 0 && control == end)
531
if (!is_shared(stack,functions))
532
FreeList(stack->functions);
533
stack->functions=NULL;
536
if (rel && is_shared(stack,functions))
537
stack->functions= ListCopy(stack->functions);
539
stack->functions= ListDel(stack->functions, control, end);
541
stack->functions= ListAdd(stack->functions, control, end);
545
stack->flags &= ~FILE_ON;
547
stack->flags |= FILE_ON;
551
stack->flags &= ~PID_ON;
553
stack->flags |= PID_ON;
557
if (OpenProfile(cs, PROF_FILE))
559
stack->flags |= PROFILE_ON;
560
stack->p_functions= ListAdd(stack->p_functions, control, end);
566
stack->flags &= ~LINE_ON;
568
stack->flags |= LINE_ON;
572
stack->flags &= ~DEPTH_ON;
574
stack->flags |= DEPTH_ON;
578
stack->flags &= ~NUMBER_ON;
580
stack->flags |= NUMBER_ON;
584
stack->flags |= FLUSH_ON_WRITE;
590
if (!is_shared(stack, out_file))
591
DBUGCloseFile(cs, stack->out_file);
592
stack->flags &= ~FLUSH_ON_WRITE;
593
stack->out_file= stderr;
596
if (c == 'a' || c == 'A')
597
stack->flags |= OPEN_APPEND;
599
stack->flags &= ~OPEN_APPEND;
601
DBUGOpenFile(cs, control, end, stack->flags & OPEN_APPEND);
603
DBUGOpenFile(cs, "-",0,0);
606
if (sign < 0 && control == end)
608
if (!is_shared(stack,processes))
609
FreeList(stack->processes);
610
stack->processes=NULL;
613
if (rel && is_shared(stack, processes))
614
stack->processes= ListCopy(stack->processes);
616
stack->processes= ListDel(stack->processes, control, end);
618
stack->processes= ListAdd(stack->processes, control, end);
622
stack->flags &= ~PROCESS_ON;
624
stack->flags |= PROCESS_ON;
627
stack->sub_level= cs->level;
633
stack->maxdepth-= atoi(control);
640
stack->maxdepth+= atoi(control);
642
stack->maxdepth= MAXDEPTH;
644
if (stack->maxdepth > 0)
645
stack->flags |= TRACE_ON;
647
stack->flags &= ~TRACE_ON;
651
stack->flags &= ~TIMESTAMP_ON;
653
stack->flags |= TIMESTAMP_ON;
657
stack->flags &= ~SANITY_CHECK_ON;
659
stack->flags |= SANITY_CHECK_ON;
665
end= DbugStrTok(control);
673
* _db_set_ set current debugger settings
677
* VOID _db_set_(control)
682
* Given pointer to a debug control string in "control",
683
* parses the control string, and sets up a current debug
684
* settings. Pushes a new debug settings if the current is
685
* set to the initial debugger settings.
688
void _db_set_(CODE_STATE *cs, const char *control)
690
get_code_state_or_return;
692
if (cs->stack == &init_settings)
695
DbugParse(cs, control);
702
* _db_push_ push current debugger settings and set up new one
706
* VOID _db_push_(control)
711
* Given pointer to a debug control string in "control", pushes
712
* the current debug settings, parses the control string, and sets
713
* up a new debug settings with DbugParse()
717
void _db_push_(const char *control)
720
get_code_state_or_return;
722
DbugParse(cs, control);
728
* _db_set_init_ set initial debugger settings
732
* VOID _db_set_init_(control)
740
void _db_set_init_(const char *control)
743
bzero((uchar*) &tmp_cs, sizeof(tmp_cs));
744
tmp_cs.stack= &init_settings;
745
DbugParse(&tmp_cs, control);
751
* _db_pop_ pop the debug stack
755
* Pops the debug stack, returning the debug settings to its
756
* condition prior to the most recent _db_push_ invocation.
757
* Note that the pop will fail if it would remove the last
758
* valid settings from the stack. This prevents user errors
759
* in the push/pop sequence from screwing up the debugger.
760
* Maybe there should be some kind of warning printed if the
761
* user tries to pop too many states.
767
struct settings *discard;
770
get_code_state_or_return;
773
if (discard->next != NULL)
775
cs->stack= discard->next;
776
FreeState(cs, discard, 1);
783
* _db_explain_ generates 'control' string for the current settings
787
* 1 - buffer too short, output truncated
792
#define char_to_buf(C) do { \
794
if (buf >= end) goto overflow; \
796
#define str_to_buf(S) do { \
798
buf=strnmov(buf, (S), len+1); \
799
if (buf >= end) goto overflow; \
801
#define list_to_buf(l) do { \
802
struct link *listp=(l); \
805
str_to_buf(listp->str); \
806
listp=listp->next_link; \
809
#define int_to_buf(i) do { \
811
int10_to_str((i), b, 10); \
814
#define colon_to_buf do { \
815
if (buf != start) char_to_buf(':'); \
817
#define op_int_to_buf(C, val, def) do { \
818
if ((val) != (def)) \
825
#define op_intf_to_buf(C, val, def, cond) do { \
830
if ((val) != (def)) int_to_buf(val); \
833
#define op_str_to_buf(C, val, cond) do { \
839
if (*s) str_to_buf(s); \
842
#define op_list_to_buf(C, val, cond) do { \
850
#define op_bool_to_buf(C, cond) do { \
858
int _db_explain_ (CODE_STATE *cs, char *buf, size_t len)
860
char *start=buf, *end=buf+len-4;
862
get_code_state_or_return *buf=0;
864
op_list_to_buf('d', cs->stack->keywords, DEBUGGING);
865
op_int_to_buf ('D', cs->stack->delay, 0);
866
op_list_to_buf('f', cs->stack->functions, cs->stack->functions);
867
op_bool_to_buf('F', cs->stack->flags & FILE_ON);
868
op_bool_to_buf('i', cs->stack->flags & PID_ON);
869
op_list_to_buf('g', cs->stack->p_functions, PROFILING);
870
op_bool_to_buf('L', cs->stack->flags & LINE_ON);
871
op_bool_to_buf('n', cs->stack->flags & DEPTH_ON);
872
op_bool_to_buf('N', cs->stack->flags & NUMBER_ON);
874
((cs->stack->flags & FLUSH_ON_WRITE ? 0 : 32) |
875
(cs->stack->flags & OPEN_APPEND ? 'A' : 'O')),
876
cs->stack->name, cs->stack->out_file != stderr);
877
op_list_to_buf('p', cs->stack->processes, cs->stack->processes);
878
op_bool_to_buf('P', cs->stack->flags & PROCESS_ON);
879
op_bool_to_buf('r', cs->stack->sub_level != 0);
880
op_intf_to_buf('t', cs->stack->maxdepth, MAXDEPTH, TRACING);
881
op_bool_to_buf('T', cs->stack->flags & TIMESTAMP_ON);
882
op_bool_to_buf('S', cs->stack->flags & SANITY_CHECK_ON);
901
#undef op_intf_to_buf
903
#undef op_list_to_buf
904
#undef op_bool_to_buf
909
* _db_explain_init_ explain initial debugger settings
915
int _db_explain_init_(char *buf, size_t len)
918
bzero((uchar*) &cs,sizeof(cs));
919
cs.stack=&init_settings;
920
return _db_explain_(&cs, buf, len);
926
* _db_enter_ process entry point to user function
930
* VOID _db_enter_(_func_, _file_, _line_,
931
* _sfunc_, _sfile_, _slevel_, _sframep_)
932
* char *_func_; points to current function name
933
* char *_file_; points to current file name
934
* int _line_; called from source line number
935
* char **_sfunc_; save previous _func_
936
* char **_sfile_; save previous _file_
937
* int *_slevel_; save previous nesting level
938
* char ***_sframep_; save previous frame pointer
942
* Called at the beginning of each user function to tell
943
* the debugger that a new function has been entered.
944
* Note that the pointers to the previous user function
945
* name and previous user file name are stored on the
946
* caller's stack (this is why the ENTER macro must be
947
* the first "executable" code in a function, since it
948
* allocates these storage locations). The previous nesting
949
* level is also stored on the callers stack for internal
950
* self consistency checks.
952
* Also prints a trace line if tracing is enabled and
953
* increments the current function nesting depth.
955
* Note that this mechanism allows the debugger to know
956
* what the current user function is at all times, without
957
* maintaining an internal stack for the function names.
961
void _db_enter_(const char *_func_, const char *_file_,
962
uint _line_, const char **_sfunc_, const char **_sfile_,
963
uint *_slevel_, char ***_sframep_ __attribute__((unused)))
965
int save_errno=errno;
967
get_code_state_or_return;
973
*_slevel_= ++cs->level;
975
*_sframep_= cs->framep;
976
cs->framep= (char **) _sframep_;
980
if (*cs->framep == NULL)
984
stackused= ((long)(*cs->framep)) - ((long)(cs->framep));
985
stackused= stackused > 0 ? stackused : -stackused;
987
(void) fprintf(cs->stack->prof_file, PROF_EFMT , Clock(), cs->func);
989
(void) fprintf(cs->stack->prof_file, PROF_SFMT, cs->framep, stackused, *_sfunc_);
991
(void) fprintf(cs->stack->prof_file, PROF_SFMT, (ulong) cs->framep, stackused,
994
(void) fflush(cs->stack->prof_file);
1000
pthread_mutex_lock(&THR_LOCK_dbug);
1001
DoPrefix(cs, _line_);
1002
Indent(cs, cs->level);
1003
(void) fprintf(cs->stack->out_file, ">%s\n", cs->func);
1004
dbug_flush(cs); /* This does a unlock */
1012
* _db_return_ process exit from user function
1016
* VOID _db_return_(_line_, _sfunc_, _sfile_, _slevel_)
1017
* int _line_; current source line number
1018
* char **_sfunc_; where previous _func_ is to be retrieved
1019
* char **_sfile_; where previous _file_ is to be retrieved
1020
* int *_slevel_; where previous level was stashed
1024
* Called just before user function executes an explicit or implicit
1025
* return. Prints a trace line if trace is enabled, decrements
1026
* the current nesting level, and restores the current function and
1027
* file names from the defunct function's stack.
1032
void _db_return_(uint _line_, const char **_sfunc_,
1033
const char **_sfile_, uint *_slevel_)
1035
int save_errno=errno;
1037
get_code_state_or_return;
1039
if (cs->level != (int) *_slevel_)
1042
pthread_mutex_lock(&THR_LOCK_dbug);
1043
(void) fprintf(cs->stack->out_file, ERR_MISSING_RETURN, cs->process,
1051
(void) fprintf(cs->stack->prof_file, PROF_XFMT, Clock(), cs->func);
1056
pthread_mutex_lock(&THR_LOCK_dbug);
1057
DoPrefix(cs, _line_);
1058
Indent(cs, cs->level);
1059
(void) fprintf(cs->stack->out_file, "<%s\n", cs->func);
1063
cs->level= *_slevel_-1;
1067
if (cs->framep != NULL)
1068
cs->framep= (char **) *cs->framep;
1077
* _db_pargs_ log arguments for subsequent use by _db_doprnt_()
1081
* VOID _db_pargs_(_line_, keyword)
1087
* The new universal printing macro DBUG_PRINT, which replaces
1088
* all forms of the DBUG_N macros, needs two calls to runtime
1089
* support routines. The first, this function, remembers arguments
1090
* that are used by the subsequent call to _db_doprnt_().
1094
void _db_pargs_(uint _line_, const char *keyword)
1097
get_code_state_or_return;
1099
cs->u_keyword= keyword;
1106
* _db_doprnt_ handle print of debug lines
1110
* VOID _db_doprnt_(format, va_alist)
1116
* When invoked via one of the DBUG macros, tests the current keyword
1117
* set by calling _db_pargs_() to see if that macro has been selected
1118
* for processing via the debugger control string, and if so, handles
1119
* printing of the arguments via the format string. The line number
1120
* of the DBUG macro in the source is found in u_line.
1122
* Note that the format string SHOULD NOT include a terminating
1123
* newline, this is supplied automatically.
1129
void _db_doprnt_(const char *format,...)
1134
get_code_state_or_return;
1136
va_start(args,format);
1138
if (_db_keyword_(cs, cs->u_keyword))
1140
int save_errno=errno;
1142
pthread_mutex_lock(&THR_LOCK_dbug);
1143
DoPrefix(cs, cs->u_line);
1145
Indent(cs, cs->level + 1);
1147
(void) fprintf(cs->stack->out_file, "%s: ", cs->func);
1148
(void) fprintf(cs->stack->out_file, "%s: ", cs->u_keyword);
1149
(void) vfprintf(cs->stack->out_file, format, args);
1150
(void) fputc('\n',cs->stack->out_file);
1161
* _db_dump_ dump a string in hex
1165
* void _db_dump_(_line_,keyword,memory,length)
1166
* int _line_; current source line number
1168
* char *memory; Memory to print
1169
* int length; Bytes to print
1172
* Dump N characters in a binary array.
1173
* Is used to examine corrputed memory or arrays.
1176
void _db_dump_(uint _line_, const char *keyword,
1177
const unsigned char *memory, size_t length)
1183
get_code_state_or_return;
1185
if (_db_keyword_(cs, keyword))
1188
pthread_mutex_lock(&THR_LOCK_dbug);
1189
DoPrefix(cs, _line_);
1192
Indent(cs, cs->level + 1);
1193
pos= min(max(cs->level-cs->stack->sub_level,0)*INDENT,80);
1197
fprintf(cs->stack->out_file, "%s: ", cs->func);
1199
sprintf(dbuff,"%s: Memory: 0x%lx Bytes: (%ld)\n",
1200
keyword, (ulong) memory, (long) length);
1201
(void) fputs(dbuff,cs->stack->out_file);
1204
while (length-- > 0)
1206
uint tmp= *((unsigned char*) memory++);
1209
fputc('\n',cs->stack->out_file);
1212
fputc(_dig_vec_upper[((tmp >> 4) & 15)], cs->stack->out_file);
1213
fputc(_dig_vec_upper[tmp & 15], cs->stack->out_file);
1214
fputc(' ',cs->stack->out_file);
1216
(void) fputc('\n',cs->stack->out_file);
1225
* ListAdd add to the list modifiers from debug control string
1229
* static struct link *ListAdd(listp, ctlp, end)
1230
* struct link *listp;
1236
* Given pointer to a comma separated list of strings in "cltp",
1237
* parses the list, and adds it to listp, returning a pointer
1240
* Note that since each link is added at the head of the list,
1241
* the final list will be in "reverse order", which is not
1242
* significant for our usage here.
1246
static struct link *ListAdd(struct link *head,
1247
const char *ctlp, const char *end)
1250
struct link *new_malloc;
1256
while (ctlp < end && *ctlp != ',')
1259
new_malloc= (struct link *) DbugMalloc(sizeof(struct link)+len);
1260
memcpy(new_malloc->str, start, len);
1261
new_malloc->str[len]=0;
1262
new_malloc->next_link= head;
1272
* ListDel remove from the list modifiers in debug control string
1276
* static struct link *ListDel(listp, ctlp, end)
1277
* struct link *listp;
1283
* Given pointer to a comma separated list of strings in "cltp",
1284
* parses the list, and removes these strings from the listp,
1285
* returning a pointer to the new list.
1289
static struct link *ListDel(struct link *head,
1290
const char *ctlp, const char *end)
1299
while (ctlp < end && *ctlp != ',')
1305
while (*cur && !strncmp((*cur)->str, start, len))
1307
struct link *delme=*cur;
1308
*cur=(*cur)->next_link;
1309
free((void*) delme);
1311
} while (*cur && *(cur=&((*cur)->next_link)));
1319
* ListCopy make a copy of the list
1323
* static struct link *ListCopy(orig)
1324
* struct link *orig;
1328
* Given pointer to list, which contains a copy of every element from
1329
* the original list.
1331
* the orig pointer can be NULL
1333
* Note that since each link is added at the head of the list,
1334
* the final list will be in "reverse order", which is not
1335
* significant for our usage here.
1339
static struct link *ListCopy(struct link *orig)
1341
struct link *new_malloc;
1346
while (orig != NULL)
1348
len= strlen(orig->str);
1349
new_malloc= (struct link *) DbugMalloc(sizeof(struct link)+len);
1350
memcpy(new_malloc->str, orig->str, len);
1351
new_malloc->str[len]= 0;
1352
new_malloc->next_link= head;
1354
orig= orig->next_link;
1362
* InList test a given string for member of a given list
1366
* static BOOLEAN InList(linkp, cp)
1367
* struct link *linkp;
1372
* Tests the string pointed to by "cp" to determine if it is in
1373
* the list pointed to by "linkp". Linkp points to the first
1374
* link in the list. If linkp is NULL then the string is treated
1375
* as if it is in the list (I.E all strings are in the null list).
1376
* This may seem rather strange at first but leads to the desired
1377
* operation if no list is given. The net effect is that all
1378
* strings will be accepted when there is no list, and when there
1379
* is a list, only those strings in the list will be accepted.
1383
static BOOLEAN InList(struct link *linkp, const char *cp)
1385
REGISTER struct link *scan;
1386
REGISTER BOOLEAN result;
1393
for (scan= linkp; scan != NULL; scan= scan->next_link)
1395
if (!strcmp(scan->str, cp))
1409
* PushState push current settings onto stack and set up new one
1413
* static VOID PushState()
1417
* Pushes the current settings on the settings stack, and creates
1418
* a new settings. The new settings is NOT initialized
1420
* The settings stack is a linked list of settings, with the new
1421
* settings added at the head. This allows the stack to grow
1422
* to the limits of memory if necessary.
1426
static void PushState(CODE_STATE *cs)
1428
struct settings *new_malloc;
1430
new_malloc= (struct settings *) DbugMalloc(sizeof(struct settings));
1431
new_malloc->next= cs->stack;
1432
new_malloc->out_file= NULL;
1433
cs->stack= new_malloc;
1439
* FreeState Free memory associated with a struct state.
1443
* static void FreeState (state)
1444
* struct state *state;
1449
* Deallocates the memory allocated for various information in a
1450
* state. If free_state is set, also free 'state'
1453
static void FreeState(CODE_STATE *cs, struct settings *state, int free_state)
1455
if (!is_shared(state, keywords))
1456
FreeList(state->keywords);
1457
if (!is_shared(state, functions))
1458
FreeList(state->functions);
1459
if (!is_shared(state, processes))
1460
FreeList(state->processes);
1461
if (!is_shared(state, p_functions))
1462
FreeList(state->p_functions);
1463
if (!is_shared(state, out_file))
1464
DBUGCloseFile(cs, state->out_file);
1465
(void) fflush(cs->stack->out_file);
1466
if (state->prof_file)
1467
DBUGCloseFile(cs, state->prof_file);
1469
free((void*) state);
1476
* _db_end_ End debugging, freeing state stack memory.
1480
* static VOID _db_end_ ()
1484
* Ends debugging, de-allocating the memory allocated to the
1487
* To be called at the very end of the program.
1492
struct settings *discard;
1493
static struct settings tmp;
1496
get_code_state_or_return;
1498
while ((discard= cs->stack))
1500
if (discard == &init_settings)
1502
cs->stack= discard->next;
1503
FreeState(cs, discard, 1);
1507
/* Use mutex lock to make it less likely anyone access out_file */
1508
pthread_mutex_lock(&THR_LOCK_dbug);
1509
init_settings.flags= OPEN_APPEND;
1510
init_settings.out_file= stderr;
1511
init_settings.prof_file= stderr;
1512
init_settings.maxdepth= 0;
1513
init_settings.delay= 0;
1514
init_settings.sub_level= 0;
1515
init_settings.functions= 0;
1516
init_settings.p_functions= 0;
1517
init_settings.keywords= 0;
1518
init_settings.processes= 0;
1519
pthread_mutex_unlock(&THR_LOCK_dbug);
1520
FreeState(cs, &tmp, 0);
1527
* DoTrace check to see if tracing is current enabled
1531
* static BOOLEAN DoTrace(stack)
1535
* Checks to see if tracing is enabled based on whether the
1536
* user has specified tracing, the maximum trace depth has
1537
* not yet been reached, the current function is selected,
1538
* and the current process is selected. Returns TRUE if
1539
* tracing is enabled, FALSE otherwise.
1543
static BOOLEAN DoTrace(CODE_STATE *cs)
1545
return (TRACING && cs->level <= cs->stack->maxdepth &&
1546
InList(cs->stack->functions, cs->func) &&
1547
InList(cs->stack->processes, cs->process));
1554
* DoProfile check to see if profiling is current enabled
1558
* static BOOLEAN DoProfile()
1562
* Checks to see if profiling is enabled based on whether the
1563
* user has specified profiling, the maximum trace depth has
1564
* not yet been reached, the current function is selected,
1565
* and the current process is selected. Returns TRUE if
1566
* profiling is enabled, FALSE otherwise.
1571
static BOOLEAN DoProfile(CODE_STATE *cs)
1574
cs->level <= cs->stack->maxdepth &&
1575
InList(cs->stack->p_functions, cs->func) &&
1576
InList(cs->stack->processes, cs->process);
1583
get_code_state_or_return NULL;
1584
return cs->stack->out_file;
1591
* _db_strict_keyword_ test keyword for member of keyword list
1595
* BOOLEAN _db_strict_keyword_(keyword)
1600
* Similar to _db_keyword_, but keyword is NOT accepted if keyword list
1601
* is empty. Used in DBUG_EXECUTE_IF() - for actions that must not be
1602
* executed by default.
1604
* Returns TRUE if keyword accepted, FALSE otherwise.
1608
BOOLEAN _db_strict_keyword_(const char *keyword)
1611
get_code_state_or_return FALSE;
1612
if (!DEBUGGING || cs->stack->keywords == NULL)
1614
return _db_keyword_(cs, keyword);
1620
* _db_keyword_ test keyword for member of keyword list
1624
* BOOLEAN _db_keyword_(keyword)
1629
* Test a keyword to determine if it is in the currently active
1630
* keyword list. As with the function list, a keyword is accepted
1631
* if the list is null, otherwise it must match one of the list
1632
* members. When debugging is not on, no keywords are accepted.
1633
* After the maximum trace level is exceeded, no keywords are
1634
* accepted (this behavior subject to change). Additionally,
1635
* the current function and process must be accepted based on
1636
* their respective lists.
1638
* Returns TRUE if keyword accepted, FALSE otherwise.
1642
BOOLEAN _db_keyword_(CODE_STATE *cs, const char *keyword)
1644
get_code_state_or_return FALSE;
1646
return (DEBUGGING &&
1647
(!TRACING || cs->level <= cs->stack->maxdepth) &&
1648
InList(cs->stack->functions, cs->func) &&
1649
InList(cs->stack->keywords, keyword) &&
1650
InList(cs->stack->processes, cs->process));
1656
* Indent indent a line to the given indentation level
1660
* static VOID Indent(indent)
1665
* Indent a line to the given level. Note that this is
1666
* a simple minded but portable implementation.
1667
* There are better ways.
1669
* Also, the indent must be scaled by the compile time option
1670
* of character positions per nesting level.
1674
static void Indent(CODE_STATE *cs, int indent)
1678
indent= max(indent-1-cs->stack->sub_level,0)*INDENT;
1679
for (count= 0; count < indent ; count++)
1681
if ((count % INDENT) == 0)
1682
fputc('|',cs->stack->out_file);
1684
fputc(' ',cs->stack->out_file);
1692
* FreeList free all memory associated with a linked list
1696
* static VOID FreeList(linkp)
1697
* struct link *linkp;
1701
* Given pointer to the head of a linked list, frees all
1702
* memory held by the list and the members of the list.
1706
static void FreeList(struct link *linkp)
1708
REGISTER struct link *old;
1710
while (linkp != NULL)
1713
linkp= linkp->next_link;
1722
* DoPrefix print debugger line prefix prior to indentation
1726
* static VOID DoPrefix(_line_)
1731
* Print prefix common to all debugger output lines, prior to
1732
* doing indentation if necessary. Print such information as
1733
* current process name, current source file name and line number,
1734
* and current function nesting depth.
1738
static void DoPrefix(CODE_STATE *cs, uint _line_)
1741
if (cs->stack->flags & PID_ON)
1744
(void) fprintf(cs->stack->out_file, "%-7s: ", my_thread_name());
1746
(void) fprintf(cs->stack->out_file, "%5d: ", (int) getpid());
1749
if (cs->stack->flags & NUMBER_ON)
1750
(void) fprintf(cs->stack->out_file, "%5d: ", cs->lineno);
1751
if (cs->stack->flags & TIMESTAMP_ON)
1754
/* FIXME This doesn't give microseconds as in Unix case, and the resolution is
1755
in system ticks, 10 ms intervals. See my_getsystime.c for high res */
1757
GetLocalTime(&loc_t);
1758
(void) fprintf (cs->stack->out_file,
1759
/* "%04d-%02d-%02d " */
1760
"%02d:%02d:%02d.%06d ",
1761
/*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/
1762
loc_t.wHour, loc_t.wMinute, loc_t.wSecond, loc_t.wMilliseconds);
1766
if (gettimeofday(&tv, NULL) != -1)
1768
if ((tm_p= localtime((const time_t *)&tv.tv_sec)))
1770
(void) fprintf (cs->stack->out_file,
1771
/* "%04d-%02d-%02d " */
1772
"%02d:%02d:%02d.%06d ",
1773
/*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/
1774
tm_p->tm_hour, tm_p->tm_min, tm_p->tm_sec,
1775
(int) (tv.tv_usec));
1780
if (cs->stack->flags & PROCESS_ON)
1781
(void) fprintf(cs->stack->out_file, "%s: ", cs->process);
1782
if (cs->stack->flags & FILE_ON)
1783
(void) fprintf(cs->stack->out_file, "%14s: ", BaseName(cs->file));
1784
if (cs->stack->flags & LINE_ON)
1785
(void) fprintf(cs->stack->out_file, "%5d: ", _line_);
1786
if (cs->stack->flags & DEPTH_ON)
1787
(void) fprintf(cs->stack->out_file, "%4d: ", cs->level);
1794
* DBUGOpenFile open new output stream for debugger output
1798
* static VOID DBUGOpenFile(name)
1803
* Given name of a new file (or "-" for stdout) opens the file
1804
* and sets the output stream to the new file.
1808
static void DBUGOpenFile(CODE_STATE *cs,
1809
const char *name,const char *end,int append)
1812
REGISTER BOOLEAN newfile;
1819
memcpy(cs->stack->name, name, len);
1820
cs->stack->name[len]=0;
1823
strmov(cs->stack->name,name);
1824
name=cs->stack->name;
1825
if (strcmp(name, "-") == 0)
1827
cs->stack->out_file= stdout;
1828
cs->stack->flags |= FLUSH_ON_WRITE;
1829
cs->stack->name[0]=0;
1833
if (!Writable(name))
1835
(void) fprintf(stderr, ERR_OPEN, cs->process, name);
1841
newfile= !EXISTS(name);
1842
if (!(fp= fopen(name,
1843
#if defined(MSDOS) || defined(__WIN__)
1844
append ? "a+c" : "wc"
1850
(void) fprintf(stderr, ERR_OPEN, cs->process, name);
1856
cs->stack->out_file= fp;
1859
ChangeOwner(cs, name);
1871
* OpenProfile open new output stream for profiler output
1875
* static FILE *OpenProfile(name)
1880
* Given name of a new file, opens the file
1881
* and sets the profiler output stream to the new file.
1883
* It is currently unclear whether the prefered behavior is
1884
* to truncate any existing file, or simply append to it.
1885
* The latter behavior would be desirable for collecting
1886
* accumulated runtime history over a number of separate
1887
* runs. It might take some changes to the analyzer program
1888
* though, and the notes that Binayak sent with the profiling
1889
* diffs indicated that append was the normal mode, but this
1890
* does not appear to agree with the actual code. I haven't
1891
* investigated at this time [fnf; 24-Jul-87].
1895
static FILE *OpenProfile(CODE_STATE *cs, const char *name)
1898
REGISTER BOOLEAN newfile;
1901
if (!Writable(name))
1903
(void) fprintf(cs->stack->out_file, ERR_OPEN, cs->process, name);
1905
(void) Delay(cs->stack->delay);
1909
newfile= !EXISTS(name);
1910
if (!(fp= fopen(name, "w")))
1912
(void) fprintf(cs->stack->out_file, ERR_OPEN, cs->process, name);
1917
cs->stack->prof_file= fp;
1920
ChangeOwner(cs, name);
1931
* DBUGCloseFile close the debug output stream
1935
* static VOID DBUGCloseFile(fp)
1940
* Closes the debug output stream unless it is standard output
1941
* or standard error.
1945
static void DBUGCloseFile(CODE_STATE *cs, FILE *fp)
1947
if (fp != stderr && fp != stdout && fclose(fp) == EOF)
1949
pthread_mutex_lock(&THR_LOCK_dbug);
1950
(void) fprintf(cs->stack->out_file, ERR_CLOSE, cs->process);
1960
* DbugExit print error message and exit
1964
* static VOID DbugExit(why)
1969
* Prints error message using current process name, the reason for
1970
* aborting (typically out of memory), and exits with status 1.
1971
* This should probably be changed to use a status code
1972
* defined in the user's debugger include file.
1976
static void DbugExit(const char *why)
1978
CODE_STATE *cs=code_state();
1979
(void) fprintf(stderr, ERR_ABORT, cs ? cs->process : "(null)", why);
1980
(void) fflush(stderr);
1988
* DbugMalloc allocate memory for debugger runtime support
1992
* static long *DbugMalloc(size)
1997
* Allocate more memory for debugger runtime support functions.
1998
* Failure to to allocate the requested number of bytes is
1999
* immediately fatal to the current process. This may be
2000
* rather unfriendly behavior. It might be better to simply
2001
* print a warning message, freeze the current debugger cs,
2002
* and continue execution.
2006
static char *DbugMalloc(size_t size)
2008
register char *new_malloc;
2010
if (!(new_malloc= (char*) malloc(size)))
2011
DbugExit("out of memory");
2017
* strtok lookalike - splits on ':', magically handles ::, :\ and :/
2020
static const char *DbugStrTok(const char *s)
2022
while (s[0] && (s[0] != ':' ||
2023
(s[1] == '\\' || s[1] == '/' || (s[1] == ':' && s++))))
2032
* BaseName strip leading pathname components from name
2036
* static char *BaseName(pathname)
2041
* Given pointer to a complete pathname, locates the base file
2042
* name at the end of the pathname and returns a pointer to
2047
static const char *BaseName(const char *pathname)
2049
register const char *base;
2051
base= strrchr(pathname, FN_LIBCHAR);
2052
if (base++ == NullS)
2061
* Writable test to see if a pathname is writable/creatable
2065
* static BOOLEAN Writable(pathname)
2070
* Because the debugger might be linked in with a program that
2071
* runs with the set-uid-bit (suid) set, we have to be careful
2072
* about opening a user named file for debug output. This consists
2073
* of checking the file for write access with the real user id,
2074
* or checking the directory where the file will be created.
2076
* Returns TRUE if the user would normally be allowed write or
2077
* create access to the named file. Returns FALSE otherwise.
2084
static BOOLEAN Writable(const char *pathname)
2086
REGISTER BOOLEAN granted;
2087
REGISTER char *lastslash;
2090
if (EXISTS(pathname))
2092
if (WRITABLE(pathname))
2097
lastslash= strrchr(pathname, '/');
2098
if (lastslash != NULL)
2102
if (WRITABLE(pathname))
2104
if (lastslash != NULL)
2115
* ChangeOwner change owner to real user for suid programs
2119
* static VOID ChangeOwner(pathname)
2123
* For unix systems, change the owner of the newly created debug
2124
* file to the real owner. This is strictly for the benefit of
2125
* programs that are running with the set-user-id bit set.
2127
* Note that at this point, the fact that pathname represents
2128
* a newly created file has already been established. If the
2129
* program that the debugger is linked to is not running with
2130
* the suid bit set, then this operation is redundant (but
2136
static void ChangeOwner(CODE_STATE *cs, char *pathname)
2138
if (chown(pathname, getuid(), getgid()) == -1)
2140
(void) fprintf(stderr, ERR_CHOWN, cs->process, pathname);
2142
(void) fflush(stderr);
2151
* _db_setjmp_ save debugger environment
2155
* VOID _db_setjmp_()
2159
* Invoked as part of the user's DBUG_SETJMP macro to save
2160
* the debugger environment in parallel with saving the user's
2167
EXPORT void _db_setjmp_()
2170
get_code_state_or_return;
2172
cs->jmplevel= cs->level;
2173
cs->jmpfunc= cs->func;
2174
cs->jmpfile= cs->file;
2180
* _db_longjmp_ restore previously saved debugger environment
2184
* VOID _db_longjmp_()
2188
* Invoked as part of the user's DBUG_LONGJMP macro to restore
2189
* the debugger environment in parallel with restoring the user's
2190
* previously saved environment.
2194
EXPORT void _db_longjmp_()
2197
get_code_state_or_return;
2199
cs->level= cs->jmplevel;
2201
cs->func= cs->jmpfunc;
2203
cs->file= cs->jmpfile;
2210
* perror perror simulation for systems that don't have it
2214
* static VOID perror(s)
2219
* Perror produces a message on the standard error stream which
2220
* provides more information about the library or system error
2221
* just encountered. The argument string s is printed, followed
2222
* by a ':', a blank, and then a message and a newline.
2224
* An undocumented feature of the unix perror is that if the string
2225
* 's' is a null string (NOT a NULL pointer!), then the ':' and
2226
* blank are not printed.
2228
* This version just complains about an "unknown system error".
2233
static void perror(s)
2236
if (s && *s != '\0')
2237
(void) fprintf(stderr, "%s: ", s);
2238
(void) fprintf(stderr, "<unknown system error>\n");
2240
#endif /* HAVE_PERROR */
2243
/* flush dbug-stream, free mutex lock & wait delay */
2244
/* This is because some systems (MSDOS!!) dosn't flush fileheader */
2245
/* and dbug-file isn't readable after a system crash !! */
2247
static void dbug_flush(CODE_STATE *cs)
2250
if (cs->stack->flags & FLUSH_ON_WRITE)
2253
(void) fflush(cs->stack->out_file);
2254
if (cs->stack->delay)
2255
(void) Delay(cs->stack->delay);
2258
pthread_mutex_unlock(&THR_LOCK_dbug);
2262
void _db_lock_file_()
2265
get_code_state_or_return;
2266
pthread_mutex_lock(&THR_LOCK_dbug);
2270
void _db_unlock_file_()
2273
get_code_state_or_return;
2275
pthread_mutex_unlock(&THR_LOCK_dbug);
2279
* Here we need the definitions of the clock routine. Add your
2280
* own for whatever system that you have.
2284
#if defined(HAVE_GETRUSAGE)
2286
#include <sys/param.h>
2287
#include <sys/resource.h>
2289
/* extern int getrusage(int, struct rusage *); */
2292
* Returns the user time in milliseconds used by this process so
2296
static unsigned long Clock()
2300
(void) getrusage(RUSAGE_SELF, &ru);
2301
return ru.ru_utime.tv_sec*1000 + ru.ru_utime.tv_usec/1000;
2304
#elif defined(MSDOS) || defined(__WIN__)
2306
static ulong Clock()
2308
return clock()*(1000/CLOCKS_PER_SEC);
2310
#elif defined(amiga)
2312
struct DateStamp { /* Yes, this is a hack, but doing it right */
2313
long ds_Days; /* is incredibly ugly without splitting this */
2314
long ds_Minute; /* off into a separate file */
2318
static int first_clock= TRUE;
2319
static struct DateStamp begin;
2320
static struct DateStamp elapsed;
2322
static unsigned long Clock()
2324
register struct DateStamp *now;
2325
register unsigned long millisec= 0;
2326
extern VOID *AllocMem();
2328
now= (struct DateStamp *) AllocMem((long) sizeof(struct DateStamp), 0L);
2331
if (first_clock == TRUE)
2334
(void) DateStamp(now);
2337
(void) DateStamp(now);
2338
millisec= 24 * 3600 * (1000 / HZ) * (now->ds_Days - begin.ds_Days);
2339
millisec += 60 * (1000 / HZ) * (now->ds_Minute - begin.ds_Minute);
2340
millisec += (1000 / HZ) * (now->ds_Tick - begin.ds_Tick);
2341
(void) FreeMem(now, (long) sizeof(struct DateStamp));
2346
static unsigned long Clock()
2351
#endif /* THREADS */
2356
* Fake vfprintf for systems that don't support it. If this
2357
* doesn't work, you are probably SOL...
2360
static int vfprintf(stream, format, ap)
2368
ARG0= va_arg(ap, ARGS_TYPE);
2369
ARG1= va_arg(ap, ARGS_TYPE);
2370
ARG2= va_arg(ap, ARGS_TYPE);
2371
ARG3= va_arg(ap, ARGS_TYPE);
2372
ARG4= va_arg(ap, ARGS_TYPE);
2373
ARG5= va_arg(ap, ARGS_TYPE);
2374
ARG6= va_arg(ap, ARGS_TYPE);
2375
ARG7= va_arg(ap, ARGS_TYPE);
2376
ARG8= va_arg(ap, ARGS_TYPE);
2377
ARG9= va_arg(ap, ARGS_TYPE);
2378
rtnval= fprintf(stream, format, ARGS_LIST);
2382
#endif /* NO_VARARGS */
2387
* Dummy function, workaround for MySQL bug#14420 related
2388
* build failure on a platform where linking with an empty
2391
* This block can be removed as soon as a fix for bug#14420
2394
int i_am_a_dummy_function() {