diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java index 9a397b5d70..211261c0ed 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java @@ -411,11 +411,6 @@ public class DebuggerStaticMappingServicePlugin extends Plugin return new AddressRangeImpl(min, max); } - public Program openStaticProgram() { - return ProgramURLUtils.openHackedUpGhidraURL(programManager, tool.getProject(), - mapping.getStaticProgramURL(), ProgramManager.OPEN_VISIBLE); - } - public boolean isStaticProgramOpen() { return program != null; } @@ -587,31 +582,22 @@ public class DebuggerStaticMappingServicePlugin extends Plugin return Collections.unmodifiableMap(result); } - protected void openAndCollectPrograms(AddressRange rng, Range span, - Set result, Set failures) { + protected void collectMappedProgramURLsInView(AddressRange rng, Range span, + Set result) { TraceAddressSnapRange tatr = new ImmutableTraceAddressSnapRange(rng, span); for (Entry out : outbound.entrySet()) { if (!out.getKey().intersects(tatr)) { continue; } MappingEntry me = out.getValue(); - try { - result.add(me.openStaticProgram()); - } - catch (Exception e) { - if (failures == null) { - throw e; - } - failures.add(e); - } + result.add(me.getStaticProgramURL()); } } - public Set openMappedProgramsInView(AddressSetView set, Range span, - Set failures) { - Set result = new HashSet<>(); + public Set getMappedProgramURLsInView(AddressSetView set, Range span) { + Set result = new HashSet<>(); for (AddressRange rng : set) { - openAndCollectPrograms(rng, span, result, failures); + collectMappedProgramURLsInView(rng, span, result); } return Collections.unmodifiableSet(result); } @@ -1154,20 +1140,24 @@ public class DebuggerStaticMappingServicePlugin extends Plugin @Override public Set getOpenMappedProgramsAtSnap(Trace trace, long snap) { - InfoPerTrace info = requireTrackedInfo(trace); - if (info == null) { - return null; + synchronized (lock) { + InfoPerTrace info = requireTrackedInfo(trace); + if (info == null) { + return null; + } + return info.getOpenMappedProgramsAtSnap(snap); } - return info.getOpenMappedProgramsAtSnap(snap); } @Override public ProgramLocation getOpenMappedLocation(TraceLocation loc) { - InfoPerTrace info = requireTrackedInfo(loc.getTrace()); - if (info == null) { - return null; + synchronized (lock) { + InfoPerTrace info = requireTrackedInfo(loc.getTrace()); + if (info == null) { + return null; + } + return info.getOpenMappedLocations(loc.getAddress(), loc.getLifespan()); } - return info.getOpenMappedLocations(loc.getAddress(), loc.getLifespan()); } protected long getNonScratchSnap(TraceProgramView view) { @@ -1176,75 +1166,106 @@ public class DebuggerStaticMappingServicePlugin extends Plugin @Override public ProgramLocation getStaticLocationFromDynamic(ProgramLocation loc) { - loc = ProgramLocationUtils.fixLocation(loc, true); - TraceProgramView view = (TraceProgramView) loc.getProgram(); - Trace trace = view.getTrace(); - TraceLocation tloc = new DefaultTraceLocation(trace, null, - Range.singleton(getNonScratchSnap(view)), loc.getByteAddress()); - ProgramLocation mapped = getOpenMappedLocation(tloc); - if (mapped == null) { - return null; + synchronized (lock) { + loc = ProgramLocationUtils.fixLocation(loc, true); + TraceProgramView view = (TraceProgramView) loc.getProgram(); + Trace trace = view.getTrace(); + TraceLocation tloc = new DefaultTraceLocation(trace, null, + Range.singleton(getNonScratchSnap(view)), loc.getByteAddress()); + ProgramLocation mapped = getOpenMappedLocation(tloc); + if (mapped == null) { + return null; + } + return ProgramLocationUtils.replaceAddress(loc, mapped.getProgram(), + mapped.getByteAddress()); } - return ProgramLocationUtils.replaceAddress(loc, mapped.getProgram(), - mapped.getByteAddress()); } @Override public Set getOpenMappedLocations(ProgramLocation loc) { - InfoPerProgram info = requireTrackedInfo(loc.getProgram()); - if (info == null) { - return null; + synchronized (lock) { + InfoPerProgram info = requireTrackedInfo(loc.getProgram()); + if (info == null) { + return null; + } + return info.getOpenMappedTraceLocations(loc.getByteAddress()); } - return info.getOpenMappedTraceLocations(loc.getByteAddress()); } @Override public TraceLocation getOpenMappedLocation(Trace trace, ProgramLocation loc, long snap) { - InfoPerProgram info = requireTrackedInfo(loc.getProgram()); - if (info == null) { - return null; + synchronized (lock) { + InfoPerProgram info = requireTrackedInfo(loc.getProgram()); + if (info == null) { + return null; + } + return info.getOpenMappedTraceLocation(trace, loc.getByteAddress(), snap); } - return info.getOpenMappedTraceLocation(trace, loc.getByteAddress(), snap); } @Override public ProgramLocation getDynamicLocationFromStatic(TraceProgramView view, ProgramLocation loc) { - TraceLocation tloc = getOpenMappedLocation(view.getTrace(), loc, getNonScratchSnap(view)); - if (tloc == null) { - return null; + synchronized (lock) { + TraceLocation tloc = + getOpenMappedLocation(view.getTrace(), loc, getNonScratchSnap(view)); + if (tloc == null) { + return null; + } + return ProgramLocationUtils.replaceAddress(loc, view, tloc.getAddress()); } - return ProgramLocationUtils.replaceAddress(loc, view, tloc.getAddress()); } @Override public Map> getOpenMappedViews(Trace trace, AddressSetView set, long snap) { - InfoPerTrace info = requireTrackedInfo(trace); - if (info == null) { - return null; + synchronized (lock) { + InfoPerTrace info = requireTrackedInfo(trace); + if (info == null) { + return null; + } + return info.getOpenMappedViews(set, Range.singleton(snap)); } - return info.getOpenMappedViews(set, Range.singleton(snap)); } @Override public Map> getOpenMappedViews(Program program, AddressSetView set) { - InfoPerProgram info = requireTrackedInfo(program); - if (info == null) { - return null; + synchronized (lock) { + InfoPerProgram info = requireTrackedInfo(program); + if (info == null) { + return null; + } + return info.getOpenMappedViews(set); } - return info.getOpenMappedViews(set); } @Override public Set openMappedProgramsInView(Trace trace, AddressSetView set, long snap, Set failures) { - InfoPerTrace info = requireTrackedInfo(trace); - if (info == null) { - return null; + Set urls; + synchronized (lock) { + InfoPerTrace info = requireTrackedInfo(trace); + if (info == null) { + return null; + } + urls = info.getMappedProgramURLsInView(set, Range.singleton(snap)); } - return info.openMappedProgramsInView(set, Range.singleton(snap), failures); + Set result = new HashSet<>(); + for (URL url : urls) { + try { + Program program = ProgramURLUtils.openHackedUpGhidraURL(programManager, + tool.getProject(), url, ProgramManager.OPEN_VISIBLE); + result.add(program); + } + catch (Exception e) { + if (failures == null) { + throw e; + } + failures.add(e); + } + } + return result; } protected String normalizePath(String path) {