--pid and --core

Joel Brobecker brobecker@adacore.com
Fri Jan 4 05:03:00 GMT 2008


Hi Pedro,

> 2007-12-28  Pedro Alves  <pedro_alves@portugalmail.pt>
> 
> 	* 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



More information about the Gdb-patches mailing list