+ All Categories
Home > Technology > VS Debugging Tricks

VS Debugging Tricks

Date post: 15-Dec-2014
Category:
Upload: sasha-goldshtein
View: 12,797 times
Download: 0 times
Share this document with a friend
Description:
Visual Studio undocumented native debugging tricks presentation. By Ofek Shilon.
35
Little Known Native Debugging Tricks Ofek Shilon Director of Algorithms @ Sarin Technologies www.thetweaker.wordpress.com
Transcript
Page 1: VS Debugging Tricks

Little KnownNative Debugging Tricks

Ofek ShilonDirector of Algorithms @ Sarin Technologies

www.thetweaker.wordpress.com

Page 2: VS Debugging Tricks
Page 3: VS Debugging Tricks

DISCLAIMER

Page 4: VS Debugging Tricks

VS AS AN INTERPRETER

Page 5: VS Debugging Tricks

Expression Evaluator

• Demo• Scope– Watch, QuickWatch,– Immediate,– BP conditions, ‘when hit’

• Call Functions from the debugger!

Page 6: VS Debugging Tricks

Expression Evaluator

• Context Operator– Documentation is wrong.– Might require decorated names.– VS2010 blocked WIN-API, but eased usage of

others.– VS11B supports the simpler syntax

msvcr110d.dll!fabs(-8.0f)

Page 7: VS Debugging Tricks

Expression Evaluator

• Thread context• Access insensitive• Blind to inlined functions• Things to try when evaluation fails:– Very explicit casting,– Explicit addresses.

Page 8: VS Debugging Tricks

Edit and Continue

• Demo• Stale code

Page 9: VS Debugging Tricks

Edit and Continue• Preparation: /ZI, /INCREMENTAL

Page 10: VS Debugging Tricks

Edit and Continue

• Limitations:– Inconsistent with /RELEASE, /OPT:REF, /OPT:ICF,

/ORDER, /FORCE,– Does not invoke custom build steps,– Isn’t supported on attached processes,– Can’t change object layout,– Doesn’t regenerate IDL files,– Can’t change resource files,– Does not build static libs.

Page 11: VS Debugging Tricks

CLICK SAVERS

Page 12: VS Debugging Tricks

StepOver

• Demo

Page 13: VS Debugging Tricks

StepOver

• VC6: autoexp section [ExecutionControl]• VC7: Reg key -

HKCU\Software\Microsoft\VisualStudio\7.0\NativeDE\StepOver

• VC8: HKLM\Software\Microsoft\VisualStudio\8.0\NativeDE\StepOver

• VC10, VC11B: HKCU\Software\Microsoft\VisualStudio\10.0_Config\NativeDE\StepOverDropped ‘=NoStepInto’ syntax

Page 14: VS Debugging Tricks

StepOver

• Warning!When 2 or more instances of VSare active, occasionally it would create and use a duplicate reg key

… and all ’10.0_Config’ modifications would have no effect !

Page 16: VS Debugging Tricks

autoexp

• How’s the debugger ‘aware’ of STL containers?• autoexp.dat– By default at

%VS folder %\Common7\Packages\Debugger

Page 17: VS Debugging Tricks

autoexp

• Demo

• Specialized syntax for common containers: Array, List, Map, Tree.

• Re-parsed on every debugging session• Extremely fragile, yet excellent investment

Page 18: VS Debugging Tricks

autoexp

• Status limbo:

Page 19: VS Debugging Tricks

autoexp

• Bypass file path via env var: _vcee_autoexp• Bypass visualizer locally: xxx,!• Bypass

globally in Tools/Options:

Page 20: VS Debugging Tricks

autoexp• Resources:– Avery Lee

http://virtualdub.org/blog/pivot/entry.php?id=120

– Stephan T. Lavavej BoostCon presentationhttp://filetolink.com/d/?h=a456fc7fd3d35644edcbe5e764d1ba63&t=1315076450&f=17ad36ef

– My blog: complete MFC containers visualization, Matrix 2D visualization, and morewww.thetweaker.wordpress.org

– A request to make autoexp official:http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2056273-support-debug-visualizers-through-autoexp-dat

Page 21: VS Debugging Tricks

Sound Alerts

• Win7:Control Panel \ Hardware and Sounds \ Sound \ Change system sounds

• WinXP:Control Panel \Sounds and Audio... \Program Events – Microsoft Developer

Page 22: VS Debugging Tricks

TRACING ERRORS

Page 23: VS Debugging Tricks

GetLastError Interactively

• GetLastError implementation:

• (int*)($fs)+0x34• (int*)($tib)+0x34• $err !• Credit: msdn

http://msdn.microsoft.com/en-us/library/dtw169z6.aspx

Page 24: VS Debugging Tricks

Extensions• Customizing ‘,hr’ display in autoexp.dat:

• Other TEB data: (_TEB*)$tib

Page 25: VS Debugging Tricks

Breaking on Errors

• BP location: (int*)($tib)+0x34• Specific error: BP condition– Slooooooooow

• g_dwLastErrorToBreakOn !– (int*){,,ntdll.dll}_g_dwLastErrorToBreakOn– Fails in VC10 over Win7. Restored in VC11B

• Credit: Daniel Pearson, http://blogs.msdn.com/b/danpear/archive/2007/04/06/2033100.aspx

Page 26: VS Debugging Tricks

INVESTIGATING CODE

Page 28: VS Debugging Tricks

Naming Native Threads

• Demo

• ‘Documented hack’Credit: MSDNhttp://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx

Page 29: VS Debugging Tricks

Breaking on Data Read

• Some code required.• Links to 4 implementations:

http://thetweaker.wordpress.com/2011/05/22/breaking-on-data-read/

• Request to make it official:http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2668700-expose-break-on-read-breakpoints

Page 30: VS Debugging Tricks

Static Object Layout

• /d1reportSingleClassLayout• /d1reportAllClassLayout

• Credit: Andy Richhttp://blogs.msdn.com/b/vcblog/archive/2007/05/17/diagnosing-hidden-odr-violations-in-visual-c-and-fixing-lnk2022.aspx

Page 31: VS Debugging Tricks

ENHANCED DIAGNOSIS

Page 32: VS Debugging Tricks

Useful Pseudo-registers

• $tid-> very useful as a BP condition.

• $env=0-> view debugee environment variables– In VC11: just $env in watch

• $cmdline = 0-> view launching command lineCredit: John Cunningham, http://blogs.msdn.com/b/ms_joc/archive/2004/08/23/218912.aspx

Page 33: VS Debugging Tricks

Useful Pseudo-registers

• $handles-> narrows down handle leaks

• $clk-> rough profiling

• $user-> view permissions info

• Credits: Steve Steiner, Gregg Miskelly, et. al. http://blogs.msdn.com/b/stevejs/http://blogs.msdn.com/b/greggm/

Page 34: VS Debugging Tricks

Searching Through Memory

• Credit: msdnhttp://msdn.microsoft.com/en-us/library/ms171363.aspx


Recommended