Ghidra is a software reverse engineering (SRE) framework
Merge remote-tracking branch 'origin/Ghidra_10.1'
Ryan Kurtz737fe4a04bd3
diff --cc Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProvider.javaindex ffbb098f5e,c2c28e659e..c03fe58b3e--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProvider.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProvider.java@@@ -382,95 -341,11 +383,98 @@@ public class DebuggerRegionsProvider ex.enabledWhen(ctx -> currentTrace != null).onAction(this::activatedSelectCurrent).buildAndInstallLocal(this);--+ actionForceFullView = ForceFullViewAction.builder(plugin)+ .enabledWhen(ctx -> currentTrace != null)+ .onAction(this::activatedForceFullView)+ .buildAndInstallLocal(this);+ contextChanged();+ }++ private boolean isContextNonEmpty(DebuggerRegionActionContext ctx) {+ return !ctx.getSelectedRegions().isEmpty();+ }++ private static Set<TraceMemoryRegion> getSelectedRegions(DebuggerRegionActionContext ctx) {+ if (ctx == null) {+ return null;+ }+ return ctx.getSelectedRegions()+ .stream()+ .map(r -> r.getRegion())+ .collect(Collectors.toSet());+ }++ private void activatedMapRegions(DebuggerRegionActionContext ignored) {+ mapRegions(getSelectedRegions(myActionContext));+ }++ private void activatedMapRegionsTo(DebuggerRegionActionContext ignored) {+ Set<TraceMemoryRegion> sel = getSelectedRegions(myActionContext);+ if (sel == null || sel.isEmpty()) {+ return;+ }+ mapRegionsTo(sel);+ }++ private void activatedMapRegionTo(DebuggerRegionActionContext ignored) {+ Set<TraceMemoryRegion> sel = getSelectedRegions(myActionContext);+ if (sel == null || sel.size() != 1) {+ return;+ }+ mapRegionTo(sel.iterator().next());+ }++ protected void promptRegionProposal(Collection<RegionMapEntry> proposal) {+ if (proposal.isEmpty()) {+ Msg.showInfo(this, getComponent(), "Map Regions",+ "Could not formulate a propsal for any selection region." ++ " You may need to import and/or open the destination images first.");+ return;+ }+ Collection<RegionMapEntry> adjusted =+ regionProposalDialog.adjustCollection(getTool(), proposal);+ if (adjusted == null || staticMappingService == null) {+ return;+ }+ tool.executeBackgroundCommand(+ new MapRegionsBackgroundCommand(staticMappingService, adjusted), currentTrace);+ }++ protected void mapRegions(Set<TraceMemoryRegion> regions) {+ if (staticMappingService == null) {+ return;+ }+ Map<?, RegionMapProposal> map = staticMappingService.proposeRegionMaps(regions,+ List.of(programManager.getAllOpenPrograms()));+ Collection<RegionMapEntry> proposal = MapProposal.flatten(map.values());+ promptRegionProposal(proposal);+ }++ protected void mapRegionsTo(Set<TraceMemoryRegion> regions) {+ if (staticMappingService == null) {+ return;+ }+ Program program = currentProgram;+ if (program == null) {+ return;+ }+ RegionMapProposal map = staticMappingService.proposeRegionMap(regions, program);+ Collection<RegionMapEntry> proposal = map.computeMap().values();+ promptRegionProposal(proposal);+ }++ protected void mapRegionTo(TraceMemoryRegion region) {+ if (staticMappingService == null) {+ return;+ }+ ProgramLocation location = currentLocation;+ MemoryBlock block = computeBlock(location);+ if (block == null) {+ return;+ }+ RegionMapProposal map =+ staticMappingService.proposeRegionMap(region, location.getProgram(), block);+ promptRegionProposal(map.computeMap().values());}private void activatedSelectCurrent(ActionContext ignored) {diff --cc Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/pcode/DebuggerPcodeStepperProviderTest.javaindex dc995b1f92,0000000000..0ee6ae2dadmode 100644,000000..100644--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/pcode/DebuggerPcodeStepperProviderTest.java+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/pcode/DebuggerPcodeStepperProviderTest.java@@@ -1,122 -1,0 +1,122 @@@+/* ###+ * 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.pcode;++import static org.junit.Assert.*;++import org.junit.Before;+import org.junit.Test;++import com.google.common.collect.Range;++import ghidra.app.plugin.assembler.Assembler;+import ghidra.app.plugin.assembler.Assemblers;+import ghidra.app.plugin.core.debug.gui.AbstractGhidraHeadedDebuggerGUITest;+import ghidra.app.plugin.core.debug.gui.listing.DebuggerListingPlugin;+import ghidra.app.plugin.core.debug.service.emulation.DebuggerTracePcodeEmulator;+import ghidra.app.plugin.core.debug.service.tracemgr.DebuggerTraceManagerServicePlugin;+import ghidra.app.services.DebuggerEmulationService;+import ghidra.app.services.DebuggerTraceManagerService;+import ghidra.pcode.emu.PcodeThread;+import ghidra.pcode.exec.PcodeExecutor;+import ghidra.pcode.exec.trace.TraceSleighUtils;+import ghidra.program.model.address.Address;+import ghidra.program.model.listing.Instruction;+import ghidra.program.model.listing.InstructionIterator;+import ghidra.trace.model.memory.TraceMemoryFlag;+import ghidra.trace.model.thread.TraceThread;- import ghidra.trace.model.time.TraceSchedule;++import ghidra.trace.model.time.schedule.TraceSchedule;+import ghidra.util.database.UndoableTransaction;++public class DebuggerPcodeStepperProviderTest extends AbstractGhidraHeadedDebuggerGUITest {++ protected DebuggerTraceManagerService traceManager;+ protected DebuggerPcodeStepperPlugin pcodePlugin;+ protected DebuggerListingPlugin listingPlugin;++ protected DebuggerPcodeStepperProvider pcodeProvider;+ protected DebuggerEmulationService emuService;++ @Before+ public void setUpPcodeStepperProviderTest() throws Exception {+ traceManager = addPlugin(tool, DebuggerTraceManagerServicePlugin.class);+ pcodePlugin = addPlugin(tool, DebuggerPcodeStepperPlugin.class);+ listingPlugin = addPlugin(tool, DebuggerListingPlugin.class); // For colors+ emuService = tool.getService(DebuggerEmulationService.class);++ pcodeProvider = waitForComponentProvider(DebuggerPcodeStepperProvider.class);++ createTrace();+ }++ @Test+ public void testCustomUseropDisplay() throws Exception {+ Address start = tb.addr(0x00400000);+ TraceThread thread;+ InstructionIterator iit;+ try (UndoableTransaction tid = tb.startTransaction()) {+ tb.trace.getMemoryManager()+ .addRegion("echo:.text", Range.atLeast(0L), tb.range(0x00400000, 0x0040ffff),+ TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE);++ thread = tb.getOrAddThread("1", 0);++ PcodeExecutor<byte[]> init = TraceSleighUtils.buildByteExecutor(tb.trace, 0, thread, 0);+ init.executeLine("pc = 0x00400000");++ Assembler asm = Assemblers.getAssembler(tb.trace.getFixedProgramView(0));+ iit = asm.assemble(start,+ "imm r0, #1234",+ "imm r1, #2045"); // 11 bits unsigned++ }+ Instruction imm1234 = iit.next();+ Instruction imm2045 = iit.next();++ TraceSchedule schedule1 = TraceSchedule.parse("0:.t0-1");+ traceManager.openTrace(tb.trace);+ traceManager.activateThread(thread);+ traceManager.activateTime(schedule1);++ DebuggerTracePcodeEmulator emu =+ waitForValue(() -> emuService.getCachedEmulator(tb.trace, schedule1));+ assertNotNull(emu);++ // P-code step to decode already done. One for each op. One to retire.+ TraceSchedule schedule2 =+ schedule1.steppedPcodeForward(thread, imm1234.getPcode().length + 1);+ PcodeThread<byte[]> et = emu.getThread(thread.getPath(), false);+ traceManager.activateTime(schedule2);+ waitForPass(() -> assertNull(et.getFrame()));++ /**+ * NB. at the moment, there is no API to customize the service's emulator. In the meantime,+ * the vanilla PcodeThread does inject a custom library for breakpoints, so we'll use that+ * as our "custom userop" test case. It might also be nice if the emulator service placed+ * breakpoints, no?+ */+ emu.addBreakpoint(imm2045.getAddress(), "1:1");++ // Just one to decode is necessary+ TraceSchedule schedule3 = schedule2.steppedPcodeForward(thread, 1);+ traceManager.activateTime(schedule3);+ waitForPass(() -> assertEquals(schedule3, pcodeProvider.current.getTime()));++ assertTrue(pcodeProvider.pcodeTableModel.getModelData()+ .stream()+ .anyMatch(r -> r.getCode().contains("emu_swi")));+ }+}