To Download this article :-
memory-profiling-using-intel-system-studio.pdf (344.62 KB)
Introduction
One of the problems with developing embedded systems is the detection of memory errors; like
- Memory leaks
- Memory corruption
- Allocation / de-allocation API mismatches
- Inconsistent memory API usage etc.
These memory errors degrade performance of any embedded systems. Designing and programming an embedded application requires great care. The application must be robust enough to handle every possible error that can occur; care should be taken to anticipate these errors and handle them accordingly—especially in the area of memory.
In this article we have described how to use Intel® System Studio to find dynamic and static memory issues in any embedded application. The two approaches are complementary because no single approach can find all memory error.
Intel® System Studio
Intel® System Studio a new comprehensive integrated tool suite provides developers with advanced system tools and technologies that help accelerate the delivery of the next generation power efficient, high performance, and reliable embedded and mobile devices.
To get more information about Intel® System Studio – http://software.intel.com/en-us/intel-system-studio
Dynamic Memory Analysis
Dynamic memory analysis is the testing and evaluation of an embedded application for any memory errors during runtime.
Advantage of dynamic memory analysis: Dynamic memory analysis is the analysis of an application that is performed by executing application. For dynamic memory analysis to be effective, the target program must be executed with sufficient test inputs to analyze entire program.
Intel® Inspector 2013 for Systems
The Intel® Inspector 2013 for Systems helps developers identify and resolve memory and threading correctness issues in their unmanaged C, C++ and Fortran programs as well as in the unmanaged portion of mixed managed and unmanaged programs. Additionally the tool identifies threading correctness issues in managed .NET C# programs.
Installation, Configure and Build
You need to follow certain steps to run Inspector 2013 for Systems on an embedded platform. Please refer to article - How to use Intel® Inspector 2013 for Systems
Intel® Inspector 2013 for Systems will currently identifies following type of dynamic memory problems.
| Problem Type | Description |
|---|---|
|
Incorrect memcpy call |
When an application calls the memcpy function with two pointers that overlap within the range to be copied. |
|
Invalid deallocation |
When an application calls a deallocation function with an address that does not correspond to dynamically allocated memory. |
|
Invalid memory access |
When a read or write instruction references memory that is logically or physically invalid. |
|
Invalid partial memory access |
When a read or write instruction references a block (2-bytes or more) of memory where part of the block is logically invalid. |
|
Memory growth |
When a block of memory is allocated but not deallocated within a specific time segment during application execution. |
|
Memory leak |
When a block of memory is allocated, never deallocated, and not reachable at application exit (there is no pointer available to deallocate the block). |
|
Memory not deallocated |
When a block of memory is allocated, never deallocated, but still reachable at application exit (there is a pointer available to deallocate the block). |
|
Mismatched allocation/deallocation |
When a deallocation is attempted with a function that is not the logical reflection of the allocator used. |
|
Missing allocation |
When an invalid pointer is passed to a deallocation function. The invalid address may point to a previously released heap block. |
|
Uninitialized memory access |
When a read of an uninitialized memory location is reported. |
|
Uninitialized partial memory access |
When a read instruction references a block (2-bytes or more) of memory where part of the block is uninitialized. |
|
Cross-thread stack access |
When a thread accesses a different thread's stack |
To get more information about each type of dynamic memory problem, sample code and Possible correction strategies, please refer to Intel® Inspector 2013 for systems reference manual (Problem Type reference section).
Static Memory Analysis
Static memory analysis is the testing and evaluation of an application by examining the code without executing the application.
Advantage of static memory analysis: It examines all possible execution paths and variable values, not just those invoked during execution. Thus static memory analysis can reveal memory errors that may not manifest themselves until years after release. This aspect of static memory analysis is especially valuable in security assurance.
Intel® C++ Compiler:
Intel compiler delivers outstanding performance for your applications as they run on systems using Intel® Atom or Intel® Core™ or Xeon® processors and IA-compatible processors. The Intel® C++ Compiler can generate code for IA-32, Intel® 64, and Intel® Many Integrated Core Architecture (Intel® MIC Architecture) applications on Intel®-based Linux* system.
Configure and Build
Intel® Static Analysis can be enabled with Intel® C++ compiler using the Compiler option “-diag-enable sc [n]”. To get more information refer to article – ‘Developing secured embedded applications using Intel® System Studio’
| Problem Type | Description |
|---|---|
|
Bounds violation |
An attempt to access outside the bounds of a variable (usually an array) was found. Bounds violations can corrupt memory or read from uninitialized data, leading to unpredictable behavior. |
|
Object size overflow |
Buffer overflow error at block assignment operation.This error indicates that the destination size is too small to accommodate the data being moved to the destination. |
|
Buffer overflow through pointer |
A memory write through a pointer creates a buffer overflow. |
|
Double free |
Dynamically allocated storage, for example from new or malloc, must be freed only once. Freeing the same data twice can corrupt the heap. |
|
Insufficient memory allocation |
The size of allocated memory is less than the size of the pointed-to type of the pointer to which it is assigned. Usually, this error results from an incorrect size computation. This error often leads to a subsequent bounds violation. |
|
Reference to freed storage |
Memory is accessed after it has been deallocated. |
|
Uses address after free |
Use of pointer to deallocated storage. |
|
Incorrect memory deallocation |
An improper value was passed to a memory deallocation routine. This error indicates that the value being passed to a memory deallocation routine did not come from a call to the matching memory allocation routine. |
|
Unchecked memory allocation |
A pointer to allocated memory was not checked for null before dereference. |
The Static Analysis Problem Type Reference documents all problem types detected by the compiler when running in static analysis mode.
For more information refer to – Static Analysis Problem Type Reference manual.
Conclusion: Intel® System Studio provides you dynamic and static memory analysis feature to build robust embedded application.
