public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Tristan Gingold <gingold@adacore.com>
To: Jack Howarth <howarth@bromo.med.uc.edu>
Cc: gdb@sourceware.org
Subject: Re: PR13901
Date: Mon, 02 Apr 2012 13:22:00 -0000	[thread overview]
Message-ID: <EFC4BDD1-BEE8-49A0-BF48-3E753AC8D628@adacore.com> (raw)
In-Reply-To: <20120402131715.GA30548@bromo.med.uc.edu>


On Apr 2, 2012, at 3:17 PM, Jack Howarth wrote:

> On Mon, Apr 02, 2012 at 01:57:31PM +0200, Tristan Gingold wrote:
>> 
>> On Apr 2, 2012, at 12:44 PM, Tristan Gingold wrote:
>> 
>>> 
>>> On Mar 30, 2012, at 3:42 PM, Jack Howarth wrote:
>>> 
>>>> Tristan,
>>>> Have you noticed that recent FSF gdb releases including 7.4 have been
>>>> non-functional when built targeting i386-apple-darwin? The run-time failures
>>>> have changed between 7.2 and 7.4. Currently the failure is exhibited as
>>>> errors of the form...
>>>> 
>>>> (gdb) break main
>>>> Breakpoint 1 at 0xd80: file himenoBMTxpa.c, line 71.
>>>> (gdb) r
>>>> Starting program: /Users/howarth/a.out 
>>>> darwin_set_sstep: unknown flavour: 4
>>>> Error calling thread_get_state for GP registers for thread 0x8451lxwarning:
>>>> Mach error at "i386-darwin-nat.c:118" in function
>>>> "i386_darwin_fetch_inferior_registers": (os/kern) invalid argument (0x4)
>>>> 
>>>> http://sourceware.org/bugzilla/show_bug.cgi?id=13901
>>>> 
>>>> Is this something that is trivial to fix? It would be nice if both MacPorts
>>>> and fink could have a functional i386 build of FSF gdb. In fink, we currently
>>>> have gdb restricted to x86_64 fink (although the x86_64-apple-darwin build
>>>> can debug i386 binaries fine). MacPorts has left their gdb pacakge at 7.1
>>>> (which I guess is that last version that worked for both i386-apple-darwin
>>>> and x86_64-apple-darwin. Thanks in advance for any clarifications.
>>> 
>>> I now understand the issue:
>>> 
>>> gdb spawns bash to run the program, but the bash spawned is 64 bits, which is not understood by gdb...
>> 
>> Fixed by this patch (committed on trunk):
>> 
>> 2012-04-02  Tristan Gingold  <gingold@adacore.com>
>> 
>> 	PR gdb/13901
>> 	* darwin-nat.c (darwin_execvp): Sey binary preference.
>> 
>> Index: darwin-nat.c
>> ===================================================================
>> RCS file: /cvs/src/src/gdb/darwin-nat.c,v
>> retrieving revision 1.31
>> diff -c -r1.31 darwin-nat.c
>> *** darwin-nat.c	14 Mar 2012 01:46:59 -0000	1.31
>> --- darwin-nat.c	2 Apr 2012 11:55:36 -0000
>> ***************
>> *** 39,44 ****
>> --- 39,45 ----
>>  #include "value.h"
>>  #include "arch-utils.h"
>>  #include "bfd.h"
>> + #include "bfd/mach-o.h"
>> 
>>  #include <sys/ptrace.h>
>>  #include <sys/signal.h>
>> ***************
>> *** 1538,1543 ****
>> --- 1539,1560 ----
>>        return;
>>      }
>> 
>> +   /* Specify the same binary preference to spawn the shell as the
>> +      exec binary.  This avoids spawning a 64bit shell while debugging
>> +      a 32bit program, which may confuse gdb.
>> +      Also, this slightly breaks internal layers as we suppose the binary
>> +      is Mach-O.  Doesn't harm in practice.  */
>> +   if (exec_bfd != NULL)
>> +     {
>> +       cpu_type_t pref;
>> +       size_t ocount;
>> + 
>> +       pref = bfd_mach_o_get_data (exec_bfd)->header.cputype;
>> +       res = posix_spawnattr_setbinpref_np (&attr, 1, &pref, &ocount);
>> +       if (res != 0 || ocount != 1)
>> + 	fprintf_unfiltered (gdb_stderr, "Cannot set posix_spawn binpref\n");
>> +     }
>> + 
>>    posix_spawnp (NULL, argv[0], NULL, &attr, argv, env);
>>  }
>> 
> 
> Tristan,
>   This almost fixes the bug for the i386-apple-darwin10 build. However, while this
> eliminates the failures when debugging i386 executables in the i386 darwin build of gdb 7.4,
> it still results in the following failure when debugging x86_64 executables in the
> same i386 darwin build of gdb...

I replied in bugzilla.  You simply need to configure with --enable-64-bit-bfd to enable the support of 64 bit executables.

Tristan.

> 
> % clang -arch x86_64 -g himenoBMTxpa.c
> % file ./a.out
> ./a.out: Mach-O 64-bit executable x86_64
> % fsf-gdb ./a.out
> GNU gdb (GDB) 7.4
> Copyright (C) 2012 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> and "show warranty" for details.
> This GDB was configured as "i386-apple-darwin10.8.0".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>...
> 
> warning: A handler for the OS ABI "Darwin" is not built into this configuration
> of GDB.  Attempting to continue with the default i386:x86-64 settings.
> 
> Reading symbols from /Users/howarth/a.out...Reading symbols from
> /Users/howarth/a.out.dSYM/Contents/Resources/DWARF/a.out...done.
> done.
> (gdb) break main
> Breakpoint 1 at 0xd80: file himenoBMTxpa.c, line 71.
> (gdb) r
> Starting program: /Users/howarth/a.out 
> darwin_set_sstep: unknown flavour: 4
> Error calling thread_get_state for GP registers for thread 0x5379lxwarning:
> Mach error at "i386-darwin-nat.c:118" in function
> "i386_darwin_fetch_inferior_registers": (os/kern) invalid argument (0x4)
> (gdb)
> 
> Thanks for your efforts in fixing this.
>            Jack

  reply	other threads:[~2012-04-02 13:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-30 13:42 PR13901 Jack Howarth
2012-03-30 14:19 ` PR13901 Tristan Gingold
2012-04-02 10:44 ` PR13901 Tristan Gingold
2012-04-02 11:57   ` PR13901 Tristan Gingold
2012-04-02 13:17     ` PR13901 Jack Howarth
2012-04-02 13:22       ` Tristan Gingold [this message]
2012-04-02 13:56     ` PR13901 Pedro Alves
2012-04-02 14:07       ` PR13901 Tristan Gingold
2012-04-02 14:17         ` PR13901 Pedro Alves
2012-04-02 14:25           ` PR13901 Tristan Gingold
2012-04-02 14:59           ` PR13901 Andreas Schwab
2012-04-02 15:08             ` PR13901 Tristan Gingold
2012-04-02 15:23             ` PR13901 Pedro Alves
2012-04-02 16:22               ` PR13901 Andreas Schwab
2012-04-02 16:31                 ` PR13901 Pedro Alves
2012-04-02 17:28                   ` PR13901 Andreas Schwab
2012-04-03  7:28       ` PR13901 John Gilmore
2012-04-04 14:23         ` PR13901 Pedro Alves
2012-04-04 14:47           ` PR13901 Tristan Gingold
2012-04-04 15:01             ` PR13901 Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EFC4BDD1-BEE8-49A0-BF48-3E753AC8D628@adacore.com \
    --to=gingold@adacore.com \
    --cc=gdb@sourceware.org \
    --cc=howarth@bromo.med.uc.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).