2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // Ensure that the unwinder can cope with the signal handler.
11 // REQUIRES: target={{(aarch64|riscv64|s390x|x86_64)-.+linux.*}}
13 // TODO: Figure out why this fails with Memory Sanitizer.
23 #include <sys/types.h>
27 _Unwind_Reason_Code
frame_handler(struct _Unwind_Context
* ctx
, void* arg
) {
29 Dl_info info
= { 0, 0, 0, 0 };
31 // Unwind util the main is reached, above frames depend on the platform and
33 if (dladdr(reinterpret_cast<void *>(_Unwind_GetIP(ctx
)), &info
) &&
34 info
.dli_sname
&& !strcmp("main", info
.dli_sname
)) {
37 return _URC_NO_REASON
;
40 void signal_handler(int signum
) {
42 _Unwind_Backtrace(frame_handler
, NULL
);
46 int main(int, char**) {
47 signal(SIGUSR1
, signal_handler
);
48 kill(getpid(), SIGUSR1
);