Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dsDebug.h

Go to the documentation of this file.
00001 /* 
00002  * $Id: dsDebug.h,v 1.6 2004/09/28 10:43:18 dsamersoff Exp $
00003  */
00004 
00009 #ifndef dsDebug_h
00010 #define dsDebug_h
00011 
00012 #include <assert.h>
00013 
00014 #include <iostream>
00015 #include <iomanip>
00016 
00017 #ifdef HAVE_CONFIG_H
00018 # include <config.h>
00019 #endif
00020 
00021 #ifndef DS_DEBUG_OUT
00022 #  define DS_DEBUG_OUT cerr 
00023 #endif
00024 
00025 #ifdef DS_TRACE_DESTRUCTOR
00026 #  define destructor  DS_DEBUG_OUT << "*DEBUG: " << __FILE__ << ':' << __LINE__ << " *DESTRUCTOR\n";
00027 #else
00028 #  define destructor 
00029 #endif
00030 
00031 #ifdef DS_DEBUG
00032 #  define dmsg(s)     DS_DEBUG_OUT << "*DEBUG: " << __FILE__ << ':' << __LINE__ << " " << (s) << "\n";
00033 #  define dout(s)     DS_DEBUG_OUT << "*DEBUG: " << __FILE__ << ':' << __LINE__ << " " << #s << ": '" << (s) << "'\n";
00034 #  define doutx(s)    DS_DEBUG_OUT << "*DEBUG: " << __FILE__ << ':' << __LINE__ << " " << #s << ": '" << hex << (s) << "'\n";
00035 #  define ds_gdb_wait { int _ds_gdb_wait = 1; while(_ds_gdb_wait); }
00036 #else /* Placeholders */
00037 #  define dmsg(s)     
00038 #  define dout(s)     
00039 #  define doutx(s)    
00040 #  define ds_gdb_wait 
00041 #endif /* DS_DEBUG */
00042 
00043 
00056 #define MAX_DEPTH 40
00057 
00058 #if ARCH == i386
00059 
00060 inline void __dsBacktrace (std::ostream& os)
00061 {
00062   /* We assume that all the code is generated with frame pointers set.  */
00063 
00064    unsigned long *sp, *bp, *ra;
00065 
00066     int max = MAX_DEPTH;
00067 
00068     __asm__ volatile ("mov %%ebp,%0" : "=g"(bp));
00069     __asm__ volatile ("mov %%esp,%0" : "=g"(sp));
00070 
00071   while (max--)
00072   {
00073 
00074     ra = (unsigned long *) bp[1];
00075     bp = (unsigned long *) bp[0];
00076     
00077     if (!sp || bp < sp)     
00078         break;
00079 
00080     os << std::dec << MAX_DEPTH-max << "# " << std::hex << (unsigned long) (ra-1) << std::endl;
00081    }
00082 }
00083 
00084 #endif
00085 
00086 #if ARCH == sparc
00087 
00088 inline void __dsBacktrace (std::ostream& os)
00089 {
00090     unsigned long   *sp, *ra;
00091     int max = MAX_DEPTH;
00092 
00093 
00094     __asm__ volatile ("ta 3");
00095     __asm__ volatile ("mov %%sp,%0" : "=r"(sp));
00096 
00097     while (max--)
00098     {
00099         ra = (unsigned long *) sp[15];
00100         sp = (unsigned long *) sp[14];
00101 
00102         /* stop when we get the call to main */
00103         if (!ra)
00104                 break;
00105 
00106         os << std::dec << MAX_DEPTH-max << "# " << std::hex << (unsigned long) (ra) << std::endl;
00107     }
00108 }
00109 
00110 
00111 #endif
00112 
00113 #endif

Generated on Mon May 16 18:26:57 2005 for libdms4 by doxygen1.3-rc2