To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (an extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at

If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

Dynamic code analysis

Dynamic code analysis

Jan 31 2013

Dynamic code analysis is the method of analyzing an application right during its execution. The dynamic analysis process can be divided into several steps: preparing input data, running a test program launch and gathering the necessary parameters, and analyzing the output data. When performing the test launch, the program can be executed both on a real and a virtual processor. The source code should be necessarily compiled into an executable file, i.e. you can't use this method to analyze a code containing compilation or build errors.

Dynamic analysis can be performed on programs written in various programming languages: C, C++, Java, C#, PHP, Python, Erlang, and many others.

There exist special dynamic code analysis utilities intended for program launch and output data gathering and analysis. Many contemporary development environments already have dynamic analysis tools as one of its modules. Such is, for example, the Microsoft Visual Studio 2012's debugger and profiler.

Dynamic analysis tools differ in the way they interact with the program being checked:

  • source code instrumentation - a special code is added into the source code before compilation to detect errors;
  • object code instrumentation - a special code is added directly into the executable file;
  • compilation stage instrumentation - a checking code is added through special compiler switches (this mode is supported, for instance, by the GNU C/C++ 4.x compiler);
  • the tool doesn't change the source code; instead, it uses special execution stage libraries - special debugging versions of system libraries are used to detect errors.

Dynamic analysis is executed by passing a set of data to the input of the program being checked. That's why the efficiency of analysis depends directly on the quality and quantity of the input test data. It's them that the fullness of code coverage obtained through the test depends on.

Dynamic testing can provide the following metrics to you:

  • resources consumed - the time of program execution on the whole or its modules individually, the number of external queries (for example, to the database), the number of memory being used, and other resources;
  • cyclomatic complexity, the degree of code coverage with tests, and other program metrics;
  • program errors - division by zero, null pointer dereferencing, memory leaks, "race conditions";
  • vulnerabilities in the program.

Dynamic testing is most important in the areas where program reliability, response time, and consumed resources are the crucial criteria. It may be, for instance, a real-time system managing a responsible production area or a database server. Any bug that occurs in these systems may be critical.

Dynamic testing can be performed on the principles of white box and black box. Their only difference is that you have information about the program code in case of the "white box", while you don't have it in case of the "black box". There also exists the so called "gray box" method when you know the program structure but these data are not used in the testing itself.

When performing dynamic testing, you also have to minimize the influence of instrumentation on execution of the program being tested (temporal characteristics, resources consumed, or program errors).

Dynamic testing allows you to make sure that the product works well or reveals errors showing that the program doesn't work. The second goal of the testing is a more productive one from the viewpoint of quality enhancement, as it doesn't allow you to ignore the program drawbacks. But if no defects have been revealed during the testing, it doesn't necessarily mean there are no any at all. Even 100% code coverage with tests doesn't mean there are no errors in the code, since dynamic testing cannot reveal logic errors. Another important aspect is whether testing utilities have errors themselves.

A separate task third-party utilities may be used to solve is creation of input test data. Some utilities use the following method: they mark the input data and track their movement as the program is being executed. At the next iteration of test launch the utility will generate a new set of input parameters, and son on - until it gets the needed result.

Thus, dynamic analysis has both weak and strong points.

The pros of dynamic code analysis are the following:

  • In most cases, generation of false positives is impossible, as error detection occurs right at the moment of its occurrence; thus, the error detected is not a prediction based on the analysis of the program model, but a statement of the fact of its occurrence;
  • Usually you don't need the source code; it allows you to test proprietary code.

These are the cons of dynamic code analysis:

  • Dynamic analysis detects defects only on the route defined by the concrete input data; defects in other code fragments won't be found;
  • It cannot check the correctness of code operation, i.e. if the code does what it must;
  • Significant computational resources are required to perform the testing;
  • Only one execution path can be checked at each particular moment, which makes you run the test many times to provide as complete testing as possible;
  • When the test is run on a real processor, execution of incorrect code may have unpredictable consequences.

Having its own weak and strong points, the dynamic analysis technology can be used most effectively together with the static analysis technology.


Popular related articles
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 22 2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
PVS-Studio ROI

Date: Jan 30 2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
The Evil within the Comparison Functions

Date: May 19 2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
The way static analyzers fight against false positives, and why they do it

Date: Mar 20 2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
The Ultimate Question of Programming, Refactoring, and Everything

Date: Apr 14 2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
The Last Line Effect

Date: May 31 2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
Appreciate Static Code Analysis!

Date: Oct 16 2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
PVS-Studio for Java

Date: Jan 17 2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…

Comments (0)

Next comments
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →