Managing Memory Errors with Intel? Parallel Inspector XE
___________________________________________________________________
Intel? Academic Community
Disclaimer
The information contained in this document is provided for informational
purposes only and represents the current view of Intel Corporation ("Intel") and
its contributors ("Contributors") on, as of the date of publication. Intel and
the Contributors make no commitment to update the information contained in this
document, and Intel reserves the right to make changes at any time, without
notice.
DISCLAIMER. THIS DOCUMENT, IS PROVIDED "AS IS." NEITHER INTEL, NOR THE
CONTRIBUTORS MAKE ANY REPRESENTATIONS OF ANY KIND WITH RESPECT TO PRODUCTS
REFERENCED HEREIN, WHETHER SUCH PRODUCTS ARE THOSE OF INTEL, THE CONTRIBUTORS,
OR THIRD PARTIES. INTEL, AND ITS CONTRIBUTORS EXPRESSLY DISCLAIM ANY AND ALL
WARRANTIES, IMPLIED OR EXPRESS, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT, AND ANY
WARRANTY ARISING OUT OF THE INFORMATION CONTAINED HEREIN, INCLUDING WITHOUT
LIMITATION, ANY PRODUCTS, SPECIFICATIONS, OR OTHER MATERIALS REFERENCED HEREIN.
INTEL, AND ITS CONTRIBUTORS DO NOT WARRANT THAT THIS DOCUMENT IS FREE FROM
ERRORS, OR THAT ANY PRODUCTS OR OTHER TECHNOLOGY DEVELOPED IN CONFORMANCE WITH
THIS DOCUMENT WILL PERFORM IN THE INTENDED MANNER, OR WILL BE FREE FROM
INFRINGEMENT OF THIRD PARTY PROPRIETARY RIGHTS, AND INTEL, AND ITS CONTRIBUTORS
DISCLAIM ALL LIABILITY THEREFOR. INTEL, AND ITS CONTRIBUTORS DO NOT WARRANT THAT
ANY PRODUCT REFERENCED HEREIN OR ANY PRODUCT OR TECHNOLOGY DEVELOPED IN RELIANCE
UPON THIS DOCUMENT, IN WHOLE OR IN PART, WILL BE SUFFICIENT, ACCURATE, RELIABLE,
COMPLETE, FREE FROM DEFECTS OR SAFE FOR ITS INTENDED PURPOSE, AND HEREBY
DISCLAIM ALL LIABILITIES THEREFOR. ANY PERSON MAKING, USING OR SELLING SUCH
PRODUCT OR TECHNOLOGY DOES SO AT HIS OR HER OWN RISK.
Licenses may be
required. Intel, its contributors and others may have patents or pending patent
applications, trademarks, copyrights or other intellectual proprietary rights
covering subject matter contained or described in this document. No license,
express, implied, by estoppels or otherwise, to any intellectual property rights
of Intel or any other party is granted herein. It is your responsibility to seek
licenses for such intellectual property rights from Intel and others where
appropriate. Limited License Grant. Intel hereby grants you a limited copyright
license to copy this document for your use and internal distribution only. You
may not distribute this document externally, in whole or in part, to any other
person or entity. LIMITED LIABILITY. IN NO EVENT SHALL INTEL, OR ITS
CONTRIBUTORS HAVE ANY LIABILITY TO YOU OR TO ANY OTHER THIRD PARTY, FOR ANY LOST
PROFITS, LOST DATA, LOSS OF USE OR COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES, OR FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF YOUR USE OF THIS DOCUMENT OR RELIANCE UPON THE INFORMATION CONTAINED
HEREIN, UNDER ANY CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF
WHETHER INTEL, OR ANY CONTRIBUTOR HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH
DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE
ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.
Intel and Intel logo are trademarks or registered trademarks of Intel
Corporation or its subsidiaries in the United States and other countries.
*Other names and brands may be claimed as the property of others.
Copyright
? 2010, Intel Corporation. All Rights Reserved.Table of Contents
Parallelism Tools –
Checking for Memory Access
Violations 1
Activity 1 - Choose, Build and Run
a project 1
Activity 2 - Configure and Run
Analysis 8
Activity 3 - Manage result data
after analysis 12
Activity 4 - Resolve, Rebuild and
Rerun 17
Parallelism Tools – Checking for Memory Access
violations
Activity 1 – Choose, Build and Run a Project
Time |
Ten |
Objective |
|
The
application is a 2-D ray tracer/renderer called tachyon written in C++.
The code is small enough that you may be able to identify potential memory
access violations by visual inspection. If you identify and make a list of
problems, check your list with the list that Parallel Inspector XE identifies.
Choose a project
- With
Windows Explorer*, locate the samples folder in the Parallel
Inspector XE directory. - From the
Microsoft Visual Studio* menu, choose File > Open >
Project/Solution. - In the Open Project dialog box, open
the filesamples\windows\tachyon_insp_xe\vc8\tachyon_insp_xe.sln fileby double-clicking it.This
should now display tachyon_insp_xe solution in the
Solution Explorer.
- In the
Solution Explorer, right-click the
find_and_fix_memory_errors project and choose Set as
Startup Project from among the menu options.
Build a project
- We first
need to verify debug mode is configured to produce the best results. So in the
Solution Explorer, right-click the
find_and_fix_memory_errors project and choose
Properties to display the Property Pages
dialog box. - Verify
the Configuration drop-down list is set to
Debug or Active(Debug).
- In the left pane, choose Configuration
Properties > C/C++ > General. - Verify the Debug Information
Format is set to Program Database (/Zi) or
Program Database for Edit & Continue (/ZI). - In the left pane, choose Configuration
Properties > C/C++ > Optimization. - Verify the Optimization
field is set to Disabled (/Od). - In the left pane, choose Configuration
Properties > C/C++ > Code Generation. - Verify the Runtime Library
field is set to Multi-threaded DLL (/MD) or
Multi-threaded Debug DLL (/MDd). - In the
left pane, choose Configuration Properties > Linker >
Debugging. - Verify the Generate Debug
Info field is set to Yes (/DEBUG). - Verify
the project is set to build in debug mode. Click the Configuration
Manager button and verify the Active solution
configuration drop-down list is set to Debug. - Click the Close button to
close the Configuration Manager dialog box. - Click the OK button to close
the Property Pages dialog box.
Run a project
- From the Visual Studio* menu, choose
Debug > Start Without Debugging. - When the Visual Studio* IDE responds this
project is out of date, click Yes to build the project. - The application is run but the application
output window will be empty and grey because of memory errors in the code! - You verified the find_and_fix_memory_errors
project is set to produce the most accurate, complete results, compiled and
linked the project and ensured the resulting find_and_fix_memory_errors.exe
file runs on your system outside the Inspector XE.
Activity 2 – Configure and Run analysis
Time |
Ten |
Objective |
|
Configure a memory error
analysis
Analysis folder and choose the Detect Memory
Problems analysis type to display a window similar to the following.
(If necessary, click the icon
in the Details region to display analysis type
characteristics.)
Use the Navigation toolbar | |
The Analysis Types region | |
Use the checkbox(es) and drop-down field(s) | |
The Details region shows | |
Use the Command toolbar to |
- After you finish experimenting, ensure your
Analysis Type window resembles the following window: - You
chose a preset analysis type of intermediate scope to detect memory errors in
the find_and_fix_memory_errors.exe file.
Run
a memory error analysis
- Click
the Analyze button on the Analysis Type
window to:
- Execute
the find_and_fix_memory_errors.exe file. - Identify
memory errors that may need handling. - Collect
the result in a folder in the tachyon_insp_xe\vc8\My Inspector XE 2011
Project - find_and_fix_memory_errors folder. - Finalize
the result (convert symbol information into filenames and line numbers,
perform duplicate elimination, and form problem sets).
- During
collection, the Inspector XE displays a Collection Log window
similar to the following:
The Visual Studio* IDE offers a pointer to | |
The result name appears in the tab. Here,
| |
The Collection Log pane This tutorial does not cover examining and | |
The Collector Messages You can control where application output |
Activity 3 – Manage result data after analysis
Time |
Fifteen |
Objective |
|
After
analysis (both collection and finalization) completes successfully, the
Inspector XE displays the Summary window:
Choose
Problem Set
Start
exploring a memory error.
Interpret
the Summary window
The Summary window is the Notice the arrow to the left of the | |
Think of the Problem Sets | |
The Observations in Problem Here, the Inspector XE selected the | |
This tutorial does not cover manipulating | |
The Summaries/Subsets pane This tutorial does not cover searching for |
Choose
a problem set
Double-click the data row for the
Mismatched allocation/deallocation problem set source file to
display the Sources window, which provides more visibility into
the error:
Interpret
Result Data
In
this section, we will see how to determine the cause of the detected memory
error.
To
interpret the Sources window:
Like the pane on the The Allocation site | |
The Related Observation | |
The Focus Observation Code | |
This tutorial does not cover manipulating |
To
interpret window icons:
Icon |
Meaning | |
This observation is the focus observation. |
Observation source code is available for | |
This observation is related to the focus |
To
understand the issue:
Look at the code in the Focus Observation
Code pane and the Related Observation Code pane.
The code in the Allocation site
observation in the Related Observation Code pane contains a new
allocator, while the code in the Mismatched deallocation site
observation in the Focus Observation Code pane contains a free() deallocator.
A Mismatched
allocation/deallocation problem occurs when you attempt a deallocation
with a function that is not the logical reflection of the allocator. In the C++
programming language, the following are matched reflections:
- newanddelete
- new[]anddelete[]
- malloc()andfree()
Only the matching deallocation technique is
uniquely aware of all the memory allocation techniques and internal data storage
used by the allocation technique. Using the wrong deallocation technique will
almost certainly corrupt memory reclamation, its sole job.
Activity 4 – Resolve, Rebuild and Rerun
Time |
Twenty |
Objective |
|
Resolve
an issue:
- Double-click the
highlighted code in the Focus Observation Code pane to open
the find_and_fix_memory_errors.cpp source file in a separate tab where you can
edit it with the Visual Studio* editor:
- Comment
free(drawing);and uncomment//delete
drawing;:
- Click
the r000mi2 tab to redisplay the Sources
window:
- Click
the Summary button to redisplay the Summary
window:
Resolve
another issue:
Now resolve another detected memory error by
following the below steps:
Chooseanother problem
set:
In the Problem Sets pane on the
Summary window, double-click the data row for a Memory
Leak problem set to display the Sources window:
To access more information on
interpreting and resolving problems:
- Right-click the
Allocation site observation in the Observations in
Problem Set pane. - Choose
Explain Problem to display Inspector XE Help information for
the Memory Leak problem type.
To interpret result data:
A Memory leak problem occurs
when a block of memory is allocated and never released.
The Allocation site observation
represents the location from which the memory block was allocated. Here, the
source code shows a malloc()
allocator.
Scroll the source code to near line 180:
The issue is obvious: The free()
call that releases the memory allocated by the malloc()
call is commented out.
To resolve memory leak problems (while avoiding
related mismatched allocation/deallocation problems): Match anymalloc()call
with afree()call,
anewwith adelete, and
anew[]with adelete[]as
soon as all use of the allocated space has occurred, but not sooner. Never mix
and match.
Be aware:
- If you
do not deallocate soon enough, you waste space the program might need. - If you
deallocate too soon, you may do one of the following:- Corrupt your
memory allocator or the space it manages when you later write to that space. - End up
with bogus data if you later read that space when you previously returned it
to the memory allocator.
- Corrupt your
- Make
sure you free any space allocated within a function prior to exiting that
function, or else make sure the function caller does the deallocation for the
called function.
To resolve the issue:
- Click
the find_and_fix_memory_errors.cpp tab to redisplay the
find_and_fix_memory_errors.cpp source file in the Visual Studio*
editor:
- Uncomment//free(local_mbox);:
- Click
the r000mi2 tab to redisplay the Sources
window:
Rebuild
and Rerun Analysis
To see if
your edits resolved the memory errors:
- Rebuild
the project with your edited source code. - Run
another analysis. - Start
managing result data after collection.
To
rebuild the project:
- Right-click the
find_and_fix_memory_errors project in the Solution
Explorer. - Choose Build.
To
run another analysis:
From the
Visual Studio* menu, choose Tools > Intel Inspector
XE 2011 > Analyze As... > Memory Error
Analysis / Detect Memory Problems to run another analysis of the same
analysis type:
Notice the
image now displays.
To
start managing result data after collection:
After
analysis (both collection and finalization) completes successfully, the
Inspector XE displays the Summary window:
Notice the
Inspector XE:
- Created
a new result tab. - No
longer detected Mismatched allocation/deallocation and
Memory leak problems.
Try fixing
the remaining problem set(s) yourself.
Intel 编译器 内存安全检查 真心的很详细 转,布布扣,bubuko.com