pf2 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -2
  3. data/Cargo.lock +186 -17
  4. data/Cargo.toml +1 -1
  5. data/README.md +18 -6
  6. data/Rakefile +8 -0
  7. data/crates/backtrace-sys2/.gitignore +1 -0
  8. data/crates/backtrace-sys2/Cargo.toml +9 -0
  9. data/crates/backtrace-sys2/build.rs +48 -0
  10. data/crates/backtrace-sys2/src/lib.rs +5 -0
  11. data/crates/backtrace-sys2/src/libbacktrace/.gitignore +15 -0
  12. data/crates/backtrace-sys2/src/libbacktrace/Isaac.Newton-Opticks.txt +9286 -0
  13. data/crates/backtrace-sys2/src/libbacktrace/LICENSE +29 -0
  14. data/crates/backtrace-sys2/src/libbacktrace/Makefile.am +623 -0
  15. data/crates/backtrace-sys2/src/libbacktrace/Makefile.in +2666 -0
  16. data/crates/backtrace-sys2/src/libbacktrace/README.md +36 -0
  17. data/crates/backtrace-sys2/src/libbacktrace/aclocal.m4 +864 -0
  18. data/crates/backtrace-sys2/src/libbacktrace/alloc.c +167 -0
  19. data/crates/backtrace-sys2/src/libbacktrace/allocfail.c +136 -0
  20. data/crates/backtrace-sys2/src/libbacktrace/allocfail.sh +104 -0
  21. data/crates/backtrace-sys2/src/libbacktrace/atomic.c +113 -0
  22. data/crates/backtrace-sys2/src/libbacktrace/backtrace-supported.h.in +66 -0
  23. data/crates/backtrace-sys2/src/libbacktrace/backtrace.c +129 -0
  24. data/crates/backtrace-sys2/src/libbacktrace/backtrace.h +189 -0
  25. data/crates/backtrace-sys2/src/libbacktrace/btest.c +501 -0
  26. data/crates/backtrace-sys2/src/libbacktrace/compile +348 -0
  27. data/crates/backtrace-sys2/src/libbacktrace/config/enable.m4 +38 -0
  28. data/crates/backtrace-sys2/src/libbacktrace/config/lead-dot.m4 +31 -0
  29. data/crates/backtrace-sys2/src/libbacktrace/config/libtool.m4 +7436 -0
  30. data/crates/backtrace-sys2/src/libbacktrace/config/ltoptions.m4 +369 -0
  31. data/crates/backtrace-sys2/src/libbacktrace/config/ltsugar.m4 +123 -0
  32. data/crates/backtrace-sys2/src/libbacktrace/config/ltversion.m4 +23 -0
  33. data/crates/backtrace-sys2/src/libbacktrace/config/lt~obsolete.m4 +98 -0
  34. data/crates/backtrace-sys2/src/libbacktrace/config/multi.m4 +68 -0
  35. data/crates/backtrace-sys2/src/libbacktrace/config/override.m4 +117 -0
  36. data/crates/backtrace-sys2/src/libbacktrace/config/unwind_ipinfo.m4 +37 -0
  37. data/crates/backtrace-sys2/src/libbacktrace/config/warnings.m4 +227 -0
  38. data/crates/backtrace-sys2/src/libbacktrace/config.guess +1700 -0
  39. data/crates/backtrace-sys2/src/libbacktrace/config.h.in +182 -0
  40. data/crates/backtrace-sys2/src/libbacktrace/config.sub +1885 -0
  41. data/crates/backtrace-sys2/src/libbacktrace/configure +15740 -0
  42. data/crates/backtrace-sys2/src/libbacktrace/configure.ac +613 -0
  43. data/crates/backtrace-sys2/src/libbacktrace/dwarf.c +4402 -0
  44. data/crates/backtrace-sys2/src/libbacktrace/edtest.c +120 -0
  45. data/crates/backtrace-sys2/src/libbacktrace/edtest2.c +43 -0
  46. data/crates/backtrace-sys2/src/libbacktrace/elf.c +7443 -0
  47. data/crates/backtrace-sys2/src/libbacktrace/fileline.c +407 -0
  48. data/crates/backtrace-sys2/src/libbacktrace/filenames.h +52 -0
  49. data/crates/backtrace-sys2/src/libbacktrace/filetype.awk +13 -0
  50. data/crates/backtrace-sys2/src/libbacktrace/install-debuginfo-for-buildid.sh.in +65 -0
  51. data/crates/backtrace-sys2/src/libbacktrace/install-sh +501 -0
  52. data/crates/backtrace-sys2/src/libbacktrace/instrumented_alloc.c +114 -0
  53. data/crates/backtrace-sys2/src/libbacktrace/internal.h +389 -0
  54. data/crates/backtrace-sys2/src/libbacktrace/libtool.m4 +7436 -0
  55. data/crates/backtrace-sys2/src/libbacktrace/ltmain.sh +8636 -0
  56. data/crates/backtrace-sys2/src/libbacktrace/ltoptions.m4 +369 -0
  57. data/crates/backtrace-sys2/src/libbacktrace/ltsugar.m4 +123 -0
  58. data/crates/backtrace-sys2/src/libbacktrace/ltversion.m4 +23 -0
  59. data/crates/backtrace-sys2/src/libbacktrace/lt~obsolete.m4 +98 -0
  60. data/crates/backtrace-sys2/src/libbacktrace/macho.c +1355 -0
  61. data/crates/backtrace-sys2/src/libbacktrace/missing +215 -0
  62. data/crates/backtrace-sys2/src/libbacktrace/mmap.c +331 -0
  63. data/crates/backtrace-sys2/src/libbacktrace/mmapio.c +110 -0
  64. data/crates/backtrace-sys2/src/libbacktrace/move-if-change +83 -0
  65. data/crates/backtrace-sys2/src/libbacktrace/mtest.c +410 -0
  66. data/crates/backtrace-sys2/src/libbacktrace/nounwind.c +66 -0
  67. data/crates/backtrace-sys2/src/libbacktrace/pecoff.c +957 -0
  68. data/crates/backtrace-sys2/src/libbacktrace/posix.c +104 -0
  69. data/crates/backtrace-sys2/src/libbacktrace/print.c +92 -0
  70. data/crates/backtrace-sys2/src/libbacktrace/read.c +110 -0
  71. data/crates/backtrace-sys2/src/libbacktrace/simple.c +108 -0
  72. data/crates/backtrace-sys2/src/libbacktrace/sort.c +108 -0
  73. data/crates/backtrace-sys2/src/libbacktrace/state.c +72 -0
  74. data/crates/backtrace-sys2/src/libbacktrace/stest.c +137 -0
  75. data/crates/backtrace-sys2/src/libbacktrace/test-driver +148 -0
  76. data/crates/backtrace-sys2/src/libbacktrace/test_format.c +55 -0
  77. data/crates/backtrace-sys2/src/libbacktrace/testlib.c +234 -0
  78. data/crates/backtrace-sys2/src/libbacktrace/testlib.h +110 -0
  79. data/crates/backtrace-sys2/src/libbacktrace/ttest.c +161 -0
  80. data/crates/backtrace-sys2/src/libbacktrace/unittest.c +92 -0
  81. data/crates/backtrace-sys2/src/libbacktrace/unknown.c +65 -0
  82. data/crates/backtrace-sys2/src/libbacktrace/xcoff.c +1606 -0
  83. data/crates/backtrace-sys2/src/libbacktrace/xztest.c +508 -0
  84. data/crates/backtrace-sys2/src/libbacktrace/zstdtest.c +523 -0
  85. data/crates/backtrace-sys2/src/libbacktrace/ztest.c +541 -0
  86. data/ext/pf2/Cargo.toml +1 -0
  87. data/ext/pf2/src/backtrace.rs +127 -0
  88. data/ext/pf2/src/lib.rs +3 -0
  89. data/ext/pf2/src/profile.rs +16 -1
  90. data/ext/pf2/src/profile_serializer.rs +95 -21
  91. data/ext/pf2/src/ringbuffer.rs +7 -0
  92. data/ext/pf2/src/ruby_init.rs +18 -6
  93. data/ext/pf2/src/ruby_internal_apis.rs +47 -0
  94. data/ext/pf2/src/sample.rs +22 -1
  95. data/ext/pf2/src/signal_scheduler/configuration.rs +7 -0
  96. data/ext/pf2/src/signal_scheduler/timer_installer.rs +79 -126
  97. data/ext/pf2/src/signal_scheduler.rs +95 -26
  98. data/ext/pf2/src/timer_thread_scheduler.rs +88 -12
  99. data/ext/pf2/src/util.rs +2 -2
  100. data/lib/pf2/reporter.rb +12 -5
  101. data/lib/pf2/version.rb +1 -1
  102. data/lib/pf2.rb +3 -6
  103. metadata +97 -6
@@ -0,0 +1,137 @@
1
+ /* stest.c -- Test for libbacktrace internal sort 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 <stdio.h>
36
+ #include <stdlib.h>
37
+ #include <string.h>
38
+ #include <sys/types.h>
39
+
40
+ #include "backtrace.h"
41
+ #include "internal.h"
42
+
43
+ /* Test the local qsort implementation. */
44
+
45
+ #define MAX 10
46
+
47
+ struct test
48
+ {
49
+ size_t count;
50
+ int input[MAX];
51
+ int output[MAX];
52
+ };
53
+
54
+ static struct test tests[] =
55
+ {
56
+ {
57
+ 10,
58
+ { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
59
+ { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
60
+ },
61
+ {
62
+ 9,
63
+ { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
64
+ { 1, 2, 3, 4, 5, 6, 7, 8, 9 }
65
+ },
66
+ {
67
+ 10,
68
+ { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 },
69
+ { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
70
+ },
71
+ {
72
+ 9,
73
+ { 9, 8, 7, 6, 5, 4, 3, 2, 1 },
74
+ { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
75
+ },
76
+ {
77
+ 10,
78
+ { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 },
79
+ { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
80
+ },
81
+ {
82
+ 5,
83
+ { 4, 5, 3, 1, 2 },
84
+ { 1, 2, 3, 4, 5 },
85
+ },
86
+ {
87
+ 5,
88
+ { 1, 1, 1, 1, 1 },
89
+ { 1, 1, 1, 1, 1 },
90
+ },
91
+ {
92
+ 5,
93
+ { 1, 1, 2, 1, 1 },
94
+ { 1, 1, 1, 1, 2 },
95
+ },
96
+ {
97
+ 5,
98
+ { 2, 1, 1, 1, 1 },
99
+ { 1, 1, 1, 1, 2 },
100
+ },
101
+ };
102
+
103
+ static int
104
+ compare (const void *a, const void *b)
105
+ {
106
+ const int *ai = (const int *) a;
107
+ const int *bi = (const int *) b;
108
+
109
+ return *ai - *bi;
110
+ }
111
+
112
+ int
113
+ main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
114
+ {
115
+ int failures;
116
+ size_t i;
117
+ int a[MAX];
118
+
119
+ failures = 0;
120
+ for (i = 0; i < sizeof tests / sizeof tests[0]; i++)
121
+ {
122
+ memcpy (a, tests[i].input, tests[i].count * sizeof (int));
123
+ backtrace_qsort (a, tests[i].count, sizeof (int), compare);
124
+ if (memcmp (a, tests[i].output, tests[i].count * sizeof (int)) != 0)
125
+ {
126
+ size_t j;
127
+
128
+ fprintf (stderr, "test %d failed:", (int) i);
129
+ for (j = 0; j < tests[i].count; j++)
130
+ fprintf (stderr, " %d", a[j]);
131
+ fprintf (stderr, "\n");
132
+ ++failures;
133
+ }
134
+ }
135
+
136
+ exit (failures > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
137
+ }
@@ -0,0 +1,148 @@
1
+ #! /bin/sh
2
+ # test-driver - basic testsuite driver script.
3
+
4
+ scriptversion=2016-01-11.22; # UTC
5
+
6
+ # Copyright (C) 2011-2017 Free Software Foundation, Inc.
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2, or (at your option)
11
+ # any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+
21
+ # As a special exception to the GNU General Public License, if you
22
+ # distribute this file as part of a program that contains a
23
+ # configuration script generated by Autoconf, you may include it under
24
+ # the same distribution terms that you use for the rest of that program.
25
+
26
+ # This file is maintained in Automake, please report
27
+ # bugs to <bug-automake@gnu.org> or send patches to
28
+ # <automake-patches@gnu.org>.
29
+
30
+ # Make unconditional expansion of undefined variables an error. This
31
+ # helps a lot in preventing typo-related bugs.
32
+ set -u
33
+
34
+ usage_error ()
35
+ {
36
+ echo "$0: $*" >&2
37
+ print_usage >&2
38
+ exit 2
39
+ }
40
+
41
+ print_usage ()
42
+ {
43
+ cat <<END
44
+ Usage:
45
+ test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
46
+ [--expect-failure={yes|no}] [--color-tests={yes|no}]
47
+ [--enable-hard-errors={yes|no}] [--]
48
+ TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
49
+ The '--test-name', '--log-file' and '--trs-file' options are mandatory.
50
+ END
51
+ }
52
+
53
+ test_name= # Used for reporting.
54
+ log_file= # Where to save the output of the test script.
55
+ trs_file= # Where to save the metadata of the test run.
56
+ expect_failure=no
57
+ color_tests=no
58
+ enable_hard_errors=yes
59
+ while test $# -gt 0; do
60
+ case $1 in
61
+ --help) print_usage; exit $?;;
62
+ --version) echo "test-driver $scriptversion"; exit $?;;
63
+ --test-name) test_name=$2; shift;;
64
+ --log-file) log_file=$2; shift;;
65
+ --trs-file) trs_file=$2; shift;;
66
+ --color-tests) color_tests=$2; shift;;
67
+ --expect-failure) expect_failure=$2; shift;;
68
+ --enable-hard-errors) enable_hard_errors=$2; shift;;
69
+ --) shift; break;;
70
+ -*) usage_error "invalid option: '$1'";;
71
+ *) break;;
72
+ esac
73
+ shift
74
+ done
75
+
76
+ missing_opts=
77
+ test x"$test_name" = x && missing_opts="$missing_opts --test-name"
78
+ test x"$log_file" = x && missing_opts="$missing_opts --log-file"
79
+ test x"$trs_file" = x && missing_opts="$missing_opts --trs-file"
80
+ if test x"$missing_opts" != x; then
81
+ usage_error "the following mandatory options are missing:$missing_opts"
82
+ fi
83
+
84
+ if test $# -eq 0; then
85
+ usage_error "missing argument"
86
+ fi
87
+
88
+ if test $color_tests = yes; then
89
+ # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
90
+ red='' # Red.
91
+ grn='' # Green.
92
+ lgn='' # Light green.
93
+ blu='' # Blue.
94
+ mgn='' # Magenta.
95
+ std='' # No color.
96
+ else
97
+ red= grn= lgn= blu= mgn= std=
98
+ fi
99
+
100
+ do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
101
+ trap "st=129; $do_exit" 1
102
+ trap "st=130; $do_exit" 2
103
+ trap "st=141; $do_exit" 13
104
+ trap "st=143; $do_exit" 15
105
+
106
+ # Test script is run here.
107
+ "$@" >$log_file 2>&1
108
+ estatus=$?
109
+
110
+ if test $enable_hard_errors = no && test $estatus -eq 99; then
111
+ tweaked_estatus=1
112
+ else
113
+ tweaked_estatus=$estatus
114
+ fi
115
+
116
+ case $tweaked_estatus:$expect_failure in
117
+ 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
118
+ 0:*) col=$grn res=PASS recheck=no gcopy=no;;
119
+ 77:*) col=$blu res=SKIP recheck=no gcopy=yes;;
120
+ 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;;
121
+ *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;;
122
+ *:*) col=$red res=FAIL recheck=yes gcopy=yes;;
123
+ esac
124
+
125
+ # Report the test outcome and exit status in the logs, so that one can
126
+ # know whether the test passed or failed simply by looking at the '.log'
127
+ # file, without the need of also peaking into the corresponding '.trs'
128
+ # file (automake bug#11814).
129
+ echo "$res $test_name (exit status: $estatus)" >>$log_file
130
+
131
+ # Report outcome to console.
132
+ echo "${col}${res}${std}: $test_name"
133
+
134
+ # Register the test result, and other relevant metadata.
135
+ echo ":test-result: $res" > $trs_file
136
+ echo ":global-test-result: $res" >> $trs_file
137
+ echo ":recheck: $recheck" >> $trs_file
138
+ echo ":copy-in-global-log: $gcopy" >> $trs_file
139
+
140
+ # Local Variables:
141
+ # mode: shell-script
142
+ # sh-indentation: 2
143
+ # eval: (add-hook 'write-file-hooks 'time-stamp)
144
+ # time-stamp-start: "scriptversion="
145
+ # time-stamp-format: "%:y-%02m-%02d.%02H"
146
+ # time-stamp-time-zone: "UTC0"
147
+ # time-stamp-end: "; # UTC"
148
+ # End:
@@ -0,0 +1,55 @@
1
+ /* test_format.c -- Test for libbacktrace library
2
+ Copyright (C) 2018-2021 Free Software Foundation, Inc.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ (1) Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ (2) Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in
13
+ the documentation and/or other materials provided with the
14
+ distribution.
15
+
16
+ (3) The name of the author may not be used to
17
+ endorse or promote products derived from this software without
18
+ specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ POSSIBILITY OF SUCH DAMAGE. */
31
+
32
+ /* This program tests the externally visible interfaces of the
33
+ libbacktrace library. */
34
+
35
+ #include <assert.h>
36
+ #include <stdio.h>
37
+ #include <stdlib.h>
38
+ #include <string.h>
39
+ #include <unistd.h>
40
+
41
+ #include "filenames.h"
42
+
43
+ #include "backtrace.h"
44
+ #include "backtrace-supported.h"
45
+
46
+ #include "testlib.h"
47
+
48
+ int
49
+ main (int argc ATTRIBUTE_UNUSED, char **argv)
50
+ {
51
+ state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS,
52
+ error_callback_create, NULL);
53
+
54
+ exit (failures ? EXIT_FAILURE : EXIT_SUCCESS);
55
+ }
@@ -0,0 +1,234 @@
1
+ /* testlib.c -- test functions for libbacktrace 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 <assert.h>
34
+ #include <stdio.h>
35
+ #include <stdlib.h>
36
+ #include <string.h>
37
+
38
+ #include "filenames.h"
39
+
40
+ #include "backtrace.h"
41
+
42
+ #include "testlib.h"
43
+
44
+ /* The backtrace state. */
45
+
46
+ void *state;
47
+
48
+ /* The number of failures. */
49
+
50
+ int failures;
51
+
52
+ /* Return the base name in a path. */
53
+
54
+ const char *
55
+ base (const char *p)
56
+ {
57
+ const char *last;
58
+ const char *s;
59
+
60
+ last = NULL;
61
+ for (s = p; *s != '\0'; ++s)
62
+ {
63
+ if (IS_DIR_SEPARATOR (*s))
64
+ last = s + 1;
65
+ }
66
+ return last != NULL ? last : p;
67
+ }
68
+
69
+ /* Check an entry in a struct info array. */
70
+
71
+ void
72
+ check (const char *name, int index, const struct info *all, int want_lineno,
73
+ const char *want_function, const char *want_file, int *failed)
74
+ {
75
+ if (*failed)
76
+ return;
77
+ if (all[index].filename == NULL || all[index].function == NULL)
78
+ {
79
+ fprintf (stderr, "%s: [%d]: missing file name or function name\n",
80
+ name, index);
81
+ *failed = 1;
82
+ return;
83
+ }
84
+ if (strcmp (base (all[index].filename), want_file) != 0)
85
+ {
86
+ fprintf (stderr, "%s: [%d]: got %s expected %s\n", name, index,
87
+ all[index].filename, want_file);
88
+ *failed = 1;
89
+ }
90
+ if (all[index].lineno != want_lineno)
91
+ {
92
+ fprintf (stderr, "%s: [%d]: got %d expected %d\n", name, index,
93
+ all[index].lineno, want_lineno);
94
+ *failed = 1;
95
+ }
96
+ if (strcmp (all[index].function, want_function) != 0)
97
+ {
98
+ fprintf (stderr, "%s: [%d]: got %s expected %s\n", name, index,
99
+ all[index].function, want_function);
100
+ *failed = 1;
101
+ }
102
+ }
103
+
104
+ /* The backtrace callback function. */
105
+
106
+ int
107
+ callback_one (void *vdata, uintptr_t pc ATTRIBUTE_UNUSED,
108
+ const char *filename, int lineno, const char *function)
109
+ {
110
+ struct bdata *data = (struct bdata *) vdata;
111
+ struct info *p;
112
+
113
+ if (data->index >= data->max)
114
+ {
115
+ fprintf (stderr, "callback_one: callback called too many times\n");
116
+ data->failed = 1;
117
+ return 1;
118
+ }
119
+
120
+ p = &data->all[data->index];
121
+ if (filename == NULL)
122
+ p->filename = NULL;
123
+ else
124
+ {
125
+ p->filename = strdup (filename);
126
+ assert (p->filename != NULL);
127
+ }
128
+ p->lineno = lineno;
129
+ if (function == NULL)
130
+ p->function = NULL;
131
+ else
132
+ {
133
+ p->function = strdup (function);
134
+ assert (p->function != NULL);
135
+ }
136
+ ++data->index;
137
+
138
+ return 0;
139
+ }
140
+
141
+ /* An error callback passed to backtrace. */
142
+
143
+ void
144
+ error_callback_one (void *vdata, const char *msg, int errnum)
145
+ {
146
+ struct bdata *data = (struct bdata *) vdata;
147
+
148
+ fprintf (stderr, "%s", msg);
149
+ if (errnum > 0)
150
+ fprintf (stderr, ": %s", strerror (errnum));
151
+ fprintf (stderr, "\n");
152
+ data->failed = 1;
153
+ }
154
+
155
+ /* The backtrace_simple callback function. */
156
+
157
+ int
158
+ callback_two (void *vdata, uintptr_t pc)
159
+ {
160
+ struct sdata *data = (struct sdata *) vdata;
161
+
162
+ if (data->index >= data->max)
163
+ {
164
+ fprintf (stderr, "callback_two: callback called too many times\n");
165
+ data->failed = 1;
166
+ return 1;
167
+ }
168
+
169
+ data->addrs[data->index] = pc;
170
+ ++data->index;
171
+
172
+ return 0;
173
+ }
174
+
175
+ /* An error callback passed to backtrace_simple. */
176
+
177
+ void
178
+ error_callback_two (void *vdata, const char *msg, int errnum)
179
+ {
180
+ struct sdata *data = (struct sdata *) vdata;
181
+
182
+ fprintf (stderr, "%s", msg);
183
+ if (errnum > 0)
184
+ fprintf (stderr, ": %s", strerror (errnum));
185
+ fprintf (stderr, "\n");
186
+ data->failed = 1;
187
+ }
188
+
189
+ /* The backtrace_syminfo callback function. */
190
+
191
+ void
192
+ callback_three (void *vdata, uintptr_t pc ATTRIBUTE_UNUSED,
193
+ const char *symname, uintptr_t symval,
194
+ uintptr_t symsize)
195
+ {
196
+ struct symdata *data = (struct symdata *) vdata;
197
+
198
+ if (symname == NULL)
199
+ data->name = NULL;
200
+ else
201
+ {
202
+ data->name = strdup (symname);
203
+ assert (data->name != NULL);
204
+ }
205
+ data->val = symval;
206
+ data->size = symsize;
207
+ }
208
+
209
+ /* The backtrace_syminfo error callback function. */
210
+
211
+ void
212
+ error_callback_three (void *vdata, const char *msg, int errnum)
213
+ {
214
+ struct symdata *data = (struct symdata *) vdata;
215
+
216
+ fprintf (stderr, "%s", msg);
217
+ if (errnum > 0)
218
+ fprintf (stderr, ": %s", strerror (errnum));
219
+ fprintf (stderr, "\n");
220
+ data->failed = 1;
221
+ }
222
+
223
+ /* The backtrace_create_state error callback function. */
224
+
225
+ void
226
+ error_callback_create (void *data ATTRIBUTE_UNUSED, const char *msg,
227
+ int errnum)
228
+ {
229
+ fprintf (stderr, "%s", msg);
230
+ if (errnum > 0)
231
+ fprintf (stderr, ": %s", strerror (errnum));
232
+ fprintf (stderr, "\n");
233
+ exit (EXIT_FAILURE);
234
+ }
@@ -0,0 +1,110 @@
1
+ /* testlib.h -- Header for test functions for libbacktrace 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
+ #ifndef LIBBACKTRACE_TESTLIB_H
34
+ #define LIBBACKTRACE_TESTLIB_H
35
+
36
+ /* Portable attribute syntax. Actually some of these tests probably
37
+ won't work if the attributes are not recognized. */
38
+
39
+ #ifndef GCC_VERSION
40
+ # define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
41
+ #endif
42
+
43
+ #if (GCC_VERSION < 2007)
44
+ # define __attribute__(x)
45
+ #endif
46
+
47
+ #ifndef ATTRIBUTE_UNUSED
48
+ # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
49
+ #endif
50
+
51
+ /* Used to collect backtrace info. */
52
+
53
+ struct info
54
+ {
55
+ char *filename;
56
+ int lineno;
57
+ char *function;
58
+ };
59
+
60
+ /* Passed to backtrace callback function. */
61
+
62
+ struct bdata
63
+ {
64
+ struct info *all;
65
+ size_t index;
66
+ size_t max;
67
+ int failed;
68
+ };
69
+
70
+ /* Passed to backtrace_simple callback function. */
71
+
72
+ struct sdata
73
+ {
74
+ uintptr_t *addrs;
75
+ size_t index;
76
+ size_t max;
77
+ int failed;
78
+ };
79
+
80
+ /* Passed to backtrace_syminfo callback function. */
81
+
82
+ struct symdata
83
+ {
84
+ const char *name;
85
+ uintptr_t val, size;
86
+ int failed;
87
+ };
88
+
89
+ /* The backtrace state. */
90
+
91
+ extern void *state;
92
+
93
+ /* The number of failures. */
94
+
95
+ extern int failures;
96
+
97
+ extern const char *base (const char *p);
98
+ extern void check (const char *name, int index, const struct info *all,
99
+ int want_lineno, const char *want_function,
100
+ const char *want_file, int *failed);
101
+ extern int callback_one (void *, uintptr_t, const char *, int, const char *);
102
+ extern void error_callback_one (void *, const char *, int);
103
+ extern int callback_two (void *, uintptr_t);
104
+ extern void error_callback_two (void *, const char *, int);
105
+ extern void callback_three (void *, uintptr_t, const char *, uintptr_t,
106
+ uintptr_t);
107
+ extern void error_callback_three (void *, const char *, int);
108
+ extern void error_callback_create (void *, const char *, int);
109
+
110
+ #endif /* !defined(LIBBACKTRACE_TESTLIB_H) */