zoukankan      html  css  js  c++  java
  • GDB快速入门

    GDB快速入门

    GDB(GNU DeBugger)是Linux下强大的C/C++调试器,纯命令行操作

    启动

    以下为测试代码

    #include <stdio.h>
    
    int nGlobalVar = 0;
    
    int tempFunction(int a, int b)
    {
        printf("tempFunction is called, a = %d, b = %d
    ", a, b);
        return (a + b);
    }
    
    int main()
    {
        int n;
        n = 1;
        n++;
        n--;
    
        nGlobalVar += 100;
        nGlobalVar -= 12;
    
        printf("n = %d, nGlobalVar = %d
    ", n, nGlobalVar);
    
        n = tempFunction(1, 2);
        printf("n = %d", n);
    
        return 0;
    }
    

    启动调试

    $gcc -g hello.c -o hello #-g表示生成符号表和调试信息等
    $gdb -q hello #-q表示禁止显示介绍信息和版权
    

    常用指令

    • file hello:要装入调试的可执行文件
    • cd dir:改变工作目录
    • pwd:返回当前目录
    • run:执行正在被调试的程序
    • kill:停止当前正在调试的程序
    • list:列出正在调试的应用程序源码
    • break 行号:在某一行设置断点
    • tbreak:temporary breakpoints只运行一次的断点
    • watch var:监控变量
    • next:step over
    • step:step into
    • display var:每一次运行都会显示变量
    • undisplay varNum:删除display的变量
    • print expr:显示一次表达式的值
    • delete breakNum:删除指定断点,如果不加参数就删除所有
    • shell cmd:执行Linux shell命令
    • make:不退出gdb重新编译
    • quit:退出gdb
    • info breakpoints:查看断点
    • info func:显示所有函数名
    • info local:显示当前函数的所有局部变量
    • help:查看帮助
    • continue:进入下一个断点

    其他当然还有很多细节,即用即查

  • 相关阅读:
    js-排序算法
    django csrf token添加
    django mongodb配置
    django logging
    linux文件行首行尾添加或替换
    linux 大小写转化
    linux $参数
    mysql 基本操作
    生产者消费者示例
    python smtplib发email
  • 原文地址:https://www.cnblogs.com/fanghao/p/7639058.html
Copyright © 2011-2022 走看看