pf2 0.2.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 +22 -2
- data/Cargo.lock +186 -17
- data/Cargo.toml +1 -1
- data/README.md +17 -6
- 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 +1 -0
- data/ext/pf2/src/backtrace.rs +126 -0
- data/ext/pf2/src/lib.rs +1 -0
- data/ext/pf2/src/profile.rs +16 -1
- data/ext/pf2/src/profile_serializer.rs +95 -21
- data/ext/pf2/src/ringbuffer.rs +7 -0
- data/ext/pf2/src/ruby_init.rs +18 -6
- data/ext/pf2/src/sample.rs +22 -1
- data/ext/pf2/src/signal_scheduler/configuration.rs +7 -0
- data/ext/pf2/src/signal_scheduler/timer_installer.rs +34 -27
- data/ext/pf2/src/signal_scheduler.rs +95 -26
- data/ext/pf2/src/timer_thread_scheduler.rs +88 -12
- data/ext/pf2/src/util.rs +2 -2
- data/lib/pf2/reporter.rb +12 -5
- data/lib/pf2/version.rb +1 -1
- data/lib/pf2.rb +3 -6
- metadata +96 -2
@@ -0,0 +1,104 @@
|
|
1
|
+
/* posix.c -- POSIX file I/O routines for the backtrace library.
|
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 <errno.h>
|
36
|
+
#include <sys/types.h>
|
37
|
+
#include <sys/stat.h>
|
38
|
+
#include <fcntl.h>
|
39
|
+
#include <unistd.h>
|
40
|
+
|
41
|
+
#include "backtrace.h"
|
42
|
+
#include "internal.h"
|
43
|
+
|
44
|
+
#ifndef O_BINARY
|
45
|
+
#define O_BINARY 0
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#ifndef O_CLOEXEC
|
49
|
+
#define O_CLOEXEC 0
|
50
|
+
#endif
|
51
|
+
|
52
|
+
#ifndef FD_CLOEXEC
|
53
|
+
#define FD_CLOEXEC 1
|
54
|
+
#endif
|
55
|
+
|
56
|
+
/* Open a file for reading. */
|
57
|
+
|
58
|
+
int
|
59
|
+
backtrace_open (const char *filename, backtrace_error_callback error_callback,
|
60
|
+
void *data, int *does_not_exist)
|
61
|
+
{
|
62
|
+
int descriptor;
|
63
|
+
|
64
|
+
if (does_not_exist != NULL)
|
65
|
+
*does_not_exist = 0;
|
66
|
+
|
67
|
+
descriptor = open (filename, (int) (O_RDONLY | O_BINARY | O_CLOEXEC));
|
68
|
+
if (descriptor < 0)
|
69
|
+
{
|
70
|
+
/* If DOES_NOT_EXIST is not NULL, then don't call ERROR_CALLBACK
|
71
|
+
if the file does not exist. We treat lacking permission to
|
72
|
+
open the file as the file not existing; this case arises when
|
73
|
+
running the libgo syscall package tests as root. */
|
74
|
+
if (does_not_exist != NULL && (errno == ENOENT || errno == EACCES))
|
75
|
+
*does_not_exist = 1;
|
76
|
+
else
|
77
|
+
error_callback (data, filename, errno);
|
78
|
+
return -1;
|
79
|
+
}
|
80
|
+
|
81
|
+
#ifdef HAVE_FCNTL
|
82
|
+
/* Set FD_CLOEXEC just in case the kernel does not support
|
83
|
+
O_CLOEXEC. It doesn't matter if this fails for some reason.
|
84
|
+
FIXME: At some point it should be safe to only do this if
|
85
|
+
O_CLOEXEC == 0. */
|
86
|
+
fcntl (descriptor, F_SETFD, FD_CLOEXEC);
|
87
|
+
#endif
|
88
|
+
|
89
|
+
return descriptor;
|
90
|
+
}
|
91
|
+
|
92
|
+
/* Close DESCRIPTOR. */
|
93
|
+
|
94
|
+
int
|
95
|
+
backtrace_close (int descriptor, backtrace_error_callback error_callback,
|
96
|
+
void *data)
|
97
|
+
{
|
98
|
+
if (close (descriptor) < 0)
|
99
|
+
{
|
100
|
+
error_callback (data, "close", errno);
|
101
|
+
return 0;
|
102
|
+
}
|
103
|
+
return 1;
|
104
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
/* print.c -- Print the current 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 <stdio.h>
|
36
|
+
#include <string.h>
|
37
|
+
#include <sys/types.h>
|
38
|
+
|
39
|
+
#include "backtrace.h"
|
40
|
+
#include "internal.h"
|
41
|
+
|
42
|
+
/* Passed to callbacks. */
|
43
|
+
|
44
|
+
struct print_data
|
45
|
+
{
|
46
|
+
struct backtrace_state *state;
|
47
|
+
FILE *f;
|
48
|
+
};
|
49
|
+
|
50
|
+
/* Print one level of a backtrace. */
|
51
|
+
|
52
|
+
static int
|
53
|
+
print_callback (void *data, uintptr_t pc, const char *filename, int lineno,
|
54
|
+
const char *function)
|
55
|
+
{
|
56
|
+
struct print_data *pdata = (struct print_data *) data;
|
57
|
+
|
58
|
+
fprintf (pdata->f, "0x%lx %s\n\t%s:%d\n",
|
59
|
+
(unsigned long) pc,
|
60
|
+
function == NULL ? "???" : function,
|
61
|
+
filename == NULL ? "???" : filename,
|
62
|
+
lineno);
|
63
|
+
return 0;
|
64
|
+
}
|
65
|
+
|
66
|
+
/* Print errors to stderr. */
|
67
|
+
|
68
|
+
static void
|
69
|
+
error_callback (void *data, const char *msg, int errnum)
|
70
|
+
{
|
71
|
+
struct print_data *pdata = (struct print_data *) data;
|
72
|
+
|
73
|
+
if (pdata->state->filename != NULL)
|
74
|
+
fprintf (stderr, "%s: ", pdata->state->filename);
|
75
|
+
fprintf (stderr, "libbacktrace: %s", msg);
|
76
|
+
if (errnum > 0)
|
77
|
+
fprintf (stderr, ": %s", strerror (errnum));
|
78
|
+
fputc ('\n', stderr);
|
79
|
+
}
|
80
|
+
|
81
|
+
/* Print a backtrace. */
|
82
|
+
|
83
|
+
void __attribute__((noinline))
|
84
|
+
backtrace_print (struct backtrace_state *state, int skip, FILE *f)
|
85
|
+
{
|
86
|
+
struct print_data data;
|
87
|
+
|
88
|
+
data.state = state;
|
89
|
+
data.f = f;
|
90
|
+
backtrace_full (state, skip + 1, print_callback, error_callback,
|
91
|
+
(void *) &data);
|
92
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
/* read.c -- File views without mmap.
|
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 <errno.h>
|
36
|
+
#include <stdlib.h>
|
37
|
+
#include <sys/types.h>
|
38
|
+
#include <unistd.h>
|
39
|
+
|
40
|
+
#include "backtrace.h"
|
41
|
+
#include "internal.h"
|
42
|
+
|
43
|
+
/* This file implements file views when mmap is not available. */
|
44
|
+
|
45
|
+
/* Create a view of SIZE bytes from DESCRIPTOR at OFFSET. */
|
46
|
+
|
47
|
+
int
|
48
|
+
backtrace_get_view (struct backtrace_state *state, int descriptor,
|
49
|
+
off_t offset, uint64_t size,
|
50
|
+
backtrace_error_callback error_callback,
|
51
|
+
void *data, struct backtrace_view *view)
|
52
|
+
{
|
53
|
+
uint64_t got;
|
54
|
+
ssize_t r;
|
55
|
+
|
56
|
+
if ((uint64_t) (size_t) size != size)
|
57
|
+
{
|
58
|
+
error_callback (data, "file size too large", 0);
|
59
|
+
return 0;
|
60
|
+
}
|
61
|
+
|
62
|
+
if (lseek (descriptor, offset, SEEK_SET) < 0)
|
63
|
+
{
|
64
|
+
error_callback (data, "lseek", errno);
|
65
|
+
return 0;
|
66
|
+
}
|
67
|
+
|
68
|
+
view->base = backtrace_alloc (state, size, error_callback, data);
|
69
|
+
if (view->base == NULL)
|
70
|
+
return 0;
|
71
|
+
view->data = view->base;
|
72
|
+
view->len = size;
|
73
|
+
|
74
|
+
got = 0;
|
75
|
+
while (got < size)
|
76
|
+
{
|
77
|
+
r = read (descriptor, view->base, size - got);
|
78
|
+
if (r < 0)
|
79
|
+
{
|
80
|
+
error_callback (data, "read", errno);
|
81
|
+
free (view->base);
|
82
|
+
return 0;
|
83
|
+
}
|
84
|
+
if (r == 0)
|
85
|
+
break;
|
86
|
+
got += (uint64_t) r;
|
87
|
+
}
|
88
|
+
|
89
|
+
if (got < size)
|
90
|
+
{
|
91
|
+
error_callback (data, "file too short", 0);
|
92
|
+
free (view->base);
|
93
|
+
return 0;
|
94
|
+
}
|
95
|
+
|
96
|
+
return 1;
|
97
|
+
}
|
98
|
+
|
99
|
+
/* Release a view read by backtrace_get_view. */
|
100
|
+
|
101
|
+
void
|
102
|
+
backtrace_release_view (struct backtrace_state *state,
|
103
|
+
struct backtrace_view *view,
|
104
|
+
backtrace_error_callback error_callback,
|
105
|
+
void *data)
|
106
|
+
{
|
107
|
+
backtrace_free (state, view->base, view->len, error_callback, data);
|
108
|
+
view->data = NULL;
|
109
|
+
view->base = NULL;
|
110
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/* simple.c -- The backtrace_simple function.
|
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 "unwind.h"
|
36
|
+
#include "backtrace.h"
|
37
|
+
|
38
|
+
/* The simple_backtrace routine. */
|
39
|
+
|
40
|
+
/* Data passed through _Unwind_Backtrace. */
|
41
|
+
|
42
|
+
struct backtrace_simple_data
|
43
|
+
{
|
44
|
+
/* Number of frames to skip. */
|
45
|
+
int skip;
|
46
|
+
/* Library state. */
|
47
|
+
struct backtrace_state *state;
|
48
|
+
/* Callback routine. */
|
49
|
+
backtrace_simple_callback callback;
|
50
|
+
/* Error callback routine. */
|
51
|
+
backtrace_error_callback error_callback;
|
52
|
+
/* Data to pass to callback routine. */
|
53
|
+
void *data;
|
54
|
+
/* Value to return from backtrace. */
|
55
|
+
int ret;
|
56
|
+
};
|
57
|
+
|
58
|
+
/* Unwind library callback routine. This is passed to
|
59
|
+
_Unwind_Backtrace. */
|
60
|
+
|
61
|
+
static _Unwind_Reason_Code
|
62
|
+
simple_unwind (struct _Unwind_Context *context, void *vdata)
|
63
|
+
{
|
64
|
+
struct backtrace_simple_data *bdata = (struct backtrace_simple_data *) vdata;
|
65
|
+
uintptr_t pc;
|
66
|
+
int ip_before_insn = 0;
|
67
|
+
|
68
|
+
#ifdef HAVE_GETIPINFO
|
69
|
+
pc = _Unwind_GetIPInfo (context, &ip_before_insn);
|
70
|
+
#else
|
71
|
+
pc = _Unwind_GetIP (context);
|
72
|
+
#endif
|
73
|
+
|
74
|
+
if (bdata->skip > 0)
|
75
|
+
{
|
76
|
+
--bdata->skip;
|
77
|
+
return _URC_NO_REASON;
|
78
|
+
}
|
79
|
+
|
80
|
+
if (!ip_before_insn)
|
81
|
+
--pc;
|
82
|
+
|
83
|
+
bdata->ret = bdata->callback (bdata->data, pc);
|
84
|
+
|
85
|
+
if (bdata->ret != 0)
|
86
|
+
return _URC_END_OF_STACK;
|
87
|
+
|
88
|
+
return _URC_NO_REASON;
|
89
|
+
}
|
90
|
+
|
91
|
+
/* Get a simple stack backtrace. */
|
92
|
+
|
93
|
+
int __attribute__((noinline))
|
94
|
+
backtrace_simple (struct backtrace_state *state, int skip,
|
95
|
+
backtrace_simple_callback callback,
|
96
|
+
backtrace_error_callback error_callback, void *data)
|
97
|
+
{
|
98
|
+
struct backtrace_simple_data bdata;
|
99
|
+
|
100
|
+
bdata.skip = skip + 1;
|
101
|
+
bdata.state = state;
|
102
|
+
bdata.callback = callback;
|
103
|
+
bdata.error_callback = error_callback;
|
104
|
+
bdata.data = data;
|
105
|
+
bdata.ret = 0;
|
106
|
+
_Unwind_Backtrace (simple_unwind, &bdata);
|
107
|
+
return bdata.ret;
|
108
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/* sort.c -- Sort without allocating memory
|
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 <stddef.h>
|
36
|
+
#include <sys/types.h>
|
37
|
+
|
38
|
+
#include "backtrace.h"
|
39
|
+
#include "internal.h"
|
40
|
+
|
41
|
+
/* The GNU glibc version of qsort allocates memory, which we must not
|
42
|
+
do if we are invoked by a signal handler. So provide our own
|
43
|
+
sort. */
|
44
|
+
|
45
|
+
static void
|
46
|
+
swap (char *a, char *b, size_t size)
|
47
|
+
{
|
48
|
+
size_t i;
|
49
|
+
|
50
|
+
for (i = 0; i < size; i++, a++, b++)
|
51
|
+
{
|
52
|
+
char t;
|
53
|
+
|
54
|
+
t = *a;
|
55
|
+
*a = *b;
|
56
|
+
*b = t;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
void
|
61
|
+
backtrace_qsort (void *basearg, size_t count, size_t size,
|
62
|
+
int (*compar) (const void *, const void *))
|
63
|
+
{
|
64
|
+
char *base = (char *) basearg;
|
65
|
+
size_t i;
|
66
|
+
size_t mid;
|
67
|
+
|
68
|
+
tail_recurse:
|
69
|
+
if (count < 2)
|
70
|
+
return;
|
71
|
+
|
72
|
+
/* The symbol table and DWARF tables, which is all we use this
|
73
|
+
routine for, tend to be roughly sorted. Pick the middle element
|
74
|
+
in the array as our pivot point, so that we are more likely to
|
75
|
+
cut the array in half for each recursion step. */
|
76
|
+
swap (base, base + (count / 2) * size, size);
|
77
|
+
|
78
|
+
mid = 0;
|
79
|
+
for (i = 1; i < count; i++)
|
80
|
+
{
|
81
|
+
if ((*compar) (base, base + i * size) > 0)
|
82
|
+
{
|
83
|
+
++mid;
|
84
|
+
if (i != mid)
|
85
|
+
swap (base + mid * size, base + i * size, size);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
if (mid > 0)
|
90
|
+
swap (base, base + mid * size, size);
|
91
|
+
|
92
|
+
/* Recurse with the smaller array, loop with the larger one. That
|
93
|
+
ensures that our maximum stack depth is log count. */
|
94
|
+
if (2 * mid < count)
|
95
|
+
{
|
96
|
+
backtrace_qsort (base, mid, size, compar);
|
97
|
+
base += (mid + 1) * size;
|
98
|
+
count -= mid + 1;
|
99
|
+
goto tail_recurse;
|
100
|
+
}
|
101
|
+
else
|
102
|
+
{
|
103
|
+
backtrace_qsort (base + (mid + 1) * size, count - (mid + 1),
|
104
|
+
size, compar);
|
105
|
+
count = mid;
|
106
|
+
goto tail_recurse;
|
107
|
+
}
|
108
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
/* state.c -- Create the backtrace state.
|
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 <string.h>
|
36
|
+
#include <sys/types.h>
|
37
|
+
|
38
|
+
#include "backtrace.h"
|
39
|
+
#include "backtrace-supported.h"
|
40
|
+
#include "internal.h"
|
41
|
+
|
42
|
+
/* Create the backtrace state. This will then be passed to all the
|
43
|
+
other routines. */
|
44
|
+
|
45
|
+
struct backtrace_state *
|
46
|
+
backtrace_create_state (const char *filename, int threaded,
|
47
|
+
backtrace_error_callback error_callback,
|
48
|
+
void *data)
|
49
|
+
{
|
50
|
+
struct backtrace_state init_state;
|
51
|
+
struct backtrace_state *state;
|
52
|
+
|
53
|
+
#ifndef HAVE_SYNC_FUNCTIONS
|
54
|
+
if (threaded)
|
55
|
+
{
|
56
|
+
error_callback (data, "backtrace library does not support threads", 0);
|
57
|
+
return NULL;
|
58
|
+
}
|
59
|
+
#endif
|
60
|
+
|
61
|
+
memset (&init_state, 0, sizeof init_state);
|
62
|
+
init_state.filename = filename;
|
63
|
+
init_state.threaded = threaded;
|
64
|
+
|
65
|
+
state = ((struct backtrace_state *)
|
66
|
+
backtrace_alloc (&init_state, sizeof *state, error_callback, data));
|
67
|
+
if (state == NULL)
|
68
|
+
return NULL;
|
69
|
+
*state = init_state;
|
70
|
+
|
71
|
+
return state;
|
72
|
+
}
|