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