Class DBTraceInstruction
- All Implemented Interfaces:
InstructionContext,ProcessorContext,ProcessorContextView,CodeUnit,Instruction,MemBuffer,MemBufferMixin,PropertySet,DBTraceCodeUnitAdapter,TraceCodeUnit,TraceInstruction,TraceAddressSnapRange,InstructionAdapterFromPrototype,BoundedShape<TraceAddressSnapRange>,BoundingShape<TraceAddressSnapRange>,Rectangle2D<Address,Long, TraceAddressSnapRange>
TraceInstruction for DBTrace-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA context for guest instructions that maps addresses appropriatelyprotected classNested classes/interfaces inherited from class ghidra.util.database.spatial.DBTreeDataRecord
DBTreeDataRecord.RecordEntry<DS extends BoundedShape<NS>,NS extends BoundingShape<NS>, T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FlowOverrideprotected InstructionContextprotected intprotected MemBufferprotected ParserContextprotected InternalTracePlatformprotected InstructionPrototypeFields inherited from class ghidra.trace.database.listing.AbstractDBTraceCodeUnit
byteCache, spaceFields inherited from class ghidra.trace.database.map.DBTraceAddressSnapRangePropertyMapTree.AbstractDBTraceAddressSnapRangePropertyMapData
lifespan, range, treeFields inherited from class ghidra.program.database.DatabaseObject
keyFields inherited from interface ghidra.program.model.listing.CodeUnit
COMMENT_PROPERTY, DEFINED_DATA_PROPERTY, EOL_COMMENT, INSTRUCTION_PROPERTY, MNEMONIC, PLATE_COMMENT, POST_COMMENT, PRE_COMMENT, REPEATABLE_COMMENT, SPACE_PROPERTYFields inherited from interface ghidra.program.model.listing.Instruction
INVALID_DEPTH_CHANGE, MAX_LENGTH_OVERRIDE -
Constructor Summary
ConstructorsConstructorDescriptionDBTraceInstruction(DBTraceCodeSpace space, DBTraceAddressSnapRangePropertyMapTree<DBTraceInstruction, ?> tree, DBCachedObjectStore<?> store, DBRecord record) Construct an instruction unit -
Method Summary
Modifier and TypeMethodDescriptionvoidRestores this instruction's fallthrough address back to the default fallthrough for this instruction.voidclearRegister(Register register) Clears the register within this context.voiddelete()Delete this code unitprotected voiddoSetPlatformMapping(InternalTracePlatform platform) At load/create time: set the platform and context (which may map addresses)protected voidfresh(boolean created) Extension point: Called when the object's fields are populated.getAddress(int opIndex) Get the Address for the given operand index if one exists.Get the default fallthrough for this instruction.Address[]Get an array of Address objects for all default flows established by the underlying instruction prototype.Get the fallthrough for this instruction, factoring in any fallthrough override and delay slotted instructions.Address[]getFlows()Get an array of Address objects for all flows other than a fall-through.Get the default fall-through as viewed in the instruction's native address spaceAddress[]Get the default flows as viewed in the instruction's native address spaceGet the language of this code unitintGet length of this code unit.Get the read-only memory buffer containing the instruction bytes.getNext()intgetOperandType(int opIndex) Get the type of a specific operand.byte[]Get the actual bytes parsed when forming this instruction.intGet the actual number of bytes parsed when forming this instruction.Get the instruction parser context for the instruction which corresponds to this context object.getParserContext(Address instructionAddress) Get the instruction parser context which corresponds to the specified instruction address.Get the platform for this unitGet the read-only processor context containing the context-register state state at the corresponding instruction.protected DBTraceInstructionGet the value of this record Note that the value is sometimes the record itself, i.e., this method returnsthis.getRegister(String name) Get a Register given the name of a registerReturns all the Registers for the processor as an unmodifiable listgetRegisterValue(Register register) Get the RegisterValue for the given register.Get the contents of a processor register as a BigInteger objectbooleanbooleanReturns true if a value is defined for the given register.booleanbooleanbooleanDetermine if an instruction length override has been set.protected voidset(InternalTracePlatform platform, InstructionPrototype prototype, ProcessorContextView context, int forcedLengthOverride) Set the fields of this recordvoidsetEndSnap(long endSnap) Set the end snap of this code unitvoidsetFallThrough(Address fallThrough) Overrides the instruction's default fallthrough address to the given address.voidsetFlowOverride(FlowOverride flowOverride) Set the flow override for this instruction.voidsetLengthOverride(int length) Set instruction length override.protected voidsetRecordValue(DBTraceInstruction value) Set the value of this record Note that the value is sometimes the record itself.voidsetRegisterValue(RegisterValue value) Sets the specified register value within this context.voidsetValue(Register register, BigInteger value) Sets the value for a Register.toString()Methods inherited from class ghidra.trace.database.listing.AbstractDBTraceCodeUnit
getAddress, getBytes, getEndSnap, getMaxAddress, getStartSnap, getThread, getTraceMethods inherited from class ghidra.trace.database.map.DBTraceAddressSnapRangePropertyMapTree.AbstractDBTraceAddressSnapRangePropertyMapData
doSetLifespan, doSetRange, equals, getBounds, getLifespan, getParentKey, getRange, getShape, getSpace, hashCode, setParentKey, setShape, shapeEqualsMethods inherited from class ghidra.util.database.spatial.DBTreeDataRecord
asEntry, getDataCountMethods inherited from class ghidra.util.database.DBAnnotatedObject
doRefresh, doUpdateAll, doUpdated, doWrite, getObjectKey, getTableName, isDeleted, refresh, refresh, update, update, update, updateMethods inherited from class ghidra.program.database.DatabaseObject
checkDeleted, checkIsValid, checkIsValid, getKey, isDeleted, isInvalid, keyChanged, setDeleted, setInvalid, validateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface ghidra.program.model.listing.CodeUnit
getComment, getCommentAsArray, getMaxAddress, setComment, setCommentAsArrayMethods inherited from interface ghidra.trace.database.listing.DBTraceCodeUnitAdapter
addMnemonicReference, addOperandReference, compareTo, contains, getAddressSpace, getAddressString, getBytes, getBytesInCodeUnit, getComment, getCommentAsArray, getExternalReference, getIntProperty, getLabel, getMemory, getMinAddress, getMnemonicReferences, getObjectProperty, getOperandReferences, getPrimaryReference, getPrimarySymbol, getProgram, getProperty, getReferenceIteratorTo, getReferencesFrom, getStringProperty, getSymbols, getVoidProperty, hasProperty, isBigEndian, propertyNames, removeExternalReference, removeMnemonicReference, removeOperandReference, removeProperty, setComment, setCommentAsArray, setPrimaryMemoryReference, setProperty, setProperty, setProperty, setProperty, setProperty, setRegisterReference, setStackReference, setTypedPropertyMethods inherited from interface ghidra.trace.util.InstructionAdapterFromPrototype
getDefaultFallThroughOffset, getDefaultOperandRepresentation, getDefaultOperandRepresentationList, getDelaySlotDepth, getFullString, getInputObjects, getMnemonicString, getNumOperands, getOperandRefType, getOpObjects, getPcode, getPcode, getPcode, getRegister, getResultObjects, getScalar, getSeparator, isInDelaySlotMethods inherited from interface ghidra.program.model.lang.InstructionContext
getAddressMethods inherited from interface ghidra.program.model.mem.MemBuffer
getAddress, getInputStream, getInputStream, getUnsignedByte, getUnsignedInt, getUnsignedShort, getVarLengthInt, getVarLengthUnsignedInt, isInitializedMemoryMethods inherited from interface ghidra.program.model.mem.MemBufferMixin
getBigInteger, getByte, getBytes, getBytesInFull, getInt, getLong, getShortMethods inherited from interface ghidra.util.database.spatial.rect.Rectangle2D
computeAreaIntersection, computeAreaUnionBounds, computeCentroidDistance, contains, contains, doEquals, doHashCode, enclosedBy, encloses, getArea, getCenter, getMargin, intersection, intersects, unionBoundsMethods inherited from interface ghidra.trace.model.TraceAddressSnapRange
description, getX1, getX2, getY1, getY2, immutableMethods inherited from interface ghidra.trace.model.listing.TraceCodeUnit
getBounds, getBytes, getEndSnap, getLifespan, getRange, getStartSnap, getThread
-
Field Details
-
prototype
-
flowOverride
-
lengthOverride
protected int lengthOverride -
parserContext
-
platform
-
instructionContext
-
memBuffer
-
-
Constructor Details
-
DBTraceInstruction
public DBTraceInstruction(DBTraceCodeSpace space, DBTraceAddressSnapRangePropertyMapTree<DBTraceInstruction, ?> tree, DBCachedObjectStore<?> store, DBRecord record) Construct an instruction unit- Parameters:
space- the spacetree- the storage R*-Treestore- the object storerecord- the record
-
-
Method Details
-
doSetPlatformMapping
At load/create time: set the platform and context (which may map addresses)- Parameters:
platform- the platform
-
set
protected void set(InternalTracePlatform platform, InstructionPrototype prototype, ProcessorContextView context, int forcedLengthOverride) Set the fields of this record- Parameters:
platform- the platformprototype- the instruction prototypecontext- the context for locating or creating the prototype entryforcedLengthOverride- reduced instruction byte-length (1..7) or 0 to use default length
-
fresh
Description copied from class:DBAnnotatedObjectExtension point: Called when the object's fields are populated.This provides an opportunity for the object to initialize any non-database-backed fields that depend on the database-backed fields. Note that its use may indicate a situation better solved by a custom
DBCachedObjectStoreFactory.DBFieldCodec. If both the database-backed and non-database-backed fields are used frequently, then a codec may not be indicated. If the database-backed fields are only used in this method or to encode another frequently-used field, then a codec is likely better.For a new object, the database-backed fields remain at their initial values. They will be saved after this method returns, so they may be further initialized with custom logic.
For an object loaded from the database, the database-backed fields are already populated from the record when this method is called. They are not automatically saved after this method returns. This method should not further initialize database-backed fields in this case.
- Overrides:
freshin classDBTraceAddressSnapRangePropertyMapTree.AbstractDBTraceAddressSnapRangePropertyMapData<DBTraceInstruction>- Parameters:
created-truewhen object is being created, orfalsewhen it is being loaded.- Throws:
IOException- if further initialization fails.
-
setRecordValue
Description copied from class:DBTreeDataRecordSet the value of this record Note that the value is sometimes the record itself. In this case, this method expectsvalueto benulland does nothing. SeeSpatialMap.put(BoundedShape, Object)for more details of this pattern.- Specified by:
setRecordValuein classDBTreeDataRecord<TraceAddressSnapRange,TraceAddressSnapRange, DBTraceInstruction> - Parameters:
value- the record's new value
-
getRecordValue
Description copied from class:DBTreeDataRecordGet the value of this record Note that the value is sometimes the record itself, i.e., this method returnsthis. SeeSpatialMap.put(BoundedShape, Object)for more details of this pattern.- Specified by:
getRecordValuein classDBTreeDataRecord<TraceAddressSnapRange,TraceAddressSnapRange, DBTraceInstruction> - Returns:
- the record's value
-
delete
public void delete()Description copied from interface:TraceCodeUnitDelete this code unit- Specified by:
deletein interfaceTraceCodeUnit
-
setEndSnap
public void setEndSnap(long endSnap) Description copied from interface:TraceCodeUnitSet the end snap of this code unit- Specified by:
setEndSnapin interfaceTraceCodeUnit- Overrides:
setEndSnapin classAbstractDBTraceCodeUnit<DBTraceInstruction>- Parameters:
endSnap- the last snap of this unit's lifespan
-
getPlatform
Description copied from interface:TraceCodeUnitGet the platform for this unit- Specified by:
getPlatformin interfaceTraceCodeUnit- Returns:
- the platform
-
getLanguage
Description copied from interface:TraceCodeUnitGet the language of this code unitCurrently, for data units, this is always the base or "host" language of the trace. For instructions, this may be a guest language.
- Specified by:
getLanguagein interfaceTraceCodeUnit- Returns:
- the language
-
toString
- Overrides:
toStringin classDBTreeDataRecord<TraceAddressSnapRange,TraceAddressSnapRange, DBTraceInstruction>
-
getNext
Description copied from interface:TraceInstructionNote that it is possible instructions are staggered vertically, in which case, multiple instructions may immediately follow this in terms of the address. The rule to resolve this ambiguity is that we only consider instructions containing the starting snap of this instruction.
- Specified by:
getNextin interfaceInstruction- Specified by:
getNextin interfaceTraceInstruction- Returns:
- the instruction following this one in address order or null if none found.
-
getPrevious
Description copied from interface:TraceInstructionNote that it is possible instructions are staggered vertically, in which case, multiple instruction may immediately precede this in terms of the address. The rule to resolve this ambiguity is that we only consider instructions containing the start snap of this instruction.
- Specified by:
getPreviousin interfaceInstruction- Specified by:
getPreviousin interfaceTraceInstruction- Returns:
- the instruction before this one in address order or null if none found.
-
getPrototype
- Specified by:
getPrototypein interfaceInstruction- Returns:
- the prototype for this instruction.
-
getOperandType
public int getOperandType(int opIndex) Description copied from interface:InstructionGet the type of a specific operand.- Specified by:
getOperandTypein interfaceInstruction- Specified by:
getOperandTypein interfaceInstructionAdapterFromPrototype- Parameters:
opIndex- the index of the operand. (zero based)- Returns:
- the type of the operand.
- See Also:
-
getAddress
Description copied from interface:CodeUnitGet the Address for the given operand index if one exists. Data objects have one operand (the value).- Specified by:
getAddressin interfaceCodeUnit- Specified by:
getAddressin interfaceInstructionAdapterFromPrototype- Parameters:
opIndex- index of the operand.- Returns:
- An address if the operand represents a fully qualified address (given the context), or if the operand is a Scalar treated as an address. Null is returned if no address or scalar exists on that operand.
-
getDefaultFallThrough
Description copied from interface:TraceInstructionGet the default fallthrough for this instruction. This accounts for any instructions contained with delay slots.If the instruction is of a guest language, the returned address is mapped into the trace's base address space
- Specified by:
getDefaultFallThroughin interfaceInstruction- Specified by:
getDefaultFallThroughin interfaceTraceInstruction- Returns:
- fall-through address or null if instruction has no default fallthrough
-
getGuestDefaultFallThrough
Description copied from interface:TraceInstructionGet the default fall-through as viewed in the instruction's native address space- Specified by:
getGuestDefaultFallThroughin interfaceTraceInstruction- Returns:
- the default fall-through
-
getFallThrough
Description copied from interface:InstructionGet the fallthrough for this instruction, factoring in any fallthrough override and delay slotted instructions.- Specified by:
getFallThroughin interfaceInstruction- Returns:
- fall-through address or null if instruction has no fallthrough
-
getFallFrom
- Specified by:
getFallFromin interfaceInstruction- Returns:
- the Address for the instruction that fell through to
this instruction.
This is useful for handling instructions that are found
in a delay slot.
Note: if an instruction is in a delayslot, then it may have
a branch into the delayslot, which is handled as follows
JMPIF Y, X lab: _ADD getFallFrom() = JMPIF MOV getFallFrom() = _ADD JMP Y, X lab: _ADD getFallFrom() = null MOV getFallFrom() = _ADD JMPIF Y, X _ADD getFallFrom() = JMPIF MOV getFallFrom() = JMPIF JMP Y, X _ADD getFallFrom() = JMP MOV getFallFrom() = null
-
getFlows
Description copied from interface:InstructionGet an array of Address objects for all flows other than a fall-through. This will include any flow references which have been added to the instruction.- Specified by:
getFlowsin interfaceInstruction- Returns:
- flow addresses or null if there are no flows
-
getDefaultFlows
Description copied from interface:TraceInstructionGet an array of Address objects for all default flows established by the underlying instruction prototype. References are ignored.If the instruction is of a guest language, the returned addresses are mapped into the trace's base address space
- Specified by:
getDefaultFlowsin interfaceInstruction- Specified by:
getDefaultFlowsin interfaceTraceInstruction- Returns:
- flow addresses or null if there are no flows
-
getGuestDefaultFlows
Description copied from interface:TraceInstructionGet the default flows as viewed in the instruction's native address space- Specified by:
getGuestDefaultFlowsin interfaceTraceInstruction- Returns:
- the default flows
-
getFlowType
- Specified by:
getFlowTypein interfaceInstruction- Returns:
- the flow type of this instruction (how this instruction flows to the next instruction).
-
isFallthrough
public boolean isFallthrough()- Specified by:
isFallthroughin interfaceInstruction- Returns:
- true if this instruction has no execution flow other than fall-through.
-
hasFallthrough
public boolean hasFallthrough()- Specified by:
hasFallthroughin interfaceInstruction- Returns:
- true if this instruction has a fall-through flow.
-
getFlowOverride
- Specified by:
getFlowOverridein interfaceInstruction- Returns:
- the flow override which may have been set on this instruction.
-
setFlowOverride
Description copied from interface:InstructionSet the flow override for this instruction.- Specified by:
setFlowOverridein interfaceInstruction- Parameters:
flowOverride- flow override setting orFlowOverride.NONEto clear.
-
setLengthOverride
Description copied from interface:InstructionSet instruction length override. Specified length must be in the range 0..7 where 0 clears the setting and adopts the default length. The specified length must be less than the actual number of bytes consumed by the prototype and be a multiple of the language specified instruction alignment.NOTE: Use of the feature with a delay slot instruction is discouraged.
- Specified by:
setLengthOverridein interfaceInstruction- Parameters:
length- effective instruction code unit length.- Throws:
CodeUnitInsertionException- if expanding instruction length conflicts with another instruction or length is not a multiple of the language specified instruction alignment.
-
isLengthOverridden
public boolean isLengthOverridden()Description copied from interface:InstructionDetermine if an instruction length override has been set.- Specified by:
isLengthOverriddenin interfaceInstruction- Returns:
- true if length override has been set else false.
-
getLength
public int getLength()Description copied from interface:CodeUnitGet length of this code unit. NOTE: If aninstruction length-overrideis set this method will return the reduced length.- Specified by:
getLengthin interfaceCodeUnit- Overrides:
getLengthin classAbstractDBTraceCodeUnit<DBTraceInstruction>- Returns:
- code unit length
-
getParsedLength
public int getParsedLength()Description copied from interface:InstructionGet the actual number of bytes parsed when forming this instruction. While this method will generally return the same value asCodeUnit.getLength(), its value will differ whenInstruction.setLengthOverride(int)has been used. In addition, it is important to note thatCodeUnit.getMaxAddress()will always reflect a non-overlapping address which reflectsCodeUnit.getLength(). This method is equivalent to the following code for a given instruction:
InstructionPrototypeproto = instruction.Instruction.getPrototype(); int length = proto.getLength();- Specified by:
getParsedLengthin interfaceInstruction- Returns:
- the actual number of bytes parsed when forming this instruction
-
getParsedBytes
Description copied from interface:InstructionGet the actual bytes parsed when forming this instruction. While this method will generally return the same value asCodeUnit.getBytes(), it will return more bytes whenInstruction.setLengthOverride(int)has been used. In this override situation, the bytes returned will generally duplicate some of the parsed bytes associated with the next instruction that this instruction overlaps. This method is equivalent to the following code for a given instruction:
InstructionPrototypeproto = instruction.Instruction.getPrototype();Memorymem = instruction.MemBuffer.getMemory(); byte[] bytes = mem.getBytes(instruction.MemBuffer.getAddress(), proto.getLength()); int length = proto.getLength();- Specified by:
getParsedBytesin interfaceInstruction- Returns:
- the actual number of bytes parsed when forming this instruction
- Throws:
MemoryAccessException- if the full number of bytes could not be read
-
setFallThrough
Description copied from interface:InstructionOverrides the instruction's default fallthrough address to the given address. The given address may be null to indicate that the instruction has no fallthrough.- Specified by:
setFallThroughin interfaceInstruction- Parameters:
fallThrough- the address to be used as this instructions fallthrough address. May be null.
-
clearFallThroughOverride
public void clearFallThroughOverride()Description copied from interface:InstructionRestores this instruction's fallthrough address back to the default fallthrough for this instruction.- Specified by:
clearFallThroughOverridein interfaceInstruction
-
isFallThroughOverridden
public boolean isFallThroughOverridden()- Specified by:
isFallThroughOverriddenin interfaceInstruction- Returns:
- true if this instructions fallthrough has been overriden.
-
getInstructionContext
- Specified by:
getInstructionContextin interfaceInstruction- Returns:
- the instruction context for this instruction
-
setValue
Description copied from interface:ProcessorContextSets the value for a Register.- Specified by:
setValuein interfaceProcessorContext- Parameters:
register- the register to have its value setvalue- the value for the register (null is not permitted).- Throws:
ContextChangeException- an illegal attempt to change context was made
-
setRegisterValue
Description copied from interface:ProcessorContextSets the specified register value within this context.- Specified by:
setRegisterValuein interfaceProcessorContext- Parameters:
value- register value- Throws:
ContextChangeException- an illegal attempt to change context was made
-
clearRegister
Description copied from interface:ProcessorContextClears the register within this context.- Specified by:
clearRegisterin interfaceProcessorContext- Parameters:
register- register to be cleared.- Throws:
ContextChangeException- an illegal attempt to change context was made
-
getBaseContextRegister
- Specified by:
getBaseContextRegisterin interfaceProcessorContextView- Returns:
- the base processor context register or null if one has not been defined
-
getRegisters
Description copied from interface:ProcessorContextViewReturns all the Registers for the processor as an unmodifiable list- Specified by:
getRegistersin interfaceProcessorContextView- Returns:
- all the Registers for the processor
-
getRegister
Description copied from interface:ProcessorContextViewGet a Register given the name of a register- Specified by:
getRegisterin interfaceProcessorContextView- Parameters:
name- the name of the register.- Returns:
- The register with the given name.
-
getValue
Description copied from interface:ProcessorContextViewGet the contents of a processor register as a BigInteger object- Specified by:
getValuein interfaceProcessorContextView- Parameters:
register- register to get the value for- Returns:
- a BigInteger object containing the value of the register if a value exists, otherwise null.
-
getRegisterValue
Description copied from interface:ProcessorContextViewGet the RegisterValue for the given register.- Specified by:
getRegisterValuein interfaceProcessorContextView- Parameters:
register- register to get the value for- Returns:
- RegisterValue object containing the value of the register if a value exists, otherwise null.
-
hasValue
Description copied from interface:ProcessorContextViewReturns true if a value is defined for the given register.- Specified by:
hasValuein interfaceProcessorContextView- Parameters:
register- the register to check for a value.- Returns:
- true if the given register has a value.
-
getProcessorContext
Description copied from interface:InstructionContextGet the read-only processor context containing the context-register state state at the corresponding instruction. This is primarily used during the parse phase to provide the initial context-register state.- Specified by:
getProcessorContextin interfaceInstructionContext- Returns:
- the read-only processor context
-
getMemBuffer
Description copied from interface:InstructionContextGet the read-only memory buffer containing the instruction bytes. Its position will correspond to the instruction address.- Specified by:
getMemBufferin interfaceInstructionContext- Returns:
- instruction memory buffer
-
getParserContext
Description copied from interface:InstructionContextGet the instruction parser context for the instruction which corresponds to this context object.- Specified by:
getParserContextin interfaceInstructionContext- Returns:
- the instruction parser context for the instruction which corresponds to this context object.
- Throws:
MemoryAccessException- if memory error occurred while resolving instruction details.
-
getParserContext
public ParserContext getParserContext(Address instructionAddress) throws UnknownContextException, MemoryAccessException Description copied from interface:InstructionContextGet the instruction parser context which corresponds to the specified instruction address. This may be obtained via either caching or by parsing the instruction at the specified address. The returned ParserContext may be cast to the prototype's implementation without checking. This method will throw an UnknownContextException if a compatible ParserContext is not found at the specified address.- Specified by:
getParserContextin interfaceInstructionContext- Parameters:
instructionAddress- instruction address of requested context- Returns:
- the instruction parser context at the specified instruction address
- Throws:
UnknownContextException- if the instruction at the specified address was not previously parsed or attempting to instantiate context resulted in an exception.MemoryAccessException- if memory error occurred while resolving instruction details.
-