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.

Defining Eval Points and Conditional Breakpoints<br />

eval point unless, for example, you declare it in some other scope or<br />

declare it to be a static variable.<br />

Creating Conditional Breakpoint Examples<br />

The following are examples that show how you can create conditional<br />

breakpoints:<br />

� The following example defines a breakpoint that is reached whenever the<br />

counter variable is greater than 20 but less than 25:<br />

if (counter > 20 && counter < 25) $stop;<br />

� The following example defines a breakpoint that stops execution every<br />

tenth time that <strong>TotalView</strong> executes the $count function<br />

$count 10<br />

� The following example defines a breakpoint with a more complex expression:<br />

$count my_var * 2<br />

When the my_var variable equals 4, the process stops the eighth time it<br />

executes the $count function. After the process stops, <strong>TotalView</strong> reevaluates<br />

the expression. If my_var equals 5, the process stops again after the<br />

process executes the $count function ten more times.<br />

The <strong>TotalView</strong> internal counter is a “static” variable, which means that<br />

<strong>TotalView</strong> remembers its value every time it executes the eval point. Suppose<br />

you create an eval point within a loop that executes 120 times and the eval<br />

point contains $count 100. Also assume that the loop is within a subroutine.<br />

As expected, <strong>TotalView</strong> stops execution the 100th time the eval point executes.<br />

When you resume execution, the remaining 20 iterations occur.<br />

The next time the subroutine executes, <strong>TotalView</strong> stops execution after 80<br />

iterations because it will have counted the 20 iterations from the last time<br />

the subroutine executed.<br />

This isn't a bug that we're documenting as a feature. Suppose you have a<br />

function that is called from lots of different places from within your program.<br />

Because <strong>TotalView</strong> remembers every time a statement executes, you<br />

could, for example, stop execution every 100 times the function is called.<br />

In other words, while $count is most often used within loops, you can use it<br />

outside of them as well.<br />

For descriptions of the $stop, $count, and variations on $count, see “Using<br />

Built-in Variables and Statements” on page 394.<br />

Patching Programs<br />

You can use expressions in eval points to patch your code if you use the<br />

goto (C) and GOTO (Fortran) statements to jump to a different program<br />

location. This lets you do the following:<br />

� Branch around code that you don’t want your program to execute.<br />

� Add new statements.<br />

368 Chapter 16: Setting Action Points

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

Saved successfully!

Ooh no, something went wrong!