[lldb][InstrumentationRuntime] Make 'data' struct anonymous in order to avoid collisi...
authorMichael Buch <michaelbuch12@gmail.com>
Wed, 8 Mar 2023 11:32:06 +0000 (11:32 +0000)
committerMichael Buch <michaelbuch12@gmail.com>
Fri, 10 Mar 2023 00:40:22 +0000 (00:40 +0000)
commitadc5168d7114190ec7d931a6c346276e19b0e117
tree489440cadc9671f54ea1a673d2c38bee875e4ece
parent3ecf731376cb4661d85c10932bd7bd7c11998ad8
[lldb][InstrumentationRuntime] Make 'data' struct anonymous in order to avoid collisions with types in the debuggee

The `UBSAN`/`ASAN` plugins would previously call the internal helper
structure injected into the source expression `struct data { ... };`

This occasionally collided with user-defined types of the same (quite
common) name. In the presence of varibale with the same name LLDB would
simply fail to run the injected `InstrumentationRuntime` expressions
with:
```
warning: cannot evaluate AddressSanitizer expression:
expression failed to parse:
error: <user expression 2>:2:5: must use 'struct' tag to refer to type 'data' in this scope
    data t;
```

In the presence of another type called 'data', LLDB would most likely
crash with something like:
```
0x00000001198de614 clang::ASTNodeImporter::ImportDeclContext(clang::DeclContext*, bool) + 1088
0x00000001198de614 clang::ASTNodeImporter::ImportDeclContext(clang::DeclContext*, bool) + 1088
0x0000000119907930 clang::ASTImporter::ImportDefinition(clang::Decl*) + 596
0x00000001163db928 lldb_private::ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(clang::Decl*, clang::Decl*) + 100
0x00000001163da070 (anonymous namespace)::CompleteTagDeclsScope::~CompleteTagDeclsScope() + 572
...
```
...because it got the types confused.

This patch makes these structures anonymous so there's no
chance of clashing with other types in the program. This is
already the approach taken in `UBSan/InstrumentationRuntimeABSan.cpp`.

**Testing**

- API tests still pass
- Tested manually that the `memory history` command now works in the presence of a local called `data`

Differential Revision: https://reviews.llvm.org/D145569
lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp