Technologies for finding Technologies for finding errors errors in object-oriented software in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 Summer school on Formal Models of Software 2 Sep 2003, Tunis, Tunisia
27
Embed
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 Summer school on Formal Models.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Technologies for finding errorsTechnologies for finding errorsin object-oriented softwarein object-oriented software
Technologies for finding errorsTechnologies for finding errorsin object-oriented softwarein object-oriented software
K. Rustan M. LeinoMicrosoft Research, Redmond, WA
Lecture 1Summer school on Formal Models of Software2 Sep 2003, Tunis, Tunisia
Review: Tool architectureSource programSource program
Verification conditionVerification condition
Counterexample contextCounterexample context
Warning messagesWarning messages
Automatic theorem proverAutomatic theorem prover
Post processorPost processor
Sugared commandSugared command
Primitive commandPrimitive command
Passive commandPassive commandTra
nsl
ato
rTra
nsl
ato
rFocus today
Commands and their possible outcomes• Normal termination
– terminates normally in some state
• Erroneous termination– goes wrong, crashes the computer
• Non-termination– diverges, fails to terminates, results in infinite
recursion
• Miraculous termination– fails to start, blocks
(partial/miraculous commands)
you breach
contract,demon wins
demon breaches contract,you win!
Commands
C ::= w := E| assert P| assume P| var w in C end| C0 ; C1
| C0 [] C1
Semantics• Hoare logic
– {P} C {R} says that if command C is started in (a state satisfying) P, then:• C does not go wrong, and• if C terminates normally, then it
terminates in (a state satisfying) R
• Weakest preconditions– for a given C and R, the weakest P
satisfying {P} C {R}– written wp(C, R) or simply C.R
Command semantics—assignment
• evaluate E and change value of w to E• (w := E).R ≡ R[w := E]
• (x := x + 1).(x ≦ 10)≡ x+1 ≦ 10≡ x < 10
• (x := 15).(x ≦ 10)≡ 15 ≦ 10≡ false
• (y := x + 3*y).(x ≦ 10)≡ x ≦ 10
• (x,y := y,x).(x < y)≡ y < x
replace w by Ein R
Command semantics—assert
• if P holds, do nothing, else go wrong• (assert P).R ≡ P ∧ R
• (assert x < 10).(0 ≦ x)≡ 0 ≦ x < 10
• (assert x = y*y).(0 ≦ x)≡ x = y*y ∧ 0 ≦ x≡ x = y*y
• (assert false).(x ≦ 10)≡ false
logical AND,conjunction
Command semantics—assume
logicalimplication
logical NOT,negation
logical OR,disjunction
• if P holds, do nothing, else block
• (assume P).R ≡ ¬ P ∨ R≡ P ⇒ R
• (assume x < 10).(0 ≦ x)≡ 10 ≦ x ∨ 0 ≦ x≡ 0 ≦ x
• (assume x = y*y).(0 ≦ x)≡ x = y*y ⇒ 0 ≦ x≡ true
• (assume false).(x ≦ 10)≡ true
• introduce w with an arbitrary initial value,then do C
• (var w in C end).R ≡ (∀w ・ C.R)
• (var y in y := x end).(0 ≦ x)≡ (∀y ・ (y := x).(0 ≦ x))≡ (∀y ・ 0 ≦ x)≡ 0 ≦ x
• (var y in x := y end).(0 ≦ x)≡ (∀y ・ (x := y).(0 ≦ x))≡ (∀y ・ 0 ≦ y)≡ false
Command semantics—local variable
provided w does not occur free in R
• do C0, then C1
• (C0 ; C1).R ≡ C0.(C1.R)
• (x := x+1 ; assert x ≦ y).(0 < x)≡ (x := x+1).( (assert x ≦ y).(0 < x) )≡ (x := x+1).(0 < x ≦ y)