Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

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

close form
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

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

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

>
>
>
Viva64: working up of 64-bit applicatio…

Viva64: working up of 64-bit applications

Dec 14 2006

Viva64 - is a tool for searching of errors and possible problems at C/C ++ code at the applications port on the 64-bit platform. Nowadays when the necessity of the 64-bit versions software output is realized by the most of the developers, it is too important to be sure of the working up product quality. Even if the traditional 32-bit version of your product has been tested carefully, its portability on the 64-bit platform may reveal some unexpected problems. Some separate items are devoted to the applications portability problems, and this one tells how to provide the necessary level of the code quality with the help the static analyzer Viva64.

At present, Viva64 and VivaMP software products are included in PVS-Studio as parts of it and are no longer distributed as separate applications. Please use PVS-Studio program to obtain the necessary possibilities of code verification.

The main resources

Came to the necessity of the existing applications port on the new 64-bit system, the software developers meet with unusual problems. The programs that have been functioning like clock-watch for years begin to behave themselves indefinitely. Certainly a program has more main memory. Although during processing more data then earlier ones, the application may hang up, crash, or, what's worse to give out files with stuff instead of ones with the results of its work. The reason of it is in the change of some data types dimensions (primarily pointers). However to find out areas in the programs code, where of the code fulfillment sequence has changed because of it, with the help of the compiler standard expressions is impossible. The compiler can't give out warning messages at all potentially incorrect constructions, although a programmer has to find them out.

The code static analyzer Viva64 comes to the aid, integrating into Visual Studio 2005, it allows:

  • to detect incorrect construction at the code (from the 64-bit support's point of view);
  • to give an exact and complete diagnostics up to the line number;
  • to make navigation over the code incorrect areas;
  • to analyze the after-effects, to which may lead the error, with the help of the full reference system, integrating into MSDN;
  • to point out how to correct the errors with the help of the examples from the documentation;
  • to carry out code analysis of the whole project or solution (in the Microsoft Visual Studio terminology) , but not only separate files.

Viva64 - is the first in world code analyzer on the compatibility with the 64-bit systems in the world. Despite there existed early and exist now some other code analyzers (as a rule link-like ones), Viva64 is distinguished on principle by:

  • orientation exceptionally towards the search of problems in the 64-bit code during the 32-bit programs port as well as during the new applications working up.
  • total integration with Microsoft Visual Studio - files analysis, navigation over the code, help system.
  • minimum setup - one needn't study settings documentation, choose check levels, or set the numbers of the analyzing rules to work with the analyzer.
  • the analyzer is ready for work just after its installation.

Let's know how it works.

Installation and setup

One can download the analyzer from the site www.Viva64.com. The evaluation version allows appreciating completely its power. The installation is not difficult, that's why a user could start installation at ones, if it were an ordinary code analyzer. However there is the only most important adjustment for a user in Viva64 - is an input dialogue of the authorized information. But this adjustment will be necessary only after you can estimate all the possibilities of the tool.

As we have already said Viva64 integrates in Microsoft Visual Studio 2005 (picture 1) and allows at once starting to work.

What we'll do.

a0002_Viva64_-_working_up_of_64-bit_applications/image1.png

Picture 1: Viva64 Integration in Microsoft Visual Studio 2005.

Attention! If it is necessary, a user may consult with the embedded help system about some other settings.

The distributive Viva64 includes a test example PortSample - a project for Visual Studio 2005, which contains a simple program, demonstrating some classical errors. This example is installed separately from the Viva64 folder Windows program menu.

Adjust this example.

Functioning principle of Viva64

Open, compile and start PortSample 32-bit version. In Visual Studio you should choose the type of the platform Win32 and menu command "Build". After the example start switch on all the checkboxes (picture 2) and click the button "Run". The program will function correctly and send the message "Done". At the same time all chosen functions VXXX() with demonstrating code will be called.

a0002_Viva64_-_working_up_of_64-bit_applications/image2.png

Picture 2: Test example window.

And now let's compile and start 64-bit version of the same example, so choose the platform x64 in the project Visual Studio adjustments. After clicking the button "Run" the program will behave unpredictably and probably will crash (it depends of the computer). Its time for Viva64 to demonstrate itself.

Open the file V1XX.cpp and choose the command in Viva64 menu

"Check current file". Firstly, it'll carry out the preprocessing for macro determination opening, switching on the header files and etc. As a preprocessing result we'll get file with the expanding ".i", which is in the project folder. For the created file the analyzer will be started that will carry out the code check. After which the results of the analyzer work will be set in the window of the ambience output Visual Studio 2005. Pay attention that you may carry out file analysis just for the platform x64. In case of file check for another platform (for example, Win32) it will be sent a message about error. It means that for different platforms it is possible to use different ways of carrying out the program, which are set with the help of the #ifdef/#endif constructions.

As far as for Viva64 analyzer work is necessary to carry out preprocessing, so one should make sure that the file is compiled for the platform x64 correctly, without messages about errors.

The usage of Viva64: detect, analysis and errors correction in the code

To proceed directly with the errors detect at the open example PostSample one should choose "Check Current Project". Firstly, it will be started the preprocessor, and then the analyzer. The results of its work are shown in the output window (picture 3).

a0002_Viva64_-_working_up_of_64-bit_applications/image3.png

Picture 3: Output Window.

And this is the first:

error V101: Implicit assignment type conversion to memsize type.

Let's look at the code in this place.

  unsigned imageWidth = 1000;
  unsigned imageHeght = 1000;
  unsigned bytePerPixel = 3;
  unsigned maxFrameCountInBuffer;
  if (IsX64Platform()) {
    maxFrameCountInBuffer = 2000;
  } else {
    maxFrameCountInBuffer = 100;
  }
  size_t bufferSize = imageWidth * imageHeght *            // 34
                      bytePerPixel * maxFrameCountInBuffer;

The error is given on the line with the declaration of the variable bufferSize. We see that the variable maxFrameCountInBuffer for 64-bit platform has a value 2000.

This is admissible, because after the multiplying of all the variables we expect to get 64-bit figure (buffer size), but ... we'll get only 32-bit one. As a result the variable bufferSize will never expend 4 Gb. Although it itself is a 64-bit type. Pay attention that the compiler gives nothing on this line even at the highest diagnostics level. And Viva64 says about the error here. If you are not sure that you absolutely realize the types digit capacity problem, push F4, and the embedded help system will be opened Viva64, where is given the detailed error description with the recommendations of its correction.

Let's continue studying the example, so push F4 once more. Move to the message:

error V102: Usage non memsize type for pointer arithmetic.

Let's check the code which is at the line 71:

  int domainWidth;
  int domainHeght;
  int domainDepth;
  ...  
  char *buffer;
  ...  
  char *current = buffer;
  char *end = buffer;
  end += domainWidth * domainHeght * domainDepth; // 71

Here is another problem. From the error description we see that for the pointer arithmetic is used the type not intended for it. In this case the pointer arithmetic is carried out with 32-bit type int, but it should be used 64-bit one. Data types, using for the work with the pointers, and also for the keeping of the object sizes (for examples, arrays) in Viva64 are called memsize-types. At the reference system the memsize-types usage is examined carefully.

Let's look in the help system how to correct the present error. Here are given advices how to change the types, which take part in such arithmetic. The example correction is in the change of the variable type domainWidth, domainHeigh, domainDepth for the type ptrdiff_t or in the usage of the explicit type conversation. In all the analyzer will give out more than dozens error messages at the PostSample project.

And what is the compiler? The compiler Microsoft Visual C++ 2005 with the switched on diagnostics of the port problems (the key /Wp64) and the maximum level of the diagnostics messages (the key /W4) gives out for the entire project... only three diagnostics messages, that are also caught by the analyzer Viva64. This leads that the most errors stay undetected during the applications port on the 64-bit platform without using Viva64.

Viva64's position in the process of the software working up

There are two ways of Viva64 usage at the working up process: in the case of the prepared 32-bit application on the 64-bit platform and in the case of the working up new 64-bit application.

The 32-bit application port should be carried out in such a way:

  • prepare the project in the Studio Visual 2005, which is build correctly for the platform Win32;
  • add a new platform x64 to the project, build the project, fixing all compiler errors;
  • switch on the maximum warning level (/Wp64, Detect 64-Bit Portability Issues), correct the errors;
  • with the help of Viva64 carry out all possible errors detect, analyze them and correct;
  • move to the application testing.

In the case of a new 64-bit application enduring it is reasonable not to wait for the end of the working up, but to use Viva64 for the working up code control. Moreover one may check as well as the whole project or decision, and the separate more important code parts.

Viva64 is not a silver bullet and what is next...

It is necessary to notice that Viva64 doesn't solve all the problems, appearing at the 64-bit software enduring:

  • Viva64 can't replace full testing;
  • Viva64 knows about the most errors, but not about all;
  • Viva64 should be used by the developer, understanding all work computer principles.

In other words, if you correct all the errors at the code with the help of Viva64, shouldn't consider that the application has been already prepared and it doesn't need diagnostics.

Although Viva64 can really raise the quality of the working up software, enduce the error number and hasten the time of the product output at the market.

Popular related articles


Comments (0)

Next comments next comments
close comment form