GP-4521 fix DWARF and Golang error reporting, misc

This commit is contained in:
dev747368 2024-04-12 22:09:21 +00:00
parent 6c60bd0313
commit 0dbe5ca688
4 changed files with 38 additions and 20 deletions

View File

@ -654,18 +654,15 @@ public class GolangSymbolAnalyzer extends AbstractAnalyzer {
FunctionDefinitionDataType signature =
new FunctionDefinitionDataType(callsite.calledFunc, true);
signature.setReturnType(newReturnType);
try {
HighFunctionDBUtil.writeOverride(callsite.callingFunc,
callsite.ref.getFromAddress(), signature);
}
catch (InvalidInputException e) {
Msg.error(this, "Failed to override call", e);
}
HighFunctionDBUtil.writeOverride(callsite.callingFunc,
callsite.ref.getFromAddress(), signature);
fixedCallsiteCount++;
}
}
catch (IOException e) {
Msg.error(this, "Failed to override call", e);
catch (IOException | InvalidInputException e) {
markupSession.logWarningAt(callsite.ref.getFromAddress(),
"Failed to override with RTTI: " + e.getMessage());
unfixedCallsiteCount++;
}
}
}

View File

@ -31,7 +31,7 @@ import ghidra.app.util.bin.BinaryReader;
*/
public enum DWARFAttribute {
DW_AT_sibling(0x1, reference),
DW_AT_location(0x2, exprloc, loclist),
DW_AT_location(0x2, exprloc, loclist, block),
DW_AT_name(0x3, string),
DW_AT_ordering(0x9, constant),
//DW_AT_subscr_data(0xa),
@ -78,7 +78,7 @@ public enum DWARFAttribute {
DW_AT_discr_list(0x3d, block),
DW_AT_encoding(0x3e, constant),
DW_AT_external(0x3f, flag),
DW_AT_frame_base(0x40, exprloc, loclist),
DW_AT_frame_base(0x40, exprloc, loclist, block),
DW_AT_friend(0x41, reference),
DW_AT_identifier_case(0x42, constant),
DW_AT_macro_info(0x43, macptr),

View File

@ -20,6 +20,7 @@ import java.util.List;
import ghidra.app.util.bin.format.dwarf.DWARFUtil;
import ghidra.app.util.bin.format.golang.rtti.GoRttiMapper;
import ghidra.app.util.bin.format.golang.structmapping.MarkupSession;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.lang.Register;
@ -27,7 +28,6 @@ import ghidra.program.model.listing.*;
import ghidra.program.model.listing.Function.FunctionUpdateType;
import ghidra.program.model.pcode.Varnode;
import ghidra.program.model.symbol.*;
import ghidra.util.Msg;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
@ -91,10 +91,9 @@ public class GoFunctionFixup {
spillVars.add(newParam);
if (dt instanceof Structure &&
newParam.getVariableStorage().size() != dt.getLength()) {
Msg.warn(GoFunctionFixup.class,
"Known storage allocation problem: func %s@%s param %s register allocation for structs missing inter-field padding."
.formatted(func.getName(), func.getEntryPoint(),
newParam.toString()));
MarkupSession.logWarningAt(program, func.getEntryPoint(),
"Known storage allocation problem: param %s register allocation for structs missing inter-field padding."
.formatted(newParam.toString()));
}
}
else {
@ -121,8 +120,15 @@ public class GoFunctionFixup {
}
// Update the function in Ghidra
func.updateFunction(null, returnParam, newParams, FunctionUpdateType.CUSTOM_STORAGE, true,
SourceType.USER_DEFINED);
try {
func.updateFunction(null, returnParam, newParams, FunctionUpdateType.CUSTOM_STORAGE,
true, SourceType.USER_DEFINED);
}
catch (DuplicateNameException | InvalidInputException e) {
MarkupSession.logWarningAt(program, func.getEntryPoint(),
"Failed to update function signature: " + e.getMessage());
return;
}
// Remove any old local vars that are in the callers stack instead of in the local stack area
for (Variable localVar : func.getLocalVariables()) {

View File

@ -157,7 +157,8 @@ public class MarkupSession {
markedupAddrs.add(data.getMinAddress(), data.getMaxAddress());
}
catch (CodeUnitInsertionException e) {
throw new IOException(e);
logWarningAt(addr,
"Failed to apply data type [%s]: %s".formatted(dt.getName(), e.getMessage()));
}
}
}
@ -230,7 +231,7 @@ public class MarkupSession {
newLabelSym.setPrimary();
}
catch (InvalidInputException e) {
throw new IOException(e);
logWarningAt(addr, "Failed to label [%s]: %s".formatted(symbolName, e.getMessage()));
}
}
@ -425,4 +426,18 @@ public class MarkupSession {
refMgr.addMemoryReference(fieldAddr, refDest, RefType.DATA, SourceType.IMPORTED, 0);
}
public void logWarningAt(Address addr, String msg) {
logWarningAt(program, addr, msg);
}
public static void logWarningAt(Program program, Address addr, String msg) {
BookmarkManager bmm = program.getBookmarkManager();
Bookmark existingBM = bmm.getBookmark(addr, BookmarkType.WARNING, "Golang");
String existingTxt = existingBM != null ? existingBM.getComment() : "";
if (existingTxt.contains(msg)) {
return;
}
msg = !existingTxt.isEmpty() ? existingTxt + "; " + msg : msg;
bmm.setBookmark(addr, BookmarkType.WARNING, "Golang", msg);
}
}