From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7041 invoked by alias); 4 Jan 2008 05:03:07 -0000 Received: (qmail 6276 invoked by uid 22791); 4 Jan 2008 05:01:57 -0000 Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 04 Jan 2008 04:58:27 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 80A372A964D; Thu, 3 Jan 2008 23:58:25 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id v0N5hYqbH-ew; Thu, 3 Jan 2008 23:58:25 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 3864A2A963E; Thu, 3 Jan 2008 23:58:24 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 3CBA6E7ACB; Thu, 3 Jan 2008 20:58:13 -0800 (PST) Date: Fri, 04 Jan 2008 05:03:00 -0000 From: Joel Brobecker To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: --pid and --core Message-ID: <20080104045813.GA28411@adacore.com> References: <477D122A.4060405@codesourcery.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <477D122A.4060405@codesourcery.com> User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-01/txt/msg00048.txt.bz2 Hi Pedro, > 2007-12-28 Pedro Alves > > * main.c (captured_main): Error out if --core and --pid options > were issued simultaneously. If an explicit pid option was passed, > don't fallback to core file. Detect extra arguments better in the > presence of explicit pid or core arguments. Thanks for the patch. A couple of of comments: > + { > + ++count; > + if (count == 1) > + { > + symarg = argv[optind]; > + execarg = argv[optind]; > + } > + else if (count > 2 > + /* If we have a --pid or a --core argument, > + this argument don't make sense. */ ^^^^ doesn't > + || pidarg != NULL > + || corearg != NULL) > + { > + fprintf_unfiltered (gdb_stderr, _("\ > +Excess command line arguments ignored. (%s%s)\n"), > + argv[optind], > + (optind == argc - 1) ? "" : " ..."); > + optind = argc; > + break; > + } > + else > + /* The documentation says this can be a "ProcID" as > + well. We will try it later as both a corefile and a > + pid. */ > + pid_or_core_arg = argv[optind]; > + } It took me a long while to understand this loop. I realize this was already implemented that way before, but I think something like the code below is simpler. What do you think? /* The first argument, if specified, is the name of the executable. */ if (argc - optind > 0) { symarg = argv[optind]; execarg = argv[optind]; optind++; } /* If the user hasn't already specified a PID or the name of a core file, then a second optional argument is allowed. If present, this argument should be interpreted as either a PID or a core file, whichever works. */ if (pidarg == NULL && corearg == NULL && argc - optind > 0) { pid_or_core_arg = argv[optind]; optind++; } /* Any argument left on the command line is unexpected and will be ignored. Inform the user. */ for (; optind < argc; optind++) fprintf_unfiltered (...); Thanks, -- Joel