pf2 0.7.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/README.md +11 -0
  4. data/Rakefile +9 -2
  5. data/doc/development.md +11 -0
  6. data/examples/mandelbrot.rb +69 -0
  7. data/examples/mandelbrot_ractor.rb +77 -0
  8. data/ext/pf2/build.rs +7 -0
  9. data/ext/pf2/src/ruby_c_api_helper.c +6 -0
  10. data/ext/pf2/src/serialization/profile.rs +1 -0
  11. data/ext/pf2/src/serialization/serializer.rs +4 -0
  12. data/ext/pf2/src/signal_scheduler.rs +1 -1
  13. data/ext/pf2/src/util.rs +2 -1
  14. data/ext/pf2c/backtrace_state.c +10 -0
  15. data/ext/pf2c/backtrace_state.h +10 -0
  16. data/ext/pf2c/configuration.c +90 -0
  17. data/ext/pf2c/configuration.h +23 -0
  18. data/ext/pf2c/extconf.rb +21 -0
  19. data/ext/pf2c/pf2.c +17 -0
  20. data/ext/pf2c/pf2.h +8 -0
  21. data/ext/pf2c/ringbuffer.c +74 -0
  22. data/ext/pf2c/ringbuffer.h +24 -0
  23. data/ext/pf2c/sample.c +70 -0
  24. data/ext/pf2c/sample.h +22 -0
  25. data/ext/pf2c/serializer.c +377 -0
  26. data/ext/pf2c/serializer.h +58 -0
  27. data/ext/pf2c/session.c +344 -0
  28. data/ext/pf2c/session.h +51 -0
  29. data/lib/pf2/cli.rb +33 -2
  30. data/lib/pf2/reporter/annotate.rb +101 -0
  31. data/lib/pf2/reporter/firefox_profiler.rb +1 -1
  32. data/lib/pf2/reporter/firefox_profiler_ser2.rb +308 -0
  33. data/lib/pf2/reporter.rb +2 -0
  34. data/lib/pf2/version.rb +1 -1
  35. data/vendor/libbacktrace/.gitignore +5 -0
  36. data/vendor/libbacktrace/Isaac.Newton-Opticks.txt +9286 -0
  37. data/vendor/libbacktrace/LICENSE +29 -0
  38. data/vendor/libbacktrace/Makefile.am +708 -0
  39. data/vendor/libbacktrace/Makefile.in +2820 -0
  40. data/vendor/libbacktrace/README.md +46 -0
  41. data/vendor/libbacktrace/aclocal.m4 +864 -0
  42. data/vendor/libbacktrace/alloc.c +167 -0
  43. data/vendor/libbacktrace/allocfail.c +136 -0
  44. data/vendor/libbacktrace/allocfail.sh +104 -0
  45. data/vendor/libbacktrace/atomic.c +113 -0
  46. data/vendor/libbacktrace/backtrace-supported.h.in +66 -0
  47. data/vendor/libbacktrace/backtrace.c +129 -0
  48. data/vendor/libbacktrace/backtrace.h +189 -0
  49. data/vendor/libbacktrace/btest.c +517 -0
  50. data/vendor/libbacktrace/compile +348 -0
  51. data/vendor/libbacktrace/config/enable.m4 +38 -0
  52. data/vendor/libbacktrace/config/lead-dot.m4 +31 -0
  53. data/vendor/libbacktrace/config/libtool.m4 +7545 -0
  54. data/vendor/libbacktrace/config/ltoptions.m4 +369 -0
  55. data/vendor/libbacktrace/config/ltsugar.m4 +123 -0
  56. data/vendor/libbacktrace/config/ltversion.m4 +23 -0
  57. data/vendor/libbacktrace/config/lt~obsolete.m4 +98 -0
  58. data/vendor/libbacktrace/config/multi.m4 +68 -0
  59. data/vendor/libbacktrace/config/override.m4 +117 -0
  60. data/vendor/libbacktrace/config/unwind_ipinfo.m4 +37 -0
  61. data/vendor/libbacktrace/config/warnings.m4 +227 -0
  62. data/vendor/libbacktrace/config.guess +1700 -0
  63. data/vendor/libbacktrace/config.h.in +185 -0
  64. data/vendor/libbacktrace/config.sub +1885 -0
  65. data/vendor/libbacktrace/configure +15952 -0
  66. data/vendor/libbacktrace/configure.ac +642 -0
  67. data/vendor/libbacktrace/dwarf.c +4593 -0
  68. data/vendor/libbacktrace/edtest.c +120 -0
  69. data/vendor/libbacktrace/edtest2.c +43 -0
  70. data/vendor/libbacktrace/elf.c +7471 -0
  71. data/vendor/libbacktrace/fileline.c +407 -0
  72. data/vendor/libbacktrace/filenames.h +52 -0
  73. data/vendor/libbacktrace/filetype.awk +13 -0
  74. data/vendor/libbacktrace/install-debuginfo-for-buildid.sh.in +65 -0
  75. data/vendor/libbacktrace/install-sh +501 -0
  76. data/vendor/libbacktrace/instrumented_alloc.c +114 -0
  77. data/vendor/libbacktrace/internal.h +428 -0
  78. data/vendor/libbacktrace/ltmain.sh +8636 -0
  79. data/vendor/libbacktrace/macho.c +1361 -0
  80. data/vendor/libbacktrace/missing +215 -0
  81. data/vendor/libbacktrace/mmap.c +331 -0
  82. data/vendor/libbacktrace/mmapio.c +110 -0
  83. data/vendor/libbacktrace/move-if-change +83 -0
  84. data/vendor/libbacktrace/mtest.c +410 -0
  85. data/vendor/libbacktrace/nounwind.c +66 -0
  86. data/vendor/libbacktrace/pecoff.c +1123 -0
  87. data/vendor/libbacktrace/posix.c +104 -0
  88. data/vendor/libbacktrace/print.c +117 -0
  89. data/vendor/libbacktrace/read.c +110 -0
  90. data/vendor/libbacktrace/simple.c +108 -0
  91. data/vendor/libbacktrace/sort.c +108 -0
  92. data/vendor/libbacktrace/state.c +72 -0
  93. data/vendor/libbacktrace/stest.c +137 -0
  94. data/vendor/libbacktrace/test-driver +148 -0
  95. data/vendor/libbacktrace/test_format.c +55 -0
  96. data/vendor/libbacktrace/testlib.c +234 -0
  97. data/vendor/libbacktrace/testlib.h +110 -0
  98. data/vendor/libbacktrace/ttest.c +161 -0
  99. data/vendor/libbacktrace/unittest.c +92 -0
  100. data/vendor/libbacktrace/unknown.c +65 -0
  101. data/vendor/libbacktrace/xcoff.c +1617 -0
  102. data/vendor/libbacktrace/xztest.c +508 -0
  103. data/vendor/libbacktrace/zstdtest.c +523 -0
  104. data/vendor/libbacktrace/ztest.c +541 -0
  105. metadata +122 -3
@@ -0,0 +1,104 @@
1
+ /* posix.c -- POSIX file I/O routines for the backtrace library.
2
+ Copyright (C) 2012-2024 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,117 @@
1
+ /* print.c -- Print the current backtrace.
2
+ Copyright (C) 2012-2024 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 errors to stderr. */
51
+
52
+ static void
53
+ error_callback (void *data, const char *msg, int errnum)
54
+ {
55
+ struct print_data *pdata = (struct print_data *) data;
56
+
57
+ if (pdata->state->filename != NULL)
58
+ fprintf (stderr, "%s: ", pdata->state->filename);
59
+ fprintf (stderr, "libbacktrace: %s", msg);
60
+ if (errnum > 0)
61
+ fprintf (stderr, ": %s", strerror (errnum));
62
+ fputc ('\n', stderr);
63
+ }
64
+
65
+ /* Print one level of a backtrace if we couldn't get a file or function name.
66
+ Use syminfo to try to get a symbol name. */
67
+
68
+ static void print_syminfo_callback (void *data, uintptr_t pc,
69
+ const char *symname, uintptr_t symval,
70
+ uintptr_t symsize ATTRIBUTE_UNUSED)
71
+ {
72
+ struct print_data *pdata = (struct print_data *) data;
73
+
74
+ if (symname == NULL)
75
+ fprintf (pdata->f, "0x%lx ???\n\t???:0\n", (unsigned long) pc);
76
+ else
77
+ fprintf (pdata->f, "0x%lx ???\n\t%s+0x%lx:0\n",
78
+ (unsigned long) pc,
79
+ symname,
80
+ (unsigned long) (pc - symval));
81
+ }
82
+
83
+ /* Print one level of a backtrace. */
84
+
85
+ static int
86
+ print_callback (void *data, uintptr_t pc, const char *filename, int lineno,
87
+ const char *function)
88
+ {
89
+ struct print_data *pdata = (struct print_data *) data;
90
+
91
+ if (function == NULL && filename == NULL)
92
+ {
93
+ backtrace_syminfo (pdata->state, pc, print_syminfo_callback,
94
+ error_callback, data);
95
+ return 0;
96
+ }
97
+
98
+ fprintf (pdata->f, "0x%lx %s\n\t%s:%d\n",
99
+ (unsigned long) pc,
100
+ function == NULL ? "???" : function,
101
+ filename == NULL ? "???" : filename,
102
+ lineno);
103
+ return 0;
104
+ }
105
+
106
+ /* Print a backtrace. */
107
+
108
+ void __attribute__((noinline))
109
+ backtrace_print (struct backtrace_state *state, int skip, FILE *f)
110
+ {
111
+ struct print_data data;
112
+
113
+ data.state = state;
114
+ data.f = f;
115
+ backtrace_full (state, skip + 1, print_callback, error_callback,
116
+ (void *) &data);
117
+ }
@@ -0,0 +1,110 @@
1
+ /* read.c -- File views without mmap.
2
+ Copyright (C) 2012-2024 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-2024 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-2024 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-2024 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
+ }