llvm-project/lldb/source/Plugins/SymbolFile/NativePDB
Zequan Wu d3492ed016 [LLDB][NativePDB] Fix struct layout when it has anonymous unions.
Previously, lldb mistook fields in anonymous union in a struct as the direct
field of the struct, which causes lldb crashes due to multiple fields sharing
the same offset in a struct. This patch fixes it.

MSVC generated pdb doesn't have the debug info entity representing a anonymous
union in a struct. It looks like the following:
```
struct S {
union {
  char c;
  int i;
};
};

0x1004 | LF_FIELDLIST [size = 40]
         - LF_MEMBER [name = `c`, Type = 0x0070 (char), offset = 0, attrs = public]
         - LF_MEMBER [name = `i`, Type = 0x0074 (int), offset = 0, attrs = public]
0x1005 | LF_STRUCTURE [size = 32] `S`
         unique name: `.?AUS@@`
         vtable: <no type>, base list: <no type>, field list: 0x1004
```
Clang generated pdb is similar, though due to the [[ https://github.com/llvm/llvm-project/issues/57999 | bug ]],
it's not more useful than the debug info above. But that's not very relavent,
lldb should still be able to understand MSVC geneerated pdb.
```
0x1003 | LF_UNION [size = 60] `S::<unnamed-tag>`
         unique name: `.?AT<unnamed-type-$S1>@S@@`
         field list: <no type>
         options: forward ref (= 0x1003) | has unique name | is nested, sizeof 0
0x1004 | LF_FIELDLIST [size = 40]
         - LF_MEMBER [name = `c`, Type = 0x0070 (char), offset = 0, attrs = public]
         - LF_MEMBER [name = `i`, Type = 0x0074 (int), offset = 0, attrs = public]
         - LF_NESTTYPE [name = ``, parent = 0x1003]
0x1005 | LF_STRUCTURE [size = 32] `S`
         unique name: `.?AUS@@`
         vtable: <no type>, base list: <no type>, field list: 0x1004
         options: contains nested class | has unique name, sizeof 4
0x1006 | LF_FIELDLIST [size = 28]
         - LF_MEMBER [name = `c`, Type = 0x0070 (char), offset = 0, attrs = public]
         - LF_MEMBER [name = `i`, Type = 0x0074 (int), offset = 0, attrs = public]
0x1007 | LF_UNION [size = 60] `S::<unnamed-tag>`
         unique name: `.?AT<unnamed-type-$S1>@S@@`
         field list: 0x1006
         options: has unique name | is nested | sealed, sizeof
```
This patch delays the FieldDecl creation when travesing LF_FIELDLIST so we know
if there are multiple fields are in the same offsets and are able to group them
into different anonymous unions based on offsets. Nested anonymous union will
be flatten into one anonymous union, because we simply don't have that info, but
they are equivalent in terms of union layout.

Differential Revision: https://reviews.llvm.org/D134849
2022-10-13 12:43:45 -07:00
..
CMakeLists.txt [lldb][PDB] Add ObjectFile PDB plugin 2020-10-26 10:28:48 -07:00
CodeViewRegisterMapping.cpp Ensure newlines at the end of files (NFC) 2022-08-20 21:18:23 -07:00
CodeViewRegisterMapping.h [LLDB][NativePDB] Switch to use DWARFLocationList. 2022-08-17 13:37:13 -07:00
CompileUnitIndex.cpp [lldb] Fix use-after-move in SymbolFile/NativePDB 2022-02-14 11:03:26 -08:00
CompileUnitIndex.h Revert "Revert "[LLDB][NativePDB] Add support for inlined functions"" 2022-01-13 14:00:24 -08:00
DWARFLocationExpression.cpp [LLDB][NativePDB] Pass register_kind as reference (an oversight in 71d778f). 2022-09-20 13:41:13 -07:00
DWARFLocationExpression.h [LLDB][NativePDB] Switch to use DWARFLocationList. 2022-08-17 13:37:13 -07:00
PdbAstBuilder.cpp [LLDB][NativePDB] Fix struct layout when it has anonymous unions. 2022-10-13 12:43:45 -07:00
PdbAstBuilder.h [LLDB][NativePDB] Let native pdb use class layout in debug info. 2022-09-27 11:01:32 -07:00
PdbFPOProgramToDWARFExpression.cpp Cleanup LLVMDebugInfoCodeView headers 2022-02-08 16:00:36 +01:00
PdbFPOProgramToDWARFExpression.h
PdbIndex.cpp [LLDB][NativePDB] Return LLDB_INVALID_ADDRESS in PdbIndex::MakeVirtualAddress when input is invalid due to missing address info in symbol/public records. 2022-06-30 14:34:20 -07:00
PdbIndex.h [LLDB][NativePDB] Return LLDB_INVALID_ADDRESS in PdbIndex::MakeVirtualAddress when input is invalid due to missing address info in symbol/public records. 2022-06-30 14:34:20 -07:00
PdbSymUid.cpp
PdbSymUid.h
PdbUtil.cpp [LLDB][NativePDB] Fix struct layout when it has anonymous unions. 2022-10-13 12:43:45 -07:00
PdbUtil.h [LLDB][NativePDB] Add local variables with no location info. 2022-09-12 12:01:24 -07:00
SymbolFileNativePDB.cpp [LLDB][NativePDB] Let native pdb use class layout in debug info. 2022-09-27 11:01:32 -07:00
SymbolFileNativePDB.h [LLDB][NativePDB] Fix struct layout when it has anonymous unions. 2022-10-13 12:43:45 -07:00
UdtRecordCompleter.cpp [LLDB][NativePDB] Fix struct layout when it has anonymous unions. 2022-10-13 12:43:45 -07:00
UdtRecordCompleter.h [LLDB][NativePDB] Fix struct layout when it has anonymous unions. 2022-10-13 12:43:45 -07:00