#include <my_global.h>#include <m_string.h>#include <errno.h>#include <stdarg.h>Include dependency graph for dbug.c:

Go to the source code of this file.
Classes | |
| struct | link |
| struct | settings |
| struct | _db_code_state_ |
Defines | |
| #define | PRINTBUF 1024 |
| #define | INDENT 2 |
| #define | MAXDEPTH 200 |
| #define | TRACE_ON 000001 |
| #define | DEBUG_ON 000002 |
| #define | FILE_ON 000004 |
| #define | LINE_ON 000010 |
| #define | DEPTH_ON 000020 |
| #define | PROCESS_ON 000040 |
| #define | NUMBER_ON 000100 |
| #define | PROFILE_ON 000200 |
| #define | PID_ON 000400 |
| #define | TIMESTAMP_ON 001000 |
| #define | SANITY_CHECK_ON 002000 |
| #define | FLUSH_ON_WRITE 004000 |
| #define | OPEN_APPEND 010000 |
| #define | TRACING (cs->stack->flags & TRACE_ON) |
| #define | DEBUGGING (cs->stack->flags & DEBUG_ON) |
| #define | PROFILING (cs->stack->flags & PROFILE_ON) |
| #define | IMPORT extern |
| #define | EXPORT |
| #define | AUTO auto |
| #define | REGISTER register |
| #define | PROF_FILE "dbugmon.out" |
| #define | PROF_EFMT "E\t%ld\t%s\n" |
| #define | PROF_SFMT "S\t%lx\t%lx\t%s\n" |
| #define | PROF_XFMT "X\t%ld\t%s\n" |
| #define | is_shared(S, V) ((S)->next && (S)->next->V == (S)->V) |
| #define | get_code_state_or_return if (!cs && !((cs=code_state()))) return |
| #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 | EXISTS(pathname) (FALSE) |
| #define | Writable(name) (TRUE) |
| #define | ChangeOwner(cs, name) |
| #define | pthread_mutex_lock(A) {} |
| #define | pthread_mutex_unlock(A) {} |
| #define | Delay(A) (0) |
| #define | char_to_buf(C) |
| #define | str_to_buf(S) |
| #define | list_to_buf(l) |
| #define | int_to_buf(i) |
| #define | colon_to_buf |
| #define | op_int_to_buf(C, val, def) |
| #define | op_intf_to_buf(C, val, def, cond) |
| #define | op_str_to_buf(C, val, cond) |
| #define | op_list_to_buf(C, val, cond) |
| #define | op_bool_to_buf(C, cond) |
Typedefs | |
| typedef int | BOOLEAN |
| typedef _db_code_state_ | CODE_STATE |
Functions | |
| static void | perror () |
| IMPORT int | _sanity (const char *file, uint line) |
| static struct link * | ListAdd (struct link *, const char *, const char *) |
| static struct link * | ListDel (struct link *, const char *, const char *) |
| static struct link * | ListCopy (struct link *) |
| static void | FreeList (struct link *linkp) |
| static void | DBUGOpenFile (CODE_STATE *, const char *, const char *, int) |
| static void | DBUGCloseFile (CODE_STATE *cs, FILE *fp) |
| static void | PushState (CODE_STATE *cs) |
| static void | FreeState (CODE_STATE *cs, struct settings *state) |
| static BOOLEAN | DoTrace (CODE_STATE *cs) |
| static void | DoPrefix (CODE_STATE *cs, uint line) |
| static char * | DbugMalloc (size_t size) |
| static const char * | BaseName (const char *pathname) |
| static void | Indent (CODE_STATE *cs, int indent) |
| static BOOLEAN | InList (struct link *linkp, const char *cp) |
| static void | dbug_flush (CODE_STATE *) |
| static void | DbugExit (const char *why) |
| static const char * | DbugStrTok (const char *s) |
| static FILE * | OpenProfile (CODE_STATE *cs, const char *name) |
| static BOOLEAN | DoProfile (CODE_STATE *) |
| static unsigned long | Clock (void) |
| static CODE_STATE * | code_state (void) |
| void | _db_process_ (const char *name) |
| void | _db_set_ (CODE_STATE *cs, const char *control) |
| void | _db_push_ (const char *control) |
| void | _db_set_init_ (const char *control) |
| void | _db_pop_ () |
| int | _db_explain_ (CODE_STATE *cs, char *buf, int len) |
| int | _db_explain_init_ (char *buf, int len) |
| void | _db_enter_ (const char *_func_, const char *_file_, uint _line_, const char **_sfunc_, const char **_sfile_, uint *_slevel_, char ***_sframep_ __attribute__((unused))) |
| void | _db_return_ (uint _line_, const char **_sfunc_, const char **_sfile_, uint *_slevel_) |
| void | _db_pargs_ (uint _line_, const char *keyword) |
| void | _db_doprnt_ (const char *format,...) |
| void | _db_dump_ (uint _line_, const char *keyword, const char *memory, uint length) |
| void | _db_end_ () |
| FILE * | _db_fp_ (void) |
| BOOLEAN | _db_strict_keyword_ (const char *keyword) |
| BOOLEAN | _db_keyword_ (CODE_STATE *cs, const char *keyword) |
| static void | perror (char *s) |
| void | _db_lock_file_ () |
| void | _db_unlock_file_ () |
Variables | |
| static BOOLEAN | init_done = FALSE |
| static struct settings | init_settings |
| static const char * | db_process = 0 |
| static CODE_STATE | static_code_state |
| #define ChangeOwner | ( | cs, | |||
| name | ) |
| #define char_to_buf | ( | C | ) |
| #define colon_to_buf |
Value:
do { \ if (buf != start) char_to_buf(':'); \ } while(0)
| #define DEBUG_ON 000002 |
| #define DEBUGGING (cs->stack->flags & DEBUG_ON) |
Definition at line 116 of file dbug.c.
Referenced by _db_explain_(), _db_keyword_(), _db_set_(), and _db_strict_keyword_().
| #define Delay | ( | A | ) | (0) |
| #define DEPTH_ON 000020 |
| #define ERR_ABORT "%s: debugger aborting because %s\n" |
| #define ERR_CLOSE "%s: can't close debug file: " |
| #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\": " |
Definition at line 298 of file dbug.c.
Referenced by dbug_flush(), DBUGOpenFile(), and OpenProfile().
| #define EXISTS | ( | pathname | ) | (FALSE) |
| #define FILE_ON 000004 |
| #define FLUSH_ON_WRITE 004000 |
Definition at line 112 of file dbug.c.
Referenced by _db_explain_(), _db_set_(), dbug_flush(), and DBUGOpenFile().
| #define get_code_state_or_return if (!cs && !((cs=code_state()))) return |
Definition at line 248 of file dbug.c.
Referenced by _db_doprnt_(), _db_dump_(), _db_end_(), _db_enter_(), _db_explain_(), _db_fp_(), _db_keyword_(), _db_lock_file_(), _db_pargs_(), _db_pop_(), _db_process_(), _db_push_(), _db_return_(), _db_set_(), _db_strict_keyword_(), and _db_unlock_file_().
| #define INDENT 2 |
| #define int_to_buf | ( | i | ) |
Value:
do { \ char b[50]; \ int10_to_str((i), b, 10); \ str_to_buf(b); \ } while (0)
| #define is_shared | ( | S, | |||
| V | ) | ((S)->next && (S)->next->V == (S)->V) |
| #define LINE_ON 000010 |
| #define list_to_buf | ( | l | ) |
| #define MAXDEPTH 200 |
| #define NUMBER_ON 000100 |
| #define op_bool_to_buf | ( | C, | |||
| cond | ) |
Value:
do { \ if ((cond)) \ { \ colon_to_buf; \ char_to_buf((C)); \ } \ } while (0)
Definition at line 823 of file dbug.c.
Referenced by _db_explain_().
| #define op_int_to_buf | ( | C, | |||
| val, | |||||
| def | ) |
Value:
do { \ if ((val) != (def)) \ { \ colon_to_buf; \ char_to_buf((C)); \ int_to_buf(val); \ } \ } while (0)
Definition at line 790 of file dbug.c.
Referenced by _db_explain_().
| #define op_intf_to_buf | ( | C, | |||
| val, | |||||
| def, | |||||
| cond | ) |
Value:
do { \ if ((cond)) \ { \ colon_to_buf; \ char_to_buf((C)); \ if ((val) != (def)) int_to_buf(val); \ } \ } while (0)
Definition at line 798 of file dbug.c.
Referenced by _db_explain_().
| #define op_list_to_buf | ( | C, | |||
| val, | |||||
| cond | ) |
Value:
do { \ if ((cond)) \ { \ colon_to_buf; \ char_to_buf((C)); \ list_to_buf(val); \ } \ } while (0)
Definition at line 815 of file dbug.c.
Referenced by _db_explain_().
| #define op_str_to_buf | ( | C, | |||
| val, | |||||
| cond | ) |
Value:
do { \ if ((cond)) \ { \ char *s=(val); \ colon_to_buf; \ char_to_buf((C)); \ if (*s) str_to_buf(s); \ } \ } while (0)
Definition at line 806 of file dbug.c.
Referenced by _db_explain_().
| #define OPEN_APPEND 010000 |
| #define PID_ON 000400 |
| #define PROCESS_ON 000040 |
| #define PROF_EFMT "E\t%ld\t%s\n" |
| #define PROF_FILE "dbugmon.out" |
| #define PROF_SFMT "S\t%lx\t%lx\t%s\n" |
| #define PROF_XFMT "X\t%ld\t%s\n" |
| #define PROFILE_ON 000200 |
| #define PROFILING (cs->stack->flags & PROFILE_ON) |
| #define REGISTER register |
Definition at line 136 of file dbug.c.
Referenced by DBUGOpenFile(), FreeList(), Indent(), InList(), and OpenProfile().
| #define SANITY_CHECK_ON 002000 |
Definition at line 111 of file dbug.c.
Referenced by _db_enter_(), _db_explain_(), _db_return_(), and _db_set_().
| #define str_to_buf | ( | S | ) |
| #define TIMESTAMP_ON 001000 |
| #define TRACE_ON 000001 |
| #define TRACING (cs->stack->flags & TRACE_ON) |
Definition at line 115 of file dbug.c.
Referenced by _db_doprnt_(), _db_dump_(), _db_explain_(), _db_keyword_(), and DoTrace().
| #define Writable | ( | name | ) | (TRUE) |
| typedef struct _db_code_state_ CODE_STATE |
| void _db_doprnt_ | ( | const char * | format, | |
| ... | ||||
| ) |
Definition at line 1114 of file dbug.c.
References _db_keyword_(), args, dbug_flush(), DoPrefix(), errno, get_code_state_or_return, Indent(), _db_code_state_::level, _db_code_state_::locked, pthread_mutex_lock, TRACING, _db_code_state_::u_keyword, and _db_code_state_::u_line.
01115 { 01116 va_list args; 01117 01118 CODE_STATE *cs=0; 01119 get_code_state_or_return; 01120 01121 va_start(args,format); 01122 01123 if (_db_keyword_(cs, cs->u_keyword)) 01124 { 01125 int save_errno=errno; 01126 if (!cs->locked) 01127 pthread_mutex_lock(&THR_LOCK_dbug); 01128 DoPrefix(cs, cs->u_line); 01129 if (TRACING) 01130 Indent(cs, cs->level + 1); 01131 else 01132 (void) fprintf(cs->stack->out_file, "%s: ", cs->func); 01133 (void) fprintf(cs->stack->out_file, "%s: ", cs->u_keyword); 01134 (void) vfprintf(cs->stack->out_file, format, args); 01135 (void) fputc('\n',cs->stack->out_file); 01136 dbug_flush(cs); 01137 errno=save_errno; 01138 } 01139 va_end(args); 01140 }
Here is the call graph for this function:

Definition at line 1161 of file dbug.c.
References _db_keyword_(), _dig_vec_upper, dbug_flush(), DoPrefix(), _db_code_state_::func, get_code_state_or_return, INDENT, Indent(), _db_code_state_::level, _db_code_state_::locked, max, min, settings::out_file, pos(), pthread_mutex_lock, _db_code_state_::stack, and TRACING.
01162 { 01163 int pos; 01164 char dbuff[90]; 01165 01166 CODE_STATE *cs=0; 01167 get_code_state_or_return; 01168 01169 if (_db_keyword_(cs, (char*) keyword)) 01170 { 01171 if (!cs->locked) 01172 pthread_mutex_lock(&THR_LOCK_dbug); 01173 DoPrefix(cs, _line_); 01174 if (TRACING) 01175 { 01176 Indent(cs, cs->level + 1); 01177 pos= min(max(cs->level-cs->stack->sub_level,0)*INDENT,80); 01178 } 01179 else 01180 { 01181 fprintf(cs->stack->out_file, "%s: ", cs->func); 01182 } 01183 sprintf(dbuff,"%s: Memory: 0x%lx Bytes: (%d)\n", 01184 keyword,(ulong) memory, length); 01185 (void) fputs(dbuff,cs->stack->out_file); 01186 01187 pos=0; 01188 while (length-- > 0) 01189 { 01190 uint tmp= *((unsigned char*) memory++); 01191 if ((pos+=3) >= 80) 01192 { 01193 fputc('\n',cs->stack->out_file); 01194 pos=3; 01195 } 01196 fputc(_dig_vec_upper[((tmp >> 4) & 15)], cs->stack->out_file); 01197 fputc(_dig_vec_upper[tmp & 15], cs->stack->out_file); 01198 fputc(' ',cs->stack->out_file); 01199 } 01200 (void) fputc('\n',cs->stack->out_file); 01201 dbug_flush(cs); 01202 } 01203 }
Here is the call graph for this function:

| void _db_end_ | ( | void | ) |
Definition at line 1473 of file dbug.c.
References FreeState(), get_code_state_or_return, init_settings, settings::next, NULL, and _db_code_state_::stack.
01474 { 01475 struct settings *discard; 01476 CODE_STATE *cs=0; 01477 01478 get_code_state_or_return; 01479 01480 while((discard= cs->stack) != NULL) { 01481 if(discard == &init_settings) 01482 break; 01483 cs->stack= discard->next; 01484 FreeState (cs, discard); 01485 } 01486 }
Here is the call graph for this function:

| void _db_enter_ | ( | const char * | _func_, | |
| const char * | _file_, | |||
| uint | _line_, | |||
| const char ** | _sfunc_, | |||
| const char ** | _sfile_, | |||
| uint * | _slevel_, | |||
| char ***_sframep_ | __attribute__((unused)) | |||
| ) |
Definition at line 934 of file dbug.c.
References _sanity(), Clock(), dbug_flush(), DoPrefix(), DoProfile(), DoTrace(), errno, _db_code_state_::file, _db_code_state_::framep, _db_code_state_::func, get_code_state_or_return, Indent(), _db_code_state_::level, NULL, PROF_EFMT, PROF_SFMT, pthread_mutex_lock, and SANITY_CHECK_ON.
00937 { 00938 int save_errno=errno; 00939 CODE_STATE *cs=0; 00940 get_code_state_or_return; 00941 00942 *_sfunc_= cs->func; 00943 *_sfile_= cs->file; 00944 cs->func= _func_; 00945 cs->file= _file_; 00946 *_slevel_= ++cs->level; 00947 #ifndef THREAD 00948 *_sframep_= cs->framep; 00949 cs->framep= (char **) _sframep_; 00950 if (DoProfile(cs)) 00951 { 00952 long stackused; 00953 if (*cs->framep == NULL) 00954 stackused= 0; 00955 else 00956 { 00957 stackused= ((long)(*cs->framep)) - ((long)(cs->framep)); 00958 stackused= stackused > 0 ? stackused : -stackused; 00959 } 00960 (void) fprintf(cs->stack->prof_file, PROF_EFMT , Clock(), cs->func); 00961 #ifdef AUTOS_REVERSE 00962 (void) fprintf(cs->stack->prof_file, PROF_SFMT, cs->framep, stackused, *_sfunc_); 00963 #else 00964 (void) fprintf(cs->stack->prof_file, PROF_SFMT, (ulong) cs->framep, stackused, 00965 cs->func); 00966 #endif 00967 (void) fflush(cs->stack->prof_file); 00968 } 00969 #endif 00970 if (DoTrace(cs)) 00971 { 00972 if (!cs->locked) 00973 pthread_mutex_lock(&THR_LOCK_dbug); 00974 DoPrefix(cs, _line_); 00975 Indent(cs, cs->level); 00976 (void) fprintf(cs->stack->out_file, ">%s\n", cs->func); 00977 dbug_flush(cs); /* This does a unlock */ 00978 } 00979 #ifdef SAFEMALLOC 00980 if (cs->stack->flags & SANITY_CHECK_ON) 00981 if (_sanity(_file_,_line_)) /* Check of safemalloc */ 00982 cs->stack->flags &= ~SANITY_CHECK_ON; 00983 #endif 00984 errno=save_errno; 00985 }
Here is the call graph for this function:

| int _db_explain_ | ( | CODE_STATE * | cs, | |
| char * | buf, | |||
| int | len | |||
| ) |
Definition at line 831 of file dbug.c.
References DEBUGGING, settings::delay, DEPTH_ON, FILE_ON, settings::flags, FLUSH_ON_WRITE, settings::functions, get_code_state_or_return, settings::keywords, LINE_ON, MAXDEPTH, settings::maxdepth, settings::name, NUMBER_ON, op_bool_to_buf, op_int_to_buf, op_intf_to_buf, op_list_to_buf, op_str_to_buf, OPEN_APPEND, settings::out_file, settings::p_functions, PID_ON, PROCESS_ON, settings::processes, PROFILING, SANITY_CHECK_ON, _db_code_state_::stack, start(), settings::sub_level, TIMESTAMP_ON, and TRACING.
00832 { 00833 char *start=buf, *end=buf+len-4; 00834 00835 get_code_state_or_return *buf=0; 00836 00837 op_list_to_buf('d', cs->stack->keywords, DEBUGGING); 00838 op_int_to_buf ('D', cs->stack->delay, 0); 00839 op_list_to_buf('f', cs->stack->functions, cs->stack->functions); 00840 op_bool_to_buf('F', cs->stack->flags & FILE_ON); 00841 op_bool_to_buf('i', cs->stack->flags & PID_ON); 00842 op_list_to_buf('g', cs->stack->p_functions, PROFILING); 00843 op_bool_to_buf('L', cs->stack->flags & LINE_ON); 00844 op_bool_to_buf('n', cs->stack->flags & DEPTH_ON); 00845 op_bool_to_buf('N', cs->stack->flags & NUMBER_ON); 00846 op_str_to_buf( 00847 ((cs->stack->flags & FLUSH_ON_WRITE ? 0 : 32) | 00848 (cs->stack->flags & OPEN_APPEND ? 'A' : 'O')), 00849 cs->stack->name, cs->stack->out_file != stderr); 00850 op_list_to_buf('p', cs->stack->processes, cs->stack->processes); 00851 op_bool_to_buf('P', cs->stack->flags & PROCESS_ON); 00852 op_bool_to_buf('r', cs->stack->sub_level != 0); 00853 op_intf_to_buf('t', cs->stack->maxdepth, MAXDEPTH, TRACING); 00854 op_bool_to_buf('T', cs->stack->flags & TIMESTAMP_ON); 00855 op_bool_to_buf('S', cs->stack->flags & SANITY_CHECK_ON); 00856 00857 *buf= '\0'; 00858 return 0; 00859 00860 overflow: 00861 *end++= '.'; 00862 *end++= '.'; 00863 *end++= '.'; 00864 *end= '\0'; 00865 return 1; 00866 }
Here is the call graph for this function:

