Reprint: http://blog.sina.com.cn/s/blog_4b6f784001011yvh.html
Example:
#include <stdio.h>int Main (int argc,char *argv[] { int i = argc; printf ( argc:%d\n " ,i); for (i = 0 ; i < Argc;i++ argv[%d]:%s\n " ,i,argv[i]); return 1
Output:
gcc -G-~]#./Main a b cargc:4argv[0]:./mainargv[ 1]:aargv[2]:bargv[3]:c
Debug:
[[Email protected] (none) ~]# gdb maingnu gdb Red Hat Linux (6.6-8. Fc7rh) Copyright (C)2006Free software Foundation, Inc.gdb is Freesoftware, covered by the GNU general public License, and your arewelcome to change it and/or distribute copies of it under certain conditions. Type"Show Copying"To see the conditions. There is absolutely no warranty forGdb. Type"Show Warranty" fordetails. This GDB is configured as"I386-redhat-linux-gnu"... Using Host libthread_db Library"/lib/libthread_db.so.1". (GDB) set args a b c (GDB) rstarting program:/root/main a b cargc:4argv[0]:/root/mainargv[1]:aargv[2]:bargv[3]:cprogram exited with code on. (GDB)
or you can use R a B c as well.
GDB debugging a program with parameters