Package ghidra.program.database.module

# Class TreeManager

java.lang.Object
ghidra.program.database.module.TreeManager

All Implemented Interfaces:
  `ManagerDB`

public class TreeManager extends Object implements ManagerDB
Manage the set of trees in the program.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `DEFAULT_TREE_NAME`
  The name of the default tree that is created when a program is created.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TreeManager(DBHandle handle, ErrorHandler errHandler, AddressMap addrMap, int openMode, Lock lock, TaskMonitor monitor)`
  Construct a new TreeManager.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addMemoryBlock(String name, AddressRange range)`
  Add a memory block with the given range.
  `ProgramModule`
  `createRootModule(String treeName)`
  Create a new tree with given name.
  `void`
  `deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)`
  Delete all objects which have been applied to the address range startAddr to endAddr and update the database accordingly.
  `ProgramModule`
  `getDefaultRootModule()`
  Returns the root module for the default program tree.
  `ProgramFragment`
  `getFragment(String treeName, Address addr)`
  Get the fragment that contains the given address within the tree identified by the treeName.
  `ProgramFragment`
  `getFragment(String treeName, String name)`
  Get the fragment with the given name that is in the tree identified by the treeName.
  `ProgramModule`
  `getModule(String treeName, String name)`
  Get the module with the given name that is in the tree identified by the treeName.
  `ProgramModule`
  `getRootModule(long treeID)`
  Get the root module for the tree that has the given ID.
  `ProgramModule`
  `getRootModule(String treeName)`
  Get the root module of the tree with the given name.
  `String[]`
  `getTreeNames()`
  Get the names of all the trees in the program.
  `void`
  `imageBaseChanged(boolean commit)`
  `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(int openMode1, int currentRevision, TaskMonitor monitor)`
  Callback from program made to each manager after the program has completed initialization.
  `boolean`
  `removeTree(String treeName)`
  Remove the tree with the given name.
  `void`
  `renameTree(String oldName, String newName)`
  Rename the tree to the new name.
  `void`
  `setProgram(ProgramDB program)`
  Callback from program used to indicate all manager have been created.
  `void`
  `setProgramName(String oldName, String newName)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface ghidra.program.database.ManagerDB

  `dispose`

- ## Field Details

  - ### DEFAULT_TREE_NAME

    public static final String DEFAULT_TREE_NAME
    The name of the default tree that is created when a program is created.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### TreeManager

    public TreeManager(DBHandle handle, ErrorHandler errHandler, AddressMap addrMap, int openMode, Lock lock, TaskMonitor monitor) throws IOException, VersionException, CancelledException
    Construct a new TreeManager.
    Parameters:
      `handle` - database handle
      `errHandler` - error handler
      `addrMap` - map to convert addresses to longs and longs to addresses
      `openMode` - the open mode for the program.
      `lock` - the program synchronization lock
      `monitor` - Task monitor for upgrading
    Throws:
      `IOException` - if a database io error occurs.
      `VersionException` - if the database version is different from the expected version
      `CancelledException` - if instantiation has been cancelled

- ## Method Details

  - ### setProgram

    public void setProgram(ProgramDB program)
    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 interface `ManagerDB`
    Parameters:
      `program` - the program is set when all the initializations have been completed.

  - ### programReady

    public void programReady(int openMode1, 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 interface `ManagerDB`
    Parameters:
      `openMode1` - 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.

  - ### imageBaseChanged

    public void imageBaseChanged(boolean commit)

  - ### createRootModule

    public ProgramModule createRootModule(String treeName) throws DuplicateNameException
    Create a new tree with given name.
    Parameters:
      `treeName` - name of the tree (not the root module)
    Returns:
      root module for the new tree
    Throws:
      `DuplicateNameException` - if there is already tree named treeName

  - ### getRootModule

    public ProgramModule getRootModule(String treeName)
    Get the root module of the tree with the given name.
    Parameters:
      `treeName` - tree name
    Returns:
      root module, or null if there is no tree with the given name

  - ### getDefaultRootModule

    public ProgramModule getDefaultRootModule()
    Returns the root module for the default program tree. The default tree is the oldest tree.
    Returns:
      the root module for the default program tree. The default tree is the oldest tree.

  - ### getTreeNames

    public String[] getTreeNames()
    Get the names of all the trees in the program.
    Returns:
      sorted array of tree names

  - ### renameTree

    public void renameTree(String oldName, String newName) throws DuplicateNameException
    Rename the tree to the new name. This method has no effect on the name of the root module.
    Parameters:
      `oldName` - old name of root module
      `newName` - new name for root module
    Throws:
      `DuplicateNameException` - if newName exists as the name for another root

  - ### removeTree

    public boolean removeTree(String treeName)
    Remove the tree with the given name.
    Parameters:
      `treeName` - tree name
    Returns:
      true if the tree was removed

  - ### getModule

    public ProgramModule getModule(String treeName, String name)
    Get the module with the given name that is in the tree identified by the treeName.
    Parameters:
      `treeName` - name of the tree
      `name` - module name to look for
    Returns:
      null if there is no module with the given name in the tree

  - ### getFragment

    public ProgramFragment getFragment(String treeName, String name)
    Get the fragment with the given name that is in the tree identified by the treeName.
    Parameters:
      `treeName` - name of the tree
      `name` - name of fragment to look for
    Returns:
      null if there is no fragment with the given name in the tree

  - ### getFragment

    public ProgramFragment getFragment(String treeName, Address addr)
    Get the fragment that contains the given address within the tree identified by the treeName.
    Parameters:
      `treeName` - name of the tree
      `addr` - address contained within some fragment
    Returns:
      fragment containing addr, or null if addr does not exist in memory

  - ### addMemoryBlock

    public void addMemoryBlock(String name, AddressRange range)
    Add a memory block with the given range.
    Parameters:
      `name` - memory block name (name of new fragment)
      `range` - memory block address range

  - ### deleteAddressRange

    public void deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor) throws CancelledException
    Description copied from interface: `ManagerDB`
    Delete all objects which have been applied to the address range startAddr to endAddr and update the database accordingly.
    Specified by:
      `deleteAddressRange` in interface `ManagerDB`
    Parameters:
      `startAddr` - the first address in the range.
      `endAddr` - the last address in the range.
      `monitor` - the task monitor to use in any upgrade operations.
    Throws:
      `CancelledException` - if the user cancelled the operation via the task monitor.

  - ### moveAddressRange

    public void moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor) throws AddressOverflowException, CancelledException
    Description copied from interface: `ManagerDB`
    Move all objects within an address range to a new location.
    Specified by:
      `moveAddressRange` in interface `ManagerDB`
    Parameters:
      `fromAddr` - the first address of the range to be moved.
      `toAddr` - the address where to the range is to be moved.
      `length` - the number of addresses to move.
      `monitor` - the task monitor to use in any upgrade operations.
    Throws:
      `AddressOverflowException` - if the length is such that a address wrap occurs
      `CancelledException` - if the user cancelled the operation via the task monitor.

  - ### invalidateCache

    public void invalidateCache(boolean all) throws IOException
    Description copied from interface: `ManagerDB`
    Clears all data caches.
    Specified by:
      `invalidateCache` in interface `ManagerDB`
    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.

  - ### setProgramName

    public void setProgramName(String oldName, String newName)

  - ### getRootModule

    public ProgramModule getRootModule(long treeID)
    Get the root module for the tree that has the given ID.
    Parameters:
      `treeID` - ID of the tree
    Returns:
      root module