pdl2 中的分段错误,其中一些来自我的 .perldlrc 的代码可以直接从 pdl2 shell 正常工作

发布于 2024-11-19 07:27:22 字数 2047 浏览 1 评论 0原文

结合

是否有等效的pdl2(或 Devel::REPL)中的 perl 调试器“x”?

如何列出所有变量在给定范围内?

我已经创建了我的perldlrc,例如

use feature ':5.10';
use Data::Dumper;
use PadWalker qw/peek_our peek_my/;


sub x {
  my $depth = shift||0;

  $Data::Dumper::Maxdepth = $depth;
  print Data::Dumper->Dump([@_])
}


sub lvars {
    my $vars = in_scope_variables();

    print Dumper [keys %$vars];
}

sub in_scope_variables {
    my %in_scope = %{peek_our(1)};
    my $lexical  = peek_my(1);
    for my $name (keys %main::) {
        my $glob = $main::{$name};
        if (defined ${$glob}) {
            $in_scope{'$' . $name} = ${$glob};
        }

        if ( @{$glob}) {
            $in_scope{'@' . $name} = [@{$glob}];
        }

        if (%{$glob}) {
            $in_scope{'%' . $name} = {%{$glob}};
        }
    }

    #lexicals hide package variables
    while (my ($var, $ref) = each %$lexical) {
        $in_scope{$var} = $ref;
    }
    return \%in_scope;
}

然后我启动pdl2但方法不起作用:

$ pdl2
pdl> $xx=in_scope_variables()
Runtime error: You can't FIRSTKEY with the %~ hash at (eval 254) line 38

pdl> lvars
Segmentation fault

如果我评论了循环

# for my $name (keys %main::) {
#     [...]
# }

那么只有lvars失败:

pdl> $xx=in_scope_variables()
pdl> lvars                   
Segmentation fault

但是如果我运行直接在 pdl2 shell 中编写代码它可以工作

pdl> $xx=in_scope_variables()
pdl> x 1, $xx        
$VAR1 = {
          '$_REPL' => 'REF(0x19999708)'
        };
pdl> print Dumper [keys %$xx];  
$VAR1 = [
          '$_REPL'
        ];

有人知道为什么会发生这两个错误吗?

这是 pdl2 问题、Devel::REPL 问题还是我做了一些愚蠢的事情?

我正在使用 perl 5.12 和 Perldl2 Shell v0.005

combining

Is there an equivalent to the perl debugger 'x' in pdl2 (or Devel::REPL)?

and

How can I list all variables that are in a given scope?

I have created my perldlrc like

use feature ':5.10';
use Data::Dumper;
use PadWalker qw/peek_our peek_my/;


sub x {
  my $depth = shift||0;

  $Data::Dumper::Maxdepth = $depth;
  print Data::Dumper->Dump([@_])
}


sub lvars {
    my $vars = in_scope_variables();

    print Dumper [keys %$vars];
}

sub in_scope_variables {
    my %in_scope = %{peek_our(1)};
    my $lexical  = peek_my(1);
    for my $name (keys %main::) {
        my $glob = $main::{$name};
        if (defined ${$glob}) {
            $in_scope{'

Then I start pdl2 but the methods do not work:

$ pdl2
pdl> $xx=in_scope_variables()
Runtime error: You can't FIRSTKEY with the %~ hash at (eval 254) line 38

pdl> lvars
Segmentation fault

If I commented the loop

# for my $name (keys %main::) {
#     [...]
# }

Then only lvars fail:

pdl> $xx=in_scope_variables()
pdl> lvars                   
Segmentation fault

But if I run the code directly in the pdl2 shell it works

pdl> $xx=in_scope_variables()
pdl> x 1, $xx        
$VAR1 = {
          '$_REPL' => 'REF(0x19999708)'
        };
pdl> print Dumper [keys %$xx];  
$VAR1 = [
          '$_REPL'
        ];

Do someone have any idea why this two errors happens?

Is that a pdl2 problem a Devel::REPL problem or me doing something stupid?

I am using perl 5.12 and Perldl2 Shell v0.005

. $name} = ${$glob}; } if ( @{$glob}) { $in_scope{'@' . $name} = [@{$glob}]; } if (%{$glob}) { $in_scope{'%' . $name} = {%{$glob}}; } } #lexicals hide package variables while (my ($var, $ref) = each %$lexical) { $in_scope{$var} = $ref; } return \%in_scope; }

Then I start pdl2 but the methods do not work:

If I commented the loop

Then only lvars fail:

But if I run the code directly in the pdl2 shell it works

Do someone have any idea why this two errors happens?

Is that a pdl2 problem a Devel::REPL problem or me doing something stupid?

I am using perl 5.12 and Perldl2 Shell v0.005

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素年丶 2024-11-26 07:27:22
  • 解决了分段错误:

我已经更新了一年前的 PadWalker 版本,现在使用
PadWalker-1.92 工作正常。

不幸的是,我在更新之前没有写下我的版本,所以我无法报告哪个版本有问题。

  • 捕获 %main:: 变量时仍出现错误:

    运行时错误:您无法在 (eval 254) 第 38 行使用 %~ 哈希值进行 FIRSTKEY

  • SOLVED the segmentation fault:

I have updated my one year old PadWalker version and now with the
PadWalker-1.92 it works ok.

Unfortunately I didn't write down my version before updating, so I can not report with which version I had problems.

  • Still pending the error in the capture of the %main:: variables:

    Runtime error: You can't FIRSTKEY with the %~ hash at (eval 254) line 38

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文