llvm-project/lldb/unittests
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
..
API [LLDB] Applying clang-tidy modernize-use-override over LLDB 2022-04-22 13:29:47 -07:00
Breakpoint
Core [lldb] Remove LLDB reproducers 2022-09-19 14:43:31 -07:00
DataFormatter [nfc] [lldb] Prevent needless copies of DataExtractor 2021-08-04 20:35:53 +02:00
Disassembler Move GetControlFlowKind's logic to DisassemblerLLVMC.cpp 2022-07-26 12:05:23 -07:00
Editline Re-land "[lldb] Synchronize output through the IOHandler" 2022-03-15 12:53:46 -07:00
Expression [lldb] Remove LLDB reproducers 2022-09-19 14:43:31 -07:00
Host [lldb] Go back to process-directed signals in MainLoopTest.cpp 2022-09-06 14:00:53 +02:00
Instruction [LLDB][RISCV][NFC] Rewrite instruction in algebraic datatype 2022-10-05 19:45:28 +08:00
Interpreter [lldb] Remove LLDB reproducers 2022-09-19 14:43:31 -07:00
Language [lldb][CPlusPlusLanguage] Respect the step-avoid-regex for functions with auto return types 2022-10-10 12:50:15 +01:00
ObjectFile Change the meaning of a UUID with all zeros for data. 2022-08-30 10:17:58 -07:00
Platform [lldb] Remove LLDB reproducers 2022-09-19 14:43:31 -07:00
Process [lldb] Remove LLDB reproducers 2022-09-19 14:43:31 -07:00
ScriptInterpreter [lldb] Remove LLDB reproducers 2022-09-19 14:43:31 -07:00
Signals Store a by name list of signals with their actions in the Target 2022-05-26 14:50:33 -07:00
Symbol Revert "Remove the dependency between lib/DebugInfoDWARF and MC." 2022-10-06 14:58:34 -07:00
SymbolFile [LLDB][NativePDB] Fix struct layout when it has anonymous unions. 2022-10-13 12:43:45 -07:00
Target [lldb] Remove LLDB reproducers 2022-09-19 14:43:31 -07:00
TestingSupport Fix DW_OP_convert to resolve the CU relative offset correctly. 2022-09-12 16:53:19 -07:00
Thread [lldb] Remove LLDB reproducers 2022-09-19 14:43:31 -07:00
UnwindAssembly Update the CFA to use $sp when $fp is restored on arm64 2022-05-04 14:54:17 -07:00
Utility Include <cmath> before using std::pow() 2022-09-28 17:35:35 -07:00
debugserver [lldb] [unittests] Fix TcpListen() call in RNBSocketTest 2021-10-26 21:08:03 +02:00
tools [LLDB] Change RegisterValue::SetFromMemoryData to const RegisterInfo& 2022-10-12 08:10:24 +00:00
CMakeLists.txt lldb: Disable unittests if llvm_gtest target does not exist 2022-08-10 16:56:08 -07:00
gtest_common.h