1 .\" $NetBSD: backtrace.3,v 1.5 2013/08/22 17:08:43 christos Exp $
3 .\" Copyright (c) 2012 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nd fill in the backtrace of the currently executing thread
41 .Fn backtrace "void **addrlist" "size_t len"
43 .Fn backtrace_symbols "void * const *addrlist" "size_t len"
45 .Fn backtrace_symbols_fd "void * const *addrlist" "size_t len" "int fd"
47 .Fn backtrace_symbols_fmt "void * const *addrlist" "size_t len" "const char *fmt"
49 .Fn backtrace_symbols_fmt_fd "void * const *addrlist" "size_t len" "const char *fmt" "int fd"
53 function places into the array pointed by
55 the array of the values of the program counter for each frame called up to
58 The number of frames found (which can be fewer than
63 .Fn backtrace_symbols_fmt
64 function takes an array of previously filled addresses from
73 The formatting characters available are:
74 .Bl -tag -width a -offset indent
76 The numeric address of each element as would be printed using %p.
78 The name of the nearest function symbol (smaller than the address element)
81 if the symbol was dynamic, or looked up in the executable if static and
82 the /proc filesystem is available to determine the executable path.
84 The difference of the symbol address and the address element printed
87 The difference of the symbol addresss and the address element printed using
88 +0x%tx if non-zero, or nothing if zero.
90 The filename of the symbol as determined by
94 The array of formatted strings is returned as a contiguous memory address which
95 can be freed by a single
100 function is equivalent of calling
101 .Fn backtrace_symbols_fmt
102 with a format argument of
103 .Dv "%a <%n%D> at %f"
106 .Fn backtrace_symbols_fd
108 .Fn backtrace_symbols_fmt_fd
109 are similar to the non _fd named functions, only instead of returning
110 an array or strings, they print a new-line separated array of strings in
119 function returns the number of elements that were filled in the backtrace.
121 .Fn backtrace_symbols
123 .Fn backtrace_symbols_fmt
124 return a string array on success, and
128 Diagnostic output may also be produced by the ELF symbol lookup functions.
135 library of functions first appeared in
140 Errors should not be printed but communicated to the caller differently.
142 Because these functions use
144 this is a separate library instead of being part of libc/libutil
145 so that no library dependencies are introduced.
147 The Linux versions of the functions (there are no _fmt variants) use
155 only deals with dynamic symbols, we need to find the symbols from the main
156 portion of the program.
157 For that we need to locate the executable, and we use procfs for
158 finding it, which is not portable.