DebugAllYourCode: PortableMixedEnvironmentDebugging - - PowerPoint PPT Presentation

debug all your code portable mixed environment debugging
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Debug
All
Your
Code:
 
Portable
Mixed‐Environment
Debugging


Byeongcheol
Lee

 Mar:n
Hirzel
 Robert
Grimm
 Kathryn
McKinley


1

OOPSLA 2009

slide-2
SLIDE 2
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

1. Leverage
legacy
code
and
exis:ng
libraries.
 2. Match
language
features
to
a
task.


FFI Mixed-Language X Language Y Language

Programmers
build
systems
in
mul:ple
languages.


2

Portable
mixed‐environment
debugging


slide-3
SLIDE 3
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

JNI Mixed-Environment Managed Java Native C/C++

3

Portable
mixed‐environment
debugging


1. Leverage
legacy
code
and
exis:ng
libraries.
 2. Match
language
features
to
a
task.


Programmers
build
systems
in
mul:ple
languages.


Mixed-Language

slide-4
SLIDE 4
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

JNI Managed Java Native C/C++

Bugs appear in all your code!

4

The
problem


Mixed-Environment

slide-5
SLIDE 5
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

JNI Managed Java Native C/C++

The
problem
with
single‐environment
debugging


Eclipse JDT

0


5

Mixed-Environment

slide-6
SLIDE 6
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

JNI Managed Java Native C/C++

The
problem
with
single‐environment
debugging


0


Eclipse CDT

6

Mixed-Environment

slide-7
SLIDE 7
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Portable mixed-environment debugging

JNI Managed Java Native C/C++

7

Our
goal


Mixed-Environment

slide-8
SLIDE 8
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

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.


8

slide-9
SLIDE 9
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Problem:
GDB
does
not
work
at
a
Java
breakpoint.



9

JNI Managed Java Native C/C++ JDB GDB

slide-10
SLIDE 10
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Problem:
GDB
does
not
work
at
a
Java
breakpoint.



10

JNI Managed Java Native C/C++ JDB GDB Naïve composition How
can
I
print
a
C
variable
at
a
 Java
breakpoint?
 Unfortunately,
GDB
does
not
 work
at
the
Java
breakpoint.


slide-11
SLIDE 11
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Our
solu:on:
the
intermediate
agent
switches
debugger
context.


11

JNI Managed Java Native C/C++ JDB GDB Blink controller We
will
wake
up
GDB
at
a
Java
 breakpoint
‐
Switching
 debugger
context.


slide-12
SLIDE 12
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Our
solu:on:
switch
debugger
context
from
Java
to
C.


12

JDB
 J‐Agent
 C‐Agent
 j2c(){cbreak();
 void
cbreak(){
 eval j2c() breakpoint hit GDB

slide-13
SLIDE 13
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Our
solu:on:
switch
debugger
context
from
Java
to
C.


13

JDB
 J‐Agent
 C‐Agent
 j2c(){cbreak();
 void
cbreak(){
 eval j2c() breakpoint hit GDB print c_var

slide-14
SLIDE 14
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Our
solu:on:
switch
debugger
context
from
Java
to
C.


14

JDB
 J‐Agent
 C‐Agent
 j2c(){cbreak();
 void
cbreak(){
 eval j2c() return;}
 return;}
 j2c() completed breakpoint hit continue GDB print c_var

slide-15
SLIDE 15
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Problem:
GDB
does
not
understand
JNI
calling
conven:ons.


15

JNI Managed Java Native C/C++ JDB GDB How
did
the
program
reach
the
 current
breakpoint?
 How
can
I
tell
you
the
calling
 context?
 Unfortunately,
GDB
does
not
 understand
JNI
transiNons.
 Naïve composition

slide-16
SLIDE 16
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

16

jping(i)
 cpong(j)


Problem:
GDB
does
not
understand
JNI
calling
conven:ons.


slide-17
SLIDE 17
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

17

j2j_call j2c_call main
 jping(3)
 cpong(2)
 Problem:
GDB
does
not
understand
JNI
calling
conven:ons.
 main
 jping(3)
 cpong(2)
 JDB stack GDB stack

slide-18
SLIDE 18
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

18

j2j_call j2c_call c2j_call main
 jping(3)
 cpong(2)
 jping(1)
 Problem:
GDB
does
not
understand
JNI
calling
conven:ons.
 main
 jping(3)
 jping(1)
 cpong(2)
 JDB stack GDB stack GDB
does
not
 understand
JNI
 calling
 convenNon.


slide-19
SLIDE 19
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

19

j2j_call j2c_call c2j_call j2c_call main
 jping(3)
 cpong(2)
 jping(1)
 cpong(0)
 Problem:
GDB
does
not
understand
JNI
calling
conven:ons.
 main
 jping(3)
 jping(1)
 cpong(0)
 cpong(2)
 JDB stack GDB stack GDB
does
not
 understand
JNI
 calling
 convenNon.


slide-20
SLIDE 20
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

20

j2j_call j2c_call c2j_call j2c_call main
 jping(3)
 jping(1)
 cpong(0)
 cpong(2)
 main
 jping(3)
 cpong(2)
 jping(1)
 cpong(0)
 JDB stack GDB stack with the agent

Our
solu:on:
translate
JNI
transi:ons
into
C
transi:ons.


The
agent
 translates
JNI
 calls
into
C
calls
 –
transiNon
 interposiNon.


slide-21
SLIDE 21
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

21

j2j_call j2c_call c2j_call j2c_call main
 jping(3)
 jping(1)
 cpong(0)
 cpong(2)
 main
 jping(3)
 cpong(2)
 jping(1)
 cpong(0)
 JDB GDB with the agent

Our
solu:on:
compose
a
calling
context.


main
 jping(3)
 jping(1)
 Blink cpong(0)
 cpong(2)


slide-22
SLIDE 22
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Our
solu:on:
controller
and
intermediate
agent


22

JNI Managed Java Native C/C++ JDB GDB Controller Intermediate
 agent


slide-23
SLIDE 23
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

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


23

Outline


slide-24
SLIDE 24
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

JNI Mixed-Environment Managed Java Native C/C++

Debugging
boundary
code


24

What
do
I
need
to
debug
boundary
 code?


slide-25
SLIDE 25
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

JNI Mixed-Environment Managed Java Native C/C++

Advanced
features
to
debug
boundary
code


25

2.
Detec:ng
FFI
bugs
 1.
Evalua:ng
Jeannie
Expressions


slide-26
SLIDE 26
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

26

jstring name;

Problem:
you
can
not
de‐reference
opaque
pointers
in
C.


slide-27
SLIDE 27
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

27

jstring name;

print
*name


The
name
is
an


  • paque
C
pointer.



Problem:
you
can
not
de‐reference
opaque
pointers
in
C.


slide-28
SLIDE 28
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

28

“smiley”


jstring name;

print
*name
 print
`name


The
name
is
an


  • paque
C
pointer.



The
Jeannie
 backNck
gives
me
 eyes
to
see
the
 Java
world.


Our
solu:on:
use
Jeannie
expression


slide-29
SLIDE 29
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

29

“smiley”


jstring name;

print
*name
 print
`name


The
name
is
an


  • paque
C
pointer.



How
can
I
evaluate
 the
Jeannie
 expression?


Our
solu:on:
use
Jeannie
expression.


slide-30
SLIDE 30
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Build
abstract
syntax
tree


30

print

`

name

slide-31
SLIDE 31
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Evaluate
AST
in
BoOom‐up
order.


31

JDB
 Agent
 GDB $vc1 = name

print

`

name

slide-32
SLIDE 32
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Evaluate
AST
in
BoOom‐up
order.


32

JDB
 Agent
 GDB $vc1 = name $vj2 = $vc1

print

`

name

slide-33
SLIDE 33
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Evaluate
AST
in
BoOom‐up
order.


33

print

`

name

JDB
 Agent
 GDB $vc1 = name $vj2 = $vc1 Print $vj2

“smiley”


slide-34
SLIDE 34
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

JNI Managed Java Native C/C++

Advanced
features


34

B.
Detec:ng
FFI
bugs
 A.
Evalua:ng
Jeannie
Expressions


slide-35
SLIDE 35
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

35

(*env)‐>GetStringUTFChars(env,
NULL);


C
code


Problem:
you
may
misuse
foreign
func:on
interface.


slide-36
SLIDE 36
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

36

(*env)‐>GetStringUTFChars(env,
NULL);


C
code
 The NULL is invalid. The java-gnome bug 576107 crashes the J9 JVM.

Problem:
you
may
misuse
foreign
func:on
interface.


slide-37
SLIDE 37
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

37

(*env)‐>GetStringUTFChars(env,
NULL);


c2j_wrap_GetStringUTFChars(env,
cstr)
{


C
code
 Agent
 GDB The NULL is invalid. The java-gnome bug 576107 crashes the IBM J9 SR5.

Our
solu:on:
detect
FFI
bugs


slide-38
SLIDE 38
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

38

(*env)‐>GetStringUTFChars(env,
NULL);


c2j_wrap_GetStringUTFChars(env,
cstr)
{
 

if

(cstr
==
NULL)
{cbreak();}



C
code
 Agent
 GDB The NULL is invalid. The java-gnome bug 576107 crashes the IBM J9 SR5.

Our
solu:on:
detect
FFI
bugs.


slide-39
SLIDE 39
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

39

(*env)‐>GetStringUTFChars(env,
NULL);


c2j_wrap_GetStringUTFChars(env,
cstr)
{
 

if

(cstr
==
NULL)
{cbreak();}

 void
cbreak()
{


C
code
 Agent
 GDB The NULL is invalid. The java-gnome bug 576107 crashes the IBM J9 SR5. The agent immediately reports the bug.

Our
solu:on:
detect
FFI
bugs.


slide-40
SLIDE 40
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

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


40

Outline


slide-41
SLIDE 41
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Composi:on
is
simple.


41

515K source lines of code in total JDB
 17%
 GDB
 81%
 Agent

 1%
 Controller
 1%


slide-42
SLIDE 42
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Composi:on
is
portable.


42

Source lines of code Platforms IA32/Linux/ Hotspot 4,575 8,840 Agent Controller

slide-43
SLIDE 43
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Composi:on
is
portable.


43

Source lines of code Platforms IA32/Linux/ Hotspot J9 4,575 8,840 Agent Controller

slide-44
SLIDE 44
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Composi:on
is
portable.


44

Source lines of code Platforms IA32/Linux/ Hotspot J9 Cygwin 4,575 8,840 Agent Controller

slide-45
SLIDE 45
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Composi:on
is
portable.


45

Source lines of code Platforms IA32/Linux/ Hotspot J9 Cygwin Windows 4,575 8,840 9,481 Agent Controller

slide-46
SLIDE 46
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Composi:on
is
powerful.


46

The bug 576107 in java-gnome 4.0.10

Hotspot
VM
1.6.0_10
 J9
VM
SR5
 Produc:on
run
 running
 crash


slide-47
SLIDE 47
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Composi:on
is
powerful.


47

The bug 576107 in java-gnome 4.0.10

Hotspot
VM
1.6.0_10
 J9
VM
SR5
 Produc:on
run
 running
 crash
 Run:me
 checking
 (‐Xcheck:jni)
 warning
 warning


slide-48
SLIDE 48
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Composi:on
is
powerful.


48

The bug 576107 in java-gnome 4.0.10

Hotspot
VM
1.6.0_10
 J9
VM
SR5
 Produc:on
run
 running
 crash
 Run:me
 checking
 (‐Xcheck:jni)
 warning
 warning
 jdb
 running
 crash
 gdb
 running
 fault


slide-49
SLIDE 49
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Composi:on
is
powerful.


49

The bug 576107 in java-gnome 4.0.10

Hotspot
VM
1.6.0_10
 J9
VM
SR5
 Produc:on
run
 running
 crash
 Run:me
 checking
 (‐Xcheck:jni)
 warning
 warning
 jdb
 running
 crash
 gdb
 running
 fault


Blink
 breakpoint
 breakpoint


slide-50
SLIDE 50
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Related
work


  • Mixed‐environment
debuggers


– Intel
XDI
for
Harmony
JVM
 – SUN
dbx
 – MicrosoW
.NET
debuggers


  • Advance
debugging
features


– Sta:c
analyses


  • BEAM
[Kondoh
&
Onodera
’08]

  • J‐Saffire
[Furr
&
Foster
’06]

  • ILEA
[Tan
&
MorriseO
‘07]


– Language
designs


  • Jeannie
[Hirzel
&
Grimm
‘07]

  • SafeJNI
[Tan
et
al.
‘06]


– Wrapper
generators


  • Automa:c
binding
generator
[Ravitch
‘09]

  • SWIG
[Beazley
‘96]


50

slide-51
SLIDE 51
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Summary


  • Portable
mixed‐environment
debugging

  • Composi:on
with
an
intermediate
agent

  • 1. Switching
debugger
context

  • 2. Interposing
transi:ons

  • Results

  • 1. Simple

  • 2. Portable

  • 3. Powerful


51

slide-52
SLIDE 52
  • B. Lee, M. Hirzel, R. Grimm, and K. S. McKinley

Thank
you


52