• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
VS Debugging Tricks
 

VS Debugging Tricks

on

  • 11,299 views

Visual Studio undocumented native debugging tricks presentation. By Ofek Shilon.

Visual Studio undocumented native debugging tricks presentation. By Ofek Shilon.

Statistics

Views

Total Views
11,299
Views on SlideShare
8,481
Embed Views
2,818

Actions

Likes
2
Downloads
17
Comments
0

7 Embeds 2,818

http://blogs.microsoft.co.il 2707
http://feeds.feedburner.com 85
http://beta.blogs.microsoft.co.il 18
http://subscribe.ru 4
http://www.hanrss.com 2
http://www.newsblur.com 1
http://webcache.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • C++התחלות שלא הבשילו בזמןמקור עיקרי – בלוגים של מפתחי VSדברים מאד שימושיים – לחלק שמתי בקשות להפוך לפיצ'רים רשמייםVS2010 / VS2011B
  • Many people think that editing variables is the most they can intervene with the debugeeEdit variables, move execution around
  • אינליין – רלבנטי בRELEASE
  • Break *before* code change, greatly reduces the chance of stale codeUse directX sample!
  • Incremental linking: pads functions code, contains jump thunks to handle function relocationInconsistent with /OPT:REF, /OPT:ICF, /ORDER, /RELEASE, /FORCESome changes are too great, full linking occurs.All options are on by default in debug
  • 2005: for all users
  • comment std::vector רפרוף בסיסי על הסינטקס, רפרנסים טובים בסוףInsert carray childrenCarray previewVect3d preview
  • טוב גם לבדוק שם אם נדמה שלא פועל
  • כשיודעים מה לחפש – מוצאים המון
  • לא מוחבא ברג'יסטרי, יש UI, אבל במקום ממש לא סביר ורחוק מאד מVS עצמוהועף ב2005, הוחזר ב2008 לקול מחאות הציבור
  • Code: ::DeleteFile, GetLastError$fs fakes it...(int*)($fs)+0x18(int*)($tib)+0x34$errFormatting strings:12.3412.34,g$err,hr(_TEB*)$tib
  • HRESULT customization doesn’t even require debugger restart!!_TEB is not defined publically, but the debugger is aware of it. Contains much useful data for advanced scenarios (fiber-specific data, etc)
  • Doesn’t work for templated classes/methodsDoesn’t extend to wildcards/regexGood way to find entry points
  • No ‘name’ slot in TEB
  • Write-to BPs are implemented in hardware – dedicated x86 debug registers.Read-from debugs registers are available too, but were never exposed in VS.Some code required Maybe historical portability constraints? Dunno4 very similar implementations
  • Not investigating code *flow* - static feature.After /d1reportSingleClassLayout, type immediatelly your classTest: /d1reportSingleClassLayoutCDialog . show vftable, alignment, adjustorsDebug ODR violationsOptimize storageGain deep insightSince VS2010, collides with /showIncludes (?)Watch out for PCH – if your class definition isn’t compiled, its layout won’t be shown
  • $cmdline credit: John Cunningham, http://blogs.msdn.com/b/ms_joc/archive/2004/08/23/218912.aspx$env=0 no longer works in VS2010
  • Demo – on envvars.S -U 0x006fdad0 60 "ALLUSERSPROFILE"שימושי בדיבוג של דמפים מלאים

VS Debugging Tricks VS Debugging Tricks Presentation Transcript

  • Little KnownNative Debugging Tricks Ofek Shilon Director of Algorithms @ Sarin Technologies www.thetweaker.wordpress.com
  • DISCLAIMER
  • VS AS AN INTERPRETER
  • Expression Evaluator• Demo• Scope – Watch, QuickWatch, – Immediate, – BP conditions, ‘when hit’• Call Functions from the debugger!
  • 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)
  • Expression Evaluator• Thread context• Access insensitive• Blind to inlined functions• Things to try when evaluation fails: – Very explicit casting, – Explicit addresses.
  • Edit and Continue• Demo• Stale code
  • Edit and Continue• Preparation: /ZI, /INCREMENTAL
  • 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.
  • CLICK SAVERS
  • StepOver• Demo
  • StepOver• VC6: autoexp section [ExecutionControl]• VC7: Reg key - HKCUSoftwareMicrosoftVisualStudio7.0NativeDEStepOver• VC8: HKLMSoftwareMicrosoftVisualStudio8.0NativeDEStepOver• VC10, VC11B: HKCUSoftwareMicrosoftVisualStudio10.0_ConfigNativeDEStepOver Dropped ‘=NoStepInto’ syntax
  • StepOver• Warning! When 2 or more instances of VS are active, occasionally it would create and use a duplicate reg key … and all ’10.0_Config’ modifications would have no effect !
  • StepOver• Credit: Andy Pennell http://blogs.msdn.com/b/andypennell/archive/2004/02/06/69004.aspx• A request to make StepOver official: http://visualstudio.uservoice.com/forums/121579-visual- studio/suggestions/2668765-support-nostepinto-registry-mechanism
  • autoexp• How’s the debugger ‘aware’ of STL containers?• autoexp.dat – By default at %VS folder %Common7PackagesDebugger
  • autoexp• Demo• Specialized syntax for common containers: Array, List, Map, Tree.• Re-parsed on every debugging session• Extremely fragile, yet excellent investment
  • autoexp• Status limbo:
  • autoexp• Bypass file path via env var: _vcee_autoexp• Bypass visualizer locally: xxx,!• Bypass globally in Tools/Options:
  • autoexp• Resources: – Avery Lee http://virtualdub.org/blog/pivot/entry.php?id=120 – Stephan T. Lavavej BoostCon presentation http://filetolink.com/d/?h=a456fc7fd3d35644edcbe5e764d1ba63&t=1315076450&f=17ad36ef – My blog: complete MFC containers visualization, Matrix 2D visualization, and more www.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
  • Sound Alerts• Win7: Control Panel Hardware and Sounds Sound Change system sounds• WinXP: Control Panel Sounds and Audio... Program Events – Microsoft Developer
  • TRACING ERRORS
  • GetLastError Interactively• GetLastError implementation:• (int*)($fs)+0x34• (int*)($tib)+0x34• $err !• Credit: msdn http://msdn.microsoft.com/en-us/library/dtw169z6.aspx
  • Extensions• Customizing ‘,hr’ display in autoexp.dat:• Other TEB data: (_TEB*)$tib
  • 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
  • INVESTIGATING CODE
  • Breaking on all class methods• Break at function: Class::*• Credit: Habib Heydarian http://blogs.msdn.com/b/habibh/archive/2009/09/10/class-breakpoint- how-to-set-a-breakpoint-on-a-c-class-in-the-visual-studio-debugger.aspx
  • Naming Native Threads• Demo• ‘Documented hack’ Credit: MSDN http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
  • 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
  • Static Object Layout• /d1reportSingleClassLayout• /d1reportAllClassLayout• Credit: Andy Rich http://blogs.msdn.com/b/vcblog/archive/2007/05/17/diagnosing-hidden- odr-violations-in-visual-c-and-fixing-lnk2022.aspx
  • ENHANCED DIAGNOSIS
  • 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 line Credit: John Cunningham, http://blogs.msdn.com/b/ms_joc/archive/2004/08/23/218912.aspx
  • 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/
  • Searching Through Memory• Credit: msdn http://msdn.microsoft.com/en-us/library/ms171363.aspx
  • www.thetweaker.wordpress.comofekshilon@gmail.com THANK YOU.