Package ghidra.app.util.bin.format.dwarf.expression

# Class DWARFExpressionInstruction

java.lang.Object
ghidra.app.util.bin.format.dwarf.expression.DWARFExpressionInstruction

public class DWARFExpressionInstruction extends Object
An immutable representation of a single `DWARFExpression` instruction and its operands.

An instruction can take 0, 1, or 2 operands, only the last can be a blob.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final byte[]`
  `blob`
  `protected final int`
  `offset`
  `protected final DWARFExpressionOpCode`
  `opcode`
  `protected final long[]`
  `operands`
  `protected final DWARFExpressionOperandType[]`
  `operandTypes`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DWARFExpressionInstruction(DWARFExpressionOpCode op, DWARFExpressionOperandType[] operandTypes, long[] operands, byte[] blob, int offset)`
  Create a new DWARF expression instruction.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  `byte[]`
  `getBlob()`
  Returns the byte array that contains the bytes of the blob operand.
  `int`
  `getOffset()`
  Returns offset of this opcode, relative to the start of the `DWARFExpression`.
  `DWARFExpressionOpCode`
  `getOpCode()`
  Returns `DWARFExpressionOpCode` of this instruction.
  `int`
  `getOperandCount()`
  Returns number of operands this instruction has.
  `String`
  `getOperandRepresentation(int opIndex)`
  Returns formatted string representation of the specified operand, patterned after readelf's format.
  `long`
  `getOperandValue(int opindex)`
  Returns the specified operand's value. Not valid for blob operands.
  `int`
  `hashCode()`
  `static DWARFExpressionInstruction`
  `read(BinaryReader reader, byte addrSize, int intSize)`
  Reads a single instruction from the stream.
  `DWARFExpressionInstruction`
  `toGenericForm()`
  Returns a new instruction instance that is a copy of this instruction, but has had all it's operands removed.
  `String`
  `toString()`

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

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### opcode

    protected final DWARFExpressionOpCode opcode

  - ### offset

    protected final int offset

  - ### operandTypes

    protected final DWARFExpressionOperandType[] operandTypes

  - ### operands

    protected final long[] operands

  - ### blob

    protected final byte[] blob

- ## Constructor Details

  - ### DWARFExpressionInstruction

    public DWARFExpressionInstruction(DWARFExpressionOpCode op, DWARFExpressionOperandType[] operandTypes, long[] operands, byte[] blob, int offset)
    Create a new DWARF expression instruction.
    Parameters:
      `op` - enum opcode, ie. DW_OP_not from `DWARFExpressionOpCode`
      `operandTypes` - 'datatype' of each operands
      `operands` - value of the operands, pre-converted into longs.
      `blob` - if an operand is a byte array (ie. for DW_OP_implicit_value), this is the bytes
      `offset` - byte offset of this operation from the start of the DWARF expression.

- ## Method Details

  - ### read

    public static DWARFExpressionInstruction read(BinaryReader reader, byte addrSize, int intSize) throws IOException
    Reads a single instruction from the stream.
    Parameters:
      `reader` - `BinaryReader` stream
      `addrSize` - size of pointers
      `intSize` - size of ints
    Returns:
      new `DWARFExpressionInstruction`, never null. Problematic instructions will have an opcode of `DW_OP_unknown_opcode` and will contain the remainder of the stream as its blob operand
    Throws:
      `IOException` - if error reading a primitive value from the stream

  - ### toGenericForm

    public DWARFExpressionInstruction toGenericForm()
    Returns a new instruction instance that is a copy of this instruction, but has had all it's operands removed.
    Returns:
      a new instruction instance that is a copy of this instruction, but has had all it's operands removed

  - ### getOpCode

    public DWARFExpressionOpCode getOpCode()
    Returns `DWARFExpressionOpCode` of this instruction.
    Returns:
      `DWARFExpressionOpCode` of this instruction

  - ### getOperandValue

    public long getOperandValue(int opindex)
    Returns the specified operand's value. Not valid for blob operands.
    Parameters:
      `opindex` - which operand to fetch.
    Returns:
      the specified operand's value. Not valid for blob operands

  - ### getOperandCount

    public int getOperandCount()
    Returns number of operands this instruction has.
    Returns:
      number of operands this instruction has

  - ### getBlob

    public byte[] getBlob()
    Returns the byte array that contains the bytes of the blob operand.
    Returns:
      the byte array that contains the bytes of the blob operand

  - ### getOffset

    public int getOffset()
    Returns offset of this opcode, relative to the start of the `DWARFExpression`.
    Returns:
      offset of this opcode, relative to the start of the `DWARFExpression`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### getOperandRepresentation

    public String getOperandRepresentation(int opIndex)
    Returns formatted string representation of the specified operand, patterned after readelf's format.
    Parameters:
      `opIndex` - operand index
    Returns:
      formatted string representation of the specified operand, patterned after readelf's format

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`