aboutsummaryrefslogtreecommitdiff
path: root/src/trace.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-12-12 01:07:10 +0000
committerMike Buland <eichlan@xagasoft.com>2007-12-12 01:07:10 +0000
commit42e91b48b003dae34edd8f41b82ba0d7ffa67d16 (patch)
tree714355824329b2c0cd8bff2e1bdb3f8b0002b1b6 /src/trace.h
parentbc4bf91165b4f32fd5a956f9c5164d3c2af8cd98 (diff)
downloadlibbu++-42e91b48b003dae34edd8f41b82ba0d7ffa67d16.tar.gz
libbu++-42e91b48b003dae34edd8f41b82ba0d7ffa67d16.tar.bz2
libbu++-42e91b48b003dae34edd8f41b82ba0d7ffa67d16.tar.xz
libbu++-42e91b48b003dae34edd8f41b82ba0d7ffa67d16.zip
Added more tracey goodness, this is incomplete, but cool looking.
Also removed some debugging from Process, it needs a helper to clear a buffer, or an option to ignore stderr.
Diffstat (limited to '')
-rw-r--r--src/trace.h150
1 files changed, 148 insertions, 2 deletions
diff --git a/src/trace.h b/src/trace.h
index 345a2de..4f85c9b 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -9,9 +9,155 @@
9#define BU_TRACE_H 9#define BU_TRACE_H
10 10
11#ifdef BU_TRACE 11#ifdef BU_TRACE
12# define TRACE() printf("trace: %s\n", __PRETTY_FUNCTION__ ) 12#include "bu/fstring.h"
13
14namespace Nango
15{
16 template<typename t> void __tracer_format( t &v );
17
18 void __tracer( const char *pf )
19 {
20 printf("trace: %s\n", pf );
21 }
22
23#define looper( vv ) \
24 for( ; *n; n++ ) \
25 { \
26 if( *n == ',' || *n == ')' ) \
27 { \
28 fwrite( s, (int)n-(int)s, 1, stdout ); \
29 fwrite("=", 1, 1, stdout); \
30 __tracer_format( vv ); \
31 s = n; \
32 n++; \
33 break; \
34 } \
35 }
36 template<typename t1> void __tracer( const char *pf, t1 &v1 )
37 {
38 printf("trace: ");
39 const char *s = pf;
40 const char *n = pf;
41 looper( v1 );
42 fwrite( s, (int)n-(int)s, 1, stdout );
43 fwrite( "\n", 1, 1, stdout );
44 }
45
46 template<typename t1, typename t2> void __tracer( const char *pf,
47 t1 &v1, t2 &v2 )
48 {
49 printf("trace: ");
50 const char *s = pf;
51 const char *n = pf;
52 looper( v1 );
53 looper( v2 );
54 fwrite( s, (int)n-(int)s, 1, stdout );
55 fwrite( "\n", 1, 1, stdout );
56 }
57
58 template<typename t1, typename t2, typename t3>
59 void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3 )
60 {
61 printf("trace: ");
62 const char *s = pf;
63 const char *n = pf;
64 looper( v1 );
65 looper( v2 );
66 looper( v3 );
67 fwrite( s, (int)n-(int)s, 1, stdout );
68 fwrite( "\n", 1, 1, stdout );
69 }
70
71 template<typename t1, typename t2, typename t3, typename t4>
72 void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4 )
73 {
74 printf("trace: ");
75 const char *s = pf;
76 const char *n = pf;
77 looper( v1 );
78 looper( v2 );
79 looper( v3 );
80 looper( v4 );
81 fwrite( s, (int)n-(int)s, 1, stdout );
82 fwrite( "\n", 1, 1, stdout );
83 }
84
85 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 )
87 {
88 printf("trace: ");
89 const char *s = pf;
90 const char *n = pf;
91 looper( v1 );
92 looper( v2 );
93 looper( v3 );
94 looper( v4 );
95 looper( v5 );
96 fwrite( s, (int)n-(int)s, 1, stdout );
97 fwrite( "\n", 1, 1, stdout );
98 }
99
100 template<typename t1, typename t2, typename t3, typename t4, typename t5,
101 typename t6>
102 void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5,
103 t6 &v6)
104 {
105 printf("trace: ");
106 const char *s = pf;
107 const char *n = pf;
108 looper( v1 );
109 looper( v2 );
110 looper( v3 );
111 looper( v4 );
112 looper( v5 );
113 looper( v6 );
114 fwrite( s, (int)n-(int)s, 1, stdout );
115 fwrite( "\n", 1, 1, stdout );
116 }
117
118 template<typename t1, typename t2, typename t3, typename t4, typename t5,
119 typename t6, typename t7>
120 void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5,
121 t6 &v6, t7 &v7 )
122 {
123 printf("trace: ");
124 const char *s = pf;
125 const char *n = pf;
126 looper( v1 );
127 looper( v2 );
128 looper( v3 );
129 looper( v4 );
130 looper( v5 );
131 looper( v6 );
132 looper( v7 );
133 fwrite( s, (int)n-(int)s, 1, stdout );
134 fwrite( "\n", 1, 1, stdout );
135 }
136
137 template<> void __tracer_format<const int>( const int &v )
138 {
139 printf("%d", v );
140 }
141
142 template<> void __tracer_format<int>( int &v )
143 {
144 printf("%d", v );
145 }
146
147 template<> void __tracer_format<void *>( void * &v )
148 {
149 printf("0x%08X", (unsigned int)v );
150 }
151
152 template<> void __tracer_format<const char *>( const char * &v )
153 {
154 printf("\"%s\"", v );
155 }
156}
157
158# define TRACE(args...) Nango::__tracer( __PRETTY_FUNCTION__, ##args )
13#else 159#else
14# define TRACE() {} 160# define TRACE(args...) {}
15#endif 161#endif
16 162
17#endif 163#endif