Skip to content

Commit

Permalink
GP-4236: Implement new columns: PC, Func, Mod, SP. Remove: Created, D…
Browse files Browse the repository at this point in the history
…estroyed
  • Loading branch information
nsadeveloper789 committed Feb 22, 2024
1 parent f5008f9 commit 270fb01
Show file tree
Hide file tree
Showing 24 changed files with 316 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package ghidra.debug.api.action;

import java.util.concurrent.CompletableFuture;

import ghidra.debug.api.tracemgr.DebuggerCoordinates;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address;
import ghidra.program.util.ProgramLocation;
import ghidra.trace.model.TraceAddressSnapRange;
Expand Down Expand Up @@ -47,21 +45,21 @@ public interface LocationTracker {
* The address returned must be in the host platform's language, i.e., please use
* {@link TracePlatform#mapGuestToHost(Address)}.
*
* @param tool the tool containing the provider
* @param provider the service provider (usually the tool)
* @param coordinates the trace, thread, snap, etc., of the tool
* @return the address to navigate to
*/
Address computeTraceAddress(PluginTool tool, DebuggerCoordinates coordinates);
Address computeTraceAddress(ServiceProvider provider, DebuggerCoordinates coordinates);

/**
* Get the suggested input if the user activates "Go To" while this tracker is active
*
* @param tool the tool containing the provider
* @param provider the service provider (usually the tool)
* @param coordinates the user's current coordinates
* @param location the user's current location
* @return the suggested address or Sleigh expression
*/
GoToInput getDefaultGoToInput(PluginTool tool, DebuggerCoordinates coordinates,
GoToInput getDefaultGoToInput(ServiceProvider provider, DebuggerCoordinates coordinates,
ProgramLocation location);

// TODO: Is there a way to generalize these so that other dependencies need not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static boolean changeIsCurrent(TraceAddressSpace space, TraceAddressSnapRange ra
/**
* Compute a title prefix to indicate this tracking specification
*
* @param thread the provider's current thread
* @param coordinates the current coordinates
* @return a prefix, or {@code null} to use a default
*/
String computeTitle(DebuggerCoordinates coordinates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import ghidra.app.plugin.core.debug.gui.DebuggerResources.TrackLocationAction;
import ghidra.debug.api.action.*;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address;
import ghidra.program.util.ProgramLocation;
import ghidra.trace.model.TraceAddressSnapRange;
Expand Down Expand Up @@ -63,12 +63,12 @@ public LocationTracker getTracker() {
}

@Override
public Address computeTraceAddress(PluginTool tool, DebuggerCoordinates coordinates) {
public Address computeTraceAddress(ServiceProvider provider, DebuggerCoordinates coordinates) {
return null;
}

@Override
public GoToInput getDefaultGoToInput(PluginTool tool, DebuggerCoordinates coordinates,
public GoToInput getDefaultGoToInput(ServiceProvider provider, DebuggerCoordinates coordinates,
ProgramLocation location) {
if (location == null) {
return GoToInput.fromString("00000000");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import ghidra.app.plugin.core.debug.gui.DebuggerResources.TrackLocationAction;
import ghidra.debug.api.action.*;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address;
import ghidra.program.util.ProgramLocation;
import ghidra.trace.model.Trace;
Expand Down Expand Up @@ -66,9 +66,12 @@ public LocationTracker getTracker() {
}

@Override
public Address computeTraceAddress(PluginTool tool, DebuggerCoordinates coordinates) {
public Address computeTraceAddress(ServiceProvider provider, DebuggerCoordinates coordinates) {
Trace trace = coordinates.getTrace();
TraceThread thread = coordinates.getThread();
if (thread == null) {
return null;
}
long snap = coordinates.getSnap();
TraceStack stack = trace.getStackManager().getLatestStack(thread, snap);
if (stack == null) {
Expand All @@ -83,11 +86,11 @@ public Address computeTraceAddress(PluginTool tool, DebuggerCoordinates coordina
}

@Override
public GoToInput getDefaultGoToInput(PluginTool tool, DebuggerCoordinates coordinates,
public GoToInput getDefaultGoToInput(ServiceProvider provider, DebuggerCoordinates coordinates,
ProgramLocation location) {
Address address = computeTraceAddress(tool, coordinates);
Address address = computeTraceAddress(provider, coordinates);
if (address == null) {
return NoneLocationTrackingSpec.INSTANCE.getDefaultGoToInput(tool, coordinates,
return NoneLocationTrackingSpec.INSTANCE.getDefaultGoToInput(provider, coordinates,
location);
}
return GoToInput.fromAddress(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import ghidra.app.plugin.core.debug.gui.DebuggerResources.TrackLocationAction;
import ghidra.debug.api.action.*;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address;
import ghidra.program.util.ProgramLocation;
import ghidra.trace.model.TraceAddressSnapRange;
Expand Down Expand Up @@ -68,20 +68,20 @@ public LocationTracker getTracker() {
}

@Override
public Address computeTraceAddress(PluginTool tool, DebuggerCoordinates coordinates) {
public Address computeTraceAddress(ServiceProvider provider, DebuggerCoordinates coordinates) {
if (coordinates.getTime().isSnapOnly()) {
Address pc = BY_STACK.computeTraceAddress(tool, coordinates);
Address pc = BY_STACK.computeTraceAddress(provider, coordinates);
if (pc != null) {
return pc;
}
}
return BY_REG.computeTraceAddress(tool, coordinates);
return BY_REG.computeTraceAddress(provider, coordinates);
}

@Override
public GoToInput getDefaultGoToInput(PluginTool tool, DebuggerCoordinates coordinates,
public GoToInput getDefaultGoToInput(ServiceProvider provider, DebuggerCoordinates coordinates,
ProgramLocation location) {
return BY_REG.getDefaultGoToInput(tool, coordinates, location);
return BY_REG.getDefaultGoToInput(provider, coordinates, location);
}

// Note it does no good to override affectByRegChange. It must do what we'd avoid anyway.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import ghidra.debug.api.action.*;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.*;
import ghidra.program.model.lang.Register;
import ghidra.program.model.lang.RegisterValue;
Expand Down Expand Up @@ -51,10 +51,13 @@ default LocationTracker getTracker() {
}

@Override
default Address computeTraceAddress(PluginTool tool, DebuggerCoordinates coordinates) {
default Address computeTraceAddress(ServiceProvider provider, DebuggerCoordinates coordinates) {
Trace trace = coordinates.getTrace();
TracePlatform platform = coordinates.getPlatform();
TraceThread thread = coordinates.getThread();
if (thread == null) {
return null;
}
long viewSnap = coordinates.getViewSnap();
long snap = coordinates.getSnap();
int frame = coordinates.getFrame();
Expand Down Expand Up @@ -88,7 +91,7 @@ default Address computeTraceAddress(PluginTool tool, DebuggerCoordinates coordin
}

@Override
default GoToInput getDefaultGoToInput(PluginTool tool, DebuggerCoordinates coordinates,
default GoToInput getDefaultGoToInput(ServiceProvider provider, DebuggerCoordinates coordinates,
ProgramLocation location) {
Register register = computeRegister(coordinates);
return GoToInput.offsetOnly(register.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import ghidra.debug.api.action.*;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
import ghidra.debug.api.watch.WatchRow;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.pcode.exec.*;
import ghidra.pcode.exec.DebuggerPcodeUtils.WatchValue;
import ghidra.pcode.exec.SleighUtils.AddressOf;
Expand Down Expand Up @@ -117,32 +117,33 @@ class WatchLocationTracker implements LocationTracker {
private PcodeExpression compiled;

@Override
public Address computeTraceAddress(PluginTool tool, DebuggerCoordinates coordinates) {
public Address computeTraceAddress(ServiceProvider provider,
DebuggerCoordinates coordinates) {
if (!Objects.equals(current, coordinates) || exec == null) {
current = coordinates;
exec = current.getPlatform() == null ? null
: DebuggerPcodeUtils.buildWatchExecutor(tool, coordinates);
: DebuggerPcodeUtils.buildWatchExecutor(provider, coordinates);
}
else {
exec.getState().clear();
}
if (current.getTrace() == null) {
return null;
}
compiled = DebuggerPcodeUtils.compileExpression(tool, current, expression);
compiled = DebuggerPcodeUtils.compileExpression(provider, current, expression);
WatchValue value = compiled.evaluate(exec);
return value == null ? null : value.address();
}

@Override
public GoToInput getDefaultGoToInput(PluginTool tool, DebuggerCoordinates coordinates,
ProgramLocation location) {
public GoToInput getDefaultGoToInput(ServiceProvider provider,
DebuggerCoordinates coordinates, ProgramLocation location) {
TracePlatform platform = current.getPlatform();
String defaultSpace =
platform == null ? "ram" : platform.getLanguage().getDefaultSpace().getName();
AddressOf addrOf = SleighUtils.recoverAddressOf(defaultSpace, expression);
if (addrOf == null) {
return NoneLocationTrackingSpec.INSTANCE.getDefaultGoToInput(tool, coordinates,
return NoneLocationTrackingSpec.INSTANCE.getDefaultGoToInput(provider, coordinates,
location);
}
return new GoToInput(addrOf.space(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public Component getTableCellRendererComponent(GTableCellRenderingData data) {
super.getTableCellRendererComponent(data);
@SuppressWarnings("unchecked")
ValueProperty<T> p = (ValueProperty<T>) data.getValue();
if (p == null) {
setText("");
setToolTipText("");
return this;
}
setText(p.getHtmlDisplay());
setToolTipText(p.getToolTip());
setForeground(getForegroundFor(data.getTable(), p.isModified(), data.isSelected()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,8 @@ public void setName(String name) {
}
}

public static String computeShortName(String path) {
int sep = path.lastIndexOf('\\');
if (sep > 0 && sep < path.length()) {
path = path.substring(sep + 1);
}
sep = path.lastIndexOf('/');
if (sep > 0 && sep < path.length()) {
path = path.substring(sep + 1);
}
return path;
}

public String getShortName() {
return computeShortName(module.getName());
return DebuggerStaticMappingUtils.computeModuleShortName(module.getName());
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import ghidra.app.plugin.core.debug.gui.model.ObjectTableModel.ValueRow;
import ghidra.app.plugin.core.debug.gui.model.columns.TraceValueKeyColumn;
import ghidra.app.plugin.core.debug.gui.model.columns.TraceValueObjectAttributeColumn;
import ghidra.app.plugin.core.debug.service.modules.DebuggerStaticMappingUtils;
import ghidra.app.services.DebuggerTraceManagerService;
import ghidra.dbg.target.TargetStack;
import ghidra.dbg.target.TargetStackFrame;
Expand All @@ -40,7 +41,6 @@
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
import ghidra.trace.model.Trace;
import ghidra.trace.model.modules.TraceModule;
import ghidra.trace.model.stack.TraceObjectStackFrame;
import ghidra.trace.model.target.TraceObject;
import ghidra.trace.model.target.TraceObjectValue;
Expand Down Expand Up @@ -84,7 +84,8 @@ public Function getValue(ValueRow rowObject, Settings settings, Trace data,
ServiceProvider serviceProvider) throws IllegalArgumentException {
TraceObjectValue value =
rowObject.getAttributeEntry(TargetStackFrame.PC_ATTRIBUTE_NAME);
return value == null ? null : provider.getFunction(value.castValue());
return DebuggerStaticMappingUtils.getFunction(value.castValue(), provider.current,
serviceProvider);
}
}

Expand All @@ -99,7 +100,7 @@ public String getValue(ValueRow rowObject, Settings settings, Trace data,
ServiceProvider serviceProvider) throws IllegalArgumentException {
TraceObjectValue value =
rowObject.getAttributeEntry(TargetStackFrame.PC_ATTRIBUTE_NAME);
return value == null ? null : provider.getModule(value.castValue());
return DebuggerStaticMappingUtils.getModuleName(value.castValue(), provider.current);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@
import docking.action.builder.ActionBuilder;
import ghidra.app.plugin.core.debug.DebuggerPluginPackage;
import ghidra.app.plugin.core.debug.gui.DebuggerResources;
import ghidra.app.plugin.core.debug.gui.modules.ModuleRow;
import ghidra.app.plugin.core.debug.stack.UnwindStackCommand;
import ghidra.app.services.DebuggerStaticMappingService;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.annotation.AutoServiceConsumed;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
import ghidra.program.util.ProgramLocation;
import ghidra.trace.model.*;
import ghidra.trace.model.modules.TraceModule;
import ghidra.trace.model.Trace;
import ghidra.trace.model.thread.TraceThread;
import ghidra.util.HelpLocation;

Expand Down Expand Up @@ -192,39 +187,4 @@ public void traceClosed(Trace trace) {
legacyPanel.coordinatesActivated(DebuggerCoordinates.NOWHERE);
}
}

public Function getFunction(Address pc) {
if (pc == null) {
return null;
}
if (mappingService == null) {
return null;
}
TraceThread curThread = current.getThread();
if (curThread == null) {
return null;
}
TraceLocation dloc = new DefaultTraceLocation(curThread.getTrace(),
curThread, Lifespan.at(current.getSnap()), pc);
ProgramLocation sloc = mappingService.getOpenMappedLocation(dloc);
if (sloc == null) {
return null;
}
return sloc.getProgram().getFunctionManager().getFunctionContaining(sloc.getAddress());
}

public String getModule(Address pc) {
if (pc == null) {
return null;
}
Trace trace = current.getTrace();
if (trace == null) {
return null;
}
for (TraceModule module : trace.getModuleManager().getModulesAt(current.getSnap(), pc)) {
// Just take the first
return ModuleRow.computeShortName(module.getName());
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package ghidra.app.plugin.core.debug.gui.stack;

import db.Transaction;
import ghidra.app.plugin.core.debug.service.modules.DebuggerStaticMappingUtils;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
import ghidra.trace.model.stack.TraceStackFrame;
Expand Down Expand Up @@ -84,11 +85,12 @@ public boolean isCommentable() {
}

public Function getFunction() {
return panel.provider.getFunction(getProgramCounter());
return DebuggerStaticMappingUtils.getFunction(getProgramCounter(), panel.current,
panel.provider.getTool());
}

public String getModule() {
return panel.provider.getModule(getProgramCounter());
return DebuggerStaticMappingUtils.getModuleName(getProgramCounter(), panel.current);
}

protected void update() {
Expand Down
Loading

0 comments on commit 270fb01

Please sign in to comment.