2010-01-25 17:13:16 +00:00
|
|
|
http://sourceware.org/ml/gdb-patches/2010-01/msg00558.html
|
|
|
|
Subject: Re: [patch] print a more useful error message for "gdb core"
|
|
|
|
|
|
|
|
[ Fixed up since the mail. ]
|
|
|
|
|
|
|
|
On Thu, 21 Jan 2010 18:17:15 +0100, Doug Evans wrote:
|
|
|
|
> Not an exhaustive list, but if we go down the path of converting "gdb
|
|
|
|
> corefile" to "gdb -c corefile", then we also need to think about "file
|
|
|
|
> corefile" being converted to "core corefile" [or "target core
|
|
|
|
> corefile", "core" is apparently deprecated in favor of "target core"]
|
|
|
|
> and "target exec corefile" -> "target core corefile". Presumably
|
|
|
|
> "file corefile" (and "target exec corefile") would discard the
|
|
|
|
> currently selected executable. But maybe not. Will that be confusing
|
|
|
|
> for users? I don't know.
|
|
|
|
|
|
|
|
While thinking about it overriding some GDB _commands_ was not my intention.
|
|
|
|
|
|
|
|
There is a general assumption if I have a shell COMMAND and some FILE I can do
|
|
|
|
$ COMMAND FILE
|
|
|
|
and COMMAND will appropriately load the FILE.
|
|
|
|
|
|
|
|
FSF GDB currently needs to specify also the executable file for core files
|
|
|
|
which already inhibits this intuitive expectation. OTOH with the build-id
|
|
|
|
locating patch which could allow such intuitive start notneeding the
|
|
|
|
executable file. Still it currently did not work due to the required "-c":
|
|
|
|
$ COMMAND -c COREFILE
|
|
|
|
|
|
|
|
Entering "file", "core-file" or "attach" commands is already explicit enough
|
|
|
|
so that it IMO should do what the command name says without any
|
|
|
|
autodetections. The second command line argument
|
|
|
|
(captured_main->pid_or_core_arg) is also autodetected (for PID or CORE) but
|
|
|
|
neither "attach" accepts a core file nor "core-file" accepts a PID.
|
|
|
|
|
|
|
|
|
|
|
|
The patch makes sense only with the build-id patchset so this is not submit
|
|
|
|
for FSF GDB inclusion yet. I am fine with your patch (+/- Hui Zhu's pending
|
|
|
|
bfd_check_format_matches) as the patch below is its natural extension.
|
|
|
|
|
|
|
|
|
|
|
|
Sorry for the delay,
|
|
|
|
Jan
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-25 Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
|
|
|
|
|
|
* exceptions.h (enum errors <IS_CORE_ERROR>): New.
|
|
|
|
* exec.c: Include exceptions.h.
|
|
|
|
(exec_file_attach <bfd_core>): Call throw_error (IS_CORE_ERROR, ...).
|
|
|
|
* main.c (exec_or_core_file_attach): New.
|
|
|
|
(captured_main <optind < argc>): Set also corearg.
|
|
|
|
(captured_main <strcmp (execarg, symarg) == 0>): New variable func.
|
|
|
|
Call exec_or_core_file_attach if COREARG matches EXECARG. Call
|
|
|
|
symbol_file_add_main only if CORE_BFD remained NULL.
|
|
|
|
|
|
|
|
Http://sourceware.org/ml/gdb-patches/2010-01/msg00517.html
|
|
|
|
2010-01-20 Doug Evans <dje@google.com>
|
|
|
|
|
|
|
|
* exec.c (exec_file_attach): Print a more useful error message if the
|
|
|
|
user did "gdb core".
|
|
|
|
|
2012-07-03 18:54:05 +00:00
|
|
|
Index: gdb-7.4.50.20120703/gdb/exceptions.h
|
2010-07-21 21:30:20 +00:00
|
|
|
===================================================================
|
2012-07-03 18:54:05 +00:00
|
|
|
--- gdb-7.4.50.20120703.orig/gdb/exceptions.h 2012-01-04 09:17:01.000000000 +0100
|
|
|
|
+++ gdb-7.4.50.20120703/gdb/exceptions.h 2012-07-03 17:36:27.840297264 +0200
|
2012-06-03 17:40:44 +00:00
|
|
|
@@ -86,6 +86,9 @@ enum errors {
|
2012-01-03 15:00:12 +00:00
|
|
|
/* DW_OP_GNU_entry_value resolving failed. */
|
|
|
|
NO_ENTRY_VALUE_ERROR,
|
2010-01-25 17:13:16 +00:00
|
|
|
|
|
|
|
+ /* Attempt to load a core file as executable. */
|
|
|
|
+ IS_CORE_ERROR,
|
|
|
|
+
|
|
|
|
/* Add more errors here. */
|
|
|
|
NR_ERRORS
|
|
|
|
};
|
2012-07-03 18:54:05 +00:00
|
|
|
Index: gdb-7.4.50.20120703/gdb/exec.c
|
2010-07-21 21:30:20 +00:00
|
|
|
===================================================================
|
2012-07-03 18:54:05 +00:00
|
|
|
--- gdb-7.4.50.20120703.orig/gdb/exec.c 2012-07-03 17:30:07.000000000 +0200
|
|
|
|
+++ gdb-7.4.50.20120703/gdb/exec.c 2012-07-03 17:37:27.777225175 +0200
|
|
|
|
@@ -34,6 +34,7 @@
|
2010-01-25 17:13:16 +00:00
|
|
|
#include "gdbthread.h"
|
|
|
|
#include "progspace.h"
|
2012-07-03 18:54:05 +00:00
|
|
|
#include "gdb_bfd.h"
|
2010-01-25 17:13:16 +00:00
|
|
|
+#include "exceptions.h"
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include "readline/readline.h"
|
2012-07-03 18:54:05 +00:00
|
|
|
@@ -245,12 +246,27 @@ exec_file_attach (char *filename, int fr
|
2010-07-11 18:06:33 +00:00
|
|
|
|
|
|
|
if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
|
|
|
|
{
|
|
|
|
+ int is_core;
|
2010-01-28 22:26:15 +00:00
|
|
|
+
|
|
|
|
+ /* If the user accidentally did "gdb core", print a useful
|
|
|
|
+ error message. Check it only after bfd_object has been checked as
|
|
|
|
+ a valid executable may get recognized for example also as
|
|
|
|
+ "trad-core". */
|
2010-07-11 18:06:33 +00:00
|
|
|
+ is_core = bfd_check_format (exec_bfd, bfd_core);
|
2010-01-28 22:26:15 +00:00
|
|
|
+
|
2010-07-11 18:06:33 +00:00
|
|
|
/* Make sure to close exec_bfd, or else "run" might try to use
|
|
|
|
it. */
|
|
|
|
exec_close ();
|
|
|
|
- error (_("\"%s\": not in executable format: %s"),
|
|
|
|
- scratch_pathname,
|
|
|
|
- gdb_bfd_errmsg (bfd_get_error (), matching));
|
|
|
|
+
|
|
|
|
+ if (is_core != 0)
|
|
|
|
+ throw_error (IS_CORE_ERROR,
|
|
|
|
+ _("\"%s\" is a core file.\n"
|
|
|
|
+ "Please specify an executable to debug."),
|
|
|
|
+ scratch_pathname);
|
|
|
|
+ else
|
|
|
|
+ error (_("\"%s\": not in executable format: %s"),
|
|
|
|
+ scratch_pathname,
|
|
|
|
+ gdb_bfd_errmsg (bfd_get_error (), matching));
|
2010-01-28 22:26:15 +00:00
|
|
|
}
|
2010-07-11 18:06:33 +00:00
|
|
|
|
2012-07-03 18:54:05 +00:00
|
|
|
gdb_bfd_stash_filename (exec_bfd);
|
|
|
|
Index: gdb-7.4.50.20120703/gdb/main.c
|
2010-07-21 21:30:20 +00:00
|
|
|
===================================================================
|
2012-07-03 18:54:05 +00:00
|
|
|
--- gdb-7.4.50.20120703.orig/gdb/main.c 2012-07-03 17:31:40.000000000 +0200
|
|
|
|
+++ gdb-7.4.50.20120703/gdb/main.c 2012-07-03 17:36:27.843297261 +0200
|
2012-06-03 17:40:44 +00:00
|
|
|
@@ -266,6 +266,36 @@ typedef struct cmdarg {
|
|
|
|
/* Define type VEC (cmdarg_s). */
|
|
|
|
DEF_VEC_O (cmdarg_s);
|
2010-01-25 17:13:16 +00:00
|
|
|
|
|
|
|
+/* Call exec_file_attach. If it detected FILENAME is a core file call
|
|
|
|
+ core_file_command. Print the original exec_file_attach error only if
|
|
|
|
+ core_file_command failed to find a matching executable. */
|
|
|
|
+
|
|
|
|
+static void
|
|
|
|
+exec_or_core_file_attach (char *filename, int from_tty)
|
|
|
|
+{
|
|
|
|
+ volatile struct gdb_exception e;
|
|
|
|
+
|
|
|
|
+ gdb_assert (exec_bfd == NULL);
|
|
|
|
+
|
|
|
|
+ TRY_CATCH (e, RETURN_MASK_ALL)
|
|
|
|
+ {
|
|
|
|
+ exec_file_attach (filename, from_tty);
|
|
|
|
+ }
|
|
|
|
+ if (e.reason < 0)
|
|
|
|
+ {
|
|
|
|
+ if (e.error == IS_CORE_ERROR)
|
|
|
|
+ {
|
|
|
|
+ core_file_command (filename, from_tty);
|
|
|
|
+
|
|
|
|
+ /* Iff the core file found its executable suppress the error message
|
|
|
|
+ from exec_file_attach. */
|
|
|
|
+ if (exec_bfd != NULL)
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ throw_exception (e);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static int
|
|
|
|
captured_main (void *data)
|
|
|
|
{
|
2012-06-03 17:40:44 +00:00
|
|
|
@@ -764,6 +794,8 @@ captured_main (void *data)
|
2010-01-25 17:13:16 +00:00
|
|
|
{
|
|
|
|
symarg = argv[optind];
|
|
|
|
execarg = argv[optind];
|
|
|
|
+ if (optind + 1 == argc && corearg == NULL)
|
|
|
|
+ corearg = argv[optind];
|
|
|
|
optind++;
|
|
|
|
}
|
|
|
|
|
2012-06-03 17:40:44 +00:00
|
|
|
@@ -919,11 +951,25 @@ captured_main (void *data)
|
2010-01-25 17:13:16 +00:00
|
|
|
&& symarg != NULL
|
|
|
|
&& strcmp (execarg, symarg) == 0)
|
|
|
|
{
|
|
|
|
+ catch_command_errors_ftype *func;
|
|
|
|
+
|
|
|
|
+ /* Call exec_or_core_file_attach only if the file was specified as
|
|
|
|
+ a command line argument (and not an a command line option). */
|
|
|
|
+ if (corearg != NULL && strcmp (corearg, execarg) == 0)
|
|
|
|
+ {
|
|
|
|
+ func = exec_or_core_file_attach;
|
|
|
|
+ corearg = NULL;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ func = exec_file_attach;
|
|
|
|
+
|
|
|
|
/* The exec file and the symbol-file are the same. If we can't
|
2011-01-01 00:27:30 +00:00
|
|
|
open it, better only print one error message.
|
|
|
|
- catch_command_errors returns non-zero on success! */
|
2011-01-07 08:47:27 +00:00
|
|
|
- if (catch_command_errors (exec_file_attach, execarg,
|
|
|
|
- !batch_flag, RETURN_MASK_ALL))
|
2011-01-01 00:27:30 +00:00
|
|
|
+ catch_command_errors returns non-zero on success!
|
2010-01-25 17:13:16 +00:00
|
|
|
+ Do not load EXECARG as a symbol file if it has been already processed
|
|
|
|
+ as a core file. */
|
2010-07-21 21:30:20 +00:00
|
|
|
+ if (catch_command_errors (func, execarg, !batch_flag, RETURN_MASK_ALL)
|
2010-01-25 17:13:16 +00:00
|
|
|
+ && core_bfd == NULL)
|
2011-01-07 08:47:27 +00:00
|
|
|
catch_command_errors (symbol_file_add_main, symarg,
|
|
|
|
!batch_flag, RETURN_MASK_ALL);
|
2010-01-25 17:13:16 +00:00
|
|
|
}
|