Next: Existing Targets, Up: Target Vector Definition

### 13.1 Managing Execution State

A target vector can be completely inactive (not pushed on the target stack), active but not running (pushed, but not connected to a fully manifested inferior), or completely active (pushed, with an accessible inferior). Most targets are only completely inactive or completely active, but some support persistent connections to a target even when the target has exited or not yet started.

For example, connecting to the simulator using `target sim` does not create a running program. Neither registers nor memory are accessible until `run`. Similarly, after `kill`, the program can not continue executing. But in both cases gdb remains connected to the simulator, and target-specific commands are directed to the simulator.

A target which only supports complete activation should push itself onto the stack in its `to_open` routine (by calling `push_target`), and unpush itself from the stack in its `to_mourn_inferior` routine (by calling `unpush_target`).

A target which supports both partial and complete activation should still call `push_target` in `to_open`, but not call `unpush_target` in `to_mourn_inferior`. Instead, it should call either `target_mark_running` or `target_mark_exited` in its `to_open`, depending on whether the target is fully active after connection. It should also call `target_mark_running` any time the inferior becomes fully active (e.g. in `to_create_inferior` and `to_attach`), and `target_mark_exited` when the inferior becomes inactive (in `to_mourn_inferior`). The target should also make sure to call `target_mourn_inferior` from its `to_kill`, to return the target to inactive state.