Class SleighDebugLogger
- java.lang.Object
-
- ghidra.app.plugin.processors.sleigh.SleighDebugLogger
-
public class SleighDebugLogger extends java.lang.Object
SleighDebugLogger
provides the ability to obtain detailed instruction parse details.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SleighDebugLogger.SleighDebugMode
-
Constructor Summary
Constructors Constructor Description SleighDebugLogger(Program program, Address start, SleighDebugLogger.SleighDebugMode mode)
Performs a parse debug at the specified memory location within program.SleighDebugLogger(MemBuffer buf, ProcessorContextView context, Language language, SleighDebugLogger.SleighDebugMode mode)
Performs a parse debug at the specified memory location within program.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addContextPattern(PatternBlock maskvalue)
Add instruction context pattern to the current pattern group.void
addInstructionPattern(int offset, PatternBlock maskvalue)
Add instruction bit pattern to the current pattern group.void
append(byte[] value, int startbit, int bitcount)
Append a binary formatted byte array with the specified range of bits bracketed to the log.void
append(int[] value, int startbit, int bitcount)
Append a binary formatted integer array with the specified range of bits bracketed to the log.void
append(int value, int startbit, int bitcount)
Append a binary formatted integer value with the specified range of bits bracketed to the log.void
append(java.lang.String str)
Append message string to log buffer.void
dropIndent()
Shift log indent leftvoid
dropIndent(int levels)
void
dumpContextPattern(int[] maskvec, int[] valvec, int byteOffset, SleighParserContext pos)
Dump context pattern details.void
dumpContextSet(SleighParserContext pos, int num, int value, int mask)
Dump transient context setting details.void
dumpGlobalSet(SleighParserContext pos, ConstructState state, TripleSymbol sym, int num, int mask, int value)
Dump globalset details.void
endPatternGroup(boolean commit)
Terminate the current pattern groupjava.util.List<java.lang.String>
getConstructorLineNumbers()
Get list of constructor names with line numbers.static java.lang.String
getFormattedBytes(byte[] value)
Convenience method for formatting bytes as a bit sequencejava.lang.String
getFormattedInstructionMask(int opIndex)
Return general/operand bit mask formatted as a Stringjava.lang.String
getFormattedMaskedValue(int opIndex)
Return general/operand bit values formatted as a Stringbyte[]
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).byte[]
getMaskedBytes(byte[] mask)
Apply an appropriate mask for the resulting instruction bytes to obtain the corresponding masked bytes.int
getNumOperands()
Get the number of operands for the resulting prototypebyte[]
getOperandValueMask(int opIndex)
Get the byte value mask corresponding to the specified operand.void
indent()
Shift log indent rightvoid
indent(int levels)
boolean
isVerboseEnabled()
boolean
parseFailed()
void
startPatternGroup(java.lang.String name)
Start new pattern group for a specific sub-table.java.lang.String
toString()
Return log text
-
-
-
Constructor Detail
-
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
-programContext
-verbose
- if true extended debug information may be provided- Throws:
java.lang.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
-start
-verbose
- if true extended debug information may be provided- Throws:
java.lang.IllegalArgumentException
- if program language provider is not Sleigh
-
-
Method Detail
-
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 getMaskedInstructionBytes() and getInstructionBitMask() should only be invoked if this method returns false.
-
getConstructorLineNumbers
public java.util.List<java.lang.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 valuestartbit
- 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 arraystartbit
- 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 arraystartbit
- 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(java.lang.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 java.lang.String toString()
Return log text- Overrides:
toString
in classjava.lang.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 contextnum
- 4-byte offset within base context register for mask and valuevalue
- 4-byte context valuemask
- 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(java.lang.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:
java.lang.IllegalStateException
- if prototype parse failed- See Also:
SleighDebugLogger#getMaskedInstructionBytes()
-
getFormattedInstructionMask
public java.lang.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 java.lang.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 java.lang.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:
java.lang.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:
java.lang.IllegalStateException
- if prototype parse failedjava.lang.IndexOutOfBoundsException
- if opIndex is not a valid operand index
-
-