Ticket #298: debugPatch

File debugPatch, 5.2 KB (added by Wouldd, 13 years ago)

Patch for debug.c/h

Line 
1Index: navit/debug.c
2===================================================================
3--- navit/debug.c       (revision 2032)
4+++ navit/debug.c       (working copy)
5@@ -38,6 +38,8 @@
6 int segv_level=0;
7 int timestamp_prefix=0;
8 
9+int indent=0;  //intent level is incremented and decremented when using instrumented version for entry/exit else always 0
10+
11 static int dummy;
12 static GHashTable *debug_hash;
13 static const char *gdb_program;
14@@ -120,7 +122,7 @@
15        return (int)(g_hash_table_lookup(debug_hash, name));
16 }
17 
18-static void debug_timestamp(FILE *fp)
19+static void debug_timestamp(FILE *fp)
20 {
21        struct timeval tv;
22 
23@@ -142,18 +144,26 @@
24        char buffer[4096];
25 #else
26        char buffer[mlen+flen+3];
27+       
28 #endif
29        FILE *fp=debug_fp;
30-
31+       int i=0;
32        sprintf(buffer, "%s:%s", module, function);
33        if (debug_level_get(module) >= level || debug_level_get(buffer) >= level) {
34 #ifndef DEBUG_WIN32_CE_MESSAGEBOX
35                if (! fp)
36                        fp = stderr;
37+               if (indent > 0){  /*if indent is not 0 then */
38+                       for (i=0; i<indent; i++){   
39+                               fprintf(fp,"-");   /*prefix output with 1 '-' per indent level*/
40+                       }
41+               }
42                if (timestamp_prefix)
43                        debug_timestamp(fp);
44+               
45                if (prefix)
46                        fprintf(fp,"%s:",buffer);
47+                                       
48                vfprintf(fp,fmt, ap);
49                fflush(fp);
50 #else
51@@ -210,3 +220,59 @@
52                fflush(debug_fp);
53        }
54 }
55+
56+
57+/* Output trace file pointer */
58+static FILE *fp;  /*used in the constructor methods*/
59+int debugptr = &debug_timestamp;  /*used to identify pointer to static method debug_timestamp so we can exclude it from entry/exit logging*/
60+
61+void main_constructor( void )
62+{
63
64+  fp =stderr;  /*At the moment we put all instrumented output to stderr */
65+       indent=0; /*set indent to 0*/
66+  if (fp == NULL) exit(-1); /*If we had any trouble getting a pointer to stderr then FAIL*/
67+}
68+/*Close file handle after main is finished*/
69+void main_destructor( void )
70+{
71+  fclose( fp );
72+}
73+/*instrumentation function that gets called on entry into any function if you compile with -finstrument-functions*/
74+void __cyg_profile_func_enter( void *this, void *callsite )
75+{
76+  /* Function Entry Address */
77+  int i=0;  /*define iterator int for use in for loop*/
78+ if ((int *) this == (int *) debugptr){  /*check if this function is debug_timestamp since that's a sub function within the debug statement
79+                                                               the output gets werid if you trace it's entry/exit*/
80+       /*don't do entry/exit for timestamp function*/
81+ }else{         
82+        indent++;      /*we've entered a function so increment the indent*/
83+       if (indent > 0){ /*if indent is more than 0*/
84+               for (i=0; i<indent; i++){
85+                       fprintf(fp,"-");        /*prefix out output with one - for each indent level*/
86+               }
87+       }       
88+  fprintf(fp, "Entering E%p\n", (int *)this);  /*output a log statement showing Entering EfunctionPointer*/
89+ }     
90+}
91+
92+/*instrumentation function that gets called on exit from any function if you compile with -finstrument-functions*/
93+void __cyg_profile_func_exit( void *this, void *callsite )
94+{
95+  /* Function Exit Address */
96+  /*dbg_decrement_indent();*/
97+        int i=0;  /*define iterator int for use in for loop*/
98+       if ((int *) this == (int *) debugptr){/*check if this function is debug_timestamp since that's a sub function within the debug statement
99+                                                               the output gets werid if you trace it's entry/exit*/
100+       /*don't do entry/exit for timestamp function*/
101+ }else{       
102+ indent--;     /*we've entered a function so increment the indent*/
103+       if (indent > 0){  /*if indent is more than 0*/
104+               for (i=0; i<indent; i++){
105+                       fprintf(fp,"-");  /*prefix out output with one - for each indent level*/
106+               }
107+       }       
108+  fprintf(fp, "Exiting X%p\n", (int *)this);  /*output a log statement showing Exiting XfunctionPointer*/
109+}
110+}
111\ No newline at end of file
112Index: navit/debug.h
113===================================================================
114--- navit/debug.h       (revision 2032)
115+++ navit/debug.h       (working copy)
116@@ -41,9 +41,21 @@
117 void debug_level_set(const char *name, int level);
118 int debug_level_get(const char *name);
119 struct debug *debug_new(struct attr *parent, struct attr **attrs);
120-void debug_vprintf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap);
121-void debug_printf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, ...);
122+void debug_vprintf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap)
123+ __attribute__ ((no_instrument_function));
124+void debug_printf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, ...)
125+ __attribute__ ((no_instrument_function));
126 void debug_assert_fail(char *module, const int mlen,const char *function, const int flen, char *file, int line, char *expr);
127+void __cyg_profile_func_enter( void *func_address, void *call_site )
128+                                __attribute__ ((no_instrument_function));
129+
130+void __cyg_profile_func_exit ( void *func_address, void *call_site )
131+                                __attribute__ ((no_instrument_function));
132+void main_constructor( void )
133+       __attribute__ ((no_instrument_function, constructor));
134+
135+void main_destructor( void )
136+       __attribute__ ((no_instrument_function, destructor));
137 /* end of prototypes */
138 
139 #ifdef __cplusplus
140