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