Package ghidra.program.model.block

# Class PartitionCodeSubModel

java.lang.Object
ghidra.program.model.block.PartitionCodeSubModel

All Implemented Interfaces:
  `CodeBlockModel`, `SubroutineBlockModel`

public class PartitionCodeSubModel extends Object implements SubroutineBlockModel
`PartitionCodeSubModel` (Model-P) defines subroutines which do not share code with other subroutines and may have one or more entry points. Entry points represent anyone of a variety of flow entries, including a source, called, jump or fall-through entry point.

MODEL-P is the answer to those who always want to be able to know what subroutine a given instruction is in, but also do not want the subroutine to have multiple entry points. When a model-M subroutine has multiple entry points, that set of code will necessarily consist of several model-P subroutines. When a model-M subroutine has a single entry point, it will consist of a single model-P subroutine which has the same address set and entry point.

See Also:
  - `Created February 7, 2002.`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `NAME`

  ### Fields inherited from interface ghidra.program.model.block.CodeBlockModel

  `emptyBlockArray`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PartitionCodeSubModel(Program program)`
  Construct a Model-P subroutine on a program.
  `PartitionCodeSubModel(Program program, boolean includeExternals)`
  Construct a Model-P subroutine on a program.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `allowsBlockOverlap()`
  Return true if this model allows overlapping of address sets for the blocks it returns.
  `boolean`
  `externalsIncluded()`
  Returns true if externals are handled by the model, false if externals are ignored.
  `SubroutineBlockModel`
  `getBaseSubroutineModel()`
  Get the underlying base subroutine model.
  `CodeBlockModel`
  `getBasicBlockModel()`
  Get the basic block model used by this model.
  `CodeBlock`
  `getCodeBlockAt(Address addr, TaskMonitor monitor)`
  Get the code block with a starting address (i.e., entry-point) of addr.
  `CodeBlockIterator`
  `getCodeBlocks(TaskMonitor monitor)`
  Get an iterator over the code blocks in the entire program.
  `CodeBlock[]`
  `getCodeBlocksContaining(Address addr, TaskMonitor monitor)`
  Get all the Code Blocks containing the address.
  `CodeBlockIterator`
  `getCodeBlocksContaining(AddressSetView addrSet, TaskMonitor monitor)`
  Get an iterator over CodeBlocks which overlap the specified address set.
  `CodeBlockReferenceIterator`
  `getDestinations(CodeBlock block, TaskMonitor monitor)`
  Get an iterator over destination blocks flowing from this block.
  `CodeBlock`
  `getFirstCodeBlockContaining(Address addr, TaskMonitor monitor)`
  Get the (first) Model-P subroutine that contains the address.
  `FlowType`
  `getFlowType(CodeBlock block)`
  Return in general how things flow out of this node.
  `Listing`
  `getListing()`
  Returns the listing associated with this block model.
  `String`
  `getName()`
  Returns the model name.
  `String`
  `getName(CodeBlock block)`
  Get a name for this block.
  `int`
  `getNumDestinations(CodeBlock block, TaskMonitor monitor)`
  Get number of destination references flowing out of this subroutine (block).
  `int`
  `getNumSources(CodeBlock block, TaskMonitor monitor)`
  Get number of block source references flowing into this block.
  `Program`
  `getProgram()`
  Returns the program object associated with this CodeBlockModel instance.
  `CodeBlockReferenceIterator`
  `getSources(CodeBlock block, TaskMonitor monitor)`
  Get an iterator over source blocks flowing into this block.

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

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

- ## Field Details

  - ### NAME

    public static final String NAME
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### PartitionCodeSubModel

    public PartitionCodeSubModel(Program program)
    Construct a Model-P subroutine on a program.
    Parameters:
      `program` - program to create blocks from.

  - ### PartitionCodeSubModel

    public PartitionCodeSubModel(Program program, boolean includeExternals)
    Construct a Model-P subroutine on a program.
    Parameters:
      `program` - program to create blocks from.
      `includeExternals` - externals included if true

- ## Method Details

  - ### getCodeBlockAt

    public CodeBlock getCodeBlockAt(Address addr, TaskMonitor monitor) throws CancelledException
    Description copied from interface: `CodeBlockModel`
    Get the code block with a starting address (i.e., entry-point) of addr.
    Specified by:
      `getCodeBlockAt` in interface `CodeBlockModel`
    Parameters:
      `addr` - starting address of a codeblock.
      `monitor` - task monitor which allows user to cancel operation.
    Returns:
      null if there is no codeblock starting at the address.
    Throws:
      `CancelledException` - if the monitor cancels the operation.
    See Also:
      - `CodeBlockModel.getCodeBlockAt(ghidra.program.model.address.Address, ghidra.util.task.TaskMonitor)`

  - ### getCodeBlocksContaining

    public CodeBlock[] getCodeBlocksContaining(Address addr, TaskMonitor monitor) throws CancelledException
    Get all the Code Blocks containing the address. For model-P, there is only one.
    Specified by:
      `getCodeBlocksContaining` in interface `CodeBlockModel`
    Parameters:
      `addr` - Address to find a containing block.
      `monitor` - task monitor which allows user to cancel operation.
    Returns:
      A CodeBlock array with one entry containing the subroutine that contains the address null otherwise.
    Throws:
      `CancelledException` - if the monitor cancels the operation.

  - ### getFirstCodeBlockContaining

    public CodeBlock getFirstCodeBlockContaining(Address addr, TaskMonitor monitor) throws CancelledException
    Get the (first) Model-P subroutine that contains the address. This is equivalent to getCodeBlocksContaining(addr) except that it doesn't return an array since model-P subroutines don't share code.
    Specified by:
      `getFirstCodeBlockContaining` in interface `CodeBlockModel`
    Parameters:
      `addr` - Address to find a containing block.
      `monitor` - task monitor which allows user to cancel operation.
    Returns:
      A CodeBlock if any block contains the address. empty array otherwise.
    Throws:
      `CancelledException` - if the monitor cancels the operation.

  - ### getCodeBlocks

    public CodeBlockIterator getCodeBlocks(TaskMonitor monitor)
    Description copied from interface: `CodeBlockModel`
    Get an iterator over the code blocks in the entire program.
    Specified by:
      `getCodeBlocks` in interface `CodeBlockModel`
    Parameters:
      `monitor` - task monitor which allows user to cancel operation.
    See Also:
      - `CodeBlockModel.getCodeBlocks(ghidra.util.task.TaskMonitor)`

  - ### getCodeBlocksContaining

    public CodeBlockIterator getCodeBlocksContaining(AddressSetView addrSet, TaskMonitor monitor)
    Get an iterator over CodeBlocks which overlap the specified address set.
    Specified by:
      `getCodeBlocksContaining` in interface `CodeBlockModel`
    Parameters:
      `addrSet` - an address set within program
      `monitor` - task monitor which allows user to cancel operation.

  - ### getProgram

    public Program getProgram()
    Description copied from interface: `CodeBlockModel`
    Returns the program object associated with this CodeBlockModel instance.
    Specified by:
      `getProgram` in interface `CodeBlockModel`
    Returns:
      program associated with this CodeBlockModel.
    See Also:
      - `CodeBlockModel.getProgram()`

  - ### getListing

    public Listing getListing()
    Returns the listing associated with this block model.
    Returns:
      the listing associated with this block model

  - ### getName

    public String getName(CodeBlock block)
    Description copied from interface: `CodeBlockModel`
    Get a name for this block.
    Specified by:
      `getName` in interface `CodeBlockModel`
    Returns:
      usually the label at the start address of the block however the model can choose any name it wants for its blocks.
    See Also:
      - `CodeBlockModel.getName(ghidra.program.model.block.CodeBlock)`

  - ### getFlowType

    public FlowType getFlowType(CodeBlock block)
    Return in general how things flow out of this node. This method exists for the SIMPLEBLOCK model.

    Since it doesn't make a great deal of sense to ask for this method in the case of subroutines, we return FlowType.UNKNOWN as long as the block exists.

    If this block has no valid instructions, it can't flow, so FlowType.INVALID is returned.

    Specified by:
      `getFlowType` in interface `CodeBlockModel`
    Returns:
      flow type of this node

  - ### getSources

    public CodeBlockReferenceIterator getSources(CodeBlock block, TaskMonitor monitor) throws CancelledException
    Get an iterator over source blocks flowing into this block.
    Specified by:
      `getSources` in interface `CodeBlockModel`
    Parameters:
      `block` - code block to get the source iterator for.
      `monitor` - task monitor which allows user to cancel operation.
    Throws:
      `CancelledException` - if the monitor cancels the operation.

  - ### getNumSources

    public int getNumSources(CodeBlock block, TaskMonitor monitor) throws CancelledException
    Get number of block source references flowing into this block.
    Specified by:
      `getNumSources` in interface `CodeBlockModel`
    Parameters:
      `block` - code block to get the source iterator for.
      `monitor` - task monitor which allows user to cancel operation.
    Throws:
      `CancelledException` - if the monitor cancels the operation.

  - ### getDestinations

    public CodeBlockReferenceIterator getDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException
    Get an iterator over destination blocks flowing from this block.
    Specified by:
      `getDestinations` in interface `CodeBlockModel`
    Parameters:
      `block` - code block to get the destination block iterator for.
      `monitor` - task monitor which allows user to cancel operation.
    Throws:
      `CancelledException` - if the monitor cancels the operation.

  - ### getNumDestinations

    public int getNumDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException
    Get number of destination references flowing out of this subroutine (block). All Calls from this block, and all external FlowType block references from this block are counted.
    Specified by:
      `getNumDestinations` in interface `CodeBlockModel`
    Parameters:
      `block` - code block to get the number of destination references from.
      `monitor` - task monitor which allows user to cancel operation.
    Throws:
      `CancelledException` - if the monitor cancels the operation.

  - ### getBasicBlockModel

    public CodeBlockModel getBasicBlockModel()
    Description copied from interface: `CodeBlockModel`
    Get the basic block model used by this model.
    Specified by:
      `getBasicBlockModel` in interface `CodeBlockModel`
    See Also:
      - `CodeBlockModel.getBasicBlockModel()`

  - ### getName

    public String getName()
    Description copied from interface: `CodeBlockModel`
    Returns the model name.
    Specified by:
      `getName` in interface `CodeBlockModel`
    Returns:
      the model name
    See Also:
      - `CodeBlockModel.getName()`

  - ### getBaseSubroutineModel

    public SubroutineBlockModel getBaseSubroutineModel()
    Description copied from interface: `SubroutineBlockModel`
    Get the underlying base subroutine model. This is generally the MultEntSubModel (M-Model).
    Specified by:
      `getBaseSubroutineModel` in interface `SubroutineBlockModel`
    Returns:
      base subroutine model. If there is no base model, this subroutine model is returned.
    See Also:
      - `SubroutineBlockModel.getBaseSubroutineModel()`

  - ### allowsBlockOverlap

    public boolean allowsBlockOverlap()
    Description copied from interface: `CodeBlockModel`
    Return true if this model allows overlapping of address sets for the blocks it returns.
    Specified by:
      `allowsBlockOverlap` in interface `CodeBlockModel`
    Returns:
      true if this model allows overlapping of address sets for the blocks it returns. This implies that getBlocksContaining() can return more than one block. false implies that getBlocksContaining() will return at most one block.
    See Also:
      - `CodeBlockModel.allowsBlockOverlap()`

  - ### externalsIncluded

    public boolean externalsIncluded()
    Description copied from interface: `CodeBlockModel`
    Returns true if externals are handled by the model, false if externals are ignored. When handled, externals are represented by an ExtCodeBlockImpl.
    Specified by:
      `externalsIncluded` in interface `CodeBlockModel`
    See Also:
      - `CodeBlockModel.externalsIncluded()`