Package ghidra.pcode.emu

# Class ModifiedPcodeThread<T>

java.lang.Object
ghidra.pcode.emu.DefaultPcodeThread<T>
ghidra.pcode.emu.ModifiedPcodeThread<T>

All Implemented Interfaces:
  `PcodeThread<T>`

Direct Known Subclasses:
  `AuxPcodeThread`, `BytesPcodeThread`

public class ModifiedPcodeThread<T> extends DefaultPcodeThread<T>
A p-code thread which incorporates per-architecture state modifiers

All machines that include a concrete state piece, i.e., all emulators, should use threads derived from this class. This implementation assumes that the modified state can be concretized. This doesn't necessarily require the machine to be a concrete emulator, but an abstract machine must avoid or handle `ConcretionError`s arising from state modifiers.

For a complete example of a p-code emulator, see `PcodeEmulator`.

TODO: "State modifiers" are a feature of the older `Emulator`. They are crudely incorporated into threads extended from this abstract class, so that they do not yet need to be ported to this emulator.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected class`
  `ModifiedPcodeThread.GlueEmulate`
  Glue for incorporating state modifiers

  ## Nested classes/interfaces inherited from class ghidra.pcode.emu.DefaultPcodeThread

  `DefaultPcodeThread.PcodeEmulationLibrary<T>, DefaultPcodeThread.PcodeThreadExecutor<T>`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final Emulate`
  `emulate`
  `protected final EmulateInstructionStateModifier`
  `modifier`
  Part of the glue that makes existing state modifiers work in new emulation framework

  ### Fields inherited from class ghidra.pcode.emu.DefaultPcodeThread

  `arithmetic, contextreg, decoder, defaultContext, executor, frame, injects, instruction, language, library, pc, state`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ModifiedPcodeThread(String name, AbstractPcodeMachine<T> machine)`
  Construct a new thread with the given name belonging to the given machine

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected EmulateInstructionStateModifier`
  `createModifier()`
  Construct a modifier for the given language
  `protected boolean`
  `onMissingUseropDef(PcodeOp op, String opName)`
  Extension point: Behavior when a p-code userop definition is not found
  `void`
  `overrideCounter(Address counter)`
  Set the thread's program counter and write the pc register of its executor state
  `protected void`
  `postExecuteInstruction()`
  Extension point: Extra behavior after executing an instruction

  ### Methods inherited from class ghidra.pcode.emu.DefaultPcodeThread

  `advanceAfterFinished, assertCompletedInstruction, assertMidInstruction, assignContext, beginInstructionOrInject, branchToAddress, checkLoad, checkStore, clearAllInjects, clearInject, createExecutor, createInstructionDecoder, createUseropLibrary, doPluggableInitialization, dropInstruction, executeInstruction, finishInstruction, getArithmetic, getContext, getContextAfterCommits, getCounter, getExecutor, getFrame, getInject, getInstruction, getLanguage, getMachine, getName, getState, getUseropLibrary, inject, isSuspended, overrideContext, overrideContextWithDefault, preExecuteInstruction, reInitialize, run, setCounter, setSuspended, skipInstruction, skipPcodeOp, stepInstruction, stepPatch, stepPcodeOp, stepped, swi, writeCounter`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface ghidra.pcode.emu.PcodeThread

  `stepInstruction, stepPcodeOp`

- ## Field Details

  - ### modifier

    protected final EmulateInstructionStateModifier modifier
    Part of the glue that makes existing state modifiers work in new emulation framework

    NOTE: These are instantiated one per thread, rather than sharing one across the machine, because some of the modifiers are stateful and assume a single-threaded model. The best way to mitigate that assumption is to ensure a modifier is responsible for only a single thread, even though a machine may have multiple threads.

  - ### emulate

    protected final Emulate emulate

- ## Constructor Details

  - ### ModifiedPcodeThread

    public ModifiedPcodeThread(String name, AbstractPcodeMachine<T> machine)
    Construct a new thread with the given name belonging to the given machine
    Parameters:
      `name` - the name of the new thread
      `machine` - the machine to which the new thread belongs
    See Also:
      - `PcodeMachine.newThread(String)`

- ## Method Details

  - ### createModifier

    protected EmulateInstructionStateModifier createModifier()
    Construct a modifier for the given language
    Returns:
      the state modifier

  - ### overrideCounter

    public void overrideCounter(Address counter)
    Description copied from interface: `PcodeThread`
    Set the thread's program counter and write the pc register of its executor state

    Warning: Setting the counter into the middle of group constructs, e.g., parallel instructions or delay-slotted instructions, may cause undefined behavior.

    Specified by:
      `overrideCounter` in interface `PcodeThread<T>`
    Overrides:
      `overrideCounter` in class `DefaultPcodeThread<T>`
    Parameters:
      `counter` - the new target address
    See Also:
      - `PcodeThread.setCounter(Address)`

  - ### postExecuteInstruction

    protected void postExecuteInstruction()
    Description copied from class: `DefaultPcodeThread`
    Extension point: Extra behavior after executing an instruction

    This is currently used for incorporating state modifiers from the older `Emulator` framework. There is likely utility here when porting those to this framework.

    Overrides:
      `postExecuteInstruction` in class `DefaultPcodeThread<T>`

  - ### onMissingUseropDef

    protected boolean onMissingUseropDef(PcodeOp op, String opName)
    Description copied from class: `DefaultPcodeThread`
    Extension point: Behavior when a p-code userop definition is not found
    Overrides:
      `onMissingUseropDef` in class `DefaultPcodeThread<T>`
    Parameters:
      `op` - the op
      `opName` - the name of the p-code userop
    Returns:
      true if handle, false if still undefined