用GDB调试程序(二) 用GDB调试程序(三) 用GDB调试程序(四)

源文件test.cpp

#include <stdio.h>

int func(int n)
{
    int sum = 0, i;
    for (i = 0; i < n; i++) {
        sum += i;
    }
    return sum;
}

int main()
{
    int i;
    long result = 0;
    for (i = 1; i <= 100; i++) {
        result += i;
    }
    printf("result[1-100] = %ld /n", result);
    printf("result[1-250] = %d /n", func(250));
}

编译生成带调试信息的可执行文件

g++ -g test.cpp -o test

启动gdb

gdb test

gdb命令

r, run, 运行程序

q, quit, 退出gdb

l, llst,列出源码

参考资料:

用GDB调试程序(一)

用GDB调试程序(二)

用GDB调试程序(三)

用GDB调试程序(四)

转载于:https://www.cnblogs.com/gattaca/p/7582398.html

猜你喜欢

转载自blog.csdn.net/weixin_33923762/article/details/93401959
今日推荐