当私有成员变量更改值时,如何在Visual Studio Debugger中停止执行? [英] How can I stop execution in the Visual Studio Debugger when a private member variable changes value?

查看:136
本文介绍了当私有成员变量更改值时,如何在Visual Studio Debugger中停止执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的类有一个名为count的私有整数变量。



我已经在代码中打了一个断点。现在,在我继续之前,我想让它使调试器停止任何时候计数得到一个新的值分配给它。



除了促进计数到一个字段和设置断点上的设置方法,有没有其他的方法呢?

解决方案

你要找的是在托管代码中不可能。在C ++中,这被称为数据断点。它允许您在运行程序改变内存块时中断。但是,这只能在纯C ++代码中使用。



为什么没有实现的简短版本是托管代码更难。本地代码是很好的和可预测的。创建内存,除非创建一个新对象(或显式地复制内存),否则它不会移动。



托管代码复杂得多,因为它是一种垃圾回收语言。 CLR通常在内存中移动对象。因此,只是看一点记忆力不够好。它需要GC交互。



这只是实现托管断点的问题之一。


Let's say my class has a private integer variable called count.

I've already hit a breakpoint in my code. Now before I press continue, I want to make it so the debugger will stop anytime count gets a new value assigned to it.

Besides promoting count to a field and setting a breakpoint on the set method of the field, is there any other way to do this?

解决方案

What you're looking for is not possible in managed code. In C++ this is known as data break point. It allows you to break whenever a block of memory is altered by the running program. But this is only available in pure native C++ code.

A short version of why this is not implemented is that it's much harder in managed code. Native code is nice and predictable. You create memory and it doesn't move around unless you create a new object (or explicitly copy memory).

Managed code is much more complex because it's a garbage collected language. The CLR commonly moves objects around in memory. Therefore simply watching a bit of memory is not good enough. It requires GC interaction.

This is just one of the issues with implementing managed break points.

这篇关于当私有成员变量更改值时,如何在Visual Studio Debugger中停止执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆