Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Add new cmd line parameter "--pid" for attach.
@ 2002-01-04 19:25 Michael Snyder
  2002-01-05  0:59 ` Eli Zaretskii
  2002-01-07 18:55 ` Elena Zannoni
  0 siblings, 2 replies; 29+ messages in thread
From: Michael Snyder @ 2002-01-04 19:25 UTC (permalink / raw)
  To: gdb-patches


Currently if you invoke gdb as:

	gdb filename 12345

gdb will attempt to open a corefile called "12345", and if that
fails it will print a "file not found" warning, and then attempt
to attach to a process "12345".

There is a "--core <filename>" command-line argument, 
so that you can specify a corefile without a symbol file:

	gdb --core <filename>

but there is no "--pid" option to allow you to specify
a process-id without a symbol file.

This patch does two things:

1) Add a "--pid" option to allow specification of an attach pid.

2) If the second argument (after the symbol-file) begins with
a digit, try attach first instead of trying to open it as a
corefile first.  This eliminates the "file not found" warning.

2002-01-04  Michael Snyder  <msnyder@redhat.com>

	* main.c (captured_main): Add new command line option "--pid".
	If the second command line argument (following the symbol-file)
	begins with a digit, try to attach to it before trying to open
	it as a corefile.
	(print_gdb_help): Document the "--pid" argument.

Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.14
diff -c -3 -p -r1.14 main.c
*** main.c	2001/11/22 00:23:12	1.14
--- main.c	2002/01/05 03:15:43
*************** captured_main (void *data)
*** 239,244 ****
--- 239,246 ----
        {"e", required_argument, 0, 'e'},
        {"core", required_argument, 0, 'c'},
        {"c", required_argument, 0, 'c'},
+       {"pid", required_argument, 0, 'p'},
+       {"p", required_argument, 0, 'p'},
        {"command", required_argument, 0, 'x'},
        {"version", no_argument, &print_version, 1},
        {"x", required_argument, 0, 'x'},
*************** captured_main (void *data)
*** 320,325 ****
--- 322,331 ----
  	  case 'c':
  	    corearg = optarg;
  	    break;
+ 	  case 'p':
+ 	    /* "corearg" is shared by "--core" and "--pid" */
+ 	    corearg = optarg;
+ 	    break;
  	  case 'x':
  	    cmdarg[ncmd++] = optarg;
  	    if (ncmd >= cmdsize)
*************** extern int gdbtk_test (char *);
*** 463,470 ****
  	      execarg = argv[optind];
  	      break;
  	    case 2:
! 	      /* FIXME: The documentation says this can be a
! 		 "ProcID". as well.  */
  	      corearg = argv[optind];
  	      break;
  	    case 3:
--- 469,476 ----
  	      execarg = argv[optind];
  	      break;
  	    case 2:
! 	      /* The documentation says this can be a "ProcID" as well. 
! 	         We will try it as both a corefile and a pid.  */
  	      corearg = argv[optind];
  	      break;
  	    case 3:
*************** extern int gdbtk_test (char *);
*** 586,597 ****
  
    if (corearg != NULL)
      {
!       if (catch_command_errors (core_file_command, corearg, !batch, RETURN_MASK_ALL) == 0)
  	{
! 	  /* See if the core file is really a PID. */
! 	  if (isdigit (corearg[0]))
! 	    catch_command_errors (attach_command, corearg, !batch, RETURN_MASK_ALL);
  	}
      }
  
    if (ttyarg != NULL)
--- 592,611 ----
  
    if (corearg != NULL)
      {
!       /* corearg may be either a corefile or a pid.
! 	 If its first character is a digit, try attach first
! 	 and then corefile.  Otherwise try corefile first. */
! 
!       if (isdigit (corearg[0]))
  	{
! 	  if (catch_command_errors (attach_command, corearg, 
! 				    !batch, RETURN_MASK_ALL) == 0)
! 	    catch_command_errors (core_file_command, corearg, 
! 				  !batch, RETURN_MASK_ALL);
  	}
+       else /* Can't be a pid, better be a corefile. */
+ 	catch_command_errors (core_file_command, corearg, 
+ 			      !batch, RETURN_MASK_ALL);
      }
  
    if (ttyarg != NULL)
*************** extern int gdbtk_test (char *);
*** 616,621 ****
--- 630,646 ----
  	catch_command_errors (source_command, gdbinit, 0, RETURN_MASK_ALL);
        }
  
+   /* These need to be set this late in the initialization to ensure that
+      they are defined for the current environment.  They define the
+      radix variables needed by a save-breakpoints file to preserve the
+      radix across the breakpoints restoration assuming they are restored
+      using the -x (-command) command line options.  */
+      
+   set_internalvar (lookup_internalvar ("input_radix"),
+ 		   value_from_longest (builtin_type_int, (LONGEST) input_radix));
+   set_internalvar (lookup_internalvar ("output_radix"),
+ 		   value_from_longest (builtin_type_int, (LONGEST) output_radix));
+ 
    for (i = 0; i < ncmd; i++)
      {
  #if 0
*************** Options:\n\n\
*** 752,757 ****
--- 777,783 ----
    --cd=DIR           Change current directory to DIR.\n\
    --command=FILE     Execute GDB commands from FILE.\n\
    --core=COREFILE    Analyze the core dump COREFILE.\n\
+   --pid=PID          Attach to running process PID.\n\
  ", stream);
    fputs_unfiltered ("\
    --dbx              DBX compatibility mode.\n\


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-04 19:25 [RFA] Add new cmd line parameter "--pid" for attach Michael Snyder
@ 2002-01-05  0:59 ` Eli Zaretskii
  2002-01-05 13:12   ` Michael Snyder
  2002-01-07 18:55 ` Elena Zannoni
  1 sibling, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2002-01-05  0:59 UTC (permalink / raw)
  To: msnyder; +Cc: gdb-patches

> Date: Fri, 4 Jan 2002 19:21:06 -0800
> From: Michael Snyder <msnyder@cygnus.com>
> 
>     --command=FILE     Execute GDB commands from FILE.\n\
>     --core=COREFILE    Analyze the core dump COREFILE.\n\
> +   --pid=PID          Attach to running process PID.\n\
>   ", stream);

The new command-line option should be described in gdb.texinfo as
well.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-05  0:59 ` Eli Zaretskii
@ 2002-01-05 13:12   ` Michael Snyder
  2002-01-06  0:04     ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Snyder @ 2002-01-05 13:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

Eli Zaretskii wrote:
> 
> > Date: Fri, 4 Jan 2002 19:21:06 -0800
> > From: Michael Snyder <msnyder@cygnus.com>
> >
> >     --command=FILE     Execute GDB commands from FILE.\n\
> >     --core=COREFILE    Analyze the core dump COREFILE.\n\
> > +   --pid=PID          Attach to running process PID.\n\
> >   ", stream);
> 
> The new command-line option should be described in gdb.texinfo as
> well.

Sure.  How's this?

[-- Attachment #2: pid.patch --]
[-- Type: text/plain, Size: 1033 bytes --]

2002-01-05  Michael Snyder  <msnyder@redhat.com>

	* gdb.texinfo (--pid): Document new command line option (attach).

Index: gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.62
diff -p -r1.62 gdb.texinfo
*** gdb.texinfo	2001/12/30 03:52:20	1.62
--- gdb.texinfo	2002/01/05 21:10:15
*************** Connect to process ID @var{number}, as w
*** 851,856 ****
--- 851,867 ----
  (unless there is a file in core-dump format named @var{number}, in which
  case @samp{-c} specifies that file as a core dump to read).
  
+ @item -pid @ver{number}
+ @itemx -p @var{number}
+ @cindex @code{--pid}
+ @cindex @code{-p}
+ Use @var{number} as a process ID to attach to.
+ 
+ @item -p @var{number}
+ Connect to process ID @var{number}, as with the @code{attach} command.
+ If there is no such process, @value{GDBN} will attempt to open a core
+ file named @var{number}.
+ 
  @item -command @var{file}
  @itemx -x @var{file}
  @cindex @code{--command}

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-05 13:12   ` Michael Snyder
@ 2002-01-06  0:04     ` Eli Zaretskii
  2002-01-06 21:26       ` Michael Snyder
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2002-01-06  0:04 UTC (permalink / raw)
  To: msnyder; +Cc: gdb-patches

> Date: Sat, 05 Jan 2002 13:07:42 -0800
> From: Michael Snyder <msnyder@redhat.com>
> 
> + @item -pid @ver{number}
> + @itemx -p @var{number}
> + @cindex @code{--pid}
> + @cindex @code{-p}
> + Use @var{number} as a process ID to attach to.
> + 
> + @item -p @var{number}
> + Connect to process ID @var{number}, as with the @code{attach} command.
> + If there is no such process, @value{GDBN} will attempt to open a core
> + file named @var{number}.

This seems to describe the new option twice.  You probably meant to
merge the two description parts, and eliminate the second "@item -p".

Other than that, it can go in.  Thanks.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-06  0:04     ` Eli Zaretskii
@ 2002-01-06 21:26       ` Michael Snyder
  2002-01-07  1:20         ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Snyder @ 2002-01-06 21:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Eli Zaretskii wrote:
> 
> > Date: Sat, 05 Jan 2002 13:07:42 -0800
> > From: Michael Snyder <msnyder@redhat.com>
> >
> > + @item -pid @ver{number}
> > + @itemx -p @var{number}
> > + @cindex @code{--pid}
> > + @cindex @code{-p}
> > + Use @var{number} as a process ID to attach to.
> > +
> > + @item -p @var{number}
> > + Connect to process ID @var{number}, as with the @code{attach} command.
> > + If there is no such process, @value{GDBN} will attempt to open a core
> > + file named @var{number}.
> 
> This seems to describe the new option twice.  You probably meant to
> merge the two description parts, and eliminate the second "@item -p".

Actually, I just copied what was there already for the --core option.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-06 21:26       ` Michael Snyder
@ 2002-01-07  1:20         ` Eli Zaretskii
  2002-01-07 11:07           ` Michael Snyder
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2002-01-07  1:20 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches


On Sun, 6 Jan 2002, Michael Snyder wrote:

> Eli Zaretskii wrote:
> > 
> > > Date: Sat, 05 Jan 2002 13:07:42 -0800
> > > From: Michael Snyder <msnyder@redhat.com>
> > >
> > > + @item -pid @ver{number}
> > > + @itemx -p @var{number}
> > > + @cindex @code{--pid}
> > > + @cindex @code{-p}
> > > + Use @var{number} as a process ID to attach to.
> > > +
> > > + @item -p @var{number}
> > > + Connect to process ID @var{number}, as with the @code{attach} command.
> > > + If there is no such process, @value{GDBN} will attempt to open a core
> > > + file named @var{number}.
> > 
> > This seems to describe the new option twice.  You probably meant to
> > merge the two description parts, and eliminate the second "@item -p".
> 
> Actually, I just copied what was there already for the --core option.

I'm not sure what you mean.  I looked in gdb.texinfo, and all I see for 
"--core" there is this:

   @item -core @var{file}
   @itemx -c @var{file}
   @cindex @code{--core}
   @cindex @code{-c}
   Use file @var{file} as a core dump to examine.

This doesn't describe --core twice, and doesn't use @item -c twice.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-07  1:20         ` Eli Zaretskii
@ 2002-01-07 11:07           ` Michael Snyder
  2002-01-07 12:28             ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Snyder @ 2002-01-07 11:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Eli Zaretskii wrote:
> 
> On Sun, 6 Jan 2002, Michael Snyder wrote:
> 
> > Eli Zaretskii wrote:
> > >
> > > > Date: Sat, 05 Jan 2002 13:07:42 -0800
> > > > From: Michael Snyder <msnyder@redhat.com>
> > > >
> > > > + @item -pid @ver{number}
> > > > + @itemx -p @var{number}
> > > > + @cindex @code{--pid}
> > > > + @cindex @code{-p}
> > > > + Use @var{number} as a process ID to attach to.
> > > > +
> > > > + @item -p @var{number}
> > > > + Connect to process ID @var{number}, as with the @code{attach} command.
> > > > + If there is no such process, @value{GDBN} will attempt to open a core
> > > > + file named @var{number}.
> > >
> > > This seems to describe the new option twice.  You probably meant to
> > > merge the two description parts, and eliminate the second "@item -p".
> >
> > Actually, I just copied what was there already for the --core option.
> 
> I'm not sure what you mean.  I looked in gdb.texinfo, and all I see for
> "--core" there is this:
> 
>    @item -core @var{file}
>    @itemx -c @var{file}
>    @cindex @code{--core}
>    @cindex @code{-c}
>    Use file @var{file} as a core dump to examine.
> 
> This doesn't describe --core twice, and doesn't use @item -c twice.

Look at the next lines after that.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-07 11:07           ` Michael Snyder
@ 2002-01-07 12:28             ` Eli Zaretskii
  2002-01-07 13:39               ` Michael Snyder
  2002-01-07 16:14               ` Michael Snyder
  0 siblings, 2 replies; 29+ messages in thread
From: Eli Zaretskii @ 2002-01-07 12:28 UTC (permalink / raw)
  To: msnyder; +Cc: gdb-patches

> Date: Mon, 07 Jan 2002 11:02:50 -0800
> From: Michael Snyder <msnyder@redhat.com>
> > 
> >    @item -core @var{file}
> >    @itemx -c @var{file}
> >    @cindex @code{--core}
> >    @cindex @code{-c}
> >    Use file @var{file} as a core dump to examine.
> > 
> > This doesn't describe --core twice, and doesn't use @item -c twice.
> 
> Look at the next lines after that.

You mean, this?

    @item -c @var{number}
    Connect to process ID @var{number}, as with the @code{attach} command

If so, it's not entirely the same: the first -c says "-c FILE", the
second says "-c NUMBER".  In your case, both say "-p NUMBER", so I
think it's confusing to have both of them.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-07 12:28             ` Eli Zaretskii
@ 2002-01-07 13:39               ` Michael Snyder
  2002-01-07 16:14               ` Michael Snyder
  1 sibling, 0 replies; 29+ messages in thread
From: Michael Snyder @ 2002-01-07 13:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Eli Zaretskii wrote:
> 
> > Date: Mon, 07 Jan 2002 11:02:50 -0800
> > From: Michael Snyder <msnyder@redhat.com>
> > >
> > >    @item -core @var{file}
> > >    @itemx -c @var{file}
> > >    @cindex @code{--core}
> > >    @cindex @code{-c}
> > >    Use file @var{file} as a core dump to examine.
> > >
> > > This doesn't describe --core twice, and doesn't use @item -c twice.
> >
> > Look at the next lines after that.
> 
> You mean, this?
> 
>     @item -c @var{number}
>     Connect to process ID @var{number}, as with the @code{attach} command
> 
> If so, it's not entirely the same: the first -c says "-c FILE", the
> second says "-c NUMBER".  In your case, both say "-p NUMBER", so I
> think it's confusing to have both of them.

OK, I'll take out the second paragraph and commit it.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-07 12:28             ` Eli Zaretskii
  2002-01-07 13:39               ` Michael Snyder
@ 2002-01-07 16:14               ` Michael Snyder
  2002-01-08  0:53                 ` Eli Zaretskii
  1 sibling, 1 reply; 29+ messages in thread
From: Michael Snyder @ 2002-01-07 16:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 748 bytes --]

Eli Zaretskii wrote:
> 
> > Date: Mon, 07 Jan 2002 11:02:50 -0800
> > From: Michael Snyder <msnyder@redhat.com>
> > >
> > >    @item -core @var{file}
> > >    @itemx -c @var{file}
> > >    @cindex @code{--core}
> > >    @cindex @code{-c}
> > >    Use file @var{file} as a core dump to examine.
> > >
> > > This doesn't describe --core twice, and doesn't use @item -c twice.
> >
> > Look at the next lines after that.
> 
> You mean, this?
> 
>     @item -c @var{number}
>     Connect to process ID @var{number}, as with the @code{attach} command
> 
> If so, it's not entirely the same: the first -c says "-c FILE", the
> second says "-c NUMBER".  In your case, both say "-p NUMBER", so I
> think it's confusing to have both of them.

OK, how's this?

[-- Attachment #2: pid.patch --]
[-- Type: text/plain, Size: 1170 bytes --]

2002-01-05  Michael Snyder  <msnyder@redhat.com>

	* gdb.texinfo (--pid): Document new command line option (attach).

Index: gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.68
diff -p -r1.68 gdb.texinfo
*** gdb.texinfo	2002/01/07 09:28:43	1.68
--- gdb.texinfo	2002/01/08 00:12:51
*************** file.
*** 937,945 ****
  Use file @var{file} as a core dump to examine.
  
  @item -c @var{number}
! Connect to process ID @var{number}, as with the @code{attach} command
! (unless there is a file in core-dump format named @var{number}, in which
! case @samp{-c} specifies that file as a core dump to read).
  
  @item -command @var{file}
  @itemx -x @var{file}
--- 937,949 ----
  Use file @var{file} as a core dump to examine.
  
  @item -c @var{number}
! @item -pid @ver{number}
! @itemx -p @var{number}
! @cindex @code{--pid}
! @cindex @code{-p}
! Connect to process ID @var{number}, as with the @code{attach} command.
! If there is no such process, @value{GDBN} will attempt to open a core
! file named @var{number}.
  
  @item -command @var{file}
  @itemx -x @var{file}

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-04 19:25 [RFA] Add new cmd line parameter "--pid" for attach Michael Snyder
  2002-01-05  0:59 ` Eli Zaretskii
@ 2002-01-07 18:55 ` Elena Zannoni
  2002-01-08 15:15   ` Michael Snyder
  1 sibling, 1 reply; 29+ messages in thread
From: Elena Zannoni @ 2002-01-07 18:55 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches

Michael Snyder writes:
 > 
 > Currently if you invoke gdb as:
 > 
 > 	gdb filename 12345
 > 
 > gdb will attempt to open a corefile called "12345", and if that
 > fails it will print a "file not found" warning, and then attempt
 > to attach to a process "12345".
 > 
 > There is a "--core <filename>" command-line argument, 
 > so that you can specify a corefile without a symbol file:
 > 
 > 	gdb --core <filename>
 > 
 > but there is no "--pid" option to allow you to specify
 > a process-id without a symbol file.
 > 
 > This patch does two things:
 > 
 > 1) Add a "--pid" option to allow specification of an attach pid.
 > 

This bit is approved.

 > 2) If the second argument (after the symbol-file) begins with
 > a digit, try attach first instead of trying to open it as a
 > corefile first.  This eliminates the "file not found" warning.
 > 

About this, I have a question, what happens if you have a corefile
whose name starts with a digit? I tried it and I get an error:

[ezannoni@localhost gdb]$ ./gdb -nw ./gdb 2222core
GNU gdb 2002-01-03-cvs
Copyright 2001 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 conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
Attaching to program: /home/ezannoni/sources/native/gdb/gdb, process 2222
ptrace: No such process.

then it proceeds normally to figure out it's a core file.

I can be convinced that a digit is more likely to indicate a pid than
a corefile, but would there be a way to make that error be silent? I
realize that those error messages are generated in the bowels of gdb,
and it may be really hard to fix that (gee, isn't this something the
insight people have some opinion about? :-)

What's that bit about input-radix and output-radix? 

Elena



 > 2002-01-04  Michael Snyder  <msnyder@redhat.com>
 > 
 > 	* main.c (captured_main): Add new command line option "--pid".
 > 	If the second command line argument (following the symbol-file)
 > 	begins with a digit, try to attach to it before trying to open
 > 	it as a corefile.
 > 	(print_gdb_help): Document the "--pid" argument.
 > 
 > Index: main.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/main.c,v
 > retrieving revision 1.14
 > diff -c -3 -p -r1.14 main.c
 > *** main.c	2001/11/22 00:23:12	1.14
 > --- main.c	2002/01/05 03:15:43
 > *************** captured_main (void *data)
 > *** 239,244 ****
 > --- 239,246 ----
 >         {"e", required_argument, 0, 'e'},
 >         {"core", required_argument, 0, 'c'},
 >         {"c", required_argument, 0, 'c'},
 > +       {"pid", required_argument, 0, 'p'},
 > +       {"p", required_argument, 0, 'p'},
 >         {"command", required_argument, 0, 'x'},
 >         {"version", no_argument, &print_version, 1},
 >         {"x", required_argument, 0, 'x'},
 > *************** captured_main (void *data)
 > *** 320,325 ****
 > --- 322,331 ----
 >   	  case 'c':
 >   	    corearg = optarg;
 >   	    break;
 > + 	  case 'p':
 > + 	    /* "corearg" is shared by "--core" and "--pid" */
 > + 	    corearg = optarg;
 > + 	    break;
 >   	  case 'x':
 >   	    cmdarg[ncmd++] = optarg;
 >   	    if (ncmd >= cmdsize)
 > *************** extern int gdbtk_test (char *);
 > *** 463,470 ****
 >   	      execarg = argv[optind];
 >   	      break;
 >   	    case 2:
 > ! 	      /* FIXME: The documentation says this can be a
 > ! 		 "ProcID". as well.  */
 >   	      corearg = argv[optind];
 >   	      break;
 >   	    case 3:
 > --- 469,476 ----
 >   	      execarg = argv[optind];
 >   	      break;
 >   	    case 2:
 > ! 	      /* The documentation says this can be a "ProcID" as well. 
 > ! 	         We will try it as both a corefile and a pid.  */
 >   	      corearg = argv[optind];
 >   	      break;
 >   	    case 3:
 > *************** extern int gdbtk_test (char *);
 > *** 586,597 ****
 >   
 >     if (corearg != NULL)
 >       {
 > !       if (catch_command_errors (core_file_command, corearg, !batch, RETURN_MASK_ALL) == 0)
 >   	{
 > ! 	  /* See if the core file is really a PID. */
 > ! 	  if (isdigit (corearg[0]))
 > ! 	    catch_command_errors (attach_command, corearg, !batch, RETURN_MASK_ALL);
 >   	}
 >       }
 >   
 >     if (ttyarg != NULL)
 > --- 592,611 ----
 >   
 >     if (corearg != NULL)
 >       {
 > !       /* corearg may be either a corefile or a pid.
 > ! 	 If its first character is a digit, try attach first
 > ! 	 and then corefile.  Otherwise try corefile first. */
 > ! 
 > !       if (isdigit (corearg[0]))
 >   	{
 > ! 	  if (catch_command_errors (attach_command, corearg, 
 > ! 				    !batch, RETURN_MASK_ALL) == 0)
 > ! 	    catch_command_errors (core_file_command, corearg, 
 > ! 				  !batch, RETURN_MASK_ALL);
 >   	}
 > +       else /* Can't be a pid, better be a corefile. */
 > + 	catch_command_errors (core_file_command, corearg, 
 > + 			      !batch, RETURN_MASK_ALL);
 >       }
 >   
 >     if (ttyarg != NULL)
 > *************** extern int gdbtk_test (char *);
 > *** 616,621 ****
 > --- 630,646 ----
 >   	catch_command_errors (source_command, gdbinit, 0, RETURN_MASK_ALL);
 >         }
 >   
 > +   /* These need to be set this late in the initialization to ensure that
 > +      they are defined for the current environment.  They define the
 > +      radix variables needed by a save-breakpoints file to preserve the
 > +      radix across the breakpoints restoration assuming they are restored
 > +      using the -x (-command) command line options.  */
 > +      
 > +   set_internalvar (lookup_internalvar ("input_radix"),
 > + 		   value_from_longest (builtin_type_int, (LONGEST) input_radix));
 > +   set_internalvar (lookup_internalvar ("output_radix"),
 > + 		   value_from_longest (builtin_type_int, (LONGEST) output_radix));
 > + 
 >     for (i = 0; i < ncmd; i++)
 >       {
 >   #if 0
 > *************** Options:\n\n\
 > *** 752,757 ****
 > --- 777,783 ----
 >     --cd=DIR           Change current directory to DIR.\n\
 >     --command=FILE     Execute GDB commands from FILE.\n\
 >     --core=COREFILE    Analyze the core dump COREFILE.\n\
 > +   --pid=PID          Attach to running process PID.\n\
 >   ", stream);
 >     fputs_unfiltered ("\
 >     --dbx              DBX compatibility mode.\n\


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-07 16:14               ` Michael Snyder
@ 2002-01-08  0:53                 ` Eli Zaretskii
  2002-01-08 15:15                   ` Michael Snyder
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2002-01-08  0:53 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches


On Mon, 7 Jan 2002, Michael Snyder wrote:

> OK, how's this?

It's okay, but:

> ! @item -pid @ver{number}
               ^^^^
This should be @var, not @ver.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-07 18:55 ` Elena Zannoni
@ 2002-01-08 15:15   ` Michael Snyder
  2002-01-08 16:59     ` Andrew Cagney
  2002-01-10 13:13     ` Elena Zannoni
  0 siblings, 2 replies; 29+ messages in thread
From: Michael Snyder @ 2002-01-08 15:15 UTC (permalink / raw)
  To: gdb-patches

Elena Zannoni wrote:
> 
> Michael Snyder writes:
>  >
>  > Currently if you invoke gdb as:
>  >
>  >      gdb filename 12345
>  >
>  > gdb will attempt to open a corefile called "12345", and if that
>  > fails it will print a "file not found" warning, and then attempt
>  > to attach to a process "12345".
>  >
>  > There is a "--core <filename>" command-line argument,
>  > so that you can specify a corefile without a symbol file:
>  >
>  >      gdb --core <filename>
>  >
>  > but there is no "--pid" option to allow you to specify
>  > a process-id without a symbol file.
>  >
>  > This patch does two things:
>  >
>  > 1) Add a "--pid" option to allow specification of an attach pid.
>  >
> 
> This bit is approved.
> 
>  > 2) If the second argument (after the symbol-file) begins with
>  > a digit, try attach first instead of trying to open it as a
>  > corefile first.  This eliminates the "file not found" warning.
>  >
> 
> About this, I have a question, what happens if you have a corefile
> whose name starts with a digit? I tried it and I get an error:
> 
> [ezannoni@localhost gdb]$ ./gdb -nw ./gdb 2222core
> GNU gdb 2002-01-03-cvs
> Copyright 2001 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 conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for details.
> This GDB was configured as "i686-pc-linux-gnu"...
> Attaching to program: /home/ezannoni/sources/native/gdb/gdb, process 2222
> ptrace: No such process.
> 
> then it proceeds normally to figure out it's a core file.

Right -- this is actually the reverse of the old behavior
(before my change).  Previously the algorythm was this:

        Try to open a corefile
        on failure, if isdigit(string[0])
                try to attach a pid.

So if it was really a pid, you always got an error when
it tried to open it as a corefile.  Now the algorythm is:

        if isdigit (string[0])
                try to attach a pid
                on failure, try to open a corefile
        else try to open a corefile

So the only time you will get a failure warning is
if you have a corefile whose name begins with a digit.
I think that's an improvement (warning should be less
frequent). 

> 
> I can be convinced that a digit is more likely to indicate a pid than
> a corefile, but would there be a way to make that error be silent? I
> realize that those error messages are generated in the bowels of gdb,
> and it may be really hard to fix that (gee, isn't this something the
> insight people have some opinion about? :-)
> 
> What's that bit about input-radix and output-radix?

Ummm... D'oh!  Sorry, that doesn't belong there.
Please ignore it, I'll strip it out before committing.

> 
> Elena
> 
>  > 2002-01-04  Michael Snyder  <msnyder@redhat.com>
>  >
>  >      * main.c (captured_main): Add new command line option "--pid".
>  >      If the second command line argument (following the symbol-file)
>  >      begins with a digit, try to attach to it before trying to open
>  >      it as a corefile.
>  >      (print_gdb_help): Document the "--pid" argument.
>  >
>  > Index: main.c
>  > ===================================================================
>  > RCS file: /cvs/src/src/gdb/main.c,v
>  > retrieving revision 1.14
>  > diff -c -3 -p -r1.14 main.c
>  > *** main.c   2001/11/22 00:23:12     1.14
>  > --- main.c   2002/01/05 03:15:43
>  > *************** captured_main (void *data)
>  > *** 239,244 ****
>  > --- 239,246 ----
>  >         {"e", required_argument, 0, 'e'},
>  >         {"core", required_argument, 0, 'c'},
>  >         {"c", required_argument, 0, 'c'},
>  > +       {"pid", required_argument, 0, 'p'},
>  > +       {"p", required_argument, 0, 'p'},
>  >         {"command", required_argument, 0, 'x'},
>  >         {"version", no_argument, &print_version, 1},
>  >         {"x", required_argument, 0, 'x'},
>  > *************** captured_main (void *data)
>  > *** 320,325 ****
>  > --- 322,331 ----
>  >        case 'c':
>  >          corearg = optarg;
>  >          break;
>  > +      case 'p':
>  > +        /* "corearg" is shared by "--core" and "--pid" */
>  > +        corearg = optarg;
>  > +        break;
>  >        case 'x':
>  >          cmdarg[ncmd++] = optarg;
>  >          if (ncmd >= cmdsize)
>  > *************** extern int gdbtk_test (char *);
>  > *** 463,470 ****
>  >            execarg = argv[optind];
>  >            break;
>  >          case 2:
>  > !          /* FIXME: The documentation says this can be a
>  > !             "ProcID". as well.  */
>  >            corearg = argv[optind];
>  >            break;
>  >          case 3:
>  > --- 469,476 ----
>  >            execarg = argv[optind];
>  >            break;
>  >          case 2:
>  > !          /* The documentation says this can be a "ProcID" as well.
>  > !             We will try it as both a corefile and a pid.  */
>  >            corearg = argv[optind];
>  >            break;
>  >          case 3:
>  > *************** extern int gdbtk_test (char *);
>  > *** 586,597 ****
>  >
>  >     if (corearg != NULL)
>  >       {
>  > !       if (catch_command_errors (core_file_command, corearg, !batch,
RETURN_MASK_ALL) == 0)
>  >      {
>  > !      /* See if the core file is really a PID. */
>  > !      if (isdigit (corearg[0]))
>  > !        catch_command_errors (attach_command, corearg, !batch,
RETURN_MASK_ALL);
>  >      }
>  >       }
>  >
>  >     if (ttyarg != NULL)
>  > --- 592,611 ----
>  >
>  >     if (corearg != NULL)
>  >       {
>  > !       /* corearg may be either a corefile or a pid.
>  > !     If its first character is a digit, try attach first
>  > !     and then corefile.  Otherwise try corefile first. */
>  > !
>  > !       if (isdigit (corearg[0]))
>  >      {
>  > !      if (catch_command_errors (attach_command, corearg,
>  > !                                !batch, RETURN_MASK_ALL) == 0)
>  > !        catch_command_errors (core_file_command, corearg,
>  > !                              !batch, RETURN_MASK_ALL);
>  >      }
>  > +       else /* Can't be a pid, better be a corefile. */
>  > +    catch_command_errors (core_file_command, corearg,
>  > +                          !batch, RETURN_MASK_ALL);
>  >       }
>  >
>  >     if (ttyarg != NULL)
>  > *************** extern int gdbtk_test (char *);
>  > *** 616,621 ****
>  > --- 630,646 ----
>  >      catch_command_errors (source_command, gdbinit, 0, RETURN_MASK_ALL);
>  >         }
>  >
>  > +   /* These need to be set this late in the initialization to ensure that
>  > +      they are defined for the current environment.  They define the
>  > +      radix variables needed by a save-breakpoints file to preserve the
>  > +      radix across the breakpoints restoration assuming they are restored
>  > +      using the -x (-command) command line options.  */
>  > +
>  > +   set_internalvar (lookup_internalvar ("input_radix"),
>  > +               value_from_longest (builtin_type_int, (LONGEST)
input_radix));
>  > +   set_internalvar (lookup_internalvar ("output_radix"),
>  > +               value_from_longest (builtin_type_int, (LONGEST)
output_radix));
>  > +
>  >     for (i = 0; i < ncmd; i++)
>  >       {
>  >   #if 0
>  > *************** Options:\n\n\
>  > *** 752,757 ****
>  > --- 777,783 ----
>  >     --cd=DIR           Change current directory to DIR.\n\
>  >     --command=FILE     Execute GDB commands from FILE.\n\
>  >     --core=COREFILE    Analyze the core dump COREFILE.\n\
>  > +   --pid=PID          Attach to running process PID.\n\
>  >   ", stream);
>  >     fputs_unfiltered ("\
>  >     --dbx              DBX compatibility mode.\n\


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-08  0:53                 ` Eli Zaretskii
@ 2002-01-08 15:15                   ` Michael Snyder
  0 siblings, 0 replies; 29+ messages in thread
From: Michael Snyder @ 2002-01-08 15:15 UTC (permalink / raw)
  To: gdb-patches

Eli Zaretskii wrote:
> 
> On Mon, 7 Jan 2002, Michael Snyder wrote:
> 
> > OK, how's this?
> 
> It's okay, but:
> 
> > ! @item -pid @ver{number}
>                ^^^^
> This should be @var, not @ver.

Oops, OK.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-08 15:15   ` Michael Snyder
@ 2002-01-08 16:59     ` Andrew Cagney
  2002-01-10 13:09       ` Elena Zannoni
  2002-01-10 13:13     ` Elena Zannoni
  1 sibling, 1 reply; 29+ messages in thread
From: Andrew Cagney @ 2002-01-08 16:59 UTC (permalink / raw)
  To: Michael Snyder, Elena Zannoni; +Cc: gdb-patches

> About this, I have a question, what happens if you have a corefile
>> whose name starts with a digit? I tried it and I get an error:


I suspect the best thing to do is use a similar trick as recommended by 
some RM manuals given a file called ``-rf .'' i.e.  ./1234567

enjoy,
Andrew


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-08 16:59     ` Andrew Cagney
@ 2002-01-10 13:09       ` Elena Zannoni
  2002-01-10 16:20         ` Andrew Cagney
  0 siblings, 1 reply; 29+ messages in thread
From: Elena Zannoni @ 2002-01-10 13:09 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Michael Snyder, Elena Zannoni, gdb-patches

Andrew Cagney writes:
 > > About this, I have a question, what happens if you have a corefile
 > >> whose name starts with a digit? I tried it and I get an error:
 > 
 > 
 > I suspect the best thing to do is use a similar trick as recommended by 
 > some RM manuals given a file called ``-rf .'' i.e.  ./1234567
 > 
 > enjoy,
 > Andrew


"To remove a file called `-f' in the current directory, you could type
 either rm -- -f or rm ./-f "

I assume you mean 
gdb <symbolfile> ./2222core
not
gdb <symbolfile> -- 2222core


The first works fine.
I think we should mention this case in the docs.

Elena


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-08 15:15   ` Michael Snyder
  2002-01-08 16:59     ` Andrew Cagney
@ 2002-01-10 13:13     ` Elena Zannoni
  2002-01-10 14:49       ` Michael Snyder
  2002-01-10 15:02       ` Michael Snyder
  1 sibling, 2 replies; 29+ messages in thread
From: Elena Zannoni @ 2002-01-10 13:13 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches

Michael Snyder writes:
 > Elena Zannoni wrote:
 > > 
 > > Michael Snyder writes:
 > >  >
 > >  > Currently if you invoke gdb as:
 > >  >
 > >  >      gdb filename 12345
 > >  >
 > >  > gdb will attempt to open a corefile called "12345", and if that
 > >  > fails it will print a "file not found" warning, and then attempt
 > >  > to attach to a process "12345".
 > >  >
 > >  > There is a "--core <filename>" command-line argument,
 > >  > so that you can specify a corefile without a symbol file:
 > >  >
 > >  >      gdb --core <filename>
 > >  >
 > >  > but there is no "--pid" option to allow you to specify
 > >  > a process-id without a symbol file.
 > >  >
 > >  > This patch does two things:
 > >  >
 > >  > 1) Add a "--pid" option to allow specification of an attach pid.
 > >  >
 > > 
 > > This bit is approved.
 > > 
 > >  > 2) If the second argument (after the symbol-file) begins with
 > >  > a digit, try attach first instead of trying to open it as a
 > >  > corefile first.  This eliminates the "file not found" warning.
 > >  >
 > > 
 > > About this, I have a question, what happens if you have a corefile
 > > whose name starts with a digit? I tried it and I get an error:
 > > 
 > > [ezannoni@localhost gdb]$ ./gdb -nw ./gdb 2222core
 > > GNU gdb 2002-01-03-cvs
 > > Copyright 2001 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 conditions.
 > > Type "show copying" to see the conditions.
 > > There is absolutely no warranty for GDB.  Type "show warranty" for details.
 > > This GDB was configured as "i686-pc-linux-gnu"...
 > > Attaching to program: /home/ezannoni/sources/native/gdb/gdb, process 2222
 > > ptrace: No such process.
 > > 
 > > then it proceeds normally to figure out it's a core file.
 > 
 > Right -- this is actually the reverse of the old behavior
 > (before my change).  Previously the algorythm was this:
 > 
 >         Try to open a corefile
 >         on failure, if isdigit(string[0])
 >                 try to attach a pid.
 > 
 > So if it was really a pid, you always got an error when
 > it tried to open it as a corefile.  Now the algorythm is:
 > 
 >         if isdigit (string[0])
 >                 try to attach a pid
 >                 on failure, try to open a corefile
 >         else try to open a corefile
 > 
 > So the only time you will get a failure warning is
 > if you have a corefile whose name begins with a digit.
 > I think that's an improvement (warning should be less
 > frequent). 
 > 

Yes, that's what I wanted to point out. We are swapping an error
message with another. The advantage is that the warning shouldn't come
up as often.  Can you commit this, adding the bit to the docs about
specifying './2222core' instead of '2222core'?

 > > 
 > > I can be convinced that a digit is more likely to indicate a pid than
 > > a corefile, but would there be a way to make that error be silent? I
 > > realize that those error messages are generated in the bowels of gdb,
 > > and it may be really hard to fix that (gee, isn't this something the
 > > insight people have some opinion about? :-)
 > > 

Just out of curiosity have you looked into this at all?


 > > What's that bit about input-radix and output-radix?
 > 
 > Ummm... D'oh!  Sorry, that doesn't belong there.
 > Please ignore it, I'll strip it out before committing.

Yes, ok.

Elena


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 13:13     ` Elena Zannoni
@ 2002-01-10 14:49       ` Michael Snyder
  2002-01-10 15:02       ` Michael Snyder
  1 sibling, 0 replies; 29+ messages in thread
From: Michael Snyder @ 2002-01-10 14:49 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches

Elena Zannoni wrote:
> 
> Michael Snyder writes:
>  > Elena Zannoni wrote:
>  > >
>  > > Michael Snyder writes:
>  > >  >
>  > >  > Currently if you invoke gdb as:
>  > >  >
>  > >  >      gdb filename 12345
>  > >  >
>  > >  > gdb will attempt to open a corefile called "12345", and if that
>  > >  > fails it will print a "file not found" warning, and then attempt
>  > >  > to attach to a process "12345".
>  > >  >
>  > >  > There is a "--core <filename>" command-line argument,
>  > >  > so that you can specify a corefile without a symbol file:
>  > >  >
>  > >  >      gdb --core <filename>
>  > >  >
>  > >  > but there is no "--pid" option to allow you to specify
>  > >  > a process-id without a symbol file.
>  > >  >
>  > >  > This patch does two things:
>  > >  >
>  > >  > 1) Add a "--pid" option to allow specification of an attach pid.
>  > >  >
>  > >
>  > > This bit is approved.
>  > >
>  > >  > 2) If the second argument (after the symbol-file) begins with
>  > >  > a digit, try attach first instead of trying to open it as a
>  > >  > corefile first.  This eliminates the "file not found" warning.
>  > >  >
>  > >
>  > > About this, I have a question, what happens if you have a corefile
>  > > whose name starts with a digit? I tried it and I get an error:
>  > >
>  > > [ezannoni@localhost gdb]$ ./gdb -nw ./gdb 2222core
>  > > GNU gdb 2002-01-03-cvs
>  > > Copyright 2001 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 conditions.
>  > > Type "show copying" to see the conditions.
>  > > There is absolutely no warranty for GDB.  Type "show warranty" for details.
>  > > This GDB was configured as "i686-pc-linux-gnu"...
>  > > Attaching to program: /home/ezannoni/sources/native/gdb/gdb, process 2222
>  > > ptrace: No such process.
>  > >
>  > > then it proceeds normally to figure out it's a core file.
>  >
>  > Right -- this is actually the reverse of the old behavior
>  > (before my change).  Previously the algorythm was this:
>  >
>  >         Try to open a corefile
>  >         on failure, if isdigit(string[0])
>  >                 try to attach a pid.
>  >
>  > So if it was really a pid, you always got an error when
>  > it tried to open it as a corefile.  Now the algorythm is:
>  >
>  >         if isdigit (string[0])
>  >                 try to attach a pid
>  >                 on failure, try to open a corefile
>  >         else try to open a corefile
>  >
>  > So the only time you will get a failure warning is
>  > if you have a corefile whose name begins with a digit.
>  > I think that's an improvement (warning should be less
>  > frequent).
>  >
> 
> Yes, that's what I wanted to point out. We are swapping an error
> message with another. The advantage is that the warning shouldn't come
> up as often.  Can you commit this, adding the bit to the docs about
> specifying './2222core' instead of '2222core'?

Umm, I can't think of a way to say that, without more-than-doubling
the amount of text currently devoted to the subject.  I will check
it in as is, and then we can add something about this if you wish.


>  > > I can be convinced that a digit is more likely to indicate a pid than
>  > > a corefile, but would there be a way to make that error be silent? I
>  > > realize that those error messages are generated in the bowels of gdb,
>  > > and it may be really hard to fix that (gee, isn't this something the
>  > > insight people have some opinion about? :-)
>  > >
> 
> Just out of curiosity have you looked into this at all?

No.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 13:13     ` Elena Zannoni
  2002-01-10 14:49       ` Michael Snyder
@ 2002-01-10 15:02       ` Michael Snyder
  2002-01-10 23:23         ` Eli Zaretskii
  1 sibling, 1 reply; 29+ messages in thread
From: Michael Snyder @ 2002-01-10 15:02 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 3055 bytes --]

Elena Zannoni wrote:
> 
> Michael Snyder writes:
>  > Elena Zannoni wrote:
>  > >
>  > > Michael Snyder writes:
>  > >  >
>  > >  > Currently if you invoke gdb as:
>  > >  >
>  > >  >      gdb filename 12345
>  > >  >
>  > >  > gdb will attempt to open a corefile called "12345", and if that
>  > >  > fails it will print a "file not found" warning, and then attempt
>  > >  > to attach to a process "12345".
>  > >  >
>  > >  > There is a "--core <filename>" command-line argument,
>  > >  > so that you can specify a corefile without a symbol file:
>  > >  >
>  > >  >      gdb --core <filename>
>  > >  >
>  > >  > but there is no "--pid" option to allow you to specify
>  > >  > a process-id without a symbol file.
>  > >  >
>  > >  > This patch does two things:
>  > >  >
>  > >  > 1) Add a "--pid" option to allow specification of an attach pid.
>  > >  >
>  > >
>  > > This bit is approved.
>  > >
>  > >  > 2) If the second argument (after the symbol-file) begins with
>  > >  > a digit, try attach first instead of trying to open it as a
>  > >  > corefile first.  This eliminates the "file not found" warning.
>  > >  >
>  > >
>  > > About this, I have a question, what happens if you have a corefile
>  > > whose name starts with a digit? I tried it and I get an error:
>  > >
>  > > [ezannoni@localhost gdb]$ ./gdb -nw ./gdb 2222core
>  > > GNU gdb 2002-01-03-cvs
>  > > Copyright 2001 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 conditions.
>  > > Type "show copying" to see the conditions.
>  > > There is absolutely no warranty for GDB.  Type "show warranty" for details.
>  > > This GDB was configured as "i686-pc-linux-gnu"...
>  > > Attaching to program: /home/ezannoni/sources/native/gdb/gdb, process 2222
>  > > ptrace: No such process.
>  > >
>  > > then it proceeds normally to figure out it's a core file.
>  >
>  > Right -- this is actually the reverse of the old behavior
>  > (before my change).  Previously the algorythm was this:
>  >
>  >         Try to open a corefile
>  >         on failure, if isdigit(string[0])
>  >                 try to attach a pid.
>  >
>  > So if it was really a pid, you always got an error when
>  > it tried to open it as a corefile.  Now the algorythm is:
>  >
>  >         if isdigit (string[0])
>  >                 try to attach a pid
>  >                 on failure, try to open a corefile
>  >         else try to open a corefile
>  >
>  > So the only time you will get a failure warning is
>  > if you have a corefile whose name begins with a digit.
>  > I think that's an improvement (warning should be less
>  > frequent).
>  >
> 
> Yes, that's what I wanted to point out. We are swapping an error
> message with another. The advantage is that the warning shouldn't come
> up as often.  Can you commit this, adding the bit to the docs about
> specifying './2222core' instead of '2222core'?

OK, got it, doc change attached.
This is committed.

[-- Attachment #2: attach.patch --]
[-- Type: text/plain, Size: 7284 bytes --]

2002-01-04  Michael Snyder  <msnyder@redhat.com>

	* main.c (captured_main): Add new command line option "--pid".
	If the second command line argument (following the symbol-file)
	begins with a digit, try to attach to it before trying to open
	it as a corefile.
	(print_gdb_help): Document the "--pid" argument.

2002-01-05  Michael Snyder  <msnyder@redhat.com>

	* gdb.texinfo (--pid): Document new command line option (attach).

Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.14
diff -c -3 -p -r1.14 main.c
*** main.c	2001/11/22 00:23:12	1.14
--- main.c	2002/01/05 03:15:43
*************** captured_main (void *data)
*** 239,244 ****
--- 239,246 ----
        {"e", required_argument, 0, 'e'},
        {"core", required_argument, 0, 'c'},
        {"c", required_argument, 0, 'c'},
+       {"pid", required_argument, 0, 'p'},
+       {"p", required_argument, 0, 'p'},
        {"command", required_argument, 0, 'x'},
        {"version", no_argument, &print_version, 1},
        {"x", required_argument, 0, 'x'},
*************** captured_main (void *data)
*** 320,325 ****
--- 322,331 ----
  	  case 'c':
  	    corearg = optarg;
  	    break;
+ 	  case 'p':
+ 	    /* "corearg" is shared by "--core" and "--pid" */
+ 	    corearg = optarg;
+ 	    break;
  	  case 'x':
  	    cmdarg[ncmd++] = optarg;
  	    if (ncmd >= cmdsize)
*************** extern int gdbtk_test (char *);
*** 463,470 ****
  	      execarg = argv[optind];
  	      break;
  	    case 2:
! 	      /* FIXME: The documentation says this can be a
! 		 "ProcID". as well.  */
  	      corearg = argv[optind];
  	      break;
  	    case 3:
--- 469,476 ----
  	      execarg = argv[optind];
  	      break;
  	    case 2:
! 	      /* The documentation says this can be a "ProcID" as well. 
! 	         We will try it as both a corefile and a pid.  */
  	      corearg = argv[optind];
  	      break;
  	    case 3:
*************** extern int gdbtk_test (char *);
*** 586,597 ****
  
    if (corearg != NULL)
      {
!       if (catch_command_errors (core_file_command, corearg, !batch, RETURN_MASK_ALL) == 0)
  	{
! 	  /* See if the core file is really a PID. */
! 	  if (isdigit (corearg[0]))
! 	    catch_command_errors (attach_command, corearg, !batch, RETURN_MASK_ALL);
  	}
      }
  
    if (ttyarg != NULL)
--- 592,611 ----
  
    if (corearg != NULL)
      {
!       /* corearg may be either a corefile or a pid.
! 	 If its first character is a digit, try attach first
! 	 and then corefile.  Otherwise try corefile first. */
! 
!       if (isdigit (corearg[0]))
  	{
! 	  if (catch_command_errors (attach_command, corearg, 
! 				    !batch, RETURN_MASK_ALL) == 0)
! 	    catch_command_errors (core_file_command, corearg, 
! 				  !batch, RETURN_MASK_ALL);
  	}
+       else /* Can't be a pid, better be a corefile. */
+ 	catch_command_errors (core_file_command, corearg, 
+ 			      !batch, RETURN_MASK_ALL);
      }
  
    if (ttyarg != NULL)
*************** extern int gdbtk_test (char *);
*** 616,621 ****
--- 630,646 ----
  	catch_command_errors (source_command, gdbinit, 0, RETURN_MASK_ALL);
        }
  
+   /* These need to be set this late in the initialization to ensure that
+      they are defined for the current environment.  They define the
+      radix variables needed by a save-breakpoints file to preserve the
+      radix across the breakpoints restoration assuming they are restored
+      using the -x (-command) command line options.  */
+      
+   set_internalvar (lookup_internalvar ("input_radix"),
+ 		   value_from_longest (builtin_type_int, (LONGEST) input_radix));
+   set_internalvar (lookup_internalvar ("output_radix"),
+ 		   value_from_longest (builtin_type_int, (LONGEST) output_radix));
+ 
    for (i = 0; i < ncmd; i++)
      {
  #if 0
*************** Options:\n\n\
*** 752,757 ****
--- 777,783 ----
    --cd=DIR           Change current directory to DIR.\n\
    --command=FILE     Execute GDB commands from FILE.\n\
    --core=COREFILE    Analyze the core dump COREFILE.\n\
+   --pid=PID          Attach to running process PID.\n\
  ", stream);
    fputs_unfiltered ("\
    --dbx              DBX compatibility mode.\n\
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.68
diff -c -3 -p -r1.68 gdb.texinfo
*** gdb.texinfo	2002/01/07 09:28:43	1.68
--- gdb.texinfo	2002/01/10 23:01:46
*************** in sequential order.  The order makes a 
*** 891,901 ****
  When @value{GDBN} starts, it reads any arguments other than options as
  specifying an executable file and core file (or process ID).  This is
  the same as if the arguments were specified by the @samp{-se} and
! @samp{-c} options respectively.  (@value{GDBN} reads the first argument
! that does not have an associated option flag as equivalent to the
! @samp{-se} option followed by that argument; and the second argument
! that does not have an associated option flag, if any, as equivalent to
! the @samp{-c} option followed by that argument.)
  
  If @value{GDBN} has not been configured to included core file support,
  such as for most embedded targets, then it will complain about a second
--- 891,906 ----
  When @value{GDBN} starts, it reads any arguments other than options as
  specifying an executable file and core file (or process ID).  This is
  the same as if the arguments were specified by the @samp{-se} and
! @samp{-c} (or @samp{-p} options respectively.  (@value{GDBN} reads the
! first argument that does not have an associated option flag as
! equivalent to the @samp{-se} option followed by that argument; and the
! second argument that does not have an associated option flag, if any, as
! equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
! If the second argument begins with a decimal digit, @value{GDBN} will
! first attempt to attach to it as a process, and if that fails, attempt
! to open it as a corefile.  If you have a corefile whose name begins with
! a digit, you can prevent @value{GDBN} from treating it as a pid by 
! prefixing it with @samp{"./"}, eg. @samp{"./12345"}.
  
  If @value{GDBN} has not been configured to included core file support,
  such as for most embedded targets, then it will complain about a second
*************** file.
*** 934,945 ****
  @itemx -c @var{file}
  @cindex @code{--core}
  @cindex @code{-c}
! Use file @var{file} as a core dump to examine.
  
  @item -c @var{number}
! Connect to process ID @var{number}, as with the @code{attach} command
! (unless there is a file in core-dump format named @var{number}, in which
! case @samp{-c} specifies that file as a core dump to read).
  
  @item -command @var{file}
  @itemx -x @var{file}
--- 939,954 ----
  @itemx -c @var{file}
  @cindex @code{--core}
  @cindex @code{-c}
! Use file @var{file} as a core dump to examine.  
  
  @item -c @var{number}
! @item -pid @var{number}
! @itemx -p @var{number}
! @cindex @code{--pid}
! @cindex @code{-p}
! Connect to process ID @var{number}, as with the @code{attach} command.
! If there is no such process, @value{GDBN} will attempt to open a core
! file named @var{number}.
  
  @item -command @var{file}
  @itemx -x @var{file}

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 13:09       ` Elena Zannoni
@ 2002-01-10 16:20         ` Andrew Cagney
  2002-01-10 16:46           ` Elena Zannoni
  2002-01-10 17:06           ` Michael Snyder
  0 siblings, 2 replies; 29+ messages in thread
From: Andrew Cagney @ 2002-01-10 16:20 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: Michael Snyder, Elena Zannoni, gdb-patches

> "To remove a file called `-f' in the current directory, you could type
>  either rm -- -f or rm ./-f "


``--''?  Since when was ``--'' an option to rm?  You'll be telling me 
UNIX comes with colour LS next .... :-^

Yes.  The use of ./1234 should be documented.  So should (in the NEWS 
file) the quiet switch of how <pid> vs <core> is decided.

Andrew


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 16:20         ` Andrew Cagney
@ 2002-01-10 16:46           ` Elena Zannoni
  2002-01-11  2:19             ` Richard Earnshaw
  2002-01-10 17:06           ` Michael Snyder
  1 sibling, 1 reply; 29+ messages in thread
From: Elena Zannoni @ 2002-01-10 16:46 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Elena Zannoni, Michael Snyder, Elena Zannoni, gdb-patches

Andrew Cagney writes:
 > > "To remove a file called `-f' in the current directory, you could type
 > >  either rm -- -f or rm ./-f "
 > 
 > 
 > ``--''?  Since when was ``--'' an option to rm?  You'll be telling me 
 > UNIX comes with colour LS next .... :-^
 > 

yes, true, it is in the man page for rm on RH7.1!

 > Yes.  The use of ./1234 should be documented.  So should (in the NEWS 
 > file) the quiet switch of how <pid> vs <core> is decided.
 > 

Michael added this to the doco, yes.

Elena


 > Andrew


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 16:20         ` Andrew Cagney
  2002-01-10 16:46           ` Elena Zannoni
@ 2002-01-10 17:06           ` Michael Snyder
  2002-01-10 17:28             ` Andrew Cagney
                               ` (2 more replies)
  1 sibling, 3 replies; 29+ messages in thread
From: Michael Snyder @ 2002-01-10 17:06 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 472 bytes --]

Andrew Cagney wrote:
> 
> > "To remove a file called `-f' in the current directory, you could type
> >  either rm -- -f or rm ./-f "
> 
> ``--''?  Since when was ``--'' an option to rm?  You'll be telling me
> UNIX comes with colour LS next .... :-^
> 
> Yes.  The use of ./1234 should be documented.  So should (in the NEWS
> file) the quiet switch of how <pid> vs <core> is decided.


How's this?

(I suppose next you'll be wanting something on the gcore command... <g>)

[-- Attachment #2: NEWS.patch --]
[-- Type: text/plain, Size: 1197 bytes --]

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.49
diff -c -3 -p -r1.49 NEWS
*** NEWS	2002/01/06 15:02:00	1.49
--- NEWS	2002/01/11 01:04:44
***************
*** 3,8 ****
--- 3,25 ----
  
  *** Changes since GDB 5.1:
  
+ * New command line option
+ 
+ GDB now accepts --pid or -p followed by a process id.  
+ 
+ * Change in command line behavior -- corefiles vs. process ids.
+ 
+ There is a subtle behavior in the way in which GDB handles 
+ command line arguments.  The first non-flag argument is always
+ a program to debug, but the second non-flag argument may either
+ be a corefile or a process id.  Previously, GDB would attempt to
+ open the second argument as a corefile, and if that failed, would
+ issue a superfluous error message and then attempt to attach it as
+ a process.  Now, if the second argument begins with a non-digit, 
+ it will be treated as a corefile.  If it begins with a digit, 
+ GDB will attempt to attach it as a process, and if no such process
+ is found, will then attempt to open it as a corefile.
+ 
  * New native configurations
  
  x86 OpenBSD					i[3456]86-*-openbsd*

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 17:06           ` Michael Snyder
@ 2002-01-10 17:28             ` Andrew Cagney
  2002-01-10 17:56             ` Frank Ch. Eigler
  2002-01-10 23:53             ` Eli Zaretskii
  2 siblings, 0 replies; 29+ messages in thread
From: Andrew Cagney @ 2002-01-10 17:28 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches

> Andrew Cagney wrote:
> 
>> 
> 
>> > "To remove a file called `-f' in the current directory, you could type
>> > either rm -- -f or rm ./-f "
> 
>> 
>> ``--''?  Since when was ``--'' an option to rm?  You'll be telling me
>> UNIX comes with colour LS next .... :-^
>> 
>> Yes.  The use of ./1234 should be documented.  So should (in the NEWS
>> file) the quiet switch of how <pid> vs <core> is decided.
> 
> 
> 
> How's this?


Yes! Thanks.

Andrew




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 17:06           ` Michael Snyder
  2002-01-10 17:28             ` Andrew Cagney
@ 2002-01-10 17:56             ` Frank Ch. Eigler
  2002-01-11 12:26               ` Michael Snyder
  2002-01-10 23:53             ` Eli Zaretskii
  2 siblings, 1 reply; 29+ messages in thread
From: Frank Ch. Eigler @ 2002-01-10 17:56 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches


msnyder wrote:

> [...]
> + [...]  Now, if the second argument begins with a non-digit, 
> + it will be treated as a corefile.  If it begins with a digit, 
> + GDB will attempt to attach it as a process, and if no such process
> + is found, will then attempt to open it as a corefile.
> [...]

How hard would it be to stop guessing based on isdigit(arg[0]) and
parse the whole string?  Anyway, there is only a problem here if there
are *both* an entirely-numeric core file, and an existing process with
the same id.  If not both of these hold, there is no ambiguity about
what the user means, right?

- FChE


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 15:02       ` Michael Snyder
@ 2002-01-10 23:23         ` Eli Zaretskii
  2002-01-11 12:24           ` Michael Snyder
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2002-01-10 23:23 UTC (permalink / raw)
  To: msnyder; +Cc: ezannoni, gdb-patches

> Date: Thu, 10 Jan 2002 14:57:31 -0800
> From: Michael Snyder <msnyder@redhat.com>
> 
> OK, got it, doc change attached.

The docs changes are okay, except for one minor point:

> ! prefixing it with @samp{"./"}, eg. @samp{"./12345"}.

These two @samp's should be just @file{./} and @file{./12345}.  @file
does the right markup for file names, so you don't need the quotes.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 17:06           ` Michael Snyder
  2002-01-10 17:28             ` Andrew Cagney
  2002-01-10 17:56             ` Frank Ch. Eigler
@ 2002-01-10 23:53             ` Eli Zaretskii
  2 siblings, 0 replies; 29+ messages in thread
From: Eli Zaretskii @ 2002-01-10 23:53 UTC (permalink / raw)
  To: msnyder; +Cc: ac131313, gdb-patches

> Date: Thu, 10 Jan 2002 17:01:00 -0800
> From: Michael Snyder <msnyder@redhat.com>
> > 
> > Yes.  The use of ./1234 should be documented.  So should (in the NEWS
> > file) the quiet switch of how <pid> vs <core> is decided.
> 
> How's this?

Looks good, thanks.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 16:46           ` Elena Zannoni
@ 2002-01-11  2:19             ` Richard Earnshaw
  0 siblings, 0 replies; 29+ messages in thread
From: Richard Earnshaw @ 2002-01-11  2:19 UTC (permalink / raw)
  To: Elena Zannoni
  Cc: Andrew Cagney, Michael Snyder, Elena Zannoni, gdb-patches,
	Richard.Earnshaw

> Andrew Cagney writes:
>  > > "To remove a file called `-f' in the current directory, you could type
>  > >  either rm -- -f or rm ./-f "
>  > 
>  > 
>  > ``--''?  Since when was ``--'' an option to rm?  You'll be telling me 
>  > UNIX comes with colour LS next .... :-^
>  > 
> 
> yes, true, it is in the man page for rm on RH7.1!
> 
>  > Yes.  The use of ./1234 should be documented.  So should (in the NEWS 
>  > file) the quiet switch of how <pid> vs <core> is decided.
>  > 
> 
> Michael added this to the doco, yes.
> 
> Elena
> 
> 
>  > Andrew

Solaris uses a single '-' to mark the end of the options list:

 NOTES
     A - permits the user to mark explicitly the end of any  com-
     mand  line options, allowing rm  to recognize file arguments
     that begin with a -. As an aid to BSD  migration,  rm   will
     accept  -  as a synonym for -. This migration aid may disap-
     pear in a future release. If a - and a - both appear on  the
     same command line, the second will be interpreted as a file.



^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 23:23         ` Eli Zaretskii
@ 2002-01-11 12:24           ` Michael Snyder
  0 siblings, 0 replies; 29+ messages in thread
From: Michael Snyder @ 2002-01-11 12:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ezannoni, gdb-patches

Eli Zaretskii wrote:
> 
> > Date: Thu, 10 Jan 2002 14:57:31 -0800
> > From: Michael Snyder <msnyder@redhat.com>
> >
> > OK, got it, doc change attached.
> 
> The docs changes are okay, except for one minor point:
> 
> > ! prefixing it with @samp{"./"}, eg. @samp{"./12345"}.
> 
> These two @samp's should be just @file{./} and @file{./12345}.  @file
> does the right markup for file names, so you don't need the quotes.

Thanks, corrected and committed.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [RFA] Add new cmd line parameter "--pid" for attach.
  2002-01-10 17:56             ` Frank Ch. Eigler
@ 2002-01-11 12:26               ` Michael Snyder
  0 siblings, 0 replies; 29+ messages in thread
From: Michael Snyder @ 2002-01-11 12:26 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: gdb-patches

"Frank Ch. Eigler" wrote:
> 
> msnyder wrote:
> 
> > [...]
> > + [...]  Now, if the second argument begins with a non-digit,
> > + it will be treated as a corefile.  If it begins with a digit,
> > + GDB will attempt to attach it as a process, and if no such process
> > + is found, will then attempt to open it as a corefile.
> > [...]
> 
> How hard would it be to stop guessing based on isdigit(arg[0]) and
> parse the whole string? 

Wouldn't make any difference if the whole string consists of digits, 
eg. the cannonical case of a corefile called "12345".

> Anyway, there is only a problem here if there
> are *both* an entirely-numeric core file, and an existing process with
> the same id.  If not both of these hold, there is no ambiguity about
> what the user means, right?

Right.


^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2002-01-11 20:26 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-04 19:25 [RFA] Add new cmd line parameter "--pid" for attach Michael Snyder
2002-01-05  0:59 ` Eli Zaretskii
2002-01-05 13:12   ` Michael Snyder
2002-01-06  0:04     ` Eli Zaretskii
2002-01-06 21:26       ` Michael Snyder
2002-01-07  1:20         ` Eli Zaretskii
2002-01-07 11:07           ` Michael Snyder
2002-01-07 12:28             ` Eli Zaretskii
2002-01-07 13:39               ` Michael Snyder
2002-01-07 16:14               ` Michael Snyder
2002-01-08  0:53                 ` Eli Zaretskii
2002-01-08 15:15                   ` Michael Snyder
2002-01-07 18:55 ` Elena Zannoni
2002-01-08 15:15   ` Michael Snyder
2002-01-08 16:59     ` Andrew Cagney
2002-01-10 13:09       ` Elena Zannoni
2002-01-10 16:20         ` Andrew Cagney
2002-01-10 16:46           ` Elena Zannoni
2002-01-11  2:19             ` Richard Earnshaw
2002-01-10 17:06           ` Michael Snyder
2002-01-10 17:28             ` Andrew Cagney
2002-01-10 17:56             ` Frank Ch. Eigler
2002-01-11 12:26               ` Michael Snyder
2002-01-10 23:53             ` Eli Zaretskii
2002-01-10 13:13     ` Elena Zannoni
2002-01-10 14:49       ` Michael Snyder
2002-01-10 15:02       ` Michael Snyder
2002-01-10 23:23         ` Eli Zaretskii
2002-01-11 12:24           ` Michael Snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox