1、程序
#include <sstream>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
stringstream strStream;
strStream << "argc: " << argc << "\t";
for (int i = 0; i < argc; ++i)
{
strStream << "argv, " << i << ":" << argv[i] << endl;
}
cout << strStream.str().c_str();
return 0;
}
2、编译
c++ -g -o test test.cpp
chmod 777 test
3、调试
1)不带参数
[aaa@tmp]$ gdb test
GNU gdb Fedora (6.8-37.el5)
Copyright (C) 2008 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 "x86_64-redhat-linux-gnu"...
(gdb) r
Starting program: /home/aaa/tmp/test
argc: 1 argv, 0:/home/aaa/tmp/test
Program exited normally.
(gdb) quit
[aaa@tmp]$
2)带参数
方法1:
[aaa@tmp]$ gdb --args test 1 2 3 4 5 6 7 8 9 10
GNU gdb Fedora (6.8-37.el5)
Copyright (C) 2008 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 "x86_64-redhat-linux-gnu"...
(gdb) r
Starting program: /home/aaa/tmp/test 1 2 3 4 5 6 7 8 9 10
argc: 11 argv, 0:/home/aaa/tmp/test
argv, 1:1
argv, 2:2
argv, 3:3
argv, 4:4
argv, 5:5
argv, 6:6
argv, 7:7
argv, 8:8
argv, 9:9
argv, 10:10
Program exited normally.
(gdb) quit
[aaa@tmp]$
方法2:
[aaa@tmp]$ gdb test
GNU gdb Fedora (6.8-37.el5)
Copyright (C) 2008 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 "x86_64-redhat-linux-gnu"...
(gdb) set args 1 2 3 4 5 6 7 8 9 10
(gdb) r
Starting program: /home/aaa/tmp/test 1 2 3 4 5 6 7 8 9 10
argc: 11 argv, 0:/home/aaa/tmp/test
argv, 1:1
argv, 2:2
argv, 3:3
argv, 4:4
argv, 5:5
argv, 6:6
argv, 7:7
argv, 8:8
argv, 9:9
argv, 10:10
Program exited normally.
(gdb) quit
[aaa@tmp]$
原文链接: https://www.cnblogs.com/andy319/archive/2012/08/05/2623757.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/57991
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!