1 .\" Copyright (c) 2007 Apple Inc.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of Apple Inc. ("Apple") nor the names of its
13 .\" contributors may be used to endorse or promote products derived from
14 .\" this software without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY APPLE AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .Nm backtrace_symbols ,
35 .Nm backtrace_symbols_fd ,
36 .Nm backtrace_image_offsets ,
38 .Nd call stack backtrace and display functions
48 .Fa "void* const* array"
52 .Fo backtrace_symbols_fd
53 .Fa "void* const* array"
58 .Fo backtrace_image_offsets
59 .Fa "void* const* array"
60 .Fa "struct image_offset *image_offsets"
70 These routines provide a mechanism to examine the current thread's call stack.
73 writes the function return addresses of the current call stack to the array of
74 pointers referenced by
78 pointers are written. The number of pointers actually written to
83 attempts to transform a call stack obtained by
85 into an array of human-readable strings using
87 The array of strings returned has
89 elements. It is allocated using
91 and should be released using
93 There is no need to free the individual strings in the array.
95 .Fn backtrace_symbols_fd
96 performs the same operation as
97 .Fn backtrace_symbols ,
98 but the resulting strings are immediately written to the file descriptor
100 and are not returned.
102 .Fn backtrace_image_offsets
103 attempts to transform a call stack obtained by
105 into an array of image offsets, for deferred symbolication. Each entry in the
106 array has an offset relative to the
108 section of the image with the given UUID. The results are written to
110 which should be an array of
114 .Fn backtrace_from_fp
115 takes a backtrace of frames starting from the given frame pointer.
118 #include <execinfo.h>
121 void* callstack[128];
122 int i, frames = backtrace(callstack, 128);
123 char** strs = backtrace_symbols(callstack, frames);
124 for (i = 0; i < frames; ++i) {
125 printf("%s\\n", strs[i]);
132 .Fn backtrace_symbols ,
134 .Fn backtrace_symbols_fd
135 first appeared in Mac OS X 10.5.
136 .Fn backtrace_image_offsets
138 .Fn backtrace_from_fp
139 first appeared macOS 10.14 and iOS 12.