[Mono-list] Re: Seeing Values of Unwound Stack variables at Exception Handler

Jonathan Gilbert 2a5gjx302@sneakemail.com
Fri, 24 Dec 2004 00:53:13 -0500

I'm not sure about "custom stack unwinder notification", but it seems to
me, the pattern you've written there, that is:

bool finished = false;
  finished = true;
  if (!finished)

..is equivalent to this:


Don't know if this helps at all, but it is the behaviour you described with
the try/finally. The 'finally' clause always runs when code flow exits the
scope; this is why the flag is required. The flag ensures that the code
runs only when code flow did not leave the 'try' block "normally" -- that
is, when an exception occurred. This is the situation that the 'catch'
block runs under. Also note, rethrowing the exception will not interfere
with the stack trace; that is generated when the exception is constructed
("new Exception(...)"), and not when it is 'throw'n.

Jonathan Gilbert

At 01:05 PM 20/12/2004 -0500, TB wrote:
>I forgot to mention -- please reply directly to me.
>I'm not subscribed.
>On Mon, Dec 20, 2004 at 01:03:22PM -0500, TB wrote:
>> With the Microsoft CLR one can use WinDBG !clrstack to view the CLR 
>> stack when an UHHANDLED exception is thrown.  But when you have an
>> try..catch exception block active, the stack will be unwound.  The
>> Exception.StackTrace property gives you the *names* of the methods
>> that were unwound, but not the locals or function parameters -- the 
>> stack variables.
>> Does Mono allow you to register a "custom stack unwinder notification"
>> function?  I could do it myself by adding the following code to every
>> single method body:
>> function MayThrowException (int arg1, int arg2, intarg3) {
>>   bool completed = false;
>>   try {
>>     // real method body
>>    completed = true;
>>   } finally {
>>     if (!completed) {
>>       //stash arg1, args2, arg3 on heap for later perusal
>>       //possibly serialize them
>>       //you can use reflection to enumerate all method
>>       //arguments, can you use serialization to enumerate
>>       //the locals?
>>     }
>>   }
>> }
>> The compiler could output this prolog/epilogue code
>> for each method.
>> But if the Runtime called back some code before it
>> unwinds the stack that would be best.  It would help
>> to debug.
>Mono-list maillist  -  Mono-list@lists.ximian.com