From f09637e3099fac72d609c94fbf7e0af346045352 Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Fri, 4 Jun 2021 08:16:58 -0400 Subject: [PATCH] GP-17 additional function merge refinements --- .../ghidra/program/util/FunctionMerge.java | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionMerge.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionMerge.java index 64d11dd62a..7dd6b5e0b6 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionMerge.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionMerge.java @@ -15,6 +15,7 @@ */ package ghidra.program.util; +import ghidra.app.cmd.label.SetLabelPrimaryCmd; import ghidra.program.model.address.Address; import ghidra.program.model.address.AddressSetView; import ghidra.program.model.listing.*; @@ -62,7 +63,11 @@ public class FunctionMerge { originEntryPoint, expectedToNamespace); if (existingSymbol != null) { if (!existingSymbol.isPrimary()) { - existingSymbol.setPrimary(); + SetLabelPrimaryCmd cmd = + new SetLabelPrimaryCmd(originEntryPoint, fromName, expectedToNamespace); + if (cmd.applyTo(toProgram)) { + existingSymbol = cmd.getSymbol(); + } } return existingSymbol; } @@ -86,15 +91,9 @@ public class FunctionMerge { fromNamespace, conflictSymbolIDMap); } - // Move it to the new namespace. - if (currentToNamespace != desiredToNamespace) { - toFunction.setParentNamespace(desiredToNamespace); - } - - // Rename the function so that we will be able to move it. - boolean hasDifferentName = !fromName.equals(toName); - if (hasDifferentName) { - toFunction.setName(fromName, fromSource); + if (fromSource != toSource || !fromName.equals(toName) || + currentToNamespace != desiredToNamespace) { + toSymbol.setNameAndNamespace(fromName, desiredToNamespace, fromSource); } // TODO May want to save the symbol info if the function didn't get desired pathname. // FIXME @@ -127,7 +126,11 @@ public class FunctionMerge { toProgram.getSymbolTable().getSymbol(fromName, entryPoint, expectedToNamespace); if (existingSymbol != null) { if (!existingSymbol.isPrimary()) { - existingSymbol.setPrimary(); + SetLabelPrimaryCmd cmd = + new SetLabelPrimaryCmd(entryPoint, fromName, expectedToNamespace); + if (cmd.applyTo(toProgram)) { + existingSymbol = cmd.getSymbol(); + } } return existingSymbol; } @@ -151,15 +154,9 @@ public class FunctionMerge { fromNamespace, conflictSymbolIDMap); } - // Move it to the new namespace. - if (currentToNamespace != desiredToNamespace) { - toFunction.setParentNamespace(desiredToNamespace); - } - - // Rename the function so that we will be able to move it. - boolean hasDifferentName = !fromName.equals(toName); - if (hasDifferentName) { - toFunction.setName(fromName, fromSource); + if (fromSource != toSource || !fromName.equals(toName) || + currentToNamespace != desiredToNamespace) { + toSymbol.setNameAndNamespace(fromName, desiredToNamespace, fromSource); } // TODO May want to save the symbol info if the function didn't get desired pathname. // FIXME