private Function findFunction(TaskMonitor monitor) {
		if (program == null || location == null) {
			return null;
		}
		Address address = location.getAddress();
		if (address == null) {
			return null;
		}

		if (monitor.isCancelled()) {
			return null;
		}

		Function function = program.getFunctionManager().getFunctionContaining(address);
		if (function != null) {
			return function;
		}

		// couldn't find the function, make an undefined one
		function = UndefinedFunction.findFunction(program, address, monitor);
		if (function != null) {
			// Make sure there isn't a real function at the location found
			// function may not contain currentAddress in its body.
			// This will cause provider to re-decompile when
			// clicking around the currentAddress :(
			Function realFunction =
				program.getFunctionManager().getFunctionAt(function.getEntryPoint());
			if (realFunction != null) {
				return realFunction;
			}
		}

		return function;
	}
locates the function to be decompiled based on the location given at construction time.
Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompileRunnable.java