SlideShare a Scribd company logo
1 of 30
An introduction to production debugging Brian Lyttle
Help us make this even better! Thank our sponsors! This wouldn’t be possible without them. Please complete an online evaluation!
About me Brian Lyttle Solution Architect at LiquidHub E-mail blyttle@liquidhub.com Interwebs @brianly on Twitter @brianly on Stack Overflow Blog infrequently at http://brianlyttle.com
Agenda What is production debugging? Debugging fundamentals Monitoring and instrumentation Capturing crash information Common scenarios … all with a healthy number of examples Since this is an introductory talk I’m skipping: WinDbg, SOS, and ADPlus Native debugging
Audience Production debugging is something that helps a lot of different people A lot of these tools and techniques are not known by many developers. If you ever get the opportunity, go to a Mark Russinovich talk. The IT guys will know of him.
What is production debugging? Effectively any debugging you do once code has left the confines of a developer workstation. A variety of tools are required to investigate problems with: Resource usage Security or privilege violations Random crashing Bugs with 3rd party software Network failures Some consider it a “black art” only accessible to the alpha developers amongst us. As a discipline it requires you to learn more about the internals of your operating system, database etc.
Why is this important? It will make your users and manager happy:) You will get home on time. Your relationship with operations will improve. As you do more of this, your knowledge of operating systems, databases etc. will improve. Eventually your thinking will change, and you become more proactive.
Production debugging techniques Often it does not involve Visual Studio, or any other development environment. Active methods Production debuggers Tracing Protocol analysis Passive methods User reports Crash dumps Log files
Intermediate language and metadata Your .NET (managed code) assemblies are compiled to IL which is similar to assembly language. Older platforms like C/C++, classic VB, and many other do not have the concept of IL or metadata. With managed code an executable contains IL plus type information (metadata). This metadata is useful for Intellisense, serializing objects, debugging, and many other things. An interesting property of metadata is that it can help with disassembling your .NET assembly back to C#.
Exceptions decomposed Errors are supposed to be exceptional events within an application. So we have the System.Exception for conveying information about these errors. Provides a lot of important information: Stack trace Target site Custom message Inner exceptions (if any)
Obfuscating exceptions Each exception provides evidence for the person debugging the code. Like any type of evidence it can be tainted. Only catch and work with exceptions you can handle. Don’t default to catching System.Exception. If you catch an exception and need to re-throw it, make sure to throw the original. Good Bad } catch (ArgumentException ex) {    Log(ex.Message);    throw; } } catch (Exception ex) {   Log(ex.Message);    throw ex; } } catch (Exception e) {   Log(ex.Message); throw new Exception("", ex); } Logs the exception. Throws the original exception, nota new one.
Debugging symbols You might have noticed that there are debug and release options in Visual Studio. If you build in debug mode then additional code to support the debugger, and symbol (.PDB) files are generated. In release mode an optimized version of your application is built. This might still create .PDB files. PDB files are called symbols. They map your executable code to the matching Visual Studio project. Example: line number information. Best practice - keep a copy of the PDB files for every build you release.
Reading a stack trace Reading stack traces is a core skill for .NET developers.  The lines shown below provide insight into what was happening. Debug Build Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero.    at CCExample1.Program.Divide(Int32 op1, Int32 op2) in C:ode Camprojects CExample1CExample1rogram.cs:line 65    at CCExample1.Program.RunCode() in C:ode CamprojectsCExample1CExample 1rogram.cs:line 36    at CCExample1.Program.Main(String[] args) in C:ode CamprojectsCExample1 CExample1rogram.cs:line 14 3 2 1 Release Build Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero.    at CCExample1.Program.RunCode()    at CCExample1.Program.Main(String[] args) 2 1
Log files Applications often have official and unofficial logs which you can mine for information. Windows examples: Event Viewer %windir%System32ogFiles %windir%ystem32bemogs %COMMONPROGRAMFILES%icrosoft Sharedeb server extensions2OGS %systemdrive%erfLogsbr />Temp directories (everyone can write there!) Applications might also log to their database, or to a directory under their user identity. Eg. C:sersrianlyppDataocaliagnostics On Linux look in /var/log.
System resources It is very important to understand how resources constrain your application. They don’t seem that important until you run out of them. At times they will seem plentiful, but that may not be the case under the covers. Most common ,[object Object]
CPU
Disk I/O
Network I/OMeta resources ,[object Object]
Security privileges
Application caches
Software licenses
Garbage collections
Complex algorithms,[object Object]
Enter Task Manager Available on any Windows computer. Brent Ozar: a “check engine light” for your system. You get a high level view but a lot of interesting information is hidden by default. Special processes are not visible. Deeper info on Threads or other esoteric objects is not available. Resource Monitor is a useful partner for Task Manager on Vista/7. Fact: On Windows 2000 and earlier it can be plain wrong.
Process Explorer Improves on the capabilities of Task Manager. Highlights Process activity. Hierarchical view. All the gritty details. See which individual Thread is doing all the work.
Performance Monitor Process Explorer is good for spot checks, but you need something better to do background monitoring.
Metrics Available CPU % Idle Time % User Time Performance Monitor data can be captured for later review with a Data Collector Set. Export data to Excel for later analysis. It is possible to create custom performance counters. Examples: User Login Cart empties Document uploads Memory Available Mbytes Paging File % Usage Disk Disk Reads/sec Disk Writes/sec Avg. Disk Queue Length Others % Time in GC ASP.NET Cache Total Misses Windows Workflows Executing Faxes Sent ;)
Utilities * Used in the past week
Protocol analysis Snoop on what the server or client are sending over the network. These tools should be used with care. It is possible to capture passwords and other sensitive data. Work with a network admin when you need to perform a capture in a corporate environment. It is easiest to debug HTTP services with one of the specialized tools.
What is a crash dump? These are basically files containing information on the exception which caused the crash. Unhandled exceptions bubble up to the top-level of an application. Then .NET invokes it’s own default error handling. Luckily you can override this behavior and do some interesting things.

More Related Content

What's hot

Code instrumentation
Code instrumentationCode instrumentation
Code instrumentationMennan Tekbir
 
ユニバーサル Windows アプリ開発
ユニバーサル Windows アプリ開発ユニバーサル Windows アプリ開発
ユニバーサル Windows アプリ開発Akira Onishi
 
Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertionsphanleson
 
New Year PVS-Studio 6.00 Release: Scanning Roslyn
New Year PVS-Studio 6.00 Release: Scanning RoslynNew Year PVS-Studio 6.00 Release: Scanning Roslyn
New Year PVS-Studio 6.00 Release: Scanning RoslynPVS-Studio
 
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...Theo Jungeblut
 
Checking PVS-Studio with Clang
Checking PVS-Studio with ClangChecking PVS-Studio with Clang
Checking PVS-Studio with ClangAndrey Karpov
 
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...Andrey Karpov
 
Call Graph Agnostic Malware Indexing (EuskalHack 2017)
Call Graph Agnostic Malware Indexing (EuskalHack 2017)Call Graph Agnostic Malware Indexing (EuskalHack 2017)
Call Graph Agnostic Malware Indexing (EuskalHack 2017)Joxean Koret
 
A Closer Look at Real-World Patches
A Closer Look at Real-World PatchesA Closer Look at Real-World Patches
A Closer Look at Real-World PatchesDongsun Kim
 
How to Improve Visual C++ 2017 Libraries Using PVS-Studio
How to Improve Visual C++ 2017 Libraries Using PVS-StudioHow to Improve Visual C++ 2017 Libraries Using PVS-Studio
How to Improve Visual C++ 2017 Libraries Using PVS-StudioPVS-Studio
 
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-StudioAnalysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-StudioPVS-Studio
 
Espressif IoT Development Framework: 71 Shots in the Foot
Espressif IoT Development Framework: 71 Shots in the FootEspressif IoT Development Framework: 71 Shots in the Foot
Espressif IoT Development Framework: 71 Shots in the FootAndrey Karpov
 
Top 10 static code analysis tool
Top 10 static code analysis toolTop 10 static code analysis tool
Top 10 static code analysis toolscmGalaxy Inc
 
Errors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedErrors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedAndrey Karpov
 
PVS-Studio Has Finally Got to Boost
PVS-Studio Has Finally Got to BoostPVS-Studio Has Finally Got to Boost
PVS-Studio Has Finally Got to BoostAndrey Karpov
 
Reliability Patterns for Distributed Applications
Reliability Patterns for Distributed ApplicationsReliability Patterns for Distributed Applications
Reliability Patterns for Distributed ApplicationsAndrew Hamilton
 
Mining Fix Patterns for FindBugs Violations
Mining Fix Patterns for FindBugs ViolationsMining Fix Patterns for FindBugs Violations
Mining Fix Patterns for FindBugs ViolationsDongsun Kim
 
Week7 exception handling
Week7 exception handlingWeek7 exception handling
Week7 exception handlingAlpesh Oza
 

What's hot (20)

Code instrumentation
Code instrumentationCode instrumentation
Code instrumentation
 
ユニバーサル Windows アプリ開発
ユニバーサル Windows アプリ開発ユニバーサル Windows アプリ開発
ユニバーサル Windows アプリ開発
 
Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertions
 
New Year PVS-Studio 6.00 Release: Scanning Roslyn
New Year PVS-Studio 6.00 Release: Scanning RoslynNew Year PVS-Studio 6.00 Release: Scanning Roslyn
New Year PVS-Studio 6.00 Release: Scanning Roslyn
 
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
 
Checking PVS-Studio with Clang
Checking PVS-Studio with ClangChecking PVS-Studio with Clang
Checking PVS-Studio with Clang
 
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
 
Call Graph Agnostic Malware Indexing (EuskalHack 2017)
Call Graph Agnostic Malware Indexing (EuskalHack 2017)Call Graph Agnostic Malware Indexing (EuskalHack 2017)
Call Graph Agnostic Malware Indexing (EuskalHack 2017)
 
A Closer Look at Real-World Patches
A Closer Look at Real-World PatchesA Closer Look at Real-World Patches
A Closer Look at Real-World Patches
 
How to Improve Visual C++ 2017 Libraries Using PVS-Studio
How to Improve Visual C++ 2017 Libraries Using PVS-StudioHow to Improve Visual C++ 2017 Libraries Using PVS-Studio
How to Improve Visual C++ 2017 Libraries Using PVS-Studio
 
Lecture 20-21
Lecture 20-21Lecture 20-21
Lecture 20-21
 
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-StudioAnalysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
 
Espressif IoT Development Framework: 71 Shots in the Foot
Espressif IoT Development Framework: 71 Shots in the FootEspressif IoT Development Framework: 71 Shots in the Foot
Espressif IoT Development Framework: 71 Shots in the Foot
 
Top 10 static code analysis tool
Top 10 static code analysis toolTop 10 static code analysis tool
Top 10 static code analysis tool
 
Errors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedErrors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not used
 
PVS-Studio Has Finally Got to Boost
PVS-Studio Has Finally Got to BoostPVS-Studio Has Finally Got to Boost
PVS-Studio Has Finally Got to Boost
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Reliability Patterns for Distributed Applications
Reliability Patterns for Distributed ApplicationsReliability Patterns for Distributed Applications
Reliability Patterns for Distributed Applications
 
Mining Fix Patterns for FindBugs Violations
Mining Fix Patterns for FindBugs ViolationsMining Fix Patterns for FindBugs Violations
Mining Fix Patterns for FindBugs Violations
 
Week7 exception handling
Week7 exception handlingWeek7 exception handling
Week7 exception handling
 

Viewers also liked

Magento 2 View Layer Evolution
Magento 2 View Layer EvolutionMagento 2 View Layer Evolution
Magento 2 View Layer EvolutionSergii Shymko
 
Offshore directors - Are they untouchable?
Offshore directors - Are they untouchable? Offshore directors - Are they untouchable?
Offshore directors - Are they untouchable? bakerpartners
 
Socio-technical evolution and migration in the Ruby ecosystem
Socio-technical evolution and migration in the Ruby ecosystemSocio-technical evolution and migration in the Ruby ecosystem
Socio-technical evolution and migration in the Ruby ecosystemTom Mens
 
Conversion Conference 2015
Conversion Conference 2015Conversion Conference 2015
Conversion Conference 2015Theo van der Zee
 
Magento 2 Changes Overview
Magento 2 Changes OverviewMagento 2 Changes Overview
Magento 2 Changes OverviewSergii Shymko
 
Magento 2 Development Best Practices
Magento 2 Development Best PracticesMagento 2 Development Best Practices
Magento 2 Development Best PracticesBen Marks
 
Software Ecosystem Evolution. It's complex!
Software Ecosystem Evolution. It's complex!Software Ecosystem Evolution. It's complex!
Software Ecosystem Evolution. It's complex!Tom Mens
 
Keeping software development ecosystem healthy
Keeping software development ecosystem healthyKeeping software development ecosystem healthy
Keeping software development ecosystem healthyDainius Mezanskas
 
Git in the Enterprise: How to succeed at DevOps using Git and a monorepo
Git in the Enterprise: How to succeed at DevOps using Git and a monorepo Git in the Enterprise: How to succeed at DevOps using Git and a monorepo
Git in the Enterprise: How to succeed at DevOps using Git and a monorepo Perforce
 
Politica macreoeconomica e indicadores
Politica macreoeconomica e indicadoresPolitica macreoeconomica e indicadores
Politica macreoeconomica e indicadoresMariela Farfán
 
Dustin Black - Red Hat Storage Server Administration Deep Dive
Dustin Black - Red Hat Storage Server Administration Deep DiveDustin Black - Red Hat Storage Server Administration Deep Dive
Dustin Black - Red Hat Storage Server Administration Deep DiveGluster.org
 
20 Effective Ways to Involve and Support Employees During Organizational Change
20 Effective Ways to Involve and Support Employees During Organizational Change 20 Effective Ways to Involve and Support Employees During Organizational Change
20 Effective Ways to Involve and Support Employees During Organizational Change Catherine Adenle
 
21 Critical Questions to Ask before Change Management
21 Critical Questions to Ask before Change Management21 Critical Questions to Ask before Change Management
21 Critical Questions to Ask before Change ManagementCatherine Adenle
 

Viewers also liked (17)

Magento 2 View Layer Evolution
Magento 2 View Layer EvolutionMagento 2 View Layer Evolution
Magento 2 View Layer Evolution
 
Offshore directors - Are they untouchable?
Offshore directors - Are they untouchable? Offshore directors - Are they untouchable?
Offshore directors - Are they untouchable?
 
Socio-technical evolution and migration in the Ruby ecosystem
Socio-technical evolution and migration in the Ruby ecosystemSocio-technical evolution and migration in the Ruby ecosystem
Socio-technical evolution and migration in the Ruby ecosystem
 
Gluster d2
Gluster d2Gluster d2
Gluster d2
 
Conversion Conference 2015
Conversion Conference 2015Conversion Conference 2015
Conversion Conference 2015
 
Qcet launching pp
Qcet  launching ppQcet  launching pp
Qcet launching pp
 
03-Certificates
03-Certificates03-Certificates
03-Certificates
 
Etwinning
EtwinningEtwinning
Etwinning
 
Magento 2 Changes Overview
Magento 2 Changes OverviewMagento 2 Changes Overview
Magento 2 Changes Overview
 
Magento 2 Development Best Practices
Magento 2 Development Best PracticesMagento 2 Development Best Practices
Magento 2 Development Best Practices
 
Software Ecosystem Evolution. It's complex!
Software Ecosystem Evolution. It's complex!Software Ecosystem Evolution. It's complex!
Software Ecosystem Evolution. It's complex!
 
Keeping software development ecosystem healthy
Keeping software development ecosystem healthyKeeping software development ecosystem healthy
Keeping software development ecosystem healthy
 
Git in the Enterprise: How to succeed at DevOps using Git and a monorepo
Git in the Enterprise: How to succeed at DevOps using Git and a monorepo Git in the Enterprise: How to succeed at DevOps using Git and a monorepo
Git in the Enterprise: How to succeed at DevOps using Git and a monorepo
 
Politica macreoeconomica e indicadores
Politica macreoeconomica e indicadoresPolitica macreoeconomica e indicadores
Politica macreoeconomica e indicadores
 
Dustin Black - Red Hat Storage Server Administration Deep Dive
Dustin Black - Red Hat Storage Server Administration Deep DiveDustin Black - Red Hat Storage Server Administration Deep Dive
Dustin Black - Red Hat Storage Server Administration Deep Dive
 
20 Effective Ways to Involve and Support Employees During Organizational Change
20 Effective Ways to Involve and Support Employees During Organizational Change 20 Effective Ways to Involve and Support Employees During Organizational Change
20 Effective Ways to Involve and Support Employees During Organizational Change
 
21 Critical Questions to Ask before Change Management
21 Critical Questions to Ask before Change Management21 Critical Questions to Ask before Change Management
21 Critical Questions to Ask before Change Management
 

Similar to Production Debugging at Code Camp Philly

.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging TechniquesBala Subra
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notesWE-IT TUTORIALS
 
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...DevOpsDays Tel Aviv
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net FundamentalsLiquidHub
 
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01Camilo Alvarez Rivera
 
Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Stephan Chenette
 
powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonnettitude_labs
 
How to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindHow to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindAndreas Czakaj
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and DebuggingRich Helton
 
A client-side vulnerability under the microscope!
A client-side vulnerability under the microscope!A client-side vulnerability under the microscope!
A client-side vulnerability under the microscope!Nelson Brito
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet IntroductionWei Sun
 
The D language comes to help
The D language comes to helpThe D language comes to help
The D language comes to helpPVS-Studio
 
Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharingJames Hsieh
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Toolsgavhays
 
Applying Anti-Reversing Techniques to Machine Code
Applying Anti-Reversing Techniques to Machine CodeApplying Anti-Reversing Techniques to Machine Code
Applying Anti-Reversing Techniques to Machine CodeTeodoro Cipresso
 

Similar to Production Debugging at Code Camp Philly (20)

.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
Spug pt session2 - debuggingl
Spug pt session2 - debugginglSpug pt session2 - debuggingl
Spug pt session2 - debuggingl
 
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
How We Analyzed 1000 Dumps in One Day - Dina Goldshtein, Brightsource - DevOp...
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
 
Rootkit case
Rootkit caseRootkit case
Rootkit case
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
 
Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007
 
powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-london
 
How to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindHow to write clean & testable code without losing your mind
How to write clean & testable code without losing your mind
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and Debugging
 
A client-side vulnerability under the microscope!
A client-side vulnerability under the microscope!A client-side vulnerability under the microscope!
A client-side vulnerability under the microscope!
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet Introduction
 
The D language comes to help
The D language comes to helpThe D language comes to help
The D language comes to help
 
Surge2012
Surge2012Surge2012
Surge2012
 
Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharing
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Tools
 
Applying Anti-Reversing Techniques to Machine Code
Applying Anti-Reversing Techniques to Machine CodeApplying Anti-Reversing Techniques to Machine Code
Applying Anti-Reversing Techniques to Machine Code
 

Recently uploaded

AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 

Recently uploaded (20)

AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Production Debugging at Code Camp Philly

  • 1. An introduction to production debugging Brian Lyttle
  • 2. Help us make this even better! Thank our sponsors! This wouldn’t be possible without them. Please complete an online evaluation!
  • 3. About me Brian Lyttle Solution Architect at LiquidHub E-mail blyttle@liquidhub.com Interwebs @brianly on Twitter @brianly on Stack Overflow Blog infrequently at http://brianlyttle.com
  • 4. Agenda What is production debugging? Debugging fundamentals Monitoring and instrumentation Capturing crash information Common scenarios … all with a healthy number of examples Since this is an introductory talk I’m skipping: WinDbg, SOS, and ADPlus Native debugging
  • 5. Audience Production debugging is something that helps a lot of different people A lot of these tools and techniques are not known by many developers. If you ever get the opportunity, go to a Mark Russinovich talk. The IT guys will know of him.
  • 6. What is production debugging? Effectively any debugging you do once code has left the confines of a developer workstation. A variety of tools are required to investigate problems with: Resource usage Security or privilege violations Random crashing Bugs with 3rd party software Network failures Some consider it a “black art” only accessible to the alpha developers amongst us. As a discipline it requires you to learn more about the internals of your operating system, database etc.
  • 7. Why is this important? It will make your users and manager happy:) You will get home on time. Your relationship with operations will improve. As you do more of this, your knowledge of operating systems, databases etc. will improve. Eventually your thinking will change, and you become more proactive.
  • 8. Production debugging techniques Often it does not involve Visual Studio, or any other development environment. Active methods Production debuggers Tracing Protocol analysis Passive methods User reports Crash dumps Log files
  • 9. Intermediate language and metadata Your .NET (managed code) assemblies are compiled to IL which is similar to assembly language. Older platforms like C/C++, classic VB, and many other do not have the concept of IL or metadata. With managed code an executable contains IL plus type information (metadata). This metadata is useful for Intellisense, serializing objects, debugging, and many other things. An interesting property of metadata is that it can help with disassembling your .NET assembly back to C#.
  • 10. Exceptions decomposed Errors are supposed to be exceptional events within an application. So we have the System.Exception for conveying information about these errors. Provides a lot of important information: Stack trace Target site Custom message Inner exceptions (if any)
  • 11. Obfuscating exceptions Each exception provides evidence for the person debugging the code. Like any type of evidence it can be tainted. Only catch and work with exceptions you can handle. Don’t default to catching System.Exception. If you catch an exception and need to re-throw it, make sure to throw the original. Good Bad } catch (ArgumentException ex) { Log(ex.Message); throw; } } catch (Exception ex) { Log(ex.Message); throw ex; } } catch (Exception e) { Log(ex.Message); throw new Exception("", ex); } Logs the exception. Throws the original exception, nota new one.
  • 12. Debugging symbols You might have noticed that there are debug and release options in Visual Studio. If you build in debug mode then additional code to support the debugger, and symbol (.PDB) files are generated. In release mode an optimized version of your application is built. This might still create .PDB files. PDB files are called symbols. They map your executable code to the matching Visual Studio project. Example: line number information. Best practice - keep a copy of the PDB files for every build you release.
  • 13. Reading a stack trace Reading stack traces is a core skill for .NET developers. The lines shown below provide insight into what was happening. Debug Build Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero. at CCExample1.Program.Divide(Int32 op1, Int32 op2) in C:ode Camprojects CExample1CExample1rogram.cs:line 65 at CCExample1.Program.RunCode() in C:ode CamprojectsCExample1CExample 1rogram.cs:line 36 at CCExample1.Program.Main(String[] args) in C:ode CamprojectsCExample1 CExample1rogram.cs:line 14 3 2 1 Release Build Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero. at CCExample1.Program.RunCode() at CCExample1.Program.Main(String[] args) 2 1
  • 14. Log files Applications often have official and unofficial logs which you can mine for information. Windows examples: Event Viewer %windir%System32ogFiles %windir%ystem32bemogs %COMMONPROGRAMFILES%icrosoft Sharedeb server extensions2OGS %systemdrive%erfLogsbr />Temp directories (everyone can write there!) Applications might also log to their database, or to a directory under their user identity. Eg. C:sersrianlyppDataocaliagnostics On Linux look in /var/log.
  • 15.
  • 16. CPU
  • 18.
  • 23.
  • 24. Enter Task Manager Available on any Windows computer. Brent Ozar: a “check engine light” for your system. You get a high level view but a lot of interesting information is hidden by default. Special processes are not visible. Deeper info on Threads or other esoteric objects is not available. Resource Monitor is a useful partner for Task Manager on Vista/7. Fact: On Windows 2000 and earlier it can be plain wrong.
  • 25. Process Explorer Improves on the capabilities of Task Manager. Highlights Process activity. Hierarchical view. All the gritty details. See which individual Thread is doing all the work.
  • 26. Performance Monitor Process Explorer is good for spot checks, but you need something better to do background monitoring.
  • 27. Metrics Available CPU % Idle Time % User Time Performance Monitor data can be captured for later review with a Data Collector Set. Export data to Excel for later analysis. It is possible to create custom performance counters. Examples: User Login Cart empties Document uploads Memory Available Mbytes Paging File % Usage Disk Disk Reads/sec Disk Writes/sec Avg. Disk Queue Length Others % Time in GC ASP.NET Cache Total Misses Windows Workflows Executing Faxes Sent ;)
  • 28. Utilities * Used in the past week
  • 29. Protocol analysis Snoop on what the server or client are sending over the network. These tools should be used with care. It is possible to capture passwords and other sensitive data. Work with a network admin when you need to perform a capture in a corporate environment. It is easiest to debug HTTP services with one of the specialized tools.
  • 30. What is a crash dump? These are basically files containing information on the exception which caused the crash. Unhandled exceptions bubble up to the top-level of an application. Then .NET invokes it’s own default error handling. Luckily you can override this behavior and do some interesting things.
  • 31. Why generate crash dumps? Often users only know part of the story They don’t know how the application works Only a hard crash gets their full attention Small details get ignored along the way Good for fixing “broken windows” Management won’t let you work on the bits of an application that need some attention You need some metrics to take to your manager
  • 32. Windows Error Reporting Microsoft had a problem with buggy drivers making Windows bad. They needed to identify and fix this problem. End users weren’t much help so a technical solution was needed. WER was born and Microsoft were able to identify and resolve the top bugs.
  • 33. Crash dumps the hard way It is possible to write your own code to intercept an unhandled exception. Register for the event: AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler); Then write a single method to handle it: void ExceptionHandler(object sender, UnhandledExceptionEventArgs e) { // Do work... // Just make sure to quit! } Just make sure to close the application, and write some code to upload the crash dump. It’s a good job someone has done this for us.
  • 34. ELMAH makes it easy for ASP.NET ELMAH (Error Logging Modules and Handlers) is a free open source component. Features: Log to many common databases. Filter out certain error messages. Supports a wide variety of hosting scenarios. SharePoint supported in addition to Web Forms and ASP.NET MVC. Admin web pages. Steps: Add sectionGroup. Add httpHandler. Add httpModule. Configure output options
  • 35. Doing more with crash dumps Group by the Target Site and identify top exceptions. Dump the crash dump into your bug tracker and track the fix. FogBugz, CodeSmith Insight, Jira, and many other products have support.
  • 36. References Books Debugging Applications for Microsoft .NET 2.0 Windows Advanced .NET Debugging Advanced Windows Debugging Debug It! Microsoft Documentation Creating custom performance counters Windows Event Tracing Using Performance Monitor Monitoring with SQL Profiler Analyzing Network Data with Network Monitor Presentations Windows Sysinternals Primer: Process Explorer, Process Monitor, and More
  • 37. Thanks! Please complete an online evaluation! Prizes!