]>
Commit | Line | Data |
---|---|---|
51a5ef0f PS |
1 | http://sourceware.org/ml/gdb-patches/2010-01/msg00558.html |
2 | Subject: Re: [patch] print a more useful error message for "gdb core" | |
3 | ||
4 | [ Fixed up since the mail. ] | |
5 | ||
6 | On 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 | ||
16 | While thinking about it overriding some GDB _commands_ was not my intention. | |
17 | ||
18 | There is a general assumption if I have a shell COMMAND and some FILE I can do | |
19 | $ COMMAND FILE | |
20 | and COMMAND will appropriately load the FILE. | |
21 | ||
22 | FSF GDB currently needs to specify also the executable file for core files | |
23 | which already inhibits this intuitive expectation. OTOH with the build-id | |
24 | locating patch which could allow such intuitive start notneeding the | |
25 | executable file. Still it currently did not work due to the required "-c": | |
26 | $ COMMAND -c COREFILE | |
27 | ||
28 | Entering "file", "core-file" or "attach" commands is already explicit enough | |
29 | so that it IMO should do what the command name says without any | |
30 | autodetections. The second command line argument | |
31 | (captured_main->pid_or_core_arg) is also autodetected (for PID or CORE) but | |
32 | neither "attach" accepts a core file nor "core-file" accepts a PID. | |
33 | ||
34 | ||
35 | The patch makes sense only with the build-id patchset so this is not submit | |
36 | for FSF GDB inclusion yet. I am fine with your patch (+/- Hui Zhu's pending | |
37 | bfd_check_format_matches) as the patch below is its natural extension. | |
38 | ||
39 | ||
40 | Sorry for the delay, | |
41 | Jan | |
42 | ||
43 | ||
44 | 2010-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 | ||
55 | Http://sourceware.org/ml/gdb-patches/2010-01/msg00517.html | |
56 | 2010-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 | ||
140f8057 | 61 | Index: gdb-7.12.50.20170226/gdb/exec.c |
51a5ef0f | 62 | =================================================================== |
140f8057 JR |
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 | |
f727df28 | 65 | @@ -35,6 +35,7 @@ |
51a5ef0f | 66 | #include "progspace.h" |
a7de96f0 | 67 | #include "gdb_bfd.h" |
f727df28 | 68 | #include "gcore.h" |
51a5ef0f PS |
69 | +#include "exceptions.h" |
70 | ||
71 | #include <fcntl.h> | |
72 | #include "readline/readline.h" | |
140f8057 | 73 | @@ -359,12 +360,27 @@ |
51a5ef0f PS |
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 | ||
321e94d6 | 103 | if (build_section_table (exec_bfd, §ions, §ions_end)) |
140f8057 | 104 | Index: gdb-7.12.50.20170226/gdb/main.c |
51a5ef0f | 105 | =================================================================== |
140f8057 JR |
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 | }; | |
51a5ef0f PS |
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 | |
b1b25d28 | 117 | +exec_or_core_file_attach (const char *filename, int from_tty) |
51a5ef0f PS |
118 | +{ |
119 | + volatile struct gdb_exception e; | |
120 | + | |
121 | + gdb_assert (exec_bfd == NULL); | |
122 | + | |
324d13e1 | 123 | + TRY |
51a5ef0f PS |
124 | + { |
125 | + exec_file_attach (filename, from_tty); | |
126 | + } | |
324d13e1 | 127 | + CATCH (e, RETURN_MASK_ALL) |
51a5ef0f PS |
128 | + { |
129 | + if (e.error == IS_CORE_ERROR) | |
130 | + { | |
b1b25d28 | 131 | + core_file_command ((char *) filename, from_tty); |
51a5ef0f PS |
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 | + } | |
324d13e1 | 140 | + END_CATCH |
51a5ef0f PS |
141 | +} |
142 | + | |
140f8057 JR |
143 | static void |
144 | captured_main_1 (struct captured_main_args *context, int &python_script) | |
51a5ef0f | 145 | { |
140f8057 | 146 | @@ -910,6 +941,8 @@ |
51a5ef0f PS |
147 | { |
148 | symarg = argv[optind]; | |
149 | execarg = argv[optind]; | |
150 | + if (optind + 1 == argc && corearg == NULL) | |
151 | + corearg = argv[optind]; | |
152 | optind++; | |
153 | } | |
154 | ||
140f8057 | 155 | @@ -1060,11 +1093,25 @@ |
51a5ef0f PS |
156 | && symarg != NULL |
157 | && strcmp (execarg, symarg) == 0) | |
158 | { | |
b1b25d28 | 159 | + catch_command_errors_const_ftype *func; |
51a5ef0f PS |
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 | |
6ed6bacf AM |
172 | open it, better only print one error message. |
173 | - catch_command_errors returns non-zero on success! */ | |
b1b25d28 | 174 | - if (catch_command_errors_const (exec_file_attach, execarg, |
324d13e1 | 175 | - !batch_flag)) |
6ed6bacf | 176 | + catch_command_errors returns non-zero on success! |
51a5ef0f PS |
177 | + Do not load EXECARG as a symbol file if it has been already processed |
178 | + as a core file. */ | |
324d13e1 | 179 | + if (catch_command_errors_const (func, execarg, !batch_flag) |
51a5ef0f | 180 | + && core_bfd == NULL) |
140f8057 | 181 | catch_command_errors_const (symbol_file_add_main_adapter, symarg, |
324d13e1 | 182 | !batch_flag); |
51a5ef0f | 183 | } |
140f8057 | 184 | Index: gdb-7.12.50.20170226/gdb/common/common-exceptions.h |
b1b25d28 | 185 | =================================================================== |
140f8057 JR |
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 @@ | |
324d13e1 JR |
189 | "_ERROR" is appended to the name. */ |
190 | MAX_COMPLETIONS_REACHED_ERROR, | |
b1b25d28 JR |
191 | |
192 | + /* Attempt to load a core file as executable. */ | |
193 | + IS_CORE_ERROR, | |
194 | + | |
195 | /* Add more errors here. */ | |
196 | NR_ERRORS | |
197 | }; |