Re: PR13901

Tristan Gingold
2012-04-02T11:57:53Z

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);
}