[Gridflow-cvs] [svn] commit: r5665 - in /trunk/src: classes3.cxx gridflow.cxx gridflow.hxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Wed May 12 18:41:26 EDT 2010


Author: matju
Date: Wed May 12 18:41:25 2010
New Revision: 5665

Log:
short_backtrace() now takes arguments for start and end frames, and can demangle the symbols of the frames that have a known symbol.

Modified:
    trunk/src/classes3.cxx
    trunk/src/gridflow.cxx
    trunk/src/gridflow.hxx

Modified: trunk/src/classes3.cxx
==============================================================================
--- trunk/src/classes3.cxx (original)
+++ trunk/src/classes3.cxx Wed May 12 18:41:25 2010
@@ -1223,6 +1223,7 @@
 		#undef FOO
 	}
 	\decl 0 list (...) {
+		//post("YOUHOU, de %s", short_backtrace(0,4));
 		if (argc>n) argc=n;
 		for (int i=0; i<argc; i++) _n_set(i,argv[i]);
 		_0_bang();

Modified: trunk/src/gridflow.cxx
==============================================================================
--- trunk/src/gridflow.cxx (original)
+++ trunk/src/gridflow.cxx Wed May 12 18:41:25 2010
@@ -55,12 +55,16 @@
 //#include "bundled/g_canvas.h"
 //#endif
 
-/* for exception-handling in 0.9.x... Linux-only */
+/* for exception-handling in 0.9.x and 9.x... Linux-only */
 #if !defined(MACOSX) && !defined(__WIN32__)
 #include <exception>
 #include <execinfo.h>
 #endif
 #undef check
+
+//#ifdef __GNUC__
+#include <cxxabi.h>
+//#endif
 
 std::map<string,FClass *> fclasses;
 std::map<t_class *,FClass *> fclasses_pd;
@@ -923,16 +927,24 @@
 
 /* for debugging... linux-only */
 #if !defined(MACOSX) && !defined(__WIN32__)
-char *short_backtrace () {
+char *short_backtrace (int start/*=3*/, int end/*=4*/) {
 	static char buf[1024]; buf[0]=0;
-	void *array[6];
-	int nSize = backtrace(array,4);
+	void *array[end];
+	int nSize = backtrace(array,end);
 	char **symbols = backtrace_symbols(array, nSize);
-	for (int i=3,j=0; i<nSize; i++) {
+	for (int i=start,j=0; i<nSize; i++) {
 		char *a = strchr(symbols[i],'(');
 		char *b = strchr(symbols[i],'+');
-		if (a&&b) j+=sprintf(buf+j,"%s%.*s",i>3?", \n  ":"[",b-a-1,a+1);
-		else      j+=sprintf(buf+j,"%s%s"  ,i>3?", \n  ":"[",symbols[i]);
+		if (a&&b) {
+			char mangled[1024]; sprintf(mangled,"%.*s",b-a-1,a+1);
+			char *demangled = (char *)malloc(1024);
+			size_t length;
+			int status;
+			char *result = __cxxabiv1::__cxa_demangle(mangled,demangled,&length,&status);
+			j+=sprintf(buf+j,"%s%.*s",i>start?", \n  ":"[",length,demangled);
+			free(demangled);
+		}
+		else    j+=sprintf(buf+j,"%s%s",  i>start?", \n  ":"[",symbols[i]);
 	}
 	sprintf(buf+strlen(buf),"]");
 	return buf;

Modified: trunk/src/gridflow.hxx
==============================================================================
--- trunk/src/gridflow.hxx (original)
+++ trunk/src/gridflow.hxx Wed May 12 18:41:25 2010
@@ -286,7 +286,7 @@
 //a reference counting pointer class
 //note: T <= CObject
 //used mostly as P<Grid>, P<BitPacking>
-extern char *short_backtrace ();
+extern char *short_backtrace (int start=3, int end=4);
 template <class T> class P {
 public:
 



More information about the Gridflow-cvs mailing list