Satisfy Your Technical Curiosity Hardcore Production Debugging Ingo Rammer

Slides:



Advertisements
Similar presentations
Advanced Troubleshooting with Debug Diagnostics on IIS 6
Advertisements

Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
WINDBG + SOS: CANNON &SHOTGUN you should include in your toolkit.
GROUP 2 WINDOWS INTERNALS TOOLS & WINDOWS SDK DEBUGGING TOOLS David Denhollander Kevin Finkler Corey Sarnia Ailun Shen.
How to use Sysinternals tools to troubleshoot SharePoint/Office
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
Chapter 14 Chapter 14: Server Monitoring and Optimization.
A New Soar Debugger in Java Douglas Pearson ThreePenny Software
DEV450 Visual Studio: Best Practices For Debugging Managed Applications Habib Heydarian Scott Nonnenberg Program Managers Microsoft Corporation.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Virtual techdays INDIA │ august 2010 Building ASP.NET applications using SQL Server Compact Chaitanya Solapurkar │ Partner Technical Consultant,
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Introduction Purpose Objectives Content Learning Time
Microsoft ® Official Course Monitoring and Troubleshooting Custom SharePoint Solutions SharePoint Practice Microsoft SharePoint 2013.
Logging, tracing, instrumentering, debugging og fejlfinding Instrumentation End-to-End Tracing Historical Debugging Semantic Logging.
CLR: Garbage Collection Inside Out
Min Kwan Park Test Tech Lead Visual C# QA team. Fail fast To-Dos for fail fast Analyze issues Information for further action Q&A Agenda.
2 Debugging Performance Issues, Memory Issues and Crashes in.net Applications Tess Ferrandez - Norlander Support Escalation Engineer Microsoft Session.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Creating and Running Your First C# Program Telerik Software Academy Telerik School Academy.
Parallel Programming in.NET 4.0 Tasks and Threading Ingo Rammer, thinktecture
W INDOWS BLUE SCREEN OF DEATH AFTER CRASH DEBUGGING Alex Mclean Amy Valley Derek Visch.
Debugging Print And Imaging Drivers. Print driver team philosophy on driver quality There are tools to detect violations Wrongful development assumptions.
Practical Malware Analysis Ch 8: Debugging Rev
Architecture of.NET Framework .NET Framework ٭ Microsoft.NET (pronounced “dot net”) is a software component that runs on the Windows operating.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
.NET Framework Danish Sami UG Lead.NetFoundry
Writing WinDbg Extensions
DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design
Introduction Purpose This training course covers debugging an application on an SH target in the Renesas HEW (High-performance Embedded Workshop) development.
Static Testing Code Review/Verification –Code is reviewed by the developer and others after each change (Wei/William look at each other’s stuff) –Reviewed.
MACCE and Real-Time Schedulers Steve Roberts EEL 6897.
SQL Server Crash Dump Analysis A brief tour with WinDbg and other ugly tools Pablo Álvarez Doval Debugging & Optimization Team Lead
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
Debugging and Profiling With some help from Software Carpentry resources.
A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.
Debugging Ensemble Productions CAMTA Meeting 11 th November 2010 John Murray.
Advanced Debugging with Visual Studio Ingo Rammer | thinktecture | Please note: this session is a „classic“
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Msdevcon.ru#msdevcon. ИЗ ПЕРВЫХ РУК: ДИАГНОСТИКА ПРИЛОЖЕНИЙ С ПОМОЩЮ ИНСТРУМЕНТОВ VISUAL STUDIO 2012 MAXIM GOLDIN Senior Developer, Microsoft.
. NET Debugging for the Production Environment Part 4: Common Debugging Commands Brad Linscott Premier Field Engineeringing.
Windows ® 2000 Debugging André Vachon Development Lead Windows Debuggers Microsoft Corporation.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
CS 177 Week 10 Recitation Slides 1 1 Debugging. Announcements 2 2.
Ladebug Kernel Debugging Tutorial Bob Lidral. Introduction Kinds of kernel debugging How to use Ladebug for kernel debugging Not how to debug a kernel.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
1 Advanced.Net Debugging Using Visual Studio, R# and OzCode IT Week, Summer 2015.
Discover, Master, InfluenceSlide 1 Debugging the World Starting with the CLR Corneliu I. Tusnea Senior Consultant, Readify It works on my machine!
Troubleshooting Workflow 8 Raymond Cruz, Software Support Engineer.
Active-HDL Server Farm Course 11. All materials updated on: September 30, 2004 Outline 1.Introduction 2.Advantages 3.Requirements 4.Installation 5.Architecture.
Garbage Collection It Is A Way To Destroy The Unused Objects. To do so, we were using free() function in C language and delete() in C++. But, in java it.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
What's New in Visual Studio 2010 Debugging Brian Peek Senior Consultant, ASPSOFT, Inc. Microsoft MVP - C#
 Wind River Systems, Inc Chapter - 4 CrossWind.
| © 2007 LenovoLenovo Confidential Use WinDBG Tool to Analyze BSOD —— Lenovo Service Support Training.
Hardcore Production Debugging of.NET Applications Ingo Rammer
Operating System Debugging Support and How Win32 Debuggers Work
Debugging and Handling Exceptions
Malware Incident Response  Dynamic Analysis - 2
CLR MD A New Swiss Army Knife tool for Advanced Debugging
.NET and .NET Core 2. .NET Runtimes Pan Wuming 2017.
CS360 Windows Programming
.NET Debugging for the Production Environment
Enhanced Security Testing- Do Automate Debuggers
Debugging tips and tricks
When your program crashes
Introduction to Windbg
Presentation transcript:

Satisfy Your Technical Curiosity Hardcore Production Debugging Ingo Rammer

Satisfy Your Technical Curiosity Ingo Rammer and Ingo Rammer and Support and consulting for software architects and developers Application Optimization and Tuning Developer-Coaching and -Mentoring Architecture and Code Reviews Prototyping and Architectural Consulting

Satisfy Your Technical Curiosity Today Toolchest WinDbg/CDB + SOS Mdbg + MdbgSample ADPlusGFlagsLogViewer SOS Assist & DumpGen Hawkeye

Satisfy Your Technical Curiosity Today Processes Tracing.NET memory leaks API Call Logging KD and WinDbg to trace sync elements (mutex) Programmatically creating memory dumps Remote debugging with WinDbg Service debugging with WinDbg and Gflags Catching CLR Exceptions in WinDbg And more … Scenarios

Satisfy Your Technical Curiosity XCOPY Tools XCOPY – you don‘t have to install anything on a server Definitely not Visual Studio All tools are free Debuggers are from Microsoft, rest is optional  Easy to put it on most machines even in restrictive environments I carry them on a USB stick Note: Rest of the slides are mainly for your reference. We‘ll now switch to the tools!

Satisfy Your Technical Curiosity MDbg Managed Code Debugger Successor of cordbg (Common Object Runtime Debugger) Two different version! MDBG in the SDK Supported „MDBG Sample“ as C# Source IL Disassembly GUI Unsupported, but that’s the MDbg you want!

Satisfy Your Technical Curiosity MDbg Commands ru -> Run Application at -> Attach to running process g -> Go (Like F5 in Visual Studio) lo -> Load Module (“LO ILDASM”) ca ex -> Catch Exceptions w -> Where am I? (Stack Trace) t -> Thread-List t -> Thread selection (“t 3”) p -> Print (local variable)

Satisfy Your Technical Curiosity MDbg with swallowed Exceptions Drag and Drop of the EXE to MDbg Or: start Mdbg and use Run or Attach ca ex (Catch Exceptions) g (Go) When the exception is caught: w (Stack Trace) g(If needed: Go to continue)

Satisfy Your Technical Curiosity WinDbg Low Level Debugger (also Kernel Debugging) Doesn‘t know about.NET, only unmanaged code Extension module SOS (Son Of Strike) gives access to internal.NET data structures Quite complex, but extremely powerful: Memory leak analysis (all existing objects) Analysis of memory dumps Remote debugging over TCP/IP (also with TCP forwarder as relay)

Satisfy Your Technical Curiosity WinDbg Fundamentals.loadby sos mscorlib -> load SOS from the directory, from which mscorlib has been loaded. Only works *after* CLR has been initialized in the debuggee. G -> go (F5) CTRL+BREAK -> Break ~ -> Thread list ~#s-> Thread selection (z.B. ~4s) !clrstack -> Stack trace !help [cmd]-> List of SOS commands.hh [cmd]-> Help for WinDbg commands q-> Quit qd-> Quit, but detach first

Satisfy Your Technical Curiosity WinDbg and Exceptions WinDbg by default breaks at a few unmanaged exceptions (like Access Violations) SXE -> Break SXI -> Ignore SXN -> Output SXE clr -> Break on all CLR Exceptions Important: NullReferenceException, DivideByZero are not CLR Exceptions, but regular unmanaged Exceptions SXE av-> Break at Access Violation (null ref, default) SXE dz-> Break at Divide by Zero (default)

Satisfy Your Technical Curiosity WinDbg and Memory Leaks WinDbg doesn‘t know about.NET and can therefore see more than any managed code debugger !dumpheap -> All existing objects (reachable or not!) !gcroot -> garbage collection paths to an object !do -> Dump object !da -> Dump array !dso-> Dump stack objects (not precise, but very important) !dumpheap –stat !dumpheap –type !dumpheap –type !gcroot !gcroot Use together with HawkEye, to identify the class name of GUI elements.dump /ma c:\dumps\mydump.dmp -> Dump (/ma: mini dump with “All” option)

Satisfy Your Technical Curiosity Memory Dump Analysis ADPlus (Auto Dump Plus) Creates memory dumps immediately or when a certain event (unmanaged) happens Dumps can be multiple 100 MBs in size, but can usually be ZIPped quite nicely Dumps contain the complete process memory and more (handle information) Also allow reconstruction of all loaded DLLs and EXEs

Satisfy Your Technical Curiosity ADPlus C:\> adplus –hang –p C:\> adplus –hang –p C:\> adplus –hang –pn C:\> adplus –hang –pn C:\> adplus –crash –p C:\> adplus –crash –p

Satisfy Your Technical Curiosity Global Flags (Gflags.exe) Tool of Debugging Tools for Windows Allows the immediate start of a debugger when an application starts For services: Interact with Desktop has to be activated if debugger is running as frontend You can use local remote debugging if this is not desirable

Satisfy Your Technical Curiosity KD.EXE Kernel debugging for.NET applications … well? Find out about blocking situation regarding Kernel sync elements Important: current symbols! C:\> mkdir c:\symbols C:\> set _NT_SYMBOL_PATH=SRV*C:\symbols*

Satisfy Your Technical Curiosity KD for kernel sync constructs Command: !process (  not PID!) C:\> KD /kl (  local Kernel debugging) lkd> !process 0 0 (  basic information about all processes of this name) PROCESS 8900e020 SessionId: 0 Cid: 1cd0 Peb: 7ffde000 ParentCid: 12a0 lkd> !process 8900e020 2 (  2: thread information with locks) THREAD 89d86da8 Cid 1cd0.1ba0 Teb: 7ffda000 Win32Thread: WAIT: (DelayExecution) UserMode Alertable 89d86e98 NotificationTimer THREAD 87ba5020 Cid 1cd0.17e0 Teb: 7ffd6000 Win32Thread: WAIT: (UserRequest) UserMode Alertable 89d48fc0 Mutant - owning thread 89d86da8 THREAD Cid 1cd0.1d88 Teb: 7ffad000 Win32Thread: WAIT: (UserRequest) UserMode Alertable 89d48fc0 Mutant - owning thread 89d86da8 In WinDbg/SOS: use Cid from KD to match !threads command‘s OSID column to find the offending thread

Satisfy Your Technical Curiosity Creating memory dumps DbgHelp.dll of the Debugging Tools for Windows is redistributable [DllImport("DbgHelp.dll", SetLastError=true)] private static extern bool MiniDumpWriteDump( IntPtr hProcess, int processId, IntPtr fileHandle, int dumpType, IntPtr excepInfo, IntPtr userInfo, IntPtr extInfo); public static void CreateMiniDump(int pid, string outputFileName) { using (FileStream stream = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite)) { using (Process proc = Process.GetProcessById(pid)) { int dumpType = (int)0x ; MiniDumpWriteDump(proc.Handle, proc.Id, stream.Handle, dumpType, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); }

Satisfy Your Technical Curiosity Remote Debugging with WinDbg WinDbg/CDB can be started to act as a server and will listen on a TCP endpoint for commands CDB -server tcp:port=1234 CDB -server tcp:port=1234 WinDbg –remote tcp:server=localhost,port=1234 Or: WinDbg menu File  Connect to Remote Session Can also be used with Gflags! Warning: there is no built-in security

Satisfy Your Technical Curiosity Stopping on CLR Exceptions Note: the currently public versions of SOS.DLL expose critical memory leaks which consume a few MB of RAM for each CLR exception which is running through a filter like the following (even if the filter is NOT triggered) !StopOnException –create System.IO.DirectoryNotFoundException 1

Satisfy Your Technical Curiosity

Downloads MDbg Sample Google: „mdbg sample“ WinDbg, CDB, GFlags Google: „debugging tools for windows“ Hawkeye Google: hawkeye.net

Satisfy Your Technical Curiosity