GP-1585: Change TargetBreakpointLocation to range, not address,length

This commit is contained in:
Dan 2022-09-12 09:01:55 -04:00
parent 6a2cd80550
commit cb16d8dd9e
23 changed files with 1143 additions and 1161 deletions

View file

@ -16,13 +16,13 @@
package agent.lldb.model.iface2;
import ghidra.dbg.target.TargetBreakpointLocation;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressRange;
public interface LldbModelTargetBreakpointLocation
extends LldbModelTargetObject, TargetBreakpointLocation {
@Override
public Address getAddress();
AddressRange getRange();
public int getLocationId();
}

View file

@ -25,7 +25,7 @@ import ghidra.dbg.target.TargetObject;
import ghidra.dbg.target.schema.TargetAttributeType;
import ghidra.dbg.target.schema.TargetObjectSchemaInfo;
import ghidra.dbg.util.PathUtils;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.*;
@TargetObjectSchemaInfo(
name = "BreakpointLocation",
@ -46,11 +46,9 @@ public class LldbModelTargetBreakpointLocationImpl extends LldbModelTargetObject
protected LldbModelTargetAbstractXpointSpec spec;
protected SBBreakpointLocation loc;
protected Address address;
protected Integer length;
protected AddressRange range;
protected String display;
public LldbModelTargetBreakpointLocationImpl(LldbModelTargetAbstractXpointSpec spec,
SBBreakpointLocation loc) {
super(spec.getModel(), spec, keyLocation(loc), loc, "BreakpointLocation");
@ -60,21 +58,28 @@ public class LldbModelTargetBreakpointLocationImpl extends LldbModelTargetObject
doChangeAttributes("Initialization");
}
// TODO: A separate class for Impl wrapping SBWatchpoint?
public LldbModelTargetBreakpointLocationImpl(LldbModelTargetAbstractXpointSpec spec,
SBWatchpoint wpt) {
super(spec.getModel(), spec, keyLocation(wpt), wpt, "BreakpointLocation");
this.loc = null;
address = getModel().getAddress("ram", wpt.GetWatchAddress().longValue());
Address address = getModel().getAddress("ram", wpt.GetWatchAddress().longValue());
long length = wpt.GetWatchSize();
this.changeAttributes(List.of(), Map.of(
SPEC_ATTRIBUTE_NAME, parent,
ADDRESS_ATTRIBUTE_NAME, address,
LENGTH_ATTRIBUTE_NAME, length = (int) wpt.GetWatchSize(),
RANGE_ATTRIBUTE_NAME, range = makeRange(address, length),
DISPLAY_ATTRIBUTE_NAME, display = getDescription(1)),
"Initialization");
placeLocations();
}
protected static AddressRange makeRange(Address min, long length) {
Address max = min.add(length - 1);
return new AddressRangeImpl(min, max);
}
@Override
public String getDescription(int level) {
Object modelObject = getModelObject();
SBStream stream = new SBStream();
@ -91,12 +96,10 @@ public class LldbModelTargetBreakpointLocationImpl extends LldbModelTargetObject
}
protected void doChangeAttributes(String reason) {
address = getModel().getAddress("ram", loc.GetLoadAddress().longValue());
length = 1;
Address address = getModel().getAddress("ram", loc.GetLoadAddress().longValue());
this.changeAttributes(List.of(), Map.of(
SPEC_ATTRIBUTE_NAME, parent,
ADDRESS_ATTRIBUTE_NAME, address,
LENGTH_ATTRIBUTE_NAME, length,
RANGE_ATTRIBUTE_NAME, range = new AddressRangeImpl(address, address),
DISPLAY_ATTRIBUTE_NAME, display = getDescription(1)),
reason);
placeLocations();
@ -104,7 +107,8 @@ public class LldbModelTargetBreakpointLocationImpl extends LldbModelTargetObject
protected void placeLocations() {
LldbModelTargetSession parentSession = getParentSession();
Map<String, ? extends TargetObject> cachedElements = parentSession.getProcesses().getCachedElements();
Map<String, ? extends TargetObject> cachedElements =
parentSession.getProcesses().getCachedElements();
for (TargetObject obj : cachedElements.values()) {
if (obj instanceof LldbModelTargetProcess) {
LldbModelTargetProcessImpl process = (LldbModelTargetProcessImpl) obj;
@ -123,21 +127,18 @@ public class LldbModelTargetBreakpointLocationImpl extends LldbModelTargetObject
TargetObject modelObject = getModel().getModelObject(getManager().getCurrentProcess());
if (modelObject instanceof LldbModelTargetProcess) {
LldbModelTargetProcess targetProcess = (LldbModelTargetProcess) modelObject;
LldbModelTargetBreakpointLocationContainer locs = (LldbModelTargetBreakpointLocationContainer) targetProcess.getCachedAttribute("Breakpoints");
LldbModelTargetBreakpointLocationContainer locs =
(LldbModelTargetBreakpointLocationContainer) targetProcess
.getCachedAttribute("Breakpoints");
locs.removeBreakpointLocation(this);
}
}
@Override
public Integer getLength() {
return length;
}
@Override
public Address getAddress() {
return address;
public AddressRange getRange() {
return range;
}
@Override
public int getLocationId() {
return loc.GetID();

View file

@ -56,6 +56,7 @@ public class LldbModelTargetBreakpointSpecImpl extends LldbModelTargetAbstractXp
super(breakpoints, info, "BreakpointSpec");
}
@Override
public String getDescription(int level) {
SBStream stream = new SBStream();
SBBreakpoint bpt = (SBBreakpoint) getModelObject();
@ -63,16 +64,17 @@ public class LldbModelTargetBreakpointSpecImpl extends LldbModelTargetAbstractXp
return stream.GetData();
}
@Override
protected TargetBreakpointKindSet computeKinds(Object from) {
if (from instanceof SBBreakpoint) {
SBBreakpoint bpt = (SBBreakpoint) from;
return bpt.IsHardware() ?
TargetBreakpointKindSet.of(TargetBreakpointKind.HW_EXECUTE) :
TargetBreakpointKindSet.of(TargetBreakpointKind.SW_EXECUTE);
return bpt.IsHardware() ? TargetBreakpointKindSet.of(TargetBreakpointKind.HW_EXECUTE)
: TargetBreakpointKindSet.of(TargetBreakpointKind.SW_EXECUTE);
}
return TargetBreakpointKindSet.of();
}
@Override
public void updateInfo(Object info, String reason) {
setModelObject(info);
updateAttributesFromInfo(reason);
@ -91,13 +93,14 @@ public class LldbModelTargetBreakpointSpecImpl extends LldbModelTargetAbstractXp
});
}
@Override
public void updateAttributesFromInfo(String reason) {
SBBreakpoint bpt = (SBBreakpoint) getModelObject();
String description = getDescription(1);
String[] split = description.split(",");
if (split[1].contains("regex")) {
expression = split[1];
expression = expression.substring(expression.indexOf("'")+1);
expression = expression.substring(expression.indexOf("'") + 1);
expression = expression.substring(0, expression.indexOf("'"));
}
this.changeAttributes(List.of(), List.of(), Map.of( //
@ -118,15 +121,17 @@ public class LldbModelTargetBreakpointSpecImpl extends LldbModelTargetAbstractXp
LldbModelTargetBreakpointLocationImpl loc =
(LldbModelTargetBreakpointLocationImpl) elements[0];
this.changeAttributes(List.of(), List.of(), Map.of( //
TargetBreakpointLocation.ADDRESS_ATTRIBUTE_NAME, loc.address //
TargetBreakpointLocation.RANGE_ATTRIBUTE_NAME, loc.range //
), reason);
}
}
@Override
public ListenerSet<TargetBreakpointAction> getActions() {
return actions;
}
@Override
public LldbModelTargetBreakpointLocation findLocation(Object obj) {
if (!(obj instanceof BigInteger)) {
return null;