debug all your code portable mixed environment debugging

DebugAllYourCode: PortableMixedEnvironmentDebugging - PowerPoint PPT Presentation

DebugAllYourCode: PortableMixedEnvironmentDebugging ByeongcheolLee Mar:nHirzel RobertGrimm KathrynMcKinley OOPSLA 2009 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 1


  1. Debug
All
Your
Code:
 
Portable
Mixed‐Environment
Debugging
 Byeongcheol
Lee

 Mar:n
Hirzel
 Robert
Grimm
 Kathryn
McKinley
 OOPSLA 2009 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 1

  2. Portable
mixed‐environment
debugging
 Programmers
build
systems
in
mul:ple
languages.
 1. Leverage
legacy
code
and
exis:ng
libraries.
 2. Match
language
features
to
a
task.
 Mixed-Language X Language FFI Y Language B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 2

  3. Portable
mixed‐environment
debugging
 Programmers
build
systems
in
mul:ple
languages.
 1. Leverage
legacy
code
and
exis:ng
libraries.
 2. Match
language
features
to
a
task.
 Mixed-Language Managed Java JNI Native C/C++ Mixed-Environment B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 3

  4. The
problem
 Bugs appear in all your code! Managed Java JNI Native C/C++ Mixed-Environment B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 4

  5. The
problem
with
single‐environment
debugging
 Eclipse JDT 0
 Managed Java JNI Native C/C++ Mixed-Environment B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 5

  6. The
problem
with
single‐environment
debugging
 Eclipse CDT 0
 Managed Java JNI Native C/C++ Mixed-Environment B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 6

  7. Our
goal
 Portable mixed-environment debugging Managed Java JNI Native C/C++ Mixed-Environment B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 7

  8. Our
contribu:on
and
results
 Composi:on 
 1. Add
an
intermediate
agent.
 2. AOach
single‐environment
debuggers.
 3. Dispatch
debuggers
dynamically.
 Blink
results
 1. Simple :
Add
10
K
SLOC
of
new
code.
 2. Portable :
Support
Linux,
Windows,
Hotspot,
J9,
 GCC,
MicrosoW
C++.
 3. Powerful :
Catch
FFI
bugs.
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 8

  9. Problem:
GDB
does
not
work
at
a
Java
breakpoint.

 JDB GDB Managed Java JNI Native C/C++ B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 9

  10. Problem:
GDB
does
not
work
at
a
Java
breakpoint.

 Naïve composition JDB GDB How
can
I
print
a
C
variable
at
a
 Java
breakpoint?
 Unfortunately,
GDB
does
not
 work
at
the
Java
breakpoint.
 Managed Java JNI Native C/C++ B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 10

  11. Our
solu:on:
the
intermediate
agent
switches
debugger
context.
 Blink controller JDB GDB We
will
wake
up
GDB
at
a
Java
 breakpoint
‐
Switching
 debugger
context.
 Managed Java JNI Native C/C++ B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 11

  12. Our
solu:on:
switch
debugger
context
from
Java
to
C.
 JDB
 J‐Agent
 C‐Agent
 GDB j2c(){cbreak();
 eval j2c() void
cbreak(){
 breakpoint hit B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 12

  13. Our
solu:on:
switch
debugger
context
from
Java
to
C. 
 JDB
 J‐Agent
 C‐Agent
 GDB j2c(){cbreak();
 eval j2c() void
cbreak(){
 breakpoint hit print c_var B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 13

  14. Our
solu:on:
switch
debugger
context
from
Java
to
C. 
 JDB
 J‐Agent
 C‐Agent
 GDB j2c(){cbreak();
 eval j2c() void
cbreak(){
 breakpoint hit print c_var return;}
 continue return;}
 j2c() completed B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 14

  15. Problem:
GDB
does
not
understand
JNI
calling
conven:ons.
 Naïve composition JDB GDB How
did
the
program
reach
the
 current
breakpoint?
 How
can
I
tell
you
the
calling
 context?
 Managed Java JNI Native C/C++ Unfortunately,
GDB
does
not
 understand
JNI
transiNons.
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 15

  16. Problem:
GDB
does
not
understand
JNI
calling
conven:ons.
 cpong(j)
 jping(i)
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 16

  17. Problem:
GDB
does
not
understand
JNI
calling
conven:ons.
 JDB stack GDB stack main
 jping(3)
 cpong(2)
 main
 j2j_call jping(3)
 j2c_call cpong(2)
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 17

  18. Problem:
GDB
does
not
understand
JNI
calling
conven:ons.
 JDB stack GDB stack main
 jping(3)
 GDB
does
not
 cpong(2)
 understand
JNI
 jping(1)
 calling
 convenNon.
 main
 j2j_call jping(3)
 j2c_call cpong(2)
 c2j_call jping(1)
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 18

  19. Problem:
GDB
does
not
understand
JNI
calling
conven:ons.
 JDB stack GDB stack main
 jping(3)
 GDB
does
not
 cpong(2)
 understand
JNI
 jping(1)
 calling
 cpong(0)
 convenNon.
 main
 j2j_call jping(3)
 j2c_call cpong(2)
 c2j_call jping(1)
 j2c_call cpong(0)
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 19

  20. Our
solu:on:
translate
JNI
transi:ons
into
C
transi:ons.
 GDB stack JDB stack with main
 the agent The
agent
 jping(3)
 translates
JNI
 cpong(2)
 calls
into
C
calls
 –
transiNon
 jping(1)
 interposiNon.
 cpong(0)
 main
 j2j_call jping(3)
 j2c_call cpong(2)
 c2j_call jping(1)
 j2c_call cpong(0)
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 20

  21. Our
solu:on:
compose
a
calling
context.
 JDB Blink GDB with the agent main
 main
 jping(3)
 jping(3)
 cpong(2)
 cpong(2)
 jping(1)
 jping(1)
 cpong(0)
 cpong(0)
 main
 j2j_call jping(3)
 j2c_call cpong(2)
 c2j_call jping(1)
 j2c_call cpong(0)
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 21

  22. Our
solu:on:
controller
and
intermediate
agent
 Controller JDB GDB Intermediate
 agent
 JNI Managed Java Native C/C++ B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 22

  23. Outline
 I. Problem
 II. Debugger
composi:on
 A. Switching
debugger
context
 B. Interposing
transi:ons
 III. Advanced
features
 A. Evalua:ng
Jeannie
mixed‐environment
expressions
 B. Detec:ng
FFI
bugs
 IV. Evalua:on
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 23

  24. Debugging
boundary
code 
 What
do
I
need
to
debug
boundary
 code?
 Managed Java JNI Native C/C++ Mixed-Environment B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 24

  25. Advanced
features
to
debug
boundary
code 
 1.
Evalua:ng
Jeannie
Expressions
 2.
Detec:ng
FFI
bugs
 Managed Java JNI Native C/C++ Mixed-Environment B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 25

  26. Problem:
you
can
not
de‐reference
opaque
pointers
in
C.
 jstring name; B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 26

  27. Problem:
you
can
not
de‐reference
opaque
pointers
in
C.
 jstring name; The
name
is
an
 print
*name
 opaque
C
pointer.

 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 27

  28. Our
solu:on:
use
Jeannie
expression
 “smiley”
 jstring name; The
name
is
an
 print
*name
 opaque
C
pointer.

 The
Jeannie
 print
`name
 backNck
gives
me
 eyes
to
see
the
 Java
world.
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 28

  29. Our
solu:on:
use
Jeannie
expression.
 “smiley”
 jstring name; The
name
is
an
 print
*name
 opaque
C
pointer.

 How
can
I
evaluate
 print
`name
 the
Jeannie
 expression?
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 29

  30. Build
abstract
syntax
tree
 print ` name B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 30

  31. Evaluate
AST
in
BoOom‐up
order.
 print ` name Agent
 JDB
 GDB $vc 1 = name B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 31

  32. Evaluate
AST
in
BoOom‐up
order.
 print ` name Agent
 JDB
 GDB $vc 1 = name $vj 2 = $vc 1 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 32

  33. Evaluate
AST
in
BoOom‐up
order.
 print ` name Agent
 JDB
 GDB $vc 1 = name $vj 2 = $vc 1 Print $vj 2 “smiley”
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 33

  34. Advanced
features 
 A.
Evalua:ng
Jeannie
Expressions
 B.
Detec:ng
FFI
bugs
 Managed Java JNI Native C/C++ B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 34

  35. Problem:
you
may
misuse
foreign
func:on
interface.
 C
code
 (*env)‐>GetStringUTFChars(env,
 NULL );
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 35

  36. Problem:
you
may
misuse
foreign
func:on
interface.
 C
code
 The NULL is invalid. The java-gnome bug 576107 crashes the J9 JVM. (*env)‐>GetStringUTFChars(env,
 NULL );
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 36

  37. Our
solu:on:
detect
FFI
bugs
 Agent
 C
code
 GDB The NULL is invalid. The java-gnome bug 576107 crashes the IBM J9 SR5. (*env)‐>GetStringUTFChars(env,
 NULL );
 c2j_wrap_GetStringUTFChars(env,
cstr)
{
 B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley 37

Recommend


More recommend