From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1436 invoked by alias); 8 Jan 2002 23:15:33 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 1023 invoked by uid 22784); 8 Jan 2002 23:15:27 -0000 From: Michael Snyder Newsgroups: cygnus.patches.gdb Subject: Re: [RFA] Add new cmd line parameter "--pid" for attach. Date: Tue, 08 Jan 2002 15:15:00 -0000 Organization: Red Hat, Inc. Message-ID: <3C3B70ED.D8256B4A@redhat.com> References: <200201050321.g053L6l16505@reddwarf.cygnus.com> <15418.21637.258565.54021@localhost.cygnus.com> NNTP-Posting-Host: reddwarf.cygnus.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: cronkite.cygnus.com 1010528793 16437 205.180.231.12 (8 Jan 2002 22:26:33 GMT) X-Complaints-To: postmaster@cygnus.com NNTP-Posting-Date: 8 Jan 2002 22:26:33 GMT X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2-2smp i686) X-Accept-Language: en To: gdb-patches@sources.redhat.com DJ-Gateway: from newsgroup cygnus.patches.gdb X-SW-Source: 2002-01/txt/msg00150.txt.bz2 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 " command-line argument, > > so that you can specify a corefile without a symbol file: > > > > gdb --core > > > > 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 > > > > * 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\