C指针原理(30)-C语言-LINUX/UNIX环境下调试

版权声明:本博客所有文章版权归博主刘兴所有,转载请注意来源 https://blog.csdn.net/AI_LX/article/details/89370940

file 文件名

在gdb中载入某可执行文件

break

设置断点

支持如下形式:
break 行号;
break 函数名称;
break 行号/函数名称 if 条件

info

查看和可执行程序相关的
各种信息

kill

终止正在调试的程序

print

显示变量或表达式的值

set args

设置调试程序的运行参数

“set args 参数列表”

delete

删除设置的某个断点
或观测点

delete后可以使用breakpoints、
checkpoint、display、mem和
tracepoints。可使用
help delete查看

clear

删除设置在指定行号
或函数上的断点

continue

从断点处继续执行程序

list

列出gdb中可加载的
程序代码

不带任何参数使用list命令时,
会从开始位置列出所有代码,
同时list还支持列出指定行号
之间的代码

watch

在程序中设置观测点

如果数据改变,将给出
变化前后的情况

run

运行在gdb中可加载的程序

next

单步执行程序

step

进入所调用的函数内部,
查看执行情况

退出调用函数,回到调用处
使用finish命令

whatis

查看变量或函数类型

调用格式为“whatis 变量名/
函数名

ptype

显示数据结构定义情况

与whatis不同的是,
ptype可以显示类或
数据结构的定义情况

make

编译程序

quit

退出

一、gdb,在shell窗口调试

main.c内容:

main.c

#include <stdio.h>

int main()

{

int y=0;

for (int i=0;i<10;i++){

y+=i;

}

return 0;

}

编译:

xxxxxxx@xxxxxxx-desktop:~/test$ gcc -ggdb -std=c99 -o main main.c

启动gdb

1、gdb 执行文件名

xxxxxxx@xxxxxxx-desktop:~/test$ gdb main

GNU gdb (GDB) 7.1-ubuntu

Copyright © 2010 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 “i486-linux-gnu”.

For bug reporting instructions, please see:

http://www.gnu.org/software/gdb/bugs/;…

Reading symbols from /home/xxxxxxx/test/main…done.

2、list为列出源代码

(gdb) list

1

2 #include <stdio.h>

3 int main()

4 {

5 int y=0;

6 for (int i=0;i<10;i++){

7 y+=i;

8 }

9 return 0;

10 }

3、运行

(gdb) run

Starting program: /home/xxxxxxx/test/main

Program exited normally.

4、退出gdb

(gdb) quit

5、启动gdb后,再设置要加载的文件

(gdb) file main

Reading symbols from /home/xxxxxxx/test/main…done.

6、设置断点,,使用break行号

(gdb) list

warning: Source file is more recent than executable.

1

2 #include <stdio.h>

3 int main()

4 {

5 int y=0;

6 for (int i=0;i<10;i++){

7 y+=i;

8 }

9 return 0;

10 }

(gdb) break 7

Breakpoint 1 at 0x80483ca: file main.c, line 7.

7、运行,run

(gdb) run

Starting program: /home/xxxxxxx/test/main

Breakpoint 1, main () at main.c:7

7 y+=i;

8、离开这个断点,继续运行

(gdb) c

Continuing.

9、监视变量

(gdb) watch y

Hardware watchpoint 2: y

10、检查变量变化

(gdb) c

Continuing.

Hardware watchpoint 2: y

Old value = 1

New value = 3

main () at main.c:6

6 for (int i=0;i<10;i++){

(gdb) c

Continuing.

Breakpoint 1, main () at main.c:7

7 y+=i;

(gdb) c

Continuing.

Hardware watchpoint 2: y

Old value = 3

New value = 6

main () at main.c:6

6 for (int i=0;i<10;i++){

二、ddd,使用

可以在选择行或某变量后,watch,break等按钮,很方便,图形方式调试

右中部的面板是一些流程调试

splint是一个动态检查C语言程序安全弱点和编写错误的程序.splint会进行
多种常规检查,包括未使用的变量,类型不一致,使用未定义变量,无法执行的
代码,忽略返回值,执行路径未返回,无限循环等错误.

安装:

root@dp:/home/dp/cursestest # cd /usr/ports/devel/splint

root@dp:/usr/ports/devel/splint # make install clean

猜你喜欢

转载自blog.csdn.net/AI_LX/article/details/89370940