GDB debugging a program with parameters

Source: Internet
Author: User

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++)
printf ("argv[%d]:%s\n", I,argv[i]);
return 1;
} output: [[email protected] (none) ~]# gcc-g-o main main.c
[[Email protected] (none) ~]#./main a b C
Argc:4
Argv[0]:./main
Argv[1]:a
Argv[2]:b
ARGV[3]:C debug: [[Email protected] (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.
Type "Show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "Show warranty" for details.
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) R
Starting program:/root/main a b C
Argc:4
Argv[0]:/root/main
Argv[1]:a
Argv[2]:b
Argv[3]:cprogram exited with code 01.
(GDB)or you can do it with R a b C.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.