Stack Trace with actual parameter values

arm

Newcomer
Joined
Dec 3, 2003
Messages
2
I would like to have the possibility to trace with the normal stack dump
the actual values of the parameters? Does anybody know how to get them
from stack ?

In detail:

with stackTrace.GetFrame(frameCount);

and stackFrame.GetMethod();

I can get the called methods on stack and with reflection
the type and count of the parameters but i can see no
way to get the actual value of each parameter which would
help a lot in a log-file in case of an exception!
 
You can see the parameter values in VS. In the Call Stack, double click on the line you want and then you can examine the values from the context of that call.

For example, look at this C# program:
C#:
static void Test2(int i)
{
	Debug.WriteLine(i);
}

static void Test(int i)
{
	i++;
	Test2(i);
}
[STAThread]
static void Main() 
{
	int i = 5;
	Test(i);
}

Set a breakpoint on the line "Debug.WriteLine...". If you look at i, it shows 6. In the callstack, find the line and double click it:
Test.exe!Class1.Main() Line 34

Now if you examine i, you'll see it's still 5. It's showing you that it passed 5 to the function Test.

The key is the double click in the Call Stack, which sets context to that line of code.

-ner
 
My problem is not to see the values in the debugger but to write them
in a log-file while program is running!
 
I know when you catch an exception there are a lot of options as far as the data you can extract from an exception. The stack trace is one of them but there might be more. You can pragmatically log that information from your catch block.

MSDN on Exception. Hopefully that helps.
 
VS can do it, but it does it through the runtime environment, which your code can't directly manipulate. The Exception class has a private variable named _stackTrace which contains raw binary data, but I couldn't decipher it or find any info about it. From the look of things, this probably isn't a very simple task, to say the least.
 
It's been a while since I've had to do this, but I used to use core dumps (which held a stack trace in them) in conjuction with a debugger to get that sort of informaiton. Granted this was with gcc and it seems that the JIT Debugger stops core dumps from ever happening, but perhaps you can force it and use the VS debugger to decipher the binary?

This isn't a fancy solution but what about just logging the values yourself?
Code:
Function Super(String arg1)
{
   Try
   {
      DoStuff()
   }
   Catch (exception)
   {
      Log(exception.StackTrace)
      Log(exception.Message)
      Log(arg1)
   }
}
Of course, that won't work if you don't have access to the code.
 
Back
Top