调试之设置数据断点 (zz.IS2120)

本文介绍如何在Visual Studio中设置数据断点,当特定内存位置的值被写入时触发断点。文章解释了数据断点的工作原理及限制条件,并提供了设置步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How to: Set a Data Breakpoint (Native Only)

//z 2012-09-11 09:43:48 IS2120@优快云.T3678804781[T31,L404,R7,V204]
Data breakpoints break execution when a value that is stored at a specified memory location is written. If the value is read but not written, execution does not break.

Data breakpoints do not work under these conditions: if a process that is not being debugged writes to the memory location, or if the memory location is shared between two or more processes.

Data breakpoints do not work if the memory location is updated within the kernel. For example, if memory is passed to the 32-bit Windows ReadFile function, the memory will be updated from kernel mode and the debugger does not break on the memory write.

To set data breakpoints, the debugger must be in break mode only.

Addresses of variables change from one debugging session to the next. For this reason, data breakpoints are automatically disabled at the end of each debugging session.

If you set a data breakpoint on a local variable, the data breakpoint remains enabled when the function ends. However, the memory address it is set on no longer has the same meaning. Therefore, the results of such a breakpoint are unpredictable. If you set a data breakpoint on a local variable, the best practice is to remove or disable the breakpoint before the function ends.

Visual Studio supports a maximum of four data breakpoints per solution.

Note The dialog boxes and menu commands you see might differ from those described in Help, depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu.

To set a memory change breakpoint

//z 2012-09-11 09:43:48 IS2120@优快云.T3678804781[T31,L404,R7,V204]
On the Debug menu, choose New Breakpoint, and then click New Data Breakpoint.
  1. -or-

    In the Breakpoints window menu, click New, and then choose New Data Breakpoint.

    The New Breakpoint dialog box appears.

  2. In the Address box, type a memory address or expression that evaluates to a memory address.

    For example, type &avar to break when the contents of variable avar change.

  3. In the Byte Count box, type the number of bytes you want the debugger to watch.

    For example, if you type 4, the debugger will watch the four bytes starting at &myFunction and break if any of those bytes change value.

  4. Click OK.

调试 断点 观察 变量 变化 内存 变化
//z 2012-09-11 09:43:48 IS2120@优快云.T3678804781[T31,L404,R7,V204]

转载于:https://www.cnblogs.com/IS2120/archive/2012/09/11/6745832.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值