The TotalView Memory Debugger

TotalView Memory Debugging Benefits

  • Built into the debugger so you don't have to switch tools
  • Lets you interactively locate memory problems
  • Breaks wasteful cycle of run-to-completion, report, fix, run-to-completion, fix...
  • Does not instrument your code or rewrite libraries
  • Graphically displays memory use, allocations, and leaks
  • Provides any-time views of memory status, not just post-mortem reports
  • Easily locates allocations that cause leaks
  • Stops execution when program incorrectly uses heap
  • Lets you hone in on what's important by filtering out what you do not want to see
  • Saves and imports memory state so you can compare states at different times

TotalView Debugger has an integrated, interactive memory debugger that helps you find and eliminate memory problems as you debug your code.

It's built into the debugger, it's less intrusive than other memory analysis tools, and you don't have to re-compile. It's a whole new experience in debugging memory problems.

Working with C, C++, and Fortran code, the Memory Debugger lets you watch for memory leaks, monitor the amount of memory your program uses, and track how it allocates and frees memory. You can move through any debugging session, looking for leaks, and tracking heap allocations and deallocations while getting the memory usage information you want. Far more useful and convenient than post-mortem reports, our memory debugger reports (or views) show status and leaks at any time. You get all the information about the heap, whenever you need it. And you can stop execution, check for problems, test fixes, and then continue debugging.
 

Displaying Heap Information

Heap status views give you an easy way to track your heap activity, make leaks visible, and drill down to specifics. The graphical heap browser makes it easy to interpret your heap activity. In this graphical view, color-coded bars show allocated, deallocated, and leaked memory blocks. You can select individual bars to get more detailed information, including the source line on which the block was allocated or deallocated. Zooming out immediately shows you how fragmented your heap is and how allocations and leaks relate to your program's activities.

Showing Memory Leaks

Leak detection is easy. Heap status views display leaks in red. Leak detection views organize this information hierarchically, showing you just your leaks. TotalView tells you, down to the line number, how many bytes were leaked, so you can concentrate on your biggest leaks and ignore those that are mere nuisances.
 

Filtering Heap Information

The Memory Debugger gives you clear pictures of memory problems by eliminating the clutter and confusion caused by irrelevant data. For example, filters let you hide leaks originating in libraries over which you have no control.

You can create filters in two ways. The easier is to select a block in a view, right-click, and select the filter command. This removes all blocks originating from that place in your code. The second lets you enter information in a dialog box. For example, you could tell the Memory Debugger that it should only show information from one or two libraries.
 

Viewing Memory Usage

The Memory Debugger can show you the amount of memory that your program uses. This information lets you quickly identify when memory use isn't what you expect it to be. Here's a figure that has two of the ways you can see this information.

For each process, program, or library, TotalView shows the amount of memory used by the text and data areas, as well as the heap, stack, and virtual memory sizes. Watch these windows over time, and you'll notice when memory usage gets out of hand for a process or your program. For more detailed information, you can tell the Memory Debugger to display information in tables.
 

Reporting Memory Events

The Memory Debugger tracks memory events and can stop and display event information before the event occurs. You can then tell the TotalView debugger to skip over the instruction that might cause memory-related crashes.

Some of the events that TotalView detects:

  • Free not allocated: An application calls free() with an address not existing in any block allocated on the heap.
  • Realloc not allocated: An application calls realloc() with an address not at any block allocated on the heap.
  • Address not at start of block: free() or realloc() address not at the start of a previously allocated block.
  • Free interior pointer: The address being freed is within an allocated block.
  • Deallocation notification: When your program deallocates a block, stop execution.
  • Out of Memory: Your program couldn't allocate the memory block. While program's should check for this, not all do.

 

Checking for Dangling Pointers

Figuring out how your program uses and shares memory is usually quite complicated. TotalView helps by telling you the status of the memory your program's pointers are pointing to.

Whenever you stop your application and look at a pointer, TotalView gives you information about the pointer's memory. For example, the memory might be:

  • Dangling--allocated and then freed
  • Allocated--allocated
  • Interior--pointing to the middle of a block

Because TotalView displays this information when it displays variables, you'll know instantly if your program is accessing old or incorrect data.


 

Tagging Memory Blocks

Explore the state of any block, find where it was allocated or deallocated, or even tag a block. Tagging tells TotalView to raise an event when the tagged block is freed or reallocated. You can also tell the Memory Debugger to remember a block. This makes it easy to look at the block's state whenever you want. TotalView provides detailed information about the pointers that direct you to memory blocks in the heap. If you are viewing a pointer to a heap block, you can bring up the Block Properties Window to see detailed information about this block.


 

Using Baselines

Baselines let you see what has changed from one point in your program to another. After setting a baseline, you let your program execute. After you stop execution, the Memory Debugger can generate a summary of your program's changes or of any leaks that have occurred. You can then let your program execute for a while, then halt it again to continue to see information from the baseline.

If you need to obtain more details, just open the Memory Debugger and display a Leak Detection or Heap Status View. While these views normally show all information that the Memory Debugger has collected, each of these views has a Relative to Baseline checkbox that limits the information being displayed to the allocations and leaks that occurred since you set the baseline.
 

Comparing Saved Memory States

The Memory Debugger lets you save memory information to disk. At a later time, you can read this information back in and compare that old state with the current state or with two older states. In most cases, you can create views of this saved information exactly as if it were the data for an executing program. In addition, you can create a memory compare view that shows you the differences between two memory states.

Comparing the current state to a baseline is valuable when trying to understand how your program is using memory.
 

Exporting Memory Information

If you need to look at information with a different tool, in a different way, or in a different context, use the View Export feature. Export various memory debugging views to text or HTML for later viewing or printing. You can export most views.
 

Showing Corrupted Memory

The Memory Debugger can surround allocations with a small amount of additional memory. It will also write a pattern into this memory. If your program overwrites this memory, you can tell that a problem occurred either by asking for a report or by an event notification when your program deallocates a guarded block.


 

Advanced Memory Debugging Features

The toughest memory bugs are those that cause wrong answers. For these kinds of bugs, you'd much rather have your program crash and then analyze what caused the problem. For these and other reasons, TotalView offers many advanced features, including:

  • Memory block painting, which helps you see if your program is accessing uninitialized areas of memory. Painting is used most often to detect when your program is using deallocated memory.
  • Memory hoarding, which tells the Memory Debugger to hold onto memory after your program frees it. This lets your program keep running and often lets you discover code that is trying to write into memory that it thinks is freed.