Class SourceFileManagerDB
java.lang.Object
ghidra.program.database.sourcemap.SourceFileManagerDB
- All Implemented Interfaces:
ErrorHandler
,ManagerDB
,SourceFileManager
public class SourceFileManagerDB
extends Object
implements SourceFileManager, ManagerDB, ErrorHandler
Database Manager for managing source files and source map information.
-
Field Summary
FieldsFields inherited from interface ghidra.program.model.sourcemap.SourceFileManager
DUMMY
-
Constructor Summary
ConstructorsConstructorDescriptionSourceFileManagerDB
(DBHandle dbh, AddressMapDB addrMap, OpenMode openMode, Lock lock, TaskMonitor monitor) Constructor -
Method Summary
Modifier and TypeMethodDescriptionboolean
addSourceFile
(SourceFile sourceFile) Adds aSourceFile
to this manager.addSourceMapEntry
(SourceFile sourceFile, int lineNumber, Address baseAddr, long length) Creates aSourceMapEntry
withSourceFile
sourceFile
, line numberlineNumber
, and non-negative lengthlength
and adds it to the program database.boolean
containsSourceFile
(SourceFile sourceFile) Returns true precisely when this manager containssourceFile
.void
Notification that an IO exception occurred.void
deleteAddressRange
(Address start, Address end, TaskMonitor monitor) Delete all objects which have been applied to the address range startAddr to endAddr and update the database accordingly.Returns aList
containing allSourceFile
s of the program.Returns aList
containingSourceFile
s which are mapped to at least one address in the programgetSourceMapEntries
(SourceFile sourceFile, int minLine, int maxLine) Returns the sorted list ofSourceMapEntry
s forsourceFile
with line number betweenminLine
andmaxLine
, inclusive.getSourceMapEntries
(Address addr) Returns a sorted list ofSourceMapEntry
s associated with an addressaddr
.getSourceMapEntryIterator
(Address address, boolean forward) Returns aSourceMapEntryIterator
starting ataddress
.boolean
void
invalidateCache
(boolean all) Clears all data caches.void
moveAddressRange
(Address fromAddr, Address toAddr, long length, TaskMonitor monitor) Move all objects within an address range to a new location.void
programReady
(OpenMode openMode, int currentRevision, TaskMonitor monitor) Callback from program made to each manager after the program has completed initialization.boolean
removeSourceFile
(SourceFile sourceFile) Removes aSourceFile
from this manager.boolean
Removes aSourceMapEntry
from this manager.void
setProgram
(ProgramDB program) Callback from program used to indicate all manager have been created.void
transferSourceMapEntries
(SourceFile source, SourceFile target) Changes the source map so that anySourceMapEntry
associated withsource
is associated withtarget
instead.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ghidra.program.model.sourcemap.SourceFileManager
addSourceMapEntry, getSourceMapEntries, getSourceMapEntries
-
Field Details
-
lock
-
-
Constructor Details
-
SourceFileManagerDB
public SourceFileManagerDB(DBHandle dbh, AddressMapDB addrMap, OpenMode openMode, Lock lock, TaskMonitor monitor) throws VersionException Constructor- Parameters:
dbh
- database handleaddrMap
- map longs to addressesopenMode
- modelock
- program synchronization lockmonitor
- task monitor- Throws:
VersionException
- if the database is incompatible with the current schema
-
-
Method Details
-
setProgram
Description copied from interface:ManagerDB
Callback from program used to indicate all manager have been created. When this method is invoked, all managers have been instantiated but may not be fully initialized.- Specified by:
setProgram
in interfaceManagerDB
- Parameters:
program
- the program is set when all the initializations have been completed.
-
programReady
public void programReady(OpenMode openMode, int currentRevision, TaskMonitor monitor) throws IOException, CancelledException Description copied from interface:ManagerDB
Callback from program made to each manager after the program has completed initialization. This method may be used by managers to perform additional upgrading which may have been deferred.- Specified by:
programReady
in interfaceManagerDB
- Parameters:
openMode
- the mode that the program is being opened.currentRevision
- current program revision. If openMode is UPGRADE, this value reflects the pre-upgrade value.monitor
- the task monitor to use in any upgrade operations.- Throws:
IOException
- if a database io error occurs.CancelledException
- if the user cancelled the operation via the task monitor.
-
invalidateCache
Description copied from interface:ManagerDB
Clears all data caches.- Specified by:
invalidateCache
in interfaceManagerDB
- Parameters:
all
- if false, some managers may not need to update their cache if they can tell that its not necessary. If this flag is true, then all managers should clear their cache no matter what.- Throws:
IOException
- if a database io error occurs.
-
deleteAddressRange
public void deleteAddressRange(Address start, Address end, TaskMonitor monitor) throws CancelledException Delete all objects which have been applied to the address range startAddr to endAddr and update the database accordingly. The specified start and end addresses must form a valid range within a singleAddressSpace
.
Note: this method will split any source map entries that intersect the address range but are not entirely contained within it. Parts within the range to delete will be deleted.- Specified by:
deleteAddressRange
in interfaceManagerDB
- Parameters:
start
- first address in rangeend
- last address in rangemonitor
- task monitor- Throws:
CancelledException
- ifmonitor
is cancelled
-
moveAddressRange
public void moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor) throws AddressOverflowException, CancelledException Move all objects within an address range to a new location.
Note: this method will move any source map entry which is entirely contained within the source address range. Entries which also contain addresses outside of this range will be split and parts within the range to move will be moved.- Specified by:
moveAddressRange
in interfaceManagerDB
- Parameters:
fromAddr
- first address of range to be movedtoAddr
- target addresslength
- number of addresses to movemonitor
- task monitor- Throws:
AddressOverflowException
- if overflow occurs when computing new addressesCancelledException
- ifmonitor
is cancelled
-
addSourceFile
Description copied from interface:SourceFileManager
Adds aSourceFile
to this manager. A SourceFile must be added before it can be associated with any source map information.- Specified by:
addSourceFile
in interfaceSourceFileManager
- Parameters:
sourceFile
- source file to add (can't be null)- Returns:
- true if this manager did not already contain sourceFile
- Throws:
LockException
- if invoked without exclusive access
-
removeSourceFile
Description copied from interface:SourceFileManager
Removes aSourceFile
from this manager. Any associatedSourceMapEntry
s will also be removed.- Specified by:
removeSourceFile
in interfaceSourceFileManager
- Parameters:
sourceFile
- source file to remove- Returns:
- true if sourceFile was in the manager
- Throws:
LockException
- if invoked without exclusive access
-
getSourceMapEntries
Description copied from interface:SourceFileManager
Returns a sorted list ofSourceMapEntry
s associated with an addressaddr
.- Specified by:
getSourceMapEntries
in interfaceSourceFileManager
- Parameters:
addr
- address- Returns:
- line number
-
addSourceMapEntry
public SourceMapEntry addSourceMapEntry(SourceFile sourceFile, int lineNumber, Address baseAddr, long length) throws LockException, AddressOverflowException Description copied from interface:SourceFileManager
Creates aSourceMapEntry
withSourceFile
sourceFile
, line numberlineNumber
, and non-negative lengthlength
and adds it to the program database.Entries with non-zero lengths must either cover the same address range or be disjoint.
- Specified by:
addSourceMapEntry
in interfaceSourceFileManager
- Parameters:
sourceFile
- source filelineNumber
- line numberbaseAddr
- minimum address of rangelength
- number of addresses in range- Returns:
- created SourceMapEntry
- Throws:
LockException
- if invoked without exclusive accessAddressOverflowException
- if baseAddr + length-1 overflows
-
intersectsSourceMapEntry
Description copied from interface:SourceFileManager
- Specified by:
intersectsSourceMapEntry
in interfaceSourceFileManager
- Parameters:
addrs
- addresses to check- Returns:
- true when at least one address has source map info
-
dbError
Description copied from interface:ErrorHandler
Notification that an IO exception occurred.- Specified by:
dbError
in interfaceErrorHandler
- Parameters:
e
-IOException
which was cause of error- Throws:
RuntimeException
- optional exception which may be thrown when responding to error condition.
-
getMappedSourceFiles
Description copied from interface:SourceFileManager
Returns aList
containingSourceFile
s which are mapped to at least one address in the program- Specified by:
getMappedSourceFiles
in interfaceSourceFileManager
- Returns:
- mapped source file list
-
getAllSourceFiles
Description copied from interface:SourceFileManager
Returns aList
containing allSourceFile
s of the program.- Specified by:
getAllSourceFiles
in interfaceSourceFileManager
- Returns:
- source file list
-
transferSourceMapEntries
Description copied from interface:SourceFileManager
Changes the source map so that anySourceMapEntry
associated withsource
is associated withtarget
instead. Any entries associated withtarget
before invocation will still be associated withtarget
after invocation.source
will not be associated with any entries after invocation (unlesssource
andtarget
are the same). Line number information is not changed.- Specified by:
transferSourceMapEntries
in interfaceSourceFileManager
- Parameters:
source
- source file to get info fromtarget
- source file to move info to- Throws:
LockException
- if invoked without exclusive access
-
getSourceMapEntryIterator
Description copied from interface:SourceFileManager
Returns aSourceMapEntryIterator
starting ataddress
.- Specified by:
getSourceMapEntryIterator
in interfaceSourceFileManager
- Parameters:
address
- starting addressforward
- direction of iterator (true = forward)- Returns:
- iterator
-
containsSourceFile
Description copied from interface:SourceFileManager
Returns true precisely when this manager containssourceFile
.- Specified by:
containsSourceFile
in interfaceSourceFileManager
- Parameters:
sourceFile
- source file- Returns:
- true if source file already added
-
getSourceMapEntries
Description copied from interface:SourceFileManager
Returns the sorted list ofSourceMapEntry
s forsourceFile
with line number betweenminLine
andmaxLine
, inclusive.- Specified by:
getSourceMapEntries
in interfaceSourceFileManager
- Parameters:
sourceFile
- source fileminLine
- minimum line numbermaxLine
- maximum line number- Returns:
- source map entries
-
removeSourceMapEntry
Description copied from interface:SourceFileManager
Removes aSourceMapEntry
from this manager.- Specified by:
removeSourceMapEntry
in interfaceSourceFileManager
- Parameters:
entry
- entry to remove- Returns:
- true if entry was in the manager
- Throws:
LockException
- if invoked without exclusive access
-