pf2 0.9.0 → 1.0.0.alpha1

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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -4
  3. data/Rakefile +3 -9
  4. data/doc/development.md +6 -0
  5. data/ext/pf2/debug.h +12 -0
  6. data/ext/pf2/extconf.rb +23 -6
  7. data/ext/{pf2c → pf2}/sample.c +6 -0
  8. data/ext/{pf2c → pf2}/sample.h +4 -0
  9. data/ext/{pf2c → pf2}/serializer.c +1 -1
  10. data/ext/{pf2c → pf2}/session.c +70 -20
  11. data/ext/{pf2c → pf2}/session.h +5 -0
  12. data/lib/pf2/cli.rb +3 -11
  13. data/lib/pf2/reporter/firefox_profiler_ser2.rb +17 -13
  14. data/lib/pf2/reporter/stack_weaver.rb +8 -0
  15. data/lib/pf2/reporter.rb +0 -1
  16. data/lib/pf2/version.rb +1 -1
  17. data/lib/pf2.rb +1 -1
  18. metadata +18 -135
  19. data/Cargo.lock +0 -630
  20. data/Cargo.toml +0 -3
  21. data/crates/backtrace-sys2/.gitignore +0 -1
  22. data/crates/backtrace-sys2/Cargo.toml +0 -9
  23. data/crates/backtrace-sys2/build.rs +0 -45
  24. data/crates/backtrace-sys2/src/lib.rs +0 -5
  25. data/crates/backtrace-sys2/src/libbacktrace/.gitignore +0 -15
  26. data/crates/backtrace-sys2/src/libbacktrace/Isaac.Newton-Opticks.txt +0 -9286
  27. data/crates/backtrace-sys2/src/libbacktrace/LICENSE +0 -29
  28. data/crates/backtrace-sys2/src/libbacktrace/Makefile.am +0 -708
  29. data/crates/backtrace-sys2/src/libbacktrace/Makefile.in +0 -2820
  30. data/crates/backtrace-sys2/src/libbacktrace/README.md +0 -46
  31. data/crates/backtrace-sys2/src/libbacktrace/aclocal.m4 +0 -864
  32. data/crates/backtrace-sys2/src/libbacktrace/alloc.c +0 -167
  33. data/crates/backtrace-sys2/src/libbacktrace/allocfail.c +0 -136
  34. data/crates/backtrace-sys2/src/libbacktrace/allocfail.sh +0 -104
  35. data/crates/backtrace-sys2/src/libbacktrace/atomic.c +0 -113
  36. data/crates/backtrace-sys2/src/libbacktrace/backtrace-supported.h.in +0 -66
  37. data/crates/backtrace-sys2/src/libbacktrace/backtrace.c +0 -129
  38. data/crates/backtrace-sys2/src/libbacktrace/backtrace.h +0 -189
  39. data/crates/backtrace-sys2/src/libbacktrace/btest.c +0 -517
  40. data/crates/backtrace-sys2/src/libbacktrace/compile +0 -348
  41. data/crates/backtrace-sys2/src/libbacktrace/config/enable.m4 +0 -38
  42. data/crates/backtrace-sys2/src/libbacktrace/config/lead-dot.m4 +0 -31
  43. data/crates/backtrace-sys2/src/libbacktrace/config/libtool.m4 +0 -7545
  44. data/crates/backtrace-sys2/src/libbacktrace/config/ltoptions.m4 +0 -369
  45. data/crates/backtrace-sys2/src/libbacktrace/config/ltsugar.m4 +0 -123
  46. data/crates/backtrace-sys2/src/libbacktrace/config/ltversion.m4 +0 -23
  47. data/crates/backtrace-sys2/src/libbacktrace/config/lt~obsolete.m4 +0 -98
  48. data/crates/backtrace-sys2/src/libbacktrace/config/multi.m4 +0 -68
  49. data/crates/backtrace-sys2/src/libbacktrace/config/override.m4 +0 -117
  50. data/crates/backtrace-sys2/src/libbacktrace/config/unwind_ipinfo.m4 +0 -37
  51. data/crates/backtrace-sys2/src/libbacktrace/config/warnings.m4 +0 -227
  52. data/crates/backtrace-sys2/src/libbacktrace/config.guess +0 -1700
  53. data/crates/backtrace-sys2/src/libbacktrace/config.h.in +0 -185
  54. data/crates/backtrace-sys2/src/libbacktrace/config.sub +0 -1885
  55. data/crates/backtrace-sys2/src/libbacktrace/configure +0 -15929
  56. data/crates/backtrace-sys2/src/libbacktrace/configure.ac +0 -632
  57. data/crates/backtrace-sys2/src/libbacktrace/dwarf.c +0 -4409
  58. data/crates/backtrace-sys2/src/libbacktrace/edtest.c +0 -120
  59. data/crates/backtrace-sys2/src/libbacktrace/edtest2.c +0 -43
  60. data/crates/backtrace-sys2/src/libbacktrace/elf.c +0 -7465
  61. data/crates/backtrace-sys2/src/libbacktrace/fileline.c +0 -407
  62. data/crates/backtrace-sys2/src/libbacktrace/filenames.h +0 -52
  63. data/crates/backtrace-sys2/src/libbacktrace/filetype.awk +0 -13
  64. data/crates/backtrace-sys2/src/libbacktrace/install-debuginfo-for-buildid.sh.in +0 -65
  65. data/crates/backtrace-sys2/src/libbacktrace/install-sh +0 -501
  66. data/crates/backtrace-sys2/src/libbacktrace/instrumented_alloc.c +0 -114
  67. data/crates/backtrace-sys2/src/libbacktrace/internal.h +0 -428
  68. data/crates/backtrace-sys2/src/libbacktrace/ltmain.sh +0 -8636
  69. data/crates/backtrace-sys2/src/libbacktrace/macho.c +0 -1361
  70. data/crates/backtrace-sys2/src/libbacktrace/missing +0 -215
  71. data/crates/backtrace-sys2/src/libbacktrace/mmap.c +0 -331
  72. data/crates/backtrace-sys2/src/libbacktrace/mmapio.c +0 -110
  73. data/crates/backtrace-sys2/src/libbacktrace/move-if-change +0 -83
  74. data/crates/backtrace-sys2/src/libbacktrace/mtest.c +0 -410
  75. data/crates/backtrace-sys2/src/libbacktrace/nounwind.c +0 -66
  76. data/crates/backtrace-sys2/src/libbacktrace/pecoff.c +0 -1123
  77. data/crates/backtrace-sys2/src/libbacktrace/posix.c +0 -104
  78. data/crates/backtrace-sys2/src/libbacktrace/print.c +0 -117
  79. data/crates/backtrace-sys2/src/libbacktrace/read.c +0 -110
  80. data/crates/backtrace-sys2/src/libbacktrace/simple.c +0 -108
  81. data/crates/backtrace-sys2/src/libbacktrace/sort.c +0 -108
  82. data/crates/backtrace-sys2/src/libbacktrace/state.c +0 -72
  83. data/crates/backtrace-sys2/src/libbacktrace/stest.c +0 -137
  84. data/crates/backtrace-sys2/src/libbacktrace/test-driver +0 -148
  85. data/crates/backtrace-sys2/src/libbacktrace/test_format.c +0 -55
  86. data/crates/backtrace-sys2/src/libbacktrace/testlib.c +0 -234
  87. data/crates/backtrace-sys2/src/libbacktrace/testlib.h +0 -110
  88. data/crates/backtrace-sys2/src/libbacktrace/ttest.c +0 -161
  89. data/crates/backtrace-sys2/src/libbacktrace/unittest.c +0 -92
  90. data/crates/backtrace-sys2/src/libbacktrace/unknown.c +0 -65
  91. data/crates/backtrace-sys2/src/libbacktrace/xcoff.c +0 -1617
  92. data/crates/backtrace-sys2/src/libbacktrace/xztest.c +0 -508
  93. data/crates/backtrace-sys2/src/libbacktrace/zstdtest.c +0 -523
  94. data/crates/backtrace-sys2/src/libbacktrace/ztest.c +0 -541
  95. data/ext/pf2/Cargo.toml +0 -25
  96. data/ext/pf2/build.rs +0 -10
  97. data/ext/pf2/src/backtrace.rs +0 -127
  98. data/ext/pf2/src/lib.rs +0 -22
  99. data/ext/pf2/src/profile.rs +0 -69
  100. data/ext/pf2/src/profile_serializer.rs +0 -241
  101. data/ext/pf2/src/ringbuffer.rs +0 -150
  102. data/ext/pf2/src/ruby_c_api_helper.c +0 -6
  103. data/ext/pf2/src/ruby_init.rs +0 -40
  104. data/ext/pf2/src/ruby_internal_apis.rs +0 -77
  105. data/ext/pf2/src/sample.rs +0 -67
  106. data/ext/pf2/src/scheduler.rs +0 -10
  107. data/ext/pf2/src/serialization/profile.rs +0 -48
  108. data/ext/pf2/src/serialization/serializer.rs +0 -329
  109. data/ext/pf2/src/serialization.rs +0 -2
  110. data/ext/pf2/src/session/configuration.rs +0 -114
  111. data/ext/pf2/src/session/new_thread_watcher.rs +0 -80
  112. data/ext/pf2/src/session/ruby_object.rs +0 -90
  113. data/ext/pf2/src/session.rs +0 -248
  114. data/ext/pf2/src/siginfo_t.c +0 -5
  115. data/ext/pf2/src/signal_scheduler.rs +0 -201
  116. data/ext/pf2/src/signal_scheduler_unsupported_platform.rs +0 -39
  117. data/ext/pf2/src/timer_thread_scheduler.rs +0 -179
  118. data/ext/pf2/src/util.rs +0 -31
  119. data/ext/pf2c/extconf.rb +0 -21
  120. data/lib/pf2/reporter/firefox_profiler.rb +0 -397
  121. data/rust-toolchain.toml +0 -2
  122. data/rustfmt.toml +0 -1
  123. /data/ext/{pf2c → pf2}/backtrace_state.c +0 -0
  124. /data/ext/{pf2c → pf2}/backtrace_state.h +0 -0
  125. /data/ext/{pf2c → pf2}/configuration.c +0 -0
  126. /data/ext/{pf2c → pf2}/configuration.h +0 -0
  127. /data/ext/{pf2c → pf2}/pf2.c +0 -0
  128. /data/ext/{pf2c → pf2}/pf2.h +0 -0
  129. /data/ext/{pf2c → pf2}/ringbuffer.c +0 -0
  130. /data/ext/{pf2c → pf2}/ringbuffer.h +0 -0
  131. /data/ext/{pf2c → pf2}/serializer.h +0 -0
@@ -1,104 +0,0 @@
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
- }
@@ -1,117 +0,0 @@
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
- }
@@ -1,110 +0,0 @@
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
- }
@@ -1,108 +0,0 @@
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
- }
@@ -1,108 +0,0 @@
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
- }
@@ -1,72 +0,0 @@
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
- }