Merge remote-tracking branch 'origin/GP-2429_ghizard_Improve_Demangler_Analyzer_post_analysis_popup_error_messaging'

This commit is contained in:
Ryan Kurtz
2022-08-10 13:10:34 -04:00
4 changed files with 50 additions and 17 deletions

View File

@@ -263,29 +263,34 @@ public abstract class AbstractDemanglerAnalyzer extends AbstractAnalyzer {
if (demangled.applyTo(program, address, options, monitor)) {
return;
}
logApplyErrorMessage(log, demangled, address, null);
String errorString = demangled.getErrorMessage();
logApplyErrorMessage(log, demangled, address, null, errorString);
}
catch (Exception e) {
logApplyErrorMessage(log, demangled, address, e);
logApplyErrorMessage(log, demangled, address, e, null);
}
}
private void logApplyErrorMessage(MessageLog log, DemangledObject demangled, Address address,
Exception exception) {
Exception exception, String errorString) {
String message;
String name;
if (exception == null) {
if (exception != null) {
message = ExceptionUtils.getMessage(exception);
name = StringUtils.EMPTY;
}
else if (errorString != null) {
message = errorString;
name = StringUtils.EMPTY;
}
else {
// Eventually, if we switch all errors over to being passed by an exception, then
// we can eliminate this block of code (and not pass null into this method).
message = "Unknown error at address " + address;
name = "\n\t" + demangled.getName();
}
else {
message = ExceptionUtils.getMessage(exception);
name = StringUtils.EMPTY;
}
String className = demangled.getClass().getSimpleName();
log.appendMsg(getName(), "Apply failure (" + className + ": " + message + ")\n\t" +

View File

@@ -72,6 +72,7 @@ public abstract class DemangledObject implements Demangled {
// Status of mangled String converted successfully to demangled String
private boolean demangledNameSucceeded = false;
private String errorMessage = null;
DemangledObject(String mangled, String originalDemangled) {
this.mangled = mangled;
@@ -307,6 +308,25 @@ public abstract class DemangledObject implements Demangled {
return false;
}
/**
* Returns the error message that can be set when an error is encountered, but which is made
* available to the calling method to get details of the error beyond boolean value that is
* returned by {@link #applyTo(Program, Address, DemanglerOptions,TaskMonitor)}.
* @return a message pertaining to issues encountered in the apply methods. Can be null
*/
public String getErrorMessage() {
return errorMessage;
}
/**
* Set the message that {@link #applyTo(Program, Address, DemanglerOptions,TaskMonitor)} caller
* can read
* @param message the message
*/
protected void setErrorMessage(String message) {
this.errorMessage = message;
}
public boolean applyTo(Program program, Address address, DemanglerOptions options,
TaskMonitor monitor) throws Exception {
return applyPlateCommentOnly(program, address);
@@ -341,9 +361,9 @@ public abstract class DemangledObject implements Demangled {
}
/**
* Sets the plate comment to be used if the {@link #getOriginalDemangled()} string is not
* Sets the plate comment to be used if the {@link #getOriginalDemangled()} string is not
* available
*
*
* @param plateComment the plate comment text
*/
public void setBackupPlateComment(String plateComment) {
@@ -355,7 +375,7 @@ public abstract class DemangledObject implements Demangled {
* to the original demangled text. If that is not available, then any text set by
* {@link #setBackupPlateComment(String)} will be used. The last choice for this text is
* the signature generated by {@link #getSignature(boolean)}.
*
*
* @return the text
*/
protected String generatePlateComment() {

View File

@@ -84,8 +84,10 @@ public class DemangledString extends DemangledObject {
Symbol s = program.getSymbolTable().getPrimarySymbol(address);
if (s != null && s.getSymbolType() == SymbolType.FUNCTION) {
Msg.error(this,
"Failed to demangled string at " + address + " due to existing function");
String message =
"Failed to demangled string at " + address + " due to existing function";
setErrorMessage(message);
Msg.error(this, message);
return false;
}

View File

@@ -210,7 +210,9 @@ public class DemangledVariable extends DemangledObject {
CreateDataCmd cmd = new CreateDataCmd(address, demangledDT, false,
ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA);
if (!cmd.applyTo(program)) {
Msg.error(this, "Failed to create data at " + address + ": " + cmd.getStatusMsg());
String message = cmd.getStatusMsg();
setErrorMessage(message);
Msg.error(this, message);
return false;
}
return true;
@@ -247,7 +249,9 @@ public class DemangledVariable extends DemangledObject {
listing.createData(address, demangledDT);
}
catch (CodeUnitInsertionException e) {
Msg.trace(this, "Unable to create demangled data '" + demangledDT + "' @ " + address);
String message = "Unable to create demangled data '" + demangledDT + "' @ " + address;
setErrorMessage(message);
Msg.trace(this, message);
}
return true; // return true, as we did not fail to demangle
@@ -306,7 +310,9 @@ public class DemangledVariable extends DemangledObject {
CreateDataCmd cmd = new CreateDataCmd(address, pointer, false,
ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA);
if (!cmd.applyTo(program)) {
Msg.error(this, "Failed to create pointer at " + address + ": " + cmd.getStatusMsg());
String message = "Failed to create pointer at " + address + ": " + cmd.getStatusMsg();
setErrorMessage(message);
Msg.error(this, message);
return false;
}
return true;
@@ -314,7 +320,7 @@ public class DemangledVariable extends DemangledObject {
/**
* get the next symbol defined or auto after address
*
*
* @param program - program to check
* @param address - address to get symbol after
* @return address of the location of the next symbol or the last address in program