20
Production Debugging Ingo Rammer [email protected]

Production Debugging Ingo Rammer [email protected]

Embed Size (px)

Citation preview

Page 1: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

Production Debugging

Ingo [email protected]

Page 2: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

Ingo Rammer und

• Kleine Beratungsfirma für Softwareentwickler

• Unterstützung, Coaching und Beratung für Software-Architekten und -Entwickler– Architektur- und Code-Reviews– Prototypentwicklung und Architekturberatung– Coaching und Mentoring– Anwendungsoptimierung und Troubleshooting

• http://www.thinktecture.com• [email protected]

Page 3: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

… oder „Wenn nix mehr geht, geht doch noch was“

Page 4: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

Ziel dieser 75 Minuten

• Tools• Techniken• Links

• Gewissheit: Sie können das Problem lösen!

Page 5: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

Szenarien

• Applikationsfehler, die nicht ausreichend geloggt werden

• „Verschluckte“ Exceptions, die im Produktivbetrieb essentielle Infos vernichten

• Anwendungen, die sich „einfach so beenden“

• Memory Leaks in grafischen Applikationen und in Server-Anwendungen

• … und kein Visual Studio weit und breit

Page 6: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

Gemeinsamkeiten der Tools

• XCOPY – am Server muss nichts installiert werden• Kostenlos• Debugger kommen von Microsoft, Rest ist optional

Page 7: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

MDbg

• Managed Code Debugger• Nachfolger von cordbg (Common Object

Runtime Debugger)• Zwei unterschiedliche Versionen!

– MDBG im SDK • Supported

– „MDBG Sample“ als C# Quellcode• IL Disassembler• Grafische Oberfläche• Unsupported

Page 8: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

MDbg Kommandos

• ru -> Run (Starte Anwendung)• at -> Attach (Laufenden Prozess

debuggen)• g -> Go (Äquivalent von F5 in Visual

Studio)• lo -> Load Module (z.B. “LO ILDASM”)

• ca ex -> Catch Exceptions• w -> Wo bin ich? (Stack Trace)• t -> Thread-Liste• t <#> -> Thread auswählen (z.B. “t 3”)• p -> Print (Lokale Variable)

Page 9: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

MDbg bei verschluckten Exceptions

• Drag und Drop der EXE auf MDbg– Alternativ: Start von Mdbg, dann Verwendung von Run

oder Attach• ca ex (Catch Exceptions)• g (Go)• Sobald die Exception auftritt:

– w (Stack Trace)– g (Bei Bedarf: Go)

Page 10: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

WinDbg

• Low Level Debugger (auch Kernel Debugging)

• Kennt .NET nicht, sondern grundsätzlich nur unmanaged code

• Erweiterungsmodul SOS (Son Of Strike) erlaubt Zugriff auf interne .NET Datenstrukturen

• Relativ komplex, bietet aber wichtige Features:– Memory Leak Analyse („alle existierenden

Objekte“)– Analyse von Memory Dumps– Remote Debugging über TCP/IP (auch mit TCP

Forwardern als Relay-Stationen)

Page 11: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

WinDbg Grundlagen

• .loadby sos mscorlib -> lade SOS aus dem Verzeichnis, aus dem mscorlib

geladen wurde. Funktioniert erst, nachdem CLR im

Zielprozess initialisiert wurde!• G -> go (F5)• CTRL+BREAK -> Break• ~ -> Thread List• ~#s -> Thread Auswahl (z.B. ~4s)• !clrstack -> Stack Trace• !help [cmd] -> Liste der SOS Funktionen• .hh [cmd] -> Hilfe zu WinDbg Funktionen

Page 12: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

WinDbg und Exceptions

• WinDbg geht standardmässig bei einigen unmanaged Exceptions (Access Violations) in den Break-Modus

• SXE <event> -> Break• SXI <event> -> Ignorieren• SXN <event> -> Output

• SXE clr -> Break bei allen CLR Exceptions

• Wichtig: NullReferenceException, DivideByZero sind keine CLR Exceptions, sondern „normale“ unmanaged Exceptions

• SXE av -> Break bei Access Violation (Null Ref, default)• SXE dz -> Break bei Division durch Null (default)

Page 13: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

WinDbg und Speicherleaks

• WinDbg kennt .NET primär nicht und kann daher mehr sehen als ein .NET Debugger

• !dumpheap -> Alle geladenen Objekte• !gcroot -> Garbage Collection Pfade zu den Objekten• !do <adr> -> Dump Object• !da <adr> -> Dump Array• !dso -> Dump Stack Objects (nicht präzise)

• !dumpheap –stat• !dumpheap –type <klassenName>• !gcroot <objektAdresse>

• Interessant zusammen mit HawkEye zum Identifizieren der Klassennamen von GUI-Elementen

• .dump /ma c:\dumps\mydump.dmp -> Dump (/ma: mini dump mit “All” Option)

Page 14: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

Memory Dump Analyse

• ADPlus (Auto Dump Plus)– Erzeugt Memory Dumps sofort oder bei Exceptions

(allerdings nur unmanaged)– Dumps sind im Allgemeinen zwischen 40 und 500 MB

gross aber gut komprimierbar– Dumps beinhalten den gesamten Prozessspeicher und

mehr– Zum Beispiel auch Rekonstruktion der geladenen DLLs

und EXEs

Page 15: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

ADPlus

• C:\> adplus –hang –p <PID>• C:\> adplus –hang –pn <ProzessName>• C:\> adplus –crash –p <PID>

Page 16: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

Global Flags

• Tool in den Debugging Tools für Windows• Erlaubt das sofortige Starten eines Debuggers bei

Programmstart• Bei Services: „Interact with Desktop“ muss

aktiviert sein

Page 17: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

DumpGen und SOS Assist

• SOS Assist: Grafisches Tools für WinDbg• DumpGen: Erzeugung von Dumps

• Beide Tools: Kostenlos. In ständiger Entwicklung. Aktuell: Sehr frühe Preview Version

• Download nur für Teilnehmer unserer Debugging-Kurse oder Vorträge. Verteilung im Unternehmen ist natürlich ok.

• URL: http://www.thinktecture.com/SOSAssist

Page 18: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

Logging und LogViewer

• Alle API Zugriffe können von WinDbg geloggt werden– Parameter und Rückgabewerte

• !load logexts -> Lade Logging Erweiterung• !logm i * -> Inkludiere alle Module• !loge c:\logs -> Starte Log in c:\logs (Enable)• !logb f -> Flush des Log-Puffers• !logd -> Log Beenden (Disable)

• Betrachtung mit LogViewer (ebenfalls Debugging Tools für Windows)

Page 19: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

Downloads

• MDbg Sample – Google: „mdbg sample“

• WinDbg, CDB, GFlags– Google: „debugging tools for windows“

• Hawkeye – Google: hawkeye .net

Page 20: Production Debugging Ingo Rammer ingo.rammer@thinktecture.com

http://www.thinktecture.com/

[email protected]://blogs.thinktecture.com/ingo/

In-depth support and consulting for

software architects and developers

{ }