From 7d67188d0b9aec27b83cafcc89529ecc5c8e1a28 Mon Sep 17 00:00:00 2001 From: ghidragon <106987263+ghidragon@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:47:18 -0500 Subject: [PATCH] GP-3970 program caching and refactoring of ProgramManager and OpenProgramTask --- .../core/debug/gui/model/ObjectTreeModel.java | 4 +- .../database/program/DBTraceProgramView.java | 11 + .../program/DBTraceProgramViewRegisters.java | 11 + Ghidra/Features/Base/certification.manifest | 1 - .../help/topics/Tool/ToolOptions_Dialog.htm | 175 +++--- .../app/merge/ProgramMergeManagerPlugin.java | 37 +- .../FunctionComparisonProvider.java | 20 +- .../core/progmgr/MultiProgramManager.java | 172 ++---- .../app/plugin/core/progmgr/ProgramCache.java | 110 ++++ .../plugin/core/progmgr/ProgramLocator.java | 201 +++++++ .../core/progmgr/ProgramManagerPlugin.java | 522 +++++++++--------- .../ghidra/app/services/ProgramManager.java | 88 ++- .../app/util/task/OpenProgramRequest.java | 55 ++ .../ghidra/app/util/task/OpenProgramTask.java | 411 ++------------ .../ghidra/app/util/task/ProgramOpener.java | 304 ++++++++++ .../src/main/java/ghidra/test/TestEnv.java | 21 +- .../plugin/core/progmgr/ProgramCacheTest.java | 115 ++++ .../progmgr/ProgramCachingServiceTest.java | 97 ++++ .../framework/project/tool/CloseToolTest.java | 7 +- .../app/services/TestDummyProgramManager.java | 26 +- .../plugin/core/diff/DiffProgramManager.java | 25 +- .../ghidra/feature/vt/api/db/VTSessionDB.java | 2 +- .../feature/vt/api/util/EmptyVTSession.java | 11 + .../vt/gui/plugin/VTSubToolManager.java | 4 +- .../vt/gui/wizard/NewSessionPanel.java | 2 +- .../main/java/ghidra/util/timer/GTimer.java | 4 +- .../java/ghidra/util/timer/GTimerCache.java | 336 +++++++++++ .../ghidra/util/timer/GTimerCacheTest.java | 253 +++++++++ .../framework/data/DomainObjectAdapter.java | 31 +- .../data/DomainObjectFileListener.java | 32 ++ .../ghidra/framework/model/DomainObject.java | 17 + .../framework/protocol/ghidra/GhidraURL.java | 9 + .../ghidra/program/model/StubProgram.java | 11 + .../src/main/java/utility/function/Dummy.java | 21 + 34 files changed, 2198 insertions(+), 948 deletions(-) create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramCache.java create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramLocator.java create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/task/OpenProgramRequest.java create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/task/ProgramOpener.java create mode 100644 Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/progmgr/ProgramCacheTest.java create mode 100644 Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/progmgr/ProgramCachingServiceTest.java create mode 100644 Ghidra/Framework/Generic/src/main/java/ghidra/util/timer/GTimerCache.java create mode 100644 Ghidra/Framework/Generic/src/test/java/ghidra/util/timer/GTimerCacheTest.java create mode 100644 Ghidra/Framework/Project/src/main/java/ghidra/framework/data/DomainObjectFileListener.java diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/model/ObjectTreeModel.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/model/ObjectTreeModel.java index 7b2d34d53c..8cde85d33f 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/model/ObjectTreeModel.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/model/ObjectTreeModel.java @@ -621,9 +621,7 @@ public class ObjectTreeModel implements DisplaysModified { protected List generateObjectChildren(TraceObject object) { List result = ObjectTableModel - .distinctCanonical(object.getValues(span) - .stream() - .filter(this::isValueVisible)) + .distinctCanonical(object.getValues(span).stream().filter(this::isValueVisible)) .map(v -> nodeCache.getOrCreateNode(v)) .sorted() .collect(Collectors.toList()); diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java index 0c321b41fd..55ebe86cbd 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java @@ -26,6 +26,7 @@ import org.apache.commons.lang3.tuple.Pair; import db.Transaction; import ghidra.framework.data.DomainObjectEventQueues; +import ghidra.framework.data.DomainObjectFileListener; import ghidra.framework.model.*; import ghidra.framework.options.Options; import ghidra.framework.store.LockException; @@ -1274,6 +1275,16 @@ public class DBTraceProgramView implements TraceProgramView { trace.removeCloseListener(listener); } + @Override + public void addDomainFileListener(DomainObjectFileListener listener) { + throw new UnsupportedOperationException(); + } + + @Override + public void removeDomainFileListener(DomainObjectFileListener listener) { + throw new UnsupportedOperationException(); + } + @Override public EventQueueID createPrivateEventQueue(DomainObjectListener listener, int maxDelay) { getEventTranslator(); diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewRegisters.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewRegisters.java index d29517c7c2..2e0bd8c1e6 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewRegisters.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewRegisters.java @@ -21,6 +21,7 @@ import java.util.*; import db.Transaction; import ghidra.framework.data.DomainObjectEventQueues; +import ghidra.framework.data.DomainObjectFileListener; import ghidra.framework.model.*; import ghidra.framework.options.Options; import ghidra.framework.store.LockException; @@ -478,6 +479,16 @@ public class DBTraceProgramViewRegisters implements TraceProgramView { view.removeCloseListener(listener); } + @Override + public void addDomainFileListener(DomainObjectFileListener listener) { + throw new UnsupportedOperationException(); + } + + @Override + public void removeDomainFileListener(DomainObjectFileListener listener) { + throw new UnsupportedOperationException(); + } + @Override public EventQueueID createPrivateEventQueue(DomainObjectListener listener, int maxDelay) { return eventQueues.createPrivateEventQueue(listener, maxDelay); diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifest index 608491ab2a..9b63f669c3 100644 --- a/Ghidra/Features/Base/certification.manifest +++ b/Ghidra/Features/Base/certification.manifest @@ -389,7 +389,6 @@ src/main/help/help/topics/MemoryMapPlugin/images/MoveMemory.png||GHIDRA||||END| src/main/help/help/topics/MemoryMapPlugin/images/SetImageBaseDialog.png||GHIDRA||||END| src/main/help/help/topics/MemoryMapPlugin/images/SplitMemoryBlock.png||GHIDRA||||END| src/main/help/help/topics/Misc/Appendix.htm||GHIDRA||||END| -src/main/help/help/topics/Misc/Tips.htm||NONE||||END| src/main/help/help/topics/Misc/Welcome_to_Ghidra_Help.htm||GHIDRA||||END| src/main/help/help/topics/Navigation/Navigation.htm||GHIDRA||||END| src/main/help/help/topics/Navigation/images/GoToDialog.png||GHIDRA||||END| diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Tool/ToolOptions_Dialog.htm b/Ghidra/Features/Base/src/main/help/help/topics/Tool/ToolOptions_Dialog.htm index 2ef2591db5..5adc29b190 100644 --- a/Ghidra/Features/Base/src/main/help/help/topics/Tool/ToolOptions_Dialog.htm +++ b/Ghidra/Features/Base/src/main/help/help/topics/Tool/ToolOptions_Dialog.htm @@ -22,12 +22,12 @@

-
-

The Tool Options dialog has a filter text field - that can be used to quickly find options relating to a keyword. Any options names or - descriptions that contain the keyword text will be displayed.
-

-
+
+

The Tool Options dialog has a filter text field + that can be used to quickly find options relating to a keyword. Any options names or + descriptions that contain the keyword text will be displayed.
+

+

To display the Options dialog, select Edit

You can restore any currently selected options panel to its default settings by pressing the Restore Defaults button at the bottom of the options panel. Use caution - when executing this action, as it cannot be undone.

+ when executing this action, as it cannot be undone.


- - - - - - -
-

-
+
+ +



@@ -56,37 +50,34 @@

Key Bindings

-

You can create a new key binding (accelerator key) for an action or modify the - default key binding. The key binding that you add can be used to execute the action - using the keyboard. Below we describe the Key Bindings options editor.

+

You can create a new key binding (accelerator key) for an action or modify the + default key binding. The key binding that you add can be used to execute the action using the + keyboard. Below we describe the Key Bindings options editor.

-

Not all key bindings are changeable - via the tool options. For example, the following keys cannot be changed: +

Not all key bindings are changeable via + the tool options. For example, the following keys cannot be changed:

+
    -
  • - F1, Help, Ctrl-F1, F4 (this bindings are reserved and cannot be used - when assigning key bindings to actions) -
  • -
  • - Menu Navigation Actions: 1-9, Page Up/Down, End, Home (these key - bindings are usable with a menu or popup menu open and are otherwise available for - assignment to key bindings). -
  • -
-

+
  • F1, Help, Ctrl-F1, F4 (this bindings are reserved and cannot be used + when assigning key bindings to actions)
  • + +
  • Menu Navigation Actions: 1-9, Page Up/Down, End, Home (these key + bindings are usable with a menu or popup menu open and are otherwise available for + assignment to key bindings).
  • +
    +
    -
    -

    You can also change key bindings - from within Ghidra by pressing F4 while the mouse is over any toolbar icon or menu - item. Click here for more info.

    +

    You can also change key bindings from + within Ghidra by pressing F4 while the mouse is over any toolbar icon or menu item. + Click here for more info.

    The Key Bindings option editor has a table with the following sortable columns: - Action Name, Key Binding, and Plugin Name. To change a value in - the table, select the row and then edit the text field below the table.

    + Action Name, Key Binding, and Plugin Name. To change a value in the + table, select the row and then edit the text field below the table.

    • The text field below the table captures keystroke combinations entered.
    • @@ -99,16 +90,9 @@ Key Bindings Options panel works the same as for a regular Ghidra Tool.

    - - - - - - -
    -

    -
    - +
    + +

    Change a Key Binding

    @@ -144,9 +128,8 @@ is enabled), then a dialog is displayed for you to choose what action you want to perform.

    -

    To avoid the extra step of choosing the - action from the dialog, do not map the same key to actions that are applicable in the same - context.

    +

    To avoid the extra step of choosing the action from the dialog, do not map the same key to + actions that are applicable in the same context.

    Remove a Key Binding

    @@ -194,15 +177,15 @@
  • Press OK to import the key bindings.
  • -

    Importing key bindings will override - your current key bindings settings. It is suggested that you export your - key bindings before you import so that you may revert to your previous settings if - necessary.

    +

    Importing key bindings will + override your current key bindings settings. It is suggested that you export your key bindings before you import so that you may revert to your + previous settings if necessary.

    After importing you must save your - tool (File Save Tool) if you want you changes - to persist between tool invocations.

    + tool (File + Save Tool) if you want you changes to persist between tool + invocations.

    Key Binding Short-Cut

    @@ -259,7 +242,8 @@
    1. Select Edit Tool Options from the menu bar.
    2. + "help/shared/arrow.gif"> Tool Options from the menu + bar.
    3. Select the Key Bindings node in the options tree.
    4. @@ -283,15 +267,14 @@ basic options. Plugins may add their own options to the Tool options. If a tool does not have a plugin that uses an option, the option will not show up on the Tool panel. For example, the Ghidra Project Window does not have plugins that use the Max Go to Entries - or Subroutine Model, so these options will not appear on the Tool panel. - If an option has a description, it will show up in the description panel below the tree when - you pass the mouse pointer over the component in the options panel.

      + or Subroutine Model, so these options will not appear on the Tool panel. If an option + has a description, it will show up in the description panel below the tree when you pass the + mouse pointer over the component in the options panel.

      - @@ -379,7 +362,6 @@
      Option
      - @@ -395,31 +377,27 @@ others. - - + - - - + + - + - + - + @@ -450,7 +428,48 @@ +

      Program Caching

      + +
      +

      Some features of Ghidra require opening programs briefly. Often the same set of programs + may need to be opened repeatedly. Ghidra provides a caching service to make these uses more + efficient. The following two options are available:

      +
      + +
      +
      +
      Option
      Automatically Save Tools This controls whether Ghidra will save tool state when the tool is closed.
      Restore Previous ProjectThis controls - whether or not Ghidra automatically opens the previously loaded project on - startup.This controls whether or not Ghidra automatically + opens the previously loaded project on startup.
      Default Tool Launch ModeThis controls - if a new or already running tool should be used during default launch. - Tool "reuse" mode will open selected file within a suitable running tool - if one can be identified, otherwise a new tool will be launched. - This controls if a new or already running tool should + be used during default launch. Tool "reuse" mode will open selected file within a + suitable running tool if one can be identified, otherwise a new tool will be + launched.
      + + + + + + + + + + + + + + + + + + + +
      OptionDescription
      Program Cache SizeThis options + specifies the maximum number of programs to keep open in the cache.
      Program Cache DurationThis option + specifies how long (in minutes) to keep an otherwise unused cached program open. If + the program is in use by some feature, it won't be closed when the time + expires, and it will stay in the cache for the full cache time.
      +
      +
      + +

      Related Topics:

      +
      +