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