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.

Why is There an Expression System?<br />

invocation and polymorphism. (This is discussed in “Using C++” on<br />

page 384.)<br />

Calling Functions: Problems and Issues<br />

Unfortunately, calling functions in the expression system can cause problems.<br />

Some of these problems are:<br />

� What happens if the function has a side-effect. For example, suppose<br />

you have enter my_var[cntr] in one row in an Expression List Window, followed<br />

by my_var[++cntr] in another? If cntr equals 3, you’ll be seeing<br />

the values of my_var[3] and my_var[4]. However, since cntr now equals 4,<br />

the first entry is no longer correct.<br />

� What happens when the function crashes (after all you are trying to debug<br />

problems), doesn’t return, returns the wrong value, or hits a breakpoint?<br />

� What does calling functions do to your debugging interaction if evaluation<br />

takes an excessive amount of time?<br />

� What happens if a function creates processes and threads? Or worse,<br />

kills them?<br />

In general, there are some protections in the code. For example, if you’re<br />

displaying items in an Expression List Window, <strong>TotalView</strong> avoids being in an<br />

infinite loop by only evaluating items once. This does mean that the information<br />

is only accurate at the time at which <strong>TotalView</strong> made the evaluation.<br />

In most other cases, you’re basically on your own. If there’s a problem,<br />

you’ll get an error message. If something takes too long, you can press the<br />

Halt button. But if a function alters memory values or starts or stops processes<br />

or threads and you can’t live with it, you’ll need to restart your program.<br />

However, if an error occurs while using the Evaluate Window, pressing<br />

the Stop button pops the stack, leaving your program in the state it was in<br />

before you used the Evaluate command. However, changes made to heap<br />

variables will, of course, not be undone.<br />

Expressions in Eval Points and the Evaluate Window<br />

Expression evaluation is not limited to a Variable Window or an Expression<br />

List Window. You can use expressions within eval points and in the Tools ><br />

Evaluate Window. The expressions you type here also let you use programming<br />

language constructs. For example, here’s a trivial example of code<br />

that can execute within the Evaluate Window:<br />

int i, j, k;<br />

j = k = 10;<br />

for (i=0; i< 20; i++)<br />

{<br />

j = j + access_func(i, k);<br />

}<br />

j;<br />

This code fragment declares a couple of variables, runs them through a for<br />

loop, then displays the value of j. In all cases, the programming language<br />

constructs being interpreted or compiled within <strong>TotalView</strong> are based on<br />

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

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

Saved successfully!

Ooh no, something went wrong!