1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
// ------------------------------------------------------------
//
// mdbug.h
//
// Include file for the mdbug class.
//
#pragma ident "%Z%%M% %I% %E% SMI"
// Copyright (c) 1994 by Sun Microsystems, Inc.
// .LIBRARY base
// .NAME mdbug - macros for debugging C++ programs.
// .FILE dbug.cc
// .FILE mdbug.h
// .SECTION Description
// The mdbug package provides a set of macros for debugging C++ programs.
// Features include tracing function entry and exit points, printing
// of debug messages, and heap corruption detection. All features can
// be selectively enabled at run time using command line options. Also
// defining the macro DBUG_OFF removes all mdbug code from the compilation.
#ifndef MDBUG_H
#define MDBUG_H
#define DBUG_STMT(A) do { A } while (0)
#ifndef DBUG_OFF
class dbug_routine {
private:
static int sd_on; // Debug on/off flag.
static long sd_lineno; // Output line number.
static const char *sd_process; // Current process.
static class dbug_state *sd_push; // Push information.
static void dbug_thread_exit(void *data);
const char *d_func; // Name of current function.
const char *d_file; // Name of current file.
dbug_routine *d_prev; // Callers dbug_routine object.
int d_leaveline; // Exit line from routine.
public:
dbug_routine(int line, const char *file, const char *function);
~dbug_routine();
void db_leave(int line);
int db_keyword(const char *keyword);
void db_pargs(int line, const char *keyword);
void db_printf(const char *, ...);
void db_traceprint(int line, const char *keyword);
void db_assert(int line, const char *msgp);
void db_precond(int line, const char *msgp);
static const char *db_push(const char *);
static void db_pop();
void db_process(const char *);
static int db_debugon();
};
#define dbug_enter(A) dbug_routine _did(__LINE__, __FILE__, A)
#define dbug_leave() _did.db_leave(__LINE__)
#define dbug_traceprint(KEY) _did.db_traceprint(__LINE__, KEY)
#define dbug_push(A) dbug_routine::db_push(A)
#define dbug_pop() dbug_routine::db_pop()
#define dbug_process(A) _did.db_process(A)
#define dbug_assert(A) \
DBUG_STMT(if (!(A)) { _did.db_assert(__LINE__, #A); })
#define dbug_precond(A) \
DBUG_STMT(if (!(A)) { _did.db_precond(__LINE__, #A); })
#define dbug_execute(KEY, CODE) \
DBUG_STMT(if (dbug_routine::db_debugon()) \
{ if (_did.db_keyword(KEY)) { CODE } })
#define dbug_print(KEY, ARGS) \
DBUG_STMT(if (dbug_routine::db_debugon()) \
{ _did.db_pargs(__LINE__, KEY); _did.db_printf ARGS; })
// ------------------------------------------------------------
//
// db_debugon
//
// Description:
// Returns 1 if debugging is currently enabled, 0 otherwise.
// Arguments:
// Returns:
// Errors:
// Preconditions:
inline int
dbug_routine::db_debugon()
{
return (sd_on);
}
#else /* if DBUG_OFF */
#define dbug_enter(A) 0
#define dbug_leave() 0
#define dbug_traceprint(KEY) 0
#define dbug_push(A) 0
#define dbug_pop() 0
#define dbug_process(A) 0
#define dbug_execute(KEY, CODE) 0
#define dbug_print(KEY, ARGS) 0
#define dbug_assert(A) 0
#define dbug_precond(A) 0
#endif /* DBUG_OFF */
#endif /* MDBUG_H */
|