diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/pcode/DebuggerPcodeStepperProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/pcode/DebuggerPcodeStepperProvider.java index 4c7112d028..57e85b7ed1 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/pcode/DebuggerPcodeStepperProvider.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/pcode/DebuggerPcodeStepperProvider.java @@ -28,8 +28,6 @@ import java.util.stream.Collectors; import javax.swing.*; import javax.swing.table.*; -import org.apache.commons.lang3.StringUtils; - import db.Transaction; import docking.action.DockingAction; import docking.widgets.table.*; @@ -61,8 +59,7 @@ import ghidra.program.model.pcode.PcodeOp; import ghidra.program.model.pcode.Varnode; import ghidra.trace.model.Trace; import ghidra.trace.model.time.schedule.TraceSchedule; -import ghidra.util.ColorUtils; -import ghidra.util.HTMLUtilities; +import ghidra.util.*; import ghidra.util.table.GhidraTable; import ghidra.util.table.GhidraTableFilterPanel; import ghidra.util.table.column.AbstractGColumnRenderer; @@ -71,23 +68,16 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { private static final FontRenderContext METRIC_FRC = new FontRenderContext(new AffineTransform(), false, false); - private static final Color COLOR_BACKGROUND = - new GColor("color.bg.listing"); - private static final Color COLOR_BACKGROUND_CURSOR = - new GColor("color.bg.currentline.listing"); + private static final Color COLOR_BACKGROUND = new GColor("color.bg.listing"); + private static final Color COLOR_BACKGROUND_CURSOR = new GColor("color.bg.currentline.listing"); private static final Color COLOR_BACKGROUND_COUNTER = new GColor("color.debugger.plugin.resources.pcode.counter"); - private static final Color COLOR_FOREGROUND_ADDRESS = - new GColor("color.fg.listing.address"); - private static final Color COLOR_FOREGROUND_REGISTER = - new GColor("color.fg.listing.register"); - private static final Color COLOR_FOREGROUND_SCALAR = - new GColor("color.fg.listing.constant"); - private static final Color COLOR_FOREGROUND_LOCAL = - new GColor("color.fg.listing.label.local"); - private static final Color COLOR_FOREGROUND_MNEMONIC = - new GColor("color.fg.listing.mnemonic"); + private static final Color COLOR_FOREGROUND_ADDRESS = new GColor("color.fg.listing.address"); + private static final Color COLOR_FOREGROUND_REGISTER = new GColor("color.fg.listing.register"); + private static final Color COLOR_FOREGROUND_SCALAR = new GColor("color.fg.listing.constant"); + private static final Color COLOR_FOREGROUND_LOCAL = new GColor("color.fg.listing.label.local"); + private static final Color COLOR_FOREGROUND_MNEMONIC = new GColor("color.fg.listing.mnemonic"); private static final Color COLOR_FOREGROUND_UNIMPL = new GColor("color.fg.listing.mnemonic.unimplemented"); private static final Color COLOR_FOREGROUND_SEPARATOR = @@ -96,23 +86,10 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { new GColor("color.fg.listing.pcode.label"); private static final Color COLOR_FOREGROUND_SPACE = new GColor("color.fg.listing.pcode.address.space"); - private static final Color COLOR_FOREGROUND_RAW = - new GColor("color.fg.listing.pcode.varnode"); + private static final Color COLOR_FOREGROUND_RAW = new GColor("color.fg.listing.pcode.varnode"); private static final Color COLOR_FOREGROUND_USEROP = new GColor("color.fg.listing.pcode.userop"); - private static final String SPAN_ADDRESS = "addr"; - private static final String SPAN_REGISTER = "reg"; - private static final String SPAN_SCALAR = "scalar"; - private static final String SPAN_LOCAL = "loc"; - private static final String SPAN_MNEMONIC = "op"; - private static final String SPAN_UNIMPL = "unimpl"; - private static final String SPAN_SEPARATOR = "sep"; - private static final String SPAN_LINE_LABEL = "lab"; - private static final String SPAN_SPACE = "space"; - private static final String SPAN_RAW = "raw"; - private static final String SPAN_USEROP = "usr"; - protected static final Comparator UNIQUE_COMPARATOR = (u1, u2) -> { assert u1.isUnique() && u2.isUnique(); return u1.getAddress().compareTo(u2.getAddress()); @@ -241,8 +218,7 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { if (dataType == null) { return null; } - try (Transaction tid = - current.getTrace().openTransaction("Resolve DataType")) { + try (Transaction tid = current.getTrace().openTransaction("Resolve DataType")) { return current.getTrace().getDataTypeManager().resolve(dataType, null); } } @@ -296,17 +272,11 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { @Override public Component getTableCellRendererComponent(GTableCellRenderingData data) { super.getTableCellRendererComponent(data); - setText(injectStyle(getText())); + Object value = data.getValue(); + String text = getText(value); + setText(text); return this; } - - String injectStyle(String html) { - if (StringUtils.startsWithIgnoreCase(html, "")) { - String style = computeStyle(); - return style + html.substring("".length()); - } - return html; - } } class UniqueRefCellRenderer extends AbstractGColumnRenderer { @@ -339,8 +309,8 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { } } - protected static String htmlSpan(String cls, String display) { - return String.format("%s", cls, + protected static String htmlColor(Color color, String display) { + return String.format("%s", WebColors.toString(color), HTMLUtilities.escapeHTML(display)); } @@ -391,83 +361,87 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { @Override public void appendAddressWordOffcut(long wordOffset, long offcut) { - codeHtml.append(htmlSpan(SPAN_ADDRESS, stringifyWordOffcut(wordOffset, offcut))); + codeHtml.append( + htmlColor(COLOR_FOREGROUND_ADDRESS, stringifyWordOffcut(wordOffset, offcut))); } @Override public void appendCharacter(char c) { if (c == '=') { codeHtml.append(" "); - codeHtml.append(htmlSpan(SPAN_SEPARATOR, "=")); + codeHtml.append(htmlColor(COLOR_FOREGROUND_SEPARATOR, "=")); codeHtml.append(" "); } else if (c == ' ') { codeHtml.append(" "); } else { - codeHtml.append(htmlSpan(SPAN_SEPARATOR, Character.toString(c))); + codeHtml.append(htmlColor(COLOR_FOREGROUND_SEPARATOR, Character.toString(c))); } } @Override public void appendIndent() { + // stub } @Override public void appendLabel(String label) { - codeHtml.append(htmlSpan(SPAN_LOCAL, label)); + codeHtml.append(htmlColor(COLOR_FOREGROUND_LOCAL, label)); } @Override public void appendLineLabel(long label) { hasLabel = true; - labelHtml.append(htmlSpan(SPAN_LINE_LABEL, stringifyLineLabel(label))); + labelHtml.append(htmlColor(COLOR_FOREGROUND_LINE_LABEL, stringifyLineLabel(label))); } @Override public void appendLineLabelRef(long label) { - codeHtml.append(htmlSpan(SPAN_LINE_LABEL, stringifyLineLabel(label))); + codeHtml.append(htmlColor(COLOR_FOREGROUND_LINE_LABEL, stringifyLineLabel(label))); } @Override public void appendMnemonic(int opcode) { - String style = opcode == PcodeOp.UNIMPLEMENTED ? SPAN_UNIMPL : SPAN_MNEMONIC; - codeHtml.append(htmlSpan(style, stringifyOpMnemonic(opcode))); + Color style = opcode == PcodeOp.UNIMPLEMENTED ? COLOR_FOREGROUND_UNIMPL + : COLOR_FOREGROUND_MNEMONIC; + codeHtml.append(htmlColor(style, stringifyOpMnemonic(opcode))); } @Override public void appendRawVarnode(AddressSpace space, long offset, long size) { - codeHtml.append(htmlSpan(SPAN_RAW, stringifyRawVarnode(space, offset, size))); + codeHtml.append( + htmlColor(COLOR_FOREGROUND_RAW, stringifyRawVarnode(space, offset, size))); } @Override public void appendRegister(Register register) { - codeHtml.append(htmlSpan(SPAN_REGISTER, stringifyRegister(register))); + codeHtml.append(htmlColor(COLOR_FOREGROUND_REGISTER, stringifyRegister(register))); } @Override public void appendScalar(long value) { - codeHtml.append(htmlSpan(SPAN_SCALAR, stringifyScalarValue(value))); + codeHtml.append(htmlColor(COLOR_FOREGROUND_SCALAR, stringifyScalarValue(value))); } @Override public void appendSpace(AddressSpace space) { - codeHtml.append(htmlSpan(SPAN_SPACE, stringifySpace(space))); + codeHtml.append(htmlColor(COLOR_FOREGROUND_SPACE, stringifySpace(space))); } @Override public void appendUnique(long offset) { - codeHtml.append(htmlSpan(SPAN_LOCAL, stringifyUnique(offset))); + codeHtml.append(htmlColor(COLOR_FOREGROUND_LOCAL, stringifyUnique(offset))); } @Override public void appendUserop(int id) { - codeHtml.append(htmlSpan(SPAN_USEROP, stringifyUserop(language, id))); + codeHtml.append(htmlColor(COLOR_FOREGROUND_USEROP, stringifyUserop(language, id))); } @Override - protected String stringifyUseropUnchecked(Language language, int id) { - String name = super.stringifyUseropUnchecked(language, id); + protected String stringifyUseropUnchecked(Language lang, int id) { + String name = super.stringifyUseropUnchecked(lang, id); if (name != null) { return name; } @@ -507,8 +481,8 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { } @Override - protected ToPcodeRowsAppender createAppender(Language language, boolean indent) { - return new ToPcodeRowsAppender(language, frame); + protected ToPcodeRowsAppender createAppender(Language lang, boolean indent) { + return new ToPcodeRowsAppender(lang, frame); } @Override @@ -598,23 +572,6 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { contextChanged(); } - protected String computeStyle() { - StringBuilder sb = new StringBuilder(""); // NB. should already be at end - return sb.toString(); - } - protected int measureColWidth(JLabel renderer, String sample) { Font font = renderer.getFont(); Insets insets = renderer.getBorder().getBorderInsets(renderer); @@ -636,9 +593,9 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { pcodeTable.setBackground(COLOR_BACKGROUND); pcodeTable.setSelectionBackground(COLOR_BACKGROUND_CURSOR); - JScrollPane pcodeScrollPane = new JScrollPane(pcodeTablePanel, - ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, - ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + JScrollPane pcodeScrollPane = + new JScrollPane(pcodeTablePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); JPanel pcodePanel = new JPanel(new BorderLayout()); pcodePanel.add(pcodeScrollPane, BorderLayout.CENTER); @@ -706,8 +663,7 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { .onAction(c -> stepBackwardActivated()) .buildAndInstallLocal(this); actionStepForward = DebuggerResources.EmulatePcodeForwardAction.builder(plugin) - .enabledWhen( - c -> current.getThread() != null) + .enabledWhen(c -> current.getThread() != null) .onAction(c -> stepForwardActivated()) .buildAndInstallLocal(this); } @@ -814,10 +770,9 @@ public class DebuggerPcodeStepperProvider extends ComponentProviderAdapter { // TODO: Highlight uniques that the selected op(s) reference // (including overlaps) // TODO: Permit modification of unique variables - List toAdd = - uniques.stream() - .map(u -> new UniqueRow(this, language, state, arithmetic, u)) - .collect(Collectors.toList()); + List toAdd = uniques.stream() + .map(u -> new UniqueRow(this, language, state, arithmetic, u)) + .collect(Collectors.toList()); uniqueTableModel.addAll(toAdd); }