Page 1 of 1

Better stack traces

Posted: 09 Oct 2011 13:24
by marco.r
(Not sure if this is the right section)

I think that stack traces would be much more informative if for class instances, instead of just "INSTANCE" a string representation of the
class (i.e. the output of _tostring) would be printed.

I tried with the following quick hack, and it seems to do the job
(but I have zero experience with the squirrel VM so I'm not sure it is bug free :p)

Code: Select all


--- src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp.orig	2011-10-09 15:01:53.000000000 +0200
+++ src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp	2011-10-09 15:02:10.000000000 +0200
@@ -91,7 +91,10 @@
 					pf(v,_SC("[%s] CLASS\n"),name);
 					break;
 				case OT_INSTANCE:
-					pf(v,_SC("[%s] INSTANCE\n"),name);
+					sq_tostring(v,-1);
+					sq_getstring(v,-1,&s);
+					pf(v,_SC("[%s] %s\n"),name,s);
+					sq_poptop(v);
 					break;
 				case OT_WEAKREF:
 					pf(v,_SC("[%s] WEAKREF\n"),name);
Of course it needs more than this (e.g. what if the _tostring method throws an exception ?), but if there is interest I could make it more complete.

Re: Better stack traces

Posted: 09 Oct 2011 13:31
by Zuu
Looks good to me. No idea if there are any pit holes or cases where this will not work as I'm not familiar with the code that you have modified.