From: Michael Snyder <msnyder@redhat.com>
To: Elena Zannoni <ezannoni@redhat.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFA] Add new cmd line parameter "--pid" for attach.
Date: Thu, 10 Jan 2002 15:02:00 -0000 [thread overview]
Message-ID: <3C3E1C5B.792436B4@redhat.com> (raw)
In-Reply-To: <15421.63701.263775.202282@localhost.cygnus.com>
[-- 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}
next prev parent reply other threads:[~2002-01-10 23:02 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-04 19:25 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 [this message]
2002-01-10 23:23 ` Eli Zaretskii
2002-01-11 12:24 ` Michael Snyder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3C3E1C5B.792436B4@redhat.com \
--to=msnyder@redhat.com \
--cc=ezannoni@redhat.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox