1 http://sourceware.org/ml/gdb-patches/2010-01/msg00558.html
2 Subject: Re: [patch] print a more useful error message for "gdb core"
4 [ Fixed up since the mail. ]
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.
16 While thinking about it overriding some GDB _commands_ was not my intention.
18 There is a general assumption if I have a shell COMMAND and some FILE I can do
20 and COMMAND will appropriately load the FILE.
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":
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.
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.
44 2010-01-25 Jan Kratochvil <jan.kratochvil@redhat.com>
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.
55 Http://sourceware.org/ml/gdb-patches/2010-01/msg00517.html
56 2010-01-20 Doug Evans <dje@google.com>
58 * exec.c (exec_file_attach): Print a more useful error message if the
61 Index: 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
66 #include "progspace.h"
69 +#include "exceptions.h"
72 #include "readline/readline.h"
75 if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
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
83 + is_core = bfd_check_format (exec_bfd, bfd_core);
85 /* Make sure to close exec_bfd, or else "run" might try to use
88 - error (_("\"%s\": not in executable format: %s"),
90 - gdb_bfd_errmsg (bfd_get_error (), matching));
93 + throw_error (IS_CORE_ERROR,
94 + _("\"%s\" is a core file.\n"
95 + "Please specify an executable to debug."),
98 + error (_("\"%s\": not in executable format: %s"),
100 + gdb_bfd_errmsg (bfd_get_error (), matching));
103 if (build_section_table (exec_bfd, §ions, §ions_end))
104 Index: 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
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. */
117 +exec_or_core_file_attach (const char *filename, int from_tty)
119 + volatile struct gdb_exception e;
121 + gdb_assert (exec_bfd == NULL);
125 + exec_file_attach (filename, from_tty);
127 + CATCH (e, RETURN_MASK_ALL)
129 + if (e.error == IS_CORE_ERROR)
131 + core_file_command ((char *) filename, from_tty);
133 + /* Iff the core file found its executable suppress the error message
134 + from exec_file_attach. */
135 + if (exec_bfd != NULL)
138 + throw_exception (e);
144 captured_main_1 (struct captured_main_args *context, int &python_script)
148 symarg = argv[optind];
149 execarg = argv[optind];
150 + if (optind + 1 == argc && corearg == NULL)
151 + corearg = argv[optind];
155 @@ -1060,11 +1093,25 @@
157 && strcmp (execarg, symarg) == 0)
159 + catch_command_errors_const_ftype *func;
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)
165 + func = exec_or_core_file_attach;
169 + func = exec_file_attach;
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,
176 + catch_command_errors returns non-zero on success!
177 + Do not load EXECARG as a symbol file if it has been already processed
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,
184 Index: 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
189 "_ERROR" is appended to the name. */
190 MAX_COMPLETIONS_REACHED_ERROR,
192 + /* Attempt to load a core file as executable. */
195 /* Add more errors here. */