]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-6.6-buildid-locate-core-as-arg.patch
up to 10.2
[packages/gdb.git] / gdb-6.6-buildid-locate-core-as-arg.patch
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: gdb-6.6-buildid-locate-core-as-arg.patch
5
6 ;;=push+jan
7
8 http://sourceware.org/ml/gdb-patches/2010-01/msg00558.html
9
10 [ Fixed up since the mail.  ]
11
12 On 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
22 While thinking about it overriding some GDB _commands_ was not my intention.
23
24 There is a general assumption if I have a shell COMMAND and some FILE I can do
25 $ COMMAND FILE
26 and COMMAND will appropriately load the FILE.
27
28 FSF GDB currently needs to specify also the executable file for core files
29 which already inhibits this intuitive expectation.  OTOH with the build-id
30 locating patch which could allow such intuitive start  notneeding the
31 executable file.  Still it currently did not work due to the required "-c":
32 $ COMMAND -c COREFILE
33
34 Entering "file", "core-file" or "attach" commands is already explicit enough
35 so that it IMO should do what the command name says without any
36 autodetections.  The second command line argument
37 (captured_main->pid_or_core_arg) is also autodetected (for PID or CORE) but
38 neither "attach" accepts a core file nor "core-file" accepts a PID.
39
40 The patch makes sense only with the build-id patchset so this is not submit
41 for FSF GDB inclusion yet.  I am fine with your patch (+/- Hui Zhu's pending
42 bfd_check_format_matches) as the patch below is its natural extension.
43
44 Sorry for the delay,
45 Jan
46
47 2010-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
58 Http://sourceware.org/ml/gdb-patches/2010-01/msg00517.html
59 2010-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".
63
64 diff --git a/gdb/exec.c b/gdb/exec.c
65 --- a/gdb/exec.c
66 +++ b/gdb/exec.c
67 @@ -18,6 +18,8 @@
68     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
69  
70  #include "defs.h"
71 +#include "arch-utils.h"
72 +#include "exceptions.h"
73  #include "frame.h"
74  #include "inferior.h"
75  #include "target.h"
76 @@ -495,12 +497,27 @@ exec_file_attach (const char *filename, int from_tty)
77  
78        if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
79         {
80 +         int is_core;
81 +
82 +         /* If the user accidentally did "gdb core", print a useful
83 +            error message.  Check it only after bfd_object has been checked as
84 +            a valid executable may get recognized for example also as
85 +            "trad-core".  */
86 +         is_core = bfd_check_format (exec_bfd, bfd_core);
87 +
88           /* Make sure to close exec_bfd, or else "run" might try to use
89              it.  */
90           exec_close ();
91 -         error (_("\"%ps\": not in executable format: %s"),
92 -                styled_string (file_name_style.style (), scratch_pathname),
93 -                gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
94 +
95 +         if (is_core != 0)
96 +           throw_error (IS_CORE_ERROR,
97 +                        _("\"%s\" is a core file.\n"
98 +                          "Please specify an executable to debug."),
99 +                        scratch_pathname);
100 +         else
101 +           error (_("\"%ps\": not in executable format: %s"),
102 +                  styled_string (file_name_style.style (), scratch_pathname),
103 +                  gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
104         }
105  
106        if (build_section_table (exec_bfd, &sections, &sections_end))
107 diff --git a/gdb/main.c b/gdb/main.c
108 --- a/gdb/main.c
109 +++ b/gdb/main.c
110 @@ -524,6 +524,34 @@ struct cmdarg
111    char *string;
112  };
113  
114 +/* Call exec_file_attach.  If it detected FILENAME is a core file call
115 +   core_file_command.  Print the original exec_file_attach error only if
116 +   core_file_command failed to find a matching executable.  */
117 +
118 +static void
119 +exec_or_core_file_attach (const char *filename, int from_tty)
120 +{
121 +  gdb_assert (exec_bfd == NULL);
122 +
123 +  try
124 +    {
125 +      exec_file_attach (filename, from_tty);
126 +    }
127 +  catch (gdb_exception_error &e)
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 (std::move (e));
139 +    }
140 +}
141 +
142  static void
143  captured_main_1 (struct captured_main_args *context)
144  {
145 @@ -959,6 +987,8 @@ captured_main_1 (struct captured_main_args *context)
146         {
147           symarg = argv[optind];
148           execarg = argv[optind];
149 +         if (optind + 1 == argc && corearg == NULL)
150 +           corearg = argv[optind];
151           optind++;
152         }
153  
154 @@ -1114,12 +1144,25 @@ captured_main_1 (struct captured_main_args *context)
155        && symarg != NULL
156        && strcmp (execarg, symarg) == 0)
157      {
158 +      catch_command_errors_const_ftype *func;
159 +
160 +      /* Call exec_or_core_file_attach only if the file was specified as
161 +        a command line argument (and not an a command line option).  */
162 +      if (corearg != NULL && strcmp (corearg, execarg) == 0)
163 +       {
164 +         func = exec_or_core_file_attach;
165 +         corearg = NULL;
166 +       }
167 +      else
168 +       func = exec_file_attach;
169 +
170        /* The exec file and the symbol-file are the same.  If we can't
171           open it, better only print one error message.
172 -         catch_command_errors returns non-zero on success!  */
173 -      ret = catch_command_errors (exec_file_attach, execarg,
174 -                                 !batch_flag);
175 -      if (ret != 0)
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 +      ret = catch_command_errors (func, execarg, !batch_flag);
180 +      if (ret != 0 && core_bfd == NULL)
181         ret = catch_command_errors (symbol_file_add_main_adapter,
182                                     symarg, !batch_flag);
183      }
184 diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h
185 --- a/gdbsupport/common-exceptions.h
186 +++ b/gdbsupport/common-exceptions.h
187 @@ -106,6 +106,9 @@ enum errors {
188       "_ERROR" is appended to the name.  */
189    MAX_COMPLETIONS_REACHED_ERROR,
190  
191 +  /* Attempt to load a core file as executable.  */
192 +  IS_CORE_ERROR,
193 +
194    /* Add more errors here.  */
195    NR_ERRORS
196  };
This page took 0.07591 seconds and 3 git commands to generate.