Viva64: working up of 64-bitapplicationsAuthor: Evgeniy RyzhkovDate: 14.12.2006At present, Viva64 and VivaMP software prod...
•   orientation exceptionally towards the search of problems in the 64 bit code during the 32                             ...
The distributive Viva64 includes a test example PortSample - a project for Visual Studio 2005, whichcontains a simple prog...
project folder. For the created file the analyzer will be started that will carry out the code check. After               ...
if (IsX64Platform()) {       maxFrameCountInBuffer = 2000;   } else {       maxFrameCountInBuffer = 100;   }   size_t buff...
domainWidth, domainHeigh, domainDepth for the type ptrdiff_t or in the usage of the explicit typeconversation. In all the ...
Upcoming SlideShare
Loading in …5
×

Viva64: working up of 64-bit applications

392 views

Published on

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.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
392
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Viva64: working up of 64-bit applications

  1. 1. Viva64: working up of 64-bitapplicationsAuthor: Evgeniy RyzhkovDate: 14.12.2006At present, Viva64 and VivaMP software products are included in PVS-Studio as parts of it and are nolonger distributed as separate applications. Please use PVS-Studio program to obtain the necessarypossibilities of code verification.AbstractViva64 - is a tool for searching of errors and possible problems at C/C ++ code at the applications port onthe 64-bit platform. Nowadays when the necessity of the 64-bit versions software output is realized bythe most of the developers, it is too important to be sure of the working up product quality. Even if thetraditional 32-bit version of your product has been tested carefully, its portability on the 64-bit platformmay reveal some unexpected problems. Some separate items are devoted to the applications portabilityproblems, and this one tells how to provide the necessary level of the code quality with the help thestatic analyzer Viva64.The main resourcesCame to the necessity of the existing applications port on the new 64-bit system, the softwaredevelopers meet with unusual problems. The programs that have been functioning like clock-watch foryears begin to behave themselves indefinitely. Certainly a program has more main memory. Althoughduring processing more data then earlier ones, the application may hang up, crash, or, whats worse togive out files with stuff instead of ones with the results of its work. The reason of it is in the change ofsome 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 compilerstandard expressions is impossible. The compiler cant give out warning messages at all potentiallyincorrect 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 supports 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 isdistinguished on principle by:
  2. 2. • orientation exceptionally towards the search of problems in the 64 bit code during the 32 64-bit 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 neednt 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.Lets know how it works.Installation and setupOne can download the analyzer from the site www.Viva64.com. The evaluation version allowsappreciating completely its power. The installation is not difficult, thats why a user could startinstallation at ones, if it were an ordinary code analyzer. However there is the only most importantadjustment for a user in Viva64 - is an input dialogue of the authorized information. But this adjustment a64will 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 oncestarting to work.What well do. 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 othersettings.
  3. 3. The distributive Viva64 includes a test example PortSample - a project for Visual Studio 2005, whichcontains a simple program, demonstrating some classical errors. This example is installed separatelyfrom the Viva64 folder Windows program menu.Adjust this example.Functioning principle of Viv Viva64Open, compile and start PortSample 32 bit version. In Visual Studio you should choose the type of the 32-bitplatform 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. Picture 2: Test example window.And now lets compile and start 64 bit version of the same example, so choose the plat 64-bit platform x64 in theproject Visual Studio adjustments. After clicking the button "Run" the program will behaveunpredictably and probably will crash (it depends of the computer). Its time for Viva64 to demonstrateitself.Open the file V1XX.cpp and choose the command in Viva64 menu"Check current file". Firstly, itll carry out the preprocessing for macro determination opening, switchingon the header files and etc. As a preprocessing result well get file with the expanding ".i", which is in the
  4. 4. 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 Studio2005. Pay attention that you may carry out file analysis just for the platform x64. In case of file check for justanother platform (for example, Win32) it will be sent a message about error. It means that for differentplatforms it is possible to use different ways of carrying out the program, which are set with the he of helpthe #ifdef/#endif constructions.As far as for Viva64 analyzer work is necessary to carry out preprocessing, so one should make sure thatthe file is compiled for the platform x64 correctly, without messages about errors.The usage of Viva64: detect, analysis and errors correction in the codeTo proceed directly with the errors detect at the open example PostSample one should choose "CheckCurrent Project". Firstly, it will be started the preprocessor, and then the analyzer. The results of itswork are shown in the output window (picture 3). e Picture 3: Output Window.And this is the first:error V101: Implicit assignment type conversion to memsize type.Lets look at the code in this place. unsigned imageWidth = 1000; unsigned imageHeght = 1000 1000; unsigned bytePerPixel = 3; unsigned maxFrameCountInBuffer;
  5. 5. 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 variablemaxFrameCountInBuffer 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 (buffersize), but ... well get only 32-bit one. As a result the variable bufferSize will never expend 4 Gb. Althoughit itself is a 64-bit type. Pay attention that the compiler gives nothing on this line even at the highestdiagnostics level. And Viva64 says about the error here. If you are not sure that you absolutely realizethe types digit capacity problem, push F4, and the embedded help system will be opened Viva64, whereis given the detailed error description with the recommendations of its correction.Lets continue studying the example, so push F4 once more. Move to the message:error V102: Usage non memsize type for pointer arithmetic.Lets 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; // 71Here is another problem. From the error description we see that for the pointer arithmetic is used thetype not intended for it. In this case the pointer arithmetic is carried out with 32-bit type int, but itshould be used 64-bit one. Data types, using for the work with the pointers, and also for the keeping ofthe object sizes (for examples, arrays) in Viva64 are called memsize-types. At the reference system thememsize-types usage is examined carefully.Lets look in the help system how to correct the present error. Here are given advices how to change thetypes, which take part in such arithmetic. The example correction is in the change of the variable type
  6. 6. domainWidth, domainHeigh, domainDepth for the type ptrdiff_t or in the usage of the explicit typeconversation. In all the analyzer will give out more than dozens error messages at the PostSampleproject.And what is the compiler? The compiler Microsoft Visual C++ 2005 with the switched on diagnostics ofthe 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 analyzerViva64. This leads that the most errors stay undetected during the applications port on the 64-bitplatform without using Viva64.Viva64s position in the process of the software working upThere are two ways of Viva64 usage at the working up process: in the case of the prepared 32-bitapplication 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 workingup, but to use Viva64 for the working up code control. Moreover one may check as well as the wholeproject 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 doesnt solve all the problems, appearing at the 64-bit softwareenduring: • Viva64 cant 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, shouldnt consider thatthe application has been already prepared and it doesnt need diagnostics.Although Viva64 can really raise the quality of the working up software, enduce the error number andhasten the time of the product output at the market.

×