- 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 * exec.c (exec_file_attach): Print a more useful error message if the
user did "gdb core". user did "gdb core".
Index: gdb-7.1/gdb/exceptions.h --- ./gdb/exceptions.h 2010-04-11 22:31:30.000000000 +0200
=================================================================== +++ ./gdb/exceptions.h 2010-04-11 22:31:47.000000000 +0200
--- 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
@@ -78,6 +78,9 @@ enum errors { @@ -78,6 +78,9 @@ enum errors {
/* Feature is not supported in this copy of GDB. */ /* Feature is not supported in this copy of GDB. */
UNSUPPORTED_ERROR, UNSUPPORTED_ERROR,
@ -72,10 +70,8 @@ Index: gdb-7.1/gdb/exceptions.h
/* Add more errors here. */ /* Add more errors here. */
NR_ERRORS NR_ERRORS
}; };
Index: gdb-7.1/gdb/exec.c --- ./gdb/exec.c 2010-04-11 22:31:30.000000000 +0200
=================================================================== +++ ./gdb/exec.c 2010-04-11 22:41:26.000000000 +0200
--- 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
@@ -34,6 +34,7 @@ @@ -34,6 +34,7 @@
#include "arch-utils.h" #include "arch-utils.h"
#include "gdbthread.h" #include "gdbthread.h"
@ -84,28 +80,39 @@ Index: gdb-7.1/gdb/exec.c
#include <fcntl.h> #include <fcntl.h>
#include "readline/readline.h" #include "readline/readline.h"
@@ -259,6 +260,17 @@ exec_file_attach (char *filename, int fr @@ -256,12 +257,27 @@ exec_file_attach (char *filename, int fr
/* Make sure to close exec_bfd, or else "run" might try to use
it. */ if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
exec_close (); {
+ int is_core;
+ +
+ /* If the user accidentally did "gdb core", print a useful + /* If the user accidentally did "gdb core", print a useful
+ error message. Check it only after bfd_object has been checked as + error message. Check it only after bfd_object has been checked as
+ a valid executable may get recognized for example also as + a valid executable may get recognized for example also as
+ "trad-core". */ + "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, + throw_error (IS_CORE_ERROR,
+ _("\"%s\" is a core file.\n" + _("\"%s\" is a core file.\n"
+ "Please specify an executable to debug."), + "Please specify an executable to debug."),
+ scratch_pathname); + scratch_pathname);
+ + else
error (_("\"%s\": not in executable format: %s"), + error (_("\"%s\": not in executable format: %s"),
scratch_pathname, + scratch_pathname,
gdb_bfd_errmsg (bfd_get_error (), matching)); + 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 /* FIXME - This should only be run for RS6000, but the ifdef is a poor
+++ gdb-7.1/gdb/main.c 2010-03-25 18:40:49.000000000 +0100 --- ./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) @@ -241,6 +241,36 @@ captured_command_loop (void *data)
return 1; return 1;
} }

View File

@ -36,7 +36,7 @@ Version: 7.1
# The release always contains a leading reserved number, start it at 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. # `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 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 Group: Development/Debuggers
@ -1050,6 +1050,9 @@ fi
%endif %endif
%changelog %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 * 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). - testsuite: Fix gdb.base/gstack.exp also for ppc64 inferiors (for BZ 579793).