From 51e522934646c5c388a9e0be157ada793029ba2e Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Thu, 18 May 2023 11:54:49 -0400 Subject: [PATCH] GP-1528: Fix dynamic listing context / focus issue, now that GP-3349 is done. --- .../AbstractTraceDisassembleAction.java | 14 ++---- .../AbstractTracePatchInstructionAction.java | 6 +-- ...CurrentPlatformTraceDisassembleAction.java | 11 ++--- .../DebuggerDisassemblerPlugin.java | 16 +++---- .../DebuggerProgramLocationActionContext.java | 44 +++++++++++++++++++ .../DebuggerBreakpointMarkerPlugin.java | 12 ++--- .../copying/DebuggerCopyActionsPlugin.java | 39 ++++++---------- .../listing/DebuggerListingActionContext.java | 38 ++++++++++++++++ .../gui/listing/DebuggerListingPlugin.java | 16 ++++--- .../gui/listing/DebuggerListingProvider.java | 8 +++- ...emoryStateListingBackgroundColorModel.java | 4 +- .../DebuggerMemoryBytesActionContext.java | 34 ++++++++++++++ .../memory/DebuggerMemoryBytesProvider.java | 5 +++ .../debug/gui/time/DebuggerTimePlugin.java | 17 +++---- .../DebuggerEmulationServicePlugin.java | 6 +-- .../DebuggerLogicalBreakpointService.java | 3 +- .../ghidra/debug/flatapi/FlatDebuggerAPI.java | 4 +- .../core/codebrowser/CodeViewerProvider.java | 8 +++- .../ProgramByteViewerComponentProvider.java | 8 ++-- 19 files changed, 192 insertions(+), 101 deletions(-) create mode 100644 Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/action/DebuggerProgramLocationActionContext.java create mode 100644 Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingActionContext.java create mode 100644 Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesActionContext.java diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/AbstractTraceDisassembleAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/AbstractTraceDisassembleAction.java index e02d26ff3a..c000d8641e 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/AbstractTraceDisassembleAction.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/AbstractTraceDisassembleAction.java @@ -17,10 +17,9 @@ package ghidra.app.plugin.core.debug.disassemble; import docking.ActionContext; import docking.action.DockingAction; -import ghidra.app.context.ListingActionContext; +import ghidra.app.plugin.core.debug.gui.listing.DebuggerListingActionContext; import ghidra.program.model.address.*; import ghidra.program.model.lang.LanguageID; -import ghidra.program.model.listing.Program; import ghidra.program.util.ProgramSelection; import ghidra.trace.model.guest.TracePlatform; import ghidra.trace.model.program.TraceProgramView; @@ -41,15 +40,10 @@ public abstract class AbstractTraceDisassembleAction extends DockingAction { @Override public void actionPerformed(ActionContext context) { - if (!(context instanceof ListingActionContext)) { + if (!(context instanceof DebuggerListingActionContext lac)) { return; } - ListingActionContext lac = (ListingActionContext) context; - Program program = lac.getProgram(); - if (!(program instanceof TraceProgramView)) { - return; - } - TraceProgramView view = (TraceProgramView) program; + TraceProgramView view = lac.getProgram(); Address address = lac.getAddress(); AddressSpace space = address.getAddressSpace(); AddressSetView set; @@ -58,7 +52,7 @@ public abstract class AbstractTraceDisassembleAction extends DockingAction { set = selection; } else { - set = program.getAddressFactory() + set = view.getAddressFactory() .getAddressSet(space.getMinAddress(), space.getMaxAddress()); } TracePlatform platform = getPlatform(view); diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/AbstractTracePatchInstructionAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/AbstractTracePatchInstructionAction.java index 316ecca896..b9efb61aad 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/AbstractTracePatchInstructionAction.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/AbstractTracePatchInstructionAction.java @@ -24,7 +24,6 @@ import ghidra.app.plugin.core.assembler.PatchInstructionAction; import ghidra.program.model.address.*; import ghidra.program.model.lang.*; import ghidra.program.model.listing.CodeUnit; -import ghidra.program.model.listing.Program; import ghidra.program.model.mem.MemoryAccessException; import ghidra.program.util.DefaultLanguageService; import ghidra.trace.model.guest.TracePlatform; @@ -134,10 +133,9 @@ public abstract class AbstractTracePatchInstructionAction extends PatchInstructi } protected TraceProgramView getView() { - Program program = getProgram(); - if (!(program instanceof TraceProgramView)) { + if (!(getProgram() instanceof TraceProgramView view)) { return null; } - return (TraceProgramView) program; + return view; } } diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/CurrentPlatformTraceDisassembleAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/CurrentPlatformTraceDisassembleAction.java index 0d4b9482b3..53f68583cb 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/CurrentPlatformTraceDisassembleAction.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/CurrentPlatformTraceDisassembleAction.java @@ -20,11 +20,11 @@ import docking.action.*; import ghidra.app.context.ListingActionContext; import ghidra.app.plugin.core.debug.DebuggerCoordinates; import ghidra.app.plugin.core.debug.disassemble.DebuggerDisassemblerPlugin.Reqs; +import ghidra.app.plugin.core.debug.gui.listing.DebuggerListingActionContext; import ghidra.app.plugin.core.debug.mapping.DebuggerPlatformMapper; import ghidra.app.plugin.core.debug.mapping.DisassemblyResult; import ghidra.framework.cmd.TypedBackgroundCommand; import ghidra.program.model.address.*; -import ghidra.program.model.listing.Program; import ghidra.program.util.ProgramSelection; import ghidra.trace.model.Trace; import ghidra.trace.model.program.TraceProgramView; @@ -53,15 +53,10 @@ public class CurrentPlatformTraceDisassembleAction extends DockingAction { if (plugin.platformService == null) { return null; } - if (!(context instanceof ListingActionContext)) { + if (!(context instanceof DebuggerListingActionContext lac)) { return null; } - ListingActionContext lac = (ListingActionContext) context; - Program program = lac.getProgram(); - if (!(program instanceof TraceProgramView)) { - return null; - } - TraceProgramView view = (TraceProgramView) program; + TraceProgramView view = lac.getProgram(); Trace trace = view.getTrace(); DebuggerCoordinates current = plugin.traceManager == null ? DebuggerCoordinates.NOWHERE : plugin.traceManager.getCurrentFor(trace); diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/DebuggerDisassemblerPlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/DebuggerDisassemblerPlugin.java index 2ddc0b40b8..a6deeaf25d 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/DebuggerDisassemblerPlugin.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/disassemble/DebuggerDisassemblerPlugin.java @@ -22,9 +22,9 @@ import docking.Tool; import docking.action.DockingActionIf; import docking.actions.PopupActionProvider; import generic.jar.ResourceFile; -import ghidra.app.context.ListingActionContext; import ghidra.app.plugin.PluginCategoryNames; import ghidra.app.plugin.core.debug.DebuggerPluginPackage; +import ghidra.app.plugin.core.debug.gui.listing.DebuggerListingActionContext; import ghidra.app.plugin.core.debug.mapping.DebuggerPlatformMapper; import ghidra.app.services.DebuggerPlatformService; import ghidra.app.services.DebuggerTraceManagerService; @@ -34,7 +34,6 @@ import ghidra.framework.plugintool.annotation.AutoServiceConsumed; import ghidra.framework.plugintool.util.PluginStatus; import ghidra.program.model.address.Address; import ghidra.program.model.lang.*; -import ghidra.program.model.listing.Program; import ghidra.program.util.DefaultLanguageService; import ghidra.program.util.ProgramContextImpl; import ghidra.trace.model.Trace; @@ -209,23 +208,18 @@ public class DebuggerDisassemblerPlugin extends Plugin implements PopupActionPro @Override public List getPopupActions(Tool tool, ActionContext context) { - if (!(context instanceof ListingActionContext)) { - return null; - } /** * I could use Navigatable.isDynamic, but it seems more appropriate, since the types are in * scope here, to check for an actual trace. */ - ListingActionContext lac = (ListingActionContext) context; + if (!(context instanceof DebuggerListingActionContext lac)) { + return null; + } Address address = lac.getAddress(); if (address == null) { return null; } - Program program = lac.getProgram(); - if (!(program instanceof TraceProgramView)) { - return null; - } - TraceProgramView view = (TraceProgramView) program; + TraceProgramView view = lac.getProgram(); return getActionsFor(new ArrayList<>(), view.getTrace(), view.getSnap(), address); } } diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/action/DebuggerProgramLocationActionContext.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/action/DebuggerProgramLocationActionContext.java new file mode 100644 index 0000000000..23d8ec3503 --- /dev/null +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/action/DebuggerProgramLocationActionContext.java @@ -0,0 +1,44 @@ +/* ### + * 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.plugin.core.debug.gui.action; + +import docking.ActionContext; +import ghidra.program.model.address.Address; +import ghidra.program.model.listing.CodeUnit; +import ghidra.program.util.ProgramLocation; +import ghidra.program.util.ProgramSelection; +import ghidra.trace.model.program.TraceProgramView; + +public interface DebuggerProgramLocationActionContext extends ActionContext { + default TraceProgramView getProgram() { + ProgramLocation location = getLocation(); + return location == null ? null : (TraceProgramView) location.getProgram(); + } + + ProgramLocation getLocation(); + + boolean hasSelection(); + + ProgramSelection getSelection(); + + boolean hasHighlight(); + + ProgramSelection getHighlight(); + + Address getAddress(); + + CodeUnit getCodeUnit(); +} diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPlugin.java index 2099812c72..ddca50a4b5 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPlugin.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPlugin.java @@ -244,8 +244,7 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin return null; } Program progOrView = locs.get(0).getProgram(); - if (progOrView instanceof TraceProgramView) { - TraceProgramView view = (TraceProgramView) progOrView; + if (progOrView instanceof TraceProgramView view) { return view.getTrace(); } return null; @@ -498,8 +497,7 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin } protected static State computeState(LogicalBreakpoint breakpoint, Program programOrView) { - if (programOrView instanceof TraceProgramView) { - TraceProgramView view = (TraceProgramView) programOrView; + if (programOrView instanceof TraceProgramView view) { return breakpoint.computeStateForTrace(view.getTrace()); } // Program view should consider all trace placements @@ -975,8 +973,7 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin for (Map.Entry pEnt : markersByProgram.entrySet()) { Program program = pEnt.getKey(); BreakpointMarkerSets marks = pEnt.getValue(); - if (program instanceof TraceProgramView) { - TraceProgramView view = (TraceProgramView) program; + if (program instanceof TraceProgramView view) { Trace trace = view.getTrace(); doMarks(marks, breakpointService.getBreakpoints(trace), lb -> lb.computeStateForTrace(trace)); @@ -1071,10 +1068,9 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin } for (Map.Entry ent : copyOfMarkers.entrySet()) { Program program = ent.getKey(); - if (!(program instanceof TraceProgramView)) { + if (!(program instanceof TraceProgramView view)) { continue; } - TraceProgramView view = (TraceProgramView) program; if (view.getTrace() != trace) { continue; } diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/copying/DebuggerCopyActionsPlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/copying/DebuggerCopyActionsPlugin.java index 3a920f6c63..1cc6a9350d 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/copying/DebuggerCopyActionsPlugin.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/copying/DebuggerCopyActionsPlugin.java @@ -22,6 +22,7 @@ import ghidra.app.plugin.PluginCategoryNames; import ghidra.app.plugin.core.debug.AbstractDebuggerPlugin; import ghidra.app.plugin.core.debug.DebuggerPluginPackage; import ghidra.app.plugin.core.debug.gui.DebuggerResources.*; +import ghidra.app.plugin.core.debug.gui.action.DebuggerProgramLocationActionContext; import ghidra.app.plugin.core.exporter.ExporterDialog; import ghidra.app.services.*; import ghidra.framework.plugintool.PluginInfo; @@ -87,41 +88,29 @@ public class DebuggerCopyActionsPlugin extends AbstractDebuggerPlugin { protected void createActions() { actionExportView = ExportTraceViewAction.builder(this) .enabled(false) - .withContext(ProgramLocationActionContext.class) - .enabledWhen(this::checkTrace) + .withContext(DebuggerProgramLocationActionContext.class, true) .onAction(this::activatedExportView) .buildAndInstall(tool); // Using programManager here depends on it calling tool.updateContext() actionCopyIntoCurrentProgram = CopyIntoCurrentProgramAction.builder(this) .enabled(false) - .withContext(ProgramLocationActionContext.class) + .withContext(DebuggerProgramLocationActionContext.class, true) .enabledWhen( - ctx -> checkTraceSelection(ctx) && programManager.getCurrentProgram() != null) + ctx -> ctx.hasSelection() && programManager.getCurrentProgram() != null) .onAction(this::activatedCopyIntoCurrentProgram) .buildAndInstall(tool); actionCopyIntoNewProgram = CopyIntoNewProgramAction.builder(this) .enabled(false) - .withContext(ProgramLocationActionContext.class) - .enabledWhen(this::checkTraceSelection) + .withContext(DebuggerProgramLocationActionContext.class, true) + .enabledWhen(DebuggerProgramLocationActionContext::hasSelection) .onAction(this::activatedCopyIntoNewProgram) .buildAndInstall(tool); } - protected boolean checkTrace(ProgramLocationActionContext context) { - return context.getProgram() instanceof TraceProgramView; - } - - protected boolean checkTraceSelection(ProgramLocationActionContext context) { - return checkTrace(context) && context.hasSelection(); - } - - protected void activatedExportView(ProgramLocationActionContext context) { - if (!checkTrace(context)) { - return; - } - TraceProgramView view = (TraceProgramView) context.getProgram(); + protected void activatedExportView(DebuggerProgramLocationActionContext context) { + TraceProgramView view = context.getProgram(); // Avoid odd race conditions by fixing the snap TraceProgramView fixed = view instanceof TraceVariableSnapProgramView ? view.getTrace().getFixedProgramView(view.getSnap()) @@ -133,11 +122,11 @@ public class DebuggerCopyActionsPlugin extends AbstractDebuggerPlugin { tool.showDialog(dialog); } - protected void activatedCopyIntoCurrentProgram(ProgramLocationActionContext context) { - if (!checkTraceSelection(context)) { + protected void activatedCopyIntoCurrentProgram(DebuggerProgramLocationActionContext context) { + if (!context.hasSelection()) { return; } - copyDialog.setSource((TraceProgramView) context.getProgram(), context.getSelection()); + copyDialog.setSource(context.getProgram(), context.getSelection()); copyDialog.setProgramManager(programManager); copyDialog.setStaticMappingService(mappingService); copyDialog.setModelService(modelService); @@ -147,11 +136,11 @@ public class DebuggerCopyActionsPlugin extends AbstractDebuggerPlugin { tool.showDialog(copyDialog); } - protected void activatedCopyIntoNewProgram(ProgramLocationActionContext context) { - if (!checkTraceSelection(context)) { + protected void activatedCopyIntoNewProgram(DebuggerProgramLocationActionContext context) { + if (!context.hasSelection()) { return; } - copyDialog.setSource((TraceProgramView) context.getProgram(), context.getSelection()); + copyDialog.setSource(context.getProgram(), context.getSelection()); copyDialog.setProgramManager(programManager); copyDialog.setStaticMappingService(mappingService); copyDialog.setModelService(modelService); diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingActionContext.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingActionContext.java new file mode 100644 index 0000000000..e91688d37f --- /dev/null +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingActionContext.java @@ -0,0 +1,38 @@ +/* ### + * 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.plugin.core.debug.gui.listing; + +import ghidra.app.plugin.core.codebrowser.CodeViewerActionContext; +import ghidra.app.plugin.core.codebrowser.CodeViewerProvider; +import ghidra.app.plugin.core.debug.gui.action.DebuggerProgramLocationActionContext; +import ghidra.program.util.ProgramLocation; +import ghidra.trace.model.program.TraceProgramView; + +public class DebuggerListingActionContext extends CodeViewerActionContext + implements DebuggerProgramLocationActionContext { + public DebuggerListingActionContext(CodeViewerProvider provider) { + super(provider); + } + + public DebuggerListingActionContext(CodeViewerProvider provider, ProgramLocation location) { + super(provider, location); + } + + @Override + public TraceProgramView getProgram() { + return (TraceProgramView) super.getProgram(); + } +} diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingPlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingPlugin.java index 491ee98ce6..998f40b916 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingPlugin.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingPlugin.java @@ -33,8 +33,7 @@ import ghidra.app.plugin.core.debug.DebuggerCoordinates; import ghidra.app.plugin.core.debug.DebuggerPluginPackage; import ghidra.app.plugin.core.debug.event.*; import ghidra.app.plugin.core.debug.gui.DebuggerResources.AbstractNewListingAction; -import ghidra.app.plugin.core.debug.gui.action.LocationTrackingSpec; -import ghidra.app.plugin.core.debug.gui.action.NoneLocationTrackingSpec; +import ghidra.app.plugin.core.debug.gui.action.*; import ghidra.app.services.*; import ghidra.app.util.viewer.format.FormatManager; import ghidra.app.util.viewer.listingpanel.ListingPanel; @@ -79,7 +78,6 @@ import utilities.util.SuppressableCallback.Suppression; DebuggerStaticMappingService.class, // For static listing sync. TODO: Optional? DebuggerEmulationService.class, // TODO: Optional? ProgramManager.class, // For static listing sync - //GoToService.class, // For static listing sync ClipboardService.class, MarkerService.class // TODO: Make optional? }, @@ -118,8 +116,6 @@ public class DebuggerListingPlugin extends AbstractCodeBrowserPlugin contextGetTraceSnap(ActionContext context) { - if (context instanceof ProgramLocationActionContext) { - ProgramLocationActionContext ctx = (ProgramLocationActionContext) context; - Program program = ctx.getProgram(); - if (program instanceof TraceProgramView) { - TraceProgramView view = (TraceProgramView) program; - return Map.entry(view.getTrace(), view.getSnap()); - } - return null; + if (context instanceof DebuggerProgramLocationActionContext ctx) { + TraceProgramView view = ctx.getProgram(); + return Map.entry(view.getTrace(), view.getSnap()); } - if (context instanceof DebuggerSnapActionContext) { - DebuggerSnapActionContext ctx = (DebuggerSnapActionContext) context; + if (context instanceof DebuggerSnapActionContext ctx) { if (ctx.getTrace() != null) { return Map.entry(ctx.getTrace(), ctx.getSnap()); } diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePlugin.java index 9f0fcc0fc4..6527611d59 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePlugin.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePlugin.java @@ -472,8 +472,7 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm private boolean emulateAddThreadEnabled(ProgramLocationActionContext ctx) { Program programOrView = ctx.getProgram(); - if (programOrView instanceof TraceProgramView) { - TraceProgramView view = (TraceProgramView) programOrView; + if (programOrView instanceof TraceProgramView view) { if (!ProgramEmulationUtils.isEmulatedProgram(view.getTrace())) { return false; } @@ -503,8 +502,7 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm private void emulateAddThreadActivated(ProgramLocationActionContext ctx) { Program programOrView = ctx.getProgram(); - if (programOrView instanceof TraceProgramView) { - TraceProgramView view = (TraceProgramView) programOrView; + if (programOrView instanceof TraceProgramView view) { Trace trace = view.getTrace(); Address tracePc = ctx.getAddress(); diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/DebuggerLogicalBreakpointService.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/DebuggerLogicalBreakpointService.java index c82255606a..ddde74affe 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/DebuggerLogicalBreakpointService.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/DebuggerLogicalBreakpointService.java @@ -181,8 +181,7 @@ public interface DebuggerLogicalBreakpointService { BiFunction progFunc, BiFunction traceFunc) { Program progOrView = loc.getProgram(); - if (progOrView instanceof TraceProgramView) { - TraceProgramView view = (TraceProgramView) progOrView; + if (progOrView instanceof TraceProgramView view) { return traceFunc.apply(view.getTrace(), addressFromLocation(loc)); } return progFunc.apply(progOrView, addressFromLocation(loc)); diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java index 4ecc3296fe..8e2d55d58b 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java @@ -2581,8 +2581,8 @@ public interface FlatDebuggerAPI { */ default Trace getTrace(ProgramLocation location) { Program program = location.getProgram(); - if (program instanceof TraceProgramView) { - return ((TraceProgramView) program).getTrace(); + if (program instanceof TraceProgramView view) { + return view.getTrace(); } return null; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeViewerProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeViewerProvider.java index f28db45020..eccd6d4b6e 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeViewerProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeViewerProvider.java @@ -266,6 +266,10 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter return decorationPanel; } + protected CodeViewerActionContext newCodeViewerActionContext() { + return new CodeViewerActionContext(this); + } + @Override public ActionContext getActionContext(MouseEvent event) { if (program == null) { @@ -273,7 +277,7 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter } if (event == null) { - return new CodeViewerActionContext(this); + return newCodeViewerActionContext(); } Object source = event.getSource(); @@ -283,7 +287,7 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter if (programLocation == null) { return null; } - return new CodeViewerActionContext(this); + return newCodeViewerActionContext(); } FieldHeader headerPanel = listingPanel.getFieldHeader(); diff --git a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ProgramByteViewerComponentProvider.java b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ProgramByteViewerComponentProvider.java index 4f73d2cdbe..1f32637478 100644 --- a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ProgramByteViewerComponentProvider.java +++ b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ProgramByteViewerComponentProvider.java @@ -132,14 +132,14 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi @Override public ActionContext getActionContext(MouseEvent event) { - return getByteViewerActionContext(); - } - - ByteViewerActionContext getByteViewerActionContext() { ByteBlockInfo info = panel.getCursorLocation(); if (info == null) { return null; } + return newByteViewerActionContext(); + } + + protected ByteViewerActionContext newByteViewerActionContext() { return new ByteViewerActionContext(this); }