打破文件的所有方法是什么:Perl调试器中的行?

时间:2011-07-15 04:05:11

标签: perl debugging

我尝试了几种方法,没有工作:

b file:line
f file
b line
b load <file>

这里有什么问题?

2 个答案:

答案 0 :(得分:2)

我不完全理解你的问题,但perl调试器中'b'的所有选项都可以用'h b'查看:

DB<3> h b
b        Sets breakpoint on current line)
b [line] [condition]
        Set breakpoint; line defaults to the current execution line;
        condition breaks if it evaluates to true, defaults to '1'.
b subname [condition]
        Set breakpoint at first line of subroutine.
b $var        Set breakpoint at first line of subroutine referenced by $var.
b load filename Set breakpoint on 'require'ing the given file.
b postpone subname [condition]
        Set breakpoint at first line of subroutine after 
        it is compiled.
b compile subname
        Stop after the subroutine is compiled.

似乎没有“所有案例的一种用法”模式。根据我的经验,你可以:

  • 逐步调试一些语句,直到你感兴趣的模块被加载
  • '使用'要在
  • 中设置断点的模块

加载您感兴趣的模块后,您可以使用'b [subname]'模式。不要忘记您可能需要使用包名称完全限定子名称:

  DB<5> use JSON;

  DB<6> b JSON::import
  DB<7> JSON->import
JSON::import(/opt/xt/xt-perl/lib/site_perl/5.12.4/JSON.pm:78):
78:     my $pkg = shift;
auto(-1)  DB<<8>> v
75  
76  
77  sub import {
78==>b      my $pkg = shift;
79:     my @what_to_export;
80:     my $no_export;
81  
82:     for my $tag (@_) {
83:         if ($tag eq '-support_by_pp') {
84:             if (!$_ALLOW_UNSUPPORTED++) {

你也可以

  • 添加“$ DB :: single = 1;”在您的源代码中(不要忘记在完成后删除它!)

并且只是'c'继续通过调试器,直到你在代码中加热该行。必须在源代码中添加和删除特殊标记违反了调试的一般原则,但有时可以在某个困难或缓慢的地方轻松停止,以便通过调试器步进。

答案 1 :(得分:1)

我想,你已经在调试器中启动了一个perl脚本,它使用了一些包含一些软件包的模块。

  1. 您可以使用调试器命令S列出可用的子例程。可选的正则表达式模式可用于过滤列表: S [[!]pat] List subroutine names [not] matching pattern

  2. 要为某个包中的函数设置断点,可以使用此形式的断点命令b package::function。我猜想它可以更好地记录下来。

  3. 前段时间我遇到了同样的问题,我现在就这样使用它了。

    更新:我刚检查了序列

    f file
    b line
    

    当模块加载 use packagerequire package之前,这适用于我。 file的路径是相对于当前目录指定的。

相关问题