You are previewing Advanced .NET Debugging.
O'Reilly logo
Advanced .NET Debugging

Book Description

“Mario Hewardt’s Advanced .NET Debugging is an excellent resource for both beginner and experienced developers working with .NET. The book is also packed with many debugging tips and discussions of CLR internals, which will benefit developers architecting software.” –Jeffrey Richter, consultant, trainer, and author at Wintellect “Mario has done it again. His Advanced Windows Debugging (coauthored with Daniel Pravat) is an invaluable resource for native code debugging, and Advanced .NET Debugging achieves the same quality, clarity, and breadth to make it just as invaluable for .NET debugging.” –Mark Russinovich, Technical Fellow, Microsoft Corporation

The Only Complete, Practical Guide to Fixing the Toughest .NET Bugs

Advanced .NET Debugging is the first focused, pragmatic guide to tracking down today’s most complex and challenging .NET application bugs. It is the only book to focus entirely on using powerful native debugging tools, including WinDBG, NTSD, and CDB, to debug .NET applications. Using these tools, author Mario Hewardt explains how to identify the real root causes of problems—far more quickly than you ever could with other debuggers.

Hewardt first introduces the key concepts needed to successfully use .NET’s native debuggers. Next, he turns to sophisticated debugging techniques, using real-world examples that demonstrate many common C# programming errors.

This book enables you to

  • Make practical use of postmortem debugging, including PowerDBG and other “power tools”

  • Understand the debugging details and implications of the new .NET CLR 4.0

  • Master and successfully use Debugging Tools for Windows, as well as SOS, SOSEX, CLR Profiler, and other powerful tools

  • Gain a deeper, more practical understanding of CLR internals, such as examining thread-specific data, managed heap and garbage collector, interoperability layer, and .NET exceptions

  • Solve difficult synchronization problems, managed heap problems, interoperability problems, and much more

  • Generate and successfully analyze crash dumps 

  • A companion web site (advanceddotnetdebugging.com) contains all sample code, examples, and bonus content.

    Table of Contents

    1. Advanced .NET Debugging
      1. Praise for Advanced .NET Debugging
      2. List of Code Listings
      3. Foreword
      4. Preface
        1. Who Should Read This Book?
          1. Software Developers
          2. Quality Assurance
          3. Product Support Engineers
          4. Operations Engineers
        2. Prerequisites
        3. Organization
          1. Part I—Overview
            1. Chapter 1—Introduction to the Tools
            2. Chapter 2—CLR Fundamentals
            3. Chapter 3—Basic Debugging Tasks
          2. Part II—Applied Debugging
            1. Chapter 4—Assembly Loader
            2. Chapter 5—Managed Heap and Garbage Collection
            3. Chapter 6—Synchronization
            4. Chapter 7—Interoperability
          3. Part III—Advanced Topics
            1. Chapter 8—Postmortem Debugging
            2. Chapter 9—Power Tools
            3. Chapter 10—CLR 4.0
        4. Conventions
        5. Required Tools
        6. Sample Code
        7. Support
        8. Summary
      5. Acknowledgments
      6. About the Author
      7. I. Overview
        1. 1. Introduction to the Tools
            1. Debugging Tools for Windows
            2. .NET 2.0—Redistributable
            3. .NET 2.0—SDK
            4. SOS
            5. SOSEX
            6. CLR Profiler
            7. Performance Counters
            8. Reflector for .NET
            9. PowerDbg
            10. Managed Debugging Assistants
            1. Summary
        2. 2. CLR Fundamentals
            1. High-Level Overview
            2. CLR and the Windows Loader
              1. Loading Native Images
              2. Loading .NET Assemblies
            3. Application Domains
              1. The System Application Domain
              2. The Shared Application Domain
              3. The Default Application Domain
            4. Assembly Overview
            5. Assembly Manifest
            6. Type Metadata
              1. Sync Block Table
              2. Type Handle
              3. Method Descriptors
              4. Modules
              5. Metadata Tokens
              6. EEClass
            1. Summary
        3. 3. Basic Debugging Tasks
            1. The Debugger and the Debugger Target
            2. Symbols
            3. Controlling Execution
              1. Breaking Execution
              2. Resuming Execution
              3. Stepping Through Code
              4. Exiting a Debugging Session
            4. Loading Managed Code Extensions
              1. Loading the SOS Extension DLL
              2. Loading the SOSEX Extension DLL
            5. Controlling CLR Debugging
            6. Setting Breakpoints
              1. Setting Breakpoints on JIT Compiled Functions
              2. Setting Breakpoints on Functions Not Yet JIT Compiled
              3. Setting Breakpoints in Precompiled Assemblies
              4. Setting Breakpoints on Generic Methods
            7. Object Inspection
              1. Dumping Raw Memory
              2. Dumping Value Types
              3. Dumping Basic Reference Types
              4. Dumping Arrays
              5. Dumping Stack Objects
              6. Finding Object Sizes
              7. Dumping Exceptions
            8. Thread Operations
              1. ClrStack
              2. Threads
              3. DumpStack
              4. EEStack
              5. COMState
            9. Code Inspection
              1. Unassembling Code
              2. Getting a Method Descriptor from a Code Address
              3. Showing the Intermediate Language Instructions
            10. CLR Internals Commands
              1. Getting the CLR Version
              2. Finding the Method Descriptor from a Name
              3. Dumping the Sync Block of an Object
              4. Dumping the Method Table of an Object
              5. Dumping Information About the Managed Heap and Garbage Collector
            11. Diagnostics Commands
              1. Finding the Application Domain of an Object
              2. Process Information
            12. SOSEX Extension Commands
              1. Extended Breakpoint Support
                1. Breakpoint List
                2. Setting Breakpoints
              2. Managed Metadata
              3. Stack Traces
              4. Object Inspection
              5. Automated Deadlock Detection
              6. Managed Heap and Garbage Collector Commands
            13. Crash Dump Files
            1. Summary
      8. II. Applied Debugging
        1. 4. Assembly Loader
            1. CLR Loader Overview
              1. Assembly Identity
              2. Global Assembly Cache
              3. Default Load Context
              4. Load-from Context
              5. Load-without Context
            2. Simple Assembly Load Failure
            3. Load Context Failure
            4. Interoperability and DllNotFoundException
            5. Debugging Light Weight Code Generation
            1. Summary
        2. 5. Managed Heap and Garbage Collection
            1. Windows Memory Architecture Overview
              1. Allocating Memory
            2. Garbage Collector Internals
              1. Generations
              2. Roots
              3. Finalization
              4. Reclaiming GC Memory
              5. Large Object Heap
              6. Pinning
              7. Garbage Collection Modes
            3. Debugging Managed Heap Corruptions
            4. Debugging Managed Heap Fragmentation
            5. Debugging Out of Memory Exceptions
            1. Summary
        3. 6. Synchronization
            1. Synchronization Basics
            2. Thread Synchronization Primitives
              1. Events
              2. Mutex
              3. Semaphore
              4. Monitor
              5. ReaderWriterLock(Slim)
              6. Thread Pool
            3. Synchronization Internals
              1. Object Header
              2. Sync Blocks
              3. Thin Locks
            4. Synchronization Scenarios
              1. Basic Deadlock
              2. Orphaned Lock Exceptions
              3. Thread Abortion
              4. Finalizer Hangs
            1. Summary
        4. 7. Interoperability
            1. Platform Invocation
            2. COM Interoperability
              1. Runtime Callable Wrapper
            3. Debugging P/Invoke Calls
              1. Calling Conventions
              2. Delegates
            4. Debugging Interop Leaks
            5. Debugging COM Interop Finalization
            1. Summary
      9. III. Advanced Topics
        1. 8. Postmortem Debugging
            1. Dump File Fundamentals
              1. Generating Dump Files Using the Debuggers
                1. DbgManagedDebugger
                2. DbgJITDebugLaunchSettings
              2. Generating Dump Files Using ADPlus
              3. Debugging Dump Files
              4. The Data Access Layer
              5. Dump File Analysis: Unhandled .NET Exception
            2. Windows Error Reporting
              1. Windows Error Reporting Architecture
                1. Enrolling in Windows Error Reporting
                2. Navigating the WER Web Site
                3. Mapping Binaries to Products
                4. Querying the Windows Error Reporting Service
                5. Providing Responses
                6. Reporting and Subscribing
                7. Programmatic Access to Windows Error Reporting
            1. Summary
        2. 9. Power Tools
            1. PowerDbg
              1. Installing PowerDbg
              2. Analyze-PowerDbgThreads
              3. Send-PowerDbgCommand
              4. Extending PowerDbg
            2. Visual Studio
              1. SOS Integration
              2. .NET Framework Source-Level Debugging
              3. Visual Studio 2010
            3. CLR Profiler
              1. Running the CLR Profiler
              2. Summary View
              3. Histogram Views
              4. Graph Views
            4. WinDbg and the CmdTree Command
            1. Summary
        3. 10. CLR 4.0
            1. Tools
              1. Debugging Tools for Windows
              2. .NET 4.0 Redistributable
              3. SOS
            2. Managed Heap and Garbage Collection
              1. Extended Diagnostics
                1. VerifyObj
                2. FindRoots
                3. HeapStat
                4. GCWhere
                5. ListNearObj
                6. AnalyzeOOM
              2. Background Garbage Collection
            3. Synchronization
              1. Thread Pool and Tasks
              2. Monitor
              3. Barrier
              4. CountdownEvent
              5. ManualResetEventSlim
              6. SemaphoreSlim
              7. SpinWait and SpinLock
            4. Interoperability
            5. Postmortem Debugging
            1. Summary