pf2 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -2
- data/Cargo.lock +650 -0
- data/Cargo.toml +3 -0
- data/README.md +110 -13
- data/Rakefile +8 -0
- data/crates/backtrace-sys2/.gitignore +1 -0
- data/crates/backtrace-sys2/Cargo.toml +9 -0
- data/crates/backtrace-sys2/build.rs +48 -0
- data/crates/backtrace-sys2/src/lib.rs +5 -0
- data/crates/backtrace-sys2/src/libbacktrace/.gitignore +15 -0
- data/crates/backtrace-sys2/src/libbacktrace/Isaac.Newton-Opticks.txt +9286 -0
- data/crates/backtrace-sys2/src/libbacktrace/LICENSE +29 -0
- data/crates/backtrace-sys2/src/libbacktrace/Makefile.am +623 -0
- data/crates/backtrace-sys2/src/libbacktrace/Makefile.in +2666 -0
- data/crates/backtrace-sys2/src/libbacktrace/README.md +36 -0
- data/crates/backtrace-sys2/src/libbacktrace/aclocal.m4 +864 -0
- data/crates/backtrace-sys2/src/libbacktrace/alloc.c +167 -0
- data/crates/backtrace-sys2/src/libbacktrace/allocfail.c +136 -0
- data/crates/backtrace-sys2/src/libbacktrace/allocfail.sh +104 -0
- data/crates/backtrace-sys2/src/libbacktrace/atomic.c +113 -0
- data/crates/backtrace-sys2/src/libbacktrace/backtrace-supported.h.in +66 -0
- data/crates/backtrace-sys2/src/libbacktrace/backtrace.c +129 -0
- data/crates/backtrace-sys2/src/libbacktrace/backtrace.h +189 -0
- data/crates/backtrace-sys2/src/libbacktrace/btest.c +501 -0
- data/crates/backtrace-sys2/src/libbacktrace/compile +348 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/enable.m4 +38 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/lead-dot.m4 +31 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/libtool.m4 +7436 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/ltoptions.m4 +369 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/ltsugar.m4 +123 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/ltversion.m4 +23 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/lt~obsolete.m4 +98 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/multi.m4 +68 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/override.m4 +117 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/unwind_ipinfo.m4 +37 -0
- data/crates/backtrace-sys2/src/libbacktrace/config/warnings.m4 +227 -0
- data/crates/backtrace-sys2/src/libbacktrace/config.guess +1700 -0
- data/crates/backtrace-sys2/src/libbacktrace/config.h.in +182 -0
- data/crates/backtrace-sys2/src/libbacktrace/config.sub +1885 -0
- data/crates/backtrace-sys2/src/libbacktrace/configure +15740 -0
- data/crates/backtrace-sys2/src/libbacktrace/configure.ac +613 -0
- data/crates/backtrace-sys2/src/libbacktrace/dwarf.c +4402 -0
- data/crates/backtrace-sys2/src/libbacktrace/edtest.c +120 -0
- data/crates/backtrace-sys2/src/libbacktrace/edtest2.c +43 -0
- data/crates/backtrace-sys2/src/libbacktrace/elf.c +7443 -0
- data/crates/backtrace-sys2/src/libbacktrace/fileline.c +407 -0
- data/crates/backtrace-sys2/src/libbacktrace/filenames.h +52 -0
- data/crates/backtrace-sys2/src/libbacktrace/filetype.awk +13 -0
- data/crates/backtrace-sys2/src/libbacktrace/install-debuginfo-for-buildid.sh.in +65 -0
- data/crates/backtrace-sys2/src/libbacktrace/install-sh +501 -0
- data/crates/backtrace-sys2/src/libbacktrace/instrumented_alloc.c +114 -0
- data/crates/backtrace-sys2/src/libbacktrace/internal.h +389 -0
- data/crates/backtrace-sys2/src/libbacktrace/libtool.m4 +7436 -0
- data/crates/backtrace-sys2/src/libbacktrace/ltmain.sh +8636 -0
- data/crates/backtrace-sys2/src/libbacktrace/ltoptions.m4 +369 -0
- data/crates/backtrace-sys2/src/libbacktrace/ltsugar.m4 +123 -0
- data/crates/backtrace-sys2/src/libbacktrace/ltversion.m4 +23 -0
- data/crates/backtrace-sys2/src/libbacktrace/lt~obsolete.m4 +98 -0
- data/crates/backtrace-sys2/src/libbacktrace/macho.c +1355 -0
- data/crates/backtrace-sys2/src/libbacktrace/missing +215 -0
- data/crates/backtrace-sys2/src/libbacktrace/mmap.c +331 -0
- data/crates/backtrace-sys2/src/libbacktrace/mmapio.c +110 -0
- data/crates/backtrace-sys2/src/libbacktrace/move-if-change +83 -0
- data/crates/backtrace-sys2/src/libbacktrace/mtest.c +410 -0
- data/crates/backtrace-sys2/src/libbacktrace/nounwind.c +66 -0
- data/crates/backtrace-sys2/src/libbacktrace/pecoff.c +957 -0
- data/crates/backtrace-sys2/src/libbacktrace/posix.c +104 -0
- data/crates/backtrace-sys2/src/libbacktrace/print.c +92 -0
- data/crates/backtrace-sys2/src/libbacktrace/read.c +110 -0
- data/crates/backtrace-sys2/src/libbacktrace/simple.c +108 -0
- data/crates/backtrace-sys2/src/libbacktrace/sort.c +108 -0
- data/crates/backtrace-sys2/src/libbacktrace/state.c +72 -0
- data/crates/backtrace-sys2/src/libbacktrace/stest.c +137 -0
- data/crates/backtrace-sys2/src/libbacktrace/test-driver +148 -0
- data/crates/backtrace-sys2/src/libbacktrace/test_format.c +55 -0
- data/crates/backtrace-sys2/src/libbacktrace/testlib.c +234 -0
- data/crates/backtrace-sys2/src/libbacktrace/testlib.h +110 -0
- data/crates/backtrace-sys2/src/libbacktrace/ttest.c +161 -0
- data/crates/backtrace-sys2/src/libbacktrace/unittest.c +92 -0
- data/crates/backtrace-sys2/src/libbacktrace/unknown.c +65 -0
- data/crates/backtrace-sys2/src/libbacktrace/xcoff.c +1606 -0
- data/crates/backtrace-sys2/src/libbacktrace/xztest.c +508 -0
- data/crates/backtrace-sys2/src/libbacktrace/zstdtest.c +523 -0
- data/crates/backtrace-sys2/src/libbacktrace/ztest.c +541 -0
- data/ext/pf2/Cargo.toml +25 -0
- data/ext/pf2/build.rs +3 -0
- data/ext/pf2/extconf.rb +6 -1
- data/ext/pf2/src/backtrace.rs +126 -0
- data/ext/pf2/src/lib.rs +15 -0
- data/ext/pf2/src/profile.rs +65 -0
- data/ext/pf2/src/profile_serializer.rs +204 -0
- data/ext/pf2/src/ringbuffer.rs +152 -0
- data/ext/pf2/src/ruby_init.rs +74 -0
- data/ext/pf2/src/sample.rs +66 -0
- data/ext/pf2/src/siginfo_t.c +5 -0
- data/ext/pf2/src/signal_scheduler/configuration.rs +31 -0
- data/ext/pf2/src/signal_scheduler/timer_installer.rs +199 -0
- data/ext/pf2/src/signal_scheduler.rs +311 -0
- data/ext/pf2/src/timer_thread_scheduler.rs +319 -0
- data/ext/pf2/src/util.rs +30 -0
- data/lib/pf2/cli.rb +1 -1
- data/lib/pf2/reporter.rb +48 -16
- data/lib/pf2/version.rb +1 -1
- data/lib/pf2.rb +20 -5
- metadata +128 -5
- data/ext/pf2/pf2.c +0 -246
@@ -0,0 +1,407 @@
|
|
1
|
+
/* fileline.c -- Get file and line number information in a backtrace.
|
2
|
+
Copyright (C) 2012-2021 Free Software Foundation, Inc.
|
3
|
+
Written by Ian Lance Taylor, Google.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are
|
7
|
+
met:
|
8
|
+
|
9
|
+
(1) Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
(2) Redistributions in binary form must reproduce the above copyright
|
13
|
+
notice, this list of conditions and the following disclaimer in
|
14
|
+
the documentation and/or other materials provided with the
|
15
|
+
distribution.
|
16
|
+
|
17
|
+
(3) The name of the author may not be used to
|
18
|
+
endorse or promote products derived from this software without
|
19
|
+
specific prior written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
22
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
23
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
25
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
26
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
28
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
29
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
30
|
+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
POSSIBILITY OF SUCH DAMAGE. */
|
32
|
+
|
33
|
+
#include "config.h"
|
34
|
+
|
35
|
+
#include <sys/types.h>
|
36
|
+
#include <sys/stat.h>
|
37
|
+
#include <errno.h>
|
38
|
+
#include <fcntl.h>
|
39
|
+
#include <stdlib.h>
|
40
|
+
#include <unistd.h>
|
41
|
+
|
42
|
+
#if defined (HAVE_KERN_PROC_ARGS) || defined (HAVE_KERN_PROC)
|
43
|
+
#include <sys/sysctl.h>
|
44
|
+
#endif
|
45
|
+
|
46
|
+
#ifdef HAVE_MACH_O_DYLD_H
|
47
|
+
#include <mach-o/dyld.h>
|
48
|
+
#endif
|
49
|
+
|
50
|
+
#ifdef HAVE_WINDOWS_H
|
51
|
+
#ifndef WIN32_MEAN_AND_LEAN
|
52
|
+
#define WIN32_MEAN_AND_LEAN
|
53
|
+
#endif
|
54
|
+
|
55
|
+
#ifndef NOMINMAX
|
56
|
+
#define NOMINMAX
|
57
|
+
#endif
|
58
|
+
|
59
|
+
#include <windows.h>
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#include "backtrace.h"
|
63
|
+
#include "internal.h"
|
64
|
+
|
65
|
+
#ifndef HAVE_GETEXECNAME
|
66
|
+
#define getexecname() NULL
|
67
|
+
#endif
|
68
|
+
|
69
|
+
#if !defined (HAVE_KERN_PROC_ARGS) && !defined (HAVE_KERN_PROC)
|
70
|
+
|
71
|
+
#define sysctl_exec_name1(state, error_callback, data) NULL
|
72
|
+
#define sysctl_exec_name2(state, error_callback, data) NULL
|
73
|
+
|
74
|
+
#else /* defined (HAVE_KERN_PROC_ARGS) || |defined (HAVE_KERN_PROC) */
|
75
|
+
|
76
|
+
static char *
|
77
|
+
sysctl_exec_name (struct backtrace_state *state,
|
78
|
+
int mib0, int mib1, int mib2, int mib3,
|
79
|
+
backtrace_error_callback error_callback, void *data)
|
80
|
+
{
|
81
|
+
int mib[4];
|
82
|
+
size_t len;
|
83
|
+
char *name;
|
84
|
+
size_t rlen;
|
85
|
+
|
86
|
+
mib[0] = mib0;
|
87
|
+
mib[1] = mib1;
|
88
|
+
mib[2] = mib2;
|
89
|
+
mib[3] = mib3;
|
90
|
+
|
91
|
+
if (sysctl (mib, 4, NULL, &len, NULL, 0) < 0)
|
92
|
+
return NULL;
|
93
|
+
name = (char *) backtrace_alloc (state, len, error_callback, data);
|
94
|
+
if (name == NULL)
|
95
|
+
return NULL;
|
96
|
+
rlen = len;
|
97
|
+
if (sysctl (mib, 4, name, &rlen, NULL, 0) < 0)
|
98
|
+
{
|
99
|
+
backtrace_free (state, name, len, error_callback, data);
|
100
|
+
return NULL;
|
101
|
+
}
|
102
|
+
return name;
|
103
|
+
}
|
104
|
+
|
105
|
+
#ifdef HAVE_KERN_PROC_ARGS
|
106
|
+
|
107
|
+
static char *
|
108
|
+
sysctl_exec_name1 (struct backtrace_state *state,
|
109
|
+
backtrace_error_callback error_callback, void *data)
|
110
|
+
{
|
111
|
+
/* This variant is used on NetBSD. */
|
112
|
+
return sysctl_exec_name (state, CTL_KERN, KERN_PROC_ARGS, -1,
|
113
|
+
KERN_PROC_PATHNAME, error_callback, data);
|
114
|
+
}
|
115
|
+
|
116
|
+
#else
|
117
|
+
|
118
|
+
#define sysctl_exec_name1(state, error_callback, data) NULL
|
119
|
+
|
120
|
+
#endif
|
121
|
+
|
122
|
+
#ifdef HAVE_KERN_PROC
|
123
|
+
|
124
|
+
static char *
|
125
|
+
sysctl_exec_name2 (struct backtrace_state *state,
|
126
|
+
backtrace_error_callback error_callback, void *data)
|
127
|
+
{
|
128
|
+
/* This variant is used on FreeBSD. */
|
129
|
+
return sysctl_exec_name (state, CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1,
|
130
|
+
error_callback, data);
|
131
|
+
}
|
132
|
+
|
133
|
+
#else
|
134
|
+
|
135
|
+
#define sysctl_exec_name2(state, error_callback, data) NULL
|
136
|
+
|
137
|
+
#endif
|
138
|
+
|
139
|
+
#endif /* defined (HAVE_KERN_PROC_ARGS) || |defined (HAVE_KERN_PROC) */
|
140
|
+
|
141
|
+
#ifdef HAVE_MACH_O_DYLD_H
|
142
|
+
|
143
|
+
static char *
|
144
|
+
macho_get_executable_path (struct backtrace_state *state,
|
145
|
+
backtrace_error_callback error_callback, void *data)
|
146
|
+
{
|
147
|
+
uint32_t len;
|
148
|
+
char *name;
|
149
|
+
|
150
|
+
len = 0;
|
151
|
+
if (_NSGetExecutablePath (NULL, &len) == 0)
|
152
|
+
return NULL;
|
153
|
+
name = (char *) backtrace_alloc (state, len, error_callback, data);
|
154
|
+
if (name == NULL)
|
155
|
+
return NULL;
|
156
|
+
if (_NSGetExecutablePath (name, &len) != 0)
|
157
|
+
{
|
158
|
+
backtrace_free (state, name, len, error_callback, data);
|
159
|
+
return NULL;
|
160
|
+
}
|
161
|
+
return name;
|
162
|
+
}
|
163
|
+
|
164
|
+
#else /* !defined (HAVE_MACH_O_DYLD_H) */
|
165
|
+
|
166
|
+
#define macho_get_executable_path(state, error_callback, data) NULL
|
167
|
+
|
168
|
+
#endif /* !defined (HAVE_MACH_O_DYLD_H) */
|
169
|
+
|
170
|
+
#if HAVE_DECL__PGMPTR
|
171
|
+
|
172
|
+
#define windows_executable_filename() _pgmptr
|
173
|
+
|
174
|
+
#else /* !HAVE_DECL__PGMPTR */
|
175
|
+
|
176
|
+
#define windows_executable_filename() NULL
|
177
|
+
|
178
|
+
#endif /* !HAVE_DECL__PGMPTR */
|
179
|
+
|
180
|
+
#ifdef HAVE_WINDOWS_H
|
181
|
+
|
182
|
+
#define FILENAME_BUF_SIZE (MAX_PATH)
|
183
|
+
|
184
|
+
static char *
|
185
|
+
windows_get_executable_path (char *buf, backtrace_error_callback error_callback,
|
186
|
+
void *data)
|
187
|
+
{
|
188
|
+
size_t got;
|
189
|
+
int error;
|
190
|
+
|
191
|
+
got = GetModuleFileNameA (NULL, buf, FILENAME_BUF_SIZE - 1);
|
192
|
+
error = GetLastError ();
|
193
|
+
if (got == 0
|
194
|
+
|| (got == FILENAME_BUF_SIZE - 1 && error == ERROR_INSUFFICIENT_BUFFER))
|
195
|
+
{
|
196
|
+
error_callback (data,
|
197
|
+
"could not get the filename of the current executable",
|
198
|
+
error);
|
199
|
+
return NULL;
|
200
|
+
}
|
201
|
+
return buf;
|
202
|
+
}
|
203
|
+
|
204
|
+
#else /* !defined (HAVE_WINDOWS_H) */
|
205
|
+
|
206
|
+
#define windows_get_executable_path(buf, error_callback, data) NULL
|
207
|
+
#define FILENAME_BUF_SIZE 64
|
208
|
+
|
209
|
+
#endif /* !defined (HAVE_WINDOWS_H) */
|
210
|
+
|
211
|
+
/* Initialize the fileline information from the executable. Returns 1
|
212
|
+
on success, 0 on failure. */
|
213
|
+
|
214
|
+
static int
|
215
|
+
fileline_initialize (struct backtrace_state *state,
|
216
|
+
backtrace_error_callback error_callback, void *data)
|
217
|
+
{
|
218
|
+
int failed;
|
219
|
+
fileline fileline_fn;
|
220
|
+
int pass;
|
221
|
+
int called_error_callback;
|
222
|
+
int descriptor;
|
223
|
+
const char *filename;
|
224
|
+
char buf[FILENAME_BUF_SIZE];
|
225
|
+
|
226
|
+
if (!state->threaded)
|
227
|
+
failed = state->fileline_initialization_failed;
|
228
|
+
else
|
229
|
+
failed = backtrace_atomic_load_int (&state->fileline_initialization_failed);
|
230
|
+
|
231
|
+
if (failed)
|
232
|
+
{
|
233
|
+
error_callback (data, "failed to read executable information", -1);
|
234
|
+
return 0;
|
235
|
+
}
|
236
|
+
|
237
|
+
if (!state->threaded)
|
238
|
+
fileline_fn = state->fileline_fn;
|
239
|
+
else
|
240
|
+
fileline_fn = backtrace_atomic_load_pointer (&state->fileline_fn);
|
241
|
+
if (fileline_fn != NULL)
|
242
|
+
return 1;
|
243
|
+
|
244
|
+
/* We have not initialized the information. Do it now. */
|
245
|
+
|
246
|
+
descriptor = -1;
|
247
|
+
called_error_callback = 0;
|
248
|
+
for (pass = 0; pass < 10; ++pass)
|
249
|
+
{
|
250
|
+
int does_not_exist;
|
251
|
+
|
252
|
+
switch (pass)
|
253
|
+
{
|
254
|
+
case 0:
|
255
|
+
filename = state->filename;
|
256
|
+
break;
|
257
|
+
case 1:
|
258
|
+
filename = getexecname ();
|
259
|
+
break;
|
260
|
+
case 2:
|
261
|
+
/* Test this before /proc/self/exe, as the latter exists but points
|
262
|
+
to the wine binary (and thus doesn't work). */
|
263
|
+
filename = windows_executable_filename ();
|
264
|
+
break;
|
265
|
+
case 3:
|
266
|
+
filename = "/proc/self/exe";
|
267
|
+
break;
|
268
|
+
case 4:
|
269
|
+
filename = "/proc/curproc/file";
|
270
|
+
break;
|
271
|
+
case 5:
|
272
|
+
snprintf (buf, sizeof (buf), "/proc/%ld/object/a.out",
|
273
|
+
(long) getpid ());
|
274
|
+
filename = buf;
|
275
|
+
break;
|
276
|
+
case 6:
|
277
|
+
filename = sysctl_exec_name1 (state, error_callback, data);
|
278
|
+
break;
|
279
|
+
case 7:
|
280
|
+
filename = sysctl_exec_name2 (state, error_callback, data);
|
281
|
+
break;
|
282
|
+
case 8:
|
283
|
+
filename = macho_get_executable_path (state, error_callback, data);
|
284
|
+
break;
|
285
|
+
case 9:
|
286
|
+
filename = windows_get_executable_path (buf, error_callback, data);
|
287
|
+
break;
|
288
|
+
default:
|
289
|
+
abort ();
|
290
|
+
}
|
291
|
+
|
292
|
+
if (filename == NULL)
|
293
|
+
continue;
|
294
|
+
|
295
|
+
descriptor = backtrace_open (filename, error_callback, data,
|
296
|
+
&does_not_exist);
|
297
|
+
if (descriptor < 0 && !does_not_exist)
|
298
|
+
{
|
299
|
+
called_error_callback = 1;
|
300
|
+
break;
|
301
|
+
}
|
302
|
+
if (descriptor >= 0)
|
303
|
+
break;
|
304
|
+
}
|
305
|
+
|
306
|
+
if (descriptor < 0)
|
307
|
+
{
|
308
|
+
if (!called_error_callback)
|
309
|
+
{
|
310
|
+
if (state->filename != NULL)
|
311
|
+
error_callback (data, state->filename, ENOENT);
|
312
|
+
else
|
313
|
+
error_callback (data,
|
314
|
+
"libbacktrace could not find executable to open",
|
315
|
+
0);
|
316
|
+
}
|
317
|
+
failed = 1;
|
318
|
+
}
|
319
|
+
|
320
|
+
if (!failed)
|
321
|
+
{
|
322
|
+
if (!backtrace_initialize (state, filename, descriptor, error_callback,
|
323
|
+
data, &fileline_fn))
|
324
|
+
failed = 1;
|
325
|
+
}
|
326
|
+
|
327
|
+
if (failed)
|
328
|
+
{
|
329
|
+
if (!state->threaded)
|
330
|
+
state->fileline_initialization_failed = 1;
|
331
|
+
else
|
332
|
+
backtrace_atomic_store_int (&state->fileline_initialization_failed, 1);
|
333
|
+
return 0;
|
334
|
+
}
|
335
|
+
|
336
|
+
if (!state->threaded)
|
337
|
+
state->fileline_fn = fileline_fn;
|
338
|
+
else
|
339
|
+
{
|
340
|
+
backtrace_atomic_store_pointer (&state->fileline_fn, fileline_fn);
|
341
|
+
|
342
|
+
/* Note that if two threads initialize at once, one of the data
|
343
|
+
sets may be leaked. */
|
344
|
+
}
|
345
|
+
|
346
|
+
return 1;
|
347
|
+
}
|
348
|
+
|
349
|
+
/* Given a PC, find the file name, line number, and function name. */
|
350
|
+
|
351
|
+
int
|
352
|
+
backtrace_pcinfo (struct backtrace_state *state, uintptr_t pc,
|
353
|
+
backtrace_full_callback callback,
|
354
|
+
backtrace_error_callback error_callback, void *data)
|
355
|
+
{
|
356
|
+
if (!fileline_initialize (state, error_callback, data))
|
357
|
+
return 0;
|
358
|
+
|
359
|
+
if (state->fileline_initialization_failed)
|
360
|
+
return 0;
|
361
|
+
|
362
|
+
return state->fileline_fn (state, pc, callback, error_callback, data);
|
363
|
+
}
|
364
|
+
|
365
|
+
/* Given a PC, find the symbol for it, and its value. */
|
366
|
+
|
367
|
+
int
|
368
|
+
backtrace_syminfo (struct backtrace_state *state, uintptr_t pc,
|
369
|
+
backtrace_syminfo_callback callback,
|
370
|
+
backtrace_error_callback error_callback, void *data)
|
371
|
+
{
|
372
|
+
if (!fileline_initialize (state, error_callback, data))
|
373
|
+
return 0;
|
374
|
+
|
375
|
+
if (state->fileline_initialization_failed)
|
376
|
+
return 0;
|
377
|
+
|
378
|
+
state->syminfo_fn (state, pc, callback, error_callback, data);
|
379
|
+
return 1;
|
380
|
+
}
|
381
|
+
|
382
|
+
/* A backtrace_syminfo_callback that can call into a
|
383
|
+
backtrace_full_callback, used when we have a symbol table but no
|
384
|
+
debug info. */
|
385
|
+
|
386
|
+
void
|
387
|
+
backtrace_syminfo_to_full_callback (void *data, uintptr_t pc,
|
388
|
+
const char *symname,
|
389
|
+
uintptr_t symval ATTRIBUTE_UNUSED,
|
390
|
+
uintptr_t symsize ATTRIBUTE_UNUSED)
|
391
|
+
{
|
392
|
+
struct backtrace_call_full *bdata = (struct backtrace_call_full *) data;
|
393
|
+
|
394
|
+
bdata->ret = bdata->full_callback (bdata->full_data, pc, NULL, 0, symname);
|
395
|
+
}
|
396
|
+
|
397
|
+
/* An error callback that corresponds to
|
398
|
+
backtrace_syminfo_to_full_callback. */
|
399
|
+
|
400
|
+
void
|
401
|
+
backtrace_syminfo_to_full_error_callback (void *data, const char *msg,
|
402
|
+
int errnum)
|
403
|
+
{
|
404
|
+
struct backtrace_call_full *bdata = (struct backtrace_call_full *) data;
|
405
|
+
|
406
|
+
bdata->full_error_callback (bdata->full_data, msg, errnum);
|
407
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/* btest.c -- Filename header for libbacktrace library
|
2
|
+
Copyright (C) 2012-2018 Free Software Foundation, Inc.
|
3
|
+
Written by Ian Lance Taylor, Google.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are
|
7
|
+
met:
|
8
|
+
|
9
|
+
(1) Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
(2) Redistributions in binary form must reproduce the above copyright
|
13
|
+
notice, this list of conditions and the following disclaimer in
|
14
|
+
the documentation and/or other materials provided with the
|
15
|
+
distribution.
|
16
|
+
|
17
|
+
(3) The name of the author may not be used to
|
18
|
+
endorse or promote products derived from this software without
|
19
|
+
specific prior written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
22
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
23
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
25
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
26
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
28
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
29
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
30
|
+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
POSSIBILITY OF SUCH DAMAGE. */
|
32
|
+
|
33
|
+
#ifndef GCC_VERSION
|
34
|
+
# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#if (GCC_VERSION < 2007)
|
38
|
+
# define __attribute__(x)
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#ifndef ATTRIBUTE_UNUSED
|
42
|
+
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
43
|
+
#endif
|
44
|
+
|
45
|
+
#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
|
46
|
+
# define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == '\\')
|
47
|
+
# define HAS_DRIVE_SPEC(f) ((f)[0] != '\0' && (f)[1] == ':')
|
48
|
+
# define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || HAS_DRIVE_SPEC(f))
|
49
|
+
#else
|
50
|
+
# define IS_DIR_SEPARATOR(c) ((c) == '/')
|
51
|
+
# define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]))
|
52
|
+
#endif
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# An awk script to determine the type of a file.
|
2
|
+
/^\177ELF\001/ { if (NR == 1) { print "elf32"; exit } }
|
3
|
+
/^\177ELF\002/ { if (NR == 1) { print "elf64"; exit } }
|
4
|
+
/^\114\001/ { if (NR == 1) { print "pecoff"; exit } }
|
5
|
+
/^\144\206/ { if (NR == 1) { print "pecoff"; exit } }
|
6
|
+
/^\001\337/ { if (NR == 1) { print "xcoff32"; exit } }
|
7
|
+
/^\001\367/ { if (NR == 1) { print "xcoff64"; exit } }
|
8
|
+
/^\376\355\372\316/ { if (NR == 1) { print "macho"; exit } }
|
9
|
+
/^\316\372\355\376/ { if (NR == 1) { print "macho"; exit } }
|
10
|
+
/^\376\355\372\317/ { if (NR == 1) { print "macho"; exit } }
|
11
|
+
/^\317\372\355\376/ { if (NR == 1) { print "macho"; exit } }
|
12
|
+
/^\312\376\272\276/ { if (NR == 1) { print "macho"; exit } }
|
13
|
+
/^\276\272\376\312/ { if (NR == 1) { print "macho"; exit } }
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# install-debug-info-for-buildid.sh -- Helper script for libbacktrace library
|
4
|
+
# testing.
|
5
|
+
# Copyright (C) 2019-2021 Free Software Foundation, Inc.
|
6
|
+
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
|
19
|
+
# (3) The name of the author may not be used to
|
20
|
+
# endorse or promote products derived from this software without
|
21
|
+
# specific prior written permission.
|
22
|
+
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
# Extract build-id from src, and copy debug info of src to
|
36
|
+
# $build_id_dir/aa/bb...zz.debug.
|
37
|
+
|
38
|
+
set -e
|
39
|
+
|
40
|
+
sed=@SED@
|
41
|
+
awk=@AWK@
|
42
|
+
grep=@GREP@
|
43
|
+
objcopy=@OBJCOPY@
|
44
|
+
readelf=@READELF@
|
45
|
+
mkdir_p="@MKDIR_P@"
|
46
|
+
|
47
|
+
build_id_dir="$1"
|
48
|
+
src="$2"
|
49
|
+
|
50
|
+
buildid=$($readelf -n $src \
|
51
|
+
| $grep "Build ID" \
|
52
|
+
| $awk '{print $3}')
|
53
|
+
|
54
|
+
prefix=$(echo $buildid \
|
55
|
+
| $sed 's/^\(.\{2\}\).*/\1/')
|
56
|
+
|
57
|
+
remainder=$(echo $buildid \
|
58
|
+
| $sed 's/^.\{2\}//')
|
59
|
+
|
60
|
+
dir=$build_id_dir/$prefix
|
61
|
+
dst=$dir/$remainder.debug
|
62
|
+
|
63
|
+
$mkdir_p $dir
|
64
|
+
|
65
|
+
$objcopy --only-keep-debug $src $dst
|