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