The Only Complete, Practical Guide to Fixing the Toughest .NET Software Bugs
Advanced .NET Debugging is the first focused, pragmatic guide to tracking down today's most complex and challenging .NET application bugs.
Authored by Mario Hewardt, coauthor of the widely praised Advanced Windows Debugging, this is the only book to focus entirely on .NET's powerful native debugging tools, including WinDBG, NTSD and CDB. Using these tools, Hewardt shows how to identify the real root causes of problems--far more quickly than you ever could with visual debuggers.
Hewardt first introduces the key concepts experienced .NET developers, testers, and support professionals need 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. In particular, he presents the most thorough and useful guide to .NET memory debugging ever published.
Advanced .NET Debugging also offers detailed, practical coverage of postmortem debugging; the use of PowerDBG and other "power tools"; and, finally, the debugging implications of the new .NET CLR 4.0.
This book enables you to
Master and successfully use Debugger Tools for Windows, SOS, SOSEX, CLR Profiler, and other powerful tools
Go beyond code reviews and tracing to identify root causes more quickly and accurately
Debug live machines with zero footprint and no configuration changes
Streamline and accelerate QA testing
Support production customers using static snapshots, not live processes
Perform key tasks such as examining thread-specific data, the garbage collector heap, and .NET exceptions
Troubleshoot complex .NET assembly dependencies
Solve difficult synchronization problems, including deadlocks and thread pool problems
Track down problems with Platform Invocation and COM Interoperability
Generate and successfully analyze crash dumps
Gain a deeper, more practical understanding of the .NET runtime and its components
This book is a must-have for experienced .NET developers, QA specialists, product support engineers, and for operations engineers who maintain "cloud"-based .NET software.
Product 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.
Backcover
"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.
Foreword xix
Preface xxi
Acknowledgments xxxi
About the Author xxxiii
Part I: Overview 1
Chapter 1: Introduction to the Tools 3
Debugging Tools for Windows 3
.NET 2.0-Redistributable 4
.NET 2.0-SDK 5
SOS 8
SOSEX 10
CLR Profiler 11
Performance Counters 14
Reflector for .NET 15
PowerDbg 16
Managed Debugging Assistants 18
Summary 21
Chapter 2: CLR Fundamentals 23
High-Level Overview 23
CLR and the Windows Loader 26
Application Domains 33
Assembly Overview 38
Assembly Manifest 39
Type Metadata 42
Summary 68
Chapter 3: Basic Debugging Tasks 69
The Debugger and the Debugger Target 69
Symbols 74
Controlling Execution 77
Loading Managed Code Extensions 85
Controlling CLR Debugging 90
Setting Breakpoints 90
Object Inspection 103
Thread Operations 131
Code Inspection 143
CLR Internals Commands 146
Diagnostics Commands 149
SOSEX Extension Commands 151
Crash Dump Files 163
Summary 165
Part II: Applied Debugging 167
Chapter 4: Assembly Loader 169
CLR Loader Overview 169
Simple Assembly Load Failure 179
Load Context Failure 185
Interoperability and DllNotFoundException 195
Debugging Light Weight Code Generation 197
Summary 202
Chapter 5: Managed Heap and Garbage Collection 203
Windows Memory Architecture Overview 204
Garbage Collector Internals 213
Debugging Managed Heap Corruptions 254
Debugging Managed Heap Fragmentation 262
Debugging Out of Memory Exceptions 272
Summary 291
Chapter 6: Synchronization 293
Synchronization Basics 293
Thread Synchronization Primitives 294
Synchronization Internals 306
Synchronization Scenarios 316
Summary 344
Chapter 7: Interoperability 345
Platform Invocation 345
COM Interoperability 352
Debugging P/Invoke Calls 358
Debugging Interop Leaks 373
Debugging COM Interop Finalization 378
Summary 388
Part III: Advanced Topics 389
Chapter 8: Postmortem Debugging 391
Dump File Fundamentals 392
Windows Error Reporting 409
Summary 438
Chapter 9: Power Tools 439
PowerDbg 439
Visual Studio 448
CLR Profiler 460
WinDbg and the CmdTree Command 467
Summary 469
Chapter 10: CLR 4.0 471
Tools 471
Managed Heap and Garbage Collection 472
Synchronization 480
Interoperability 483
Postmortem Debugging 484
Summary 485
Index 487
"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.0Master and successfully use Debugging Tools for Windows, as well as SOS, SOSEX, CLR Profiler, and other powerful toolsGain a deeper, more practical understanding of CLR internals, such as examining thread-specific data, managed heap and garbage collector, interoperability layer, and .NET exceptionsSolve difficult synchronization problems, managed heap problems, interoperability problems, and much moreGenerate and successfully analyze crash dumps
A companion web site (advanceddotnetdebugging.com) contains all sample code, examples, and bonus content.
Advanced .NET Debugging is the first focused, pragmatic guide to tracking down today's most complex and challenging .NET application bugs.
Authored by Mario Hewardt, coauthor of the widely praised Advanced Windows Debugging, this is the only book to focus entirely on .NET's powerful native debugging tools, including WinDBG, NTSD and CDB. Using these tools, Hewardt shows how to identify the real root causes of problems--far more quickly than you ever could with visual debuggers.
Hewardt first introduces the key concepts experienced .NET developers, testers, and support professionals need 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. In particular, he presents the most thorough and useful guide to .NET memory debugging ever published.
Advanced .NET Debugging also offers detailed, practical coverage of postmortem debugging; the use of PowerDBG and other "power tools"; and, finally, the debugging implications of the new .NET CLR 4.0.
This book enables you to
Master and successfully use Debugger Tools for Windows, SOS, SOSEX, CLR Profiler, and other powerful tools
Go beyond code reviews and tracing to identify root causes more quickly and accurately
Debug live machines with zero footprint and no configuration changes
Streamline and accelerate QA testing
Support production customers using static snapshots, not live processes
Perform key tasks such as examining thread-specific data, the garbage collector heap, and .NET exceptions
Troubleshoot complex .NET assembly dependencies
Solve difficult synchronization problems, including deadlocks and thread pool problems
Track down problems with Platform Invocation and COM Interoperability
Generate and successfully analyze crash dumps
Gain a deeper, more practical understanding of the .NET runtime and its components
This book is a must-have for experienced .NET developers, QA specialists, product support engineers, and for operations engineers who maintain "cloud"-based .NET software.
Product 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.
Backcover
"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.
Foreword xix
Preface xxi
Acknowledgments xxxi
About the Author xxxiii
Part I: Overview 1
Chapter 1: Introduction to the Tools 3
Debugging Tools for Windows 3
.NET 2.0-Redistributable 4
.NET 2.0-SDK 5
SOS 8
SOSEX 10
CLR Profiler 11
Performance Counters 14
Reflector for .NET 15
PowerDbg 16
Managed Debugging Assistants 18
Summary 21
Chapter 2: CLR Fundamentals 23
High-Level Overview 23
CLR and the Windows Loader 26
Application Domains 33
Assembly Overview 38
Assembly Manifest 39
Type Metadata 42
Summary 68
Chapter 3: Basic Debugging Tasks 69
The Debugger and the Debugger Target 69
Symbols 74
Controlling Execution 77
Loading Managed Code Extensions 85
Controlling CLR Debugging 90
Setting Breakpoints 90
Object Inspection 103
Thread Operations 131
Code Inspection 143
CLR Internals Commands 146
Diagnostics Commands 149
SOSEX Extension Commands 151
Crash Dump Files 163
Summary 165
Part II: Applied Debugging 167
Chapter 4: Assembly Loader 169
CLR Loader Overview 169
Simple Assembly Load Failure 179
Load Context Failure 185
Interoperability and DllNotFoundException 195
Debugging Light Weight Code Generation 197
Summary 202
Chapter 5: Managed Heap and Garbage Collection 203
Windows Memory Architecture Overview 204
Garbage Collector Internals 213
Debugging Managed Heap Corruptions 254
Debugging Managed Heap Fragmentation 262
Debugging Out of Memory Exceptions 272
Summary 291
Chapter 6: Synchronization 293
Synchronization Basics 293
Thread Synchronization Primitives 294
Synchronization Internals 306
Synchronization Scenarios 316
Summary 344
Chapter 7: Interoperability 345
Platform Invocation 345
COM Interoperability 352
Debugging P/Invoke Calls 358
Debugging Interop Leaks 373
Debugging COM Interop Finalization 378
Summary 388
Part III: Advanced Topics 389
Chapter 8: Postmortem Debugging 391
Dump File Fundamentals 392
Windows Error Reporting 409
Summary 438
Chapter 9: Power Tools 439
PowerDbg 439
Visual Studio 448
CLR Profiler 460
WinDbg and the CmdTree Command 467
Summary 469
Chapter 10: CLR 4.0 471
Tools 471
Managed Heap and Garbage Collection 472
Synchronization 480
Interoperability 483
Postmortem Debugging 484
Summary 485
Index 487
"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.0Master and successfully use Debugging Tools for Windows, as well as SOS, SOSEX, CLR Profiler, and other powerful toolsGain a deeper, more practical understanding of CLR internals, such as examining thread-specific data, managed heap and garbage collector, interoperability layer, and .NET exceptionsSolve difficult synchronization problems, managed heap problems, interoperability problems, and much moreGenerate and successfully analyze crash dumps
A companion web site (advanceddotnetdebugging.com) contains all sample code, examples, and bonus content.