What are data breakpoints?
Definition:
Data breakpoints allow you to break
execution when the value stored at a
specified memory location changes.
From MSDN: How to: Set a Data Breakpoint:
How to Set a Memory Change Breakpoint
From the Debug Menu, choose New Breakpoint and click New Data Breakpoint
—or—
in the Breakpoints window Menu, click the New dropdown and choose New Data Breakpoint.
The New Breakpoint dialog box appears.
In the Address box, enter a memory address or expression that evaluates to a memory address. For example, &foo to break when the contents of variable foo change.
In the Byte Count box, enter the number of bytes you want the debugger to watch. For example, if you enter 4, the debugger will watch the four bytes starting at &foo and break if any of those bytes change value.
Click OK.
How are data breakpoints created?
On an x86 processor, you set up data breakpoints by using the debug registers on the processor. Debug registers DR0-DR3 store the addresses to watch. That's the reason that Visual Studio is limited to four data breakpoints.
data breakpoints in java/eclipse
You can set a watchpoint on a field: put the cursor at the line where the field is being declared and select the menu Run -> Toggle Watchpoint
or just set a breakpoint by double-clicking at the left margin on that line.
You can change the properties of the watchpoint like suspend on field access
or suspend on field modification
after adding it. Just right-click on the watchpoint at the left margin and select Breakpoint Properties...
Search the help for watchpoint to get more information:
A watchpoint is a special breakpoint that stops the execution of an application whenever the value of a given expression changes, without specifying where it might occur. ...
How to use data breakpoints in Visual Studio 2017, C++, CMake?
(1) Please add breakpoint firstly, and make sure that the breakpoint was hit before you add the data breakpoint.
(2) Please set the .exe as the startup item, view the result.
Atmel Studio: How exacly do data breakpoints trigger?
The debug hardware I've used that supports break on data access aren't implemented like I think most people would expect them to be. The hardware doesn't monitor the memory at the address and issue a breakpoint if it changes, it monitors the read/write bus of the CPU and breaks if an access happens at the given address (or range of addresses) and of the correct width.
The end result is you can have some activities not be caught by the hardware. DMA accessing the memory is a big one that you simply cannot catch (unless your SRAM/DRAM interface has the ability to issue a fault like that). Also, if you're accessing the address in the mode which the debug hardware isn't configured for (i.e. doing byte writes when you're looking for word writes--which might be possible if you have a very naive memset/memcpy that does byte accesses)
My guess is you're doing some byte accesses on the array declared before your pointer and stomping on the pointer by overflowing the array. Even though you set up the word access hardware breakpoint on the pointer, it isn't being caught because you're doing byte accesses.
How to set a data breakpoint on a variable address in CDB (WinDbg)
You need @@c++()
or .expr /s c++
:
0:000> bp MemoryBreak!Test::Test
0:000> g
Breakpoint 2 hit
MemoryBreak!Test::Test:
[...]
0:000> l+t
Source options are 1:
1/t - Step/trace by source line
0:000> p
MemoryBreak!Test::Test+0x42:
0:000> ? @@c++(ptr)
Evaluate expression: 2790386541360 = 00000289`afffa330
0:000> ba w 4 @@c++(ptr)+4
0:000> bl
1 e Disable Clear 00007ff7`5fac2720 [C:\....cpp @ 23] 0001 (0001) 0:**** MemoryBreak!main
2 e Disable Clear 00007ff7`5fac1fa0 [C:\....cpp @ 6] 0001 (0001) 0:**** MemoryBreak!Test::Test
3 e Disable Clear 00000289`afffa334 w 4 0001 (0001) 0:****
0:000> g
Breakpoint 3 hit
MemoryBreak!Test::Test+0xa7:
Related Topics
Avx2: Computing Dot Product of 512 Float Arrays
C++ Format MACro/Inline Ostringstream
Boost-Python How to Pass a C++ Class Instance to a Python Class
Convert Eigen Matrix to C Array
How to Create Std::Array with Initialization List Without Providing Size Directly
Memory Allocation Profiling in C++
Problems Using Member Function as Custom Deleter with Std::Shared_Ptr
How to Check If a Function Exists in C/C++
Is Boost Shared_Ptr <Xxx> Thread Safe
Can't Find Windows Forms Application for C++
Is Std::Ifstream Significantly Slower Than File
Convert a Static Library to a Shared Library (Create Libsome.So from Libsome.A): Where's My Symbols
Cin.Getline() Is Skipping an Input in C++
Using Std::Map<K,V> Where V Has No Usable Default Constructor