backtracie 0.3.0 → 1.0.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.
@@ -1,170 +0,0 @@
1
- // backtracie: Ruby gem for beautiful backtraces
2
- // Copyright (C) 2021 Ivo Anjo <ivo@ivoanjo.me>
3
- //
4
- // This file is part of backtracie.
5
- //
6
- // backtracie is free software: you can redistribute it and/or modify
7
- // it under the terms of the GNU Lesser General Public License as published by
8
- // the Free Software Foundation, either version 3 of the License, or
9
- // (at your option) any later version.
10
- //
11
- // backtracie is distributed in the hope that it will be useful,
12
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- // GNU Lesser General Public License for more details.
15
- //
16
- // You should have received a copy of the GNU Lesser General Public License
17
- // along with backtracie. If not, see <http://www.gnu.org/licenses/>.
18
-
19
- // -----------------------------------------------------------------------------
20
- // The file below has modified versions of code extracted from the Ruby project.
21
- // The Ruby project copyright and license follow:
22
- // -----------------------------------------------------------------------------
23
-
24
- // Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
25
- // You can redistribute it and/or modify it under either the terms of the
26
- // 2-clause BSDL (see the file BSDL), or the conditions below:
27
-
28
- // 1. You may make and give away verbatim copies of the source form of the
29
- // software without restriction, provided that you duplicate all of the
30
- // original copyright notices and associated disclaimers.
31
-
32
- // 2. You may modify your copy of the software in any way, provided that
33
- // you do at least ONE of the following:
34
-
35
- // a. place your modifications in the Public Domain or otherwise
36
- // make them Freely Available, such as by posting said
37
- // modifications to Usenet or an equivalent medium, or by allowing
38
- // the author to include your modifications in the software.
39
-
40
- // b. use the modified software only within your corporation or
41
- // organization.
42
-
43
- // c. give non-standard binaries non-standard names, with
44
- // instructions on where to get the original software distribution.
45
-
46
- // d. make other distribution arrangements with the author.
47
-
48
- // 3. You may distribute the software in object code or binary form,
49
- // provided that you do at least ONE of the following:
50
-
51
- // a. distribute the binaries and library files of the software,
52
- // together with instructions (in the manual page or equivalent)
53
- // on where to get the original distribution.
54
-
55
- // b. accompany the distribution with the machine-readable source of
56
- // the software.
57
-
58
- // c. give non-standard binaries non-standard names, with
59
- // instructions on where to get the original software distribution.
60
-
61
- // d. make other distribution arrangements with the author.
62
-
63
- // 4. You may modify and include the part of the software into any other
64
- // software (possibly commercial). But some files in the distribution
65
- // are not written by the author, so that they are not under these terms.
66
-
67
- // For the list of those files and their copying conditions, see the
68
- // file LEGAL.
69
-
70
- // 5. The scripts and library files supplied as input to or produced as
71
- // output from the software do not automatically fall under the
72
- // copyright of the software, but belong to whomever generated them,
73
- // and may be sold commercially, and may be aggregated with this
74
- // software.
75
-
76
- // 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
77
- // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
78
- // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
79
- // PURPOSE.
80
-
81
- #ifndef RUBY_SHARDS_H
82
- #define RUBY_SHARDS_H
83
-
84
- // -----------------------------------------------------------------------------
85
-
86
- /**********************************************************************
87
- method.h -
88
- created at: Wed Jul 15 20:02:33 2009
89
- Copyright (C) 2009 Koichi Sasada
90
- **********************************************************************/
91
-
92
- #ifdef PRE_MJIT_RUBY
93
- #include <stdbool.h>
94
- #include <vm_core.h>
95
- #include <method.h>
96
- #else
97
- #ifndef RUBY_MJIT_HEADER_INCLUDED
98
- typedef enum {
99
- VM_METHOD_TYPE_ISEQ, /*!< Ruby method */
100
- VM_METHOD_TYPE_CFUNC, /*!< C method */
101
- VM_METHOD_TYPE_ATTRSET, /*!< attr_writer or attr_accessor */
102
- VM_METHOD_TYPE_IVAR, /*!< attr_reader or attr_accessor */
103
- VM_METHOD_TYPE_BMETHOD,
104
- VM_METHOD_TYPE_ZSUPER,
105
- VM_METHOD_TYPE_ALIAS,
106
- VM_METHOD_TYPE_UNDEF,
107
- VM_METHOD_TYPE_NOTIMPLEMENTED,
108
- VM_METHOD_TYPE_OPTIMIZED, /*!< Kernel#send, Proc#call, etc */
109
- VM_METHOD_TYPE_MISSING, /*!< wrapper for method_missing(id) */
110
- VM_METHOD_TYPE_REFINED, /*!< refinement */
111
- } rb_method_type_t;
112
- #endif
113
- #endif
114
-
115
- // -----------------------------------------------------------------------------
116
-
117
- typedef struct {
118
- unsigned int is_ruby_frame : 1; // 1 -> ruby frame / 0 -> cfunc frame
119
-
120
- // for ruby frames where the callable_method_entry is not of type VM_METHOD_TYPE_ISEQ, most of the metadata we
121
- // want can be found by querying the iseq, and there may not even be an callable_method_entry
122
- unsigned int should_use_iseq : 1;
123
-
124
- rb_method_type_t vm_method_type;
125
- int line_number;
126
- VALUE iseq;
127
- VALUE callable_method_entry;
128
- VALUE self;
129
- VALUE original_id;
130
- } raw_location;
131
-
132
- int backtracie_rb_profile_frames(int limit, raw_location *raw_locations);
133
- int backtracie_rb_profile_frames_for_thread(VALUE thread, int limit, raw_location *raw_locations);
134
- bool backtracie_is_thread_alive(VALUE thread);
135
- VALUE backtracie_called_id(raw_location *the_location);
136
- VALUE backtracie_defined_class(raw_location *the_location);
137
- bool backtracie_iseq_is_block(raw_location *the_location);
138
- bool backtracie_iseq_is_eval(raw_location *the_location);
139
- VALUE backtracie_refinement_name(raw_location *the_location);
140
-
141
- // -----------------------------------------------------------------------------
142
-
143
- // Ruby 3.0 finally added support for showing "cfunc frames" (frames for methods written in C) in stack traces:
144
- // https://github.com/ruby/ruby/pull/3299/files
145
- //
146
- // The diff is rather trivial, and it makes a world of difference, given how most of Ruby's core classes are written in C.
147
- // Thus, the methods below are copied from that PR so that we can make use of this functionality on older Ruby versions.
148
- #ifdef CFUNC_FRAMES_BACKPORT_NEEDED
149
- #define backtracie_rb_profile_frame_method_name backported_rb_profile_frame_method_name
150
-
151
- VALUE backported_rb_profile_frame_method_name(VALUE frame);
152
- #else // Ruby > 3.0, just use the stock functionality
153
- #define backtracie_rb_profile_frame_method_name rb_profile_frame_method_name
154
- #endif
155
-
156
- // Backport https://github.com/ruby/ruby/pull/3084 (present in 2.7 and 3.0) to Ruby <= 2.6
157
- // The interesting bit is actually the fix to rb_profile_frame_classpath BUT since rb_profile_frame_qualified_method_name
158
- // internally relies on rb_profile_frame_classpath we also need to add a copy of that one as well.
159
- #ifdef CLASSPATH_BACKPORT_NEEDED
160
- #define backtracie_rb_profile_frame_classpath backported_rb_profile_frame_classpath
161
- #define backtracie_rb_profile_frame_qualified_method_name backported_rb_profile_frame_qualified_method_name
162
-
163
- VALUE backported_rb_profile_frame_classpath(VALUE frame);
164
- VALUE backported_rb_profile_frame_qualified_method_name(VALUE frame);
165
- #else
166
- #define backtracie_rb_profile_frame_classpath rb_profile_frame_classpath
167
- #define backtracie_rb_profile_frame_qualified_method_name rb_profile_frame_qualified_method_name
168
- #endif
169
-
170
- #endif