Setting the Program Counter

You might find it useful to resume the execution of a thread at some statement other than the one where it stopped. You can do this by resetting the value of the program counter (PC). For example, you might want to skip over some code, execute some code again after changing certain variables, or restart a thread that is in an error state.

Setting the PC can be crucial when you want to restart a thread that is in an error state. Although the PC icon in the tag field points to the source statement that caused the error, the PC actually points to the failed machine instruction within the source statement. You need to explicitly reset the PC to the correct instruction. (You can verify the actual location of the PC before and after resetting it by displaying it in the Stack Frame Pane or displaying interleaved source and assembler code in the Source Pane.)

In TotalView, you can set the PC of a stopped thread to a selected source line, a selected instruction, or an absolute value (in hexadecimal). When you set the PC to a selected line, the PC points to the memory location where the statement begins. For most situations, setting the PC to a selected line of source code is all you need to do.

To set the PC to a selected line:

  1. If you need to set the PC to a location somewhere within a line of source code, display the View > Source As > Interleaved command. TotalView responds by displaying the assembler code.
     
  2. Select the source line or instruction in the Source Pane. TotalView highlights.

    If you select a line in a C++ function template that has more than one instantiation, TotalView asks you to select an instantiation. See Selecting Source Lines for a description of how this works.

  3. Select the Thread > Set PC command. TotalView asks for confirmation, resets the PC, and moves the PC icon to the selected line.

When you select a line and ask TotalView to set the PC to that line, TotalView attempts to force the thread to continue execution at that statement in the currently selected stack frame. If the currently selected stack frame is not the top stack frame, TotalView asks if it can unwind the stack:

This frame is buried. Should we attempt to unwind the stack?

If you select Yes, TotalView discards deeper stack frames (that is, all stack frames that are more deeply nested than the selected stack frame) and resets the machine registers to their values for the selected frame. If you select No, TotalView sets the PC to the selected line, but it leaves the stack and registers in their current state. Since you cannot assume that the stack and registers have correct values, selecting No is not usually the right thing to do.

 
 
 
 
support@etnus.com
Copyright © 2001, Etnus, LLC. All rights reserved.
Version 5.0