To get really close to what you're looking for, you need to combine two features of Visual Studio: Data breakpoints and trace points. Data breakpoints allow you to notify the debugger, whenever the store value in memory changes. To set a data breakpoint, launch the debugger, and select Debug → New Breakpoint → Data Breakpoint...:
Since we are interested in the variable myValue
, we're setting the address to &myValue
, and set the size to 4 bytes (since that's what an int
is on Windows):
Now that would be pretty cool as-is already. But for non-intrusive logging, we'll set the Actions as well:
The important settings are the log message ([MYSIG]
is an arbitrary signature, so that the interesting log entries can later be filtered), that dumps the value of the variable, as well as the Continue execution check box. The latter makes this non-intrusive (or low-intrusive; logging lots of information does have a noticeable impact on runtime performance).
With that in place, running this code
inline void DataTracepoint() {
volatile int myValue{ 0 };
for ( int i = 0; i < 10; ++i ) {
myValue = i;
}
}
produces the following output in the Debug output pane:
[MYSIG] myValue = 0
[MYSIG] myValue = 1
[MYSIG] myValue = 2
[MYSIG] myValue = 3
[MYSIG] myValue = 4
[MYSIG] myValue = 5
[MYSIG] myValue = 6
[MYSIG] myValue = 7
[MYSIG] myValue = 8
[MYSIG] myValue = 9
This output can then be easily analyzed in your favorite text processor.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…