Perl -d 调试perl程序

本文介绍了如何使用Perl的-perldebug选项进行程序调试,详细讲解了如x、T、s、n、r等关键调试命令,帮助开发者在遇到问题时有效地追踪和解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在控制台输入perldoc perldebug即可如何得到如何调试perl程序的文档。


其中重要的命令如下:


p expr      Same as "print {$DB::OUT} expr" in the current package. In
                particular, because this is just Perl's own "print"
                function, this means that nested data structures and objects
                are not dumped, unlike with the "x" command.

           

x [maxdepth] expr
                Evaluates its expression in list context and dumps out the
                result in a pretty-printed fashion.


T           Produce a stack backtrace. See below for details on its
                output.


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.

r           Continue until the return from the current subroutine. Dump
                the return value if the "PrintRet" option is set (default).


<CR>        Repeat last "n" or "s" command.


L [abw]     List (default all) actions, breakpoints and watch
                expressions


l           List next window of lines.

l line      List a single line.

    l subname   List first window of lines from subroutine. *subname* may be
                a variable that contains a code reference.


b           Sets breakpoint on current line

b [line] [condition]
                Set a breakpoint before the given line. If a condition is
                specified, it's evaluated each time the statement is
                reached: a breakpoint is taken only if the condition is
                true. Breakpoints may only be set on lines that begin an
                executable statement. Conditions don't use "if":

                    b 237 $x > 30
                    b 237 ++$count237 < 11
                    b 33 /pattern/i

b subname [condition]
                Set a breakpoint before the first line of the named
                subroutine. *subname* may be a variable containing a code
                reference (in this case *condition* is not supported).

c [line|sub]
                Continue, optionally inserting a one-time-only breakpoint at
                the specified line or subroutine.


q or ^D     Quit. ("quit" doesn't work for this, unless you've made an
                alias) This is the only supported way to exit the debugger,
                though typing "exit" twice might work.

                Set the "inhibit_exit" option to 0 if you want to be able to
                step off the end the script. You may also need to set
                $finished to 0 if you want to step through global
                destruction.

R           Restart the debugger by "exec()"ing a new session. We try to
                maintain your history across this, but internal settings and
                command-line options may be lost.

                The following setting are currently preserved: history,
                breakpoints, actions, debugger options, and the Perl
                command-line options -w, -I, and -e.


w expr      Add a global watch-expression. Whenever a watched global
                changes the debugger will stop and display the old and new
                values.

W expr      Delete watch-expression

W *         Delete all watch-expressions.




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值