diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-12-12 17:06:16 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-12-12 17:06:16 +0000 |
commit | 7eb00b6d3037a7e30c326b43e23502f777b92eb6 (patch) | |
tree | 60013b086b3682c68192ad2ac8337e221ec9eba9 /src/trace.h | |
parent | ba4167f75c8f7ba8726132eed94af3ae6cd38eee (diff) | |
download | libbu++-7eb00b6d3037a7e30c326b43e23502f777b92eb6.tar.gz libbu++-7eb00b6d3037a7e30c326b43e23502f777b92eb6.tar.bz2 libbu++-7eb00b6d3037a7e30c326b43e23502f777b92eb6.tar.xz libbu++-7eb00b6d3037a7e30c326b43e23502f777b92eb6.zip |
Corrected some issues with the new trace system. It's now working fine. It's backword compatible, and the new features are a lot of fun. Since it uses template functions you can add any new variable types to be formatted.
Diffstat (limited to 'src/trace.h')
-rw-r--r-- | src/trace.h | 96 |
1 files changed, 51 insertions, 45 deletions
diff --git a/src/trace.h b/src/trace.h index 4f85c9b..fb54aaf 100644 --- a/src/trace.h +++ b/src/trace.h | |||
@@ -8,19 +8,21 @@ | |||
8 | #ifndef BU_TRACE_H | 8 | #ifndef BU_TRACE_H |
9 | #define BU_TRACE_H | 9 | #define BU_TRACE_H |
10 | 10 | ||
11 | #ifdef BU_TRACE | 11 | #include <stdio.h> |
12 | #include "bu/fstring.h" | 12 | #include <stdint.h> |
13 | 13 | ||
14 | namespace Nango | 14 | namespace Bu |
15 | { | 15 | { |
16 | template<typename t> void __tracer_format( t &v ); | 16 | /* template<typename t> void __tracer_format( t &v ) |
17 | |||
18 | void __tracer( const char *pf ) | ||
19 | { | 17 | { |
20 | printf("trace: %s\n", pf ); | 18 | __tracer_format( *const_cast<const t *>(&v) ); |
21 | } | 19 | } |
20 | */ | ||
21 | template<typename t> void __tracer_format( const t &v ); | ||
22 | 22 | ||
23 | #define looper( vv ) \ | 23 | void __tracer( const char *pf ); |
24 | |||
25 | #define looper( vv ) \ | ||
24 | for( ; *n; n++ ) \ | 26 | for( ; *n; n++ ) \ |
25 | { \ | 27 | { \ |
26 | if( *n == ',' || *n == ')' ) \ | 28 | if( *n == ',' || *n == ')' ) \ |
@@ -33,6 +35,7 @@ namespace Nango | |||
33 | break; \ | 35 | break; \ |
34 | } \ | 36 | } \ |
35 | } | 37 | } |
38 | |||
36 | template<typename t1> void __tracer( const char *pf, t1 &v1 ) | 39 | template<typename t1> void __tracer( const char *pf, t1 &v1 ) |
37 | { | 40 | { |
38 | printf("trace: "); | 41 | printf("trace: "); |
@@ -42,9 +45,9 @@ namespace Nango | |||
42 | fwrite( s, (int)n-(int)s, 1, stdout ); | 45 | fwrite( s, (int)n-(int)s, 1, stdout ); |
43 | fwrite( "\n", 1, 1, stdout ); | 46 | fwrite( "\n", 1, 1, stdout ); |
44 | } | 47 | } |
45 | 48 | ||
46 | template<typename t1, typename t2> void __tracer( const char *pf, | 49 | template<typename t1, typename t2> void __tracer( const char *pf, |
47 | t1 &v1, t2 &v2 ) | 50 | t1 &v1, t2 &v2 ) |
48 | { | 51 | { |
49 | printf("trace: "); | 52 | printf("trace: "); |
50 | const char *s = pf; | 53 | const char *s = pf; |
@@ -54,9 +57,9 @@ namespace Nango | |||
54 | fwrite( s, (int)n-(int)s, 1, stdout ); | 57 | fwrite( s, (int)n-(int)s, 1, stdout ); |
55 | fwrite( "\n", 1, 1, stdout ); | 58 | fwrite( "\n", 1, 1, stdout ); |
56 | } | 59 | } |
57 | 60 | ||
58 | template<typename t1, typename t2, typename t3> | 61 | template<typename t1, typename t2, typename t3> |
59 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3 ) | 62 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3 ) |
60 | { | 63 | { |
61 | printf("trace: "); | 64 | printf("trace: "); |
62 | const char *s = pf; | 65 | const char *s = pf; |
@@ -67,9 +70,9 @@ namespace Nango | |||
67 | fwrite( s, (int)n-(int)s, 1, stdout ); | 70 | fwrite( s, (int)n-(int)s, 1, stdout ); |
68 | fwrite( "\n", 1, 1, stdout ); | 71 | fwrite( "\n", 1, 1, stdout ); |
69 | } | 72 | } |
70 | 73 | ||
71 | template<typename t1, typename t2, typename t3, typename t4> | 74 | template<typename t1, typename t2, typename t3, typename t4> |
72 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4 ) | 75 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4 ) |
73 | { | 76 | { |
74 | printf("trace: "); | 77 | printf("trace: "); |
75 | const char *s = pf; | 78 | const char *s = pf; |
@@ -81,9 +84,9 @@ namespace Nango | |||
81 | fwrite( s, (int)n-(int)s, 1, stdout ); | 84 | fwrite( s, (int)n-(int)s, 1, stdout ); |
82 | fwrite( "\n", 1, 1, stdout ); | 85 | fwrite( "\n", 1, 1, stdout ); |
83 | } | 86 | } |
84 | 87 | ||
85 | template<typename t1, typename t2, typename t3, typename t4, typename t5> | 88 | template<typename t1, typename t2, typename t3, typename t4, typename t5> |
86 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5 ) | 89 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5 ) |
87 | { | 90 | { |
88 | printf("trace: "); | 91 | printf("trace: "); |
89 | const char *s = pf; | 92 | const char *s = pf; |
@@ -96,11 +99,11 @@ namespace Nango | |||
96 | fwrite( s, (int)n-(int)s, 1, stdout ); | 99 | fwrite( s, (int)n-(int)s, 1, stdout ); |
97 | fwrite( "\n", 1, 1, stdout ); | 100 | fwrite( "\n", 1, 1, stdout ); |
98 | } | 101 | } |
99 | 102 | ||
100 | template<typename t1, typename t2, typename t3, typename t4, typename t5, | 103 | template<typename t1, typename t2, typename t3, typename t4, typename t5, |
101 | typename t6> | 104 | typename t6> |
102 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5, | 105 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5, |
103 | t6 &v6) | 106 | t6 &v6) |
104 | { | 107 | { |
105 | printf("trace: "); | 108 | printf("trace: "); |
106 | const char *s = pf; | 109 | const char *s = pf; |
@@ -114,11 +117,11 @@ namespace Nango | |||
114 | fwrite( s, (int)n-(int)s, 1, stdout ); | 117 | fwrite( s, (int)n-(int)s, 1, stdout ); |
115 | fwrite( "\n", 1, 1, stdout ); | 118 | fwrite( "\n", 1, 1, stdout ); |
116 | } | 119 | } |
117 | 120 | ||
118 | template<typename t1, typename t2, typename t3, typename t4, typename t5, | 121 | template<typename t1, typename t2, typename t3, typename t4, typename t5, |
119 | typename t6, typename t7> | 122 | typename t6, typename t7> |
120 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5, | 123 | void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5, |
121 | t6 &v6, t7 &v7 ) | 124 | t6 &v6, t7 &v7 ) |
122 | { | 125 | { |
123 | printf("trace: "); | 126 | printf("trace: "); |
124 | const char *s = pf; | 127 | const char *s = pf; |
@@ -133,29 +136,32 @@ namespace Nango | |||
133 | fwrite( s, (int)n-(int)s, 1, stdout ); | 136 | fwrite( s, (int)n-(int)s, 1, stdout ); |
134 | fwrite( "\n", 1, 1, stdout ); | 137 | fwrite( "\n", 1, 1, stdout ); |
135 | } | 138 | } |
136 | 139 | #undef looper | |
137 | template<> void __tracer_format<const int>( const int &v ) | 140 | |
138 | { | 141 | template<> void __tracer_format<int8_t>( const int8_t &v ); |
139 | printf("%d", v ); | 142 | template<> void __tracer_format<uint8_t>( const uint8_t &v ); |
140 | } | 143 | template<> void __tracer_format<int16_t>( const int16_t &v ); |
141 | 144 | template<> void __tracer_format<uint16_t>( const uint16_t &v ); | |
142 | template<> void __tracer_format<int>( int &v ) | 145 | template<> void __tracer_format<int32_t>( const int32_t &v ); |
143 | { | 146 | template<> void __tracer_format<uint32_t>( const uint32_t &v ); |
144 | printf("%d", v ); | 147 | template<> void __tracer_format<int64_t>( const int64_t &v ); |
145 | } | 148 | template<> void __tracer_format<uint64_t>( const uint64_t &v ); |
146 | 149 | template<> void __tracer_format<bool>( const bool &v ); | |
147 | template<> void __tracer_format<void *>( void * &v ) | 150 | template<> void __tracer_format<char>( const char &v ); |
148 | { | 151 | template<> void __tracer_format<long>( const long &v ); |
149 | printf("0x%08X", (unsigned int)v ); | 152 | template<> void __tracer_format<unsigned long>( const unsigned long &v ); |
150 | } | 153 | template<> void __tracer_format<float>( const float &v ); |
151 | 154 | template<> void __tracer_format<double>( const double &v ); | |
152 | template<> void __tracer_format<const char *>( const char * &v ) | 155 | template<> void __tracer_format<void *>( void * const &v ); |
153 | { | 156 | template<> void __tracer_format<char *>( char * const &v ); |
154 | printf("\"%s\"", v ); | 157 | template<> void __tracer_format<char **>( char ** const &v ); |
155 | } | 158 | template<> void __tracer_format<void const *>( void const * const &v ); |
159 | template<> void __tracer_format<char const *>( char const * const &v ); | ||
160 | template<> void __tracer_format<char const **>( char const ** const &v ); | ||
156 | } | 161 | } |
157 | 162 | ||
158 | # define TRACE(args...) Nango::__tracer( __PRETTY_FUNCTION__, ##args ) | 163 | #ifdef BU_TRACE |
164 | # define TRACE(args...) Bu::__tracer( __PRETTY_FUNCTION__, ##args ) | ||
159 | #else | 165 | #else |
160 | # define TRACE(args...) {} | 166 | # define TRACE(args...) {} |
161 | #endif | 167 | #endif |