Docsity

CMSC 631: Program Analysis and Understanding - Fall 2004, Study notes of Computer Science

Toggle sidebar
bg1
CMSC 631 – Program Analysis and
Understanding
Fall 2004
2
CMSC 631, Fall 2004
• Topic: Analyzing and understanding software
• Three main focus areas:
■Static analysis
-Automatic reasoning about source code
■Formal systems and notations
-Vocabulary for talking about programs
■Programming language features
-Affects programs and how we reason about them
About this Class
3
CMSC 631, Fall 2004
• Jeff Foster
■Office: 4129 AVW
■E-mail: jfoster at cs.umd.edu
■Office hours: Tuesday, Friday 11am-12pm
-Or by appointment
• Morgan Kleene
■E-mail: kleene at cs.umd.edu
Personnel
4
CMSC 631, Fall 2004
• CMSC 430 or equivalent compiler class
■Ideas we will use in this class:
-Parse trees/abstract syntax trees
-BNF notation for grammars
-Type checking (usually not much covered in compilers class)
-Data flow analysis (sometimes not covered in compilers class)
-Tools like yacc and lex may be useful for your project
■We won’t use most of the other material
-So even if you haven’t taken compilers class, you may be OK
-Talk to me if you’re not sure
Prerequisite
5
CMSC 631, Fall 2004
Textbooks
• No required textbooks
• Two recommended texts
■Pierce, Types and Programming Languages
■Huth and Ryan, Logic in Computer Science
• Neither covers everything in the course
• On reserve in CS library
6
CMSC 631, Fall 2004
• Will read 1-3 papers per week
■Typically, papers available on the web
-Otherwise will hand out photocopies in class
•Must participate in brief discussion on class wiki
■http://corundum.cs.umd.edu:8000/CMSC631
■Post a few sentences to a paragraph or two on
-Main contributions/ideas in paper
-Ideas that were unclear – what do I need to cover in class?
-Relationship to other papers we’ve read
-etc...
Expectations: Readings
pf3
pf4
pf5

Partial preview of the text

Download CMSC 631: Program Analysis and Understanding - Fall 2004 and more Study notes Computer Science in PDF only on Docsity!

CMSC 631 – Program Analysis and Understanding Fall 2004

CMSC 631, Fall 2004 2

• Topic: Analyzing and understanding software

• Three main focus areas:

■ (^) Static analysis

  • Automatic reasoning about source code ■ Formal systems and notations
  • Vocabulary for talking about programs ■ Programming language features
  • Affects programs and how we reason about them

About this Class

CMSC 631, Fall 2004 3

• Jeff Foster

■ (^) Office: 4129 AVW ■ (^) E-mail: jfoster at cs.umd.edu ■ (^) Office hours: Tuesday, Friday 11am-12pm

  • Or by appointment

• Morgan Kleene

■ E-mail: kleene at cs.umd.edu

Personnel

CMSC 631, Fall 2004 4

• CMSC 430 or equivalent compiler class

■ (^) Ideas we will use in this class:

  • Parse trees/abstract syntax trees
  • BNF notation for grammars
  • Type checking (usually not much covered in compilers class)
  • Data flow analysis (sometimes not covered in compilers class)
  • Tools like yacc and lex may be useful for your project ■ We won’t use most of the other material
  • So even if you haven’t taken compilers class,^ you may be OK
  • Talk to me if you’re not sure

Prerequisite

Textbooks

• No required textbooks

• Two recommended texts

■ Pierce, Types and Programming Languages ■ Huth and Ryan, Logic in Computer Science

• Neither covers everything in the course

• On reserve in CS library

• Will read 1-3 papers per week

■ (^) Typically, papers available on the web

  • Otherwise will hand out photocopies in class

• Must participate in brief discussion on class wiki

■ (^) http://corundum.cs.umd.edu:8000/CMSC ■ (^) Post a few sentences to a paragraph or two on

  • Main contributions/ideas in paper
  • Ideas that were unclear – what do I need to cover in class?
  • Relationship to other papers we’ve read
  • etc...

Expectations: Readings

CMSC 631, Fall 2004 7

• Must post comments by noon on day of class

■ First post! can just put up a summary ■ (^) Later posts need to take earlier posts into account ■ (^) Posting earlier is less work

• 10% of grade will be on class participation,

including comments on wiki

■ (^) Includes talk on selected paper in 2nd half of course

Expectations: Readings (cont’d)

CMSC 631, Fall 2004 8

Expectations: Homework

• Two kinds of assignments:

■ Programming assignments (20% of grade)

  • Every two weeks
  • Implement the ideas we see in lecture ■ (^) Written assignments (10% of grade)
  • Every week
  • Short problem sets

• This is how you will learn things

■ (^) Much more effective than listening to a lecture

CMSC 631, Fall 2004 9

• Class goal: Teach you how to do research

■ (^) So you have to do research as part of the class

• Substantial research project (35% of grade)

■ (^) Any topic vaguely related to the class is acceptable

  • Will post some suggestions for projects later on
  • May also be able to share project with other class ■ Completed in groups of size 1 or 2

• This will consume second-half of semester

■ Will ease up on homeworks, reading

Expectations: Project

CMSC 631, Fall 2004 10

Expectations: Project (cont’d)

• Deliverables

■ (^) Project proposal (one page) + talk with me ■ (^) Project write-up

  • A conference-style paper (5-15 pages, as appropriate) ■ Implementation, if any ■ (^) In-class presentation
  • 15-20 minutes,^ depending on # of projects

• Last year, 2 projects turned into publications

■ (^) And a couple more could have been

• Final exam (25% of grade)

■ (^) Based on written and programming assignments ■ (^) Take-home or in-class (we’ll vote at the end of the semester)

Expectations: Exam

• Don’t do it

Academic Dishonesty

CMSC 631, Fall 2004 19

• Dataflow facts form a lattice

• Each statement has a transformation function

■ (^) Out(S) = Gen(S) U (In(S) - Kill(S)) ■

• Terminates because

■ Finite height lattice ■ (^) Monotone transformation functions

Lattices and Termination

x =? x = 3 x = 6 ...

x = *

CMSC 631, Fall 2004 20

• Transform CFG so each use has a single defn

Static Single Assignment Form

x := 0

v := 3 v := 4 + x

x := x + v

x 1 := 0

v 1 := 3 v 2 := 4 + x 1

v 3 := !(v 1 ,v 2 )

x 2 := x 1 + v 3

CMSC 631, Fall 2004 21

• Three syntactic forms

variable function function application

• One reduction rule

■ (replace by in )

• Can represent any computable function!

Lambda Calculus

CMSC 631, Fall 2004 22

• Conditionals

■ (^) true = false = ■ (^) if a then b else c =

  • if true then b else c =
  • if false then b else c =

• Can also represent numbers, pairs, data

structures, etc, etc.

• Result: Lingua franca of PL

Example

ML: Meta-Language

• ML designed originally for theorem provers

■ (^) But after a while, realized could be general-purpose

• Mostly-functional language

■ Similar to lambda-calculus

  • Mostly functional, encouraged not to use side-effects
  • Call-by-value

• We’ll use O’Caml for programming assignments

• Machine represents all values as bit patterns

■ (^) Is 00110110111100101100111010101000

  • A signed integer? Unsigned integer? Floating-point number? Address of an integer? Address of a function? etc.

• Type systems allow us to distinguish these

■ To choose operation (which + op), e.g., FORTRAN ■ To avoid programming mistakes

  • E.g.,^ don’t treat integer as a function address

Type Systems

CMSC 631, Fall 2004 25

in type environment , expression has type

Simply-typed λ-calculus

dom(A) !

!

!

!

!! !

!

CMSC 631, Fall 2004 26

• Liskov:

■ If for each object^ of type^ there is an object^ of type such that for all programs defined in terms of , the behavior of is unchanged when is substituted for then is a subtype of.

• Informal statement

■ (^) If anyone expecting a can be given an instead, then is a subtype of.

Subtyping

CMSC 631, Fall 2004 27

• Old idea: Shouldn’t just hack up code, try to

prove programs are correct

• Proofs require reasoning about the meaning of

programs

• First system: Formalize program behavior in logic

■ (^) Hoare, Dijkstra, Gries, others

Axiomatic Semantics

CMSC 631, Fall 2004 28

■ If statement is executed in a state satisfying precondition , then will terminate, and will hold of the resulting state ■ (^) Partial correctness: ignore termination

• Weakest precondition for assignment

■ (^) Axiom: ■ (^) Example:

Hoare Triples

• Technique for validating hardware

■ (^) Lots of parallelism (concurrency), but ■ (^) Not a lot of structure (e.g., no dynamic allocation)

• Example: mutual-exclusion protocol

Model Checking

loop out: x1 := 1; last := 1 req: await x2 = 0 or last = 2 in: x1 := 0 end loop

loop out: x2 := 1; last := 2 req: await x1 = 0 or last = 1 in: x2 := 0 end loop (Example from Henzinger)

||

• Program defines a state graph

■ (^) State = (pc1, pc2, x1, x2, last) ■ (^) Is any bad state (iiXXX) reachable from the start state?

Transition Graph

oo 001

ro 101 or 012

io 101 rr 112

ir 112

CMSC 631, Fall 2004 37

• Extended Static Checker

■ Can perform deep reasoning about programs ■ (^) Array out-of-bounds ■ (^) Null pointer errors ■ (^) Failure to satisfy internal invariants

• Based on theorem proving

Applications: Axiomatic Semantics

CMSC 631, Fall 2004 38

• Type qualifiers

■ Format-string vulnerabilities, deadlocks, file I/O protocol errors, kernel security holes

• Vault and Cyclone

■ (^) Memory allocation and deallocation errors, library protocol errors, misuse of locks

Applications: Type Systems

CMSC 631, Fall 2004 39

• PL has a great mix of theory and practice

■ (^) Very deep theory ■ (^) But lots of practical applications

• Recent exciting new developments

■ Focus on program correctness instead of speed ■ Forget about full correctness, though ■ Scalability to large programs essential

Conclusion