2 * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
17 /* $Id: backtrace.h,v 1.2 2009/09/01 18:40:25 jinmei Exp $ */
19 /*! \file isc/backtrace.h
20 * \brief provide a back trace of the running process to help debug problems.
22 * This module tries to get a back trace of the process using some platform
23 * dependent way when available. It also manages an internal symbol table
24 * that maps function addresses used in the process to their textual symbols.
25 * This module is expected to be used to help debug when some fatal error
28 * IMPORTANT NOTE: since the (major) intended use case of this module is
29 * dumping a back trace on a fatal error, normally followed by self termination,
30 * functions defined in this module generally doesn't employ assertion checks
31 * (if it did, a program bug could cause infinite recursive calls to a
32 * backtrace function). These functions still perform minimal checks and return
33 * ISC_R_FAILURE if they detect an error, but the caller should therefore be
34 * very careful about the use of these functions, and generally discouraged to
35 * use them except in an exit path. The exception is
36 * isc_backtrace_getsymbolfromindex(), which is expected to be used in a
37 * non-error-handling context and validates arguments with assertion checks.
40 #ifndef ISC_BACKTRACE_H
41 #define ISC_BACKTRACE_H 1
47 #include <isc/types.h>
52 struct isc_backtrace_symmap {
57 extern const int isc__backtrace_nsymbols;
58 extern const isc_backtrace_symmap_t isc__backtrace_symtable[];
66 isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes);
68 * Get a back trace of the running process above this function itself. On
69 * success, addrs[i] will store the address of the call point of the i-th
70 * stack frame (addrs[0] is the caller of this function). *nframes will store
71 * the total number of frames.
73 * Requires (note that these are not ensured by assertion checks, see above):
75 *\li 'addrs' is a valid array containing at least 'maxaddrs' void * entries.
77 *\li 'nframes' must be non NULL.
84 *\li #ISC_R_NOTIMPLEMENTED
88 isc_backtrace_getsymbolfromindex(int index, const void **addrp,
89 const char **symbolp);
91 * Returns the content of the internal symbol table of the given index.
92 * On success, *addrsp and *symbolp point to the address and the symbol of
93 * the 'index'th entry of the table, respectively. If 'index' is not in the
94 * range of the symbol table, ISC_R_RANGE will be returned.
98 *\li 'addrp' must be non NULL && '*addrp' == NULL.
100 *\li 'symbolp' must be non NULL && '*symbolp' == NULL.
109 isc_backtrace_getsymbol(const void *addr, const char **symbolp,
110 unsigned long *offsetp);
112 * Searches the internal symbol table for the symbol that most matches the
113 * given 'addr'. On success, '*symbolp' will point to the name of function
114 * to which the address 'addr' belong, and '*offsetp' will store the offset
115 * from the function's entry address to 'addr'.
117 * Requires (note that these are not ensured by assertion checks, see above):
119 *\li 'symbolp' must be non NULL && '*symbolp' == NULL.
121 *\li 'offsetp' must be non NULL.
131 #endif /* ISC_BACKTRACE_H */