summaryrefslogtreecommitdiff
path: root/test/tsan/debug_locate.cc
diff options
context:
space:
mode:
authorKuba Mracek <mracek@apple.com>2016-12-19 17:52:20 +0000
committerKuba Mracek <mracek@apple.com>2016-12-19 17:52:20 +0000
commit738b5d632334eebef26de214156f53e3074b13bd (patch)
tree6ec10c257c4a8d94f3e543d898f99c24976da579 /test/tsan/debug_locate.cc
parent1b9e1ee0c7a5a30d1621e3409d21871140cbc049 (diff)
[tsan] Implement __tsan_get_alloc_stack and __tsan_locate_address to query pointer types and allocation stacks of heap pointers
In ASan, we have __asan_locate_address and __asan_get_alloc_stack, which is used in LLDB/Xcode to show the allocation backtrace for a heap memory object. This patch implements the same for TSan. Differential Revision: https://reviews.llvm.org/D27656 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290119 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/debug_locate.cc')
-rw-r--r--test/tsan/debug_locate.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/tsan/debug_locate.cc b/test/tsan/debug_locate.cc
new file mode 100644
index 000000000..6f88b6f13
--- /dev/null
+++ b/test/tsan/debug_locate.cc
@@ -0,0 +1,43 @@
+// RUN: %clangxx_tsan -O0 %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <stdlib.h>
+
+extern "C" const char *
+__tsan_locate_address(void *addr, char *name, size_t name_size,
+ void **region_address_ptr, size_t *region_size_ptr);
+
+long global_var;
+
+int main() {
+ long stack_var;
+ void *heap_var = malloc(10);
+
+ fprintf(stderr, "stack_var = %p\n", &stack_var);
+ fprintf(stderr, "global_var = %p\n", &global_var);
+ fprintf(stderr, "heap_var = %p\n", heap_var);
+ // CHECK: stack_var = [[STACK_VAR:0x[0-9a-f]+]]
+ // CHECK: global_var = [[GLOBAL_VAR:0x[0-9a-f]+]]
+ // CHECK: heap_var = [[HEAP_VAR:0x[0-9a-f]+]]
+
+ const char *type;
+ char name[128];
+ void *start;
+ size_t size;
+ type = __tsan_locate_address(&stack_var, name, 128, &start, &size);
+ fprintf(stderr, "type: %s\n", type);
+ // CHECK: type: stack
+
+ type = __tsan_locate_address(&global_var, name, 128, &start, &size);
+ fprintf(stderr, "type: %s, name = %s, start = %p, size = %zu\n", type, name,
+ start, size);
+ // CHECK: type: global, name = global_var, start = [[GLOBAL_VAR]], size = 8
+
+ type = __tsan_locate_address(heap_var, name, 128, &start, &size);
+ fprintf(stderr, "type: %s, start = %p, size = %zu\n", type, start, size);
+ // CHECK: type: heap, start = [[HEAP_VAR]], size = 10
+
+ free(heap_var);
+ return 0;
+}