gdb带参数调试方法
2016-07-16 11:25
387 查看
例子:
#include <stdio.h>
int main(int argc,char *argv[])
{
int i = argc;
printf("argc:%d\n",i);
for(i = 0;i < argc;i++)
printf("argv[%d]:%s\n",i,argv[i]);
return 1;
}
输出:
[root@(none) ~]# gcc -g -o main main.c
[root@(none) ~]# ./main a b c
argc:4
argv[0]:./main
argv[1]:a
argv[2]:b
argv[3]:c
调试:
[root@(none) ~]# gdb main
GNU gdb Red Hat Linux (6.6-8.fc7rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) set args a b c
(gdb) r
Starting program: /root/main a b c
argc:4
argv[0]:/root/main
argv[1]:a
argv[2]:b
argv[3]:c
Program exited with code 01.
(gdb)
或者用 r a b c也可以的
#include <stdio.h>
int main(int argc,char *argv[])
{
int i = argc;
printf("argc:%d\n",i);
for(i = 0;i < argc;i++)
printf("argv[%d]:%s\n",i,argv[i]);
return 1;
}
输出:
[root@(none) ~]# gcc -g -o main main.c
[root@(none) ~]# ./main a b c
argc:4
argv[0]:./main
argv[1]:a
argv[2]:b
argv[3]:c
调试:
[root@(none) ~]# gdb main
GNU gdb Red Hat Linux (6.6-8.fc7rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) set args a b c
(gdb) r
Starting program: /root/main a b c
argc:4
argv[0]:/root/main
argv[1]:a
argv[2]:b
argv[3]:c
Program exited with code 01.
(gdb)
或者用 r a b c也可以的
相关文章推荐
- 【记录】ADC
- HTML5 协议 WebSocket 教程
- Java之协变返回类型详解(附源码)
- springVS javaee
- 【奔跑的FPGA】part one--ip核仿真流程
- Ajax过程
- Scala Trait详解
- Android基础小知识
- Boost log库的使用
- LeetCode:Symmetric Tree(镜像二叉树)
- poj 2991 Traveling by Stagecoach
- Android应用基础知识
- typedef的用法总结
- 数据库事务
- alter table锁表,MySQL出现Waiting for table metadata lock的场景浅析及解决方案
- Python3操作MySQL,查询数据并保存到文件中
- 表格行列高亮显示的实现(二)
- 随笔-接入微信SDK64位包报错
- iOS开发实现下载器的基本功能(1)
- 之前写的一些博文