]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-6.6-buildid-locate-core-as-arg.patch
- updated (performance fixes).
[packages/gdb.git] / gdb-6.6-buildid-locate-core-as-arg.patch
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
61 Index: gdb-7.4.50.20111218/gdb/exceptions.h
62 ===================================================================
63 --- gdb-7.4.50.20111218.orig/gdb/exceptions.h   2011-10-09 21:21:38.000000000 +0200
64 +++ gdb-7.4.50.20111218/gdb/exceptions.h        2011-12-19 01:41:20.900509347 +0100
65 @@ -88,6 +88,9 @@ enum errors {
66    /* DW_OP_GNU_entry_value resolving failed.  */
67    NO_ENTRY_VALUE_ERROR,
68  
69 +  /* Attempt to load a core file as executable.  */
70 +  IS_CORE_ERROR,
71 +
72    /* Add more errors here.  */
73    NR_ERRORS
74  };
75 Index: gdb-7.4.50.20111218/gdb/exec.c
76 ===================================================================
77 --- gdb-7.4.50.20111218.orig/gdb/exec.c 2011-03-23 19:23:54.000000000 +0100
78 +++ gdb-7.4.50.20111218/gdb/exec.c      2011-12-19 01:41:04.863568846 +0100
79 @@ -35,6 +35,7 @@
80  #include "arch-utils.h"
81  #include "gdbthread.h"
82  #include "progspace.h"
83 +#include "exceptions.h"
84  
85  #include <fcntl.h>
86  #include "readline/readline.h"
87 @@ -254,12 +255,27 @@ exec_file_attach (char *filename, int fr
88  
89        if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
90         {
91 +         int is_core;
92 +
93 +         /* If the user accidentally did "gdb core", print a useful
94 +            error message.  Check it only after bfd_object has been checked as
95 +            a valid executable may get recognized for example also as
96 +            "trad-core".  */
97 +         is_core = bfd_check_format (exec_bfd, bfd_core);
98 +
99           /* Make sure to close exec_bfd, or else "run" might try to use
100              it.  */
101           exec_close ();
102 -         error (_("\"%s\": not in executable format: %s"),
103 -                scratch_pathname,
104 -                gdb_bfd_errmsg (bfd_get_error (), matching));
105 +
106 +         if (is_core != 0)
107 +           throw_error (IS_CORE_ERROR,
108 +                  _("\"%s\" is a core file.\n"
109 +                    "Please specify an executable to debug."),
110 +                  scratch_pathname);
111 +         else
112 +           error (_("\"%s\": not in executable format: %s"),
113 +                  scratch_pathname,
114 +                  gdb_bfd_errmsg (bfd_get_error (), matching));
115         }
116  
117        /* FIXME - This should only be run for RS6000, but the ifdef is a poor
118 Index: gdb-7.4.50.20111218/gdb/main.c
119 ===================================================================
120 --- gdb-7.4.50.20111218.orig/gdb/main.c 2011-12-19 00:28:01.000000000 +0100
121 +++ gdb-7.4.50.20111218/gdb/main.c      2011-12-19 01:41:04.863568846 +0100
122 @@ -248,6 +248,36 @@ captured_command_loop (void *data)
123    return 1;
124  }
125  
126 +/* Call exec_file_attach.  If it detected FILENAME is a core file call
127 +   core_file_command.  Print the original exec_file_attach error only if
128 +   core_file_command failed to find a matching executable.  */
129 +
130 +static void
131 +exec_or_core_file_attach (char *filename, int from_tty)
132 +{
133 +  volatile struct gdb_exception e;
134 +
135 +  gdb_assert (exec_bfd == NULL);
136 +
137 +  TRY_CATCH (e, RETURN_MASK_ALL)
138 +    {
139 +      exec_file_attach (filename, from_tty);
140 +    }
141 +  if (e.reason < 0)
142 +    {
143 +      if (e.error == IS_CORE_ERROR)
144 +       {
145 +         core_file_command (filename, from_tty);
146 +
147 +         /* Iff the core file found its executable suppress the error message
148 +            from exec_file_attach.  */
149 +         if (exec_bfd != NULL)
150 +           return;
151 +       }
152 +      throw_exception (e);
153 +    }
154 +}
155 +
156  static int
157  captured_main (void *data)
158  {
159 @@ -704,6 +734,8 @@ captured_main (void *data)
160         {
161           symarg = argv[optind];
162           execarg = argv[optind];
163 +         if (optind + 1 == argc && corearg == NULL)
164 +           corearg = argv[optind];
165           optind++;
166         }
167  
168 @@ -845,11 +877,25 @@ captured_main (void *data)
169        && symarg != NULL
170        && strcmp (execarg, symarg) == 0)
171      {
172 +      catch_command_errors_ftype *func;
173 +
174 +      /* Call exec_or_core_file_attach only if the file was specified as
175 +        a command line argument (and not an a command line option).  */
176 +      if (corearg != NULL && strcmp (corearg, execarg) == 0)
177 +       {
178 +         func = exec_or_core_file_attach;
179 +         corearg = NULL;
180 +       }
181 +      else
182 +       func = exec_file_attach;
183 +
184        /* The exec file and the symbol-file are the same.  If we can't
185           open it, better only print one error message.
186 -         catch_command_errors returns non-zero on success!  */
187 -      if (catch_command_errors (exec_file_attach, execarg,
188 -                               !batch_flag, RETURN_MASK_ALL))
189 +         catch_command_errors returns non-zero on success!
190 +        Do not load EXECARG as a symbol file if it has been already processed
191 +        as a core file.  */
192 +      if (catch_command_errors (func, execarg, !batch_flag, RETURN_MASK_ALL)
193 +         && core_bfd == NULL)
194         catch_command_errors (symbol_file_add_main, symarg,
195                               !batch_flag, RETURN_MASK_ALL);
196      }
This page took 0.052436 seconds and 3 git commands to generate.