zoukankan      html  css  js  c++  java
  • perl debug

    1. 进入debug模式
    # perl -d ./perl_debugger.pl
    it prompts,
    DB<1>
     
    2. 查看从第10行开始的代码。 查看函数get_pattern的代码
    DB<1> l 10
    10: my $pattern;
    DB<2> l get_pattern
    11 {
    12:    my $pattern;
    13:    print “Enter search string: “;
    14:    chomp ($pattern = );
    15:    return $pattern;
    16 }
     
    3. 在函数find_files上设置断点
    DB<3> b find_files
     
    4. 在指定的44行设置断点
    DB<4> b 44
     
    5. 查看所有的断点
    DB<5> L
    ./perl_debugger.pl:
    22:    my $pattern = shift;
    break if (1)
    44:    print join “ ”,@list;
    break if (1)
     
    6. 单步调试,s 进入调用函数,n直接下一语句不进入调用函数
    DB<5> s
    main::(./perl_debugger.pl:39):    $pattern = get_pattern();
    DB<5> s
    main::get_pattern(./perl_debugger.pl:12):
    12:    my $pattern;
    Option s and n does step by step execution of each statements. Option s steps into the subroutine. Option n executes the subroutine in a single step (stepping over it).
    The s option does stepping into the subroutine but while n option which would execute the subroutine(stepping over it).
     
    7. 继续直到下一个断点
    DB<5> c
    Enter search string: perl
    main::find_files(./perl_debugger.pl:22):
    22:    my $pattern = shift;
     
    8. 继续直到指定的行
    DB<5> c 36
    main::find_files(./perl_debugger.pl:36):
    36:    return @list;
     
    9. 打印变量的值
    DB<6> p $pattern
    perl
    DB<7> c
    main::(./perl_debugger.pl:44):    print join “ ”,@list;
    DB<7> c
    ./perl_debugger.pl
    Debugged program terminated. Use q to quit or R to restart,
    use o inhibit_exit to avoid stopping after program termination,
    h q, h R or h o to get additional info.
    After the last continue operation, the output gets printed on the stdout as “./perl_debugger.pl” since it matches the pattern “perl”.
     
    10. 从文件获得debug的命令和断点信息
    Perl debugger can get the debug command from the file and execute it. For example, create the file called “debug_cmds” with the perl debug commands as,
    c
    p $pattern
    q
    Note that R is used to restart the operation(no need quit and start debugger again).
    DB<7> R
    DB<7> source debug_cmds
    >> c
    Enter search string: perl
    ./perl_debugger.pl
    Debugged program terminated. Use q to quit or R to restart,
    use o inhibit_exit to avoid stopping after program termination,
    h q, h R or h o to get additional info.
    >> p $pattern
    perl
    >> q
     
    perl debug命令的总结
    Following options can be used once you enter the perl debugger.
    h or h h – for help page
    c – to continue down from current execution till the breakpoint otherwise till the subroutine name or line number,
    p – to show the values of variables,
    b – to place the breakpoints,
    L – to see the breakpoints set,
    d – to delete the breakpoints,
    s – to step into the next line execution.
    n – to step over the next line execution, so if next line is subroutine call, it would execute subroutine but not descend into it for inspection.
    source file – to take the debug commands from the file.
    l subname – to see the execution statements available in a subroutine.
    q – to quit from the debugger mode.
     
    perl debug的高级用法
    对调用的module中的函数设置断点:
    b foo::bar::test::subname
     
    可以设置永久的断点,在需要设置断点的行,加入:
    $DB::single =1;
     
    设置断点到调用的文件中的函数或行:
    b  line_number file_path_name
    b  function_name file_path_name
    b file_path_name:function_name
     
    f file_path_name
    b line_number or function_name
     
    监视变量的变化,当值被修改的时候,程序停下:
    w $varialename
  • 相关阅读:
    线程基础知识归纳
    并发编程情况下几个相应问题简介
    Spring Security的RBAC数据模型嵌入
    Mysql插入中文的字段内容时乱码的解决方法
    部分排序算法总结
    sendEmail 阿里云使用587端口
    linux服务器关闭ipv6 方法
    centos 6.8 安装git 报错
    强大的xargs
    nfs环境搭建报错clnt_create: RPC: Program not registered
  • 原文地址:https://www.cnblogs.com/itech/p/5284739.html
Copyright © 2011-2022 走看看