diff options
author | Yves Orton <demerphq@gmail.com> | 2022-09-26 15:00:21 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2022-10-18 15:50:30 +0200 |
commit | 40d662ad46f02fed253b998c4691175dd158c128 (patch) | |
tree | 387b3d846ee8ccee899f851c8021b70550cf19c9 /dump.c | |
parent | fc9696a5e55c64ae01cfd7890d3b832cb309b822 (diff) | |
download | perl-40d662ad46f02fed253b998c4691175dd158c128.tar.gz |
dump.c - add ways to dump HV's and AV's and SV's to any depth.
Currently you can use sv_dump() to dump an AV or HV as these are
still SV's underneath in C terms, but it will only dump out the top
level object and will not dump out its contents, whereas if you have
an RV which references the same AV or HV it will dump it out to depth
of 4.
This adds av_dump() and hv_dump() which dump up to a depth of 3 (thus
matching what sv_dump() would have showed had it been used to dump
an RV to the same object). It also adds sv_dump_depth() which allows
passing in an arbitrary depth. You could argue the former are redundant
in light of sv_dump_depth(), but the av_dump() and hv_dump() variants
do not require a cast for their arguments.
These functions are provided as debugging aids for development. They
aren't used directly in the core, and they all wrap the same core
routine that is used for sv_dump() (do_sv_dump()).
Diffstat (limited to 'dump.c')
-rw-r--r-- | dump.c | 42 |
1 files changed, 39 insertions, 3 deletions
@@ -2661,7 +2661,25 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo Dumps the contents of an SV to the C<STDERR> filehandle. -For an example of its output, see L<Devel::Peek>. +For an example of its output, see L<Devel::Peek>. If +the item is an SvROK it will dump items to a depth of 4, +otherwise it will dump only the top level item, which +means that it will not dump the contents of an AV * or +HV *. For that use C<av_dump()> or C<hv_dump()>. + +=for apidoc av_dump + +Dumps the contents of an AV to the C<STDERR> filehandle, +Similar to using Devel::Peek on an arrayref but does not +expect an RV wrapper. Dumps contents to a depth of 3 levels +deep. + +=for apidoc hv_dump + +Dumps the contents of an HV to the C<STDERR> filehandle. +Similar to using Devel::Peek on an hashref but does not +expect an RV wrapper. Dumps contents to a depth of 3 levels +deep. =cut */ @@ -2670,9 +2688,27 @@ void Perl_sv_dump(pTHX_ SV *sv) { if (sv && SvROK(sv)) - do_sv_dump(0, Perl_debug_log, sv, 0, 4, 0, 0); + sv_dump_depth(sv, 4); else - do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0); + sv_dump_depth(sv, 0); +} + +void +Perl_sv_dump_depth(pTHX_ SV *sv, I32 depth) +{ + do_sv_dump(0, Perl_debug_log, sv, 0, depth, 0, 0); +} + +void +Perl_av_dump(pTHX_ AV *av) +{ + sv_dump_depth((SV*)av, 3); +} + +void +Perl_hv_dump(pTHX_ HV *hv) +{ + sv_dump_depth((SV*)hv, 3); } int |