gdb 调试带参数的程序-转
2016-01-17 12:47
344 查看
例子:
#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也可以的
相关文章推荐
- Call to undefined function set_magic_quotes_runtime() in /opt/app/apache/install/index.php:12 Stack
- sqlite like通配符使用 -转
- 用Plane制作半透明Label
- Sqlite查询优化技巧——将LIKE语句转换为比较语句 -转
- 【Android问题】解决 Android SDK下载和更新失败“Connection to https://dl-ssl.google.com refused”的问题
- SQLite学习手册(索引和数据分析/清理)-转
- 安装php报错解决
- 《快学scala》笔记及答案1
- iOS开发之Masonry(一)
- unix设置线程优先级-转
- HDU 1074 课程安排 (状态压缩+DP,经典)
- 集群平衡介绍
- 线程属性pthread_attr_t简介-转
- 什么是MTBF测试
- VMware虚拟机开机之后等好久才能ssh连接?
- 王石:我每天都强迫自己做的一件事
- (转)高情商者的十五个表现,据说十个以上可以叱咤职场!
- iOS多线程GCD的简单使用
- windows系统下,双网卡电脑更改默认路由的命令-转
- OAuth与OpenID区别