GP-1474: Display emulator's decoded instruction in PcodeStepper

This commit is contained in:
Dan
2022-01-05 10:17:25 -05:00
parent f5f3b0338c
commit 2a4df2af92
4 changed files with 35 additions and 1 deletions

View File

@@ -52,6 +52,7 @@ import ghidra.pcode.exec.PcodeExecutorState;
import ghidra.pcode.exec.PcodeFrame; import ghidra.pcode.exec.PcodeFrame;
import ghidra.program.model.data.DataType; import ghidra.program.model.data.DataType;
import ghidra.program.model.lang.Language; import ghidra.program.model.lang.Language;
import ghidra.program.model.listing.Instruction;
import ghidra.program.model.pcode.PcodeOp; import ghidra.program.model.pcode.PcodeOp;
import ghidra.program.model.pcode.Varnode; import ghidra.program.model.pcode.Varnode;
import ghidra.trace.model.Trace; import ghidra.trace.model.Trace;
@@ -347,10 +348,11 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
GhidraTable uniqueTable; GhidraTable uniqueTable;
UniqueTableModel uniqueTableModel = new UniqueTableModel(); UniqueTableModel uniqueTableModel = new UniqueTableModel();
private GhidraTableFilterPanel<UniqueRow> uniqueFilterPanel; GhidraTableFilterPanel<UniqueRow> uniqueFilterPanel;
GhidraTable pcodeTable; GhidraTable pcodeTable;
PcodeTableModel pcodeTableModel = new PcodeTableModel(); PcodeTableModel pcodeTableModel = new PcodeTableModel();
JLabel instructionLabel;
// No filter panel on p-code // No filter panel on p-code
DockingAction actionStepBackward; DockingAction actionStepBackward;
@@ -457,6 +459,8 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
JPanel pcodePanel = new JPanel(new BorderLayout()); JPanel pcodePanel = new JPanel(new BorderLayout());
pcodeTable = new GhidraTable(pcodeTableModel); pcodeTable = new GhidraTable(pcodeTableModel);
pcodePanel.add(new JScrollPane(pcodeTable)); pcodePanel.add(new JScrollPane(pcodeTable));
instructionLabel = new JLabel();
pcodePanel.add(instructionLabel, BorderLayout.NORTH);
mainPanel.setLeftComponent(pcodePanel); mainPanel.setLeftComponent(pcodePanel);
JPanel uniquePanel = new JPanel(new BorderLayout()); JPanel uniquePanel = new JPanel(new BorderLayout());
@@ -620,6 +624,9 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
} }
protected void doLoadPcodeFrame() { protected void doLoadPcodeFrame() {
if (instructionLabel != null) {
instructionLabel.setText("(no instruction)");
}
if (emulationService == null) { if (emulationService == null) {
return; return;
} }
@@ -660,6 +667,13 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter {
populateSingleton(EnumPcodeRow.DECODE); populateSingleton(EnumPcodeRow.DECODE);
return; return;
} }
Instruction instruction = thread.getInstruction();
if (instruction == null) {
instructionLabel.setText("(no instruction)");
}
else {
instructionLabel.setText(instruction.toString());
}
PcodeFrame frame = thread.getFrame(); PcodeFrame frame = thread.getFrame();
if (frame == null) { if (frame == null) {
/** /**

View File

@@ -28,6 +28,7 @@ import ghidra.pcode.emu.*;
import ghidra.pcode.exec.*; import ghidra.pcode.exec.*;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.lang.*; import ghidra.program.model.lang.*;
import ghidra.program.model.listing.Instruction;
import ghidra.test.AbstractGhidraHeadlessIntegrationTest; import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
import ghidra.test.ToyProgramBuilder; import ghidra.test.ToyProgramBuilder;
import ghidra.trace.database.ToyDBTraceBuilder; import ghidra.trace.database.ToyDBTraceBuilder;
@@ -333,6 +334,11 @@ public class TraceScheduleTest extends AbstractGhidraHeadlessIntegrationTest {
public PcodeFrame getFrame() { public PcodeFrame getFrame() {
return null; return null;
} }
@Override
public Instruction getInstruction() {
return null;
}
@Override @Override
public void executeInstruction() { public void executeInstruction() {

View File

@@ -284,6 +284,7 @@ public class DefaultPcodeThread<T> implements PcodeThread<T> {
} }
postExecuteInstruction(); postExecuteInstruction();
frame = null; frame = null;
instruction = null;
} }
@Override @Override
@@ -291,6 +292,11 @@ public class DefaultPcodeThread<T> implements PcodeThread<T> {
return frame; return frame;
} }
@Override
public Instruction getInstruction() {
return instruction;
}
protected void assertCompletedInstruction() { protected void assertCompletedInstruction() {
if (frame != null) { if (frame != null) {
throw new IllegalStateException("The current instruction or inject has not finished."); throw new IllegalStateException("The current instruction or inject has not finished.");

View File

@@ -22,6 +22,7 @@ import ghidra.pcode.emu.DefaultPcodeThread.SleighEmulationLibrary;
import ghidra.pcode.exec.*; import ghidra.pcode.exec.*;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.lang.RegisterValue; import ghidra.program.model.lang.RegisterValue;
import ghidra.program.model.listing.Instruction;
/** /**
* An emulated thread of execution * An emulated thread of execution
@@ -157,6 +158,13 @@ public interface PcodeThread<T> {
*/ */
PcodeFrame getFrame(); PcodeFrame getFrame();
/**
* Get the current decoded instruction, if applicable
*
* @return the instruction
*/
Instruction getInstruction();
/** /**
* Execute the next instruction, ignoring injects * Execute the next instruction, ignoring injects
* *