Debug/Inspect without breakpoint

  • Thread starter Thread starter Wal Turner
  • Start date Start date
W

Wal Turner

Consider the following simple class:

public class ClassA
{
public static string VAR = "hello";
}

public void MethodA()
{
while(true)
{
Thread.sleep(1000);
Console.WriteLine("oi");
}
}


Assume that MethodA has been called already. If we debug this process and
put a breakpoint at Console.WriteLine( ), we can easily determine the value
of VAR. However, I can only seem to do this when the breakpoint gets hit.
I'm thinking there must be a way to determine what the current value of VAR
is *without* the breakpoint. If I use the Command Window - Immediate, and
do

ClassA.VAR

I get 'The expression cannot be evaluated while in run mode.'

Obviously I can make my program hit a breakpoint by doing something but it
would be cleaner if I could just inspect any static class variable without
having to place a breakpoint.

Wal
 
Wal,

Surely the obvious problem with this is that if your program is not as a
break point, or paused as a result of stepping from a break point, then the
application is running...

From the IDE's point of view, if the application is currently running,
what's to stop VAR from changing while you're trying to evaluate it?
 
Well, the only situation that I can kind of relate to, is when using
something like Direct3D where you want to track something like the
framerate. I usually set up some sort of onscreen trace message that
will interactively change as the application runs so I can inspect its
value at run-time.

A few conditional compile statements and it makes management of this
super easy

#if DEBUG
Trace.Write(this.FPS)
#endif

Hope that helps,
Joel Martinez
http://www.onetug.org - Orlando .NET User Group
http://www.codecube.net - Blog
 
Correct, the application is running....but suppose the application in
question shows some unexpected behaviour, (not an error per se) and you want
to expect some variables, lets say a static class array, which you knew
wouldnt be changing (even if it was doesnt matter)...the only way you'd be
able to 'get in' to inspect it is to have a breakpoint hit! The
information of the array is obviously stored in memory somewhere but i see
it as a limitation that you can't inspect it without having a breakpoint.

I suppose its not *that* difficult to get around...you just have a thread
that constantly loops and does nothing that you can put a breakpoint on and
get a 'hold' of the application. Not that pretty

Wal

----- Original Message -----
From: "Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Wednesday, November 17, 2004 8:06 PM
Subject: Re: Debug/Inspect without breakpoint
 
Wal,

The way you'd monitor this sort of thing is logging (or tracing) the
variables you want to monitor to disk (or to another window). By providing a
brief description around the variable log, you'll be able to see a run
history of your application after it's finished. This will allow you to look
at any variable you wish, at any point in the application without stopping
it.

If you place timestamps into your log you can record when the problems occur
and line them up with the log times to find out if the variables change
etc...

It's also useful for monitoring which code paths were executed and which
were not reached.

Dan.


Wal Turner said:
Correct, the application is running....but suppose the application in
question shows some unexpected behaviour, (not an error per se) and you
want
to expect some variables, lets say a static class array, which you knew
wouldnt be changing (even if it was doesnt matter)...the only way you'd be
able to 'get in' to inspect it is to have a breakpoint hit! The
information of the array is obviously stored in memory somewhere but i see
it as a limitation that you can't inspect it without having a breakpoint.

I suppose its not *that* difficult to get around...you just have a thread
that constantly loops and does nothing that you can put a breakpoint on
and
get a 'hold' of the application. Not that pretty

Wal

----- Original Message -----
From: "Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Wednesday, November 17, 2004 8:06 PM
Subject: Re: Debug/Inspect without breakpoint

Wal,

Surely the obvious problem with this is that if your program is not as a
break point, or paused as a result of stepping from a break point, then
the application is running...

From the IDE's point of view, if the application is currently running,
what's to stop VAR from changing while you're trying to evaluate it?
 
Back
Top