首页 > 代码库 > gdb 调试带参数的程序
gdb 调试带参数的程序
转载: http://blog.sina.com.cn/s/blog_4b6f784001011yvh.html
例子:
#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;
}
{
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) ~]# ./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
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)
(gdb)
或者用 r a b c也可以的
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。