NationalSecurityAgency/ghidra · error · UnwindException

No function contains {pc}

Error message

No function contains {pc}

What it means

Thrown by UnwindAnalysis.AnalysisForPC constructor when the program counter address does not fall within any function in the program's FunctionManager. The analysis requires a containing function to build the basic block graph and compute unwind information, so without one, it cannot proceed.

Source

Thrown at Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/UnwindAnalysis.java:163

		private final DijkstraShortestPathsAlgorithm<BlockVertex, BlockEdge> pathFinder;
		private final Set<StackUnwindWarning> warnings = new LinkedHashSet<>();

		/**
		 * Begin analysis for unwinding a frame, knowing only the program counter for that frame
		 * 
		 * <p>
		 * This will look up the function containing the program counter. If there's isn't one, then
		 * this analysis cannot proceed.
		 * 
		 * @param pc the program counter
		 * @param monitor a monitor for progress and cancellation
		 * @throws CancelledException if the monitor cancels the analysis
		 */
		public AnalysisForPC(Address pc, TaskMonitor monitor) throws CancelledException {
			this.pc = pc;
			this.function = program.getFunctionManager().getFunctionContaining(pc);
			if (function == null) {
				throw new UnwindException("No function contains " + pc);
			}
			this.monitor = monitor;
			this.graph = new BlockGraph(monitor);
			this.pathFinder =
				new DijkstraShortestPathsAlgorithm<>(graph, GEdgeWeightMetric.unitMetric());
			this.pcBlock = new BlockVertex(
				Unique.assertAtMostOne(blockModel.getCodeBlocksContaining(pc, monitor)));
		}

		/**
		 * Compute the shortest path(s) from function entry to the program counter
		 * 
		 * @return the paths. There's usually only one
		 * @throws CancelledException if the monitor cancels the analysis
		 */
		public Collection<Deque<BlockEdge>> getEntryPaths() throws CancelledException {
			BlockVertex entryBlock = new BlockVertex(Unique.assertAtMostOne(
				blockModel.getCodeBlocksContaining(function.getEntryPoint(), monitor)));

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Run auto-analysis on the program to create functions covering the PC address.
  2. Manually create a function at or containing the PC address (right-click > Create Function in listing).
  3. Verify the PC value is correct — check that the trace-to-program mapping resolved the right address.
  4. If the address is legitimately not in a function (e.g., JIT, shellcode), define a function there manually.

Example fix

// No code fix; ensure a function exists at the PC:
// In Ghidra: navigate to PC address > right-click > Create Function
// Or programmatically:
// new CreateFunctionCmd(pcAddress).applyTo(program);
Defensive patterns

Strategy: validation

Validate before calling

// Before calling UnwindAnalysis, verify a function contains the PC:
Function fn = program.getFunctionManager().getFunctionContaining(pc);
if (fn == null) {
    // trigger auto-analysis or create function before unwinding
}

Type guard

private boolean isPcInFunction(Address pc, Program program) {
    return program.getFunctionManager().getFunctionContaining(pc) != null;
}

Try / catch

try {
    new AnalysisForPC(pc, monitor).computeUnwindInfo();
} catch (UnwindException e) {
    if (e.getMessage().startsWith("No function contains")) {
        // auto-create function, then retry
    } else { throw e; }
}

Prevention

When it happens

Trigger: AnalysisForPC constructor calls program.getFunctionManager().getFunctionContaining(pc) which returns null. Occurs when the PC is in a code region that has no defined function — e.g., the address is in the middle of data, in unanalyzed code, or the function boundaries don't cover it.

Common situations: Auto-analysis hasn't been run or was incomplete. The PC is in a code cave, jump table, or data region that Ghidra doesn't recognize as code. The function was split or the disassembly created a gap. The program mapping points to the wrong address.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/33099aba2b3e591d. Report an issue: GitHub.