linux下gdb调试方法与技巧整理

您所在的位置:网站首页 gdb查看内存的方法 linux下gdb调试方法与技巧整理

linux下gdb调试方法与技巧整理

2023-11-11 03:55| 来源: 网络整理| 查看: 265

目录 一、gdb简介二、gdb使用流程1、启动gdb2、查看源码3、运行程序4、设置断点5、单步执行6、查看变量7、退出gdb 三、gdb基本使用命令1、运行命令2、设置断点3、查看源码4、打印表达式5、查看运行信息6、分割窗口7、cgdb强大工具8、常用gdb调试命令汇总 四、总结

一、gdb简介

GDB是一个由GNU开源组织发布的、UNIX/LINUX操作系统下的、基于命令行的、功能强大的程序调试工具。 对于一名Linux下工作的c/c++程序员,gdb是必不可少的工具;

二、gdb使用流程

这里用c程序做基本演示,c++程序也是一样的;

1、启动gdb

编译一个测试程序,-g表示可以调试,命令如下:

gcc -g test.c -o test

启动gdb,命令如下:

gdb test gdb -q test //表示不打印gdb版本信息,界面较为干净;

测试如下:

root@ubuntu:/home/eit/c_test# gdb test GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from test...done. (gdb) q root@ubuntu:/home/eit/c_test# gdb -q test Reading symbols from test...done. (gdb)

到此gdb启动完成!

2、查看源码

list(简写 l): 查看源程序代码,默认显示10行,按回车键继续看余下的。 测试如下:

(gdb) list 9 #define MAX_SIZE 10 11 int main() 12 { 13 int i,fd,size1 ,size2 ,len; 14 char *buf = "helo!I'm liujiangyong "; 15 char buf_r[15]; 16 len = strlen(buf); 17 fd = open("/home/hello.txt",O_CREAT | O_TRUNC | O_RDWR,0666); 18 if (fd


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3