Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel::Peek: Indentation gap when dumping MG object #16380

Open
p5pRT opened this issue Jan 25, 2018 · 14 comments
Open

Devel::Peek: Indentation gap when dumping MG object #16380

p5pRT opened this issue Jan 25, 2018 · 14 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 25, 2018

Migrated from rt.perl.org#132764 (status was 'open')

Searchable as RT132764$

@p5pRT
Copy link
Author

p5pRT commented Jan 25, 2018

From @KES777

Created by @KES777

Depending on the PL_dumpindent the MG_OBJ details are dumped with indentation gap​:

Look at output​:

PL_dumpindent = 1;
SV = PVMG(0x1d74a70) at 0x1bba790
  REFCNT = 1
  FLAGS = (GMG,SMG,RMG)
  IV = 0
  NV = 0
  PV = 0
  MAGIC = 0x1bb3bd0
  MG_VIRTUAL = &PL_vtbl_packelem
  MG_TYPE = PERL_MAGIC_tiedscalar(q)
  MG_FLAGS = 0x02
  REFCOUNTED
  MG_OBJ = 0x1baffe8
  SV = IV(0x1baffd8) at 0x1baffe8
^^
  REFCNT = 1
  FLAGS = (ROK)
  RV = 0x1c778b8
  SV = PVHV(0x1ba1c60) at 0x1c778b8
  ^^
...

PL_dumpindent = 2;
SV = PVMG(0x21aa9d0) at 0x1ff0790
  REFCNT = 1
  FLAGS = (GMG,SMG,RMG)
  IV = 0
  NV = 0
  PV = 0
  MAGIC = 0x1fe9b90
  MG_VIRTUAL = &PL_vtbl_packelem
  MG_TYPE = PERL_MAGIC_tiedscalar(q)
  MG_FLAGS = 0x02
  REFCOUNTED
  MG_OBJ = 0x1fe5fe8
  SV = IV(0x1fe5fd8) at 0x1fe5fe8
  ^^
  REFCNT = 1
  FLAGS = (ROK)
  RV = 0x21a90e8
  SV = PVHV(0x1fd7c60) at 0x21a90e8
  ^^
...

PL_dumpindent = 3;
SV = PVMG(0x15999c0) at 0x13df790
  REFCNT = 1
  FLAGS = (GMG,SMG,RMG)
  IV = 0
  NV = 0
  PV = 0
  MAGIC = 0x13d8b90
  MG_VIRTUAL = &PL_vtbl_packelem
  MG_TYPE = PERL_MAGIC_tiedscalar(q)
  MG_FLAGS = 0x02
  REFCOUNTED
  MG_OBJ = 0x13d4fe8
  SV = IV(0x13d4fd8) at 0x13d4fe8
  ^^
  REFCNT = 1
  FLAGS = (ROK)
  RV = 0x16c8098
  SV = PVHV(0x13c6c60) at 0x16c8098
  ^^

So this is unclear where SV belons to
Is it belongs to MAGIC or MG_OBJ?

There is no any documentation about PL_dumpindent

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.24.0:

Configured by kes at Wed Oct 19 14:07:47 EEST 2016.

Summary of my perl5 (revision 5 version 24 subversion 0) configuration:
   
  Platform:
    osname=linux, osvers=4.4.0-43-generic, archname=x86_64-linux
    uname='linux work 4.4.0-43-generic #63-ubuntu smp wed oct 12 13:48:03 utc 2016 x86_64 x86_64 x86_64 gnulinux '
    config_args='-de -Dprefix=/home/kes/perl5/perlbrew/perls/perl-5.24.0 -Aeval:scriptdir=/home/kes/perl5/perlbrew/perls/perl-5.24.0/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion='', gccversion='5.4.0 20160609', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.23.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.23'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'

Locally applied patches:
    Devel::PatchPerl 1.38


@INC for perl 5.24.0:
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0/x86_64-linux
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0
    .


Environment for perl 5.24.0:
    HOME=/home/kes
    LANG=en_US.UTF-8
    LANGUAGE=en
    LC_ADDRESS=uk_UA.UTF-8
    LC_IDENTIFICATION=uk_UA.UTF-8
    LC_MEASUREMENT=uk_UA.UTF-8
    LC_MESSAGES=en_US.UTF-8
    LC_MONETARY=uk_UA.UTF-8
    LC_NAME=uk_UA.UTF-8
    LC_NUMERIC=uk_UA.UTF-8
    LC_PAPER=uk_UA.UTF-8
    LC_TELEPHONE=uk_UA.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.0/bin:/home/kes/bin:/home/kes/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    PERLBREW=command perlbrew
    PERLBREW_BASHRC_VERSION=0.78
    PERLBREW_HOME=/home/kes/.perlbrew
    PERLBREW_MANPATH=/home/kes/perl5/perlbrew/perls/perl-5.24.0/man
    PERLBREW_PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.0/bin
    PERLBREW_PERL=perl-5.24.0
    PERLBREW_ROOT=/home/kes/perl5/perlbrew
    PERLBREW_VERSION=0.78
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jan 26, 2018

From @KES777

Another example of ambiguity​:
SV = IV(0x2598d20) at 0x2598d30
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x25a3840
  SV = PVCV(0x2597c28) at 0x25a3840
  REFCNT = 3
  FLAGS = ()
  COMP_STASH = 0x2583ff8 "main"
  START = 0x25aae40 ===> 1
  ROOT = 0x27842f0
  GVGV​::GV = 0x25a3660 "main" :​: "t"
  FILE = "/home/kes/tmp/t3.pl"
  DEPTH = 1
  FLAGS = 0x0
  OUTSIDE_SEQ = 2000
  PADLIST = 0x2774220
  PADNAME = 0x27d2970(0x27e0410) PAD = 0x25a36c0(0x26ba700)
  3. 0x2743170<1> (2001,2002) "$x"
  OUTSIDE = 0x25843d0 (MAIN)

Here we can think that PADNAME is member of PVCV. But from the next out we can understand that PADNAME is child for PADLIST​:
SV = PVCV(0x2597c28) at 0x25a3840
  REFCNT = 2
  FLAGS = ()
  COMP_STASH = 0x2583ff8 "main"
  START = 0x25aae40 ===> 1
  ROOT = 0x27842f0
  GVGV​::GV = 0x25a3660 "main" :​: "t"
  FILE = "/home/kes/tmp/t3.pl"
  DEPTH = 1
  FLAGS = 0x0
  OUTSIDE_SEQ = 2000
  PADLIST = 0x2774220
  PADNAME = 0x27d2970(0x27e0410) PAD = 0x25a36c0(0x26ba700)
  3. 0x2743170<1> (2001,2002) "$x"
  OUTSIDE = 0x25843d0 (MAIN)

@p5pRT
Copy link
Author

p5pRT commented Feb 12, 2018

From @KES777

Also there are different defaults for PL_dumpindent when dumping from perl script and from XS

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @jkeenan

On Thu, 25 Jan 2018 11​:16​:40 GMT, kes-kes@​yandex.ru wrote​:

Message-Id​: <5.24.0_11686_1516878441@​work>
To​: perlbug@​perl.org
Reply-To​: kes-kes@​yandex.ru
Cc​: kes-kes@​yandex.ru
From​: kes-kes@​yandex.ru
Subject​: Devel​::Peek​: Indentation gap when dumping MG object

This is a bug report for perl from kes-kes@​yandex.ru,
generated with the help of perlbug 1.40 running under perl 5.24.0.

-----------------------------------------------------------------
[Please describe your issue here]

Depending on the PL_dumpindent the MG_OBJ details are dumped with
indentation gap​:

Look at output​:

PL_dumpindent = 1;
SV = PVMG(0x1d74a70) at 0x1bba790
REFCNT = 1
FLAGS = (GMG,SMG,RMG)
IV = 0
NV = 0
PV = 0
MAGIC = 0x1bb3bd0
MG_VIRTUAL = &PL_vtbl_packelem
MG_TYPE = PERL_MAGIC_tiedscalar(q)
MG_FLAGS = 0x02
REFCOUNTED
MG_OBJ = 0x1baffe8
SV = IV(0x1baffd8) at 0x1baffe8
^^
REFCNT = 1
FLAGS = (ROK)
RV = 0x1c778b8
SV = PVHV(0x1ba1c60) at 0x1c778b8
^^
...

PL_dumpindent = 2;
SV = PVMG(0x21aa9d0) at 0x1ff0790
REFCNT = 1
FLAGS = (GMG,SMG,RMG)
IV = 0
NV = 0
PV = 0
MAGIC = 0x1fe9b90
MG_VIRTUAL = &PL_vtbl_packelem
MG_TYPE = PERL_MAGIC_tiedscalar(q)
MG_FLAGS = 0x02
REFCOUNTED
MG_OBJ = 0x1fe5fe8
SV = IV(0x1fe5fd8) at 0x1fe5fe8
^^
REFCNT = 1
FLAGS = (ROK)
RV = 0x21a90e8
SV = PVHV(0x1fd7c60) at 0x21a90e8
^^
...

PL_dumpindent = 3;
SV = PVMG(0x15999c0) at 0x13df790
REFCNT = 1
FLAGS = (GMG,SMG,RMG)
IV = 0
NV = 0
PV = 0
MAGIC = 0x13d8b90
MG_VIRTUAL = &PL_vtbl_packelem
MG_TYPE = PERL_MAGIC_tiedscalar(q)
MG_FLAGS = 0x02
REFCOUNTED
MG_OBJ = 0x13d4fe8
SV = IV(0x13d4fd8) at 0x13d4fe8
^^
REFCNT = 1
FLAGS = (ROK)
RV = 0x16c8098
SV = PVHV(0x13c6c60) at 0x16c8098
^^

Would you be able to provide a short program which a programmer not fluent in XS could run in order to become familiar with this problem. (It's not clear what you did to generate the sample above.)

So this is unclear where SV belons to
Is it belongs to MAGIC or MG_OBJ?

There is no any documentation about PL_dumpindent

Confirmed -- but if it's an implementation detail internal to Peek.xs we probably don't want to formally document it. The POD in Peek.pm takes a very cautious approach​: 'This document will take a passive, and safe, approach to data debugging and for that it will describe only the "Dump()" function.'

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @KES777

The Devel​::Peek makes use of undocumented perlapi function​: do_sv_dump

https://metacpan.org/source/XSAWYERX/perl-5.28.0/ext/Devel-Peek/Peek.xs#L337
https://perldoc.perl.org/perlapi.html#do_sv_dump

The issue is about formatting​:

  PADLIST = 0x2774220
  PADNAME = 0x27d2970(0x27e0410) PAD = 0x25a36c0(0x26ba700)

VS

  PADLIST = 0x2774220
  PADNAME = 0x27d2970(0x27e0410) PAD = 0x25a36c0(0x26ba700)

From the output I can not say that PADNAME is member of PADLIST

See an example​: https://metacpan.org/pod/Devel::Peek#A-reference-to-a-subroutine

This undocumented function has configuration for the indentation.
And this **configuration is applied only to curtain lines** of output. Which lead to confusion.

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @jkeenan

On Tue, 04 Sep 2018 08​:09​:34 GMT, kes-kes@​yandex.ru wrote​:

The Devel​::Peek makes use of undocumented perlapi function​: do_sv_dump

https://metacpan.org/source/XSAWYERX/perl-5.28.0/ext/Devel-
Peek/Peek.xs#L337
https://perldoc.perl.org/perlapi.html#do_sv_dump

The issue is about formatting​:

PADLIST = 0x2774220
PADNAME = 0x27d2970(0x27e0410) PAD = 0x25a36c0(0x26ba700)

VS

PADLIST = 0x2774220
PADNAME = 0x27d2970(0x27e0410) PAD = 0x25a36c0(0x26ba700)

From the output I can not say that PADNAME is member of PADLIST

See an example​: https://metacpan.org/pod/Devel::Peek#A-reference-to-a-
subroutine

This undocumented function has configuration for the indentation.
And this **configuration is applied only to curtain lines** of output.
Which lead to confusion.

Please find attached a small program, '132764-devel-peek.pl', which Dump-s a reference to a subroutine using a sub name drawn from the Devel​::Peek documentation. When I run it (perl-5.28.0), I get the output attached as '132764.top_targets.output.txt'.

How would I re-write sub MY​::top_targets to make it complicated enough to display the ambiguous indentation you just described?

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @jkeenan

132764-devel-peek.pl

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @jkeenan

SV = IV(0x25e0568) at 0x25e0578
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x2606fb0
  SV = PVCV(0x25fd4b8) at 0x2606fb0
  REFCNT = 2
  FLAGS = ()
  COMP_STASH = 0x25e03f8 "main"
  START = 0x2615070 ===> 1
  ROOT = 0x2626918
  GVGV​::GV = 0x2606fe0 "MY" :​: "top_targets"
  FILE = "132764-devel-peek.pl"
  DEPTH = 0
  FLAGS = 0x0
  OUTSIDE_SEQ = 389
  PADLIST = 0x26110b0
  PADNAME = 0x2615b50(0x26835c0) PAD = 0x2606ed8(0x26334f0)
  OUTSIDE = 0x25e0728 (MAIN)

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @KES777

How would I re-write sub MY​::top_targets to make it complicated enough
to display the ambiguous indentation you just described?

Actually your dump is already ambigious​:

  PADNAME is a member of PADLIST, not the `SV = PVCV(0x25fd4b8) at 0x2606fb0`

Play with this value​:

PL_dumpindent = 3;

I change your script and attach the XS

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @KES777

132764-devel-peek.pl

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @KES777

dump.xs

@p5pRT
Copy link
Author

p5pRT commented Sep 6, 2018

From @tonycoz

On Tue, 04 Sep 2018 08​:01​:39 -0700, jkeenan wrote​:

How would I re-write sub MY​::top_targets to make it complicated enough
to display the ambiguous indentation you just described?

The attached patch against blead might make this easier to demonstrate.

$ ./perl -Ilib -MDevel​::Peek -e '$Devel​::Peek​::dumpindent = 2; Dump(\$!)'
SV = IV(0x55ffb73264f8) at 0x55ffb7326508
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x55ffb7348a88
  SV = PVMG(0x55ffb73783c0) at 0x55ffb7348a88
  REFCNT = 2
  FLAGS = (GMG,SMG)
  IV = 0
  NV = 0
  PV = 0
  MAGIC = 0x55ffb734c820
  MG_VIRTUAL = &PL_vtbl_sv
  MG_TYPE = PERL_MAGIC_sv(\0)
  MG_OBJ = 0x55ffb7326610
  MG_LEN = 1
  MG_PTR = 0x55ffb73685c0 "!"
$ ./perl -Ilib -MDevel​::Peek -e '$Devel​::Peek​::dumpindent = 1; Dump(\$!)'
SV = IV(0x55d9bf3cb4f8) at 0x55d9bf3cb508
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x55d9bf3eda88
SV = PVMG(0x55d9bf41d3d0) at 0x55d9bf3eda88
  REFCNT = 2
  FLAGS = (GMG,SMG)
  IV = 0
  NV = 0
  PV = 0
  MAGIC = 0x55d9bf3f5220
  MG_VIRTUAL = &PL_vtbl_sv
  MG_TYPE = PERL_MAGIC_sv(\0)
  MG_OBJ = 0x55d9bf3cb610
  MG_LEN = 1
  MG_PTR = 0x55d9bf423bf0 "!"

Tony

@p5pRT
Copy link
Author

p5pRT commented Sep 6, 2018

From @tonycoz

0001-perl-132764-provide-control-over-Dump-s-indent-level.patch
From f4e7b27e04a51b46154f733b7e06c8c7f9d1bfe6 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Thu, 6 Sep 2018 10:32:52 +1000
Subject: (perl #132764) provide control over Dump()s indent level

Mostly intended for easily demonstrating the issue in #132764.

Needs tests/docs before it's merged to blead.
---
 ext/Devel-Peek/Peek.pm | 2 ++
 ext/Devel-Peek/Peek.xs | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/ext/Devel-Peek/Peek.pm b/ext/Devel-Peek/Peek.pm
index 3d790e763a..0c9499b44e 100644
--- a/ext/Devel-Peek/Peek.pm
+++ b/ext/Devel-Peek/Peek.pm
@@ -18,6 +18,8 @@ require XSLoader;
 
 XSLoader::load();
 
+our $dump_indent = 2;
+
 sub import {
   my $c = shift;
   my $ops_rx = qr/^:opd(=[stP]*)?\b/;
diff --git a/ext/Devel-Peek/Peek.xs b/ext/Devel-Peek/Peek.xs
index 8a8c0b96d7..9550ca4a8e 100644
--- a/ext/Devel-Peek/Peek.xs
+++ b/ext/Devel-Peek/Peek.xs
@@ -333,7 +333,8 @@ S_do_dump(pTHX_ SV *const sv, I32 lim)
     const STRLEN pv_lim = pv_lim_sv ? SvIV(pv_lim_sv) : 0;
     SV *dumpop = perl_get_sv("Devel::Peek::dump_ops", 0);
     const U16 save_dumpindent = PL_dumpindent;
-    PL_dumpindent = 2;
+    SV *dumpindent_sv = perl_get_sv("Devel::Peek::dumpindent", 0);
+    PL_dumpindent = dumpindent_sv ? SvIV(dumpindent_sv) : 2;
     do_sv_dump(0, Perl_debug_log, sv, 0, lim,
 	       (bool)(dumpop && SvTRUE(dumpop)), pv_lim);
     PL_dumpindent = save_dumpindent;
@@ -458,7 +459,8 @@ PPCODE:
     const STRLEN pv_lim = pv_lim_sv ? SvIV(pv_lim_sv) : 0;
     SV *dumpop = perl_get_sv("Devel::Peek::dump_ops", 0);
     const U16 save_dumpindent = PL_dumpindent;
-    PL_dumpindent = 2;
+    SV *dumpindent_sv = perl_get_sv("Devel::Peek::dumpindent", 0);
+    PL_dumpindent = dumpindent_sv ? SvIV(dumpindent_sv) : 2;
 
     for (i=1; i<items; i++) {
 	PerlIO_printf(Perl_debug_log, "Elt No. %ld  0x%" UVxf "\n", i - 1, PTR2UV(ST(i)));
-- 
2.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants