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

# Class DWARFExpressionEvaluator

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

public class DWARFExpressionEvaluator extends Object
Evaluates a `DWARFExpression`.

If an instruction needs a value in a register or memory location, the current `DWARFExpressionEvaluator.ValueReader` callback will be called to fetch the value. The default implementation is to throw an exception, but future work may plug in a constant propagation callback.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `DWARFExpressionEvaluator.ValueReader`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DWARFExpressionEvaluator(DWARFCompilationUnit cu)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `evaluate(byte[] exprBytes)`
  Executes the instructions found in the expression.
  `void`
  `evaluate(byte[] exprBytes, long... stackArgs)`
  Executes the instructions found in the expression.
  `void`
  `evaluate(DWARFExpression expr)`
  `void`
  `evaluate(DWARFExpression expr, long... stackArgs)`
  Executes the instructions found in the expression.
  `DWARFCompilationUnit`
  `getDWARFCompilationUnit()`
  `DWARFExpression`
  `getExpr()`
  `int`
  `getMaxStepCount()`
  `int`
  `getPtrSize()`
  `boolean`
  `hasNext()`
  Returns true if there are instructions that can be evaluated.
  `boolean`
  `isEmpty()`
  `Object`
  `peek()`
  Peek at the top value of the stack.
  `Object`
  `pop()`
  Pop the top value off the stack.
  `long`
  `popLong()`
  Pop the top value off the stack, and coerce it into a scalar long.
  `Scalar`
  `popScalar()`
  Pop the top value off the stack, and coerce it into a scalar.
  `Varnode`
  `popVarnode()`
  Pop the top value off the stack, and coerce it into a varnode.
  `void`
  `push(boolean b)`
  `void`
  `push(long l)`
  `void`
  `push(Address addr)`
  `void`
  `push(Register reg)`
  `void`
  `push(Object val)`
  `void`
  `setExpression(DWARFExpression expr)`
  Sets the current expression.
  `void`
  `setFrameBaseStackLocation(int offset)`
  `void`
  `setFrameBaseVal(Varnode frameBaseVal)`
  `void`
  `setMaxStepCount(int maxStepCount)`
  `void`
  `setValReader(DWARFExpressionEvaluator.ValueReader valReader)`
  `boolean`
  `step()`
  Evaluates the next instruction in the expression.
  `String`
  `toString()`
  `DWARFExpressionEvaluator.ValueReader`
  `withStaticStackRegisterValues(Integer stackOffset, Integer stackFrameOffset)`

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

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

- ## Constructor Details

  - ### DWARFExpressionEvaluator

    public DWARFExpressionEvaluator(DWARFCompilationUnit cu)

- ## Method Details

  - ### getDWARFCompilationUnit

    public DWARFCompilationUnit getDWARFCompilationUnit()

  - ### getExpr

    public DWARFExpression getExpr()

  - ### isEmpty

    public boolean isEmpty()

  - ### getPtrSize

    public int getPtrSize()

  - ### setFrameBaseStackLocation

    public void setFrameBaseStackLocation(int offset)

  - ### setFrameBaseVal

    public void setFrameBaseVal(Varnode frameBaseVal)

  - ### setValReader

    public void setValReader(DWARFExpressionEvaluator.ValueReader valReader)

  - ### withStaticStackRegisterValues

    public DWARFExpressionEvaluator.ValueReader withStaticStackRegisterValues(Integer stackOffset, Integer stackFrameOffset)

  - ### getMaxStepCount

    public int getMaxStepCount()

  - ### setMaxStepCount

    public void setMaxStepCount(int maxStepCount)

  - ### push

    public void push(Address addr)

  - ### push

    public void push(Register reg)

  - ### push

    public void push(boolean b)

  - ### push

    public void push(long l)

  - ### push

    public void push(Object val)

  - ### peek

    public Object peek() throws DWARFExpressionException
    Peek at the top value of the stack.
    Returns:
      top value of the stack
    Throws:
      `DWARFExpressionException` - if stack is empty

  - ### pop

    public Object pop() throws DWARFExpressionException
    Pop the top value off the stack.
    Returns:
      top value of the stack
    Throws:
      `DWARFExpressionException` - if stack is empty

  - ### popScalar

    public Scalar popScalar() throws DWARFExpressionException
    Pop the top value off the stack, and coerce it into a scalar.
    Returns:
      top value of the stack, as a scalar
    Throws:
      `DWARFExpressionException` - if stack is empty or value can not be used as a scalar

  - ### popVarnode

    public Varnode popVarnode() throws DWARFExpressionException
    Pop the top value off the stack, and coerce it into a varnode.
    Returns:
      top value of the stack, as a varnode
    Throws:
      `DWARFExpressionException` - if stack is empty or value can not be used as a varnode

  - ### popLong

    public long popLong() throws DWARFExpressionException
    Pop the top value off the stack, and coerce it into a scalar long.
    Returns:
      top value of the stack, as a scalar long
    Throws:
      `DWARFExpressionException` - if stack is empty or value can not be used as a long

  - ### evaluate

    public void evaluate(byte[] exprBytes) throws DWARFExpressionException
    Executes the instructions found in the expression.
    Parameters:
      `exprBytes` - raw bytes of the expression
    Throws:
      `DWARFExpressionException` - if error

  - ### evaluate

    public void evaluate(byte[] exprBytes, long... stackArgs) throws DWARFExpressionException
    Executes the instructions found in the expression.
    Parameters:
      `exprBytes` - raw bytes of the expression
      `stackArgs` - any values to push onto the stack before execution
    Throws:
      `DWARFExpressionException` - if error

  - ### setExpression

    public void setExpression(DWARFExpression expr)
    Sets the current expression.
    Parameters:
      `expr` - `DWARFExpression`

  - ### hasNext

    public boolean hasNext()
    Returns true if there are instructions that can be evaluated.
    Returns:
      true if there are instructions that can be evaluated

  - ### step

    public boolean step() throws DWARFExpressionException
    Evaluates the next instruction in the expression.
    Returns:
      true if there are more instructions
    Throws:
      `DWARFExpressionException` - if error

  - ### evaluate

    public void evaluate(DWARFExpression expr, long... stackArgs) throws DWARFExpressionException
    Executes the instructions found in the expression.
    Parameters:
      `expr` - `DWARFException` to evaluate
      `stackArgs` - - pushed 0..N, so stackArgs[0] will be deepest, stackArgs[N] will be topmost.
    Throws:
      `DWARFExpressionException` - if error

  - ### evaluate

    public void evaluate(DWARFExpression expr) throws DWARFExpressionException
    Throws:
      `DWARFExpressionException`

  - ### toString

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