private AddressSet selectSubroutines(TaskMonitor monitor, Program program,
			AddressSet startAddresses) throws CancelledException {
		// Create a new address set to hold the entire selection.
		AddressSet newAddressSet = new AddressSet();

		// If we don't have any addresses simply return.
		if ((startAddresses == null) || (startAddresses.getNumAddresses() <= 0)) {
			return newAddressSet;
		}

		monitor.initialize(startAddresses.getNumAddresses());

		CodeBlockModel cbm = blockModelService.getActiveSubroutineModel();
		CodeBlockIterator iter = cbm.getCodeBlocksContaining(startAddresses, monitor);
		while (iter.hasNext()) {
			if (monitor.isCancelled()) {
				return newAddressSet;
			}

			CodeBlock block = iter.next();
			newAddressSet.add(block);
			monitor.incrementProgress(block.getNumAddresses());
		}

		return newAddressSet;
	}
selectSubroutines selects all the subroutines that contain code units from
the initial address set passed in as a parameter.
@param monitor a cancellable task monitor
@param startAddresses the initial addresses that should be used to select
subroutines.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/select/flow/SelectByFlowPlugin.java