Skip to content

Ghidra is a software reverse engineering (SRE) framework

Updated tool closing to cancel and wait for tasks

dragonmacher65f47892079c
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisManager.java
index add58bad86..5be6e12775 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisManager.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisManager.java
@@ -458,8 +458,8 @@ public class AutoAnalysisManager implements DomainObjectListener, DomainObjectCl
break;
// FIXME: must resolve cyclic issues before this can be done
// case ChangeManager.DOCR_MEM_REFERENCE_ADDED:
-// // Allow high-priority reference-driven code analyzers a
-// // shot at processing computed flows determined during
+// // Allow high-priority reference-driven code analyzers a
+// // shot at processing computed flows determined during
// // constant propagation.
// pcr = (ProgramChangeRecord) doRecord;
// Reference ref = (Reference) pcr.getNewValue();
@@ -801,7 +801,7 @@ public class AutoAnalysisManager implements DomainObjectListener, DomainObjectCl
}
if (!yield) {
- notifyAnalysisEnded();
+ notifyAnalysisEnded(monitor.isCancelled());
if (printTaskTimes) {
printTimedTasks();
saveTaskTimes();
@@ -848,13 +848,13 @@ public class AutoAnalysisManager implements DomainObjectListener, DomainObjectCl
listeners.remove(listener);
}
- private void notifyAnalysisEnded() {
+ private void notifyAnalysisEnded(boolean isCancelled) {
for (AnalysisTaskList list : taskArray) {
list.notifyAnalysisEnded(program);
}
for (AutoAnalysisManagerListener listener : listeners) {
- listener.analysisEnded(this);
+ listener.analysisEnded(this, isCancelled);
}
log.clear();
}
@@ -1061,7 +1061,7 @@ public class AutoAnalysisManager implements DomainObjectListener, DomainObjectCl
}
catch (OptionsVetoException e) {
// FIXME!! Not good to popup for all use cases
- // This will only happen if an Analyzer author makes a mistake
+ // This will only happen if an Analyzer author makes a mistake
Msg.showError(this, null, "Invalid Analysis Option",
"Invalid Analysis option set during initialization", e);
}
@@ -1179,7 +1179,7 @@ public class AutoAnalysisManager implements DomainObjectListener, DomainObjectCl
/**
* Get the set of addresses that have been protected from clearing
- *
+ *
* @return protected locations
*/
public AddressSetView getProtectedLocations() {
@@ -1188,7 +1188,7 @@ public class AutoAnalysisManager implements DomainObjectListener, DomainObjectCl
/**
* Add a location that is know good code to be protected from clearing for this Analysis run only.
- *
+ *
* @param addr address to protect
*/
public void setProtectedLocation(Address addr) {
@@ -1197,7 +1197,7 @@ public class AutoAnalysisManager implements DomainObjectListener, DomainObjectCl
/**
* Add a set of known good code locations to be protected from clearing for this Analysis run only.
- *
+ *
* @param set of addresses to protect
*/
public void setProtectedLocations(AddressSet set) {
@@ -1292,12 +1292,12 @@ public class AutoAnalysisManager implements DomainObjectListener, DomainObjectCl
testLen = spacer.length() - 5;
}
taskTimesStringBuf
- .append(" " + element + spacer.substring(testLen) + secString + "\n");
+ .append(" " + element + spacer.substring(testLen) + secString + "\n");
}
taskTimesStringBuf.append("-----------------------------------------------------\n");
taskTimesStringBuf
- .append(" Total Time " + (int) (totalTaskTime / 1000.00) + " secs\n");
+ .append(" Total Time " + (int) (totalTaskTime / 1000.00) + " secs\n");
taskTimesStringBuf.append("-----------------------------------------------------\n");
return taskTimesStringBuf.toString();
@@ -1556,7 +1556,7 @@ public class AutoAnalysisManager implements DomainObjectListener, DomainObjectCl
public long getMaximum() {
return Math.max(primaryMonitor.getMaximum(), secondaryMonitor.getMaximum());
}
-
+
@Override
public void checkCanceled() throws CancelledException {
primaryMonitor.checkCancelled();
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisManagerListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisManagerListener.java
index 0abbe6f554..66f78dd86c 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisManagerListener.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisManagerListener.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +17,5 @@ package ghidra.app.plugin.core.analysis;
public interface AutoAnalysisManagerListener {
- void analysisEnded(AutoAnalysisManager manager);
-
+ public void analysisEnded(AutoAnalysisManager manager, boolean isCancelled);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisPlugin.java
index 88e43295d5..eb6d4a01fa 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/AutoAnalysisPlugin.java
@@ -46,7 +46,7 @@ import ghidra.util.task.TaskLauncher;
/**
* AutoAnalysisPlugin
- *
+ *
* Provides support for auto analysis tasks. Manages a pipeline or priority of
* tasks to run given some event has occurred.
*/
@@ -101,32 +101,32 @@ public class AutoAnalysisPlugin extends Plugin implements AutoAnalysisManagerLis
*/
private void createActions() {
- // use this index to make sure that the following actions are ordered in the way that
+ // use this index to make sure that the following actions are ordered in the way that
// they are inserted
int subGroupIndex = 0;
- autoAnalyzeAction = new ActionBuilder("Auto Analyze", getName())
- .menuPath("&Analysis", "&Auto Analyze...")
- .menuGroup(ANALYZE_GROUP_NAME, "" + subGroupIndex++)
- .keyBinding("A")
- .withContext(ListingActionContext.class, true)
- .onAction(this::analyzeCallback)
- .buildAndInstall(tool);
+ autoAnalyzeAction =
+ new ActionBuilder("Auto Analyze", getName()).menuPath("&Analysis", "&Auto Analyze...")
+ .menuGroup(ANALYZE_GROUP_NAME, "" + subGroupIndex++)
+ .keyBinding("A")
+ .withContext(ListingActionContext.class, true)
+ .onAction(this::analyzeCallback)
+ .buildAndInstall(tool);
// we need to specially override the validContextWhen so that as a side effect, we
// can change the action name to not include a program name when the action is
- // actually invalid.
+ // actually invalid.
autoAnalyzeAction.validContextWhen(ac -> {
updateActionName(ac);
return ac instanceof ListingActionContext;
});
new ActionBuilder("Analyze All Open", getName())
- .menuPath("&Analysis", "Analyze All &Open...")
- .menuGroup(ANALYZE_GROUP_NAME, "" + subGroupIndex++)
- .withContext(ListingActionContext.class, true)
- .onAction(c -> analyzeAllCallback())
- .buildAndInstall(tool);
+ .menuPath("&Analysis", "Analyze All &Open...")
+ .menuGroup(ANALYZE_GROUP_NAME, "" + subGroupIndex++)
+ .withContext(ListingActionContext.class, true)
+ .onAction(c -> analyzeAllCallback())
+ .buildAndInstall(tool);
tool.setMenuGroup(new String[] { "Analysis", "One Shot" }, ANALYZE_GROUP_NAME);
@@ -263,8 +263,8 @@ public class AutoAnalysisPlugin extends Plugin implements AutoAnalysisManagerLis
private void programActivated(Program program) {
program.getOptions(StoredAnalyzerTimes.OPTIONS_LIST)
- .registerOption(StoredAnalyzerTimes.OPTION_NAME, OptionType.CUSTOM_TYPE, null, null,
- "Cumulative analysis task times", new StoredAnalyzerTimesPropertyEditor());
+ .registerOption(StoredAnalyzerTimes.OPTION_NAME, OptionType.CUSTOM_TYPE, null, null,
+ "Cumulative analysis task times", new StoredAnalyzerTimesPropertyEditor());
}
@@ -276,7 +276,7 @@ public class AutoAnalysisPlugin extends Plugin implements AutoAnalysisManagerLis
}
/**
- * Show the options panel for the auto analysis options.
+ * Show the options panel for the auto analysis options.
*/
private boolean showOptionsDialog(Program program) {
tool.clearStatusInfo();
@@ -298,7 +298,7 @@ public class AutoAnalysisPlugin extends Plugin implements AutoAnalysisManagerLis
}
@Override
- public void analysisEnded(AutoAnalysisManager manager) {
+ public void analysisEnded(AutoAnalysisManager manager, boolean isCancelled) {
MessageLog log = manager.getMessageLog();
if (log.hasMessages()) {
@@ -370,10 +370,13 @@ public class AutoAnalysisPlugin extends Plugin implements AutoAnalysisManagerLis
private class FirstTimeAnalyzedCallback implements AutoAnalysisManagerListener {
@Override
- public void analysisEnded(AutoAnalysisManager manager) {
+ public void analysisEnded(AutoAnalysisManager manager, boolean isCancelled) {
manager.removeListener(this);
- tool.firePluginEvent(new FirstTimeAnalyzedPluginEvent(AutoAnalysisPlugin.this.getName(),
- manager.getProgram()));
+
+ if (!isCancelled) {
+ tool.firePluginEvent(new FirstTimeAnalyzedPluginEvent(
+ AutoAnalysisPlugin.this.getName(), manager.getProgram()));
+ }
}
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java
index b45a06cf26..3154e63d6b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java
@@ -472,7 +472,7 @@ public class ProgramManagerPlugin extends Plugin implements ProgramManager {
@Override
protected boolean saveData() {
- boolean result = programSaveMgr.canCloseAll();
+ boolean result = programSaveMgr.saveAll();
contextChanged();
return result;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramSaveManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramSaveManager.java
index 8895ec949c..f9a5dc6523 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramSaveManager.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramSaveManager.java
@@ -81,15 +81,12 @@ class ProgramSaveManager {
return false;
}
- boolean canCloseAll() {
+ boolean saveAll() {
Program[] programs = programMgr.getAllOpenPrograms();
List<Program> saveList = new ArrayList<>();
List<Program> lockList = new ArrayList<>();
try {
for (Program program : programs) {
-// if (programs[i].isTemporary()) {
-// continue;
-// }
if (isOnlyToolConsumer(program)) {
if (!acquireSaveLock(program, "Close")) {
return false;
@@ -307,7 +304,7 @@ class ProgramSaveManager {
// String title = "Save "+currentProgram.getName();
// String closeItem = closingProgram ? "program" : "tool";
// String filename = currentProgram.getDomainFile().getPathname();
-// StringBuffer buf = new StringBuffer();
+// StringBuffer buf = new StringBuffer();
// buf.append("The program ("+filename+") is currently being modified by the\n");
// buf.append("the following actions:\n \n");
// ProgramDB program = (ProgramDB)currentProgram;
@@ -327,16 +324,16 @@ class ProgramSaveManager {
// buf.append("Do you want to abort the actions and continue to close the ");
// buf.append(closeItem);
// buf.append("?");
-//
+//
// int result = OptionDialog.showOptionDialog(tool.getToolFrame(),title , buf.toString(),
// "Abort Actions", OptionDialog.WARNING_MESSAGE);
-//
+//
// return result == OptionDialog.OPTION_ONE;
// }
// private boolean checkForSave(Program currentProgram) {
// DomainFile df = currentProgram.getDomainFile();
-//
-// String filename = df.getName();
+//
+// String filename = df.getName();
//
// if (!df.isInProject()) {
// return OptionDialog.showOptionDialog(tool.getToolFrame(),
@@ -346,7 +343,7 @@ class ProgramSaveManager {
// "If you continue, your changes will be lost!",
// "Continue", OptionDialog.QUESTION_MESSAGE) != OptionDialog.CANCEL_OPTION;
// }
-//
+//
// if (df.isReadOnly()) {
// return OptionDialog.showOptionDialog(tool.getToolFrame(),
// "Program Changed",
@@ -354,9 +351,9 @@ class ProgramSaveManager {
// " has been changed. \n"+
// "If you continue, your changes will be lost!",
// "Continue", OptionDialog.QUESTION_MESSAGE) != OptionDialog.CANCEL_OPTION;
-//
+//
// }
-//
+//
//
// int result = OptionDialog.showOptionDialog(tool.getToolFrame(),
// "Save Program?",
@@ -364,7 +361,7 @@ class ProgramSaveManager {
// " has changed. Do you want to save it?",
// "&Save", "Do&n't Save",
// OptionDialog.QUESTION_MESSAGE);
-//
+//
// if (result == OptionDialog.CANCEL_OPTION) {
// return false;
// }
@@ -526,7 +523,7 @@ class ProgramSaveManager {
* @param folder new parent folder
* @param newName name for domain object
* @param doOverwrite true means the given name already exists and the user
- * wants to overwrite that existing file; false means a new file will
+ * wants to overwrite that existing file; false means a new file will
* get created
*/
SaveAsTask(DomainObject obj, DomainFolder folder, String newName, boolean doOverwrite) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/GccExceptionAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/GccExceptionAnalyzer.java
index 2359547cfd..cd0e9950a5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/GccExceptionAnalyzer.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/GccExceptionAnalyzer.java
@@ -57,7 +57,7 @@ public class GccExceptionAnalyzer extends AbstractAnalyzer {
private Set<Program> visitedPrograms = new HashSet<>();
private AutoAnalysisManagerListener analysisListener =
- (manager) -> visitedPrograms.remove(manager.getProgram());
+ (manager, isCancelled) -> visitedPrograms.remove(manager.getProgram());
/**
* Creates an analyzer for marking up the GCC exception handling information.
@@ -106,9 +106,10 @@ public class GccExceptionAnalyzer extends AbstractAnalyzer {
boolean isGcc =
program.getCompilerSpec().getCompilerSpecID().getIdAsString().equalsIgnoreCase("gcc");
- boolean isDefault =
- program.getCompilerSpec().getCompilerSpecID().getIdAsString().equalsIgnoreCase(
- "default");
+ boolean isDefault = program.getCompilerSpec()
+ .getCompilerSpecID()
+ .getIdAsString()
+ .equalsIgnoreCase("default");
if (!isGcc && !isDefault) {
return false;
@@ -156,7 +157,7 @@ public class GccExceptionAnalyzer extends AbstractAnalyzer {
/*
* Parses the standard GCC exception handling support sections:
* 1) EHFrameHeader ('.eh_frame_hdr')
- * 2) EHFrame ('.eh_frame')
+ * 2) EHFrame ('.eh_frame')
*/
private void handleStandardSections(Program program, TaskMonitor monitor, MessageLog log)
throws CancelledException {
@@ -405,8 +406,8 @@ public class GccExceptionAnalyzer extends AbstractAnalyzer {
}
/**
- * A TypeInfo associates the address of a type information record with the filter value that
- * is used to handle a catch action for that type.
+ * A TypeInfo associates the address of a type information record with the filter value that
+ * is used to handle a catch action for that type.
*/
private class TypeInfo {
private Address typeInfoAddress;
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/framework/project/tool/CloseToolTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/framework/project/tool/CloseToolTest.java
index 1bc331c153..3e46da1431 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/framework/project/tool/CloseToolTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/framework/project/tool/CloseToolTest.java
@@ -173,13 +173,7 @@ public class CloseToolTest extends AbstractGhidraHeadedIntegrationTest {
assertNotNull("Did not get option dialog to close tool with running task", dialog);
pressButtonByText(dialog, "Yes");
- // check for another warning about closing the program with running tasks
- dialog = waitForDialogComponent(OptionDialog.class);
- assertNotNull("Did not get option dialog to close program with running task", dialog);
- pressButtonByText(dialog, "Close!");
- waitForSwing();
-
- assertNull("Tool did not close after task", tool.getToolFrame());
+ waitFor(() -> tool.getToolFrame() == null, "Tool did not close after task");
stopBackgroundCommand(tool, cmd);
}
@@ -231,11 +225,9 @@ public class CloseToolTest extends AbstractGhidraHeadedIntegrationTest {
@Override
public boolean applyTo(DomainObject obj, TaskMonitor monitor) {
hasStarted = true;
-
- while (!stop) {
+ while (!stop && !monitor.isCancelled()) {
sleep(100);
}
-
return true;
}
}
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndTool.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndTool.java
index 44000e7246..55bbdbe917 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndTool.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndTool.java
@@ -233,7 +233,7 @@ public class FrontEndTool extends PluginTool implements OptionsChangeListener {
@Override
protected boolean doSaveTool() {
// This method is overridden to allow the FrontEndTool to perform custom saving.
- // The super.doSaveTool is designed to save tools to the user's tool chest directory. The
+ // The super.doSaveTool is designed to save tools to the user's tool chest directory. The
// FrontEndTool saves its state directly in the user's settings directory and includes
// the entire project's state such as what tools were running and data states for each
// running tool.
@@ -397,7 +397,7 @@ public class FrontEndTool extends PluginTool implements OptionsChangeListener {
}
@Override
- public boolean canClose() {
+ protected boolean canClose() {
return super.canClose() && plugin.closeActiveProject();
}
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginTool.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginTool.java
index 303eac34cc..932a4dfaf9 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginTool.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginTool.java
@@ -54,6 +54,7 @@ import ghidra.framework.plugintool.mgr.*;
import ghidra.framework.plugintool.util.*;
import ghidra.framework.project.ProjectDataService;
import ghidra.util.*;
+import ghidra.util.exception.CancelledException;
import ghidra.util.task.*;
import help.Help;
import help.HelpService;
@@ -737,14 +738,6 @@ public abstract class PluginTool extends AbstractDockingTool {
taskMgr.executeCommand(cmd, obj);
}
- /**
- * Cancel any running command and clear the command queue.
- * @param wait if true wait for current task to cancel cleanly
- */
- public void terminateBackgroundCommands(boolean wait) {
- taskMgr.stop(wait);
- }
-
/**
* Add the given background command to a queue that is processed after the
* main background command completes.
@@ -1049,7 +1042,7 @@ public abstract class PluginTool extends AbstractDockingTool {
saveAsAction.setEnabled(true);
saveAsAction
- .setHelpLocation(new HelpLocation(ToolConstants.TOOL_HELP_TOPIC, "Tool_Changes"));
+ .setHelpLocation(new HelpLocation(ToolConstants.TOOL_HELP_TOPIC, "Tool_Changes"));
addAction(saveAction);
addAction(saveAsAction);
@@ -1075,7 +1068,7 @@ public abstract class PluginTool extends AbstractDockingTool {
menuData.setMenuSubGroup(Integer.toString(subGroup++));
exportToolAction.setMenuBarData(menuData);
exportToolAction
- .setHelpLocation(new HelpLocation(ToolConstants.TOOL_HELP_TOPIC, "Export_Tool"));
+ .setHelpLocation(new HelpLocation(ToolConstants.TOOL_HELP_TOPIC, "Export_Tool"));
addAction(exportToolAction);
DockingAction exportDefautToolAction =
@@ -1098,42 +1091,42 @@ public abstract class PluginTool extends AbstractDockingTool {
protected void addHelpActions() {
new ActionBuilder("About Ghidra", ToolConstants.TOOL_OWNER)
- .menuPath(ToolConstants.MENU_HELP, "&About Ghidra")
- .menuGroup("ZZA")
- .helpLocation(new HelpLocation(ToolConstants.ABOUT_HELP_TOPIC, "About_Ghidra"))
- .inWindow(ActionBuilder.When.ALWAYS)
- .onAction(c -> DockingWindowManager.showDialog(new AboutDialog()))
- .buildAndInstall(this);
+ .menuPath(ToolConstants.MENU_HELP, "&About Ghidra")
+ .menuGroup("ZZA")
+ .helpLocation(new HelpLocation(ToolConstants.ABOUT_HELP_TOPIC, "About_Ghidra"))
+ .inWindow(ActionBuilder.When.ALWAYS)
+ .onAction(c -> DockingWindowManager.showDialog(new AboutDialog()))
+ .buildAndInstall(this);
new ActionBuilder("User Agreement", ToolConstants.TOOL_OWNER)
- .menuPath(ToolConstants.MENU_HELP, "&User Agreement")
- .menuGroup(ToolConstants.HELP_CONTENTS_MENU_GROUP)
- .helpLocation(new HelpLocation(ToolConstants.ABOUT_HELP_TOPIC, "User_Agreement"))
- .inWindow(ActionBuilder.When.ALWAYS)
- .onAction(
- c -> DockingWindowManager.showDialog(new UserAgreementDialog(false, false)))
- .buildAndInstall(this);
+ .menuPath(ToolConstants.MENU_HELP, "&User Agreement")
+ .menuGroup(ToolConstants.HELP_CONTENTS_MENU_GROUP)
+ .helpLocation(new HelpLocation(ToolConstants.ABOUT_HELP_TOPIC, "User_Agreement"))
+ .inWindow(ActionBuilder.When.ALWAYS)
+ .onAction(
+ c -> DockingWindowManager.showDialog(new UserAgreementDialog(false, false)))
+ .buildAndInstall(this);
final ErrorReporter reporter = ErrLogDialog.getErrorReporter();
if (reporter != null) {
new ActionBuilder("Report Bug", ToolConstants.TOOL_OWNER)
- .menuPath(ToolConstants.MENU_HELP, "&Report Bug...")
- .menuGroup("BBB")
- .helpLocation(new HelpLocation("ErrorReporting", "Report_Bug"))
- .inWindow(ActionBuilder.When.ALWAYS)
- .onAction(c -> reporter.report(getToolFrame(), "User Bug Report", null))
- .buildAndInstall(this);
+ .menuPath(ToolConstants.MENU_HELP, "&Report Bug...")
+ .menuGroup("BBB")
+ .helpLocation(new HelpLocation("ErrorReporting", "Report_Bug"))
+ .inWindow(ActionBuilder.When.ALWAYS)
+ .onAction(c -> reporter.report(getToolFrame(), "User Bug Report", null))
+ .buildAndInstall(this);
}
HelpService help = Help.getHelpService();
new ActionBuilder("Contents", ToolConstants.TOOL_OWNER)
- .menuPath(ToolConstants.MENU_HELP, "&Contents")
- .menuGroup(ToolConstants.HELP_CONTENTS_MENU_GROUP)
- .helpLocation(new HelpLocation("Misc", "Welcome_to_Ghidra_Help"))
- .inWindow(ActionBuilder.When.ALWAYS)
- .onAction(c -> help.showHelp(null, false, getToolFrame()))
- .buildAndInstall(this);
+ .menuPath(ToolConstants.MENU_HELP, "&Contents")
+ .menuGroup(ToolConstants.HELP_CONTENTS_MENU_GROUP)
+ .helpLocation(new HelpLocation("Misc", "Welcome_to_Ghidra_Help"))
+ .inWindow(ActionBuilder.When.ALWAYS)
+ .onAction(c -> help.showHelp(null, false, getToolFrame()))
+ .buildAndInstall(this);
}
/**
@@ -1151,7 +1144,7 @@ public abstract class PluginTool extends AbstractDockingTool {
* <LI>Running tasks. Closing with running tasks could lead to data loss.
* <LI>Plugins get asked if they can be closed. They may prompt the user to resolve
* some plugin specific state.
- * <LI>The user is prompted to save any data changes.
+ * <LI>The user is prompted to save any data changes.
* <LI>Tools are saved, possibly asking the user to resolve any conflicts caused by
* changing multiple instances of the same tool in different ways.
* <LI>If all the above conditions passed, the tool is closed and disposed.
@@ -1165,7 +1158,7 @@ public abstract class PluginTool extends AbstractDockingTool {
}
protected boolean canClose() {
- if (isBusy()) {
+ if (!canStopTasks()) {
return false;
}
if (!canClosePlugins()) {
@@ -1179,7 +1172,7 @@ public abstract class PluginTool extends AbstractDockingTool {
/**
* Normally, tools are not allowed to close while tasks are running in that tool as it
- * could leave the application in an unstable state. Tools that exit the application
+ * could leave the application in an unstable state. Tools that exit the application
* (such as the FrontEndTool) can override this so that the user can terminate running tasks
* and not have that prevent exiting the application.
* @return whether the user is allowed to terminate tasks so that the tool can be closed.
@@ -1199,20 +1192,29 @@ public abstract class PluginTool extends AbstractDockingTool {
/**
* Checks if this tool has running tasks, with optionally giving the user an
* opportunity to cancel them.
- *
+ *
* @return true if this tool has running tasks
*/
- protected boolean isBusy() {
- if (taskMgr.isBusy()) {
- int result = OptionDialog.showYesNoDialog(getToolFrame(), "Tool Busy Executing Task",
- "The tool is busy performing a background task.\n If you continue the" +
- " task may be terminated and some work may be lost!\n\nContinue anyway?");
- if (result != OptionDialog.YES_OPTION) {
- return true;
- }
- taskMgr.stop(false);
+ protected boolean canStopTasks() {
+ if (!taskMgr.isBusy()) {
+ return true;
}
- return false;
+
+ int result = OptionDialog.showYesNoDialog(getToolFrame(), "Tool Busy Executing Task",
+ "The tool is busy performing a background task.\n If you continue the" +
+ " task may be terminated and some work may be lost!\n\nContinue anyway?");
+ if (result != OptionDialog.YES_OPTION) {
+ return false;
+ }
+
+ Task task = new Task("Stopping Tasks", true, false, true) {
+ @Override
+ public void run(TaskMonitor monitor) throws CancelledException {
+ taskMgr.stop(monitor);
+ }
+ };
+ TaskLauncher.launch(task);
+ return !task.isCancelled();
}
/**
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginToolAccessUtils.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginToolAccessUtils.java
index 011a2ceac3..d08c83056e 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginToolAccessUtils.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginToolAccessUtils.java
@@ -42,7 +42,7 @@ public class PluginToolAccessUtils {
* @return true if the tool can be closed
*/
public static boolean canClose(PluginTool tool) {
- return !tool.isBusy() && tool.canClosePlugins();
+ return tool.canStopTasks() && tool.canClosePlugins();
}
}
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.java
index e9906c9c8e..f5ba6c13e4 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.java
@@ -271,30 +271,28 @@ public class ToolTaskManager implements Runnable {
}
/**
- * Cancel the currently running task and clear all commands that are
- * scheduled to run. Block until the currently running task ends.
+ * Cancel the currently running task and clear all commands that are scheduled to run. Block
+ * until the currently running task ends.
*
- * @param wait if true wait for current task to cancel cleanly
+ * @param monitor a monitor to cancel waiting for the task to finish
*/
- public void stop(boolean wait) {
+ public void stop(TaskMonitor monitor) {
- Thread oldTaskThread = null;
synchronized (this) {
if (isBusy()) {
toolTaskMonitor.cancel();
- oldTaskThread = taskThread;
}
if (currentTask != null) {
clearQueuedCommands(currentTask.getDomainObject());
}
}
- if (oldTaskThread != null && wait) {
+ while (taskThread != null && !monitor.isCancelled()) {
try {
- oldTaskThread.join();
+ Thread.sleep(100);
}
catch (InterruptedException e) {
- // guess we don't care?
+ // try again
}
}
}
@@ -522,6 +520,7 @@ public class ToolTaskManager implements Runnable {
* Clear list of tasks and queue of scheduled commands.
*/
public synchronized void dispose() {
+
clearTasks();
List<UndoableDomainObject> list = new ArrayList<>(queuedCommandsMap.keySet());
for (UndoableDomainObject obj : list) {