1 / 54

Mago Debugger Inner Workings

An implementation overview By Aldo Núñez. Mago Debugger Inner Workings. Mago Debugger. What is debugging? What is a debugger? What is Mago ? Execution Agent Expression Evaluator Symbol Reader Debug Engine D and the debugger. What is debugging?. Run/Attach Control Inspect Why?

ordell
Download Presentation

Mago Debugger Inner Workings

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An implementation overview By Aldo Núñez Mago DebuggerInner Workings

  2. Mago Debugger • What is debugging? • What is a debugger? • What is Mago? • Execution Agent • Expression Evaluator • Symbol Reader • Debug Engine • D and the debugger

  3. What is debugging? • Run/Attach • Control • Inspect • Why? • Find out the cause of a problem (bug)

  4. Run/Attach • Kick off a process • Attach to an already running process

  5. Control • Breakpoints • Stepping • Changing instruction pointer • Suspend and resume threads

  6. Inspect • Callstack • Loaded modules • Threads • Memory • Registers • Variables • Expressions

  7. Mago Debugger • What is debugging? • What is a debugger? • What is Mago? • Execution Agent • Expression Evaluator • Symbol Reader • Debug Engine • D and the debugger

  8. What is a debugger? • A process that runs, controls, and inspects another process • Special relationship between debugger and debuggee • System notifies debugger of events taking place in debuggee

  9. OS APIs v. Hardware

  10. Break and Run Mode

  11. A Windows Debugger Loop event ← WaitForDebugEvent( timeout ) if got event ContinueDebugEvent( event.pid,event.tid, DISCARD_EXCEPTION ) Until event.code = EXIT_PROCESS

  12. Debug Events • Start Process • Exit Process • Start Thread • Exit Thread • Load Module • Unload Module • Exception • Message

  13. Windows API for Debugging

  14. OS and HW Co-op (x86): Single Step

  15. OS and HW Co-op (x86): Breakpoint

  16. Mago Debugger • What is debugging? • What is a debugger? • What is Mago? • Execution Agent • Expression Evaluator • Symbol Reader • Debug Engine • D and the debugger

  17. What is Mago? • A debugger for D programs • A set of independent libraries • A Visual Studio plug-in

  18. History • Interest in debuggers since 2005 • Started September 2009 • Source code released August 2010 • Integrated into Visual D September 2010

  19. Libraries v. Visual Studio plug-in • Benefits to making separate components • Targeted testing • Mix and match for different purposes • Use with any shell program • Benefits to making VS plug-in • Well tested shell program already written • High level debug programming model

  20. What doesMago look like?

  21. Component Responsibilities

  22. Mago Debugger • What is debugging? • What is a debugger? • What is Mago? • Execution Agent • Expression Evaluator • Symbol Reader • Debug Engine • D and the debugger

  23. Execution Agent • Abstracts run, control, and inspection services • Built first to make it as solid as possible • Many APIs are locked to thread that started debuggee • Because of underlying Windows API

  24. Services • WaitForEvent,Continue from event • Launch, Terminate • Attach, Detach • Read, Write Memory • Set, Remove Breakpoint • Step, Cancel Step • Async Break

  25. Breakpoint Management • Software breakpoint abstraction • Hardware breakpoint abstraction • Breakpoint sharing • Resuming from breakpoint

  26. Breakpoint Lifecycle

  27. Multithreaded Single-Step • Stepping over a single instruction • Can easily step over most instructions with native single step (SS) • Others require setting a BP after the instruction • REP string instructions

  28. Single-step with SS

  29. Single-step with BP: Bad

  30. Single-step with BP: Good

  31. Steppers • State machines for complex stepping • In, Over, Out, Go/Resume • Instruction, Statement • Control low-level SS and BP • Receive notification of SS and BP events • Can be canceled

  32. Stepping Scenarios • Instruction steppers handle 18 scenarios • 3x Instruction type: (simple, call, REP) • 2x At a BP • 3x Movement: (Go, Step In, Step Over) • Range stepper uses instruction steppers over an address range • Step Out stepper runs to a BP at return address

  33. Example: Call Instruction, At BP

  34. Threading

  35. Mago Debugger • What is debugging? • What is a debugger? • What is Mago? • Execution Agent • Expression Evaluator • Symbol Reader • Debug Engine • D and the debugger

  36. Expression Evaluator • Evaluates D expressions • Input is textual expression • Output is a result value record • Declarations, symbols, and input values come from outside • IValueBinder, IDeclaration • Handles formatting values • Enumerates children of values • Based on DMD front end

  37. EE Data Flow

  38. EE Usage MakeTypeEnv( &typeEnv ); MakeNameTable( &nameTable ); ParseText( L”a[2] + 3”, typeEnv, nameTable, &expr ); expr->Bind( options, binder ); expr->Evaluate( options, binder, &result );

  39. Resulting Node Tree

  40. Mago Debugger • What is debugging? • What is a debugger? • What is Mago? • Execution Agent • Expression Evaluator • Symbol Reader • Debug Engine • D and the debugger

  41. Symbol Reader • Reads debug info for a program • Maps of source files to lines • Maps of source code lines to addresses • Functions – address and scopes • Symbols – name, type, value, storage • Types • Reads specific formats • Currently, CodeView 4.10, output by DMD

  42. Compare to DWARF CodeView DWARF Flexible Attributes: key-value Explicit base type definition Location expressions Compression Flatten tree Abbreviations Byte code for tables • Fixed record fields • Numeric constant compression • Common type encoding • Sorted symbols • Nested Lexical blocks

  43. CodeView Sample

  44. Mago Debugger • What is debugging? • What is a debugger? • What is Mago? • Execution Agent • Expression Evaluator • Symbol Reader • Debug Engine • D and the debugger

  45. Debug Engine • A plug-in to the VS Debugger package (vsdebug.dll) • Standalone DLL doesn’t depend on any other package • Expected to implement AD7 interface • Knows how to debug one kind of program • DEs are multiplexed during a debug session

  46. AD7 Interface • A programming model for debugging processes • Single-threaded calls from VS Debugger to DE • Simplifies design • COM interfaces • Debug Engine is a COM co-class

  47. Programming Model • IDebugEngine2 • IDebugThread2 • IDebugBoundBreakpoint2 • IDebugExpression2 • IDebugStackFrame2 • IDebugDisassemblyStream2 • IDebugEvent2

  48. Threading

  49. Mago Debugger • What is debugging? • What is a debugger? • What is Mago? • Execution Agent • Expression Evaluator • Symbol Reader • Debug Engine • D and the debugger

  50. D and the debugger • Rewrite in D eventually • Only EE and parts of DE know about D • EE Test input generated by D program • Expression and expected value • Uses compile-time reflection

More Related