MySQL 8.0.40
Source Code Documentation
dbug.cc File Reference
#include "my_config.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <algorithm>
#include "m_string.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_sys.h"
#include "my_thread_local.h"
#include "thr_mutex.h"
#include "thr_rwlock.h"
#include <fnmatch.h>
#include <signal.h>

Classes

struct  link
 
struct  settings
 
struct  CODE_STATE
 

Macros

#define INDENT   2 /* Indentation per trace level */
 
#define MAXDEPTH   200 /* Maximum trace depth default */
 
#define DEBUG_ON   (1 << 1) /* Debug enabled */
 
#define FILE_ON   (1 << 2) /* File name print enabled */
 
#define LINE_ON   (1 << 3) /* Line number print enabled */
 
#define DEPTH_ON   (1 << 4) /* Function nest level print enabled */
 
#define PROCESS_ON   (1 << 5) /* Process name print enabled */
 
#define NUMBER_ON   (1 << 6) /* Number each line of output */
 
#define PROFILE_ON   (1 << 7) /* Print out profiling code */
 
#define PID_ON   (1 << 8) /* Identify each line with process id */
 
#define TIMESTAMP_ON   (1 << 9) /* timestamp every line of output */
 
#define FLUSH_ON_WRITE   (1 << 10) /* Flush on every write */
 
#define OPEN_APPEND   (1 << 11) /* Open for append */
 
#define TRACE_ON   ((uint)1 << 31) /* Trace enabled. MUST be the highest bit!*/
 
#define TRACING   (cs->stack->flags & TRACE_ON)
 
#define DEBUGGING   (cs->stack->flags & DEBUG_ON)
 
#define PROFILING   (cs->stack->flags & PROFILE_ON)
 
#define SUBDIR   1 /* this MUST be 1 */
 
#define INCLUDE   2
 
#define EXCLUDE   4
 
#define MATCHED   65536
 
#define NOT_MATCHED   0
 
#define is_shared(S, V)   ((S)->next && (S)->next->V == (S)->V)
 
#define get_code_state_if_not_set_or_return    if (!cs && !((cs = code_state()))) return
 
#define get_code_state_or_return    if (!((cs = code_state()))) return
 
#define ListAdd(A, B, C)   ListAddDel(A, B, C, INCLUDE)
 
#define ListDel(A, B, C)   ListAddDel(A, B, C, EXCLUDE)
 
#define DO_TRACE   1
 
#define DONT_TRACE   2
 
#define ENABLE_TRACE   3
 
#define DISABLE_TRACE   4
 
#define ERR_MISSING_RETURN    "missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n"
 
#define ERR_MISSING_UNLOCK   "missing DBUG_UNLOCK_FILE 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 Delay(A)   sleep(((uint)A) / 10)
 
#define framep_trace_flag(cs, frp)
 
#define fflags(cs)    cs->stack->out_file ? ListFlags(cs->stack->functions) : TRACE_ON;
 
#define char_to_buf(C)
 
#define str_to_buf(S)
 
#define list_to_buf(l, f)
 
#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)
 

Functions

static struct linkListAddDel (struct link *, const char *, const char *, int)
 
static struct linkListCopy (struct link *)
 
static int InList (struct link *linkp, const char *cp)
 
static uint ListFlags (struct link *linkp)
 
static void FreeList (struct link *linkp)
 
static int isseparator (const char *ptr)
 
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, int free_state)
 
static int DoTrace (CODE_STATE *cs)
 
static void DoPrefix (CODE_STATE *cs, uint line)
 
static bool Writable (const char *pathname)
 
static char * DbugMalloc (size_t size)
 
static const char * BaseName (const char *pathname)
 
static void Indent (CODE_STATE *cs, int indent)
 
static void DbugFlush (CODE_STATE *)
 
static void DbugExit (const char *why)
 
static const char * DbugStrTok (const char *s)
 
static void DbugVfprintf (FILE *stream, const char *format, va_list args)
 
static CODE_STATEcode_state (void)
 
static void read_lock_stack (CODE_STATE *cs)
 Lock the stack debugging settings. More...
 
static void unlock_stack (CODE_STATE *cs)
 Unlock the stack debugging settings. More...
 
void _db_process_ (const char *name)
 
static int DbugParse (CODE_STATE *cs, const char *control)
 
static void FixTraceFlags_helper (CODE_STATE *cs, const char *func, struct _db_stack_frame_ *framep)
 
static void FixTraceFlags (uint old_fflags, CODE_STATE *cs)
 
void _db_set_ (const char *control)
 
void _db_push_ (const char *control)
 
int _db_is_pushed_ ()
 Returns true if session-local settings have been set. More...
 
void _db_set_init_ (const char *control)
 
void _db_pop_ ()
 
int _db_explain_ (CODE_STATE *cs, char *buf, size_t len)
 
int _db_explain_init_ (char *buf, size_t len)
 
void _db_enter_ (const char *_func_, int func_len, const char *_file_, uint _line_, struct _db_stack_frame_ *_stack_frame_)
 
void _db_return_ (uint _line_, struct _db_stack_frame_ *_stack_frame_)
 
void _db_pargs_ (uint _line_, const char *keyword)
 
int _db_enabled_ ()
 
void _db_doprnt_ (const char *format,...)
 
void _db_dump_ (uint _line_, const char *keyword, const unsigned char *memory, size_t length)
 
void _db_end_ ()
 
FILE * _db_fp_ (void)
 
int _db_keyword_ (CODE_STATE *cs, const char *keyword, int strict)
 
void _db_flush_ ()
 
void _db_flush_gcov_ ()
 
void _db_suicide_ ()
 
void _db_lock_file_ ()
 
void _db_unlock_file_ ()
 

Variables

static bool init_done = false
 
static struct settings init_settings
 Global debugging settings. More...
 
static const char * db_process = nullptr
 
static native_mutex_t THR_LOCK_dbug
 
static native_mutex_t THR_LOCK_gcov
 A mutex protecting flushing of gcov data, see db_flush_gcov(). More...
 
static native_rw_lock_t THR_LOCK_init_settings
 Lock, to protect init_settings. More...
 

Macro Definition Documentation

◆ char_to_buf

#define char_to_buf (   C)
Value:
do { \
*buf++ = (C); \
if (buf >= end) goto overflow; \
} while (0)
Definition: buf0block_hint.cc:30
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192

◆ colon_to_buf

#define colon_to_buf
Value:
do { \
if (buf != start) char_to_buf(':'); \
} while (0)
#define char_to_buf(C)
Definition: dbug.cc:939
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:177

◆ DEBUG_ON

#define DEBUG_ON   (1 << 1) /* Debug enabled */

◆ DEBUGGING

#define DEBUGGING   (cs->stack->flags & DEBUG_ON)

◆ Delay

#define Delay (   A)    sleep(((uint)A) / 10)

◆ DEPTH_ON

#define DEPTH_ON   (1 << 4) /* Function nest level print enabled */

◆ DISABLE_TRACE

#define DISABLE_TRACE   4

◆ DO_TRACE

#define DO_TRACE   1

◆ DONT_TRACE

#define DONT_TRACE   2

◆ ENABLE_TRACE

#define ENABLE_TRACE   3

◆ ERR_ABORT

#define ERR_ABORT   "%s: debugger aborting because %s\n"

◆ ERR_CLOSE

#define ERR_CLOSE   "%s: can't close debug file: "

◆ ERR_MISSING_RETURN

#define ERR_MISSING_RETURN    "missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n"

◆ ERR_MISSING_UNLOCK

#define ERR_MISSING_UNLOCK   "missing DBUG_UNLOCK_FILE macro in function \"%s\"\n"

◆ ERR_OPEN

#define ERR_OPEN   "%s: can't open debug output stream \"%s\": "

◆ EXCLUDE

#define EXCLUDE   4

◆ fflags

#define fflags (   cs)     cs->stack->out_file ? ListFlags(cs->stack->functions) : TRACE_ON;

◆ FILE_ON

#define FILE_ON   (1 << 2) /* File name print enabled */

◆ FLUSH_ON_WRITE

#define FLUSH_ON_WRITE   (1 << 10) /* Flush on every write */

◆ framep_trace_flag

#define framep_trace_flag (   cs,
  frp 
)
Value:
(frp ? frp->level & TRACE_ON \
: (ListFlags(cs->stack->functions) & INCLUDE) ? 0 \
#define TRACE_ON
Definition: dbug.cc:150
#define INCLUDE
Definition: dbug.cc:170
static uint ListFlags(struct link *linkp)
Definition: dbug.cc:1573
Definition: commit_order_queue.h:34
unsigned int uint
Definition: uca9-dump.cc:75

◆ get_code_state_if_not_set_or_return

#define get_code_state_if_not_set_or_return    if (!cs && !((cs = code_state()))) return

◆ get_code_state_or_return

#define get_code_state_or_return    if (!((cs = code_state()))) return

◆ INCLUDE

#define INCLUDE   2

◆ INDENT

#define INDENT   2 /* Indentation per trace level */

◆ int_to_buf

#define int_to_buf (   i)
Value:
do { \
char b[50]; \
longlong10_to_str((i), b, 10); \
str_to_buf(b); \
} while (0)

◆ is_shared

#define is_shared (   S,
 
)    ((S)->next && (S)->next->V == (S)->V)

◆ LINE_ON

#define LINE_ON   (1 << 3) /* Line number print enabled */

◆ list_to_buf

#define list_to_buf (   l,
 
)
Value:
do { \
struct link *listp = (l); \
while (listp) { \
if (listp->flags & (f)) { \
str_to_buf(listp->str); \
if (listp->flags & SUBDIR) char_to_buf('/'); \
} \
listp = listp->next_link; \
} \
} while (0)
#define SUBDIR
Definition: dbug.cc:169

◆ ListAdd

#define ListAdd (   A,
  B,
 
)    ListAddDel(A, B, C, INCLUDE)

◆ ListDel

#define ListDel (   A,
  B,
 
)    ListAddDel(A, B, C, EXCLUDE)

◆ MATCHED

#define MATCHED   65536

◆ MAXDEPTH

#define MAXDEPTH   200 /* Maximum trace depth default */

◆ NOT_MATCHED

#define NOT_MATCHED   0

◆ NUMBER_ON

#define NUMBER_ON   (1 << 6) /* Number each line of output */

◆ op_bool_to_buf

#define op_bool_to_buf (   C,
  cond 
)
Value:
do { \
if ((cond)) { \
colon_to_buf; \
char_to_buf((C)); \
} \
} while (0)

◆ op_int_to_buf

#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)

◆ op_intf_to_buf

#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)
#define int_to_buf(i)
Definition: dbug.cc:961

◆ op_list_to_buf

#define op_list_to_buf (   C,
  val,
  cond 
)
Value:
do { \
if ((cond)) { \
int f = ListFlags(val); \
colon_to_buf; \
char_to_buf((C)); \
if (f & INCLUDE) list_to_buf(val, INCLUDE); \
if (f & EXCLUDE) { \
colon_to_buf; \
char_to_buf('-'); \
char_to_buf((C)); \
list_to_buf(val, EXCLUDE); \
} \
} \
} while (0)
#define EXCLUDE
Definition: dbug.cc:171
#define list_to_buf(l, f)
Definition: dbug.cc:950

◆ op_str_to_buf

#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)
#define str_to_buf(S)
Definition: dbug.cc:944

◆ OPEN_APPEND

#define OPEN_APPEND   (1 << 11) /* Open for append */

◆ PID_ON

#define PID_ON   (1 << 8) /* Identify each line with process id */

◆ PROCESS_ON

#define PROCESS_ON   (1 << 5) /* Process name print enabled */

◆ PROFILE_ON

#define PROFILE_ON   (1 << 7) /* Print out profiling code */

◆ PROFILING

#define PROFILING   (cs->stack->flags & PROFILE_ON)

◆ str_to_buf

#define str_to_buf (   S)
Value:
do { \
char_to_buf(','); \
buf = my_stpnmov(buf, (S), end - buf); \
if (buf >= end) goto overflow; \
} while (0)
static char * my_stpnmov(char *dst, const char *src, size_t n)
Definition: m_string.h:145

◆ SUBDIR

#define SUBDIR   1 /* this MUST be 1 */

◆ TIMESTAMP_ON

#define TIMESTAMP_ON   (1 << 9) /* timestamp every line of output */

◆ TRACE_ON

#define TRACE_ON   ((uint)1 << 31) /* Trace enabled. MUST be the highest bit!*/

◆ TRACING

#define TRACING   (cs->stack->flags & TRACE_ON)

Function Documentation

◆ _db_doprnt_()

void _db_doprnt_ ( const char *  format,
  ... 
)

◆ _db_dump_()

void _db_dump_ ( uint  _line_,
const char *  keyword,
const unsigned char *  memory,
size_t  length 
)

◆ _db_enabled_()

int _db_enabled_ ( )

◆ _db_end_()

void _db_end_ ( void  )

◆ _db_enter_()

void _db_enter_ ( const char *  _func_,
int  func_len,
const char *  _file_,
uint  _line_,
struct _db_stack_frame_ _stack_frame_ 
)

◆ _db_explain_()

int _db_explain_ ( CODE_STATE cs,
char *  buf,
size_t  len 
)

◆ _db_explain_init_()

int _db_explain_init_ ( char *  buf,
size_t  len 
)

◆ _db_flush_()

void _db_flush_ ( )

◆ _db_flush_gcov_()

void _db_flush_gcov_ ( )

◆ _db_fp_()

FILE * _db_fp_ ( void  )

◆ _db_is_pushed_()

int _db_is_pushed_ ( void  )

Returns true if session-local settings have been set.

◆ _db_keyword_()

int _db_keyword_ ( CODE_STATE cs,
const char *  keyword,
int  strict 
)

◆ _db_lock_file_()

void _db_lock_file_ ( void  )

◆ _db_pargs_()

void _db_pargs_ ( uint  _line_,
const char *  keyword 
)

◆ _db_pop_()

void _db_pop_ ( void  )

◆ _db_process_()

void _db_process_ ( const char *  name)

◆ _db_push_()

void _db_push_ ( const char *  control)

◆ _db_return_()

void _db_return_ ( uint  _line_,
struct _db_stack_frame_ _stack_frame_ 
)

◆ _db_set_()

void _db_set_ ( const char *  control)

◆ _db_set_init_()

void _db_set_init_ ( const char *  control)

◆ _db_suicide_()

void _db_suicide_ ( )

◆ _db_unlock_file_()

void _db_unlock_file_ ( void  )

◆ BaseName()

static const char * BaseName ( const char *  pathname)
static

◆ code_state()

static CODE_STATE * code_state ( void  )
static

◆ DBUGCloseFile()

static void DBUGCloseFile ( CODE_STATE cs,
FILE *  fp 
)
static

◆ DbugExit()

static void DbugExit ( const char *  why)
static

◆ DbugFlush()

static void DbugFlush ( CODE_STATE cs)
static

◆ DbugMalloc()

static char * DbugMalloc ( size_t  size)
static

◆ DBUGOpenFile()

static void DBUGOpenFile ( CODE_STATE cs,
const char *  name,
const char *  end,
int  append 
)
static

◆ DbugParse()

static int DbugParse ( CODE_STATE cs,
const char *  control 
)
static

◆ DbugStrTok()

static const char * DbugStrTok ( const char *  s)
static

◆ DbugVfprintf()

static void DbugVfprintf ( FILE *  stream,
const char *  format,
va_list  args 
)
static

◆ DoPrefix()

static void DoPrefix ( CODE_STATE cs,
uint  line 
)
static

◆ DoTrace()

static int DoTrace ( CODE_STATE cs)
static

◆ FixTraceFlags()

static void FixTraceFlags ( uint  old_fflags,
CODE_STATE cs 
)
static

◆ FixTraceFlags_helper()

static void FixTraceFlags_helper ( CODE_STATE cs,
const char *  func,
struct _db_stack_frame_ framep 
)
static

◆ FreeList()

static void FreeList ( struct link linkp)
static

◆ FreeState()

static void FreeState ( CODE_STATE cs,
struct settings state,
int  free_state 
)
static

◆ Indent()

static void Indent ( CODE_STATE cs,
int  indent 
)
static

◆ InList()

static int InList ( struct link linkp,
const char *  cp 
)
static

◆ isseparator()

static int isseparator ( const char *  ptr)
inlinestatic

◆ ListAddDel()

static struct link * ListAddDel ( struct link head,
const char *  ctlp,
const char *  end,
int  todo 
)
static

◆ ListCopy()

static struct link * ListCopy ( struct link orig)
static

◆ ListFlags()

static uint ListFlags ( struct link linkp)
static

◆ PushState()

static void PushState ( CODE_STATE cs)
static

◆ read_lock_stack()

static void read_lock_stack ( CODE_STATE cs)
static

Lock the stack debugging settings.

Only the shared (global) settings are locked if necessary, per thread settings are local and safe to use. This lock is re entrant.

See also
unlock_stack

◆ unlock_stack()

static void unlock_stack ( CODE_STATE cs)
static

Unlock the stack debugging settings.

See also
read_lock_stack

◆ Writable()

static bool Writable ( const char *  pathname)
static

Variable Documentation

◆ db_process

const char* db_process = nullptr
static

◆ init_done

bool init_done = false
static

◆ init_settings

struct settings init_settings
static

Global debugging settings.

This structure shared between all threads, and is the last element in each thread CODE_STATE::stack chain. Protected by THR_LOCK_init_settings.

◆ THR_LOCK_dbug

native_mutex_t THR_LOCK_dbug
static

◆ THR_LOCK_gcov

native_mutex_t THR_LOCK_gcov
static

A mutex protecting flushing of gcov data, see db_flush_gcov().

We don't re-use THR_LOCK_dbug, because that would disallow: DBUG_LOCK_FILE; ..... DBUG_SUICIDE(); .... DBUG_UNLOCK_FILE;

◆ THR_LOCK_init_settings

native_rw_lock_t THR_LOCK_init_settings
static

Lock, to protect init_settings.

For performance reasons, the member init_settings.flags is not protected.