30
Thomas Ball Sriram K. Rajamani http:// research.microsoft.com /slam/ Bebop: A Path-sensitive Interprocedural Dataflow Analysis Engine

Thomas Ball Sriram K. Rajamani

Embed Size (px)

DESCRIPTION

Bebop: A Path-sensitive Interprocedural Dataflow Analysis Engine. Thomas Ball Sriram K. Rajamani. http://research.microsoft.com/slam/. What is Bebop?. Model checker for boolean programs A generic dataflow engine. What are Boolean Programs?. C program with just boolean variables - PowerPoint PPT Presentation

Citation preview

Page 1: Thomas Ball Sriram K. Rajamani

Thomas BallSriram K. Rajamani

http://research.microsoft.com/slam/

Bebop: A Path-sensitive Interprocedural Dataflow

Analysis Engine

Page 2: Thomas Ball Sriram K. Rajamani

What is Bebop?

Model checker for boolean programs

A generic dataflow engine

Page 3: Thomas Ball Sriram K. Rajamani

What are Boolean Programs?

C program with just boolean variables

Used to represent abstractions of C programs

Language for encoding dataflow problems

Page 4: Thomas Ball Sriram K. Rajamani

Agenda

SLAM and boolean programs

Bebop – internals

Current status and future plans

Page 5: Thomas Ball Sriram K. Rajamani

Checking API Usage

Application

C lib | DLL |

COM |…

API

Does an application follow the “proper usage” rules of an API?

Page 6: Thomas Ball Sriram K. Rajamani

State MachineFor Locking

Unlocked Locked Error

U

L

L

U

state {

int locked = 0;

}

Lock.call {

if (locked==1) abort;

else locked = 1;

}

UnLock.call {

if (locked==0) abort;

else locked = 0;

}

Page 7: Thomas Ball Sriram K. Rajamani

Demo

Page 8: Thomas Ball Sriram K. Rajamani

Goal:

Run the state machine through all paths in the program

Problem: Too many paths!

Solution: Data flow analysis

Problem : False alarms

Solution : Better abstraction

Page 9: Thomas Ball Sriram K. Rajamani

False alarmdo { //get the write lock

KeAcquireSpinLock( &devExt->writeListLock );

nPacketsOld = nPackets; request = devExt->WriteListHeadVa;

if(request && request->status){devExt->WriteListHeadVa = request->Next;

KeReleaseSpinLock(&devExt->writeListLock);

...nPackets++;

}} while (nPackets != nPacketsOld);

KeReleaseSpinLock(&devExt->writeListLock);

Page 10: Thomas Ball Sriram K. Rajamani

False alarmdo { //get the write lock

KeAcquireSpinLock( &devExt->writeListLock );

nPacketsOld = nPackets; request = devExt->WriteListHeadVa;

if(request && request->status){devExt->WriteListHeadVa = request->Next;

KeReleaseSpinLock(&devExt->writeListLock);

...nPackets++;

}} while (nPackets != nPacketsOld);

KeReleaseSpinLock(&devExt->writeListLock);

Page 11: Thomas Ball Sriram K. Rajamani

Abstractiondo { //get the write lock

KeAcquireSpinLock( &devExt->writeListLock );

nPacketsOld = nPackets; b := true; request = devExt->WriteListHeadVa;

if(request && request->status){devExt->WriteListHeadVa = request->Next;

KeReleaseSpinLock(&devExt->writeListLock);

...

nPackets++; b := b ? false : *; }

} while (nPackets != nPacketsOld);

KeReleaseSpinLock(&devExt->writeListLock);

Boolean variable b represents the condition (nPacketsOld == nPackets)

b

b

!bb

Page 12: Thomas Ball Sriram K. Rajamani

Abstractiondo { //get the write lock

KeAcquireSpinLock( &devExt->writeListLock );

nPacketsOld = nPackets; b := true; request = devExt->WriteListHeadVa;

if(request && request->status){devExt->WriteListHeadVa = request->Next;

KeReleaseSpinLock(&devExt->writeListLock);

...

nPackets++; b := b ? false : *; }

} while (nPackets != nPacketsOld);

KeReleaseSpinLock(&devExt->writeListLock);

Boolean variable b represents the condition (nPacketsOld == nPackets)

b

b

!bb

Page 13: Thomas Ball Sriram K. Rajamani

Boolean programdo { //get the write lock

KeAcquireSpinLock();

b := true;

if(*){

KeReleaseSpinLock();...

b := b ? false : *; }

} while ( !b );

KeReleaseSpinLock();

Boolean variable b represents the condition (nPacketsOld == nPackets)

b

b

!bb

Page 14: Thomas Ball Sriram K. Rajamani

C program

Boolean program

c2bp

bebop

Fail, p

Pass

newton

GOLF

SLIC

CFG + VFG

predicates

Error GUI

Spec.

predicates

Page 15: Thomas Ball Sriram K. Rajamani

Agenda

SLAM and boolean programs

Bebop – internals

Current status and future plans

Page 16: Thomas Ball Sriram K. Rajamani

Interprocedural dataflow analysis

[Sharir-Pnueli, 1981] “functional approach” (v) = maps facts from “entry” to facts at v inefficient algorithm

[Reps-Horwitz-Sagiv, POPL’95] construct “exploded supergraph”

product of CFG and dataflow facts efficient refinement of Sharir-Pnueli iterative addition of edges to graph

“path edges”: <entry,d1> -> <v,d2> “summary edges”: <call,d1> -> <return,d2>

Page 17: Thomas Ball Sriram K. Rajamani

decl g;void main()decl u,v; [1] u := !v;

[2] equal(u,v);

[3] if (g) then R: skip;

fi [4] return;

void equal(a, b)

[5] if (a = b) then [6] g := 1; else [7] g := 0; fi [8] return;

[1] [1] [1]

[2] [2]

u!=v

g=0

[5] [5]

[7]

[3]

[4]

[1]

[8]

[7]

u=v

g=0

u!=v

g=1

u=v

g=1

Page 18: Thomas Ball Sriram K. Rajamani

Symbolic dataflow analysis

Do not construct explicit “exploded supergraph”

Represent “path edges” and “summary edges” implicitly (using BDDs)

[Ball, Rajamani, SPIN 2000]

Page 19: Thomas Ball Sriram K. Rajamani

Binary Decision Diagrams [Bryant]

Ordered decision tree for f = a b c d

0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0

d d d d d d d

c c c c

0 1

0 1 0 1

0 1 0 1 0 1 1

b b

a

d

Page 20: Thomas Ball Sriram K. Rajamani

OBDD reduction

a

b b

c c

d d

0 1

0

01

01

01

1

10

01

01

f = a b c d

Page 21: Thomas Ball Sriram K. Rajamani

Difficulty

Do not want to encode control flow graph with BDDs

Solution: No need to represent the CFG “source”

<entry,d1> -> <v,d2>

Partition path edges by their “target”! PE(v) = { <d1,d2> | <entry,d1> ->

<v,d2> } use a BDD to represent PE(v)

Page 22: Thomas Ball Sriram K. Rajamani

decl g;void main()decl u,v; [1] u := !v;

[2] equal(u,v);

[3] if (g) then R: skip;

fi [4] return;

[1] [1] [1]

[2] [2]

u!=v

g=0

[5] [5]

[7]

[3]

[4]

[1]

[8]

[7]

u=v

g=0

u!=v

g=1

u=v

g=1

void equal(a, b)

[5] if (a = b) then [6] g := 1; else [7] g := 0; fi [8] return;

Page 23: Thomas Ball Sriram K. Rajamani

decl g;void main()decl u,v; [1] u := !v;

[2] equal(u,v);

[3] if (g) then R: skip;

fi [4] return;

[1] [1] [1]

[2] [2]

u!=v

g=0

[5] [5]

[7]

[3]

[4]

[1]

[8]

[7]

u=v

g=0

u!=v

g=1

u=v

g=1

void equal(a, b)

[5] if (a = b) then [6] g := 1; else [7] g := 0; fi [8] return;

Page 24: Thomas Ball Sriram K. Rajamani

decl g;void main()decl u,v; [1] u := !v;

[2] equal(u,v);

[3] if (g) then R: skip;

fi [4] return;

[1] [1] [1]

[2] [2]

[5] [5]

[7]

[3]

[4]

[1]

[8]

[7]

g=g’& u=u’& v=v’

g=g’& v!=u’ & v=v’

g=g’ & a=a’ & b=b’ & a!=b

g’=0 & v’!=u’ & v=v’

g’=0 & v!=u’ & v=v’

g=g’& a=a’ & b=b’& a!=b

g’=0 & a=a’ & b=b’& a!=b

void equal(a, b)

[5] if (a = b) then [6] g := 1; else [7] g := 0; fi [8] return;

Page 25: Thomas Ball Sriram K. Rajamani

Boolean Programs

A target language for encoding finite interprocedural program analyses

All the control-flow primitives of C, including procedures and recursion direct mapping of control-flow ease programming of DFA

Boolean variables represent finite sets of dataflow facts implicit three-valued logic via BDDs

Page 26: Thomas Ball Sriram K. Rajamani

void foo( int *p, int *q) if( p != NULL)

q = p; if( p != NULL)

*q = *p + 1;

void foo( bool bp, bool bq) if(bp)

bq = bp; if(bp)

skip

Nullness analysis

C programBoolean program

Page 27: Thomas Ball Sriram K. Rajamani

Performance

Complexity: O(E * 2O(N)

) E is the size of the CFG N is the max. number of variables in scope

Some execution times 300 line C driver in 9 seconds

37 predicates 1,100 line boolean program 300 boolean variables

7,000 line C driver in 8 seconds 22 predicates 16,000 line boolean program 400 boolean variables

Page 28: Thomas Ball Sriram K. Rajamani

Conclusions

Boolean programs – a generic model Abstractions in model checking

software Adding predicate sensitivity to dataflow

Bebop – a symbolic dataflow analyzer Explicit representation of CFG Implicit representation of path edges

and summary edges Generation of hierarchical error traces

Page 29: Thomas Ball Sriram K. Rajamani

In progress

Separate compilation Combine top-down and bottom-up

Precision/efficiency tradeoff Cartesian abstraction Partition the BDDs

don’t track all correlations large amount of work to draw upon

from symbolic model checking

Page 30: Thomas Ball Sriram K. Rajamani

Software Productivity ToolsMicrosoft Research

http://research.microsoft.com/slam/