如何持续更新VS2008 Watch Window(不停止执行)?
在 Adobe Director 中,有一个监视窗口会在我的应用程序运行时更新。 例如,如果我有一个游戏应用程序并且正在观察球对象的实例,我可以看到它的所有值(速度、高度、状态变量等)在应用程序运行时实时更新。 我还可以将任何其他对象添加到窗口中并深入了解其变量,而无需停止执行。
在 Visual Studio 中(我在 2008 年),在 C# 中,有没有一种方法可以让 Debug > 当我的应用程序运行时观察窗口更新? 换句话说,我想在应用程序运行时密切关注给定对象的不同变量,而不是冻结所有内容并检查某个特定时刻的事物状态。
如果这是不可能的,有什么方法可以观察任意对象的值(无需预先对这些对象进行硬编码)。 例如,对于坦克对象,我们有位置、方向、速度等。假设有数十种不同类型的游戏对象,每个对象都有十几个左右的值。 这些值每秒改变 60 次。
目标是能够在运行时选择要“观察”的游戏对象,然后深入了解其变量的层次结构(与观察器窗格的方式相同)。 同样,该工具无法提前了解对象,因此无法针对特定对象进行硬编码。
提前致谢!
亚当
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
创建一个断点,右键单击它,选择命中事件,然后设置变量的打印。 这有效。
create a breakpoint, right click it, select on hit event, and setup printing of the variable there. This works.
如果您想要监视变量的特定值,可以使用条件断点: http://msdn.microsoft.com/en-us/library/7sye83ce.aspx
当然,也总是有值得信赖的 ASSERT() 宏。
如果您有非常复杂的调试需求,您可能需要在应用程序中编写自定义代码以进行调试。 通常,此类内容会包含在 #ifdef _DEBUG/#endif 语句中,以便发布版本不受影响。 您可以支持从旧的日志文件调试备用到编写显示您需要查看的当前值的自定义监视窗口的所有内容。
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.
没有办法做到这一点。
There is not a way to do this.
这可能会有所帮助:
http://msdn.microsoft.com/en-us/ Library/z4ecfxd9.aspx
打开或关闭自动属性评估
This might help:
http://msdn.microsoft.com/en-us/library/z4ecfxd9.aspx
To turn automatic property evaluation on or off
我不知道在不进入调试器的情况下进行观看的方法,但是您可以使用几种不同的方法。
我个人会使用 Trace.Writeline 或类似的东西来进行跟踪(我使用自定义库)。 但是,您还可以使用跟踪点获得快速解决方案,跟踪点是将内容输出到输出窗口的断点。
我进行了简短的谷歌搜索,这篇文章似乎为了概述如何设置它们,您将变量名称放在 { } 中,它们会输出到输出窗口,似乎没有闯入调试器(尽管在幕后这正是它所做的)
希望有帮助
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
我不确定是否可以像您所描述的那样将调试监视窗口设置为持续更新。 您是否考虑过使用
TRACE
宏会在应用程序运行时将内容输出到输出面板吗?根据 TRACE 语句的执行频率,您的输出窗口可能会被淹没,但它至少应该为您提供运行时所需的信息。
编辑 1:如果您不使用 MFC,请查看此 StackOverflow answer 解释了另一种方法。
编辑2:再次查看这个问题,不清楚您使用的是C++还是.Net - 如果您使用C#,那么您可以通过使用
Debug获得类似的结果
和Trace
类 - 可以找到一篇描述其使用的好文章 在这里。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?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
andTrace
classes - a good article describing their use can be found here.