BRL-CAD
Loading...
Searching...
No Matches
exit.h
Go to the documentation of this file.
1/* E X I T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2026 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21#ifndef BU_EXIT_H
22#define BU_EXIT_H
23
24#include "common.h"
25
26#include <stdio.h> /* for FILE */
27
28#include "bu/defines.h"
29#include "bu/hook.h"
30
31
33
34/** @{ */
35/** @file bu/exit.h */
36
37/**
38 * this routine provides a trace of the call stack to the caller,
39 * generally called either directly, via a signal handler, or through
40 * bu_bomb() with the appropriate bu_debug flags set.
41 *
42 * the implementation may use an in-process stack unwinder or an
43 * external debugger, depending on platform support.
44 *
45 * the stack backtrace will be written to the provided 'fp' file
46 * pointer. it's the caller's responsibility to open and close
47 * that pointer if necessary. If 'fp' is NULL, stdout will be used.
48 *
49 * returns truthfully if a backtrace was attempted.
50 */
51BU_EXPORT extern int bu_backtrace(FILE *fp);
52
53/**
54 * A version of bu_backtrace where the caller provides their own
55 * full path to their executable for passing to GDB, rather than
56 * having libbu attempt to determine that path.
57 *
58 * Passing NULL to argv0 makes the behavior identical to
59 * that of bu_backtrace.
60 */
61BU_EXPORT extern int bu_backtrace_app(FILE *fp, const char *argv0);
62
63/**
64 * Adds a hook to the list of bu_bomb hooks. The top (newest) one of these
65 * will be called with its associated client data and a string to be
66 * processed. Typically, these hook functions will display the output
67 * (possibly in an X window) or record it.
68 *
69 * NOTE: The hook functions are all non-PARALLEL.
70 */
71BU_EXPORT extern void bu_bomb_add_hook(bu_hook_t func, void *clientdata);
72
73/* TODO - missing functions, if we're not going to expose the bu_bomb hook
74 * list.. is this the API we want? */
79/**
80 * Abort the running process.
81 *
82 * The bu_bomb routine is called on a fatal error, generally where no
83 * recovery is possible. Error handlers may, however, be registered
84 * with BU_SETJUMP(). This routine intentionally limits calls to
85 * other functions and intentionally uses no stack variables. Just in
86 * case the application is out of memory, bu_bomb deallocates a small
87 * buffer of memory.
88 *
89 * Before termination, it optionally performs the following operations
90 * in the order listed:
91 *
92 * 1. Outputs str to standard error
93 *
94 * 2. Calls any callback functions set in the global bu_bomb_hook_list
95 * variable with str passed as an argument.
96 *
97 * 3. Jumps to any user specified error handler registered with the
98 * BU_SETJUMP() facility.
99 *
100 * 4. Outputs str to the terminal device in case standard error is
101 * redirected.
102 *
103 * 5. Aborts abnormally (via abort) if BU_DEBUG_COREDUMP is defined.
104 *
105 * 6. Exits with exit(12).
106 *
107 * Only produce a core-dump when that debugging bit is set. Note that
108 * this function is meant to be a last resort semi-graceful abort.
109 *
110 * This routine should never return unless there is a BU_SETJUMP()
111 * handler registered.
112 */
113BU_EXPORT NORETURN extern void bu_bomb(const char *str);
115
116/**
117 * Semi-graceful termination of the application that doesn't cause a
118 * stack trace, exiting with the specified status after printing the
119 * given message. It's okay for this routine to use the stack,
120 * contrary to bu_bomb's behavior since it should be called for
121 * expected termination situations.
122 *
123 * This routine should generally not be called within a library. Use
124 * bu_bomb or (better) cascade the error back up to the application.
125 *
126 * This routine should never return.
127 */
128BU_EXPORT NORETURN _BU_ATTR_PRINTF23 extern void bu_exit(int status, const char *fmt, ...);
130
131/**
132 * @brief
133 * Generate a crash report file, including a call stack backtrace and
134 * other system details.
135 */
136
137/**
138 * this routine writes out details of the currently running process to
139 * the specified file, including an informational header about the
140 * execution environment, stack trace details, kernel and hardware
141 * information, and current version information.
142 *
143 * returns truthfully if the crash report was written.
144 *
145 * due to various reasons, this routine is NOT thread-safe.
146 */
147BU_EXPORT extern int bu_crashreport(const char *filename);
149/**
150 * A version of bu_crashreport where the caller provides their own
151 * full path to their executable for passing to GDB, rather than
152 * having libbu attempt to determine that path.
153 *
154 * Passing NULL to argv0 makes the behavior identical to
155 * that of bu_crashreport.
156 */
157BU_EXPORT extern int bu_crashreport_app(const char *filename, const char *argv0);
159
160/** @} */
161
163
164#endif /* BU_EXIT_H */
165
166/*
167 * Local Variables:
168 * mode: C
169 * tab-width: 8
170 * indent-tabs-mode: t
171 * c-file-style: "stroustrup"
172 * End:
173 * ex: shiftwidth=4 tabstop=8
174 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
void bu_bomb_restore_hooks(struct bu_hook_list *save_hlp)
int bu_backtrace_app(FILE *fp, const char *argv0)
void bu_bomb_delete_all_hooks(void)
int bu_backtrace(FILE *fp)
void bu_bomb_add_hook(bu_hook_t func, void *clientdata)
int bu_crashreport_app(const char *filename, const char *argv0)
int bu_crashreport(const char *filename)
Generate a crash report file, including a call stack backtrace and other system details.
void bu_bomb_save_all_hooks(struct bu_hook_list *save_hlp)
NORETURN void bu_bomb(const char *str)
NORETURN _BU_ATTR_PRINTF23 void bu_exit(int status, const char *fmt,...)
#define _BU_ATTR_PRINTF23
Definition defines.h:95
int(* bu_hook_t)(void *, void *)
Definition hook.h:41
#define NORETURN
Definition common.h:460