32 #if defined(DEVEL_RALF)
35 #define BUGEX_MAX_STRING_PRINT 40
37 #define RALF_DUMP_EXPR(type,var) ALL_DUMP_EXPR(type,var)
38 #define RALF_DUMP_VAL(var) ALL_DUMP_VAL(var)
39 #define RALF_DUMP_STR(var) ALL_DUMP_STR(var)
40 #define RALF_DUMP_PTR(var) ALL_DUMP_PTR(var)
41 #define RALF_DUMP_MARK() ALL_DUMP_MARK()
45 #define RALF_DUMP_VAL(var)
46 #define RALF_DUMP_STR(var)
47 #define RALF_DUMP_MARK()
54 #if defined(BUGEX_DUMPS)
56 #ifndef _GLIBCXX_CCTYPE
62 #define ALL_DUMP_EXPR(type,expr) \
64 type tmp_var = (expr); \
65 bugex_dump_value(&tmp_var, "[" #expr "]", sizeof(tmp_var), __FILE__, __LINE__); \
68 #define ALL_DUMP_VAL(var) bugex_dump_value(&var, #var, sizeof(var), __FILE__, __LINE__)
69 #define ALL_DUMP_STR(var) bugex_dump_string(&var, #var, __FILE__, __LINE__)
70 #define ALL_DUMP_PTR(var) bugex_dump_pointer(&var, #var, __FILE__, __LINE__)
71 #define ALL_DUMP_MARK() bugex_dump_mark(__FILE__, __LINE__)
73 static void bugex_dump_mark(
const char *file,
size_t lineno) {
74 fprintf(stderr,
"%s:%zu: ------------------------------ MARK\n", file, lineno);
78 static void bugex_printString(
const char *
str,
size_t len) {
80 unsigned char c = (
unsigned char)*str++;
86 case '\n':
fputs(
"\\n", stderr);
break;
87 case '\t':
fputs(
"\\t", stderr);
break;
88 default: fprintf(stderr,
"\\%i", (
int)c);
break;
94 static void bugex_dump_pointer(
void *somePtr,
const char *someName,
const char *file,
size_t lineno) {
95 fprintf(stderr,
"%s:%zu: %s: %p -> %p\n", file, lineno, someName, somePtr, *(
void**)somePtr);
99 static void bugex_dump_string(
void *strPtr,
const char *strName,
const char *file,
size_t lineno) {
100 const char *
s = *((
const char **)strPtr);
102 fprintf(stderr,
"%s:%zu: ", file, lineno);
105 fprintf(stderr,
"%s is NULp (&=%p)\n", strName, strPtr);
108 size_t len = strlen(s);
110 fprintf(stderr,
"%s = \"", strName);
111 if (len <= BUGEX_MAX_STRING_PRINT) {
112 bugex_printString(s, len);
115 bugex_printString(s, BUGEX_MAX_STRING_PRINT/2);
116 fprintf(stderr,
"\" .. \"");
117 bugex_printString(s+len-BUGEX_MAX_STRING_PRINT/2, BUGEX_MAX_STRING_PRINT/2);
119 fprintf(stderr,
"\" (len=%zu, &=%p -> %p)\n", len, strPtr, s);
125 #define BUGEX_VALSIZES 4
126 static unsigned short bugex_valsize[] = {
sizeof(
char),
sizeof(
short),
sizeof(
int),
sizeof(
long), 0 };
127 enum bugex_valtype { BUGEX_CHAR, BUGEX_SHORT, BUGEX_INT, BUGEX_LONG, BUGEX_UNKNOWN };
129 static void bugex_dump_value(
void *valuePtr,
const char *valueName,
size_t size,
const char *file,
size_t lineno) {
131 enum bugex_valtype
type = BUGEX_UNKNOWN;
133 if (size == bugex_valsize[BUGEX_INT]) {
137 for (vs = 0; vs < BUGEX_VALSIZES; ++vs) {
138 if (size == bugex_valsize[vs]) {
139 type = (
enum bugex_valtype)vs;
144 fprintf(stderr,
"%s:%zu: ", file, lineno);
148 unsigned char c = *(
unsigned char*)valuePtr;
149 int i = (
int)(
signed char)c;
151 fprintf(stderr,
"(char) %s = '%c' = %i", valueName, c, i);
152 if (i<0) fprintf(stderr,
" = %u", (
unsigned int)c);
153 fprintf(stderr,
" (&=%p)", valuePtr);
157 unsigned short s = *(
unsigned short *)valuePtr;
158 signed short ss = (
signed short)s;
160 fprintf(stderr,
"(short) %s = %hi", valueName, (
int)ss);
161 if (ss<0) fprintf(stderr,
" = %hu", s);
162 fprintf(stderr,
" = 0x%hx (&=%p)", s, valuePtr);
166 unsigned int u = *(
unsigned int *)valuePtr;
169 fprintf(stderr,
"(int) %s = %i", valueName, i);
170 if (i<0) fprintf(stderr,
" = %u", u);
171 fprintf(stderr,
" = 0x%x (&=%p)", u, valuePtr);
175 unsigned long l = *(
unsigned long *)valuePtr;
176 fprintf(stderr,
"(long) %s = %li = %lu = 0x%lx (&=%p)", valueName, (
signed long)l, (
unsigned long)l, (
unsigned long)l, valuePtr);
180 fprintf(stderr,
"value '%s' has unknown size (use cast operator!)", valueName);
184 fprintf(stderr,
"\n");
188 #endif // BUGEX_DUMPS
fputs(TRACE_PREFIX, stderr)
GB_write_int const char s