Beruflich Dokumente
Kultur Dokumente
Andrew R. Bernat
University of Wisconsin bernat@cs.wisc.edu
March 2006
Design Objectives
Whole-program instrumentation
Instrument every instruction in the program and all control flow edges as well
Efficient instrumentation
No traps! Minimize extraneous jumps Restrict register save/restores
Multitramps
Whole-program instrumentation
All instructions, including neighbors All control flow edges
Function Relocation
Efficient instrumentation
Blocks too small for branch to instrumentation Instrumentation too far away No traps!
Shared functions
Copy to remove sharing
Function rewriting
Undo optimizations
2006 Andrew R. Bernat 4 Generalized Code Relocation
Mini Trampolines
Instrumentation Code
instr2
Application Program
Mini Trampolines
Instrumentation Code
Edge instrumentation
Application Program Function foo Edge Trampoline pre-branch branch branch fallthrough jump taken Base Trampolines
Inefficient instrumentation
Edges, consecutive instructions require extra branches
Multitramp Principles
Basic-block instrumentation
One jump to/from per block Efficient instrumentation of neighbor instructions
10
Multitramps
Application Program Function foo Multitramp Base Tramp Instruction Instruction Basic Block Base Tramp Branch Fallthrough
2006 Andrew R. Bernat 11
Target
Generalized Code Relocation
Multitramp Implementation
A multitramp is a tree of code objects Code objects provide the following:
Maximum space required (worst case) Generate, install, and link callbacks Map relocated to original address
Multitramp Example
Base Tramp 1 Instruction Branch Base Tramp 2 Base Tramp 3
2006 Andrew R. Bernat
save ; BT 1 <branch <MT 1 restore ; BT 1 <relocated instr< <branch <BT 3 save ; BT 2 <branch <MT 3 restore ; BT 2 return save ; BT 3 <branch <MT 4 restore ; BT 3 return
Generalized Code Relocation
In-Line Instrumentation
Current out-of-line model is based on the requirements of Paradyn
Frequent insertion/removal of instrumentation
14
In-Line Instrumentation
In-line instrumentation into a single code sequence:
Relocated instructions Save/restore code Instrumentation
Multitramp Status
Extensible implementation
Can add new code objects to multitramp CFG:
Raw binary sections. Control flow-altering code
In-line instrumentation
POWER, x86-64
Platform-independent design
Encapsulated platform-dependent sections Included with all platforms in Dyninst 5.0
16
Multitramp Results
Whole-program instrumentation
Instrument every instruction in the program and all control flow edges as well
Efficient instrumentation
No traps! Minimize extraneous jumps Restrict register save/restores
Function Relocation
The basic block may be too small to contain a branch to instrumentation
IA-32, x86-64
18
Old Approach
One-time relocation
Preemptively expand possible instrumentation sites:
Function entry, exit, call sites; loop entry, exits But what about everything else?
19
block 1
block 3
Add modification
block 4
block 2 block 2
block 4
block 5
block 5
21
Undo optimizations
Rewrite the function during relocation Example: unwinding a tail call
22
23
Design Objectives
Whole-program instrumentation
Instrument every instruction in the program and all control flow edges as well
Efficient instrumentation
No traps! Minimize extraneous jumps Restrict register save/restores
Conclusion
Multitramps
Whole-program instrumentation approach
Function relocation
Instrument everywhere (without traps)
People
Drew Bernat Multitramps Nate Rosenblum Function relocation Nick Rutar Register optimizations
25