diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/DebuggerLocationLabel.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/DebuggerLocationLabel.java index 3d6bc97ab6..5336bce079 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/DebuggerLocationLabel.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/DebuggerLocationLabel.java @@ -199,5 +199,6 @@ public class DebuggerLocationLabel extends JLabel { public void updateLabel() { String label = computeLocationString(); setText(label); + setToolTipText(label); } } diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProvider.java index 6ca658c6a8..68ab43afd7 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProvider.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProvider.java @@ -17,8 +17,8 @@ package ghidra.app.plugin.core.debug.gui.listing; import static ghidra.app.plugin.core.debug.gui.DebuggerResources.ICON_REGISTER_MARKER; -import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Dimension; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.lang.invoke.MethodHandles; @@ -26,8 +26,8 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.swing.Box; import javax.swing.JLabel; -import javax.swing.JPanel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -210,6 +210,7 @@ public class DebuggerListingProvider extends CodeViewerProvider { protected void specChanged(LocationTrackingSpec spec) { updateTitle(); trackingLabel.setText(""); + trackingLabel.setToolTipText(""); trackingLabel.setForeground(Colors.FOREGROUND); trackingSpecChangeListeners.fire.locationTrackingSpecChanged(spec); } @@ -335,9 +336,11 @@ public class DebuggerListingProvider extends CodeViewerProvider { addDisplayListener(readsMemTrait.getDisplayListener()); - JPanel northPanel = new JPanel(new BorderLayout()); - northPanel.add(locationLabel, BorderLayout.WEST); - northPanel.add(trackingLabel, BorderLayout.EAST); + Box northPanel = Box.createHorizontalBox(); + northPanel.add(locationLabel); + locationLabel.setMinimumSize(new Dimension(0, 0)); + northPanel.add(Box.createGlue()); + northPanel.add(trackingLabel); this.setNorthComponent(northPanel); if (isConnected) { setTitle(DebuggerResources.TITLE_PROVIDER_LISTING); @@ -1066,7 +1069,9 @@ public class DebuggerListingProvider extends CodeViewerProvider { } protected void goToAndUpdateTrackingLabel(TraceProgramView curView, ProgramLocation loc) { - trackingLabel.setText(trackingTrait.computeLabelText()); + String labelText = trackingTrait.computeLabelText(); + trackingLabel.setText(labelText); + trackingLabel.setToolTipText(labelText); if (goTo(curView, loc)) { trackingLabel.setForeground(Colors.FOREGROUND); } diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java index 1b2ea7e9b6..afcc606f25 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java @@ -16,14 +16,14 @@ package ghidra.app.plugin.core.debug.gui.memory; import java.awt.BorderLayout; +import java.awt.Dimension; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.lang.invoke.MethodHandles; import java.math.BigInteger; import java.util.*; -import javax.swing.JLabel; -import javax.swing.JPanel; +import javax.swing.*; import org.apache.commons.lang3.StringUtils; @@ -133,6 +133,7 @@ public class DebuggerMemoryBytesProvider extends ProgramByteViewerComponentProvi protected void specChanged(LocationTrackingSpec spec) { updateTitle(); trackingLabel.setText(""); + trackingLabel.setToolTipText(""); trackingLabel.setForeground(Colors.FOREGROUND); } } @@ -206,9 +207,11 @@ public class DebuggerMemoryBytesProvider extends ProgramByteViewerComponentProvi createActions(); addDisplayListener(readsMemTrait.getDisplayListener()); - JPanel northPanel = new JPanel(new BorderLayout()); - northPanel.add(locationLabel, BorderLayout.WEST); - northPanel.add(trackingLabel, BorderLayout.EAST); + Box northPanel = Box.createHorizontalBox(); + northPanel.add(locationLabel); + locationLabel.setMinimumSize(new Dimension(0, 0)); + northPanel.add(Box.createGlue()); + northPanel.add(trackingLabel); decorationComponent.add(northPanel, BorderLayout.NORTH); goToTrait.goToCoordinates(current); @@ -479,7 +482,9 @@ public class DebuggerMemoryBytesProvider extends ProgramByteViewerComponentProvi } protected void goToAndUpdateTrackingLabel(TraceProgramView curView, ProgramLocation loc) { - trackingLabel.setText(trackingTrait.computeLabelText()); + String labelText = trackingTrait.computeLabelText(); + trackingLabel.setText(labelText); + trackingLabel.setToolTipText(labelText); if (goTo(curView, loc)) { trackingLabel.setForeground(Colors.FOREGROUND); } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/EnumDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/EnumDB.java index 5d32fcd8b1..4e27dbe53c 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/EnumDB.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/EnumDB.java @@ -112,12 +112,16 @@ class EnumDB extends DataTypeDB implements Enum { long minValue = valueMap.firstKey(); long maxValue = valueMap.lastKey(); + if (maxValue > getMaxPossibleValue(length, true)) { + if (minValue < 0) { + return INVALID; + } + return UNSIGNED; + } + if (minValue < 0) { return SIGNED; } - if (maxValue > getMaxPossibleValue(length, true)) { - return UNSIGNED; - } return NONE; // we have no negatives and no large unsigned values } @@ -874,6 +878,19 @@ class EnumDB extends DataTypeDB implements Enum { } } + @Override + public EnumSignedState getSignedState() { + lock.acquire(); + try { + checkIsValid(); + initializeIfNeeded(); + return signedState; + } + finally { + lock.release(); + } + } + @Override public int getMinimumPossibleLength() { lock.acquire(); diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/EnumSignedState.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/EnumSignedState.java index d0f9838caa..28bb405dfb 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/EnumSignedState.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/EnumSignedState.java @@ -18,13 +18,14 @@ package ghidra.program.database.data; /** * Keeps track of the signed state of an enum datatype. Enum are fundamentally either signed or * unsigned, but sometimes you can't tell based on the values they contain. Once a negative value - * is added, then the enum becomes locked as signed, preventing high unsigned values from being - * added. Once a high value unsigned value is added, then it becomes locked as unsigned value. If - * neither a negative value or high unsigned value has been added, then the enum is not locked as - * either signed or unsigned. + * is added, then the enum becomes locked as signed, preventing high unsigned values (those values + * that are too big for signed value of the enum size) from being added. Once a high value unsigned + * value is added, then it becomes locked as unsigned value. If neither a negative value or high + * unsigned value has been added, then the enum is not locked as either signed or unsigned. */ public enum EnumSignedState { SIGNED, // Enum contains at least 1 negative value, preventing high unsigned values UNSIGNED, // Enum contains at least 1 high unsigned value, preventing negative values - NONE // Enum contains neither a negative or a high unsigned value, so can go either way + NONE, // Enum contains neither a negative or a high unsigned value, so can go either way + INVALID // Enum contains both negative and high unsigned values; can happen with old types } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Enum.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Enum.java index 774a99b631..239737e92e 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Enum.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Enum.java @@ -19,6 +19,7 @@ import java.math.BigInteger; import java.util.NoSuchElementException; import ghidra.docking.settings.Settings; +import ghidra.program.database.data.EnumSignedState; public interface Enum extends DataType { @@ -133,6 +134,12 @@ public interface Enum extends DataType { */ public boolean isSigned(); + /** + * Returns the signed state. + * @return the signed state. + */ + public EnumSignedState getSignedState(); + /** * Returns the maximum value that this enum can represent based on its size and signedness. * @return the maximum value that this enum can represent based on its size and signedness. diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/EnumDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/EnumDataType.java index 192e564c57..60934ecf4d 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/EnumDataType.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/EnumDataType.java @@ -148,6 +148,11 @@ public class EnumDataType extends GenericDataType implements Enum { @Override public void add(String valueName, long value, String comment) { + doAdd(valueName, value, comment); + signedState = computeSignedness(); + } + + private void doAdd(String valueName, long value, String comment) { bitGroups = null; checkValue(value); if (nameMap.containsKey(valueName)) { @@ -161,8 +166,6 @@ public class EnumDataType extends GenericDataType implements Enum { if (!StringUtils.isBlank(comment)) { commentMap.put(valueName, comment); } - signedState = computeSignedness(); - } private EnumSignedState computeSignedness() { @@ -172,12 +175,16 @@ public class EnumDataType extends GenericDataType implements Enum { long minValue = valueMap.firstKey(); long maxValue = valueMap.lastKey(); + if (maxValue > getMaxPossibleValue(length, true)) { + if (minValue < 0) { + return INVALID; + } + return UNSIGNED; + } + if (minValue < 0) { return SIGNED; } - if (maxValue > getMaxPossibleValue(length, true)) { - return UNSIGNED; - } return NONE; // we have no negatives and no large unsigned values } @@ -277,6 +284,11 @@ public class EnumDataType extends GenericDataType implements Enum { return signedState == SIGNED; } + @Override + public EnumSignedState getSignedState() { + return signedState; + } + @Override public long getMinPossibleValue() { return getMinPossibleValue(length, signedState != UNSIGNED); @@ -503,10 +515,10 @@ public class EnumDataType extends GenericDataType implements Enum { commentMap = new HashMap<>(); setLength(enumm.getLength()); String[] names = enumm.getNames(); + signedState = enumm.getSignedState(); for (String valueName : names) { - add(valueName, enumm.getValue(valueName), enumm.getComment(valueName)); + doAdd(valueName, enumm.getValue(valueName), enumm.getComment(valueName)); } - computeSignedness(); } @Override