Class SleighDebugLogger

java.lang.Object
ghidra.app.plugin.processors.sleigh.SleighDebugLogger

public class SleighDebugLogger extends Object
SleighDebugLogger provides the ability to obtain detailed instruction parse details.
  • Constructor Details

    • SleighDebugLogger

      public SleighDebugLogger(MemBuffer buf, ProcessorContextView context, Language language, SleighDebugLogger.SleighDebugMode mode)
      Performs a parse debug at the specified memory location within program.
      Parameters:
      buf - the memory buffer
      context - the processor context
      language - the sleigh language
      mode - the sleigh debug mode
      Throws:
      IllegalArgumentException - if program language provider is not Sleigh
    • SleighDebugLogger

      public SleighDebugLogger(Program program, Address start, SleighDebugLogger.SleighDebugMode mode)
      Performs a parse debug at the specified memory location within program.
      Parameters:
      program - the program the memory location is found in
      start - the start address of the memory location
      mode - the sleigh debug mode
      Throws:
      IllegalArgumentException - if program language provider is not Sleigh
  • Method Details

    • isVerboseEnabled

      public boolean isVerboseEnabled()
      Returns:
      true if constructed for verbose logging
    • parseFailed

      public boolean parseFailed()
      Returns:
      true if a parse error was detected, otherwise false is returned. The methods getMaskedBytes() and getInstructionMask() should only be invoked if this method returns false.
    • getConstructorLineNumbers

      public List<String> getConstructorLineNumbers()
      Get list of constructor names with line numbers. Any debug mode may be used.
      Returns:
      list
    • append

      public void append(int value, int startbit, int bitcount)
      Append a binary formatted integer value with the specified range of bits bracketed to the log. A -1 value for both startbit and bitcount disable the bit range bracketing. NOTE: Method has no affect unless constructed with VERBOSE logging mode.
      Parameters:
      value - integer value
      startbit - identifies the first most-significant bit within the bracketed range (left-most value bit is bit-0, right-most value bit is bit-31)
      bitcount - number of bits included within range
    • append

      public void append(int[] value, int startbit, int bitcount)
      Append a binary formatted integer array with the specified range of bits bracketed to the log. A -1 value for both startbit and bitcount disable the bit range bracketing. NOTE: Method has no affect unless constructed with VERBOSE logging mode.
      Parameters:
      value - integer array
      startbit - identifies the first most-significant bit within the bracketed range (left-most value[0] bit is bit-0, right-most value[n] bit is bit-<32(n+1)-1> ).
      bitcount - number of bits included within range
    • append

      public void append(byte[] value, int startbit, int bitcount)
      Append a binary formatted byte array with the specified range of bits bracketed to the log. A -1 value for both startbit and bitcount disable the bit range bracketing. NOTE: Method has no affect unless constructed with VERBOSE logging mode.
      Parameters:
      value - byte array
      startbit - identifies the first most-significant bit within the bracketed range (left-most value[0] bit is bit-0, right-most value[n] bit is bit-<8(n+1)-1> ).
      bitcount - number of bits included within range
    • append

      public void append(String str)
      Append message string to log buffer. NOTE: Method has no affect unless constructed with VERBOSE logging mode.
      Parameters:
      str - message string
    • indent

      public void indent()
      Shift log indent right
    • indent

      public void indent(int levels)
    • dropIndent

      public void dropIndent()
      Shift log indent left
    • dropIndent

      public void dropIndent(int levels)
    • toString

      public String toString()
      Return log text
      Overrides:
      toString in class Object
    • dumpContextPattern

      public void dumpContextPattern(int[] maskvec, int[] valvec, int byteOffset, SleighParserContext pos)
      Dump context pattern details. NOTE: Method has no affect unless constructed with VERBOSE logging mode.
      Parameters:
      maskvec -
      valvec -
      byteOffset -
      pos -
    • dumpContextSet

      public void dumpContextSet(SleighParserContext pos, int num, int value, int mask)
      Dump transient context setting details. NOTE: Method has no affect unless constructed with VERBOSE logging mode.
      Parameters:
      pos - instruction context
      num - 4-byte offset within base context register for mask and value
      value - 4-byte context value
      mask - 4-byte context mask
    • dumpGlobalSet

      public void dumpGlobalSet(SleighParserContext pos, ConstructState state, TripleSymbol sym, int num, int mask, int value) throws MemoryAccessException
      Dump globalset details. The target address is currently not included in the log. NOTE: Method has no affect unless constructed with VERBOSE logging mode.
      Parameters:
      pos -
      state -
      sym -
      num -
      mask -
      value -
      Throws:
      MemoryAccessException
    • startPatternGroup

      public void startPatternGroup(String name)
      Start new pattern group for a specific sub-table. A null can correspond to a top-level constructor or low level complex pattern (AND, OR). All committed unnamed groups with the same parent group will be combined.
      Parameters:
      name - group name or null for unnamed group
    • endPatternGroup

      public void endPatternGroup(boolean commit)
      Terminate the current pattern group
      Parameters:
      commit - if false group will be discarded, if true group will be retained
    • addInstructionPattern

      public void addInstructionPattern(int offset, PatternBlock maskvalue)
      Add instruction bit pattern to the current pattern group.
      Parameters:
      offset - base offset at which the specified maskvalue can be applied.
      maskvalue - pattern mask/value
    • addContextPattern

      public void addContextPattern(PatternBlock maskvalue)
      Add instruction context pattern to the current pattern group.
      Parameters:
      maskvalue - pattern mask/value
    • getInstructionMask

      public byte[] getInstructionMask()
      Returns the instruction bit mask which identifies those bits used to uniquely identify the instruction (includes addressing modes, generally excludes register selector bits associated with attaches or immediate values used in for semantic values only).
      Throws:
      IllegalStateException - if prototype parse failed
      See Also:
    • getFormattedInstructionMask

      public String getFormattedInstructionMask(int opIndex)
      Return general/operand bit mask formatted as a String
      Parameters:
      opIndex - operand index or -1 for mnemonic mask
      Returns:
      bit mask string
    • getFormattedMaskedValue

      public String getFormattedMaskedValue(int opIndex)
      Return general/operand bit values formatted as a String
      Parameters:
      opIndex - operand index or -1 for mnemonic bit values
      Returns:
      bit value string
    • getFormattedBytes

      public static String getFormattedBytes(byte[] value)
      Convenience method for formatting bytes as a bit sequence
      Parameters:
      value - byte array
      Returns:
      binary formatted bytes
    • getNumOperands

      public int getNumOperands()
      Get the number of operands for the resulting prototype
      Returns:
      operand count
      Throws:
      IllegalStateException - if prototype parse failed
    • getMaskedBytes

      public byte[] getMaskedBytes(byte[] mask)
      Apply an appropriate mask for the resulting instruction bytes to obtain the corresponding masked bytes.
      Parameters:
      mask - instruction, operand or similarly sized mask
      Returns:
      masked instruction bytes
    • getOperandValueMask

      public byte[] getOperandValueMask(int opIndex)
      Get the byte value mask corresponding to the specified operand.
      Parameters:
      opIndex - operand index within the instruction representation
      Returns:
      byte mask or null if operand does not have a corresponding sub-constructor or attach
      Throws:
      IllegalStateException - if prototype parse failed
      IndexOutOfBoundsException - if opIndex is not a valid operand index