Filename | /usr/lib/x86_64-linux-gnu/perl-base/Carp.pm |
Statements | Executed 77 statements in 2.99ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 308µs | 344µs | BEGIN@168 | Carp::
1 | 1 | 1 | 36µs | 36µs | BEGIN@95 | Carp::
1 | 1 | 1 | 21µs | 21µs | BEGIN@572 | Carp::
1 | 1 | 1 | 18µs | 25µs | BEGIN@6 | Carp::
3 | 3 | 1 | 13µs | 13µs | _fetch_sub | Carp::
1 | 1 | 1 | 7µs | 13µs | BEGIN@137 | Carp::
1 | 1 | 1 | 7µs | 7µs | BEGIN@3 | Carp::
1 | 1 | 1 | 6µs | 11µs | BEGIN@728 | Carp::
1 | 1 | 1 | 4µs | 8µs | BEGIN@254 | Carp::
1 | 1 | 1 | 4µs | 4µs | BEGIN@49 | Carp::
1 | 1 | 1 | 4µs | 8µs | BEGIN@73 | Carp::
1 | 1 | 1 | 4µs | 9µs | BEGIN@187 | Carp::
1 | 1 | 1 | 4µs | 11µs | BEGIN@61 | Carp::
1 | 1 | 1 | 4µs | 15µs | BEGIN@742 | Carp::
1 | 1 | 1 | 4µs | 4µs | BEGIN@294 | Carp::
1 | 1 | 1 | 3µs | 6µs | BEGIN@749 | Carp::
1 | 1 | 1 | 3µs | 3µs | _univ_mod_loaded | Carp::
1 | 1 | 1 | 3µs | 4µs | BEGIN@4 | Carp::
1 | 1 | 1 | 2µs | 14µs | BEGIN@5 | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:103] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:115] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:139] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:184] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:188] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:190] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:192] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:208] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:406] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:417] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:66] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:86] | Carp::
0 | 0 | 0 | 0s | 0s | _cgc | Carp::
0 | 0 | 0 | 0s | 0s | caller_info | Carp::
0 | 0 | 0 | 0s | 0s | carp | Carp::
0 | 0 | 0 | 0s | 0s | cluck | Carp::
0 | 0 | 0 | 0s | 0s | confess | Carp::
0 | 0 | 0 | 0s | 0s | croak | Carp::
0 | 0 | 0 | 0s | 0s | export_fail | Carp::
0 | 0 | 0 | 0s | 0s | format_arg | Carp::
0 | 0 | 0 | 0s | 0s | get_status | Carp::
0 | 0 | 0 | 0s | 0s | get_subname | Carp::
0 | 0 | 0 | 0s | 0s | long_error_loc | Carp::
0 | 0 | 0 | 0s | 0s | longmess | Carp::
0 | 0 | 0 | 0s | 0s | longmess_heavy | Carp::
0 | 0 | 0 | 0s | 0s | ret_backtrace | Carp::
0 | 0 | 0 | 0s | 0s | ret_summary | Carp::
0 | 0 | 0 | 0s | 0s | short_error_loc | Carp::
0 | 0 | 0 | 0s | 0s | shortmess | Carp::
0 | 0 | 0 | 0s | 0s | shortmess_heavy | Carp::
0 | 0 | 0 | 0s | 0s | str_len_trim | Carp::
0 | 0 | 0 | 0s | 0s | trusts | Carp::
0 | 0 | 0 | 0s | 0s | trusts_directly | Carp::
0 | 0 | 0 | 0s | 0s | CARP_TRACE | Regexp::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Carp; | ||||
2 | |||||
3 | 2 | 24µs | 1 | 7µs | # spent 7µs within Carp::BEGIN@3 which was called:
# once (7µs+0s) by diagnostics::BEGIN@186 at line 3 # spent 7µs making 1 call to Carp::BEGIN@3 |
4 | 3 | 13µs | 2 | 5µs | # spent 4µs (3+1) within Carp::BEGIN@4 which was called:
# once (3µs+1µs) by diagnostics::BEGIN@186 at line 4 # spent 4µs making 1 call to Carp::BEGIN@4
# spent 1µs making 1 call to strict::import |
5 | 2 | 39µs | 2 | 26µs | # spent 14µs (2+12) within Carp::BEGIN@5 which was called:
# once (2µs+12µs) by diagnostics::BEGIN@186 at line 5 # spent 14µs making 1 call to Carp::BEGIN@5
# spent 12µs making 1 call to warnings::import |
6 | # spent 25µs (18+8) within Carp::BEGIN@6 which was called:
# once (18µs+8µs) by diagnostics::BEGIN@186 at line 26 | ||||
7 | # Very old versions of warnings.pm load Carp. This can go wrong due | ||||
8 | # to the circular dependency. If warnings is invoked before Carp, | ||||
9 | # then warnings starts by loading Carp, then Carp (above) tries to | ||||
10 | # invoke warnings, and gets nothing because warnings is in the process | ||||
11 | # of loading and hasn't defined its import method yet. If we were | ||||
12 | # only turning on warnings ("use warnings" above) this wouldn't be too | ||||
13 | # bad, because Carp would just gets the state of the -w switch and so | ||||
14 | # might not get some warnings that it wanted. The real problem is | ||||
15 | # that we then want to turn off Unicode warnings, but "no warnings | ||||
16 | # 'utf8'" won't be effective if we're in this circular-dependency | ||||
17 | # situation. So, if warnings.pm is an affected version, we turn | ||||
18 | # off all warnings ourselves by directly setting ${^WARNING_BITS}. | ||||
19 | # On unaffected versions, we turn off just Unicode warnings, via | ||||
20 | # the proper API. | ||||
21 | 1 | 14µs | if(!defined($warnings::VERSION) || eval($warnings::VERSION) < 1.06) { # spent 2µs executing statements in string eval | ||
22 | ${^WARNING_BITS} = ""; | ||||
23 | } else { | ||||
24 | 1 | 900ns | 1 | 8µs | "warnings"->unimport("utf8"); # spent 8µs making 1 call to warnings::unimport |
25 | } | ||||
26 | 1 | 108µs | 1 | 25µs | } # spent 25µs making 1 call to Carp::BEGIN@6 |
27 | |||||
28 | sub _fetch_sub { # fetch sub without autovivifying | ||||
29 | 3 | 1µs | my($pack, $sub) = @_; | ||
30 | 3 | 900ns | $pack .= '::'; | ||
31 | # only works with top-level packages | ||||
32 | 3 | 1µs | return unless exists($::{$pack}); | ||
33 | 3 | 1µs | for ($::{$pack}) { | ||
34 | 3 | 5µs | return unless ref \$_ eq 'GLOB' && *$_{HASH} && exists $$_{$sub}; | ||
35 | 3 | 800ns | for ($$_{$sub}) { | ||
36 | return ref \$_ eq 'GLOB' ? *$_{CODE} : undef | ||||
37 | 3 | 7µs | } | ||
38 | } | ||||
39 | } | ||||
40 | |||||
41 | # UTF8_REGEXP_PROBLEM is a compile-time constant indicating whether Carp | ||||
42 | # must avoid applying a regular expression to an upgraded (is_utf8) | ||||
43 | # string. There are multiple problems, on different Perl versions, | ||||
44 | # that require this to be avoided. All versions prior to 5.13.8 will | ||||
45 | # load utf8_heavy.pl for the swash system, even if the regexp doesn't | ||||
46 | # use character classes. Perl 5.6 and Perls [5.11.2, 5.13.11) exhibit | ||||
47 | # specific problems when Carp is being invoked in the aftermath of a | ||||
48 | # syntax error. | ||||
49 | # spent 4µs within Carp::BEGIN@49 which was called:
# once (4µs+0s) by diagnostics::BEGIN@186 at line 55 | ||||
50 | 1 | 4µs | if("$]" < 5.013011) { | ||
51 | *UTF8_REGEXP_PROBLEM = sub () { 1 }; | ||||
52 | } else { | ||||
53 | 1 | 800ns | *UTF8_REGEXP_PROBLEM = sub () { 0 }; | ||
54 | } | ||||
55 | 1 | 45µs | 1 | 4µs | } # spent 4µs making 1 call to Carp::BEGIN@49 |
56 | |||||
57 | # is_utf8() is essentially the utf8::is_utf8() function, which indicates | ||||
58 | # whether a string is represented in the upgraded form (using UTF-8 | ||||
59 | # internally). As utf8::is_utf8() is only available from Perl 5.8 | ||||
60 | # onwards, extra effort is required here to make it work on Perl 5.6. | ||||
61 | # spent 11µs (4+7) within Carp::BEGIN@61 which was called:
# once (4µs+7µs) by diagnostics::BEGIN@186 at line 68 | ||||
62 | 1 | 2µs | 1 | 7µs | if(defined(my $sub = _fetch_sub utf8 => 'is_utf8')) { # spent 7µs making 1 call to Carp::_fetch_sub |
63 | *is_utf8 = $sub; | ||||
64 | } else { | ||||
65 | # black magic for perl 5.6 | ||||
66 | *is_utf8 = sub { unpack("C", "\xaa".$_[0]) != 170 }; | ||||
67 | } | ||||
68 | 1 | 87µs | 1 | 11µs | } # spent 11µs making 1 call to Carp::BEGIN@61 |
69 | |||||
70 | # The downgrade() function defined here is to be used for attempts to | ||||
71 | # downgrade where it is acceptable to fail. It must be called with a | ||||
72 | # second argument that is a true value. | ||||
73 | # spent 8µs (4+3) within Carp::BEGIN@73 which was called:
# once (4µs+3µs) by diagnostics::BEGIN@186 at line 88 | ||||
74 | 1 | 2µs | 1 | 3µs | if(defined(my $sub = _fetch_sub utf8 => 'downgrade')) { # spent 3µs making 1 call to Carp::_fetch_sub |
75 | *downgrade = \&{"utf8::downgrade"}; | ||||
76 | } else { | ||||
77 | *downgrade = sub { | ||||
78 | my $r = ""; | ||||
79 | my $l = length($_[0]); | ||||
80 | for(my $i = 0; $i != $l; $i++) { | ||||
81 | my $o = ord(substr($_[0], $i, 1)); | ||||
82 | return if $o > 255; | ||||
83 | $r .= chr($o); | ||||
84 | } | ||||
85 | $_[0] = $r; | ||||
86 | }; | ||||
87 | } | ||||
88 | 1 | 68µs | 1 | 8µs | } # spent 8µs making 1 call to Carp::BEGIN@73 |
89 | |||||
90 | # is_safe_printable_codepoint() indicates whether a character, specified | ||||
91 | # by integer codepoint, is OK to output literally in a trace. Generally | ||||
92 | # this is if it is a printable character in the ancestral character set | ||||
93 | # (ASCII or EBCDIC). This is used on some Perls in situations where a | ||||
94 | # regexp can't be used. | ||||
95 | # spent 36µs within Carp::BEGIN@95 which was called:
# once (36µs+0s) by diagnostics::BEGIN@186 at line 117 | ||||
96 | *is_safe_printable_codepoint = | ||||
97 | "$]" >= 5.007_003 ? | ||||
98 | eval(q(sub ($) { | ||||
99 | my $u = utf8::native_to_unicode($_[0]); | ||||
100 | $u >= 0x20 && $u <= 0x7e; | ||||
101 | })) | ||||
102 | : ord("A") == 65 ? | ||||
103 | sub ($) { $_[0] >= 0x20 && $_[0] <= 0x7e } | ||||
104 | : | ||||
105 | sub ($) { | ||||
106 | # Early EBCDIC | ||||
107 | # 3 EBCDIC code pages supported then; all controls but one | ||||
108 | # are the code points below SPACE. The other one is 0x5F on | ||||
109 | # POSIX-BC; FF on the other two. | ||||
110 | # FIXME: there are plenty of unprintable codepoints other | ||||
111 | # than those that this code and the comment above identifies | ||||
112 | # as "controls". | ||||
113 | $_[0] >= ord(" ") && $_[0] <= 0xff && | ||||
114 | $_[0] != (ord ("^") == 106 ? 0x5f : 0xff); | ||||
115 | } | ||||
116 | 1 | 34µs | ; # spent 3µs executing statements in string eval | ||
117 | 1 | 122µs | 1 | 36µs | } # spent 36µs making 1 call to Carp::BEGIN@95 |
118 | |||||
119 | # spent 3µs within Carp::_univ_mod_loaded which was called:
# once (3µs+0s) by Carp::BEGIN@137 at line 138 | ||||
120 | 1 | 400ns | return 0 unless exists($::{"UNIVERSAL::"}); | ||
121 | 1 | 300ns | for ($::{"UNIVERSAL::"}) { | ||
122 | 1 | 5µs | return 0 unless ref \$_ eq "GLOB" && *$_{HASH} && exists $$_{"$_[0]::"}; | ||
123 | for ($$_{"$_[0]::"}) { | ||||
124 | return 0 unless ref \$_ eq "GLOB" && *$_{HASH} && exists $$_{"VERSION"}; | ||||
125 | for ($$_{"VERSION"}) { | ||||
126 | return 0 unless ref \$_ eq "GLOB"; | ||||
127 | return ${*$_{SCALAR}}; | ||||
128 | } | ||||
129 | } | ||||
130 | } | ||||
131 | } | ||||
132 | |||||
133 | # _maybe_isa() is usually the UNIVERSAL::isa function. We have to avoid | ||||
134 | # the latter if the UNIVERSAL::isa module has been loaded, to avoid infi- | ||||
135 | # nite recursion; in that case _maybe_isa simply returns true. | ||||
136 | 1 | 100ns | my $isa; | ||
137 | # spent 13µs (7+6) within Carp::BEGIN@137 which was called:
# once (7µs+6µs) by diagnostics::BEGIN@186 at line 146 | ||||
138 | 1 | 2µs | 1 | 3µs | if (_univ_mod_loaded('isa')) { # spent 3µs making 1 call to Carp::_univ_mod_loaded |
139 | *_maybe_isa = sub { 1 } | ||||
140 | } | ||||
141 | else { | ||||
142 | # Since we have already done the check, record $isa for use below | ||||
143 | # when defining _StrVal. | ||||
144 | 1 | 900ns | 1 | 3µs | *_maybe_isa = $isa = _fetch_sub(UNIVERSAL => "isa"); # spent 3µs making 1 call to Carp::_fetch_sub |
145 | } | ||||
146 | 1 | 81µs | 1 | 13µs | } # spent 13µs making 1 call to Carp::BEGIN@137 |
147 | |||||
148 | # We need an overload::StrVal or equivalent function, but we must avoid | ||||
149 | # loading any modules on demand, as Carp is used from __DIE__ handlers and | ||||
150 | # may be invoked after a syntax error. | ||||
151 | # We can copy recent implementations of overload::StrVal and use | ||||
152 | # overloading.pm, which is the fastest implementation, so long as | ||||
153 | # overloading is available. If it is not available, we use our own pure- | ||||
154 | # Perl StrVal. We never actually use overload::StrVal, for various rea- | ||||
155 | # sons described below. | ||||
156 | # overload versions are as follows: | ||||
157 | # undef-1.00 (up to perl 5.8.0) uses bless (avoid!) | ||||
158 | # 1.01-1.17 (perl 5.8.1 to 5.14) uses Scalar::Util | ||||
159 | # 1.18+ (perl 5.16+) uses overloading | ||||
160 | # The ancient 'bless' implementation (that inspires our pure-Perl version) | ||||
161 | # blesses unblessed references and must be avoided. Those using | ||||
162 | # Scalar::Util use refaddr, possibly the pure-Perl implementation, which | ||||
163 | # has the same blessing bug, and must be avoided. Also, Scalar::Util is | ||||
164 | # loaded on demand. Since we avoid the Scalar::Util implementations, we | ||||
165 | # end up having to implement our own overloading.pm-based version for perl | ||||
166 | # 5.10.1 to 5.14. Since it also works just as well in more recent ver- | ||||
167 | # sions, we use it there, too. | ||||
168 | # spent 344µs (308+36) within Carp::BEGIN@168 which was called:
# once (308µs+36µs) by diagnostics::BEGIN@186 at line 210 | ||||
169 | 2 | 74µs | if (eval { require "overloading.pm" }) { | ||
170 | 1 | 21µs | *_StrVal = eval 'sub { no overloading; "$_[0]" }' # spent 22µs executing statements in string eval # includes 9µs spent executing 1 call to 2 subs defined therein. | ||
171 | } | ||||
172 | else { | ||||
173 | # Work around the UNIVERSAL::can/isa modules to avoid recursion. | ||||
174 | |||||
175 | # _mycan is either UNIVERSAL::can, or, in the presence of an | ||||
176 | # override, overload::mycan. | ||||
177 | *_mycan = _univ_mod_loaded('can') | ||||
178 | ? do { require "overload.pm"; _fetch_sub overload => 'mycan' } | ||||
179 | : \&UNIVERSAL::can; | ||||
180 | |||||
181 | # _blessed is either UNIVERAL::isa(...), or, in the presence of an | ||||
182 | # override, a hideous, but fairly reliable, workaround. | ||||
183 | *_blessed = $isa | ||||
184 | ? sub { &$isa($_[0], "UNIVERSAL") } | ||||
185 | : sub { | ||||
186 | my $probe = "UNIVERSAL::Carp_probe_" . rand; | ||||
187 | 2 | 132µs | 2 | 14µs | # spent 9µs (4+5) within Carp::BEGIN@187 which was called:
# once (4µs+5µs) by diagnostics::BEGIN@186 at line 187 # spent 9µs making 1 call to Carp::BEGIN@187
# spent 5µs making 1 call to strict::unimport |
188 | local *$probe = sub { "unlikely string" }; | ||||
189 | local $@; | ||||
190 | local $SIG{__DIE__} = sub{}; | ||||
191 | (eval { $_[0]->$probe } || '') eq 'unlikely string' | ||||
192 | }; | ||||
193 | |||||
194 | *_StrVal = sub { | ||||
195 | my $pack = ref $_[0]; | ||||
196 | # Perl's overload mechanism uses the presence of a special | ||||
197 | # "method" named "((" or "()" to signal it is in effect. | ||||
198 | # This test seeks to see if it has been set up. "((" post- | ||||
199 | # dates overloading.pm, so we can skip it. | ||||
200 | return "$_[0]" unless _mycan($pack, "()"); | ||||
201 | # Even at this point, the invocant may not be blessed, so | ||||
202 | # check for that. | ||||
203 | return "$_[0]" if not _blessed($_[0]); | ||||
204 | bless $_[0], "Carp"; | ||||
205 | my $str = "$_[0]"; | ||||
206 | bless $_[0], $pack; | ||||
207 | $pack . substr $str, index $str, "="; | ||||
208 | } | ||||
209 | } | ||||
210 | 1 | 128µs | 1 | 344µs | } # spent 344µs making 1 call to Carp::BEGIN@168 |
211 | |||||
212 | 1 | 300ns | our $VERSION = '1.52'; | ||
213 | 1 | 800ns | $VERSION =~ tr/_//d; | ||
214 | |||||
215 | 1 | 200ns | our $MaxEvalLen = 0; | ||
216 | 1 | 100ns | our $Verbose = 0; | ||
217 | 1 | 100ns | our $CarpLevel = 0; | ||
218 | 1 | 0s | our $MaxArgLen = 64; # How much of each argument to print. 0 = all. | ||
219 | 1 | 100ns | our $MaxArgNums = 8; # How many arguments to print. 0 = all. | ||
220 | 1 | 100ns | our $RefArgFormatter = undef; # allow caller to format reference arguments | ||
221 | |||||
222 | 1 | 76µs | require Exporter; | ||
223 | 1 | 6µs | our @ISA = ('Exporter'); | ||
224 | 1 | 500ns | our @EXPORT = qw(confess croak carp); | ||
225 | 1 | 400ns | our @EXPORT_OK = qw(cluck verbose longmess shortmess); | ||
226 | 1 | 200ns | our @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode | ||
227 | |||||
228 | # The members of %Internal are packages that are internal to perl. | ||||
229 | # Carp will not report errors from within these packages if it | ||||
230 | # can. The members of %CarpInternal are internal to Perl's warning | ||||
231 | # system. Carp will not report errors from within these packages | ||||
232 | # either, and will not report calls *to* these packages for carp and | ||||
233 | # croak. They replace $CarpLevel, which is deprecated. The | ||||
234 | # $Max(EvalLen|(Arg(Len|Nums)) variables are used to specify how the eval | ||||
235 | # text and function arguments should be formatted when printed. | ||||
236 | |||||
237 | our %CarpInternal; | ||||
238 | our %Internal; | ||||
239 | |||||
240 | # disable these by default, so they can live w/o require Carp | ||||
241 | 1 | 800ns | $CarpInternal{Carp}++; | ||
242 | 1 | 200ns | $CarpInternal{warnings}++; | ||
243 | 1 | 200ns | $Internal{Exporter}++; | ||
244 | 1 | 100ns | $Internal{'Exporter::Heavy'}++; | ||
245 | |||||
246 | # if the caller specifies verbose usage ("perl -MCarp=verbose script.pl") | ||||
247 | # then the following method will be called by the Exporter which knows | ||||
248 | # to do this thanks to @EXPORT_FAIL, above. $_[1] will contain the word | ||||
249 | # 'verbose'. | ||||
250 | |||||
251 | sub export_fail { shift; $Verbose = shift if $_[0] eq 'verbose'; @_ } | ||||
252 | |||||
253 | sub _cgc { | ||||
254 | 2 | 218µs | 2 | 12µs | # spent 8µs (4+4) within Carp::BEGIN@254 which was called:
# once (4µs+4µs) by diagnostics::BEGIN@186 at line 254 # spent 8µs making 1 call to Carp::BEGIN@254
# spent 4µs making 1 call to strict::unimport |
255 | return \&{"CORE::GLOBAL::caller"} if defined &{"CORE::GLOBAL::caller"}; | ||||
256 | return; | ||||
257 | } | ||||
258 | |||||
259 | sub longmess { | ||||
260 | local($!, $^E); | ||||
261 | # Icky backwards compatibility wrapper. :-( | ||||
262 | # | ||||
263 | # The story is that the original implementation hard-coded the | ||||
264 | # number of call levels to go back, so calls to longmess were off | ||||
265 | # by one. Other code began calling longmess and expecting this | ||||
266 | # behaviour, so the replacement has to emulate that behaviour. | ||||
267 | my $cgc = _cgc(); | ||||
268 | my $call_pack = $cgc ? $cgc->() : caller(); | ||||
269 | if ( $Internal{$call_pack} or $CarpInternal{$call_pack} ) { | ||||
270 | return longmess_heavy(@_); | ||||
271 | } | ||||
272 | else { | ||||
273 | local $CarpLevel = $CarpLevel + 1; | ||||
274 | return longmess_heavy(@_); | ||||
275 | } | ||||
276 | } | ||||
277 | |||||
278 | our @CARP_NOT; | ||||
279 | |||||
280 | sub shortmess { | ||||
281 | local($!, $^E); | ||||
282 | my $cgc = _cgc(); | ||||
283 | |||||
284 | # Icky backwards compatibility wrapper. :-( | ||||
285 | local @CARP_NOT = scalar( $cgc ? $cgc->() : caller() ); | ||||
286 | shortmess_heavy(@_); | ||||
287 | } | ||||
288 | |||||
289 | sub croak { die shortmess @_ } | ||||
290 | sub confess { die longmess @_ } | ||||
291 | sub carp { warn shortmess @_ } | ||||
292 | sub cluck { warn longmess @_ } | ||||
293 | |||||
294 | # spent 4µs within Carp::BEGIN@294 which was called:
# once (4µs+0s) by diagnostics::BEGIN@186 at line 301 | ||||
295 | 1 | 4µs | if("$]" >= 5.015002 || ("$]" >= 5.014002 && "$]" < 5.015) || | ||
296 | ("$]" >= 5.012005 && "$]" < 5.013)) { | ||||
297 | *CALLER_OVERRIDE_CHECK_OK = sub () { 1 }; | ||||
298 | } else { | ||||
299 | *CALLER_OVERRIDE_CHECK_OK = sub () { 0 }; | ||||
300 | } | ||||
301 | 1 | 944µs | 1 | 4µs | } # spent 4µs making 1 call to Carp::BEGIN@294 |
302 | |||||
303 | sub caller_info { | ||||
304 | my $i = shift(@_) + 1; | ||||
305 | my %call_info; | ||||
306 | my $cgc = _cgc(); | ||||
307 | { | ||||
308 | # Some things override caller() but forget to implement the | ||||
309 | # @DB::args part of it, which we need. We check for this by | ||||
310 | # pre-populating @DB::args with a sentinel which no-one else | ||||
311 | # has the address of, so that we can detect whether @DB::args | ||||
312 | # has been properly populated. However, on earlier versions | ||||
313 | # of perl this check tickles a bug in CORE::caller() which | ||||
314 | # leaks memory. So we only check on fixed perls. | ||||
315 | @DB::args = \$i if CALLER_OVERRIDE_CHECK_OK; | ||||
316 | package DB; | ||||
317 | |||||
- - | |||||
322 | unless ( defined $call_info{file} ) { | ||||
323 | return (); | ||||
324 | } | ||||
325 | |||||
326 | my $sub_name = Carp::get_subname( \%call_info ); | ||||
327 | if ( $call_info{has_args} ) { | ||||
328 | # Guard our serialization of the stack from stack refcounting bugs | ||||
329 | # NOTE this is NOT a complete solution, we cannot 100% guard against | ||||
330 | # these bugs. However in many cases Perl *is* capable of detecting | ||||
331 | # them and throws an error when it does. Unfortunately serializing | ||||
332 | # the arguments on the stack is a perfect way of finding these bugs, | ||||
333 | # even when they would not affect normal program flow that did not | ||||
334 | # poke around inside the stack. Inside of Carp.pm it makes little | ||||
335 | # sense reporting these bugs, as Carp's job is to report the callers | ||||
336 | # errors, not the ones it might happen to tickle while doing so. | ||||
337 | # See: https://rt.perl.org/Public/Bug/Display.html?id=131046 | ||||
338 | # and: https://rt.perl.org/Public/Bug/Display.html?id=52610 | ||||
339 | # for more details and discussion. - Yves | ||||
340 | my @args = map { | ||||
341 | my $arg; | ||||
342 | local $@= $@; | ||||
343 | eval { | ||||
344 | $arg = $_; | ||||
345 | 1; | ||||
346 | } or do { | ||||
347 | $arg = '** argument not available anymore **'; | ||||
348 | }; | ||||
349 | $arg; | ||||
350 | } @DB::args; | ||||
351 | if (CALLER_OVERRIDE_CHECK_OK && @args == 1 | ||||
352 | && ref $args[0] eq ref \$i | ||||
353 | && $args[0] == \$i ) { | ||||
354 | @args = (); # Don't let anyone see the address of $i | ||||
355 | local $@; | ||||
356 | my $where = eval { | ||||
357 | my $func = $cgc or return ''; | ||||
358 | my $gv = | ||||
359 | (_fetch_sub B => 'svref_2object' or return '') | ||||
360 | ->($func)->GV; | ||||
361 | my $package = $gv->STASH->NAME; | ||||
362 | my $subname = $gv->NAME; | ||||
363 | return unless defined $package && defined $subname; | ||||
364 | |||||
365 | # returning CORE::GLOBAL::caller isn't useful for tracing the cause: | ||||
366 | return if $package eq 'CORE::GLOBAL' && $subname eq 'caller'; | ||||
367 | " in &${package}::$subname"; | ||||
368 | } || ''; | ||||
369 | @args | ||||
370 | = "** Incomplete caller override detected$where; \@DB::args were not set **"; | ||||
371 | } | ||||
372 | else { | ||||
373 | my $overflow; | ||||
374 | if ( $MaxArgNums and @args > $MaxArgNums ) | ||||
375 | { # More than we want to show? | ||||
376 | $#args = $MaxArgNums - 1; | ||||
377 | $overflow = 1; | ||||
378 | } | ||||
379 | |||||
380 | @args = map { Carp::format_arg($_) } @args; | ||||
381 | |||||
382 | if ($overflow) { | ||||
383 | push @args, '...'; | ||||
384 | } | ||||
385 | } | ||||
386 | |||||
387 | # Push the args onto the subroutine | ||||
388 | $sub_name .= '(' . join( ', ', @args ) . ')'; | ||||
389 | } | ||||
390 | $call_info{sub_name} = $sub_name; | ||||
391 | return wantarray() ? %call_info : \%call_info; | ||||
392 | } | ||||
393 | |||||
394 | # Transform an argument to a function into a string. | ||||
395 | our $in_recurse; | ||||
396 | sub format_arg { | ||||
397 | my $arg = shift; | ||||
398 | |||||
399 | if ( my $pack= ref($arg) ) { | ||||
400 | |||||
401 | # legitimate, let's not leak it. | ||||
402 | if (!$in_recurse && _maybe_isa( $arg, 'UNIVERSAL' ) && | ||||
403 | do { | ||||
404 | local $@; | ||||
405 | local $in_recurse = 1; | ||||
406 | local $SIG{__DIE__} = sub{}; | ||||
407 | eval {$arg->can('CARP_TRACE') } | ||||
408 | }) | ||||
409 | { | ||||
410 | return $arg->CARP_TRACE(); | ||||
411 | } | ||||
412 | elsif (!$in_recurse && | ||||
413 | defined($RefArgFormatter) && | ||||
414 | do { | ||||
415 | local $@; | ||||
416 | local $in_recurse = 1; | ||||
417 | local $SIG{__DIE__} = sub{}; | ||||
418 | eval {$arg = $RefArgFormatter->($arg); 1} | ||||
419 | }) | ||||
420 | { | ||||
421 | return $arg; | ||||
422 | } | ||||
423 | else | ||||
424 | { | ||||
425 | # Argument may be blessed into a class with overloading, and so | ||||
426 | # might have an overloaded stringification. We don't want to | ||||
427 | # risk getting the overloaded stringification, so we need to | ||||
428 | # use _StrVal, our overload::StrVal()-equivalent. | ||||
429 | return _StrVal $arg; | ||||
430 | } | ||||
431 | } | ||||
432 | return "undef" if !defined($arg); | ||||
433 | downgrade($arg, 1); | ||||
434 | return $arg if !(UTF8_REGEXP_PROBLEM && is_utf8($arg)) && | ||||
435 | $arg =~ /\A-?[0-9]+(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?\z/; | ||||
436 | my $suffix = ""; | ||||
437 | if ( 2 < $MaxArgLen and $MaxArgLen < length($arg) ) { | ||||
438 | substr ( $arg, $MaxArgLen - 3 ) = ""; | ||||
439 | $suffix = "..."; | ||||
440 | } | ||||
441 | if(UTF8_REGEXP_PROBLEM && is_utf8($arg)) { | ||||
442 | for(my $i = length($arg); $i--; ) { | ||||
443 | my $c = substr($arg, $i, 1); | ||||
444 | my $x = substr($arg, 0, 0); # work around bug on Perl 5.8.{1,2} | ||||
445 | if($c eq "\"" || $c eq "\\" || $c eq "\$" || $c eq "\@") { | ||||
446 | substr $arg, $i, 0, "\\"; | ||||
447 | next; | ||||
448 | } | ||||
449 | my $o = ord($c); | ||||
450 | substr $arg, $i, 1, sprintf("\\x{%x}", $o) | ||||
451 | unless is_safe_printable_codepoint($o); | ||||
452 | } | ||||
453 | } else { | ||||
454 | $arg =~ s/([\"\\\$\@])/\\$1/g; | ||||
455 | # This is all the ASCII printables spelled-out. It is portable to all | ||||
456 | # Perl versions and platforms (such as EBCDIC). There are other more | ||||
457 | # compact ways to do this, but may not work everywhere every version. | ||||
458 | $arg =~ s/([^ !"#\$\%\&'()*+,\-.\/0123456789:;<=>?\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]^_`abcdefghijklmnopqrstuvwxyz\{|}~])/sprintf("\\x{%x}",ord($1))/eg; | ||||
459 | } | ||||
460 | downgrade($arg, 1); | ||||
461 | return "\"".$arg."\"".$suffix; | ||||
462 | } | ||||
463 | |||||
464 | sub Regexp::CARP_TRACE { | ||||
465 | my $arg = "$_[0]"; | ||||
466 | downgrade($arg, 1); | ||||
467 | if(UTF8_REGEXP_PROBLEM && is_utf8($arg)) { | ||||
468 | for(my $i = length($arg); $i--; ) { | ||||
469 | my $o = ord(substr($arg, $i, 1)); | ||||
470 | my $x = substr($arg, 0, 0); # work around bug on Perl 5.8.{1,2} | ||||
471 | substr $arg, $i, 1, sprintf("\\x{%x}", $o) | ||||
472 | unless is_safe_printable_codepoint($o); | ||||
473 | } | ||||
474 | } else { | ||||
475 | # See comment in format_arg() about this same regex. | ||||
476 | $arg =~ s/([^ !"#\$\%\&'()*+,\-.\/0123456789:;<=>?\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]^_`abcdefghijklmnopqrstuvwxyz\{|}~])/sprintf("\\x{%x}",ord($1))/eg; | ||||
477 | } | ||||
478 | downgrade($arg, 1); | ||||
479 | my $suffix = ""; | ||||
480 | if($arg =~ /\A\(\?\^?([a-z]*)(?:-[a-z]*)?:(.*)\)\z/s) { | ||||
481 | ($suffix, $arg) = ($1, $2); | ||||
482 | } | ||||
483 | if ( 2 < $MaxArgLen and $MaxArgLen < length($arg) ) { | ||||
484 | substr ( $arg, $MaxArgLen - 3 ) = ""; | ||||
485 | $suffix = "...".$suffix; | ||||
486 | } | ||||
487 | return "qr($arg)$suffix"; | ||||
488 | } | ||||
489 | |||||
490 | # Takes an inheritance cache and a package and returns | ||||
491 | # an anon hash of known inheritances and anon array of | ||||
492 | # inheritances which consequences have not been figured | ||||
493 | # for. | ||||
494 | sub get_status { | ||||
495 | my $cache = shift; | ||||
496 | my $pkg = shift; | ||||
497 | $cache->{$pkg} ||= [ { $pkg => $pkg }, [ trusts_directly($pkg) ] ]; | ||||
498 | return @{ $cache->{$pkg} }; | ||||
499 | } | ||||
500 | |||||
501 | # Takes the info from caller() and figures out the name of | ||||
502 | # the sub/require/eval | ||||
503 | sub get_subname { | ||||
504 | my $info = shift; | ||||
505 | if ( defined( $info->{evaltext} ) ) { | ||||
506 | my $eval = $info->{evaltext}; | ||||
507 | if ( $info->{is_require} ) { | ||||
508 | return "require $eval"; | ||||
509 | } | ||||
510 | else { | ||||
511 | $eval =~ s/([\\\'])/\\$1/g; | ||||
512 | return "eval '" . str_len_trim( $eval, $MaxEvalLen ) . "'"; | ||||
513 | } | ||||
514 | } | ||||
515 | |||||
516 | # this can happen on older perls when the sub (or the stash containing it) | ||||
517 | # has been deleted | ||||
518 | if ( !defined( $info->{sub} ) ) { | ||||
519 | return '__ANON__::__ANON__'; | ||||
520 | } | ||||
521 | |||||
522 | return ( $info->{sub} eq '(eval)' ) ? 'eval {...}' : $info->{sub}; | ||||
523 | } | ||||
524 | |||||
525 | # Figures out what call (from the point of view of the caller) | ||||
526 | # the long error backtrace should start at. | ||||
527 | sub long_error_loc { | ||||
528 | my $i; | ||||
529 | my $lvl = $CarpLevel; | ||||
530 | { | ||||
531 | ++$i; | ||||
532 | my $cgc = _cgc(); | ||||
533 | my @caller = $cgc ? $cgc->($i) : caller($i); | ||||
534 | my $pkg = $caller[0]; | ||||
535 | unless ( defined($pkg) ) { | ||||
536 | |||||
537 | # This *shouldn't* happen. | ||||
538 | if (%Internal) { | ||||
539 | local %Internal; | ||||
540 | $i = long_error_loc(); | ||||
541 | last; | ||||
542 | } | ||||
543 | elsif (defined $caller[2]) { | ||||
544 | # this can happen when the stash has been deleted | ||||
545 | # in that case, just assume that it's a reasonable place to | ||||
546 | # stop (the file and line data will still be intact in any | ||||
547 | # case) - the only issue is that we can't detect if the | ||||
548 | # deleted package was internal (so don't do that then) | ||||
549 | # -doy | ||||
550 | redo unless 0 > --$lvl; | ||||
551 | last; | ||||
552 | } | ||||
553 | else { | ||||
554 | return 2; | ||||
555 | } | ||||
556 | } | ||||
557 | redo if $CarpInternal{$pkg}; | ||||
558 | redo unless 0 > --$lvl; | ||||
559 | redo if $Internal{$pkg}; | ||||
560 | } | ||||
561 | return $i - 1; | ||||
562 | } | ||||
563 | |||||
564 | sub longmess_heavy { | ||||
565 | if ( ref( $_[0] ) ) { # don't break references as exceptions | ||||
566 | return wantarray ? @_ : $_[0]; | ||||
567 | } | ||||
568 | my $i = long_error_loc(); | ||||
569 | return ret_backtrace( $i, @_ ); | ||||
570 | } | ||||
571 | |||||
572 | # spent 21µs within Carp::BEGIN@572 which was called:
# once (21µs+0s) by diagnostics::BEGIN@186 at line 579 | ||||
573 | 1 | 4µs | if("$]" >= 5.017004) { | ||
574 | # The LAST_FH constant is a reference to the variable. | ||||
575 | 1 | 15µs | $Carp::{LAST_FH} = \eval '\${^LAST_FH}'; # spent 2µs executing statements in string eval | ||
576 | } else { | ||||
577 | eval '*LAST_FH = sub () { 0 }'; | ||||
578 | } | ||||
579 | 1 | 522µs | 1 | 21µs | } # spent 21µs making 1 call to Carp::BEGIN@572 |
580 | |||||
581 | # Returns a full stack backtrace starting from where it is | ||||
582 | # told. | ||||
583 | sub ret_backtrace { | ||||
584 | my ( $i, @error ) = @_; | ||||
585 | my $mess; | ||||
586 | my $err = join '', @error; | ||||
587 | $i++; | ||||
588 | |||||
589 | my $tid_msg = ''; | ||||
590 | if ( defined &threads::tid ) { | ||||
591 | my $tid = threads->tid; | ||||
592 | $tid_msg = " thread $tid" if $tid; | ||||
593 | } | ||||
594 | |||||
595 | my %i = caller_info($i); | ||||
596 | $mess = "$err at $i{file} line $i{line}$tid_msg"; | ||||
597 | if( $. ) { | ||||
598 | # Use ${^LAST_FH} if available. | ||||
599 | if (LAST_FH) { | ||||
600 | if (${+LAST_FH}) { | ||||
601 | $mess .= sprintf ", <%s> %s %d", | ||||
602 | *${+LAST_FH}{NAME}, | ||||
603 | ($/ eq "\n" ? "line" : "chunk"), $. | ||||
604 | } | ||||
605 | } | ||||
606 | else { | ||||
607 | local $@ = ''; | ||||
608 | local $SIG{__DIE__}; | ||||
609 | eval { | ||||
610 | CORE::die; | ||||
611 | }; | ||||
612 | if($@ =~ /^Died at .*(, <.*?> (?:line|chunk) \d+).$/ ) { | ||||
613 | $mess .= $1; | ||||
614 | } | ||||
615 | } | ||||
616 | } | ||||
617 | $mess .= "\.\n"; | ||||
618 | |||||
619 | while ( my %i = caller_info( ++$i ) ) { | ||||
620 | $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n"; | ||||
621 | } | ||||
622 | |||||
623 | return $mess; | ||||
624 | } | ||||
625 | |||||
626 | sub ret_summary { | ||||
627 | my ( $i, @error ) = @_; | ||||
628 | my $err = join '', @error; | ||||
629 | $i++; | ||||
630 | |||||
631 | my $tid_msg = ''; | ||||
632 | if ( defined &threads::tid ) { | ||||
633 | my $tid = threads->tid; | ||||
634 | $tid_msg = " thread $tid" if $tid; | ||||
635 | } | ||||
636 | |||||
637 | my %i = caller_info($i); | ||||
638 | return "$err at $i{file} line $i{line}$tid_msg\.\n"; | ||||
639 | } | ||||
640 | |||||
641 | sub short_error_loc { | ||||
642 | # You have to create your (hash)ref out here, rather than defaulting it | ||||
643 | # inside trusts *on a lexical*, as you want it to persist across calls. | ||||
644 | # (You can default it on $_[2], but that gets messy) | ||||
645 | my $cache = {}; | ||||
646 | my $i = 1; | ||||
647 | my $lvl = $CarpLevel; | ||||
648 | { | ||||
649 | my $cgc = _cgc(); | ||||
650 | my $called = $cgc ? $cgc->($i) : caller($i); | ||||
651 | $i++; | ||||
652 | my $caller = $cgc ? $cgc->($i) : caller($i); | ||||
653 | |||||
654 | if (!defined($caller)) { | ||||
655 | my @caller = $cgc ? $cgc->($i) : caller($i); | ||||
656 | if (@caller) { | ||||
657 | # if there's no package but there is other caller info, then | ||||
658 | # the package has been deleted - treat this as a valid package | ||||
659 | # in this case | ||||
660 | redo if defined($called) && $CarpInternal{$called}; | ||||
661 | redo unless 0 > --$lvl; | ||||
662 | last; | ||||
663 | } | ||||
664 | else { | ||||
665 | return 0; | ||||
666 | } | ||||
667 | } | ||||
668 | redo if $Internal{$caller}; | ||||
669 | redo if $CarpInternal{$caller}; | ||||
670 | redo if $CarpInternal{$called}; | ||||
671 | redo if trusts( $called, $caller, $cache ); | ||||
672 | redo if trusts( $caller, $called, $cache ); | ||||
673 | redo unless 0 > --$lvl; | ||||
674 | } | ||||
675 | return $i - 1; | ||||
676 | } | ||||
677 | |||||
678 | sub shortmess_heavy { | ||||
679 | return longmess_heavy(@_) if $Verbose; | ||||
680 | return @_ if ref( $_[0] ); # don't break references as exceptions | ||||
681 | my $i = short_error_loc(); | ||||
682 | if ($i) { | ||||
683 | ret_summary( $i, @_ ); | ||||
684 | } | ||||
685 | else { | ||||
686 | longmess_heavy(@_); | ||||
687 | } | ||||
688 | } | ||||
689 | |||||
690 | # If a string is too long, trims it with ... | ||||
691 | sub str_len_trim { | ||||
692 | my $str = shift; | ||||
693 | my $max = shift || 0; | ||||
694 | if ( 2 < $max and $max < length($str) ) { | ||||
695 | substr( $str, $max - 3 ) = '...'; | ||||
696 | } | ||||
697 | return $str; | ||||
698 | } | ||||
699 | |||||
700 | # Takes two packages and an optional cache. Says whether the | ||||
701 | # first inherits from the second. | ||||
702 | # | ||||
703 | # Recursive versions of this have to work to avoid certain | ||||
704 | # possible endless loops, and when following long chains of | ||||
705 | # inheritance are less efficient. | ||||
706 | sub trusts { | ||||
707 | my $child = shift; | ||||
708 | my $parent = shift; | ||||
709 | my $cache = shift; | ||||
710 | my ( $known, $partial ) = get_status( $cache, $child ); | ||||
711 | |||||
712 | # Figure out consequences until we have an answer | ||||
713 | while ( @$partial and not exists $known->{$parent} ) { | ||||
714 | my $anc = shift @$partial; | ||||
715 | next if exists $known->{$anc}; | ||||
716 | $known->{$anc}++; | ||||
717 | my ( $anc_knows, $anc_partial ) = get_status( $cache, $anc ); | ||||
718 | my @found = keys %$anc_knows; | ||||
719 | @$known{@found} = (); | ||||
720 | push @$partial, @$anc_partial; | ||||
721 | } | ||||
722 | return exists $known->{$parent}; | ||||
723 | } | ||||
724 | |||||
725 | # Takes a package and gives a list of those trusted directly | ||||
726 | sub trusts_directly { | ||||
727 | my $class = shift; | ||||
728 | 2 | 82µs | 2 | 15µs | # spent 11µs (6+5) within Carp::BEGIN@728 which was called:
# once (6µs+5µs) by diagnostics::BEGIN@186 at line 728 # spent 11µs making 1 call to Carp::BEGIN@728
# spent 5µs making 1 call to strict::unimport |
729 | my $stash = \%{"$class\::"}; | ||||
730 | for my $var (qw/ CARP_NOT ISA /) { | ||||
731 | # Don't try using the variable until we know it exists, | ||||
732 | # to avoid polluting the caller's namespace. | ||||
733 | if ( $stash->{$var} && ref \$stash->{$var} eq 'GLOB' | ||||
734 | && *{$stash->{$var}}{ARRAY} && @{$stash->{$var}} ) { | ||||
735 | return @{$stash->{$var}} | ||||
736 | } | ||||
737 | } | ||||
738 | return; | ||||
739 | } | ||||
740 | |||||
741 | 1 | 500ns | if(!defined($warnings::VERSION) || | ||
742 | 3 | 24µs | 2 | 26µs | # spent 15µs (4+11) within Carp::BEGIN@742 which was called:
# once (4µs+11µs) by diagnostics::BEGIN@186 at line 742 # spent 15µs making 1 call to Carp::BEGIN@742
# spent 11µs making 1 call to warnings::unimport |
743 | # Very old versions of warnings.pm import from Carp. This can go | ||||
744 | # wrong due to the circular dependency. If Carp is invoked before | ||||
745 | # warnings, then Carp starts by loading warnings, then warnings | ||||
746 | # tries to import from Carp, and gets nothing because Carp is in | ||||
747 | # the process of loading and hasn't defined its import method yet. | ||||
748 | # So we work around that by manually exporting to warnings here. | ||||
749 | 2 | 58µs | 2 | 9µs | # spent 6µs (3+3) within Carp::BEGIN@749 which was called:
# once (3µs+3µs) by diagnostics::BEGIN@186 at line 749 # spent 6µs making 1 call to Carp::BEGIN@749
# spent 3µs making 1 call to strict::unimport |
750 | *{"warnings::$_"} = \&$_ foreach @EXPORT; | ||||
751 | } | ||||
752 | |||||
753 | 1 | 8µs | 1; | ||
754 | |||||
755 | __END__ |