Replies: 3 comments 3 replies
-
I know having structures fields with duplicate names was discussed in the past, but I see no reasonable way around it for virtual function tables. I think it should be allowed and maybe the decompiler could emit a comment above the access giving the offset of the field? |
Beta Was this translation helpful? Give feedback.
-
@astrelsky Anonymous unions had been tried and are not a good solution, as the Decompiler doesn't emit what one would use in source code to refer to members of the anonymous unions, and they would only be pursuing the shoe-horn solution that we are trying to avoid. We are striving to make sure that what we design will be consistently used whether by users and analyzers alike to receive input from users, debug information, or program information. There is a lot to be done including reworking the Symbol/DataType systems, Decompiler, Debugger, PDB/DWARF, and other analyzers. The rough prototypes are trying to work out algorithms while still providing some useful tools for the users. The same is true for the PDB capability. These prototypes will likely be thrown away when the final designs are surfaced. |
Beta Was this translation helpful? Give feedback.
-
I'm speaking directly about PDB, but DWARF (Itanium ABI) could have similar situation. Lets say you have class A with virtual functions, and B with virtual function, and C : A, B that has virtual functions. When C gets laid out, you will find an occurence of class A inside of C and an occurrence of B inside C. The occurrence of B inside of C has its own vftptr that is used if you cast C to B. There is also a vftptr that was initially laid out for class A within C that C will share (in the circumstance of this simple example). For PDB, this would look roughly like:
The entries for methods of class A will be in the table first, followed by the entries for class C which includes (maybe first) the entries for class B. When class C is cast to class B in this case, the this pointer is moved. When class C is cast to class A, the this pointer (since this example is simple) is not moved, so the location of the vftptr being shared with C points to the same table, but the table that it points to is only consulted for the entries that pertain to class A. Let's say that class A has 2 entries in its vftable, class B has 1, and class C has 4. Then class A and class C share the same table, but class A knows its table size is 2, but class C knows the same table size to be 4. MSFT just lays things out such that the shared entries are the first two, and thus the same table (after the class has been constructed). PDB knows the shapes of the three tables such that it could create pointers for the vftptrs, but we have the same conflict as with constructing the class in general (why the work had not continued in the current fashion); do we use unions or something elset to allow this shared vftptr? I view this as the vftable of A owned by C, and thus could construct it with 4 entries, but if the class C is cast to class A, then it is only legitimate for class A to consider that it has 2 entries belonging to it. A native class A would have the vftable only having 2 entries. The prototype PDB work currently only sets the shape to be that of class A; this is a known issue that I intend to fix. But how to present this is still a challenge and would be a challenge for what you want. What are your thoughts? Ignoring this issue at the moment, I'd like to better understand what you would like to "edit." If a class structure had a single vftptr with datatype Back to the question... do you plan to edit the structure of |
Beta Was this translation helpful? Give feedback.
-
@ghizard @dev747368 @ghidra007 I'm pinging the three of you since, afaik, you maintain the debug parsers and the C++ RTTI scripts.
This discussion will omit virtual base classes since Ghidra's datatype model is currently incompatible with it.
It would be a good idea to standardize the way c++ classes are represented in Ghidra so that the debug parsers and RTTI analysis can construct them in the same way. This will lead to less confusion and make reversing programs written in c++ easier.
My suggestion would be the following:
Beta Was this translation helpful? Give feedback.
All reactions