mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-22 04:05:39 +00:00
GP-2134 corrected structure edit issue when adding pointer-to-self
component
This commit is contained in:
parent
6239edb52b
commit
0797cf45d9
@ -19,25 +19,28 @@ import ghidra.program.model.data.*;
|
||||
|
||||
public class CompositeViewerDataTypeManager extends StandAloneDataTypeManager {
|
||||
|
||||
/** The full name of the composite data type being edited. */
|
||||
/** The data type manager for original composite data type being edited.
|
||||
/**
|
||||
* The data type manager for original composite data type being edited.
|
||||
* This is where the edited datatype will be written back to.
|
||||
*/
|
||||
private DataTypeManager originalDTM;
|
||||
private Composite originalComposite;
|
||||
private Composite viewComposite;
|
||||
private int transactionID;
|
||||
|
||||
/**
|
||||
* Creates a data type manager that the structure editor will use
|
||||
* internally for updating the structure being edited.
|
||||
* @param rootName the root name for this data type manager (usually the program name).
|
||||
* @param composite the composite data type that is being edited. (cannot be null).
|
||||
* @param originalComposite the original composite data type that is being edited. (cannot be null).
|
||||
*/
|
||||
public CompositeViewerDataTypeManager(String rootName, Composite composite) {
|
||||
super(rootName, composite.getDataTypeManager().getDataOrganization());
|
||||
public CompositeViewerDataTypeManager(String rootName, Composite originalComposite) {
|
||||
super(rootName, originalComposite.getDataTypeManager().getDataOrganization());
|
||||
this.originalComposite = originalComposite;
|
||||
transactionID = startTransaction("");
|
||||
originalDTM = composite.getDataTypeManager();
|
||||
originalDTM = originalComposite.getDataTypeManager();
|
||||
universalID = originalDTM.getUniversalID(); // mimic original DTM
|
||||
super.resolve(composite, null);
|
||||
viewComposite = (Composite) super.resolve(originalComposite, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,4 +59,16 @@ public class CompositeViewerDataTypeManager extends StandAloneDataTypeManager {
|
||||
return originalDTM.allowsDefaultBuiltInSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType resolve(DataType dataType, DataTypeConflictHandler handler) {
|
||||
if (dataType == originalComposite && viewComposite != null) {
|
||||
// be sure to resolve use of original composite (e.g., pointer use)
|
||||
// from program/archive to view instance. The viewComposite will
|
||||
// be null while resolving it during instantiation of this
|
||||
// DataTypeManager instance.
|
||||
return viewComposite;
|
||||
}
|
||||
return super.resolve(dataType, handler);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -527,6 +527,27 @@ public class StructureEditorUnlockedCellEdit2Test
|
||||
|
||||
assertEquals(29, model.getLength());
|
||||
assertEquals(4, dt.getLength());
|
||||
|
||||
// insert new component at end first to force difference
|
||||
// between program type and editor type. This is done to
|
||||
// ensure we do not incorrectly update the edited structure
|
||||
// during the resolve processing
|
||||
|
||||
int newRow = model.getNumComponents();
|
||||
editCell(getTable(), newRow, column); // blank row
|
||||
assertIsEditingField(newRow, column);
|
||||
|
||||
setText("byte");
|
||||
pressEnterToSelectChoice();
|
||||
|
||||
assertNotEditingField();
|
||||
assertEquals(1, model.getNumSelectedRows());
|
||||
assertEquals(newRow + 1, model.getMinIndexSelected()); // blank row
|
||||
assertCellString("byte", newRow, column);
|
||||
assertEquals(30, model.getLength());
|
||||
|
||||
// change row-3 datatype from dword to simpleStructure*
|
||||
|
||||
editCell(getTable(), 3, column);
|
||||
assertIsEditingField(3, column);
|
||||
|
||||
@ -537,7 +558,7 @@ public class StructureEditorUnlockedCellEdit2Test
|
||||
assertEquals(1, model.getNumSelectedRows());
|
||||
assertEquals(3, model.getMinIndexSelected());
|
||||
assertCellString("simpleStructure *", 3, column);
|
||||
assertEquals(29, model.getLength());
|
||||
assertEquals(30, model.getLength());
|
||||
dt = getDataType(3);
|
||||
assertEquals(4, dt.getLength());
|
||||
assertEquals("simpleStructure *", dt.getDisplayName());
|
||||
|
Loading…
Reference in New Issue
Block a user