• 039 语法调试


    调试技术

    • 调试流程:单元测试 -> 集成测试 -> 交测试部
    • 分类
      • 静态调试
      • 动态调试

    pdb 调试

    常用命令 解释
    break / b 设置断点
    continue / c 继续执行程序
    list / l 查看当前行的代码段
    step / s 进入函数
    return / r 执行代码直到从当前函数返回
    exit / q 中止并退出
    next / n 执行下一行
    pp 打印变量的值
    help 帮助

    举例

    import pdb
    
    str1 = "aaa"
    pdb.set_trace()
    
    str2 = "bbb"
    str3 = "ccc"
    final = str1 + str2 + str3
    print(final)
    

    >>>

    > d:pdb_test.py(6)<module>()
    -> str2 = "bbb"
    (Pdb) n
    > d:pdb_test.py(7)<module>()
    -> str3 = "ccc"
    (Pdb) n
    > d:pdb_test.py(8)<module>()
    -> final = str1 + str2 + str3
    (Pdb) n
    > d:pdb_test.py(8)<module>()
    -> print(final)
    (Pdb) n
    aaabbbccc
    --Return--
    > d:pdb_test.py(9)<module>()->None
    -> print(final)
    (Pdb)
    

    补充

    • gdb: 将 C 反汇编
    #include <stdio.h>
    
    int main() {
        int a = 1, b = 2;
        printf("a + b = %d
    ", a + b);
    
        return 0;
    }
    
    • 将 test.c 编译为 test.exe 执行下方操作
    PS D:code> gdb test
    GNU gdb (GDB) 8.1
    Copyright (C) 2018 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-w64-mingw32".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from test...done.
    (gdb) disas main
    Dump of assembler code for function main:
       0x004015c0 <+0>:     push   %ebp
       0x004015c1 <+1>:     mov    %esp,%ebp
       0x004015c3 <+3>:     and    $0xfffffff0,%esp
       0x004015c6 <+6>:     sub    $0x20,%esp
       0x004015c9 <+9>:     call   0x401690 <__main>
       0x004015ce <+14>:    movl   $0x1,0x1c(%esp)
       0x004015d6 <+22>:    movl   $0x2,0x18(%esp)
       0x004015de <+30>:    mov    0x1c(%esp),%edx
       0x004015e2 <+34>:    mov    0x18(%esp),%eax
       0x004015e6 <+38>:    add    %edx,%eax
       0x004015e8 <+40>:    mov    %eax,0x4(%esp)
       0x004015ec <+44>:    movl   $0x404044,(%esp)
       0x004015f3 <+51>:    call   0x4025ac <printf>
       0x004015f8 <+56>:    mov    $0x0,%eax
       0x004015fd <+61>:    leave
       0x004015fe <+62>:    ret
       0x004015ff <+63>:    nop
    End of assembler dump.
    (gdb) q
    

    Pycharm 调试

    • 软件有 run, debug 两种模式
    • 断点
      • 在行号附近左键单击即可设置
      • 程序在 debug 模式下,执行到断点所在行就会暂停
    • 单步
      • 程序停在断点处后,常用“单步”一步一步调试
      • 除了单步 step over,还有 step into, step into my code

    单元测试

  • 相关阅读:
    (转)怎样获得与激活Windows 7超级管理员权限
    (转) C代码优化方案
    英语词汇立体记忆 02
    (转)LUA和C之间的函数调用
    通过lua自带例子学习lua 01
    英语词汇立体记忆 01
    反射(类加载内存分析)
    反射(类加载器的作用)
    反射(动态创建对象操作属性)
    反射(分析类初始化)
  • 原文地址:https://www.cnblogs.com/yorkyu/p/12081139.html
Copyright © 2020-2023  润新知