- Fix crash on trying to load invalid executable (BZ 581215).

This commit is contained in:
Jan Kratochvil 2010-04-11 21:32:17 +00:00
parent e5a09646a4
commit 224a73ddc6
2 changed files with 32 additions and 22 deletions

View File

@ -58,10 +58,8 @@ Http://sourceware.org/ml/gdb-patches/2010-01/msg00517.html
* exec.c (exec_file_attach): Print a more useful error message if the
user did "gdb core".
Index: gdb-7.1/gdb/exceptions.h
===================================================================
--- gdb-7.1.orig/gdb/exceptions.h 2010-01-18 07:25:22.000000000 +0100
+++ gdb-7.1/gdb/exceptions.h 2010-03-25 18:40:49.000000000 +0100
--- ./gdb/exceptions.h 2010-04-11 22:31:30.000000000 +0200
+++ ./gdb/exceptions.h 2010-04-11 22:31:47.000000000 +0200
@@ -78,6 +78,9 @@ enum errors {
/* Feature is not supported in this copy of GDB. */
UNSUPPORTED_ERROR,
@ -72,10 +70,8 @@ Index: gdb-7.1/gdb/exceptions.h
/* Add more errors here. */
NR_ERRORS
};
Index: gdb-7.1/gdb/exec.c
===================================================================
--- gdb-7.1.orig/gdb/exec.c 2010-03-25 17:46:11.000000000 +0100
+++ gdb-7.1/gdb/exec.c 2010-03-25 18:41:09.000000000 +0100
--- ./gdb/exec.c 2010-04-11 22:31:30.000000000 +0200
+++ ./gdb/exec.c 2010-04-11 22:41:26.000000000 +0200
@@ -34,6 +34,7 @@
#include "arch-utils.h"
#include "gdbthread.h"
@ -84,28 +80,39 @@ Index: gdb-7.1/gdb/exec.c
#include <fcntl.h>
#include "readline/readline.h"
@@ -259,6 +260,17 @@ exec_file_attach (char *filename, int fr
/* Make sure to close exec_bfd, or else "run" might try to use
it. */
exec_close ();
@@ -256,12 +257,27 @@ exec_file_attach (char *filename, int fr
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". */
+ if (bfd_check_format (exec_bfd, bfd_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);
+
error (_("\"%s\": not in executable format: %s"),
scratch_pathname,
gdb_bfd_errmsg (bfd_get_error (), matching));
Index: gdb-7.1/gdb/main.c
===================================================================
--- gdb-7.1.orig/gdb/main.c 2010-03-25 17:46:11.000000000 +0100
+++ gdb-7.1/gdb/main.c 2010-03-25 18:40:49.000000000 +0100
+ else
+ error (_("\"%s\": not in executable format: %s"),
+ scratch_pathname,
+ gdb_bfd_errmsg (bfd_get_error (), matching));
}
/* FIXME - This should only be run for RS6000, but the ifdef is a poor
--- ./gdb/main.c 2010-04-11 22:31:30.000000000 +0200
+++ ./gdb/main.c 2010-04-11 22:31:47.000000000 +0200
@@ -241,6 +241,36 @@ captured_command_loop (void *data)
return 1;
}

View File

@ -36,7 +36,7 @@ Version: 7.1
# The release always contains a leading reserved number, start it at 1.
# `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing.
Release: 11%{?_with_upstream:.upstream}%{dist}
Release: 12%{?_with_upstream:.upstream}%{dist}
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and GFDL and BSD and Public Domain
Group: Development/Debuggers
@ -1050,6 +1050,9 @@ fi
%endif
%changelog
* Sun Apr 11 2010 Jan Kratochvil <jan.kratochvil@redhat.com> - 7.1-12.fc13
- Fix crash on trying to load invalid executable (BZ 581215).
* Thu Apr 8 2010 Jan Kratochvil <jan.kratochvil@redhat.com> - 7.1-11.fc13
- testsuite: Fix gdb.base/gstack.exp also for ppc64 inferiors (for BZ 579793).