views:

2167

answers:

3

What is Dynamic Code Analysis?

How is it different from Static Code Analysis (ie, what can it catch that can't be caught in static)?

I've heard of bounds checking and memory analysis - what are these?

What other things are checked using dynamic analysis?

+1  A: 

Basically you instrument your code to analyze your software as it is running (dynamic) rather than just analyzing the software without running (static). Also see this JavaOne presentation comparing the two. Valgrind is one example dynamic analysis tool for C. You could also use code coverage tools like Cobertura or EMMA for Java analysis.

From Wikipedia's definition of dynamic program analysis:

Dynamic program analysis is the analysis of computer software that is performed with executing programs built from that software on a real or virtual processor (analysis performed without executing programs is known as static code analysis). Dynamic program analysis tools may require loading of special libraries or even recompilation of program code.

David Schlosnagle
+1  A: 

Bounds checking

This means runtime checks of array accesses. Contrary to C's laissez-faire approach to memory accesses and pointer arithmetic, other languages like Java or C# actually check whether or not a given array has the element one is trying to access.

David Schmitt
+3  A: 

Simply put, static analysis collect information based on source code and dynamic analisys is based on the system execution, often using instrumentation.

Advantages of dynamic analysis

  • Is able to detect dependencies that is not possible in static analysis. Ex.: dynamic dependencies using reflection, dependecy injection, polimorphism.
  • Can collect temporal information
  • Deals with real runtime values

Disadvantages of dynamic analysis

  • Much more complex to work with
  • Cannot garantee the full coverage of the source code, as is runs based on user interaction or automatic tests

Resources

There's many dynamic analysis tools in the market, being debuggers the most notorious one. On the other hand, it's still an academic research field. There's many researchers studying how to use dynamic analysis for better understanding of software systems. There's an annual workshop dedicated to dependecy analysis.

Marcio Aguiar