Skip to content

fix(java): analyzers are listed on an unanalysed program, and saving does not start analysis - #637

Open
heeen wants to merge 4 commits into
pr/settingsfrom
pr/analyzer-manager
Open

heeen wants to merge 4 commits into
pr/settingsfrom
pr/analyzer-manager

Conversation

@heeen

@heeen heeen commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #636, which is stacked on #635. This PR's own changes are the four commits below.

  • 7e5c173: list_analyzers and configure_analyzer now report each analyzer's description, so an agent can see why an extension turned an analyzer off before turning it back on.
  • 3b03ac4:
    • Ghidra registers analyzers, with their defaults and descriptions, only when it creates an AutoAnalysisManager for the program.
    • So on a program nothing had analysed, list_analyzers returned an empty list and configure_analyzer answered "Analyzer not found".
    • Both now create the manager first.
    • AnalyzerDescriptionsGhidraTest runs against a real program and fails without this fix.
  • 634c43d:
    • Saving a program, sweeping a tree, the dirty queue's check and list_project_files' analyzing flag all called AutoAnalysisManager.getAnalysisManager just to ask whether analysis was running.
    • That call creates a manager when none exists, and the manager instantiates every analyzer.
    • So saving a program or building a tree attached full auto-analysis to a program nobody had asked to analyse.
    • These checks now call hasAutoAnalysisManager first.
  • a3e7c84: the Gradle test JVM gets a 2 GB heap. After ClassSearcher.search, every analysis manager in the JVM instantiates all analyzers, and the offline plus real-Ghidra run ran out of memory on Gradle's default worker heap. Maven's default heap was already enough.

Tests

  • Java offline and real-Ghidra tiers: 1154 tests, 0 failures, 0 skipped (Ghidra 12.1.4).

https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6

heeen added 4 commits October 30, 2026 19:59
… description

Lets agents see why an analyzer is on or off before re-enabling one an
extension disabled deliberately.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
…n an unanalysed program

Ghidra stores only analysis option values that were set; the analyzers,
their defaults and descriptions are registered when an AutoAnalysisManager
is created for the program. On a program nothing had analysed,
list_analyzers returned an empty list and configure_analyzer answered
'Analyzer not found', and descriptions were missing wherever no manager
existed yet. Both now create the manager first.

AnalyzerDescriptionsGhidraTest runs against a real program (fails without
the fix); the two Mockito tests from 766b2510 are dropped, since the
manager cannot be built over a mocked Program.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
ProgramSaves.awaitAnalysis, the sweep's wait, the dirty queue's check and
list_project_files' analyzing flag called AutoAnalysisManager
.getAnalysisManager only to ask whether analysis was running. That call
creates a manager when none exists, and a manager instantiates every
analyzer (the x86 function-start pattern searchers alone are several MB),
so saving a program or building a tree attached full auto-analysis to a
program nothing had asked to analyse. With no manager nothing is
analysing; they now check hasAutoAnalysisManager first.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
AnalyzerDescriptionsGhidraTest runs ClassSearcher.search, after which
every AutoAnalysisManager in the JVM instantiates all analyzers, and the
real-Ghidra tier leaves dozens of programs open. The offline + core run
died with OutOfMemoryError on Gradle's default worker heap; Maven's
default (a quarter of RAM) was enough.

Claude-Session: https://claude.ai/code/session_01FNRMtY3ocPVd7kxcUGi2X6
@bethington

Copy link
Copy Markdown
Owner

I'd like to take this ahead of #636. Its four commits don't depend on the settings registry: the first two apply to dev cleanly, and the third conflicts only in ProgramSaves.java, against the bounded analysis wait that landed in a2b705c. Could you retarget it onto dev? #636 needs a longer review and I'd rather not hold this fix behind it.

The bug is real on dev today: ProgramSaves, DirtyQueue and SweepJob all call getAnalysisManager just to ask whether analysis is running.

@bethington bethington mentioned this pull request Nov 18, 2026

@rahul05ranjan rahul05ranjan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the central claim against upstream Ghidra and it holds: AutoAnalysisManager's private constructor (AutoAnalysisManager.java:149) runs initializeAnalyzers() → registerOptions(), so analyzer names/defaults/descriptions only appear in Program.ANALYSIS_PROPERTIES once a manager exists for the program. hasAutoAnalysisManager (line 944) is the right pre-check, and every site you converted (awaitAnalysis, analysisStatus, DirtyQueue.isAnalyzing, SweepJob.waitForAnalysisIfNeeded) only ever needed the side-effect-free query — creating a manager just to ask "is anything running?" was the actual bug. The analysisOptions() helper doing the deliberate getAnalysisManager for list_analyzers/configure_analyzer is the correct split.

One thing worth being aware of: because the manager registers a close-listener and holds every analyzer instance, a single list_analyzers call now pins several MB of analyzers to that program for its remaining lifetime — the same cost the maxHeapSize = '2g' bump in build.gradle is paying for in the test JVM. On the headless server with one program that's a non-issue, but on the GUI server an agent walking over dozens of open programs with list_analyzers would now leave a full analyzer set resident in each. If that ever matters, a variant that registers options without building the scheduler lists (e.g. a lighter ClassSearcher-based enumeration) could avoid it — no action needed unless you've seen the GUI footprint.

Small nit on the test: AnalyzerDescriptionsGhidraTest.listAnalyzersDescribesStockAnalyzersOnAnUnanalysedProgram asserts a description only for "Shared Return Calls". An assertion that at least a handful of entries carry a non-blank description (or that entries.size() is well above the handful of stale boolean options that pass the getBoolean filter) would catch a regression where analysisOptions() stops registering and the list quietly shrinks to a couple of pre-stored names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants