diff -Naurp insight-7.12.50.20170416.orig/gdb/common/common-exceptions.h insight-7.12.50.20170416.new/gdb/common/common-exceptions.h
--- insight-7.12.50.20170416.orig/gdb/common/common-exceptions.h 2017-03-04 04:09:18.000000000 +0100
+++ insight-7.12.50.20170416.new/gdb/common/common-exceptions.h 2017-04-16 12:17:55.954426687 +0100
@@ -106,6 +106,9 @@ enum errors {
"_ERROR" is appended to the name. */
MAX_COMPLETIONS_REACHED_ERROR,
+ /* Attempt to load a core file as executable. */
+ IS_CORE_ERROR,
+
/* Add more errors here. */
NR_ERRORS
};
diff -Naurp insight-7.12.50.20170416.orig/gdb/exec.c insight-7.12.50.20170416.new/gdb/exec.c
--- insight-7.12.50.20170416.orig/gdb/exec.c 2017-01-21 02:32:23.000000000 +0100
+++ insight-7.12.50.20170416.new/gdb/exec.c 2017-04-16 12:17:55.952426669 +0100
@@ -35,6 +35,7 @@
#include "progspace.h"
#include "gdb_bfd.h"
#include "gcore.h"
+#include "exceptions.h"
#include <fcntl.h>
#include "readline/readline.h"
@@ -359,12 +360,27 @@ exec_file_attach (const char *filename,
if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
{
+ int is_core;
+
+ /* 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". */
+ is_core = bfd_check_format (exec_bfd, bfd_core);
+
/* 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));
}
if (build_section_table (exec_bfd, §ions, §ions_end))
diff -Naurp insight-7.12.50.20170416.orig/gdb/main.c insight-7.12.50.20170416.new/gdb/main.c
--- insight-7.12.50.20170416.orig/gdb/main.c 2017-04-16 12:16:41.229745385 +0100
+++ insight-7.12.50.20170416.new/gdb/main.c 2017-04-16 12:17:55.953426678 +0100
@@ -458,6 +458,37 @@ struct cmdarg
char *string;
};
+/* 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 (const char *filename, int from_tty)
+{
+ volatile struct gdb_exception e;
+
+ gdb_assert (exec_bfd == NULL);
+
+ TRY
+ {
+ exec_file_attach (filename, from_tty);
+ }
+ CATCH (e, RETURN_MASK_ALL)
+ {
+ if (e.error == IS_CORE_ERROR)
+ {
+ core_file_command ((char *) 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);
+ }
+ END_CATCH
+}
+
static void
captured_main_1 (struct captured_main_args *context)
{
@@ -880,6 +911,8 @@ captured_main_1 (struct captured_main_ar
{
symarg = argv[optind];
execarg = argv[optind];
+ if (optind + 1 == argc && corearg == NULL)
+ corearg = argv[optind];
optind++;
}
@@ -1030,11 +1063,25 @@ captured_main_1 (struct captured_main_ar
&& symarg != NULL
&& strcmp (execarg, symarg) == 0)
{
+ catch_command_errors_const_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
open it, better only print one error message.
- catch_command_errors returns non-zero on success! */
- if (catch_command_errors_const (exec_file_attach, execarg,
- !batch_flag))
+ catch_command_errors returns non-zero on success!
+ Do not load EXECARG as a symbol file if it has been already processed
+ as a core file. */
+ if (catch_command_errors_const (func, execarg, !batch_flag)
+ && core_bfd == NULL)
catch_command_errors_const (symbol_file_add_main_adapter, symarg,
!batch_flag);
}