From 00546b04b221e63bf3307f5da6f2ca19c83d16ea Mon Sep 17 00:00:00 2001 From: Michael Snyder Date: Thu, 10 Jan 2002 23:03:08 +0000 Subject: [PATCH] 2002-01-10 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. --- gdb/ChangeLog | 8 ++++++++ gdb/main.c | 30 +++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b97e14d0d08..195405f1ede 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2002-01-10 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. + 2002-01-10 Eli Zaretskii * completer.c (command_completer): New function. diff --git a/gdb/main.c b/gdb/main.c index 0dbe83bccde..9b7a5f5f683 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -1,6 +1,7 @@ /* Top level stuff for GDB, the GNU debugger. Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, - 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + 1996, 1997, 1998, 1999, 2000, 2001, 2002 + Free Software Foundation, Inc. This file is part of GDB. @@ -239,6 +240,8 @@ captured_main (void *data) {"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'}, @@ -320,6 +323,10 @@ captured_main (void *data) 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) @@ -463,8 +470,8 @@ extern int gdbtk_test (char *); execarg = argv[optind]; break; case 2: - /* FIXME: The documentation says this can be a - "ProcID". as well. */ + /* 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: @@ -586,12 +593,20 @@ extern int gdbtk_test (char *); if (corearg != NULL) { - if (catch_command_errors (core_file_command, corearg, !batch, RETURN_MASK_ALL) == 0) + /* 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])) { - /* See if the core file is really a PID. */ - if (isdigit (corearg[0])) - catch_command_errors (attach_command, corearg, !batch, RETURN_MASK_ALL); + 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) @@ -752,6 +767,7 @@ Options:\n\n\ --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\ -- 2.30.2