30.01.2013 Views

TotalView Users Guide - CI Wiki

TotalView Users Guide - CI Wiki

TotalView Users Guide - CI Wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Watching Memory<br />

Using Watchpoints<br />

A watchpoint tracks a memory location—it does not track a variable. This<br />

means that a watchpoint might not perform as you would expect it to when<br />

watching stack or automatic variables. For example, suppose that you want<br />

to watch a variable in a subroutine. When control exits from the subroutine,<br />

the memory allocated on the stack for this subroutine is deallocated.<br />

At this time, <strong>TotalView</strong> is watching unallocated stack memory. When the<br />

stack memory is reallocated to a new stack frame, <strong>TotalView</strong> is still watching<br />

this same position. This means that <strong>TotalView</strong> triggers the watchpoint<br />

when something changes this newly allocated memory.<br />

Also, if your program reinvokes a subroutine, it usually executes in a different<br />

stack location. <strong>TotalView</strong> cannot monitor changes to the variable<br />

because it is at a different memory location.<br />

All of this means that in most circumstances, you shouldn’t place a watchpoint<br />

on a stack variable. If you need to watch a stack variable, you will<br />

need to create and delete the watchpoint each time your program invokes<br />

the subroutine.<br />

This doesn’t mean you can’t place a watchpoint on a stack or heap variable.<br />

It just means that what happens is undefined after this memory is released.<br />

For example, after you enter a routine, you can be assured that memory<br />

locations are always tracked accurately until the memory is released.<br />

In some circumstances, a subroutine may be called from the same location. This means<br />

that its local variables might be in the same location. So, you might want to try.<br />

If you place a watchpoint on a global or static variable that is always<br />

accessed by reference (that is, the value of a variable is always accessed<br />

using a pointer to the variable), you can set a watchpoint on it because the<br />

memory locations used by the variable are not changing.<br />

Triggering Watchpoints<br />

When a watchpoint triggers, the thread’s program counter (PC) points to<br />

the instruction following the instruction that caused the watchpoint to trigger.<br />

If the memory store instruction is the last instruction in a source statement,<br />

the PC points to the source line following the statement that triggered<br />

the watchpoint. (Breakpoints and watchpoints work differently. A breakpoint<br />

stops before an instruction executes. In contrast, a watchpoint stops<br />

after an instruction executes.)<br />

Using Multiple Watchpoints<br />

If a program modifies more than one byte with one program instruction or<br />

statement, which is normally the case when storing a word, <strong>TotalView</strong> triggers<br />

the watchpoint with the lowest memory location in the modified region.<br />

Although the program might be modifying locations monitored by other<br />

watchpoints, <strong>TotalView</strong> only triggers the watchpoint for the lowest memory<br />

<strong>TotalView</strong> <strong>Users</strong> <strong>Guide</strong>: version 8.7 377

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!