Debugging Native Extensions of Dynamic Languages
Total Page:16
File Type:pdf, Size:1020Kb
LLVM IR IN GRAALVM: MULTI-LEVEL, POLYGLOT DEBUGGING WITH SULONG Jacob Kreindl 2019 European LLVM Developers’ Meeting, April 8-9, 2019 MOTIVATION Binary LLVM IR April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 MOTIVATION Debuggers for Dynamic Languages Binary LLVM IR April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 MOTIVATION Debuggers for Dynamic Languages Binary LLVM IR April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 MOTIVATION Debuggers for Dynamic Languages Binary LLVM IR April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 MOTIVATION Debuggers for Dynamic Languages Binary LLVM IR April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 MOTIVATION Debuggers for Dynamic Languages Binary LLVM IR April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 MOTIVATION Debuggers for Dynamic Languages Binary LLVM IR Debuggers for Native Code April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 MOTIVATION Debuggers for Dynamic Languages Binary LLVM IR Debuggers for Native Code April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 MOTIVATION Debuggers for Dynamic Languages Binary LLVM IR Debuggers for Native Code April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 MOTIVATION Debuggers for Dynamic Languages Binary LLVM IR Debuggers for Native Code April 9, 2019 Jacob Kreindl, EuroLLVM’19 2 GRAALVM LLVM IR April 9, 2019 Jacob Kreindl, EuroLLVM’19 3 GRAALVM Execute & Debug LLVM IR April 9, 2019 Jacob Kreindl, EuroLLVM’19 3 GRAALVM Execute & Debug LLVM IR Execute April 9, 2019 Jacob Kreindl, EuroLLVM’19 3 GRAALVM Execute & Debug LLVM IR Execute & Debug Debug April 9, 2019 Jacob Kreindl, EuroLLVM’19 3 GRAALVM FOR DYNAMIC LANGUAGES April 9, 2019 Jacob Kreindl, EuroLLVM’19 4 GRAALVM FOR DYNAMIC LANGUAGES Language Front-End Language Front-End Language Front-End April 9, 2019 Jacob Kreindl, EuroLLVM’19 4 GRAALVM FOR DYNAMIC LANGUAGES Source Language Location Front-End op1 Language op2 if Front-End then else op3 op4 Language Front-End Language-Agnostic AST April 9, 2019 Jacob Kreindl, EuroLLVM’19 4 GRAALVM FOR DYNAMIC LANGUAGES Source Language Location Chrome Front-End Debugger op1 Language op2 if Debugger Netbeans Front-End Back-End Debugger then else op3 op4 Language Other Front-End Front-Ends Language-Agnostic AST April 9, 2019 Jacob Kreindl, EuroLLVM’19 4 SULONG – THE LLI IN GRAALVM LLVM Front-End (Clang, Dragonegg, …) block phi %8 store getelementptr 42 Debugger LLVM-IR Sulong Back-End %1 4 Language-Agnostic AST (IR-Level) April 9, 2019 Jacob Kreindl, EuroLLVM’19 5 SOURCE-LEVEL DEBUGGING WITH SULONG LLVM Front-End (Clang, Dragonegg, …) Scope & Location Value Tracking block (@llvm.dbg.*) Abstraction to Source-Level phi %8 store getelementptr 42 Debugger LLVM-IR Sulong Back-End with Debug %1 4 + DebugInfo Information Parser Language-Agnostic AST (IR-Level) + Run-Time Debug Information (Source-Level) April 9, 2019 Jacob Kreindl, EuroLLVM’19 6 DEBUGGING NATIVE EXTENSIONS OF DYNAMIC LANGUAGE PROGRAMS Ruby Program + Native Extension April 9, 2019 Jacob Kreindl, EuroLLVM’19 7 DEBUGGING NATIVE EXTENSIONS OF DYNAMIC LANGUAGE PROGRAMS LLVM IR Ruby Program One AST + Native Extension built from multiple language front-ends April 9, 2019 Jacob Kreindl, EuroLLVM’19 7 DEBUGGING NATIVE EXTENSIONS OF DYNAMIC LANGUAGE PROGRAMS GraalVM Debugger Back-End LLVM IR Ruby Program One AST + Native Extension built from multiple language front-ends April 9, 2019 Jacob Kreindl, EuroLLVM’19 7 DEMO Debugging a C-Extension for a Ruby Program with Sulong/TruffleRuby IR-LEVEL DEBUGGING WITH SULONG LLVM Front-End (Clang, Dragonegg, …) Location in ll-File op1 Abstraction to IR-Level op2 if then else Debugger LLVM-IR Sulong Back-End op3 op4 .bc + .ll File + .ll Parser Language-Agnostic Program Representation + Run-Time Debug Information April 9, 2019 Jacob Kreindl, EuroLLVM’19 9 MEMORY ACCESS IN SULONG April 9, 2019 Jacob Kreindl, EuroLLVM’19 10 MEMORY ACCESS IN SULONG Native Mode All allocations on the native heap Using java.lang.Unsafe Accessing illegal memory leads to Segfault may not be allocated { i32, i32 }* 0x00abcdef 42 84 April 9, 2019 Jacob Kreindl, EuroLLVM’19 10 MEMORY ACCESS IN SULONG Native Mode Sandboxed Mode All allocations on the native heap All allocations as Java objects Using java.lang.Unsafe Only in GraalVM Enterprise Edition Accessing illegal memory leads to Guaranteed memory safety Segfault may not be Always safe allocated to access { i32, i32 }* 0x00abcdef { i32, i32 }* <managed> { i32, i32 } <managed> 42 84 i32 42 i32 84 April 9, 2019 Jacob Kreindl, EuroLLVM’19 10 DEMO Debugging & Tracing a C-Program at IR-Level with Managed Sulong YOU CAN TRY IT YOURSELF Download GraalVM at https://www.graalvm.org/ GraalVM Community Edition is Open Source: https://github.com/oracle/graal April 9, 2019 Jacob Kreindl, EuroLLVM’19 12 IN CONCLUSION Execute & Debug LLVM IR April 9, 2019 Jacob Kreindl, EuroLLVM’19 13 IN CONCLUSION Execute & Debug Same Debugger Front-End LLVM IR for all Languages April 9, 2019 Jacob Kreindl, EuroLLVM’19 13 IN CONCLUSION Execute & Debug Same Debugger Front-End LLVM IR for all Languages Source-Level Stepping & Breakpoints April 9, 2019 Jacob Kreindl, EuroLLVM’19 13 IN CONCLUSION Execute & Debug Same Debugger Front-End LLVM IR for all Languages Source-Level Stepping & Breakpoints Cross-Language Symbol Inspection April 9, 2019 Jacob Kreindl, EuroLLVM’19 13 IN CONCLUSION Execute & Debug Same Debugger Front-End LLVM IR for all Languages Source-Level Stepping & Breakpoints Cross-Language Symbol Inspection IR-Level Debugging April 9, 2019 Jacob Kreindl, EuroLLVM’19 13 SYSTEM OVERVIEW Native Extension Code in Dynamic Language (C/C++, Fortran, (Ruby, Python, LLVM-IR Chrome Debugger + Debug Information GraalVM Interpreter for Dynamic Language Truffle Debugger Sulong (TruffleRuby, GraalPython, Truffle JVM + Graal April 9, 2019 Jacob Kreindl, EuroLLVM’19 15.