diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/SourceMapFieldFactory.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/SourceMapFieldFactory.java index 880504f2c7..b7c45cd69b 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/SourceMapFieldFactory.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/SourceMapFieldFactory.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -118,6 +118,7 @@ public class SourceMapFieldFactory extends FieldFactory { entriesToShow = entriesStartingWithinCu; } + int entriesShown = 0; for (SourceMapEntry entry : entriesToShow) { StringBuilder sb = new StringBuilder(); if (showOnlyFileNames) { @@ -149,10 +150,23 @@ public class SourceMapFieldFactory extends FieldFactory { entry.getBaseAddress().compareTo(cuAddr) <= 0 ? Palette.BLACK : OFFCUT_COLOR; AttributedString attrString = new AttributedString(sb.toString(), color, getMetrics()); fieldElements.add(new TextFieldElement(attrString, 0, 0)); + entriesShown++; + if (entriesShown == maxEntries) { + int entriesLeft = entriesToShow.size() - maxEntries; + if (entriesLeft == 0) { + break; + } + String singularOrPlural = entriesLeft == 1 ? " entry " : " entries "; + AttributedString truncatedMessage = new AttributedString( + "-- " + entriesLeft + singularOrPlural + "omitted --", + OFFCUT_COLOR, getMetrics()); + fieldElements.add(new TextFieldElement(truncatedMessage, 0, 0)); + break; + } } return ListingTextField.createMultilineTextField(this, obj, fieldElements, - startX + varWidth, width, maxEntries, hlProvider); + startX + varWidth, width, maxEntries + 1, hlProvider); } @Override diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/viewer/field/SourceMapFieldFactoryTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/viewer/field/SourceMapFieldFactoryTest.java index f1494b2a1f..dd7306ed2e 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/viewer/field/SourceMapFieldFactoryTest.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/viewer/field/SourceMapFieldFactoryTest.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -179,20 +179,32 @@ public class SourceMapFieldFactoryTest extends AbstractGhidraHeadedIntegrationTe try { sourceManager.addSourceMapEntry(source1, 1, entryPoint, 1); sourceManager.addSourceMapEntry(source2, 2, entryPoint, 1); + sourceManager.addSourceMapEntry(source2, 22, entryPoint, 1); } finally { program.endTransaction(txID, true); } ListingTextField textField = getTextField(entryPoint); - assertEquals(2, textField.getNumRows()); + assertEquals(3, textField.getNumRows()); - SwingUtilities.invokeAndWait(() -> fieldOptions + runSwing(() -> fieldOptions + .setInt(SourceMapFieldFactory.MAX_ENTRIES_PER_ADDRESS_OPTION_NAME, 2)); + waitForSwing(); + cb.updateNow(); + + textField = getTextField(entryPoint); + assertEquals(3, textField.getNumRows()); + assertTrue(textField.getText().contains("-- 1 entry omitted --")); + + runSwing(() -> fieldOptions .setInt(SourceMapFieldFactory.MAX_ENTRIES_PER_ADDRESS_OPTION_NAME, 1)); waitForSwing(); cb.updateNow(); textField = getTextField(entryPoint); - assertEquals(1, textField.getNumRows()); + assertEquals(2, textField.getNumRows()); + assertTrue(textField.getText().contains("-- 2 entries omitted --")); + } @Test