/src/wireshark/wsutil/crash_info.c
Line | Count | Source |
1 | | /* crash_info.c |
2 | | * Routines to try to provide more useful information in crash dumps. |
3 | | * |
4 | | * Wireshark - Network traffic analyzer |
5 | | * By Gerald Combs <gerald@wireshark.org> |
6 | | * Copyright 2006 Gerald Combs |
7 | | * |
8 | | * SPDX-License-Identifier: GPL-2.0-or-later |
9 | | */ |
10 | | |
11 | | #include "config.h" |
12 | | |
13 | | #include "crash_info.h" |
14 | | |
15 | | #ifdef __APPLE__ |
16 | | /* |
17 | | * Copyright 2005-2012 Apple Inc. All rights reserved. |
18 | | * |
19 | | * IMPORTANT: This Apple software is supplied to you by Apple Computer, |
20 | | * Inc. ("Apple") in consideration of your agreement to the following |
21 | | * terms, and your use, installation, modification or redistribution of |
22 | | * this Apple software constitutes acceptance of these terms. If you do |
23 | | * not agree with these terms, please do not use, install, modify or |
24 | | * redistribute this Apple software. |
25 | | * |
26 | | * In consideration of your agreement to abide by the following terms, and |
27 | | * subject to these terms, Apple grants you a personal, non-exclusive |
28 | | * license, under Apple's copyrights in this original Apple software (the |
29 | | * "Apple Software"), to use, reproduce, modify and redistribute the Apple |
30 | | * Software, with or without modifications, in source and/or binary forms; |
31 | | * provided that if you redistribute the Apple Software in its entirety and |
32 | | * without modifications, you must retain this notice and the following |
33 | | * text and disclaimers in all such redistributions of the Apple Software. |
34 | | * Neither the name, trademarks, service marks or logos of Apple Computer, |
35 | | * Inc. may be used to endorse or promote products derived from the Apple |
36 | | * Software without specific prior written permission from Apple. Except |
37 | | * as expressly stated in this notice, no other rights or licenses, express |
38 | | * or implied, are granted by Apple herein, including but not limited to |
39 | | * any patent rights that may be infringed by your derivative works or by |
40 | | * other works in which the Apple Software may be incorporated. |
41 | | * |
42 | | * The Apple Software is provided by Apple on an "AS IS" basis. APPLE |
43 | | * MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION |
44 | | * THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS |
45 | | * FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND |
46 | | * OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
47 | | * |
48 | | * IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL |
49 | | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | | * INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, |
52 | | * MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED |
53 | | * AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), |
54 | | * STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE |
55 | | * POSSIBILITY OF SUCH DAMAGE. |
56 | | */ |
57 | | |
58 | | #include <stdint.h> |
59 | | #include <stdlib.h> |
60 | | #include <stdio.h> |
61 | | #include <stdarg.h> |
62 | | |
63 | | /* |
64 | | * This used to be the way to add an application-specific string to |
65 | | * crash dumps; see |
66 | | * |
67 | | * http://www.allocinit.net/blog/2008/01/04/application-specific-information-in-leopard-crash-reports/ |
68 | | * |
69 | | * It still appears to work as of OS X 10.8 (Mountain Lion). |
70 | | */ |
71 | | __private_extern__ char *__crashreporter_info__ = NULL; |
72 | | |
73 | | #if 0 |
74 | | /* |
75 | | * And this appears to be the new way to do it, as of Lion. |
76 | | * However, if we do both, we get the message twice, so we're |
77 | | * not doing this one, for now. |
78 | | * |
79 | | * This code was lifted from SVN trunk CUPS. |
80 | | */ |
81 | | #define _crc_make_getter(attr, type) (type)(gCRAnnotations.attr) |
82 | | #define _crc_make_setter(attr, arg) (gCRAnnotations.attr = (uint64_t)(unsigned long)(arg)) |
83 | | #define CRASH_REPORTER_CLIENT_HIDDEN __attribute__((visibility("hidden"))) |
84 | | #define CRASHREPORTER_ANNOTATIONS_VERSION 4 |
85 | | #define CRASHREPORTER_ANNOTATIONS_SECTION "__crash_info" |
86 | | |
87 | | /* |
88 | | * Yes, these are all 64-bit, even on 32-bit platforms. |
89 | | * |
90 | | * version is presumably the version of this structure. |
91 | | * |
92 | | * message and message2 are reported, one after the other, |
93 | | * under "Application Specific Information". |
94 | | * |
95 | | * signature_string is reported under "Application Specific |
96 | | * Signatures". |
97 | | * |
98 | | * backtrace is reported under "Application Specific Backtrace". |
99 | | * |
100 | | * Dunno which versions are supported by which versions of macOS. |
101 | | */ |
102 | | struct crashreporter_annotations_t { |
103 | | uint64_t version; /* unsigned long */ |
104 | | uint64_t message; /* char * */ |
105 | | uint64_t signature_string; /* char * */ |
106 | | uint64_t backtrace; /* char * */ |
107 | | uint64_t message2; /* char * */ |
108 | | uint64_t thread; /* uint64_t */ |
109 | | uint64_t dialog_mode; /* unsigned int */ |
110 | | }; |
111 | | |
112 | | CRASH_REPORTER_CLIENT_HIDDEN |
113 | | struct crashreporter_annotations_t gCRAnnotations |
114 | | __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) = { |
115 | | CRASHREPORTER_ANNOTATIONS_VERSION, /* version */ |
116 | | 0, /* message */ |
117 | | 0, /* signature_string */ |
118 | | 0, /* backtrace */ |
119 | | 0, /* message2 */ |
120 | | 0, /* thread */ |
121 | | 0 /* dialog_mode */ |
122 | | }; |
123 | | |
124 | | #define CRSetCrashLogMessage(m) _crc_make_setter(message, m) |
125 | | #endif /* 0 */ |
126 | | |
127 | | void |
128 | | ws_vadd_crash_info(const char *fmt, va_list ap) |
129 | | { |
130 | | char *m, *old_info, *new_info; |
131 | | |
132 | | m = ws_strdup_vprintf(fmt, ap); |
133 | | if (__crashreporter_info__ == NULL) |
134 | | __crashreporter_info__ = m; |
135 | | else { |
136 | | old_info = __crashreporter_info__; |
137 | | new_info = ws_strdup_printf("%s\n%s", old_info, m); |
138 | | g_free(m); |
139 | | __crashreporter_info__ = new_info; |
140 | | g_free(old_info); |
141 | | } |
142 | | } |
143 | | |
144 | | #else /* __APPLE__ */ |
145 | | /* |
146 | | * Perhaps Google Breakpad (http://code.google.com/p/google-breakpad/) or |
147 | | * other options listed at |
148 | | * http://stackoverflow.com/questions/7631908/library-for-logging-call-stack-at-runtime-windows-linux |
149 | | * ? |
150 | | */ |
151 | | void |
152 | | ws_vadd_crash_info(const char *fmt _U_, va_list ap _U_) |
153 | 14 | { |
154 | 14 | } |
155 | | #endif /* __APPLE__ */ |
156 | | |
157 | | void |
158 | | ws_add_crash_info(const char *fmt, ...) |
159 | 14 | { |
160 | 14 | va_list ap; |
161 | | |
162 | 14 | va_start(ap, fmt); |
163 | 14 | ws_vadd_crash_info(fmt, ap); |
164 | | va_end(ap); |
165 | 14 | } |
166 | | |
167 | | /* |
168 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
169 | | * |
170 | | * Local variables: |
171 | | * c-basic-offset: 8 |
172 | | * tab-width: 8 |
173 | | * indent-tabs-mode: t |
174 | | * End: |
175 | | * |
176 | | * vi: set shiftwidth=8 tabstop=8 noexpandtab: |
177 | | * :indentSize=8:tabSize=8:noTabs=false: |
178 | | */ |