Merge remote-tracking branch 'origin/GP-4159' into Ghidra_11.0

This commit is contained in:
ghidra1 2023-12-19 15:21:12 -05:00
commit 719373e327
6 changed files with 21 additions and 104 deletions

View File

@ -18,16 +18,11 @@ package ghidra.app.events;
import java.lang.ref.WeakReference;
import ghidra.framework.plugintool.PluginEvent;
import ghidra.framework.plugintool.ToolEventName;
import ghidra.program.model.listing.Program;
/**
* Event for telling a tool to open a program
* <p>
* This event shares a common tool-event name with the {@link OpenProgramPluginEvent}
* so that they have a single shared tool connection.
* Event for telling a tool to close a program
*/
@ToolEventName(OpenProgramPluginEvent.TOOL_EVENT_NAME) // this allows the event to be considered for tool connection
public class CloseProgramPluginEvent extends PluginEvent {
static final String NAME = "Close Program";

View File

@ -1,76 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.app.events;
import ghidra.framework.plugintool.PluginEvent;
import ghidra.framework.plugintool.ToolEventName;
import ghidra.program.model.listing.Program;
import ghidra.program.util.ProgramLocation;
/**
* This plugin event class provides program location information for
* plugins that send information to two or more tools containing associated addresses.
*/
@ToolEventName(DualProgramLocationPluginEvent.NAME) // this allows the event to be considered for tool connection
public final class DualProgramLocationPluginEvent extends PluginEvent {
/**
* Name of this plugin event.
*/
public static final String NAME = "DualProgramLocation";
private ProgramLocation loc;
private String programName;
/**
* Construct a new DualProgramLocationPluginEvent.
* @param src the name of the plugin that generated this event.
* @param loc the ProgramLocation object that contains the new location.
* @param programName the name of the program for which the loc object refers.
*/
public DualProgramLocationPluginEvent(String src, ProgramLocation loc, String programName) {
super(src, NAME);
this.loc = loc;
this.programName = programName;
}
/**
* Construct a new DualProgramLocationPluginEvent.
* @param src the name of the plugin that generated this event.
* @param loc the ProgramLocation object that contains the new location.
* @param program the program for which the loc object refers.
*/
public DualProgramLocationPluginEvent(String src, ProgramLocation loc, Program program) {
super(src, NAME);
this.loc = loc;
this.programName = program.getName();
}
/**
* Returns the ProgramLocation stored in this event.
*/
public ProgramLocation getLocation() {
return loc;
}
/**
* Returns the Program object that the location refers to.
*/
public String getProgramName() {
return programName;
}
}

View File

@ -18,20 +18,14 @@ package ghidra.app.events;
import java.lang.ref.WeakReference;
import ghidra.framework.plugintool.PluginEvent;
import ghidra.framework.plugintool.ToolEventName;
import ghidra.program.model.listing.Program;
/**
* Event for telling a tool to open a program
* <p>
* This event shares a common tool-event name with the {@link OpenProgramPluginEvent}
* so that they have a single shared tool connection.
*/
@ToolEventName(OpenProgramPluginEvent.TOOL_EVENT_NAME) // this allows the event to be considered for tool connection
public class OpenProgramPluginEvent extends PluginEvent {
static final String NAME = "Open Program";
static final String TOOL_EVENT_NAME = "Open/Close Program";
private WeakReference<Program> programRef;

View File

@ -20,7 +20,7 @@ import java.util.HashMap;
import java.util.Map;
import ghidra.framework.data.DomainObjectFileListener;
import ghidra.framework.model.DomainObject;
import ghidra.framework.model.*;
import ghidra.program.model.listing.Program;
import ghidra.util.timer.GTimerCache;
@ -66,6 +66,7 @@ class ProgramCache extends GTimerCache<ProgramLocator, Program> {
program.addConsumer(this);
ProgramFileListener listener = new ProgramFileListener(key);
program.addDomainFileListener(listener);
program.addListener(listener);
listenerMap.put(program, listener);
}
@ -73,9 +74,10 @@ class ProgramCache extends GTimerCache<ProgramLocator, Program> {
protected void valueRemoved(ProgramLocator locator, Program program) {
// whenever programs are removed from the cache, we need to remove the cache as a consumer
// and remove the file changed listener
program.release(this);
ProgramFileListener listener = listenerMap.remove(program);
program.removeDomainFileListener(listener);
program.removeListener(listener);
program.release(this);
}
@Override
@ -92,9 +94,11 @@ class ProgramCache extends GTimerCache<ProgramLocator, Program> {
* DomainObjectFileListener for programs in the cache. If a program instance has its DomainFile
* changed (e.g., 'Save As' action), then the cache mapping is incorrect as it sill has the
* program instance associated with its old DomainFile. So we need to add a listener to
* recognize when this occurs. If it does, we simply remove the entry from the cache.
* recognize when this occurs. If it does, we simply remove the entry from the cache. Also,
* we need to remove any programs from the cache if changes are made to avoid questions about
* who is responsible for saving changed programs that only live in the cache.
*/
class ProgramFileListener implements DomainObjectFileListener {
class ProgramFileListener implements DomainObjectFileListener, DomainObjectListener {
private ProgramLocator key;
ProgramFileListener(ProgramLocator key) {
@ -105,6 +109,10 @@ class ProgramCache extends GTimerCache<ProgramLocator, Program> {
public void domainFileChanged(DomainObject object) {
remove(key);
}
}
@Override
public void domainObjectChanged(DomainObjectChangedEvent ev) {
remove(key);
}
}
}

View File

@ -341,6 +341,7 @@ public class ProgramManagerPlugin extends Plugin implements ProgramManager, Opti
@Override
public void dispose() {
programCache.clear();
programMgr.dispose();
tool.clearLastEvents();
}

View File

@ -66,8 +66,7 @@ class ProgramSaveManager {
* the user
*/
boolean canClose(Program program) {
if (program == null ||
(program.getDomainFile().getConsumers().size() > 1 && !tool.hasToolListeners())) {
if (!isOnlyToolConsumer(program)) {
return true;
}
if (acquireSaveLock(program, "Close")) {
@ -105,9 +104,7 @@ class ProgramSaveManager {
return saveChangedPrograms(saveList);
}
finally {
Iterator<Program> it = lockList.iterator();
while (it.hasNext()) {
Program p = it.next();
for (Program p : lockList) {
p.unlock();
}
}
@ -378,10 +375,9 @@ class ProgramSaveManager {
"The Program is currently being modified by the following actions/tasks:\n ");
TransactionInfo t = program.getCurrentTransactionInfo();
List<String> list = t.getOpenSubTransactions();
Iterator<String> it = list.iterator();
while (it.hasNext()) {
for (String element : list) {
buf.append("\n ");
buf.append(it.next());
buf.append(element);
}
buf.append("\n \n");
buf.append("WARNING! The above task(s) should be cancelled before attempting a " +
@ -412,10 +408,9 @@ class ProgramSaveManager {
"The Program is currently being modified by the following actions/tasks:\n ");
TransactionInfo t = program.getCurrentTransactionInfo();
List<String> list = t.getOpenSubTransactions();
Iterator<String> it = list.iterator();
while (it.hasNext()) {
for (String element : list) {
buf.append("\n ");
buf.append(it.next());
buf.append(element);
}
buf.append("\n \n");
buf.append(