DumpArenas.xs

filter: Statementstmt 89.1% 66 / 74 Branchbran 76.0% 35 / 46 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 84.1% 101 / 120 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary blib/lib/Internals/DumpArenas.pm »
1 /* This code uses several internal APIs. I'm declaring PERL_CORE
2 * purely so this is visible to anyone grepping CPAN for code that
3 * does this sort of thing.
4 *
5 * Copied and pasted structure of S_visit from sv.c
6 * Used PL_sv_arenaroot
7 * Used do_sv_dump (instead of sv_dump)
8 * Used pv_display
9 */
10 #define PERL_CORE
11  
12 #include "EXTERN.h"
13 #include "perl.h"
14 #include "XSUB.h"
15 #include "ppport.h"
16  
17 /* need workaround broken dump of !SvOBJECT with SvSTASH in dump.c */
18 /* fixed in cperl5.22.2 and perl5.23.8 */
19 #if PERL_VERSION >= 18 && (!defined(USE_CPERL) && PERL_VERSION < 24)
20 #define NEED_SAFE_SVSTASH
21 #endif
22  
23 94799 void DumpPointer( pTHX_ PerlIO *f, SV *sv ) {
24 dVAR;
25 94799 ▶ if ( &PL_sv_undef == sv ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( &PL_sv_undef == sv ) { 574 94225 94799
26 574 PerlIO_puts(f, "sv_undef");
27 }
28 94225 ▶ else if (&PL_sv_yes == sv) {
Branch: 1 branch
BranchTrueFalseTotal
else if (&PL_sv_yes == sv) { 297 93928 94225
29 297 PerlIO_puts(f, "sv_yes");
30 }
31 93928 ▶ else if (&PL_sv_no == sv) {
Branch: 1 branch
BranchTrueFalseTotal
else if (&PL_sv_no == sv) { 29 93899 93928
32 29 PerlIO_puts(f, "sv_no");
33 }
34 #if PERL_VERSION > 6
35 93899 ▶ else if (&PL_sv_placeholder == sv) { /* deleted hash entry */
Branch: 1 branch
BranchTrueFalseTotal
else if (&PL_sv_placeholder == sv) { /* deleted hash entry */ 0 93899 93899
36 0 PerlIO_printf(f, "sv_placeholder");
37 }
38 #endif
39 else {
40 93899 PerlIO_printf(f, "0x%" UVxf, PTR2UV(sv));
41 }
42 94799 }
43  
44 void
45 7956 DumpAvARRAY( pTHX_ PerlIO *f, SV *sv) {
46 7956 I32 key = 0;
47  
48 7956 PerlIO_printf(f,"AvARRAY(0x%" UVxf ") = {",PTR2UV(AvARRAY(sv)));
49 7956 ▶ if (!AvARRAY(sv)) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!AvARRAY(sv)) return; 3210 4746 7956
50 4746 ▶ if ( AvMAX(sv) != AvFILL(sv) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( AvMAX(sv) != AvFILL(sv) ) { 3559 1187 4746
51 3559 PerlIO_puts(f,"{");
52 }
53
54 72730 ▶ for ( key = 0; key <= AvMAX(sv); ++key ) {
Branch: 1 branch
BranchTrueFalseTotal
for ( key = 0; key <= AvMAX(sv); ++key ) { 67984 4746 72730
55 67984 DumpPointer(aTHX_ f, AvARRAY(sv)[key]);
56
57 /* Join with something */
58 67984 ▶ if ( AvMAX(sv) == AvFILL(sv) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( AvMAX(sv) == AvFILL(sv) ) { 11726 56258 67984
59 11726 ▶ if (key != AvMAX(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (key != AvMAX(sv)) { 10540 1186 11726
60 10540 PerlIO_puts(f, ",");
61 }
62 }
63 else {
64 56258 PerlIO_puts(
65 f,
66 56258 ▶ AvFILL(sv) == key ? "}{" :
Branch: 1 branch
BranchTrueFalseTotal
AvFILL(sv) == key ? "}{" : 53077 3181 56258
67 53077 ▶ AvMAX(sv) == key ? "}" :
Branch: 1 branch
BranchTrueFalseTotal
AvMAX(sv) == key ? "}" : 3559 49518 53077
68 ","
69 );
70 }
71 }
72 4746 PerlIO_puts(f,"}\n\n");
73 }
74  
75 void
76 1717 DumpHvARRAY( pTHX_ PerlIO *f, SV *sv) {
77 1717 U32 key = 0;
78 HE *entry;
79 1717 SV *tmp = newSVpv("",0);
80  
81 1717 PerlIO_printf(f,"HvARRAY(0x%" UVxf ")\n",PTR2UV(HvARRAY(sv)));
82 1717 ▶ if (!HvARRAY(sv)) goto hvend;
Branch: 1 branch
BranchTrueFalseTotal
if (!HvARRAY(sv)) goto hvend; 262 1455 1717
83  
84 80977 ▶ for ( key = 0; key <= HvMAX(sv); ++key ) {
Branch: 1 branch
BranchTrueFalseTotal
for ( key = 0; key <= HvMAX(sv); ++key ) { 79522 1455 80977
85 106337 ▶ for ( entry = HvARRAY(sv)[key]; entry; entry = HeNEXT(entry) ) {
Branch: 1 branch
BranchTrueFalseTotal
for ( entry = HvARRAY(sv)[key]; entry; entry = HeNEXT(entry) ) { 26815 79522 106337
86 26815 ▶ if ( HEf_SVKEY == HeKLEN(entry) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( HEf_SVKEY == HeKLEN(entry) ) { 0 26815 26815
87 0 PerlIO_printf(
88 f, " [SV 0x%" UVxf "] => ",
89 0 PTR2UV(HeKEY(entry)));
90 0 DumpPointer(aTHX_ f, (SV*)(HeKEY(entry)));
91 }
92 else {
93 53630 PerlIO_printf(
94 f, " [0x%" UVxf " %s] => ",
95 26815 PTR2UV(HeKEY(entry)),
96 26815 pv_display(
97 tmp,
98 HeKEY(entry), HeKLEN(entry), HeKLEN(entry),
99 0 ));
100 }
101 26815 DumpPointer(aTHX_ f, HeVAL(entry));
102 26815 PerlIO_puts(f, "\n");
103 }
104 }
105 1455 hvend:
106 1717 PerlIO_puts(f,"\n");
107  
108 1717 SvREFCNT_dec(tmp);
109 1717 }
110 #if 0
111 void
112 DumpHashKeys( pTHX_ PerlIO *f, SV *sv) {
113 U32 key = 0;
114 HE *entry;
115 SV *tmp = newSVpv("",0);
116  
117 PerlIO_printf(f,"SHARED HASH KEYS at 0x%" UVxf "\n", PTR2UV(sv));
118 if (!HvARRAY(sv)) goto hkend;
119
120 for ( key = 0; key <= HvMAX(sv); ++key ) {
121 for ( entry = HvARRAY(sv)[key]; entry; entry = HeNEXT(entry) ) {
122 if ( HEf_SVKEY == HeKLEN(entry) ) {
123 PerlIO_printf(f, " SV 0x%" UVxf "\n", PTR2UV(HeKEY(entry)) );
124 DumpPointer(aTHX_ f, (SV*)(HeKEY(entry)));
125 }
126 else {
127 PerlIO_printf(f, " 0x%" UVxf " %s\n", PTR2UV(HeKEY(entry)),
128 pv_display( (SV*)tmp, (const char*)HeKEY(entry),
129 HeKLEN(entry), HeKLEN(entry), 0 ) );
130 }
131 }
132 }
133 hkend:
134 PerlIO_puts(f,"\n\n");
135 SvREFCNT_dec(tmp);
136 }
137 #endif
138  
139 void
140 1 DumpArenasPerlIO( pTHX_ PerlIO *f) {
141 SV *arena;
142  
143 491 ▶ for (arena = PL_sv_arenaroot; arena; arena = (SV*)SvANY(arena)) {
Branch: 1 branch
BranchTrueFalseTotal
for (arena = PL_sv_arenaroot; arena; arena = (SV*)SvANY(arena)) { 490 1 491
144 490 const SV *const arena_end = &arena[SvREFCNT(arena)];
145 SV *sv;
146  
147 /* See also the static function S_visit in perl's sv.c
148 * This is a copied and pasted implementation of that function.
149 */
150 490 PerlIO_printf(f,"START ARENA = (0x%" UVxf "-0x%" UVxf ")\n\n",PTR2UV(arena),PTR2UV(arena_end));
151 83300 ▶ for (sv = arena + 1; sv < arena_end; ++sv) {
Branch: 1 branch
BranchTrueFalseTotal
for (sv = arena + 1; sv < arena_end; ++sv) { 82810 490 83300
152 /* not freed */
153 82810 ▶ if ((SvFLAGS(sv) != SVTYPEMASK) && SvREFCNT(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((SvFLAGS(sv) != SVTYPEMASK) && SvREFCNT(sv)) { 82715 95 82810
if ((SvFLAGS(sv) != SVTYPEMASK) && SvREFCNT(sv)) { 82715 0 82715
154  
155 /* workaround broken dump of !SvOBJECT with SvSTASH in dump.c */
156 /* only fixed in cperl so far */
157 #ifdef NEED_SAFE_SVSTASH
158 HV* savestash = NULL;
159 if (!SvOBJECT(sv) && SvTYPE(sv) >= SVt_PVMG && SvSTASH(sv)) {
160 savestash = SvSTASH(sv);
161 SvSTASH(sv) = NULL;
162 }
163 #endif
164 #if defined(USE_ITHREADS) && defined(DEBUGGING) && defined(SVpbm_VALID)
165 /* workaround broken SvTAIL() in dump.c */
166 if (SvTYPE(sv) != SVt_PVMG ||
167 (!(SvFLAGS(sv) & SVpbm_VALID) &&
168 (SvFLAGS(sv) & SVpbm_TAIL)))
169 #endif
170 #if PERL_VERSION < 8 && defined(DEBUGGING) && defined(SVpbm_VALID)
171 /* workaround broken CvANON() in 5.6 dump.c */
172 if (SvTYPE(sv) != SVt_PVCV || !(SvFLAGS(sv) & 0x500))
173 #endif
174 /* Dump the plain SV */
175 82715 do_sv_dump(0,f,sv,0,0,0,0);
176  
177 #ifdef NEED_SAFE_SVSTASH
178 if (savestash)
179 SvSTASH(sv) = savestash;
180 #endif
181 82715 PerlIO_puts(f,"\n");
182
183 /* Dump AvARRAY(0x...) = {{0x...,0x...}{0x...}} */
184 82715 switch (SvTYPE(sv)) {
185 7956 case SVt_PVAV:
186 /*if ( AvARRAY(sv) && AvMAX(sv) != -1 ) {*/
187 7956 DumpAvARRAY( aTHX_ f,sv);
188 7956 break;
189 1717 case SVt_PVHV:
190 /*if ( HvARRAY(sv) && HvMAX(sv) != (STRLEN)-1 ) {*/
191 1717 DumpHvARRAY( aTHX_ f,sv);
192 #if 0
193 if ( HvSHAREKEYS(sv) ) {
194 DumpHashKeys( aTHX_ f,sv);
195 }
196 #endif
197 74759 default:
198 74759 break;
199 }
200 }
201 else {
202 95 PerlIO_printf(f,"AVAILABLE(0x%" UVxf ")\n\n",PTR2UV(sv));
203 }
204 }
205 490 PerlIO_printf(f,"END ARENA = (0x%" UVxf "-0x%" UVxf ")\n\n",PTR2UV(arena),PTR2UV(arena_end));
206 }
207 1 }
208  
209 void
210 0 DumpArenas( pTHX ) {
211 0 ▶ DumpArenasPerlIO( aTHX_ Perl_error_log );
Branch: 4 branches
BranchTrueFalseTotal
DumpArenasPerlIO( aTHX_ Perl_error_log ); 0 0 0
DumpArenasPerlIO( aTHX_ Perl_error_log ); 0 0 0
DumpArenasPerlIO( aTHX_ Perl_error_log ); 0 0 0
DumpArenasPerlIO( aTHX_ Perl_error_log ); 0 0 0
212 0 }
213  
214 void
215 1 DumpArenasFd( pTHX_ int fd ) {
216 1 PerlIO *f = (PerlIO*)PerlIO_fdopen( fd, "w" );
217 1 DumpArenasPerlIO( aTHX_ f );
218 1 }
219  
220 MODULE = Internals::DumpArenas PACKAGE = Internals::DumpArenas
221
222 PROTOTYPES: DISABLE
223  
224 void
225 DumpArenas()
226 CODE:
227 0 DumpArenas( aTHX );
228  
229 void
230 DumpArenasFd( int fd )
231 CODE:
232 1 DumpArenasFd( aTHX_ fd );
↑ Summary blib/lib/Internals/DumpArenas.pm »