]>
git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/sanitizer_common/TestCases/get_module_and_offset_for_pc.cc
1 // RUN: %clangxx -DSHARED %s -shared -o %T/get_module_and_offset_for_pc.so -fPIC
2 // RUN: %clangxx -DSO_DIR=\"%T\" -O0 %s -ldl -o %t
3 // RUN: %run %t 2>&1 | FileCheck %s
4 // UNSUPPORTED: i386-darwin
6 // Tests __sanitizer_get_module_and_offset_for_pc.
10 #include <sanitizer/common_interface_defs.h>
15 int foo() { return 1; }
19 void Test(void *pc
, const char *name
) {
20 char module_name
[1024];
22 int ok
= __sanitizer_get_module_and_offset_for_pc(
23 pc
, module_name
, sizeof(module_name
), &offset
);
25 printf("NOT FOUND %s: %p\n", name
, pc
);
27 printf("FOUND %s: %s %p\n", name
, module_name
, offset
);
31 void TestCallerPc() { Test(__builtin_return_address(0), "callerpc"); }
34 void *handle
= dlopen(SO_DIR
"/get_module_and_offset_for_pc.so", RTLD_LAZY
);
36 void *foo
= dlsym(handle
, "foo");
42 // Call __sanitizer_get_module_and_offset_for_pc lots of times
43 // to make sure it is not too slow.
45 void *pc
= __builtin_return_address(0);
46 char module_name
[1024];
48 for (int i
= 0; i
< 1000000; ++i
) {
49 __sanitizer_get_module_and_offset_for_pc(pc
, module_name
,
50 sizeof(module_name
), &offset
);
61 // CHECK: NOT FOUND null: {{.*}}
62 // CHECK-NEXT: FOUND callerpc: {{.*}}/get_module_and_offset_for_pc.cc.tmp {{.*}}
63 // CHECK-NEXT: FOUND foo: {{.*}}/get_module_and_offset_for_pc.so {{.*}}