views:

545

answers:

6

Hello,

In Adobe Director, there is a watch window that updates while my application runs. For example, if I have a game application and am watching an instance of a ball object, I can see all of its values (velocity, altitude, state variables, etc) updating in real-time as the application is running. I can also add any other object to the window and drill down into it's variables without stopping execution.

Is there a way in Visual Studio (I'm on 2008), in C#, to have the Debug > Watch window update while my application is running? In other words, I'd like to keep an eye on the different variables of a given object while the application is running, rather than freezing everything and inspect the state of things at one particular moment in time.

If this is not possible is there any way to watch the values of arbitrary objects (without hardcoding these upfront). For example, for a tank object, we'd have position, orientation, velocity, etc. Assume dozens of different types of game objects with a dozen or so values each. These values change 60 times per second.

The goal is to be able to, at runtime, choose a game object to "watch" and then drill down into it's heirarchy of variables (in the same way the watcher pane does). Again, this tool doesn't know about the objects in advance, so can't be hardcoded for specific objects.

Thanks in advance!

Adam

A: 

This might help:

http://msdn.microsoft.com/en-us/library/z4ecfxd9.aspx

To turn automatic property evaluation on or off

  1. On the Tools menu, click Options.
  2. In the Options dialog box, open the Debugging node, and click General. Depending on your IDE settings, you may need to select Show all settings to see the Debugging node.
  3. Select or clear Enable property evaluation and other implicit function calls.
  4. Click OK.
Richard West
Hmm. I've got "Enable property evaluation" enabled. Still, elements in the watch window only update if/when a breakpoint is set and then hit.
Adam Kane
A: 

I'm not aware of a method of watching without being broken into the debugger however you could use a couple of different approaches. I would personally use trace for this with Trace.Writeline or something similar (I use a custom library). However you could also get a quick solution using Tracepoints, which are breakpoints that output content to the output window.

I had a brief google and this article seems to give an overview of how to set them, you put your variable names within { } and they are output to the output window, seemingly without breaking into the debugger (although behind the scenes that's exactly what it does)

Hope that helps

Tollo
No luck. This approach writes thousands of lines of trace text to the output window per minute. I'm really looking for something that presents an updating treeview control of arbitrary object instances.
Adam Kane
+1  A: 

If there's a particular value of a variable that you want to watch for you can use a conditional breakpoint: http://msdn.microsoft.com/en-us/library/7sye83ce.aspx

And of course there's always the trusty ASSERT() macro for that as well.

If you have really complicated debugging needs you may need to write custom code in your application just for debugging. Typically that sort of thing gets wrapped inside of #ifdef _DEBUG/#endif statements so that the release builds are not affected. You can support everything from the old standby of log file debugging up to writing a custom watch window that displays the current values that you need to see.

onedozenbagels
Hmmm... I'm looking to watch arbitrary objects that contain dozens of varialbles that update countinuously (like framerate) which change many times per second. I'd like to watch these change while the program as running as opposed to stopping the program completely and just getting a snapshot of things at one moment in time.
Adam Kane
You could set up some custom performance counters and watch them using Perfmon. Or you could write a small custom app that you update using Names Pipes to show whatever data you wanted.
onedozenbagels
A: 

create a breakpoint, right click it, select on hit event, and setup printing of the variable there. This works.

No good. I need to observe a number of variables for a number of objects while things are running. thanks though.
Adam Kane
A: 

I'm not sure it's possible to set the debug watch window continuously updating like you describe. Have you considered using the TRACE macro that will output content to the output panel as your application runs?

TRACE(_T("m_LocationX: %d\n"), m_LocationX);
TRACE(_T("m_LocationY: %d\n"), m_LocationY);

Depending on how frequently the TRACE statements are executed your output window might get flooded, however it should at least give you the information you require at runtime.


Edit 1: If you're not using MFC, then take a look at this StackOverflow answer that explains an alternative method.

Edit 2: Looking at this question again, it's not clear whether you're using C++ or .Net - If you're using C#, then you can achieve a similar result by using the Debug and Trace classes - a good article describing their use can be found here.

Alan
Hmmm, writing the values of dozens of object variables to the output window which are changing at 60fps isn't really practical as a way to monitor the values at runtime. Thanks though.
Adam Kane
+1  A: 

There is not a way to do this.

Adam Kane