[patch] print a more useful error message for "gdb core"

Hui Zhu teawater@gmail.com
Thu Jan 21 02:33:00 GMT 2010


Hello,

If you don't mind, I suggest change bfd_check_format to
bfd_check_format_matches like
http://sourceware.org/ml/gdb-patches/2010-01/msg00468.html

It will give user more help when he got bfd_error_file_ambiguously_recognized.

Thanks,
Hui

On Thu, Jan 21, 2010 at 08:12, Doug Evans <dje@google.com> wrote:
> On Wed, Jan 20, 2010 at 3:56 PM, Doug Evans <dje@google.com> wrote:
>> Hi.
>>
>> If the user accidentally does "gdb core" gdb currently prints:
>>
>> "/foo/bar": not in executable format: File format not recognized
>>
>> This patch prints a more useful error message for this particular case:
>>
>> "/foo/bar" is a core file.
>> Please specify an executable to debug.
>>
>> I will check this in in a few days if there are no objections.
>
> As noted in irc, the joys of working between multiple trees.
> The previous patch didn't call exec_close.
>
> Here's an updated patch.
>
> 2010-01-20  Doug Evans  <dje@google.com>
>
>        * exec.c (exec_file_attach): Print a more useful error message if the
>        user did "gdb core".
>
> Index: exec.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/exec.c,v
> retrieving revision 1.95
> diff -u -p -r1.95 exec.c
> --- exec.c      19 Jan 2010 09:47:47 -0000      1.95
> +++ exec.c      21 Jan 2010 00:10:17 -0000
> @@ -253,6 +253,18 @@ exec_file_attach (char *filename, int fr
>       scratch_pathname = xstrdup (scratch_pathname);
>       cleanups = make_cleanup (xfree, scratch_pathname);
>
> +      /* If the user accidentally did "gdb core", print a useful
> +        error message.  */
> +      if (bfd_check_format (exec_bfd, bfd_core))
> +       {
> +         /* Make sure to close exec_bfd, or else "run" might try to use
> +            it.  */
> +         exec_close ();
> +         error (_("\"%s\" is a core file.\n"
> +                  "Please specify an executable to debug."),
> +                scratch_pathname);
> +       }
> +
>       if (!bfd_check_format (exec_bfd, bfd_object))
>        {
>          /* Make sure to close exec_bfd, or else "run" might try to use
>



More information about the Gdb-patches mailing list