【问题标题】:How do I restrict Perl debugger output to lines in my own script?如何将 Perl 调试器输出限制为我自己脚本中的行?
【发布时间】:2012-12-07 01:57:01
【问题描述】:

我在非交互模式下运行调试器,并将输出写入文件。我想在执行时打印出我的 Perl 脚本的每一行,但只打印脚本本身中的行。我不想看到脚本调用的库代码(File::Basename、Exporter::import 等)。这似乎是应该很容易做到的事情,但perldebug 的文档只讨论了限制转储结构的深度。我想要的是否可能,如果可能,如何实现?

请注意,我正在执行我的程序如下:

PERLDB_OPTS="LineInfo=temp.txt NonStop=1 AutoTrace=1 frame=2" perl -dS myprog.pl arg0 arg1

【问题讨论】:

    标签: perl


    【解决方案1】:

    默认情况下,Devel::DumpTrace 不会进入系统模块,您可以对调试器将进入的模块进行精细控制(这并不容易,但有可能)。类似的东西

    DUMPTRACE_FH=temp.txt perl -d:DumpTrace=quiet myprog.pl 
    

    会类似于你显然想要做的事情。

    Devel::DumpTrace 在每一行上也做了更多的处理——找出变量值并将它们包含在输出中——所以它可能是多余的并且运行速度比perl -dS ... 慢很多

    (Crikey,本周 Devel::DumpTracetwo plugs!)

    【讨论】:

    • 我必须考虑在我的系统上安装这个模块。它看起来不错。
    【解决方案2】:

    您是说不想单步执行您自己程序之外的函数吗?为此,您想使用n 而不是s

    来自perldebug

       s [expr]    Single step.  Executes until the beginning of another
                   statement, descending into subroutine calls.  If an
                   expression is supplied that includes function calls, it too
                   will be single‐stepped.
    
       n [expr]    Next.  Executes over subroutine calls, until the beginning
                   of the next statement.  If an expression is supplied that
                   includes function calls, those functions will be executed
                   with stops before each statement.
    

    【讨论】:

    • 我以非交互方式运行,将所有输出写入文件。因此,我没有使用 s 或 n。我编辑了我的问题以强调这一点。
    • 啊哈,对不起,我错过了。我从来没有使用过那种非交互模式。
    猜你喜欢
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多