Class DWARFExpression

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

public class DWARFExpression extends Object
A DWARFExpression is an immutable list of operations and some factory methods to read an expression from its binary representation.

Use a DWARFExpressionEvaluator to execute a DWARFExpression.

  • Field Details

  • Method Details

    • read

      public static DWARFExpression read(byte[] exprBytes, DWARFCompilationUnit cu) throws DWARFExpressionException
      Deserializes a DWARFExpression from its raw bytes.
      Parameters:
      exprBytes - bytes containing the expression
      cu - the DWARFCompilationUnit that contained the expression
      Returns:
      new DWARFExpression, never null
      Throws:
      DWARFExpressionException - if error reading the expression, check DWARFExpressionException.getExpression() for the partial results of the read
    • toGenericForm

      public DWARFExpression toGenericForm()
      Converts this DWARFExpression into a generic form, lacking any operand values.

      Useful for aggregating statistics about unsupported/problematic expressions encountered in a binary.

      Returns:
      new DWARFExpression instance where each instruction has been stripped of all operands
    • getInstruction

      public DWARFExpressionInstruction getInstruction(int i)
      Returns the requested instruction.
      Parameters:
      i - instruction index
      Returns:
      the requested instruction
    • getInstructionCount

      public int getInstructionCount()
      Returns number of instructions in this expression.
      Returns:
      number of instructions in this expression
    • isEmpty

      public boolean isEmpty()
      Returns true if there are no instructions.
      Returns:
      true if there are no instructions
    • findInstructionByOffset

      public int findInstructionByOffset(long offset)
      Finds the index of an operation by its offset from the beginning of the expression.
      Parameters:
      offset - byte offset of instruction to find
      Returns:
      index of instruction at specified byte offset, or -1 if there is no instruction at the specified offset
    • toString

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

      public String toString(DWARFCompilationUnit cu)
    • toString

      public String toString(int caretPosition, boolean newlines, boolean offsets, DWARFRegisterMappings regMapping)
      Returns a formatted string representing this expression.
      Parameters:
      caretPosition - index of which instruction to highlight as being the current instruction, or -1 to not highlight any instruction
      newlines - boolean flag, if true each instruction will be on its own line
      offsets - boolean flag, if true the byte offset in the expression will be listed next to each instruction
      regMapping - mapping of dwarf to ghidra registers
      Returns:
      formatted string
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

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