GT-2942 - Search Text Preview - fixed bug that causes some separator

tokens to not appear in the Search Text Preview column
This commit is contained in:
dragonmacher 2019-06-18 15:27:57 -04:00
parent afc772c87c
commit f5f6b7c18b
4 changed files with 57 additions and 50 deletions

View file

@ -401,8 +401,8 @@ abstract class OperandFieldHelper extends FieldFactory {
for (int opIndex = 0; opIndex < numOperands; opIndex++) { for (int opIndex = 0; opIndex < numOperands; opIndex++) {
OperandRepresentationList operandRepresentationList = OperandRepresentationList operandRepresentationList =
codeUnitFormat.getOperandRepresentationList(inst, opIndex); codeUnitFormat.getOperandRepresentationList(inst, opIndex);
characterOffset = addElementsForOperand(inst, elements, opIndex, addElementsForOperand(inst, elements, opIndex, operandRepresentationList,
operandRepresentationList, characterOffset); characterOffset);
characterOffset = 0; characterOffset = 0;
} }
@ -504,8 +504,8 @@ abstract class OperandFieldHelper extends FieldFactory {
} }
private boolean containsNonPrimary(Reference[] refs) { private boolean containsNonPrimary(Reference[] refs) {
for (int i = 0; i < refs.length; i++) { for (Reference ref : refs) {
if (!refs[i].isPrimary()) { if (!ref.isPrimary()) {
return true; return true;
} }
} }

View file

@ -519,8 +519,10 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLoc
/** /**
* Moves the cursor to the given program location and repositions the scrollbar to * Moves the cursor to the given program location and repositions the scrollbar to
* show that location in the screen. * show that location in the screen
* @param loc the location to move to. *
* @param loc the location to move to
* @return true if the 'go to' was successful
*/ */
public boolean goTo(ProgramLocation loc) { public boolean goTo(ProgramLocation loc) {
return goTo(loc, true); return goTo(loc, true);
@ -536,6 +538,7 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLoc
* the given location will be placed in the center of the screen; * the given location will be placed in the center of the screen;
* when the parameter is false, then the screen will be scrolled * when the parameter is false, then the screen will be scrolled
* only enough to show the cursor. * only enough to show the cursor.
* @return true if the 'go to' was successful
*/ */
public boolean goTo(ProgramLocation loc, boolean centerWhenNotVisible) { public boolean goTo(ProgramLocation loc, boolean centerWhenNotVisible) {
final FieldLocation floc = getFieldLocation(loc); final FieldLocation floc = getFieldLocation(loc);
@ -555,15 +558,27 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLoc
return true; return true;
} }
/** Scroll the view of the listing to the given location. */ /**
* Scroll the view of the listing to the given location
* @param location the location
*/
public void scrollTo(ProgramLocation location) { public void scrollTo(ProgramLocation location) {
FieldLocation fieldLocation = getFieldLocation(location); FieldLocation fieldLocation = getFieldLocation(location);
if (fieldLocation == null) {
return; // this can happen when using restricted views
}
fieldPanel.scrollTo(fieldLocation); fieldPanel.scrollTo(fieldLocation);
} }
/** Center the view of the listing around the given location. */ /**
* Center the view of the listing around the given location
* @param location the location
*/
public void center(ProgramLocation location) { public void center(ProgramLocation location) {
FieldLocation fieldLocation = getFieldLocation(location); FieldLocation fieldLocation = getFieldLocation(location);
if (fieldLocation == null) {
return; // this can happen when using restricted views
}
fieldPanel.center(fieldLocation); fieldPanel.center(fieldLocation);
} }

View file

@ -17,6 +17,8 @@ package ghidra.program.model.listing;
import java.util.*; import java.util.*;
import org.apache.commons.lang3.StringUtils;
import ghidra.app.util.NamespaceUtils; import ghidra.app.util.NamespaceUtils;
import ghidra.app.util.viewer.field.CommentUtils; import ghidra.app.util.viewer.field.CommentUtils;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
@ -36,6 +38,8 @@ import ghidra.util.MathUtilities;
public class CodeUnitFormat { public class CodeUnitFormat {
private static final String EMPTY = "";
protected static final String PLUS = "+"; protected static final String PLUS = "+";
protected static final String UNDERSCORE = "_"; protected static final String UNDERSCORE = "_";
@ -112,37 +116,39 @@ public class CodeUnitFormat {
*/ */
public String getRepresentationString(CodeUnit cu, boolean includeEOLcomment) { public String getRepresentationString(CodeUnit cu, boolean includeEOLcomment) {
StringBuffer stringBuffer = new StringBuffer(getMnemonicRepresentation(cu)); StringBuilder buffy = new StringBuilder(getMnemonicRepresentation(cu));
if (cu instanceof Instruction) { if (cu instanceof Instruction) {
Instruction instr = (Instruction) cu; Instruction instr = (Instruction) cu;
int n = instr.getNumOperands(); int n = instr.getNumOperands();
for (int i = 0; i < n; i++) { if (n > 1) {
if (i == 0) { buffy.append(' ');
stringBuffer.append(" ");
}
else {
String separator = instr.getSeparator(i);
if (separator != null && separator.length() != 0) {
stringBuffer.append(separator);
}
}
stringBuffer.append(getOperandRepresentationString(cu, i));
} }
for (int i = 0; i < n; i++) {
String sep = instr.getSeparator(i);
buffy.append(StringUtils.isBlank(sep) ? EMPTY : sep);
buffy.append(getOperandRepresentationString(cu, i));
}
// grab any trailing separator at n (index + 1; see Instruction.getSeparator())
String sep = instr.getSeparator(n);
buffy.append(StringUtils.isBlank(sep) ? EMPTY : sep);
} }
else { // data always has one operand else { // data always has one operand
stringBuffer.append(" "); buffy.append(' ');
stringBuffer.append(getOperandRepresentationString(cu, 0)); buffy.append(getOperandRepresentationString(cu, 0));
} }
if (includeEOLcomment) { if (includeEOLcomment) {
String eolComment = cu.getComment(CodeUnit.EOL_COMMENT); String eolComment = cu.getComment(CodeUnit.EOL_COMMENT);
if (eolComment != null) { if (eolComment != null) {
// fixup annotations // fixup annotations
eolComment = CommentUtils.getDisplayString(eolComment, cu.getProgram()); eolComment = CommentUtils.getDisplayString(eolComment, cu.getProgram());
stringBuffer.append(" // "); buffy.append(" // ");
stringBuffer.append(eolComment); buffy.append(eolComment);
} }
} }
return stringBuffer.toString(); return buffy.toString();
} }
/** /**
@ -152,19 +158,19 @@ public class CodeUnitFormat {
* @return mnemonic representation * @return mnemonic representation
*/ */
public String getMnemonicRepresentation(CodeUnit cu) { public String getMnemonicRepresentation(CodeUnit cu) {
StringBuffer stringBuffer = new StringBuffer(); StringBuilder buffy = new StringBuilder();
String mnemonic = cu.getMnemonicString(); String mnemonic = cu.getMnemonicString();
if (options.showDataMutability && (cu instanceof Data) && mnemonic != null) { if (options.showDataMutability && (cu instanceof Data) && mnemonic != null) {
Data d = (Data) cu; Data d = (Data) cu;
if (d.isConstant()) { if (d.isConstant()) {
stringBuffer.append("const "); buffy.append("const ");
} }
else if (d.isVolatile()) { else if (d.isVolatile()) {
stringBuffer.append("volatile "); buffy.append("volatile ");
} }
} }
stringBuffer.append(mnemonic); buffy.append(mnemonic);
return stringBuffer.toString(); return buffy.toString();
} }
/** /**
@ -273,7 +279,7 @@ public class CodeUnitFormat {
* Perform register markup with explicit and implied register variable * Perform register markup with explicit and implied register variable
* reference. * reference.
* *
* @param inst instruction * @param instr instruction
* @param opIndex * @param opIndex
* @param func function containing instruction * @param func function containing instruction
* @param primaryRef primary reference or null * @param primaryRef primary reference or null
@ -446,18 +452,17 @@ public class CodeUnitFormat {
* @param opIndex operand index * @param opIndex operand index
* @param func function containing instruction * @param func function containing instruction
* @param primaryRef primary reference * @param primaryRef primary reference
* @param referencedVariable optional variable associated with reference * @param representationList the representation objects
* @param regIndexMap register index map
* @param representationList
* @return true if primaryRef was included in scalar mark-up * @return true if primaryRef was included in scalar mark-up
*/ */
private boolean performAddressMarkup(Instruction instr, int opIndex, Function func, private boolean performAddressMarkup(Instruction instr, int opIndex, Function func,
Reference primaryRef, List<Object> representationList) { Reference primaryRef, List<Object> representationList) {
if (primaryRef == null || !primaryRef.isMemoryReference()) { if (primaryRef == null || !primaryRef.isMemoryReference()) {
return false; return false;
} }
Address refAddr = primaryRef.getToAddress();
Address refAddr = primaryRef.getToAddress();
int size = representationList.size(); int size = representationList.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Object obj = representationList.get(i); Object obj = representationList.get(i);
@ -1133,13 +1138,9 @@ public class CodeUnitFormat {
* Get a representation object corresponding to the specified reference. * Get a representation object corresponding to the specified reference.
* Format options are considered when generating label. * Format options are considered when generating label.
* *
* @param cu * @param cu the code unit
* @param ref * @param ref the reference
* @param var variable which corresponds to reference or null * @param var variable which corresponds to reference or null
* @param showIndirectValue if true, indirect memory references which refer
* to a pointer will get an additional "=value" appended where
* value corresponds to data pointed to by the referenced
* pointer.
* @return reference representation object * @return reference representation object
*/ */
private Object getReferenceRepresentation(CodeUnit cu, Reference ref, Variable var) { private Object getReferenceRepresentation(CodeUnit cu, Reference ref, Variable var) {
@ -1417,9 +1418,6 @@ public class CodeUnitFormat {
return symbol.getName(); return symbol.getName();
} }
/**
* Returns ShowBlockName setting
*/
public ShowBlockName getShowBlockName() { public ShowBlockName getShowBlockName() {
return options.showBlockName; return options.showBlockName;
} }

View file

@ -24,7 +24,6 @@ import ghidra.program.model.address.*;
import ghidra.program.model.listing.Function; import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.program.model.pcode.*; import ghidra.program.model.pcode.*;
import ghidra.util.Msg;
public class DecompilerUtils { public class DecompilerUtils {
@ -315,11 +314,6 @@ public class DecompilerUtils {
int nchild = parentNode.numChildren(); int nchild = parentNode.numChildren();
for (int i = 0; i < nchild; i++) { for (int i = 0; i < nchild; i++) {
ClangNode node = parentNode.Child(i); ClangNode node = parentNode.Child(i);
if (node instanceof ClangFuncProto) {
Msg.debug(null, "");
}
if (node.numChildren() > 0) { if (node.numChildren() > 0) {
collectTokens(tokenList, node, addressSet); collectTokens(tokenList, node, addressSet);
} }