Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/GP-0-dragonmacher-test-fixes-10-…
Browse files Browse the repository at this point in the history
…22-21'
  • Loading branch information
ryanmkurtz committed Oct 25, 2021
2 parents 4b01bae + 7b87502 commit a995cfc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public FindDataTypesByNameAction(DataTypeManagerPlugin plugin, String menuSubGro
public void actionPerformed(ActionContext context) {

InputDialog inputDialog =
new InputDialog("Find Data Types", "Please enter the search string: ");
new InputDialog(NAME, "Please enter the search string: ");
PluginTool tool = plugin.getTool();
tool.showDialog(inputDialog);
if (inputDialog.isCanceled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import ghidra.program.model.scalar.Scalar;
import ghidra.program.model.symbol.*;
import ghidra.program.util.*;
import ghidra.util.StringUtilities;

/**
* Utility class with methods to get comment information that can be displayed in the
Expand Down Expand Up @@ -520,26 +521,7 @@ private RefRepeatComment[] getRepeatableComments(Listing listing, Reference[] me
}

Address address = memRefs[i].getToAddress();
String repeatableComment = listing.getComment(CodeUnit.REPEATABLE_COMMENT, address);
if (repeatableComment != null) {
set.add(new RefRepeatComment(address, new String[] { repeatableComment }));
}

CodeUnit cu = listing.getCodeUnitAt(address);
if (cu == null) {
continue;
}

String[] comment = new String[0];
Function func = listing.getFunctionAt(address);
if (func != null) {
comment = func.getRepeatableCommentAsArray();
}

if (comment.length == 0) {
comment = cu.getCommentAsArray(CodeUnit.REPEATABLE_COMMENT);
}

String[] comment = getComment(listing, address);
if (comment != null && comment.length > 0) {
set.add(new RefRepeatComment(address, comment));
totalCommentsFound++;
Expand All @@ -549,6 +531,27 @@ private RefRepeatComment[] getRepeatableComments(Listing listing, Reference[] me
return set.toArray(new RefRepeatComment[set.size()]);
}

private String[] getComment(Listing listing, Address address) {

// prefer listing comments first since there may not be a code unit at this address
String repeatableComment = listing.getComment(CodeUnit.REPEATABLE_COMMENT, address);
if (repeatableComment != null) {
return StringUtilities.toLines(repeatableComment);
}

CodeUnit cu = listing.getCodeUnitAt(address);
if (cu == null) {
return null;
}

Function func = listing.getFunctionAt(address);
if (func != null) {
return func.getRepeatableCommentAsArray();
}

return cu.getCommentAsArray(CodeUnit.REPEATABLE_COMMENT);
}

/**
* Return all the comments
* @return the comments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ else if (!address.equals(other.address)) {
return true;
}

@Override
public String toString() {
return Arrays.toString(commentLines);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void testEquals() throws Exception {
assertEquals(options1, options2);

options1.setString("foo", "foo1");
assertTrue(!options1.equals(options2));
assertFalse(options1.equals(options2));
}

@Test
Expand Down Expand Up @@ -699,15 +699,15 @@ public void testEOLCommentsOptions() throws Exception {
cb.updateNow();
btf = (ListingTextField) cb.getCurrentField();
assertEquals(12, getNumberOfLines(btf));
assertTrue(!"; ".equals(btf.getFieldElement(1, 0).getText()));
assertFalse("; ".equals(btf.getFieldElement(1, 0).getText()));
assertEquals("01003fa1", btf.getFieldElement(11, 4).getText());
assertEquals("Mem ref line1.", btf.getFieldElement(11, 11).getText());

options.setBoolean(names.get(SHOW_REF_ADDR), false);
cb.updateNow();
btf = (ListingTextField) cb.getCurrentField();
assertEquals(11, getNumberOfLines(btf));
assertTrue(!"; ".equals(btf.getFieldElement(1, 0).getText()));
assertFalse("; ".equals(btf.getFieldElement(1, 0).getText()));

cb.goToField(callAddress, "EOL Comment", 9, 4);
btf = (ListingTextField) cb.getCurrentField();
Expand All @@ -730,7 +730,7 @@ public void testLabelFieldOptions() throws Exception {
cb.updateNow();
waitForPostedSwingRunnables();

assertTrue(!cb.goToField(addr("0x10048a3"), "Label", 0, 0));
assertFalse(cb.goToField(addr("0x10048a3"), "Label", 0, 0));
options.setBoolean(names.get(0), true);
cb.updateNow();
waitForPostedSwingRunnables();
Expand Down

0 comments on commit a995cfc

Please sign in to comment.