简体   繁体   English

调试Perl程序员的工作流程

[英]Workflow to debug for a Perl programmer

I am new to Perl and I have the following problem. 我是Perl新手,我有以下问题。
I have a log output and I have found where this log output comes from. 我有一个日志输出,我已经找到了这个日志输出来自哪里。 I mean the subroutine in some module that prints it. 我的意思是打印它的某个模块中的子程序。

Now eg in Java via Eclipse I would use eg Call hierarchy and other utilities to see how/when/who calls the method and figure out how to reproduce what I need and debug. 现在,例如在Java通过Eclipse我会使用如Call hierarchy和其他公用设施怎么看/时/谁调用该方法,并找出如何重现什么,我需要和调试。

How can I do this in Perl ? 我怎么能在Perl做到这一点? Via eg grep ? 通过例如grep If I grep eg for the module name I get hundrends of lines ranging from use A require A C::B::A B::A C::B::A::some_routine C::B::A::some_other_routine etc. 如果我grep例如为模块名称,我得到的线条的范围从use A require A C::B::A B::A C::B::A::some_routine C::B::A::some_other_routine等等
On top of this I am worried that perhaps the routine I am interested in is not called directly but some script eg runs the module that is of interest to me via some obscure (to me due to my ignorance in Perl ) manner. 最重要的是,我担心也许我感兴趣的例程不是直接调用,而是一些脚本例如运行我感兴趣的模块,通过一些模糊的(由于我在Perl无知)方式。

So how would I go debug something in Perl in the most efficient way? 那么我如何以最有效的方式在Perl中调试一些东西呢? What do you Perl gurus suggest for me to do and become more efficient? Perl大师建议我做什么并提高效率?

Run the program under the Perl debugger: 在Perl调试器下运行程序:

perl -d scriptname arguments...

Set a breakpoint in the function you care about, and when the program stops at the breakpoint use the T debugger command to display a stack trace, which will show where the function was called from. 在您关心的函数中设置断点,当程序在断点处停止时,使用T调试器命令显示堆栈跟踪,该跟踪将显示调用函数的位置。

From your comments, I'm not sure this actually addresses what you're looking for. 根据您的评论,我不确定这实际上是否符合您的要求。 Maybe what you want is a cross-reference of the Perl application? 也许你想要的是Perl应用程序的交叉引用? See the FAQ How do I cross-reference my Perl programs? 请参阅常见问题解答如何交叉引用我的Perl程序?

Most of the time getting a stack trace (along with some debugging info) is a good start. 大多数时候获得堆栈跟踪(以及一些调试信息)是一个良好的开端。 One can use standard Carp module to generate stack traces: 可以使用标准Carp模块生成堆栈跟踪:

use Carp;  
print_to_log(Carp::longmess("We're here"));

Or there's an object-oriented module for that as well. 或者也有一个面向对象的模块

要在不修改任何代码的情况下获取调用堆栈的转储,可以使用perl命令行在Carp :: Always下运行程序:

perl -MCarp::Always my_program.pl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM