]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.6-buildid-locate-core-as-arg.patch
- release 4 (by relup.sh)
[packages/gdb.git] / gdb-6.6-buildid-locate-core-as-arg.patch
CommitLineData
4b0e5c1b
AM
1From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2From: Fedora GDB patches <invalid@email.com>
3Date: Fri, 27 Oct 2017 21:07:50 +0200
ed003b1c 4Subject: gdb-6.6-buildid-locate-core-as-arg.patch
4b0e5c1b
AM
5
6;;=push+jan
7
51a5ef0f 8http://sourceware.org/ml/gdb-patches/2010-01/msg00558.html
51a5ef0f
PS
9
10[ Fixed up since the mail. ]
11
12On Thu, 21 Jan 2010 18:17:15 +0100, Doug Evans wrote:
13> Not an exhaustive list, but if we go down the path of converting "gdb
14> corefile" to "gdb -c corefile", then we also need to think about "file
15> corefile" being converted to "core corefile" [or "target core
16> corefile", "core" is apparently deprecated in favor of "target core"]
17> and "target exec corefile" -> "target core corefile". Presumably
18> "file corefile" (and "target exec corefile") would discard the
19> currently selected executable. But maybe not. Will that be confusing
20> for users? I don't know.
21
22While thinking about it overriding some GDB _commands_ was not my intention.
23
24There is a general assumption if I have a shell COMMAND and some FILE I can do
25$ COMMAND FILE
26and COMMAND will appropriately load the FILE.
27
28FSF GDB currently needs to specify also the executable file for core files
29which already inhibits this intuitive expectation. OTOH with the build-id
30locating patch which could allow such intuitive start notneeding the
31executable file. Still it currently did not work due to the required "-c":
32$ COMMAND -c COREFILE
33
34Entering "file", "core-file" or "attach" commands is already explicit enough
35so that it IMO should do what the command name says without any
36autodetections. The second command line argument
37(captured_main->pid_or_core_arg) is also autodetected (for PID or CORE) but
38neither "attach" accepts a core file nor "core-file" accepts a PID.
39
51a5ef0f
PS
40The patch makes sense only with the build-id patchset so this is not submit
41for FSF GDB inclusion yet. I am fine with your patch (+/- Hui Zhu's pending
42bfd_check_format_matches) as the patch below is its natural extension.
43
51a5ef0f
PS
44Sorry for the delay,
45Jan
46
51a5ef0f
PS
472010-01-25 Jan Kratochvil <jan.kratochvil@redhat.com>
48
49 * exceptions.h (enum errors <IS_CORE_ERROR>): New.
50 * exec.c: Include exceptions.h.
51 (exec_file_attach <bfd_core>): Call throw_error (IS_CORE_ERROR, ...).
52 * main.c (exec_or_core_file_attach): New.
53 (captured_main <optind < argc>): Set also corearg.
54 (captured_main <strcmp (execarg, symarg) == 0>): New variable func.
55 Call exec_or_core_file_attach if COREARG matches EXECARG. Call
56 symbol_file_add_main only if CORE_BFD remained NULL.
57
58Http://sourceware.org/ml/gdb-patches/2010-01/msg00517.html
592010-01-20 Doug Evans <dje@google.com>
60
61 * exec.c (exec_file_attach): Print a more useful error message if the
62 user did "gdb core".
4b0e5c1b
AM
63
64diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
4b0e5c1b
AM
65--- a/gdb/common/common-exceptions.h
66+++ b/gdb/common/common-exceptions.h
67@@ -104,6 +104,9 @@ enum errors {
68 "_ERROR" is appended to the name. */
69 MAX_COMPLETIONS_REACHED_ERROR,
70
71+ /* Attempt to load a core file as executable. */
72+ IS_CORE_ERROR,
73+
74 /* Add more errors here. */
75 NR_ERRORS
76 };
77diff --git a/gdb/exec.c b/gdb/exec.c
4b0e5c1b
AM
78--- a/gdb/exec.c
79+++ b/gdb/exec.c
ed003b1c 80@@ -36,6 +36,7 @@
a7de96f0 81 #include "gdb_bfd.h"
f727df28 82 #include "gcore.h"
ed003b1c 83 #include "source.h"
51a5ef0f
PS
84+#include "exceptions.h"
85
86 #include <fcntl.h>
87 #include "readline/readline.h"
ed003b1c 88@@ -357,12 +358,27 @@ exec_file_attach (const char *filename, int from_tty)
51a5ef0f
PS
89
90 if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
91 {
92+ int is_core;
93+
94+ /* If the user accidentally did "gdb core", print a useful
95+ error message. Check it only after bfd_object has been checked as
96+ a valid executable may get recognized for example also as
97+ "trad-core". */
98+ is_core = bfd_check_format (exec_bfd, bfd_core);
99+
100 /* Make sure to close exec_bfd, or else "run" might try to use
101 it. */
102 exec_close ();
103- error (_("\"%s\": not in executable format: %s"),
104- scratch_pathname,
105- gdb_bfd_errmsg (bfd_get_error (), matching));
106+
107+ if (is_core != 0)
108+ throw_error (IS_CORE_ERROR,
109+ _("\"%s\" is a core file.\n"
110+ "Please specify an executable to debug."),
111+ scratch_pathname);
112+ else
113+ error (_("\"%s\": not in executable format: %s"),
114+ scratch_pathname,
115+ gdb_bfd_errmsg (bfd_get_error (), matching));
116 }
117
321e94d6 118 if (build_section_table (exec_bfd, &sections, &sections_end))
4b0e5c1b 119diff --git a/gdb/main.c b/gdb/main.c
4b0e5c1b
AM
120--- a/gdb/main.c
121+++ b/gdb/main.c
ed003b1c 122@@ -447,6 +447,37 @@ struct cmdarg
140f8057
JR
123 char *string;
124 };
51a5ef0f
PS
125
126+/* Call exec_file_attach. If it detected FILENAME is a core file call
127+ core_file_command. Print the original exec_file_attach error only if
128+ core_file_command failed to find a matching executable. */
129+
130+static void
b1b25d28 131+exec_or_core_file_attach (const char *filename, int from_tty)
51a5ef0f
PS
132+{
133+ volatile struct gdb_exception e;
134+
135+ gdb_assert (exec_bfd == NULL);
136+
324d13e1 137+ TRY
51a5ef0f
PS
138+ {
139+ exec_file_attach (filename, from_tty);
140+ }
324d13e1 141+ CATCH (e, RETURN_MASK_ALL)
51a5ef0f
PS
142+ {
143+ if (e.error == IS_CORE_ERROR)
144+ {
b1b25d28 145+ core_file_command ((char *) filename, from_tty);
51a5ef0f
PS
146+
147+ /* Iff the core file found its executable suppress the error message
148+ from exec_file_attach. */
149+ if (exec_bfd != NULL)
150+ return;
151+ }
152+ throw_exception (e);
153+ }
324d13e1 154+ END_CATCH
51a5ef0f
PS
155+}
156+
140f8057 157 static void
4b0e5c1b 158 captured_main_1 (struct captured_main_args *context)
51a5ef0f 159 {
ed003b1c 160@@ -883,6 +914,8 @@ captured_main_1 (struct captured_main_args *context)
51a5ef0f
PS
161 {
162 symarg = argv[optind];
163 execarg = argv[optind];
164+ if (optind + 1 == argc && corearg == NULL)
165+ corearg = argv[optind];
166 optind++;
167 }
168
ed003b1c 169@@ -1033,11 +1066,25 @@ captured_main_1 (struct captured_main_args *context)
51a5ef0f
PS
170 && symarg != NULL
171 && strcmp (execarg, symarg) == 0)
172 {
b1b25d28 173+ catch_command_errors_const_ftype *func;
51a5ef0f
PS
174+
175+ /* Call exec_or_core_file_attach only if the file was specified as
176+ a command line argument (and not an a command line option). */
177+ if (corearg != NULL && strcmp (corearg, execarg) == 0)
178+ {
179+ func = exec_or_core_file_attach;
180+ corearg = NULL;
181+ }
182+ else
183+ func = exec_file_attach;
184+
185 /* The exec file and the symbol-file are the same. If we can't
6ed6bacf
AM
186 open it, better only print one error message.
187- catch_command_errors returns non-zero on success! */
4b0e5c1b
AM
188- if (catch_command_errors (exec_file_attach, execarg,
189- !batch_flag))
6ed6bacf 190+ catch_command_errors returns non-zero on success!
51a5ef0f
PS
191+ Do not load EXECARG as a symbol file if it has been already processed
192+ as a core file. */
4b0e5c1b 193+ if (catch_command_errors (func, execarg, !batch_flag)
51a5ef0f 194+ && core_bfd == NULL)
4b0e5c1b
AM
195 catch_command_errors (symbol_file_add_main_adapter, symarg,
196 !batch_flag);
51a5ef0f 197 }
This page took 0.080355 seconds and 4 git commands to generate.