Posts

Showing posts with the label Visual Studio

memory leak detection notes (continuously updating)

Memory leak problem is very common, below is some my previous working notes: BoundsCheck BoundsCheck does not work well with mixed codes. Since my latest projects are almost all mixed, so, seldom used in my daily work. Visual studio Enable memory leak reporting There are two ways to enable memory leak check in VC, one is to define DEBUG_NEW macro, another is as below: 1: #define _CRTDBG_MAP_ALLOC 2: #include<stdlib.h> 3: #include<crtdbg.h> Then calling _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); when initializing your app. With the above changes, visual studio can dump memory block leak when quitting or between two snapshot via Windows API. For instance: c:\program files(x86)\microsoft visual studio\vc98\include\crtdbg.h(552) : {43} normal block at 0x00441C20, 40 bytes long. Data: < C > 08 02 43 00 16 00 00 00 00 00 00 00 00 00 00 00 Output mode The above output is one sample of block leak, in which, {43} is the heap block a...

VS Tips (Continuously updated)

Image
Special commands in Immediate/Watch windows c# temp variables defined in Immediate Window input “int tempVar = 0;” in the immediate window, then type $temp or @temp in Watch window, see what happens. Can be helpful combined with the usage of Conditional Breakpoints. VS can even create an object in immediate window, like Something s = new Something(); Time-measurement feature by conditional breakpoint set a trace point, and change the statement as below: {@clk }, {@clk=0 }, $FUNCTION on my 64-bit win7, time resolution is 10-6 second see what happens control var’s display suffix var,h: in watch window shows hex value var,nq: show string without escaped quotes, helpful when showing “\”” var,ac: force to evaluate the expression even if “implicit expression evaluation” is disabled in debug-general setting. May be helpful to watch some variables which has nasty side effect when auto evaluate expression, like properties watch objects out of scope: “Make Object Id”, then...

Setting data breakpoints for mixed projects in VS2008

In VS2008, data breakpoints are disabled in GUI for mixed projects, which is actually a powerful debugging mechanism for trouble-shooting. Although it could still be set in windbg, still painful. Fortunately, data breakpoints can be set programmatically. We can found one sample from below link: http://www.morearty.com/code/breakpoint/ Then, in your projects, try below code:   1: DWORD x = 1; 2: CBreakpoint bp; 3: bp.Set(&x, sizeof (x), CBreakpoint::Write); 4: ... 5: x = 100; 6:   Generally, I would like to create an foo debugging thread, keep looping/sleeping, if needed, explicitly set the watch target dynamically in the debugger, then it works well.