Package ghidra.program.model.data
Class StandAloneDataTypeManager
java.lang.Object
ghidra.program.database.data.DataTypeManagerDB
ghidra.program.model.data.StandAloneDataTypeManager
- All Implemented Interfaces:
DataTypeManager
,Closeable
,AutoCloseable
- Direct Known Subclasses:
BuiltInDataTypeManager
,FileDataTypeManager
,ProjectDataTypeManager
Basic implementation of the DataTypeManger interface
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
static enum
-
Field Summary
Fields inherited from class ghidra.program.database.data.DataTypeManagerDB
addrMap, dbHandle, DEFAULT_CALLING_CONVENTION_ID, defaultListener, errHandler, lock, readOnlyMode, sourceArchiveAdapter, tablePrefix, universalID, UNKNOWN_CALLING_CONVENTION_ID
Fields inherited from interface ghidra.program.model.data.DataTypeManager
BAD_DATATYPE_ID, BUILT_IN_ARCHIVE_KEY, BUILT_IN_ARCHIVE_UNIVERSAL_ID, BUILT_IN_DATA_TYPES_NAME, DEFAULT_DATATYPE_ID, LOCAL_ARCHIVE_KEY, LOCAL_ARCHIVE_UNIVERSAL_ID, NULL_DATATYPE_ID
-
Constructor Summary
ModifierConstructorDescriptionprotected
StandAloneDataTypeManager
(DBHandle handle, OpenMode openMode, ErrorHandler errHandler, Lock lock, TaskMonitor monitor) Constructor for a data-type manager using a specified DBHandle.protected
StandAloneDataTypeManager
(ResourceFile packedDbfile, OpenMode openMode, TaskMonitor monitor) Constructor for a data-type manager backed by a packed database file.StandAloneDataTypeManager
(String rootName) Constructor for new temporary data-type manager using the default DataOrganization.StandAloneDataTypeManager
(String rootName, DataOrganization dataOrganzation) Constructor for new temporary data-type manager using a specified DataOrganization. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canRedo()
boolean
canUndo()
Determine if there is a previous transaction that can be reverted/undone (seeundo()
).void
clearProgramArchitecture
(TaskMonitor monitor) Clear the program architecture setting and all architecture-specific data from this archive.protected void
Clear undo/redo stack.void
close()
Closes this dataType managerprotected void
deleteDataTypesUsed
(Set<Long> deletedIds) Allow extensions to perform any neccessary fixups for all datatype removals listed.void
endTransaction
(int transactionID, boolean commit) Ends the current transactionvoid
finalize()
void
Force all pending notification events to be flushedGet all transaction names that are available within theredo()
stack.Get all transaction names that are available within theundo()
stack.protected String
getName()
Returns this data type manager's namegetPath()
Get the path name associated with the storage of this stand alone datatype manager.Get the program architecture information which has been associated with this datatype manager.protected int
Get the number of active transactionsgetType()
Returns this manager's archive typeGet theStandAloneDataTypeManager.ArchiveWarning
which may have occured immediately following instatiation of thisStandAloneDataTypeManager
.Get the detail exception associated withStandAloneDataTypeManager.ArchiveWarning.LANGUAGE_NOT_FOUND
orStandAloneDataTypeManager.ArchiveWarning.COMPILER_SPEC_NOT_FOUND
warning (seegetWarning()
) immediately following instatiation of thisStandAloneDataTypeManager
.getWarningMessage
(boolean includeDetails) Get a suitable warning message.protected void
handleDataOrganizationChange
(OpenMode openMode, TaskMonitor monitor) protected void
initializeOtherAdapters
(OpenMode openMode, TaskMonitor monitor) Initialize other DB adapters after base implementation adapters has been initialized.protected void
protected boolean
Determine if a program architecture change is permittedboolean
Indicates that a failure occured establishing the program architecture for the associated archive.boolean
Indicates that an program architecture upgrade is required in order to constitute associated data.protected void
openTransaction
(String description) Open new transaction.void
redo()
protected void
replaceDataTypesUsed
(Map<Long, Long> dataTypeReplacementMap) Allow extensions to perform any neccessary fixups to address all datatype replacements.protected void
Set instance as immutable by disabling use of transactions.void
Sets this data type manager's namevoid
setProgramArchitecture
(Language language, CompilerSpecID compilerSpecId, StandAloneDataTypeManager.LanguageUpdateOption updateOption, TaskMonitor monitor) Establish the program architecture for this datatype manager.protected void
setProgramArchitecture
(ProgramArchitecture programArchitecture, VariableStorageManager variableStorageMgr, boolean store, TaskMonitor monitor) Set the architecture-specific details associated with a new datatype manager.int
startTransaction
(String description) Starts a transaction for making changes in this data type manager.void
undo()
Methods inherited from class ghidra.program.database.data.DataTypeManagerDB
addDataType, addDataTypeManagerListener, addDataTypes, addDataTypeToDelete, addDataTypeToReplace, addInvalidatedListener, allowsDefaultBuiltInSettings, allowsDefaultComponentSettings, associateDataTypeWithArchive, categoryCreated, categoryMoved, categoryRemoved, categoryRenamed, compilerSpecChanged, contains, containsCategory, createCategory, dataTypeAdded, dataTypeChanged, dataTypeDeleted, dataTypeMoved, dataTypeNameChanged, dataTypeReplaced, dataTypeSettingsChanged, dbError, dedupeAllConflicts, dedupeConflicts, disassociate, dispose, doSourceArchiveUpdates, favoritesChanged, findDataType, findDataTypeForID, findDataTypes, findDataTypes, findEnumValueNames, fixupComposites, getAddressMap, getAllComposites, getAllDataTypes, getAllDataTypes, getAllFunctionDefinitions, getAllStructures, getCallingConvention, getCallingConventionID, getCallingConventionName, getCategory, getCategory, getCategoryCount, getChildIds, getDataMap, getDataOrganization, getDataType, getDataType, getDataType, getDataType, getDataType, getDataTypeCount, getDataTypes, getDataTypes, getDataTypesContaining, getDefaultCallingConvention, getDefinedCallingConventionNames, getFavorites, getID, getKnownCallingConventionNames, getLastChangeTimeForMyManager, getLocalSourceArchive, getPointer, getPointer, getProgramArchitecture, getProgramArchitectureSummary, getResolvedID, getRootCategory, getSourceArchive, getSourceArchive, getSourceArchives, getUniqueName, getUniversalID, getUnusedConflictName, getUnusedConflictName, getVariableStorageManager, hasDataOrganizationChange, hasParent, invalidateCache, isChanged, isCreatingDataType, isFavorite, isTransactionActive, isUpdatable, migrateOldFlexArrayComponentsIfRequired, notifyRestored, readDataOrganization, remove, removeDataTypeManagerListener, removeInvalidatedListener, removeParentChildRecord, removeSourceArchive, replaceDataType, replaceSourceArchive, resolve, resolveSourceArchive, saveDataOrganization, setFavorite, sourceArchiveAdded, sourceArchiveChanged, updateID, updateLastChangeTime, updateSourceArchiveName, updateSourceArchiveName
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ghidra.program.model.data.DataTypeManager
withTransaction, withTransaction
-
Field Details
-
name
-
-
Constructor Details
-
StandAloneDataTypeManager
Constructor for new temporary data-type manager using the default DataOrganization. Note that this manager does not support the save or saveAs operation.- Parameters:
rootName
- Name of the root category.- Throws:
RuntimeIOException
- if database error occurs during creation
-
StandAloneDataTypeManager
public StandAloneDataTypeManager(String rootName, DataOrganization dataOrganzation) throws RuntimeIOException Constructor for new temporary data-type manager using a specified DataOrganization. Note that this manager does not support the save or saveAs operation.- Parameters:
rootName
- Name of the root category.dataOrganzation
- applicable data organization- Throws:
RuntimeIOException
- if database error occurs during creation
-
StandAloneDataTypeManager
protected StandAloneDataTypeManager(ResourceFile packedDbfile, OpenMode openMode, TaskMonitor monitor) throws IOException, CancelledException Constructor for a data-type manager backed by a packed database file. When opening for UPDATE an automatic upgrade will be performed if required.NOTE:
logWarning()
should be invoked immediately after instantiating aStandAloneDataTypeManager
for an existing database aftergetName()
andgetPath()
can be invoked safely. In addition, it may be appropriate to usecheck for warnings
prior to use.- Parameters:
packedDbfile
- packed datatype archive file (i.e., *.gdt resource).openMode
- open mode CREATE, READ_ONLY or UPDATEmonitor
- the progress monitor- Throws:
IOException
- a low-level IO error. This exception may also be thrown when a version error occurs (cause is VersionException).CancelledException
- if task cancelled
-
StandAloneDataTypeManager
protected StandAloneDataTypeManager(DBHandle handle, OpenMode openMode, ErrorHandler errHandler, Lock lock, TaskMonitor monitor) throws CancelledException, VersionException, IOException Constructor for a data-type manager using a specified DBHandle.
NOTE:logWarning()
should be invoked immediately after instantiating aStandAloneDataTypeManager
for an existing database aftergetName()
andgetPath()
can be invoked safely. In addition, it may be appropriate to usecheck for warnings
prior to use.- Parameters:
handle
- open database handleopenMode
- open mode CREATE, READ_ONLY or UPDATEerrHandler
- the database I/O error handlerlock
- the program synchronization lockmonitor
- the progress monitor- Throws:
CancelledException
- if task cancelledVersionException
- if the database does not match the expected version.IOException
- if a database I/O error occurs.
-
-
Method Details
-
setImmutable
protected void setImmutable()Set instance as immutable by disabling use of transactions. Attempts to start a transaction will result in aTerminatedTransactionException
. -
getWarning
Get theStandAloneDataTypeManager.ArchiveWarning
which may have occured immediately following instatiation of thisStandAloneDataTypeManager
.StandAloneDataTypeManager.ArchiveWarning.NONE
will be returned if not warning condition.- Returns:
- warning type.
-
getWarningDetail
Get the detail exception associated withStandAloneDataTypeManager.ArchiveWarning.LANGUAGE_NOT_FOUND
orStandAloneDataTypeManager.ArchiveWarning.COMPILER_SPEC_NOT_FOUND
warning (seegetWarning()
) immediately following instatiation of thisStandAloneDataTypeManager
.- Returns:
- warning detail exception or null
-
getWarningMessage
Get a suitable warning message. SeegetWarning()
for type and its severity levelStandAloneDataTypeManager.ArchiveWarning.level()
.- Parameters:
includeDetails
- if false simple message returned, otherwise more details are included.- Returns:
- warning message or null if
getWarning()
isStandAloneDataTypeManager.ArchiveWarning.NONE
.
-
logWarning
protected void logWarning() -
initializeOtherAdapters
protected void initializeOtherAdapters(OpenMode openMode, TaskMonitor monitor) throws CancelledException, IOException, VersionException Description copied from class:DataTypeManagerDB
Initialize other DB adapters after base implementation adapters has been initialized.- Overrides:
initializeOtherAdapters
in classDataTypeManagerDB
- Parameters:
openMode
- the DB open modemonitor
- the progress monitor- Throws:
CancelledException
- if the user cancels an upgradeIOException
- if a database IO error occurs.VersionException
- if the database does not match the expected version.
-
handleDataOrganizationChange
protected void handleDataOrganizationChange(OpenMode openMode, TaskMonitor monitor) throws LanguageVersionException, CancelledException, IOException - Overrides:
handleDataOrganizationChange
in classDataTypeManagerDB
- Throws:
LanguageVersionException
CancelledException
IOException
-
getProgramArchitectureSummary
Get the program architecture information which has been associated with this datatype manager. IfDataTypeManagerDB.getProgramArchitecture()
returns null this method may still return information if the program architecture was set on an archive and eitherisProgramArchitectureMissing()
orisProgramArchitectureUpgradeRequired()
returns true.- Specified by:
getProgramArchitectureSummary
in interfaceDataTypeManager
- Overrides:
getProgramArchitectureSummary
in classDataTypeManagerDB
- Returns:
- program architecture summary if it has been set
-
isProgramArchitectureUpgradeRequired
public boolean isProgramArchitectureUpgradeRequired()Indicates that an program architecture upgrade is required in order to constitute associated data. If true, the associated archive must be open for update to allow the upgrade to complete, or a new program architecture may be set/cleared if such an operation is supported.- Returns:
- true if a program architecture upgrade is required, else false
-
isProgramArchitectureMissing
public boolean isProgramArchitectureMissing()Indicates that a failure occured establishing the program architecture for the associated archive.- Returns:
- true if a failure occured establishing the program architecture
-
clearProgramArchitecture
public void clearProgramArchitecture(TaskMonitor monitor) throws CancelledException, IOException, LockException Clear the program architecture setting and all architecture-specific data from this archive. Archive will revert to using the defaultDataOrganization
. Archive must be open for update for this method to be used.- Parameters:
monitor
- task monitor- Throws:
CancelledException
- if task cancelled. If thrown, this data type manager is no longer stable and should be closed without saving.IOException
- if IO error occursLockException
- failure if exclusive access is requiredjavax.help.UnsupportedOperationException
- if architecture change is not permitted by implementation (e.g.,BuiltInDataTypeManager
).
-
setProgramArchitecture
public void setProgramArchitecture(Language language, CompilerSpecID compilerSpecId, StandAloneDataTypeManager.LanguageUpdateOption updateOption, TaskMonitor monitor) throws CompilerSpecNotFoundException, LanguageNotFoundException, IOException, CancelledException, LockException, javax.help.UnsupportedOperationException, IncompatibleLanguageException Establish the program architecture for this datatype manager. The current setting can be determined fromDataTypeManagerDB.getProgramArchitecture()
. Archive must be open for update for this method to be used.- Parameters:
language
- languagecompilerSpecId
- compiler specification ID defined by the language.updateOption
- indicates how variable storage data should be transitioned. IfisProgramArchitectureMissing()
is true andStandAloneDataTypeManager.LanguageUpdateOption.TRANSLATE
specified, the translator will be based on whatever language version can be found. In this situation it may be best to force aStandAloneDataTypeManager.LanguageUpdateOption.CLEAR
.monitor
- task monitor (cancel not permitted to avoid corrupt state)- Throws:
CompilerSpecNotFoundException
- if invalid compilerSpecId specified for languageLanguageNotFoundException
- if current language is not found (if required for data transition)IOException
- if IO error occursCancelledException
- if task cancelled. If thrown, this data type manager is no longer stable and should be closed without saving.LockException
- failure if exclusive access is requiredjavax.help.UnsupportedOperationException
- if architecture change is not permittedIncompatibleLanguageException
- if translation requested but not possible due to incompatible language architectures
-
setProgramArchitecture
protected void setProgramArchitecture(ProgramArchitecture programArchitecture, VariableStorageManager variableStorageMgr, boolean store, TaskMonitor monitor) throws IOException, CancelledException Set the architecture-specific details associated with a new datatype manager. This method is intended to be used during instantiation of derived implementations.- Overrides:
setProgramArchitecture
in classDataTypeManagerDB
- Parameters:
programArchitecture
- program architecture details (required)variableStorageMgr
- variable storage manager. Must be null.store
- if true database update will occur and datatypes will be updated if any change to the data organization is detected (a stored copy may be used to detect this condition). This should never be passed as true if opened read-only. If true and no variable storage is specified it will be created.monitor
- task monitor- Throws:
IOException
- if IO error occursCancelledException
- if task cancelledjavax.help.UnsupportedOperationException
- if language was previously set
-
isArchitectureChangeAllowed
protected boolean isArchitectureChangeAllowed()Determine if a program architecture change is permitted- Returns:
- true if change allowed else false if disallowed
-
getName
Description copied from interface:DataTypeManager
Returns this data type manager's name- Specified by:
getName
in interfaceDataTypeManager
- Returns:
- the name
-
setName
Description copied from interface:DataTypeManager
Sets this data type manager's name- Specified by:
setName
in interfaceDataTypeManager
- Parameters:
name
- the new name- Throws:
InvalidNameException
- if the given name is invalid (such as when null or empty)
-
initTransactionState
protected void initTransactionState() -
openTransaction
Description copied from interface:DataTypeManager
Open new transaction. This should generally be done with a try-with-resources block:try (Transaction tx = dtm.openTransaction(description)) { // ... Do something }
- Specified by:
openTransaction
in interfaceDataTypeManager
- Parameters:
description
- a short description of the changes to be made.- Returns:
- transaction object
- Throws:
IllegalStateException
- if thisDataTypeManager
has already been closed.
-
startTransaction
Description copied from interface:DataTypeManager
Starts a transaction for making changes in this data type manager.- Specified by:
startTransaction
in interfaceDataTypeManager
- Parameters:
description
- a short description of the changes to be made.- Returns:
- the transaction ID
-
getTransactionCount
protected int getTransactionCount()Get the number of active transactions- Returns:
- number of active transactions
-
endTransaction
public void endTransaction(int transactionID, boolean commit) Description copied from interface:DataTypeManager
Ends the current transaction- Specified by:
endTransaction
in interfaceDataTypeManager
- Parameters:
transactionID
- id of the transaction to endcommit
- true if changes are committed, false if changes in transaction are revoked
-
undo
public void undo() -
redo
public void redo() -
clearUndo
protected void clearUndo()Clear undo/redo stack.
NOTE: It is important that this always be invoked following any save operation that compacts the checkpoints within the databaseBufferMgr
. -
canRedo
public boolean canRedo()- Returns:
- true if there is a transaction previously undone that can be redone, else false
-
canUndo
public boolean canUndo()Determine if there is a previous transaction that can be reverted/undone (seeundo()
).- Returns:
- true if there is a previous transaction that can be reverted/undone, else false.
-
getRedoName
- Returns:
- transaction name that is available for
redo()
or empty String.
-
getUndoName
- Returns:
- transaction name that is available for
undo()
or empty String.
-
getAllUndoNames
Get all transaction names that are available within theundo()
stack.- Returns:
- all transaction names that are available within the
undo()
stack.
-
getAllRedoNames
Get all transaction names that are available within theredo()
stack.- Returns:
- all transaction names that are available within the
redo()
stack.
-
flushEvents
public void flushEvents()Description copied from interface:DataTypeManager
Force all pending notification events to be flushed- Specified by:
flushEvents
in interfaceDataTypeManager
-
replaceDataTypesUsed
Description copied from class:DataTypeManagerDB
Allow extensions to perform any neccessary fixups to address all datatype replacements.- Specified by:
replaceDataTypesUsed
in classDataTypeManagerDB
- Parameters:
dataTypeReplacementMap
- map of datatype replacements (oldID maps to replacementID).
-
deleteDataTypesUsed
Description copied from class:DataTypeManagerDB
Allow extensions to perform any neccessary fixups for all datatype removals listed.- Specified by:
deleteDataTypesUsed
in classDataTypeManagerDB
- Parameters:
deletedIds
- list of IDs for all datatypes which are getting removed.
-
close
public void close()Description copied from interface:DataTypeManager
Closes this dataType manager- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceDataTypeManager
- Overrides:
close
in classDataTypeManagerDB
-
finalize
public void finalize() -
getDomainFileID
- Specified by:
getDomainFileID
in classDataTypeManagerDB
-
getPath
Get the path name associated with the storage of this stand alone datatype manager.- Specified by:
getPath
in classDataTypeManagerDB
- Returns:
- path name or null if not applicable
-
getType
Description copied from interface:DataTypeManager
Returns this manager's archive type- Specified by:
getType
in interfaceDataTypeManager
- Returns:
- the type
-