Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode

Similar documents
Streams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson

CS 360 Programming Languages Interpreters

Before you start with this tutorial, you need to know basic Java programming.

CS61A Midterm 2 Review (v1.1)

6.001, Spring Semester, 1998, Final Exam Solutions Your Name: 2 Part c: The procedure eval-until: (define (eval-until exp env) (let ((return (eval-seq

Functional Programming. Pure Functional Programming

Lexical vs. Dynamic Scope

Parsing Scheme (+ (* 2 3) 1) * 1

Below are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.

Debugging Scheme Fair Threads

Project 2: Scheme Interpreter

02/03/15. Compile, execute, debugging THE ECLIPSE PLATFORM. Blanks'distribu.on' Ques+ons'with'no'answer' 10" 9" 8" No."of"students"vs."no.

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Method-Level Phase Behavior in Java Workloads

Ways to implement a language

4.2 Variations on a Scheme -- Lazy Evaluation

CIS4/681 { Articial Intelligence 2 > (insert-sort '( )) ( ) 2 More Complicated Recursion So far everything we have dened requires

6.037 Lecture 7B. Scheme Variants Normal Order Lazy Evaluation Streams

Testing Reactive Programs. Designing Programmable debugger easily

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

Zing Vision. Answering your toughest production Java performance questions

<Insert Picture Here> Multi-language JDI? You're Joking, Right?

CS558 Programming Languages

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I

Introduction to IntelliJ

Managed runtimes & garbage collection. CSE 6341 Some slides by Kathryn McKinley

CSc 520 Principles of Programming Languages

JDB - QUICK GUIDE JDB - INTRODUCTION

High-Level Language VMs

Managed runtimes & garbage collection

Fall Semester, The Metacircular Evaluator. Today we shift perspective from that of a user of computer langugaes to that of a designer of

JazzScheme: Evolution of a Lisp-Based Development System. Guillaume Cartier Louis-Julien Guillemette SFP 2010

A Brief Introduction to Scheme (II)

Sample Final Exam Questions

Documentation for LISP in BASIC

LECTURE 16. Functional Programming

Environments

CS558 Programming Languages

6.037 Lecture 4. Interpretation. What is an interpreter? Why do we need an interpreter? Stages of an interpreter. Role of each part of the interpreter

CS558 Programming Languages

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler

Dispatch techniques and closure representations

Lecture 16: Object Programming Languages

6.001, Fall Semester, 1998 Lecture Notes, October 27 { Object Oriented Programming 2 An environment diagram illustrating +define foo +cons 1 2,, +set-

Comp 311: Sample Midterm Examination

Normal Order (Lazy) Evaluation SICP. Applicative Order vs. Normal (Lazy) Order. Applicative vs. Normal? How can we implement lazy evaluation?

Operating- System Structures

Symbolic Computation and Common Lisp

psd: A Scheme Debugger An Example

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

COP4020 Programming Assignment 1 - Spring 2011

Procedural abstraction SICP Data abstractions. The universe of procedures forsqrt. Procedural abstraction example: sqrt

Vectors in Scheme. Data Structures in Scheme

MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science. Issued: Wed. 26 April 2017 Due: Wed.

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree.

JScheme : A Scheme Interpreter Embedded Within Java Source Code

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

A LISP Interpreter in ML

Lecture #24: Programming Languages and Programs

C311 Lab #3 Representation Independence: Representation Independent Interpreters

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

Lab 3-2: Exploring the Heap

A Design for Comprehensive Kernel Instrumentation

JAVA PERFORMANCE. PR SW2 S18 Dr. Prähofer DI Leopoldseder

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Debugging in AnyLogic. Nathaniel Osgood CMPT

Glacier: A Garbage Collection Simulation System

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

Under the Hood: The Java Virtual Machine. Lecture 23 CS2110 Fall 2008

Contents in Detail. Who This Book Is For... xx Using Ruby to Test Itself... xx Which Implementation of Ruby?... xxi Overview...

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides

PICOBIT: A Compact Scheme System for Microcontrollers

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Understanding Memory Allocation of Scheme Programs

JCreator. Starting JCreator

CS251 Programming Languages Handout # 47 Prof. Lyn Turbak May 22, 2005 Wellesley College. Scheme

Inheritance: Develop solutions by abstracting real-world object and their interaction into code to develop software solutions. Layering: Organization

Software Project Seminar VII: Tools of the Craft. 23 march 2006 Jevgeni Kabanov

Research compiler that will become Scala 3 Type system internals redesigned, inspired by DOT, but externally very similar More info:

A verified runtime for a verified theorem prover

Why do we need an interpreter? SICP Interpretation part 1. Role of each part of the interpreter. 1. Arithmetic calculator.

Software Engineering

Chapter 1 Getting Started

Reliable programming

Notes of the course - Advanced Programming. Barbara Russo

Short Notes of CS201

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

(scheme-1) has lambda but NOT define

Compiling Techniques

CS201 - Introduction to Programming Glossary By

Project 5 - The Meta-Circular Evaluator

In Java we have the keyword null, which is the value of an uninitialized reference type

An Implementation of Python for Racket. Pedro Palma Ramos António Menezes Leitão

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89

Introduction to Problem Solving and Programming in Python.

More Scheme CS 331. Quiz. 4. What is the length of the list (()()()())? Which element does (car (cdr (x y z))) extract from the list?

Transcription:

Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode Damien Ciabrini Manuel Serrano firstname.lastname@sophia.inria.fr INRIA Sophia Antipolis 2004 route des Lucioles - BP 93 F-06902 Sophia Antipolis, Cedex

Outline Introduction The Bugloo debugger Custom debugging features JVM debugging architecture Mapping Scheme to JVM Performances Conclusion Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.1/20

Introduction Debugging programs: to detect, to locate and to corrects errors Two kinds of debuggers: static debuggers dynamic debuggers Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.2/20

Motivation of our Work Programmers hardly use debuggers: sometimes not efficient enough not adapted to correct certain bugs "prints are simpler and quicker" How to make debuggers more attractive? Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.3/20

Motivation of our Work Programmers hardly use debuggers: sometimes not efficient enough not adapted to correct certain bugs "prints are simpler and quicker" How to make debuggers more attractive? easily accessible from the IDE acceptable performance slowndown to deal with the language specificities Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.3/20

Context of Development Work with the Bigloo Scheme compiler: Scheme C. Already has a debugger. Scheme JVM bytecode. JVM provides JPDA. JVM Platform Debugging Architecture (JPDA): A set of APIs to make debugger and profilers Standardized portability across JVMs JIT can limit performances slowdown Same classfile for normal or debug executions Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.4/20

The Bugloo Debugger Bugloo is a source level debugger : Operates on compiled Bigloo programs Basic instrumentation of the debuggee : breakpoints, stack and variables inspection Advanced debugging features Traces, memo-conditions, memory debugging Controled by a command language Integrated into the Emacs editor Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.5/20

Emacs Environment (1/2) Source buffers: Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.6/20

Emacs Environment (1/2) Source buffers: Breakpoints list Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.6/20

Emacs Environment (1/2) Source buffers: Breakpoints list Execution State: Debuggee inspection Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.6/20

Emacs Environment (1/2) Source buffers: Breakpoints list Execution State: Debuggee inspection Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.6/20

Emacs Environment (1/2) Source buffers: Breakpoints list Execution State: Debuggee inspection Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.6/20

Emacs Environment (1/2) Source buffers: Breakpoints list Execution State: Debuggee inspection Hyperlink configuration Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.6/20

Emacs Environment (2/2) Source path repository: Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.7/20

Emacs Environment (2/2) Source path repository: Where to look for sources Customization à la Emacs Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.7/20

Emacs Environment (2/2) Source path repository: Where to look for sources Customization à la Emacs Command line buffer: Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.7/20

Emacs Environment (2/2) Source path repository: Where to look for sources Customization à la Emacs Command line buffer: Manual interactions For advanced features Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.7/20

Custom Debug Features Events recording Trace of function calls Eval code at run-time Memo-breakpoints Memory Debugging Back references paths Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.8/20

Event Recording All events that occur during a debug session: History of user commands Simple replay mechanism Traces of debuggee events Variable accesses, functions calls Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.9/20

Event Recording - example 1: (define (go args) 2: (my-map (lambda (x) (+ x 1)) (1 2))) 3: 4: (define (my-map f l) 5: (if (null? l) 6: () 7: (cons (f (car l)) (my-map f (cdr l))))) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.10/20

Event Recording - example 1: (define (go args) 2: (my-map (lambda (x) (+ x 1)) (1 2))) 3: 4: (define (my-map f l) 5: (if (null? l) 6: () 7: (cons (f (car l)) (my-map f (cdr l))))) (bugloo) (info stack) #0 (my-map ::procedure ::obj) in file trace.scm:6 #1 (my-map ::procedure ::obj) in file trace.scm:7 #2 (my-map ::procedure ::obj) in file trace.scm:7 #3 (go ::pair) in file trace.scm:2 Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.10/20

Event Recording - example 1: (define (go args) 2: (my-map (lambda (x) (+ x 1)) (1 2))) 3: 4: (define (my-map f l) 5: (if (null? l) 6: () 7: (cons (f (car l)) (my-map f (cdr l))))) (bugloo) (trace list). (go ::pair) in file trace.scm:2. (my-map ::procedure ::obj) in file trace.scm:4. (<lambda:2> ::obj) in file trace.scm:2. (my-map ::procedure ::obj) in file trace.scm:4. (<lambda:2> ::obj) in file trace.scm:2. (my-map ::procedure ::obj) in file trace.scm:4 Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.10/20

Eval code at runtime Bugloo uses the built-in Scheme interpreter Debugger: eval arbitrary S-exp Debuggee: conditional breakpoints In Bugloo, a condition is a lambda Various usage: insert code without recompiling a closure is a memo-condition Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.11/20

Eval code at runtime - example 1: (define (mouse-click-handler e::int) 2: (cond 3: ((= e 1) (print "Button 1 pressed")) 4: ((= e 2) (print "Button 2 pressed")) 5: (else (print "never mind")))) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.12/20

Eval code at runtime - example 1: (define (mouse-click-handler e::int) 2: (cond 3: ((= e 1) (print "Button 1 pressed")) 4: ((= e 2) (print "Button 2 pressed")) 5: (else (print "never mind")))) (let ((but2-ok #f)) (lambda (env) (cond ((and (= (dbg env e) 1) but2-ok) (set! but2-ok #f) #t) ((= (dbg env e) 2) (set! but2-ok #t))))) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.12/20

Memory Debugging Scheme provides a GC Not sufficient to avoid memory leaks! Services provided by Bugloo: Heap inspector To monitor memory consumption Incoming references To exhibit sharing properties Back references path Which GC root is responsible of a leak Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.13/20

Memory Debugging - example 1: (module leak2 2: (export (class ast-node 3: type::symbol 4: value::obj)) 5: (main compile)) 6: 7: (define *nodes-cache* (make-hashtable)) 8: 9: (define (compile args) 10: (let ((obj (file->ast (car args)))) 11: (set! obj (ast->il obj)) 12: (set! obj (il->bytecode obj)) 13: (bytecode->file obj (cadr args)))) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.14/20

Memory Debugging - example (bugloo) (gc) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.15/20

Memory Debugging - example (bugloo) (gc) (bugloo) (info heap "::") ::ast-node => 29988 instances ::leak2 => 11 instances ::pair => 91109 instances ::struct => 1 instance ::bint => 25982 instances ::nil => 1 instance ::procedure => 1 instance ::symbol => 800 instances ::cell => 3 instances ::eof => 1 instance ::key => 1 instance ::nil => 1 instance ::unspecified => 1 instance 5137224 bytes used. (0.929s) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.15/20

Memory Debugging - example (bugloo) (gc) (bugloo) (heap get "::ast-node" 0) (bugloo) (info heap "::") ::ast-node => 29988 instances ::leak2 => 11 instances ::pair => 91109 instances ::struct => 1 instance ::bint => 25982 instances ::nil => 1 instance ::procedure => 1 instance ::symbol => 800 instances ::cell => 3 instances ::eof => 1 instance ::key => 1 instance ::nil => 1 instance ::unspecified => 1 instance 5137224 bytes used. (0.929s) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.15/20

Memory Debugging - example (bugloo) (gc) (bugloo) (info heap "::") ::ast-node => 29988 instances ::leak2 => 11 instances ::pair => 91109 instances ::struct => 1 instance ::bint => 25982 instances ::nil => 1 instance ::procedure => 1 instance ::symbol => 800 instances ::cell => 3 instances ::eof => 1 instance ::key => 1 instance ::nil => 1 instance ::unspecified => 1 instance 5137224 bytes used. (0.929s) (bugloo) (heap get "::ast-node" 0) (bugloo) (backref %obj%) #0 ::ast-node field car #1 ::pair field car #2 ::pair at index 4082 #3 ::vector at index 2 #4 ::vector field values #5 ::struct ====> *nodes-cache* command took 0.743s. Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.15/20

JVM Debugging Architecture Debugging with two JVMs JVMDI: instrumentation JDI: control (Java) Event-driven Communication Manipulation of stubs JDWP abstract channel Embed code in the debuggee conditional breakpoints memory debugging JVM Debuggee Debugger JVM JVMDI JVMPI JDWP JDI Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.16/20

Mapping Scheme To JVM (1/2) Bigloo directly maps into JVM: modules classes functions methods Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.17/20

Mapping Scheme To JVM (1/2) Bigloo directly maps into JVM: modules classes functions methods Proper display of Bigloo objects: Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.17/20

Mapping Scheme To JVM (1/2) Bigloo directly maps into JVM: modules classes functions methods Proper display of Bigloo objects: Normal display: f (::procedure) = #<procedure:1> Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.17/20

Mapping Scheme To JVM (1/2) Bigloo directly maps into JVM: modules classes functions methods Proper display of Bigloo objects: Bugloo display: f (::procedure) = procedure (foo ::obj) in file foo.scm:2 Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.17/20

Mapping Scheme To JVM (1/2) Bigloo directly maps into JVM: modules classes functions methods Proper display of Bigloo objects: Bugloo display: f (::procedure) = procedure (foo ::obj) in file foo.scm:2 Some construction are emulated: closure, higher order functions Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.17/20

Mapping Scheme To JVM (2/2) Hide internals of Bigloo compilation Filtering Single Stepping: Step out of JVM constructors: (filter ext add ("bigloo\\..*\\.<clinit>". out)) Don t stop in higher-order call dispatcher: (filter ext add ("\\.funcall[0-4]\\(". next)) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.18/20

Mapping Scheme To JVM (2/2) Hide internals of Bigloo compilation Filtering Single Stepping: Step out of JVM constructors: (filter ext add ("bigloo\\..*\\.<clinit>". out)) Don t stop in higher-order call dispatcher: (filter ext add ("\\.funcall[0-4]\\(". next)) Limitations Does not filter steps inside a function Functions still visible in the stack frame Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.18/20

Performances Performance penalties are limited: Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.19/20

Performances Performance penalties are limited: 1.5% to 6% slower than normal execution Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.19/20

Performances Performance penalties are limited: 1.5% to 6% slower than normal execution No impact on memory consumption Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.19/20

Performances Performance penalties are limited: 1.5% to 6% slower than normal execution No impact on memory consumption JIT stays enabled during debug Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.19/20

Performances Performance penalties are limited: 1.5% to 6% slower than normal execution No impact on memory consumption JIT stays enabled during debug Good performances for memory debugging: back-reference path (546 links): 4.5s on a 20 Mb heap (> 396000 objects) (Athlon XP 1900+) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.19/20

Performances Performance penalties are limited: 1.5% to 6% slower than normal execution No impact on memory consumption JIT stays enabled during debug Good performances for memory debugging: back-reference path (546 links): 4.5s on a 20 Mb heap (> 396000 objects) (Athlon XP 1900+) Can debug the Bigloo compiler ( 130000 lines) Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.19/20

Conclusion We have developed Bugloo: Can debug Bigloo programs compiled for JVM Source level debugger + custom features Integration into the (X)Emacs editor Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.20/20

Conclusion We have developed Bugloo: Can debug Bigloo programs compiled for JVM Source level debugger + custom features Integration into the (X)Emacs editor Advantages of the JVM as a debug platform: Clean API to instrument the debuggee Same classfile for debug and for performances Usable for debugging large programs Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.20/20

Conclusion We have developed Bugloo: Can debug Bigloo programs compiled for JVM Source level debugger + custom features Integration into the (X)Emacs editor Advantages of the JVM as a debug platform: Clean API to instrument the debuggee Same classfile for debug and for performances Usable for debugging large programs http://www-sop.inria.fr/mimosa/fp/bugloo Bugloo: A Source Level Debugger for Scheme Programs Compiled into JVM Bytecode p.20/20