Class DBTraceTimeViewport

java.lang.Object
ghidra.trace.database.DBTraceTimeViewport
All Implemented Interfaces:
TraceTimeViewport

public class DBTraceTimeViewport extends Object implements TraceTimeViewport
Computes and tracks the "viewport" resulting from forking patterns encoded in snapshot schedules

This is used primarily by the TraceProgramView implementation to resolve most-recent objects according to a layering or forking structure given in snapshot schedules. This listens on the given trace for changes in snapshot schedules and keeps an up-to-date set of visible (or potentially-visible) ranges from the given snap.

TODO: Because complicated forking structures are not anticipated, some minimal effort is given to cull meaningless changes, but in general, changes cause a complete re-computation of the viewport. If complex, deep forking structures prove to be desirable, then this is an area for optimization.

  • Field Details

    • trace

      protected final Trace trace
    • ordered

      protected final List<Lifespan> ordered
      NB: This is also the syncing object for the viewport. If there's even a chance an operation may need the DB's lock, esp., considering user callbacks, then it must first acquire the DB lock.
    • spanSet

      protected final Lifespan.MutableLifeSet spanSet
    • changeListeners

      protected final ListenerSet<Runnable> changeListeners
    • snap

      protected long snap
  • Constructor Details

    • DBTraceTimeViewport

      protected DBTraceTimeViewport(Trace trace)
  • Method Details

    • addChangeListener

      public void addChangeListener(Runnable l)
      Description copied from interface: TraceTimeViewport
      Add a listener for when the forking structure of this viewport changes

      This can occur when the snap changes or when any snapshot involved changes

      Specified by:
      addChangeListener in interface TraceTimeViewport
      Parameters:
      l - the listener
    • removeChangeListener

      public void removeChangeListener(Runnable l)
      Description copied from interface: TraceTimeViewport
      Remove a listener for forking structure changes
      Specified by:
      removeChangeListener in interface TraceTimeViewport
      Parameters:
      l - the listener
      See Also:
    • containsAnyUpper

      public boolean containsAnyUpper(Lifespan range)
      Description copied from interface: TraceTimeViewport
      Check if the given lifespan contains any upper snap among the involved spans
      Specified by:
      containsAnyUpper in interface TraceTimeViewport
      Parameters:
      range - the lifespan to consider
      Returns:
      true if it contains any upper snap, false otherwise.
    • isCompletelyVisible

      public <T> boolean isCompletelyVisible(AddressRange range, Lifespan lifespan, T object, TraceTimeViewport.Occlusion<T> occlusion)
      Description copied from interface: TraceTimeViewport
      Check if any part of the given object is occluded by more-recent objects
      Specified by:
      isCompletelyVisible in interface TraceTimeViewport
      Type Parameters:
      T - the type of the object
      Parameters:
      range - the address range of the object
      lifespan - the lifespan of the object
      object - optionally, the object to examine. Used to avoid "self occlusion"
      occlusion - a mechanism for querying other like objects and checking for occlusion
      Returns:
      true if completely visible, false if even partially occluded
    • computeVisibleParts

      public <T> AddressSet computeVisibleParts(AddressSetView set, Lifespan lifespan, T object, TraceTimeViewport.Occlusion<T> occlusion)
      Description copied from interface: TraceTimeViewport
      Compute the parts of a given object that are visible past more-recent objects
      Specified by:
      computeVisibleParts in interface TraceTimeViewport
      Type Parameters:
      T - the type of the object
      Parameters:
      set - the addresses comprising the object
      lifespan - the lifespan of the object
      object - the object to examine
      occlusion - a mechanism for query other like objects and removing occluded parts
      Returns:
      the set of visible addresses
    • isLower

      protected boolean isLower(long lower)
    • addSnapRange

      protected static boolean addSnapRange(long lower, long upper, Lifespan.MutableLifeSet spanSet, List<Lifespan> ordered)
    • locateMostRecentFork

      protected static TraceSnapshot locateMostRecentFork(TraceTimeManager timeManager, long from)
    • collectForkRanges

      protected static void collectForkRanges(TraceTimeManager timeManager, long curSnap, Lifespan.MutableLifeSet spanSet, List<Lifespan> ordered)
      Construct the ranges (set and ordered)

      NOTE: I cannot hold the lock during this, because I also require the DB's read lock. There are other operations, e.g., addRegion, that will hold the DB's write lock, and then also require the viewport's lock to check if it is visible. That would cause the classic tango of death.

      Parameters:
      curSnap - the seed snap
    • refreshSnapRanges

      protected void refreshSnapRanges()
    • setSnap

      public void setSnap(long snap)
      Description copied from interface: TraceTimeViewport
      Set the snapshot for this viewport
      Specified by:
      setSnap in interface TraceTimeViewport
      Parameters:
      snap - the snap
    • updateSnapshotAdded

      protected void updateSnapshotAdded(TraceSnapshot snapshot)
    • updateSnapshotChanged

      protected void updateSnapshotChanged(TraceSnapshot snapshot)
    • updateSnapshotDeleted

      protected void updateSnapshotDeleted(TraceSnapshot snapshot)
    • checkSnapshotAddedNeedsRefresh

      protected boolean checkSnapshotAddedNeedsRefresh(TraceSnapshot snapshot)
    • checkSnapshotChangedNeedsRefresh

      protected boolean checkSnapshotChangedNeedsRefresh(TraceSnapshot snapshot)
    • checkSnapshotDeletedNeedsRefresh

      protected boolean checkSnapshotDeletedNeedsRefresh(TraceSnapshot snapshot)
    • isForked

      public boolean isForked()
      Description copied from interface: TraceTimeViewport
      Check if this view is forked

      The view is considered forked if any snap previous to this has a schedule with an initial snap other than the immediately-preceding one. Such forks "break" the linearity of the trace's usual time line.

      Specified by:
      isForked in interface TraceTimeViewport
      Returns:
      true if forked, false otherwise
    • getOrderedSpans

      public List<Lifespan> getOrderedSpans()
      Description copied from interface: TraceTimeViewport
      Get the spans involved in the view in most-recent-first order
      Specified by:
      getOrderedSpans in interface TraceTimeViewport
      Returns:
      the list of spans
    • getReversedSpans

      public List<Lifespan> getReversedSpans()
      Description copied from interface: TraceTimeViewport
      Get the spans involved in the view in least-recent-first order
      Specified by:
      getReversedSpans in interface TraceTimeViewport
      Returns:
      the list of spans
    • getOrderedSpans

      public List<Lifespan> getOrderedSpans(long snap)
    • getOrderedSnaps

      public List<Long> getOrderedSnaps()
      Description copied from interface: TraceTimeViewport
      Get the snaps involved in the view in most-recent-first order

      The first is always this view's snap. Following are the source snaps of each previous snapshot's schedule where applicable.

      Specified by:
      getOrderedSnaps in interface TraceTimeViewport
      Returns:
      the list of snaps
    • getReversedSnaps

      public List<Long> getReversedSnaps()
      Description copied from interface: TraceTimeViewport
      Get the snaps involved in the view in least-recent-first order
      Specified by:
      getReversedSnaps in interface TraceTimeViewport
      Returns:
      the list of snaps
    • getTop

      public <T> T getTop(Function<Long,T> func)
      Description copied from interface: TraceTimeViewport
      Get the first non-null result of the function, applied to the most-recent snaps first

      Typically, func both retrieves an object and tests for its suitability.

      Specified by:
      getTop in interface TraceTimeViewport
      Type Parameters:
      T - the type of object to retrieve
      Parameters:
      func - the function on a snap to retrieve an object
      Returns:
      the first non-null result
    • mergedIterator

      public <T> Iterator<T> mergedIterator(Function<Long,Iterator<T>> iterFunc, Comparator<? super T> comparator)
      Description copied from interface: TraceTimeViewport
      Merge iterators from each involved snap into a single iterator

      Typically, the resulting iterator is passed through a filter to test each objects suitability.

      Specified by:
      mergedIterator in interface TraceTimeViewport
      Type Parameters:
      T - the type of objects in each iterator
      Parameters:
      iterFunc - a function on a snap to retrieve each iterator
      comparator - the comparator for merging, which must yield the same order as each iterator
      Returns:
      the merged iterator
    • unionedAddresses

      public AddressSetView unionedAddresses(Function<Long,AddressSetView> viewFunc)
      Description copied from interface: TraceTimeViewport
      Union address sets from each involved snap

      The returned union is computed lazily.

      Specified by:
      unionedAddresses in interface TraceTimeViewport
      Parameters:
      viewFunc - a function on a snap to retrieve the address set
      Returns:
      the union