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 leaf function can be unwund.
11 // REQUIRES: linux && (target={{aarch64-.+}} || target={{x86_64-.+}})
19 #include <sys/types.h>
23 _Unwind_Reason_Code
frame_handler(struct _Unwind_Context
* ctx
, void* arg
) {
25 Dl_info info
= { 0, 0, 0, 0 };
27 // Unwind util the main is reached, above frames deeped on the platfrom and architecture.
28 if (dladdr(reinterpret_cast<void *>(_Unwind_GetIP(ctx
)), &info
) &&
29 info
.dli_sname
&& !strcmp("main", info
.dli_sname
)) {
32 return _URC_NO_REASON
;
35 void signal_handler(int signum
) {
37 _Unwind_Backtrace(frame_handler
, NULL
);
41 int* faultyPointer
= NULL
;
43 __attribute__((noinline
)) void crashing_leaf_func(void) {
47 int main(int, char**) {
48 signal(SIGSEGV
, signal_handler
);