Class DBTraceMemorySpace
- All Implemented Interfaces:
InternalTraceMemoryOperations,DBTraceSpaceBased,TraceMemoryOperations,TraceMemorySpace,TraceSpaceMixin
TraceMemorySpace using a database-backed copy-on-write store.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intprotected final Map<DBTraceUtils.OffsetSnap, ghidra.trace.database.memory.DBTraceMemoryBlockEntry> static final intprotected final DBCachedObjectIndex<DBTraceUtils.OffsetSnap, ghidra.trace.database.memory.DBTraceMemoryBlockEntry> protected final DBCachedObjectStore<ghidra.trace.database.memory.DBTraceMemoryBlockEntry> protected final DBCachedObjectStore<DBTraceMemoryBufferEntry> protected final DBHandlestatic final intprotected final ReadWriteLockprotected final DBTraceMemoryManagerprotected final AddressSpaceprotected final DBTraceAddressSnapRangePropertyMapSpace<TraceMemoryState, ghidra.trace.database.memory.DBTraceMemoryStateEntry> protected final DBTraceprotected final DBTraceTimeViewport -
Constructor Summary
ConstructorsConstructorDescriptionDBTraceMemorySpace(DBTraceMemoryManager manager, DBHandle dbh, AddressSpace space, AbstractDBTraceSpaceBasedManager.DBTraceSpaceEntry ent) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckState(TraceMemoryState state) voidprotected booleandoCheckBytesChanged(long snap, AddressRange range, ByteBuffer buf1, ByteBuffer buf2) protected booleandoCheckBytesChanged(DBTraceUtils.OffsetSnap loc, int srcOffset, int maxLen, ByteBuffer eBuf, ByteBuffer pBuf) protected AddressdoFindBytesInRange(long snap, AddressRange range, ByteBuffer data, ByteBuffer mask, boolean forward, TaskMonitor monitor) protected voiddoGetBytes(DBTraceUtils.OffsetSnap loc, ByteBuffer buf, int srcOffset, int maxLen) protected Collection<Map.Entry<TraceAddressSnapRange, TraceMemoryState>> doGetStates(Lifespan span, AddressRange range) protected intdoPutBytes(long snap, Address start, ByteBuffer buf, DBTraceMemorySpace.OutSnap lastSnap, Set<TraceAddressSnapRange> changed) protected voiddoPutBytes(DBTraceUtils.OffsetSnap loc, ByteBuffer buf, int dstOffset, int maxLen) protected voiddoPutFutureBytes(DBTraceUtils.OffsetSnap loc, ByteBuffer buf, int dstOffset, int maxLen, DBTraceMemorySpace.OutSnap lastSnap, Set<TraceAddressSnapRange> changed) protected voiddoSetState(long snap, Address start, Address end, TraceMemoryState state) findBytes(long snap, AddressRange range, ByteBuffer data, ByteBuffer mask, boolean forward, TaskMonitor monitor) Search the given address range at the given snap for a given byte patternprotected ghidra.trace.database.memory.DBTraceMemoryBlockEntryfindMostRecentBlockEntry(DBTraceUtils.OffsetSnap loc, boolean inclusive) protected ghidra.trace.database.memory.DBTraceMemoryBlockEntryfindSoonestBlockEntry(DBTraceUtils.OffsetSnap loc, boolean inclusive) Locate the soonest block entry for the given offset-snap pairgetAddressesWithState(long snap, Predicate<TraceMemoryState> predicate) Get the addresses having state satisfying the given predicategetAddressesWithState(Lifespan span, AddressSetView set, Predicate<TraceMemoryState> predicate) Get at least the subset of addresses having state satisfying the given predicategetAddressesWithState(Lifespan lifespan, Predicate<TraceMemoryState> predicate) Get the addresses having state satisfying the given predicate at any time in the specified lifespanGet the address spaceintGet the block size used by internal storage.getBufferAt(long snap, Address start, ByteOrder byteOrder) Get a view of a particular snap as a memory bufferintgetBytes(long snap, Address start, ByteBuffer buf) Read the most recent bytes from the given snap and addressgetCodeSpace(boolean createIfAbsent) Get the code space for this memory spacelonggetFirstChange(Lifespan span, AddressRange range) Determine the truncation snap if the given span and range include byte changesgetLock()getMostRecentStateEntry(long snap, Address address) Get the entry recording the most recent state at the given snap and addressBreak a range of addresses into smaller ranges each mapped to its most recent state at the given timegetSnapOfMostRecentChangeToBlock(long snap, Address address) Find the internal storage block that most-recently defines the value at the given snap and address, and return the block's snap.getSpace()For register mapping conventionsGet the state of memory at a given snap and addressgetStates(long snap, AddressRange range) Break a range of addresses into smaller ranges each mapped to its state at the given snapgetTrace()Get the trace to which the memory manager belongsintgetViewBytes(long snap, Address start, ByteBuffer buf) Read the most recent bytes from the given snap and address, following schedule forksgetViewMostRecentStateEntry(long snap, Address address) Get the entry recording the most recent state at the given snap and address, following schedule forksgetViewMostRecentStateEntry(long snap, AddressRange range, Predicate<TraceMemoryState> predicate) Get the entry recording the most recent state since the given snap within the given range that satisfies a given predicate, following schedule forksgetViewState(long snap, Address address) Get the state of memory at a given snap and address, following schedule forksvoidprotected booleanisCross(long lower, long upper) voidpack()Optimize storage spaceintputBytes(long snap, Address start, ByteBuffer buf) Write bytes at the given snap and addressvoidremoveBytes(long snap, Address start, int len) Remove bytes from the given time and locationvoidsetState(long snap, AddressRange range, TraceMemoryState state) Set the state of memory over a given time and address rangevoidsetState(long snap, Address start, Address end, TraceMemoryState state) voidsetState(long snap, Address address, TraceMemoryState state) voidsetState(long snap, AddressSetView set, TraceMemoryState state) Set the state of memory over a given time and address setprotected inttruncateLen(int len, Address start) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ghidra.trace.database.space.DBTraceSpaceBased
assertInSpace, assertInSpace, explainLanguages, isMySpace, toAddress, toOverlayMethods inherited from interface ghidra.trace.database.memory.InternalTraceMemoryOperations
getBytes, getState, getStates, getValue, getViewValue, putBytes, removeValue, setState, setValueMethods inherited from interface ghidra.trace.model.memory.TraceMemoryOperations
getAddressesWithState, getBufferAt, getBytes, getMostRecentStates, getState, getStates, getValue, getViewValue, isKnown, putBytes, removeValue, setState, setValueMethods inherited from interface ghidra.trace.util.TraceSpaceMixin
getFrameLevel, getThread
-
Field Details
-
BLOCK_SHIFT
public static final int BLOCK_SHIFT- See Also:
-
BLOCK_SIZE
public static final int BLOCK_SIZE- See Also:
-
BLOCK_MASK
public static final int BLOCK_MASK- See Also:
-
DEPENDENT_COMPRESSED_SIZE_TOLERANCE
public static final int DEPENDENT_COMPRESSED_SIZE_TOLERANCE- See Also:
-
BLOCKS_PER_BUFFER
public static final int BLOCKS_PER_BUFFER- See Also:
-
manager
-
dbh
-
space
-
lock
-
trace
-
stateMapSpace
protected final DBTraceAddressSnapRangePropertyMapSpace<TraceMemoryState,ghidra.trace.database.memory.DBTraceMemoryStateEntry> stateMapSpace -
bufferStore
-
blockStore
protected final DBCachedObjectStore<ghidra.trace.database.memory.DBTraceMemoryBlockEntry> blockStore -
blocksByOffset
protected final DBCachedObjectIndex<DBTraceUtils.OffsetSnap,ghidra.trace.database.memory.DBTraceMemoryBlockEntry> blocksByOffset -
blockCacheMostRecent
protected final Map<DBTraceUtils.OffsetSnap,ghidra.trace.database.memory.DBTraceMemoryBlockEntry> blockCacheMostRecent -
viewport
-
-
Constructor Details
-
DBTraceMemorySpace
public DBTraceMemorySpace(DBTraceMemoryManager manager, DBHandle dbh, AddressSpace space, AbstractDBTraceSpaceBasedManager.DBTraceSpaceEntry ent) throws IOException, VersionException - Throws:
IOExceptionVersionException
-
-
Method Details
-
getSpace
Description copied from interface:InternalTraceMemoryOperationsFor register mapping conventions- Specified by:
getSpacein interfaceInternalTraceMemoryOperations- Returns:
- the address space
-
getLock
- Specified by:
getLockin interfaceInternalTraceMemoryOperations
-
getTrace
Description copied from interface:TraceMemoryOperationsGet the trace to which the memory manager belongs- Specified by:
getTracein interfaceTraceMemoryOperations- Specified by:
getTracein interfaceTraceSpaceMixin- Returns:
- the trace
-
getCodeSpace
Description copied from interface:TraceMemorySpaceGet the code space for this memory spaceThis is a convenience for
TraceCodeManager.getCodeSpace(AddressSpace, boolean)on this same address space.- Specified by:
getCodeSpacein interfaceTraceMemorySpace- Parameters:
createIfAbsent- true to create the space if it's not already present- Returns:
- the code space
-
getAddressSpace
Description copied from interface:TraceMemorySpaceGet the address space- Specified by:
getAddressSpacein interfaceTraceMemorySpace- Specified by:
getAddressSpacein interfaceTraceSpaceMixin- Returns:
- the address space
-
doSetState
-
checkState
-
checkStateMapIntegrity
public void checkStateMapIntegrity() -
setState
- Specified by:
setStatein interfaceTraceMemoryOperations- See Also:
-
setState
Description copied from interface:TraceMemoryOperationsSet the state of memory over a given time and address rangeSetting state to
TraceMemoryState.KNOWNvia this method is not recommended. Setting bytes will automatically update the state accordingly.- Specified by:
setStatein interfaceTraceMemoryOperations- Parameters:
snap- the timerange- the rangestate- the state
-
setState
- Specified by:
setStatein interfaceTraceMemoryOperations- See Also:
-
setState
Description copied from interface:TraceMemoryOperationsSet the state of memory over a given time and address set- Specified by:
setStatein interfaceTraceMemoryOperations- See Also:
-
getState
Description copied from interface:TraceMemoryOperationsGet the state of memory at a given snap and addressIf the location's state has not been set, the result is
null, which impliesTraceMemoryState.UNKNOWN.- Specified by:
getStatein interfaceTraceMemoryOperations- Parameters:
snap- the timeaddress- the location- Returns:
- the state
-
getViewState
Description copied from interface:TraceMemoryOperationsGet the state of memory at a given snap and address, following schedule forks- Specified by:
getViewStatein interfaceTraceMemoryOperations- Parameters:
snap- the timeaddress- the location- Returns:
- the state, and the snap where it was found
-
getMostRecentStateEntry
public Map.Entry<TraceAddressSnapRange,TraceMemoryState> getMostRecentStateEntry(long snap, Address address) Description copied from interface:TraceMemoryOperationsGet the entry recording the most recent state at the given snap and addressThe entry includes the entire entry at that snap. Parts occluded by more recent snaps are not subtracted from the entry's address range.
- Specified by:
getMostRecentStateEntryin interfaceTraceMemoryOperations- Parameters:
snap- the timeaddress- the location- Returns:
- the entry including the entire recorded range
-
getViewMostRecentStateEntry
public Map.Entry<TraceAddressSnapRange,TraceMemoryState> getViewMostRecentStateEntry(long snap, Address address) Description copied from interface:TraceMemoryOperationsGet the entry recording the most recent state at the given snap and address, following schedule forks- Specified by:
getViewMostRecentStateEntryin interfaceTraceMemoryOperations- Parameters:
snap- the latest time to consideraddress- the address- Returns:
- the most-recent entry
-
getViewMostRecentStateEntry
public Map.Entry<TraceAddressSnapRange,TraceMemoryState> getViewMostRecentStateEntry(long snap, AddressRange range, Predicate<TraceMemoryState> predicate) Description copied from interface:TraceMemoryOperationsGet the entry recording the most recent state since the given snap within the given range that satisfies a given predicate, following schedule forks- Specified by:
getViewMostRecentStateEntryin interfaceTraceMemoryOperations- Parameters:
snap- the latest time to considerrange- the range of addressespredicate- a predicate on the state- Returns:
- the most-recent entry
-
getAddressesWithState
Description copied from interface:TraceMemoryOperationsGet the addresses having state satisfying the given predicateThe implementation may provide a view that updates with changes. Behavior is not well defined for predicates testing for
TraceMemoryState.UNKNOWN.- Specified by:
getAddressesWithStatein interfaceTraceMemoryOperations- Parameters:
snap- the timepredicate- a predicate on state to search for- Returns:
- the address set
-
getAddressesWithState
public AddressSetView getAddressesWithState(Lifespan lifespan, Predicate<TraceMemoryState> predicate) Description copied from interface:TraceMemoryOperationsGet the addresses having state satisfying the given predicate at any time in the specified lifespanThe implementation may provide a view that updates with changes. Behavior is not well defined for predicates testing for
TraceMemoryState.UNKNOWN.- Specified by:
getAddressesWithStatein interfaceTraceMemoryOperations- Parameters:
lifespan- the span of timepredicate- a predicate on state to search for- Returns:
- the address set
-
getAddressesWithState
public AddressSetView getAddressesWithState(Lifespan span, AddressSetView set, Predicate<TraceMemoryState> predicate) Description copied from interface:TraceMemoryOperationsGet at least the subset of addresses having state satisfying the given predicateThe implementation may provide a larger view than requested, but within the requested set, only ranges satisfying the predicate may be present. Use
AddressSetView.intersect(AddressSetView)withsetif a strict subset is required.Because
TraceMemoryState.UNKNOWNis not explicitly stored in the map, to compute the set ofTraceMemoryState.UNKNOWNaddresses, use the predicatestate -> state != null && state != TraceMemoryState.UNKNOWNand subtract the result fromset.- Specified by:
getAddressesWithStatein interfaceTraceMemoryOperations- Parameters:
span- the range of timeset- the set to examinepredicate- a predicate on state to search for- Returns:
- the address set
-
doGetStates
protected Collection<Map.Entry<TraceAddressSnapRange,TraceMemoryState>> doGetStates(Lifespan span, AddressRange range) -
getStates
public Collection<Map.Entry<TraceAddressSnapRange,TraceMemoryState>> getStates(long snap, AddressRange range) Description copied from interface:TraceMemoryOperationsBreak a range of addresses into smaller ranges each mapped to its state at the given snapNote that
TraceMemoryState.UNKNOWNentries will not appear in the result. Gaps in the returned entries are implied to beTraceMemoryState.UNKNOWN.- Specified by:
getStatesin interfaceTraceMemoryOperations- Parameters:
snap- the timerange- the range to examine- Returns:
- the map of ranges to states
-
getMostRecentStates
public Iterable<Map.Entry<TraceAddressSnapRange,TraceMemoryState>> getMostRecentStates(TraceAddressSnapRange within) Description copied from interface:TraceMemoryOperationsBreak a range of addresses into smaller ranges each mapped to its most recent state at the given timeTypically
withinis the box whose width is the address range to break down and whose height is from "negative infinity" to the "current" snap.In this context, "most recent" means the latest state other than
TraceMemoryState.UNKNOWN.- Specified by:
getMostRecentStatesin interfaceTraceMemoryOperations- Parameters:
within- a box intersecting entries to consider- Returns:
- an iterable over the snap ranges and states
-
findMostRecentBlockEntry
protected ghidra.trace.database.memory.DBTraceMemoryBlockEntry findMostRecentBlockEntry(DBTraceUtils.OffsetSnap loc, boolean inclusive) -
findSoonestBlockEntry
protected ghidra.trace.database.memory.DBTraceMemoryBlockEntry findSoonestBlockEntry(DBTraceUtils.OffsetSnap loc, boolean inclusive) Locate the soonest block entry for the given offset-snap pairTo qualify, the entry must have a snap greater than (or optionally equal to) that given and an offset exactly equal to that given. That is, it is the earliest in time, but most follow the given snap. Additionally, if the given snap is in scratch space, the found entry must also be in scratch space.
- Parameters:
loc- the offset-snap pairinclusive- true to allow equal snap- Returns:
- the found entry, or null
-
doPutBytes
protected void doPutBytes(DBTraceUtils.OffsetSnap loc, ByteBuffer buf, int dstOffset, int maxLen) throws IOException - Throws:
IOException
-
doPutFutureBytes
protected void doPutFutureBytes(DBTraceUtils.OffsetSnap loc, ByteBuffer buf, int dstOffset, int maxLen, DBTraceMemorySpace.OutSnap lastSnap, Set<TraceAddressSnapRange> changed) throws IOException - Throws:
IOException
-
doPutBytes
protected int doPutBytes(long snap, Address start, ByteBuffer buf, DBTraceMemorySpace.OutSnap lastSnap, Set<TraceAddressSnapRange> changed) throws IOException - Throws:
IOException
-
putBytes
Description copied from interface:TraceMemoryOperationsWrite bytes at the given snap and addressThis will attempt to read
Buffer.remaining()bytes starting atBuffer.position()from the source bufferbufand write them into memory at the specified time and location. The affected region is also updated toTraceMemoryState.KNOWN. The written bytes are assumed effective for all future snaps up to the next write.- Specified by:
putBytesin interfaceTraceMemoryOperations- Parameters:
snap- the timestart- the locationbuf- the source buffer of bytes- Returns:
- the number of bytes written
-
doGetBytes
protected void doGetBytes(DBTraceUtils.OffsetSnap loc, ByteBuffer buf, int srcOffset, int maxLen) throws IOException - Throws:
IOException
-
getBytes
Description copied from interface:TraceMemoryOperationsRead the most recent bytes from the given snap and addressThis will attempt to read
Buffer.remaining()of the most recent bytes from memory at the specified time and location and write them into the destination bufferbufstarting atBuffer.position(). Where bytes in memory have no defined value, values in the destination buffer are unspecified. The implementation may leave those bytes in the destination buffer unmodified, or it may write zeroes.- Specified by:
getBytesin interfaceTraceMemoryOperations- Parameters:
snap- the timestart- the locationbuf- the destination buffer of bytes- Returns:
- the number of bytes read
-
truncateLen
-
getViewBytes
Description copied from interface:TraceMemoryOperationsRead the most recent bytes from the given snap and address, following schedule forksThis behaves similarly to
TraceMemoryOperations.getBytes(long, Address, ByteBuffer), except it checks for theTraceMemoryState.KNOWNstate among each involved snap range and reads the applicable address ranges, preferring the most recent. Where memory is never known the buffer is left unmodified.- Specified by:
getViewBytesin interfaceTraceMemoryOperations- Parameters:
snap- the timestart- the locationbuf- the destination buffer of bytes- Returns:
- the number of bytes read
-
doFindBytesInRange
protected Address doFindBytesInRange(long snap, AddressRange range, ByteBuffer data, ByteBuffer mask, boolean forward, TaskMonitor monitor) -
findBytes
public Address findBytes(long snap, AddressRange range, ByteBuffer data, ByteBuffer mask, boolean forward, TaskMonitor monitor) Description copied from interface:TraceMemoryOperationsSearch the given address range at the given snap for a given byte pattern- Specified by:
findBytesin interfaceTraceMemoryOperations- Parameters:
snap- the time to searchrange- the address range to searchdata- the values to search formask- a mask on the bits ofdata; or null to match all bytes exactlyforward- true to return the match with the lowest address inrange, false for the highest address.monitor- a monitor for progress reporting and canceling- Returns:
- the minimum address of the matched bytes, or
nullif not found
-
doCheckBytesChanged
protected boolean doCheckBytesChanged(DBTraceUtils.OffsetSnap loc, int srcOffset, int maxLen, ByteBuffer eBuf, ByteBuffer pBuf) throws IOException - Throws:
IOException
-
doCheckBytesChanged
protected boolean doCheckBytesChanged(long snap, AddressRange range, ByteBuffer buf1, ByteBuffer buf2) throws IOException - Throws:
IOException
-
getSnapOfMostRecentChangeToBlock
Description copied from interface:TraceMemoryOperationsFind the internal storage block that most-recently defines the value at the given snap and address, and return the block's snap.This method reveals portions of the internal storage so that clients can optimize difference computations by eliminating corresponding ranges defined by the same block. If the underlying implementation cannot answer this question, this returns the given snap.
- Specified by:
getSnapOfMostRecentChangeToBlockin interfaceTraceMemoryOperations- Parameters:
snap- the timeaddress- the location- Returns:
- the most snap for the most recent containing block
-
getBlockSize
public int getBlockSize()Description copied from interface:TraceMemoryOperationsGet the block size used by internal storage.This method reveals portions of the internal storage so that clients can optimize searches. If the underlying implementation cannot answer this question, this returns 0.
- Specified by:
getBlockSizein interfaceTraceMemoryOperations- Returns:
- the block size
-
isCross
protected boolean isCross(long lower, long upper) -
getFirstChange
Determine the truncation snap if the given span and range include byte changesCode units do not understand or accommodate changes in time, so the underlying bytes of the unit must be the same throughout its lifespan. Typically, units are placed with a desired creation snap, and then its life is extended into the future opportunistically. Thus, when truncating, we desire to keep the start snap, then search for the soonest byte change within the desired lifespan. Furthermore, we generally don't permit a unit to exist in both record and scratch spaces, i.e., it cannot span both the -1 and 0 snaps.
- Parameters:
span- the desired lifespanrange- the address range covered- Returns:
- the first snap that should be excluded, or
Long.MIN_VALUEto indicate no change.
-
removeBytes
Description copied from interface:TraceMemoryOperationsRemove bytes from the given time and locationThis deletes all observed bytes from the given address through length at the given snap. If there were no observations in the range at exactly the given snap, this has no effect. If there were, then those observations are removed. The next time those bytes are read, they will have a value from a previous snap, or no value at all. The affected region's state is also deleted, i.e., set to
null, implyingTraceMemoryState.UNKNOWN.Note, use of this method is discouraged. The more observations within the same range that follow the deleted observation, the more expensive this operation typically is, since all of those observations may need to be updated.
- Specified by:
removeBytesin interfaceTraceMemoryOperations- Parameters:
snap- the timestart- the locationlen- the number of bytes to remove
-
getBufferAt
Description copied from interface:TraceMemoryOperationsGet a view of a particular snap as a memory bufferThe bytes read by this buffer are the most recent bytes written before the given snap
- Specified by:
getBufferAtin interfaceTraceMemoryOperations- Parameters:
snap- the snapstart- the starting addressbyteOrder- the byte ordering for this buffer- Returns:
- the memory buffer
-
pack
public void pack()Description copied from interface:TraceMemoryOperationsOptimize storage spaceThis gives the implementation an opportunity to clean up garbage, apply compression, etc., in order to best use the storage space. Because memory observations can be sparse, a trace's memory is often compressible, and observations are not often modified or deleted, packing is recommended whenever the trace is saved to disk.
- Specified by:
packin interfaceTraceMemoryOperations
-
invalidateCache
public void invalidateCache()- Specified by:
invalidateCachein interfaceDBTraceSpaceBased
-