[gq-commit] gq/src debug.c,1.7,1.8 debug.h,1.5,1.6
Status: Beta
                
                Brought to you by:
                
                    sur5r
                    
                
            | 
     
      
      
      From: <sta...@us...> - 2003-10-13 07:30:25
      
     
   | 
Update of /cvsroot/gqclient/gq/src
In directory sc8-pr-cvs1:/tmp/cvs-serv16039
Modified Files:
	debug.c debug.h 
Log Message:
* Added the print_trace fuction to help with debugging non-crashing situations
  where the control flow is hard to figure out using a debugger.
Index: debug.c
===================================================================
RCS file: /cvsroot/gqclient/gq/src/debug.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** debug.c	5 Oct 2003 13:35:20 -0000	1.7
--- debug.c	13 Oct 2003 07:30:19 -0000	1.8
***************
*** 25,34 ****
  
  #include <stdio.h>
  #include "debug.h"
  #include "configfile.h"
  #include "common.h"
  
! int num_mallocs = 0;
! int max_mallocs = 0;
  
  #ifdef DEBUG
--- 25,42 ----
  
  #include <stdio.h>
+ 
+ #ifdef HAVE_BACKTRACE
+ #   include <execinfo.h>
+ #   include <stdlib.h>
+ #endif /* HAVE_BACKTRACE */
+ 
  #include "debug.h"
  #include "configfile.h"
  #include "common.h"
  
! 
! 
! static int num_mallocs = 0;
! static int max_mallocs = 0;
  
  #ifdef DEBUG
***************
*** 158,162 ****
--- 166,206 ----
  }
  #endif /* HAVE_MALLINFO */
+ 
+ 
+ /* taken from the documentation of the GNU libc */
+ void print_trace(void)
+ {
+ #ifdef HAVE_BACKTRACE
+      void *array[200];
+      size_t size;
+      char **strings;
+      size_t i;
+      
+      size    = backtrace(array, (sizeof(array) / sizeof(array[0])) );
+      strings = backtrace_symbols(array, size);
+      
+      if (strings) {
+ 	  fprintf(stderr, "----------------------------------------\n");
+ 	  
+ 	  for (i = 0; i < size; i++) {
+ 	       fprintf(stderr, "%s\n", strings[i]);
+ 	  }
+ 	  free(strings);
+      }
+ #endif /* BACKTRACE */
+ }
+ 
+ #else
+ 
+ void print_trace(void) 
+ {
+ }
+ 
  #endif /* DEBUG */
+ 
+ 
+ 
+ 
+ 
  
  /* 
Index: debug.h
===================================================================
RCS file: /cvsroot/gqclient/gq/src/debug.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** debug.h	5 Sep 2002 19:27:42 -0000	1.5
--- debug.h	13 Oct 2003 07:30:19 -0000	1.6
***************
*** 70,73 ****
--- 70,74 ----
  void dump_ldapservers(void);
  
+ void print_trace(void);
  
  #endif
 |