Merge remote-tracking branch 'origin/patch'

This commit is contained in:
ghidra1 2021-12-21 15:39:28 -05:00
commit cfaa8b9032
5 changed files with 102 additions and 71 deletions

View file

@ -93,6 +93,9 @@ public interface LogicalBreakpointInternal extends LogicalBreakpoint {
@Override
public String toString() {
// volatile reads
Bookmark eBookmark = this.eBookmark;
Bookmark dBookmark = this.dBookmark;
if (eBookmark != null) {
return String.format("<enabled %s(%s) at %s in %s>", eBookmark.getTypeString(),
eBookmark.getCategory(), eBookmark.getAddress(), program.getName());
@ -127,6 +130,9 @@ public interface LogicalBreakpointInternal extends LogicalBreakpoint {
}
public void deleteFromProgram() {
// volatile reads
Bookmark eBookmark = this.eBookmark;
Bookmark dBookmark = this.dBookmark;
try (UndoableTransaction tid =
UndoableTransaction.start(program, "Clear breakpoint", false)) {
BookmarkManager bookmarkManager = program.getBookmarkManager();
@ -193,6 +199,7 @@ public interface LogicalBreakpointInternal extends LogicalBreakpoint {
}
public Bookmark getBookmark() {
Bookmark eBookmark = this.eBookmark;
if (eBookmark != null) {
return eBookmark;
}

View file

@ -81,6 +81,7 @@ public class DefaultTraceRecorder implements TraceRecorder {
public DefaultTraceRecorder(DebuggerModelServicePlugin plugin, Trace trace, TargetObject target,
DefaultDebuggerTargetTraceMapper mapper) {
trace.addConsumer(this);
this.plugin = plugin;
this.tool = plugin.getTool();
this.trace = trace;
@ -99,9 +100,6 @@ public class DefaultTraceRecorder implements TraceRecorder {
this.symbolRecorder = new DefaultSymbolRecorder(this);
this.timeRecorder = new DefaultTimeRecorder(this);
this.objectManager = new TraceObjectManager(target, mapper, this);
trace.addConsumer(this);
}
/*---------------- OBJECT MANAGER METHODS -------------------*/
@ -358,9 +356,14 @@ public class DefaultTraceRecorder implements TraceRecorder {
}
protected void invalidate() {
valid = false;
objectManager.disposeModelListeners();
trace.release(this);
synchronized (this) {
if (!valid) {
return;
}
valid = false;
trace.release(this);
}
}
/*---------------- FOCUS-SUPPORT METHODS -------------------*/

View file

@ -213,11 +213,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;
}
@ -389,31 +384,22 @@ public class DebuggerStaticMappingServicePlugin extends Plugin
return Collections.unmodifiableMap(result);
}
protected void openAndCollectPrograms(AddressRange rng, Range<Long> span,
Set<Program> result, Set<Exception> failures) {
protected void collectMappedProgramURLsInView(AddressRange rng, Range<Long> span,
Set<URL> result) {
TraceAddressSnapRange tatr = new ImmutableTraceAddressSnapRange(rng, span);
for (Entry<TraceAddressSnapRange, MappingEntry> 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<Program> openMappedProgramsInView(AddressSetView set, Range<Long> span,
Set<Exception> failures) {
Set<Program> result = new HashSet<>();
public Set<URL> getMappedProgramURLsInView(AddressSetView set, Range<Long> span) {
Set<URL> result = new HashSet<>();
for (AddressRange rng : set) {
openAndCollectPrograms(rng, span, result, failures);
collectMappedProgramURLsInView(rng, span, result);
}
return Collections.unmodifiableSet(result);
}
@ -847,20 +833,24 @@ public class DebuggerStaticMappingServicePlugin extends Plugin
@Override
public Set<Program> 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) {
@ -869,75 +859,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<TraceLocation> 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<Program, Collection<MappedAddressRange>> 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<TraceSnap, Collection<MappedAddressRange>> 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<Program> openMappedProgramsInView(Trace trace, AddressSetView set, long snap,
Set<Exception> failures) {
InfoPerTrace info = requireTrackedInfo(trace);
if (info == null) {
return null;
Set<URL> 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<Program> 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 Collection<? extends Program> orderCurrentFirst(

View file

@ -79,6 +79,7 @@ public interface UndoableTransaction extends AutoCloseable {
@Override
public void close() {
if (open) {
open = false;
endTransaction(commit);
}
}

View file

@ -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.
@ -16,6 +15,8 @@
*/
package ghidra.framework.data;
import java.util.*;
import ghidra.framework.model.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.util.Msg;
@ -23,8 +24,6 @@ import ghidra.util.SystemUtilities;
import ghidra.util.datastruct.WeakDataStructureFactory;
import ghidra.util.datastruct.WeakSet;
import java.util.*;
/**
* <code>DomainObjectDBTransaction</code> represents an atomic undoable operation performed
* on a single domain object.
@ -145,7 +144,7 @@ class DomainObjectDBTransaction implements Transaction {
try {
entry = list.get(transactionID - baseId);
}
catch (ArrayIndexOutOfBoundsException e) {
catch (IndexOutOfBoundsException e) {
throw new IllegalStateException("Transaction not found");
}
if (entry.status != NOT_DONE) {