Class ExternalFunctionMerger

  • All Implemented Interfaces:
    ListingMergeConstants

    public class ExternalFunctionMerger
    extends java.lang.Object
    Class for merging external function and label changes. This class can merge external function and label changes that were made to the checked out version. It can determine where there are conflicts between the latest checked in version and my checked out version. It can then allow the user to manually merge the conflicting functions and labels. External functions do not have bodies. However their signatures, stacks and variables do get merged. This class extends the AbstractFunctionMerger to handle merging of function changes when both My and Latest have changed functions.
    Note: Externals are uniquely identified by symbol ID and the name (including namespace is also used to match externals when the external is transitioned from a label to a function and vice versa.
    Important: This class is intended to be used only for a single program version merge. It should be constructed, followed by an autoMerge(), and lastly each external with a conflict should have mergeConflicts() called on it.
    • Field Detail

      • HIGHEST_DETAIL_BIT_SHIFT

        protected static final int HIGHEST_DETAIL_BIT_SHIFT
        See Also:
        Constant Field Values
      • ALL_EXTERNAL_DIFFERENCES

        protected static final int ALL_EXTERNAL_DIFFERENCES
        See Also:
        Constant Field Values
      • KEEP_LATEST_ADD

        public static final int KEEP_LATEST_ADD
        Keep the external location added in LATEST to resolve a conflict.
        See Also:
        Constant Field Values
      • KEEP_MY_ADD

        public static final int KEEP_MY_ADD
        Keep the external location added in MY to resolve a conflict.
        See Also:
        Constant Field Values
      • KEEP_BOTH_ADDS

        public static final int KEEP_BOTH_ADDS
        Keep both of the external locations added in the LATEST and in MY when in conflict.
        See Also:
        Constant Field Values
      • MERGE_BOTH_ADDS

        public static final int MERGE_BOTH_ADDS
        Merge both of the external locations added in the LATEST and in MY when in conflict.
        See Also:
        Constant Field Values
      • KEEP_BOTH_BUTTON_NAME

        public static final java.lang.String KEEP_BOTH_BUTTON_NAME
        See Also:
        Constant Field Values
      • MERGE_BOTH_BUTTON_NAME

        public static final java.lang.String MERGE_BOTH_BUTTON_NAME
        See Also:
        Constant Field Values
      • externalDataTypeConflicts

        protected AddressSet externalDataTypeConflicts
      • externalFunctionVersusDataTypeConflicts

        protected AddressSet externalFunctionVersusDataTypeConflicts
      • totalChanges

        protected int totalChanges
      • changeNum

        protected int changeNum
      • externalFunctionRemovalChoice

        protected int externalFunctionRemovalChoice
      • externalFunctionChoice

        protected int externalFunctionChoice
      • externalDetailsChoice

        protected int externalDetailsChoice
      • externalDataTypeChoice

        protected int externalDataTypeChoice
      • externalFunctionVsDataTypeChoice

        protected int externalFunctionVsDataTypeChoice
      • externalAddChoice

        protected int externalAddChoice
      • externalRemoveChoice

        protected int externalRemoveChoice
      • FUNCTION_CONFLICT_START

        protected static final int FUNCTION_CONFLICT_START
        See Also:
        Constant Field Values
      • FUNCTION_CONFLICT_SIZE

        protected static final int FUNCTION_CONFLICT_SIZE
        See Also:
        Constant Field Values
      • DETAILS_CONFLICT_START

        protected static final int DETAILS_CONFLICT_START
        See Also:
        Constant Field Values
      • DETAILS_CONFLICT_SIZE

        protected static final int DETAILS_CONFLICT_SIZE
        See Also:
        Constant Field Values
      • FUNC_RETURN_ADDRESS_OFFSET

        protected static final int FUNC_RETURN_ADDRESS_OFFSET
        See Also:
        Constant Field Values
      • FUNC_STACK_PURGE_SIZE

        protected static final int FUNC_STACK_PURGE_SIZE
        See Also:
        Constant Field Values
      • FUNC_CALLING_CONVENTION

        protected static final int FUNC_CALLING_CONVENTION
        See Also:
        Constant Field Values
      • FUNC_SIGNATURE_SOURCE

        protected static final int FUNC_SIGNATURE_SOURCE
        See Also:
        Constant Field Values
      • errorBuf

        protected java.lang.StringBuffer errorBuf
      • infoBuf

        protected java.lang.StringBuffer infoBuf
      • programs

        protected Program[] programs
      • currentConflictPanel

        protected ConflictPanel currentConflictPanel
      • overlapChoice

        protected int overlapChoice
      • bodyChoice

        protected int bodyChoice
      • functionReturnChoice

        protected int functionReturnChoice
      • removeChoice

        protected int removeChoice
      • detailsChoice

        protected int detailsChoice
      • variableStorageChoice

        protected int variableStorageChoice
      • parameterSignatureChoice

        protected int parameterSignatureChoice
      • parameterInfoChoice

        protected int parameterInfoChoice
      • removedLocalVariableChoice

        protected int removedLocalVariableChoice
      • localVariableDetailChoice

        protected int localVariableDetailChoice
      • thunkChoice

        protected int thunkChoice
      • STORAGE_CONFLICT_CHOICES

        protected static final java.lang.String[] STORAGE_CONFLICT_CHOICES
      • STORAGE_CONFLICT_HEADINGS

        protected static final java.lang.String[] STORAGE_CONFLICT_HEADINGS
    • Constructor Detail

      • ExternalFunctionMerger

        public ExternalFunctionMerger​(ListingMergeManager listingMergeManager,
                                      boolean showListingPanel)
        Manages changes and conflicts for externals between the latest versioned program and the modified program being checked into version control.
        Parameters:
        mergeManager - the top level merge manager for merging a program version.
        resultPgm - the program to be updated with the result of the merge. This is the program that will actually get checked in.
        originalPgm - the program that was checked out.
        latestPgm - the latest checked-in version of the program.
        myPgm - the program requesting to be checked in.
        latestChanges - the address set of changes between original and latest versioned program.
        myChanges - the address set of changes between original and my modified program.
    • Method Detail

      • init

        public void init()
      • getName

        public java.lang.String getName()
      • getDescription

        public java.lang.String getDescription()
      • allChoicesAreResolved

        public boolean allChoicesAreResolved()
      • apply

        public boolean apply()
      • cancel

        public void cancel()
      • initializeAutoMerge

        protected void initializeAutoMerge​(java.lang.String progressMessage,
                                           int progressMin,
                                           int progressMax,
                                           TaskMonitor monitor)
      • replaceExternalDataType

        public void replaceExternalDataType​(ExternalLocation resultExternalLocation,
                                            ExternalLocation fromExternalLocation,
                                            TaskMonitor monitor)
                                     throws CancelledException
        replaceExternalDataType replaces the data type of the external label in program1 with the data type of the external label in program2 at the specified external space address.
        Parameters:
        resultExternalLocation -
        fromExternalLocation -
        monitor - the task monitor for notifying the user of this merge's progress.
        Throws:
        CancelledException
      • mergeConflicts

        public void mergeConflicts​(int chosenConflictOption,
                                   ConflictInfoPanel listingConflictInfoPanel,
                                   TaskMonitor monitor)
                            throws CancelledException
        Performs a manual merge of external program conflicts.
        Parameters:
        chosenConflictOption - ASK_USER means interactively resolve conflicts. JUnit testing also allows setting this to LATEST, MY, or ORIGINAL to force selection of a particular version change.
        monitor - task monitor for informing the user of progress.
        Throws:
        CancelledException - if the user cancels the merge.
      • createParamInfoConflictPanel

        protected VariousChoicesPanel createParamInfoConflictPanel​(Function[] functions,
                                                                   ghidra.app.merge.listing.AbstractFunctionMerger.ParamInfoConflict pc,
                                                                   TaskMonitor monitor)
      • refreshResultPanel

        public void refreshResultPanel​(ExternalLocation[] externalLocations)
      • saveFunctionDetailConflict

        protected void saveFunctionDetailConflict​(Function[] functions,
                                                  int type)
        Saves information indicating there is a conflict that needs to be resolved for a particular part of a function as indicated by the type.
        Parameters:
        functions - the matching set of functions from Result, Latest, My, and Original (Some may be null) which have the detailed type of conflict.
        type - function conflict flags to be set (FUNC_RETURN_TYPE, FUNC_RETURN_ADDRESS_OFFSET, FUNC_STACK_PURGE_SIZE, FUNC_NAME FUNC_INLINE, FUNC_NO_RETURN, FUNC_CALLING_CONVENTION, FUNC_VAR_STORAGE FUNC_CUSTOM_STORAGE, FUNC_VAR_DETAILS, FUNC_SIGNATURE)
      • getConflictType

        public java.lang.String getConflictType()
      • getNumConflictsResolved

        public int getNumConflictsResolved()
      • hasConflict

        public boolean hasConflict​(Address addr)
      • getConflictCount

        public int getConflictCount​(Address addr)
      • getInfoTitle

        protected java.lang.String getInfoTitle()
      • getErrorTitle

        protected java.lang.String getErrorTitle()
      • dispose

        public void dispose()
      • determineReturnConflict

        protected boolean determineReturnConflict​(Function[] functions,
                                                  boolean autoMerge,
                                                  TaskMonitor monitor)
      • determineParameterInfoConflicts

        protected java.util.List<ghidra.app.merge.listing.AbstractFunctionMerger.ParamInfoConflict> determineParameterInfoConflicts​(Function[] functions,
                                                                                                                                    boolean autoMerge,
                                                                                                                                    TaskMonitor monitor)
      • mergeParameter

        protected void mergeParameter​(int type,
                                      Address entry,
                                      int ordinal,
                                      int currentConflictOption,
                                      TaskMonitor monitor)
      • mergeParameter

        protected void mergeParameter​(int type,
                                      Function[] functions,
                                      int ordinal,
                                      int currentConflictOption,
                                      TaskMonitor monitor)
      • countSetBits

        protected int countSetBits​(int bits)
      • mergeParameters

        protected void mergeParameters​(Function[] functions,
                                       int chosenConflictOption,
                                       TaskMonitor monitor)
      • mergeParamInfo

        protected void mergeParamInfo​(Address entryPt,
                                      java.util.List<ghidra.app.merge.listing.AbstractFunctionMerger.ParamInfoConflict> paramInfoConflicts,
                                      int chosenConflictOption,
                                      TaskMonitor monitor)
                               throws CancelledException
        Throws:
        CancelledException
      • mergeParamInfo

        protected void mergeParamInfo​(Address entryPt,
                                      ghidra.app.merge.listing.AbstractFunctionMerger.ParamInfoConflict pc,
                                      int chosenConflictOption,
                                      TaskMonitor monitor)
      • mergeParamInfo

        protected void mergeParamInfo​(Function[] functions,
                                      java.util.List<ghidra.app.merge.listing.AbstractFunctionMerger.ParamInfoConflict> paramInfoConflicts,
                                      int chosenConflictOption,
                                      TaskMonitor monitor)
                               throws CancelledException
        Throws:
        CancelledException
      • mergeParamInfo

        protected void mergeParamInfo​(Function[] functions,
                                      ghidra.app.merge.listing.AbstractFunctionMerger.ParamInfoConflict pc,
                                      int chosenConflictOption,
                                      TaskMonitor monitor)
      • mergeLocals

        protected void mergeLocals​(Address entryPt,
                                   java.util.List<ghidra.app.merge.listing.AbstractFunctionMerger.LocalVariableConflict> localVarConflicts,
                                   int chosenConflictOption,
                                   TaskMonitor monitor)
                            throws CancelledException
        Throws:
        CancelledException
      • getReturnString

        protected java.lang.String getReturnString​(Function func,
                                                   boolean includeStorage)
      • getReturnInfo

        protected java.lang.String[] getReturnInfo​(Program pgm,
                                                   java.lang.String returnStr,
                                                   java.lang.String prefix,
                                                   java.lang.String suffix)
      • getSignatureInfo

        protected java.lang.String[] getSignatureInfo​(Program pgm,
                                                      Function f,
                                                      java.lang.String prefix,
                                                      java.lang.String suffix)
      • clearConflictPanel

        protected void clearConflictPanel()
      • runSwing

        protected void runSwing​(java.lang.Runnable r)
      • createLocalVariableConflictPanel

        protected VariousChoicesPanel createLocalVariableConflictPanel​(ghidra.app.merge.listing.AbstractFunctionMerger.LocalVariableConflict lvc,
                                                                       TaskMonitor monitor)
      • getVariableDetails

        protected java.util.List<java.lang.String[]> getVariableDetails​(java.util.List<Variable> list)
      • createRemovedVarConflictPanel

        protected VerticalChoicesPanel createRemovedVarConflictPanel​(ghidra.app.merge.listing.AbstractFunctionMerger.LocalVariableConflict lvc,
                                                                     TaskMonitor monitor)
        Creates the panel for resolving a conflict due to a variable being removed.
        Parameters:
        entryPt - the function entry point for the function variables.
        vars - variables from the different programs [0]=Original, [1]=Latest, [2]=My
        monitor - status monitor
        Returns:
        the panel
      • getFunctionPrompt

        protected java.lang.String getFunctionPrompt​(Address addr,
                                                     Function function,
                                                     java.lang.String version)
      • updateProgressMessage

        protected void updateProgressMessage​(java.lang.String message)
        Updates the progress message details associated with this phase of the merge.
        Parameters:
        progressMessage - a message indicating what is currently occurring in this phase. Null indicates to use the default message.