Message from discussion
How to get current running values from .LocalVariables in .NET 2.0?
Reply-To: "Ben Voigt" <r...@nospam.nospam>
From: "Ben Voigt" <r...@nospam.nospam>
References: <OAxYBgLiGHA.1276@TK2MSFTNGP03.phx.gbl>
Subject: Re: How to get current running values from .LocalVariables in .NET 2.0?
Date: Tue, 6 Jun 2006 07:53:21 -0500
Lines: 40
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
Message-ID: <eyBWygWiGHA.3320@TK2MSFTNGP03.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.clr
NNTP-Posting-Host: airband-216-138-104-162.airband.net 216.138.104.162
Path: g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!nntp.infostrada.it!feeder.news.tin.it!207.46.248.126.MISMATCH!TK2MSFTFEEDS01.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP03.phx.gbl
"Lou Zher" <ab...@127.0.0.1> wrote in message
news:OAxYBgLiGHA.1276@TK2MSFTNGP03.phx.gbl...
> We've got a project that needs to be able to see the current running
> values from the objects returned back by .LocalVariables. How is this
> done? LocalVariables only appears to give us the types of the method vars.
> -LZ
>
What are you trying to do? The values of local variables in any method are
only well-defined at very specific times.
If you are trying to add additional information to an exception stack trace,
please realize that by the time control reaches a handler, the call stack is
already unwound, and stack space may have been overwritten by, for example,
finally blocks that have already executed.
Only methods still on the call stack have valid locals.
If you are in the Exception constructor trying to capture the information,
then it is theoretically possible to capture the details, however consider
that the MSIL is converted to machine code, so any solution is going to be
architecture and runtime specific. For example, mono might store local
variables in a different order than ms.net. There's a WinAPI routine
StackWalk that might be of some use... but not much. You basically require
the debugging API distributed with the JIT compiler, since only it can
determine where the variables are stored.
Also remember that in the case of recursion, there may be multiple stack
frames corresponding to a single MethodBody and LocalVariableInfo.
If you're wanting an automated way to enumerate local variables in the
current method, please consider that your code will never be reuseable
because the process of encapsulating it changes the scope of variable
capture.
The runtime provides minidump functionality, I suggest you use that in lieu
of any attempt to capture state information on your own.