An implementation overview By Aldo Núñez.  What is debugging?  What is a debugger?  What is Mago?  Execution Agent  Expression Evaluator  Symbol.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Intermediate Code Generation
Xtensa C and C++ Compiler Ding-Kai Chen
Programming Languages and Paradigms
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
DEV300: A Tiny CPU and OS in C# Scott Hanselman Technology Evangelist/Architect Corillian Corporation
Programming Languages and Paradigms The C Programming Language.
1 Compiler Construction Intermediate Code Generation.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Introduction to Code Generation Mooly Sagiv html:// Chapter 4.
Tentative Schedule 20/12 Interpreter+ Code Generation 27/12 Code Generation for Control Flow 3/1 Activation Records 10/1 Program Analysis 17/1 Register.
History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow 
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
VB in Context Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh Pittsburgh, Pa 15260
Introduction to Code Generation Mooly Sagiv html:// Chapter 4.
Chapter 6 Implementing Processes, Threads, and Resources.
OllyDbg Debuger.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
ECE 265 – LECTURE 9 PROGRAM DESIGN 8/12/ ECE265.
Chapter 2 Software Tools and Assembly Language Syntax.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
Main sponsor PicassoMonet + RembrandtMatejko + Canaletto How Debuggers Work Karl Rehmer Failures Come in Flavors Michael Nygard REST in Java Stefan Tilkov.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Compiler Construction
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Module 6: Debugging a Windows CE Image.  Overview Debug Zones IDE Debug Setup IDE Debug Commands Platform Builder Integrated Kernel Debugger Other Debugging.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
C LANGUAGE Characteristics of C · Small size
ECE 526 – Network Processing Systems Design Microengine Programming Chapter 23: D. E. Comer.
What is a Process ? A program in execution.
CSC 1201 LAB RULES Nouf Aljaffan (C) CSC 1201 Course at KSU.
Introduction Ken Ryall – Nokia Warren Paul – Nokia Daymon Rogers – Freescale John Cortell - Freescale.
Visual Programming Borland Delphi. Developing Applications Borland Delphi is an object-oriented, visual programming environment to develop 32-bit applications.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Operating System Debugging Support and How Win32 Debuggers Work
LESSON 06.
Names and Attributes Names are a key programming language feature
CS1101X Programming Methodology
Programming Languages and Paradigms
Debugging with gdb gdb is the GNU debugger on our CS machines.
Operating Systems: A Modern Perspective, Chapter 6
LESSON 20.
Programming Paradigms
Introduction to C Programming Language
Stacks Chapter 4.
The HP OpenVMS Itanium® Calling Standard
CS360 Windows Programming
Introduction to the C Language
Module 6: Debugging a Windows CE Image
Implementing Processes, Threads, and Resources
Programming Languages and Paradigms
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

An implementation overview By Aldo Núñez

 What is debugging?  What is a debugger?  What is Mago?  Execution Agent  Expression Evaluator  Symbol Reader  Debug Engine  D and the debugger

 Run/Attach  Control  Inspect  Why?  Find out the cause of a problem (bug)

 Kick off a process  Attach to an already running process

 Breakpoints  Stepping  Changing instruction pointer  Suspend and resume threads

 Callstack  Loaded modules  Threads  Memory  Registers  Variables  Expressions

 What is debugging?  What is a debugger?  What is Mago?  Execution Agent  Expression Evaluator  Symbol Reader  Debug Engine  D and the 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

OS Debug events Break/Run mode Change state HW Single Step Breakpoints Registers

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

 Start Process  Exit Process  Start Thread  Exit Thread  Load Module  Unload Module  Exception  Message

Debug Events WaitForDebugEvent ContinueDebugEvent Launch CreateProcess TerminateProcess Attach DebugActiveProcess DebugActiveProcessStop Registers GetThreadContext SetThreadContext Memory ReadProcessMemory WriteProcessMemory Threads SuspendThread ResumeThread

Enable SS GetThreadContext context.Eflags or 0x100 SetThreadContext ContinueDebugEvent SS Event event ← WaitForEvent event.code = EXCEPTION event.exception.code = EXCEPTION_SINGLE_STEP

Enable BP ReadProcessMemory WriteProcessMemory data = 0xCC (int 3) FlushInstructionCache ContinueDebugEvent BP Event event ← WaitForEvent event.code = EXCEPTION event.exception.code = EXCEPTION_BREAKPOINT Except. address = original EIP = original + 1

 What is debugging?  What is a debugger?  What is Mago?  Execution Agent  Expression Evaluator  Symbol Reader  Debug Engine  D and the debugger

 A debugger for D programs  A set of independent libraries  A Visual Studio plug-in

 Interest in debuggers since 2005  Started September 2009  Source code released August 2010  Integrated into Visual D September 2010

 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

Debug EngineExecExprSyms

Exec Control debuggee Read and change state Expr Evaluate D Expressions Formatting Syms Read debug info DE Combine other components Expose AD7 interface

 What is debugging?  What is a debugger?  What is Mago?  Execution Agent  Expression Evaluator  Symbol Reader  Debug Engine  D and the debugger

 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

 WaitForEvent, Continue from event  Launch, Terminate  Attach, Detach  Read, Write Memory  Set, Remove Breakpoint  Step, Cancel Step  Async Break

 Software breakpoint abstraction  Hardware breakpoint abstraction  Breakpoint sharing  Resuming from breakpoint

 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

 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

 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

 What is debugging?  What is a debugger?  What is Mago?  Execution Agent  Expression Evaluator  Symbol Reader  Debug Engine  D and the debugger

 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

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

 What is debugging?  What is a debugger?  What is Mago?  Execution Agent  Expression Evaluator  Symbol Reader  Debug Engine  D and the debugger

 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

CODEVIEW  Fixed record fields  Numeric constant compression  Common type encoding  Sorted symbols  Nested Lexical blocks DWARF  Flexible  Attributes: key-value  Explicit base type definition  Location expressions  Compression  Flatten tree  Abbreviations  Byte code for tables

 What is debugging?  What is a debugger?  What is Mago?  Execution Agent  Expression Evaluator  Symbol Reader  Debug Engine  D and the debugger

 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

 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

 IDebugEngine2  IDebugThread2  IDebugBoundBreakpoint2  IDebugExpression2  IDebugStackFrame2  IDebugDisassemblyStream2  IDebugEvent2

 What is debugging?  What is a debugger?  What is Mago?  Execution Agent  Expression Evaluator  Symbol Reader  Debug Engine  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

void main( string[] args ) { writeln( " " ); if ( set == 1 ) UnaryList!(byte, ubyte, short, ushort, int, uint, long, ulong).Operation( op ); else if ( set == 2 ) UnaryList!(float, double, real, ifloat, idouble, ireal, cfloat, cdouble, creal).Operation( op ); writeln( " " ); } template Unary(T) { void Unary( void function( T ) func ) { foreach ( t; Vals!T.vals ) { Id++; writefln( " ", Prefix, Id ); func( t ); writefln( " " ); } template UnaryList(T...) { void Operation( Op op ) { foreach ( t; T ) { switch ( op ) { case Op.Negate: Unary!(t)(&UnOp!(t).Negate); break; case Op.BitNot: static if (__traits( compiles, Unary!(t)( &UnOp!(t).BitNot ))) Unary!(t)( &UnOp!(t).BitNot ); break; } template Vals(T) { static T[] vals; static this() { static if ( !__traits( isFloating, T ) ) // Add values like T.max, cast(T) -1, cast(T) 0 else // Add values like T.nan, -T.infinity, cast(T) 0 }

template UnOp(T) { static if ( __traits( isIntegral, T ) ) void BitNot( T t ) { writeln( " " ); CastTerm( t ); writeln( " " ); PrintType!(typeof( ~t ))(); PrintTerm( ~t ); writeln( " " ); } void PrintType(X)() { static if ( __traits( isArithmetic, X ) ) writefln( " ", typeid( X ) ); else writefln( " ", typeid( X ) ); } void CastTerm(X)( X x ) { writeln( " " ); PrintType!X(); PrintTerm( x ); writeln( " " ); } void PrintTerm(X)( X x ) { static if ( is(X==creal) || is(X==cdouble) || is(X==cfloat) ) { writeln( " " ); writefln( " ", x.re ); writefln( " ", x.im ); writeln( " " ); } else if ( is( X == ireal ) || is( X == idouble ) || is( X == ifloat ) ) { writefln( " ", x ); } else if ( __traits( isFloating, X ) ) { writefln( " ", x ); } else if ( is( X == ulong ) || (is( X == long ) && (x < 0)) ) { writefln( " ", x ); } else writefln( " ", x ); }

 Interface for sharing between modules  Take DMD front end or mimic it  80-bit floating point in expression eval  Disassembling variable length instructions

 Mago:  D:  Visual D IDE by Rainer Schuetze:  Visual Studio Debugger Extensibility: us/library/bb aspx us/library/bb aspx  x86 and x64 Manuals:  DWARF Format: