Skip to content

Commit 3c84fc0

Browse files
committed
[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 (cherry picked from commit adc5168)
1 parent 670b79b commit 3c84fc0

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ extern "C"
8888
int (*ptr__tsan_get_report_loc_object_type)(void *report, unsigned long idx, const char **object_type);
8989
int (*ptr__tsan_get_report_tag)(void *report, unsigned long *tag);
9090
}
91+
)";
92+
93+
const char *thread_sanitizer_retrieve_report_data_command = R"(
9194
9295
const int REPORT_TRACE_SIZE = 128;
9396
const int REPORT_ARRAY_SIZE = 4;
@@ -156,11 +159,7 @@ struct data {
156159
int idx;
157160
int tid;
158161
} unique_tids[REPORT_ARRAY_SIZE];
159-
};
160-
)";
161-
162-
const char *thread_sanitizer_retrieve_report_data_command = R"(
163-
data t = {0};
162+
} t = {0};
164163
165164
ptr__tsan_get_report_loc_object_type = (typeof(ptr__tsan_get_report_loc_object_type))(void *)dlsym((void*)-2 /*RTLD_DEFAULT*/, "__tsan_get_report_loc_object_type");
166165
ptr__tsan_get_report_tag = (typeof(ptr__tsan_get_report_tag))(void *)dlsym((void*)-2 /*RTLD_DEFAULT*/, "__tsan_get_report_tag");

lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,18 @@ __ubsan_get_current_report_data(const char **OutIssueKind,
6767
const char **OutMessage, const char **OutFilename, unsigned *OutLine,
6868
unsigned *OutCol, char **OutMemoryAddr);
6969
}
70+
)";
7071

71-
struct data {
72+
static const char *ub_sanitizer_retrieve_report_data_command = R"(
73+
struct {
7274
const char *issue_kind;
7375
const char *message;
7476
const char *filename;
7577
unsigned line;
7678
unsigned col;
7779
char *memory_addr;
78-
};
79-
)";
80+
} t;
8081
81-
static const char *ub_sanitizer_retrieve_report_data_command = R"(
82-
data t;
8382
__ubsan_get_current_report_data(&t.issue_kind, &t.message, &t.filename, &t.line,
8483
&t.col, &t.memory_addr);
8584
t;

lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,19 @@ const char *memory_history_asan_command_prefix = R"(
6767
size_t __asan_get_alloc_stack(void *addr, void **trace, size_t size, int *thread_id);
6868
size_t __asan_get_free_stack(void *addr, void **trace, size_t size, int *thread_id);
6969
}
70+
)";
7071

71-
struct data {
72+
const char *memory_history_asan_command_format =
73+
R"(
74+
struct {
7275
void *alloc_trace[256];
7376
size_t alloc_count;
7477
int alloc_tid;
7578
7679
void *free_trace[256];
7780
size_t free_count;
7881
int free_tid;
79-
};
80-
)";
81-
82-
const char *memory_history_asan_command_format =
83-
R"(
84-
data t;
82+
} t;
8583
8684
t.alloc_count = __asan_get_alloc_stack((void *)0x%)" PRIx64
8785
R"(, t.alloc_trace, 256, &t.alloc_tid);

0 commit comments

Comments
 (0)