Setting the Program Counter
TotalView lets you resume execution at a different statement than the one at which it stopped execution 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 symbol in the line number area points to the source statement that caused the error, the PC actually points to the failed machine instruction in 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 both source and assembler code in the Source Pane.)
In TotalView, you can set the PC of a stopped thread to a selected source line or a selected instruction. 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 in a line of source code, select the
View > Source As > Both command.
TotalView responds by displaying assembler code.
2. Select the source line or instruction in the Source Pane.
TotalView highlights the line.
TotalView asks for confirmation, resets the PC, and moves the PC symbol 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 can’t assume that the stack and registers have the right values, selecting No is almost always the wrong thing to do.