Your SlideShare is downloading. ×
Little Known VC++ Debugging Tricks
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Little Known VC++ Debugging Tricks

8,111

Published on

Presentation by Ofek Shilon, at the Microsoft Israel Windows Platform Developers users meeting

Presentation by Ofek Shilon, at the Microsoft Israel Windows Platform Developers users meeting

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
8,111
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • C++ VS2010 ?
  • Many people think that editing variables is the most they can intervene with the debugee Edit variables, move execution around
  • ברור שב WATCH אפשר לשערך משתנים אפשר גם לחשב סכום של מספרים כלומר יש מנוע שמפרסר ומחשב את הטקסט שמקלידים נקרא EXPRESSION-EVALUATOR, סמי - מתועד הכוח המרכזי שלו – מאפשר קריאה לפונקציות , במגבלות שתכף יתוארו . לפחות חלקן
  • אינליין – רלבנטי ב RELEASE
  • Break *before* code change, greatly reduces the chance of stale code Try to use directX sample!
  • Incremental linking: pads functions code, contains jump thunks to handle function relocation Inconsistent with /OPT:REF, /OPT:ICF, /ORDER, /RELEASE, /FORCE Some changes are too great, full linking occurs. All options are on by default in debug
  • 2005: for all users
  • 2005: for all users
  • 2005: for all users
  • comment std::vector רפרוף בסיסי על הסינטקס , רפרנסים טובים בסוף Insert carray children Carray preview Vect3d preview
  • טוב גם לבדוק שם אם נדמה שלא פועל
  • כשיודעים מה לחפש – מוצאים המון
  • אם הבילד ארוך , או אתה מחכה שעות ל BP, אתה נודד ל YNET. ובודק חזרה אחת לכמה דקות . תארו לכם שהיה אפשר לשמוע צפצוף , או קול של דרת ויידר , כשהתנאי הזה מתקיים . לא מוחבא ברג ' יסטרי , יש UI, אבל במקום ממש לא סביר ורחוק מאד מ VS עצמו הועף ב 2005, הוחזר ב 2008 לקול מחאות הציבור
  • Code: ::DeleteFile, GetLastError $fs fakes it... (int*)($fs)+0x18 (int*)($tib)+0x34 $err Formatting strings: 12.34 12.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/methods Doesn’t extend to wildcards/regex Good way to find entry points
  • No ‘name’ slot in TEB
  • Maybe historical portability constraints? Dunno 4 very similar implementations
  • Not investigating code *flow* - static feature. After /d1reportSingleClassLayout, type immediatelly your class Test: /d1reportSingleClassLayoutCDialog . show vftable, alignment, adjustors Debug ODR violations Optimize storage Gain deep insight Since 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 env vars .S -U 0x006fdad0 60 "ALLUSERSPROFILE" שימושי בדיבוג של דמפים מלאים
  • Transcript

    • 1. Little Known Native Debugging Tricks Ofek Shilon Algorithms Team Leader @ Sarin Technologies www.thetweaker.wordpress.com
    • 2.  
    • 3. DISCLAIMER
    • 4. VS AS AN INTERPRETER
    • 5. Expression Evaluator
      • Scope
        • Watch, QuickWatch,
        • Immediate,
        • BP conditions, ‘when hit’
      • Call Functions from the debugger!
      • Demo
    • 6. Expression Evaluator
      • Context Operator
        • Documentation is wrong.
        • VS2010 blocked WIN-API, but eased usage of others.
      • Thread context
      • Access insensitive
      • Blind to inlined functions
    • 7. Expression Evaluator
        • Things to try:
        • Very explicit casting,
        • Explicit addresses.
    • 8. Edit and Continue
      • Demo
      • Stale code
    • 9. Edit and Continue
      • Preparation: /ZI, /INCREMENTAL
    • 10. 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.
    • 11. CLICK SAVERS
    • 12. StepOver
      • Demo
    • 13. StepOver
      • VC6: autoexp section [ExecutionControl]
      • VC7: Reg key - HKCUSoftwareMicrosoftVisualStudio7.0NativeDEStepOver
      • VC8: HK LM SoftwareMicrosoftVisualStudio8.0NativeDEStepOver
      • VC10: HK CU SoftwareMicrosoftVisualStudio10.0 _Config NativeDEStepOver Dropped ‘=NoStepInto’ syntax
    • 14. StepOver
      • Warning!
        • When 2 or more instances of VS2010 are active, occasionally it would create and use a duplicate reg key: HKCUSoftwareMicrosoftVisualStudio10.0_Config_%PID% (e.g., …VisualStudio10.0_Config_6172) … and all ’10.0_Config’ modifications would have no effect !
      • Credit: Andy Pennell http://blogs.msdn.com/b/andypennell/archive/2004/02/06/69004.aspx
    • 15. autoexp
      • How’s the debugger ‘aware’ of STL containers?
      • autoexp.dat
        • By default at %VS folder %Common7PackagesDebugger
        • Provide alternate path in environment variable: _vcee_autoexp
    • 16. autoexp
      • Demo
      • Specialized syntax for common containers: Array, List, Map, Tree.
      • Re-parsed on every debugging session
      • Extremely fragile, yet excellent investment
    • 17. autoexp
      • Status limbo:
    • 18. autoexp
      • Bypass locally: xxx ,!
      • Bypass globally in Tools/Options:
    • 19. 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.. www.thetweaker.wordpress.org
    • 20. Sound Alerts
      • Win7: Control Panel Hardware and Sounds Sound Change system sounds
      • WinXP: Control Panel Sounds and Audio... Program Events – Microsoft Developer
    • 21. TRACING ERRORS
    • 22. GetLastError Interactively
      • GetLastError implementation:
      • (int*)($fs)+0x34
      • (int*)($tib)+0x34
      • $err !
      • Credit: msdn http:// msdn.microsoft.com/en-us/library/dtw169z6.aspx
    • 23. Extensions
      • Customizing ‘,hr’ display in autoexp.dat:
      • Other TEB data: (_TEB*)$tib
    • 24. Breaking on Errors
      • BP location: (int*)($tib)+0x34
      • Specific error: BP condition
        • Slooooooooow
      • g_dwLastErrorToBreakOn !
        • (int*){,,ntdll.dll}_g_dwLastErrorToBreakOn
        • Seems to fail for Win7.
      • Credit: Daniel Pearson, http:// blogs.msdn.com/b/danpear/archive/2007/04/06/2033100.aspx
    • 25. INVESTIGATING CODE
    • 26. 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
    • 27. Naming Native Threads
      • Demo
      • ‘ Documented hack’ Credit: MSDN http:// msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
    • 28. Breaking on Data Read
      • 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 to set the register values to the desired address.
      • Links to 4 implementations: http://thetweaker.wordpress.com/2011/05/22/breaking-on-data-read /
    • 29. Breaking on Data Read
      • Usage:
      • Interactive:
    • 30. 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
    • 31. ENHANCED DIAGNOSIS
    • 32. Useful Pseudo-registers
      • $tid -> very useful as a BP condition.
      • $env=0 -> view debugee environment variables
      • $cmdline = 0 -> view launching command line
    • 33. 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 /
    • 34. Searching Through Memory
      • Credit: msdn http:// msdn.microsoft.com/en-us/library/ms171363.aspx
    • 35. THANK YOU. www.thetweaker.wordpress.com [email_address]

    ×