Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* How to configure gdb to support '--arch=i386' on Mac OS X
@ 2009-10-07 18:09 n179911
  2009-10-07 18:32 ` Joel Brobecker
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: n179911 @ 2009-10-07 18:09 UTC (permalink / raw)
  To: gdb

Hi,

I have compiled gdb 7.0 on Mac OS X. And I have configured XCode to
use this new version of gdb 7.0.

But when I start debug my XCode project it said gdb can't recognize
the option '--arch=i386'. Here is the log of my error:

[Session started at 2009-10-07 11:00:43 -0700.]
/Users/n179911/bin/gdb/bin/gdb: unrecognized option `--arch=i386'
Use `/Users/n179911/bin/gdb/bin/gdb --help' for a complete list of options.

The Debugger has exited with status 1.The Debugger has exited with status

Can you please tell me how to build gdb to support '--arch-i386' option?

Thank you.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 18:09 How to configure gdb to support '--arch=i386' on Mac OS X n179911
@ 2009-10-07 18:32 ` Joel Brobecker
  2009-10-07 18:35 ` Michael Snyder
  2009-10-07 20:45 ` Jack Howarth
  2 siblings, 0 replies; 18+ messages in thread
From: Joel Brobecker @ 2009-10-07 18:32 UTC (permalink / raw)
  To: n179911; +Cc: gdb

> I have compiled gdb 7.0 on Mac OS X. And I have configured XCode to
> use this new version of gdb 7.0.
> 
> But when I start debug my XCode project it said gdb can't recognize
> the option '--arch=i386'. Here is the log of my error:

I suspect your Xcode is thinking it is running Apple's version of GDB,
and is trying to tell GDB which arch to select when your binary is
bi-arch. If you want to use the FSF GDB, you might have some luck
adding that command line switch and ignoring it. See gdb/main.c.

-- 
Joel


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 18:09 How to configure gdb to support '--arch=i386' on Mac OS X n179911
  2009-10-07 18:32 ` Joel Brobecker
@ 2009-10-07 18:35 ` Michael Snyder
  2009-10-07 20:10   ` n179911
  2009-10-07 20:45 ` Jack Howarth
  2 siblings, 1 reply; 18+ messages in thread
From: Michael Snyder @ 2009-10-07 18:35 UTC (permalink / raw)
  To: n179911; +Cc: gdb

n179911 wrote:
> Hi,
> 
> I have compiled gdb 7.0 on Mac OS X. And I have configured XCode to
> use this new version of gdb 7.0.
> 
> But when I start debug my XCode project it said gdb can't recognize
> the option '--arch=i386'. Here is the log of my error:
> 
> [Session started at 2009-10-07 11:00:43 -0700.]
> /Users/n179911/bin/gdb/bin/gdb: unrecognized option `--arch=i386'
> Use `/Users/n179911/bin/gdb/bin/gdb --help' for a complete list of options.
> 
> The Debugger has exited with status 1.The Debugger has exited with status
> 
> Can you please tell me how to build gdb to support '--arch-i386' option?

I don't think this has ever been a command line option in fsf gdb.
Maybe it is one that was added to Apple's version of gdb.

Try running `/Users/n179911/bin/gdb/bin/gdb --help', and
then run the same command using your installed gdb that came
with Mac OS.  My guess is that the Mac version will list
"--arch" among the command line options, but the fsf version
will not (mine doesn't).


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 18:35 ` Michael Snyder
@ 2009-10-07 20:10   ` n179911
  2009-10-07 20:20     ` Daniel Jacobowitz
                       ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: n179911 @ 2009-10-07 20:10 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb

Thank you. You are right.

The gdb comes with apple has '-arch'  option, but gdb 7.0 does not.

 $ /usr/bin/gdb --help
  --translate        Debug applications running under translation.
  -arch i386|armv6|x86_64|ppc     Specify a gdb targetting a specific
architecture

So should I do what Joel Brobecker suggested in adding that option in
gdb/main.c?

Thank you.


On Wed, Oct 7, 2009 at 11:31 AM, Michael Snyder <msnyder@vmware.com> wrote:
> n179911 wrote:
>>
>> Hi,
>>
>> I have compiled gdb 7.0 on Mac OS X. And I have configured XCode to
>> use this new version of gdb 7.0.
>>
>> But when I start debug my XCode project it said gdb can't recognize
>> the option '--arch=i386'. Here is the log of my error:
>>
>> [Session started at 2009-10-07 11:00:43 -0700.]
>> /Users/n179911/bin/gdb/bin/gdb: unrecognized option `--arch=i386'
>> Use `/Users/n179911/bin/gdb/bin/gdb --help' for a complete list of
>> options.
>>
>> The Debugger has exited with status 1.The Debugger has exited with status
>>
>> Can you please tell me how to build gdb to support '--arch-i386' option?
>
> I don't think this has ever been a command line option in fsf gdb.
> Maybe it is one that was added to Apple's version of gdb.
>
> Try running `/Users/n179911/bin/gdb/bin/gdb --help', and
> then run the same command using your installed gdb that came
> with Mac OS.  My guess is that the Mac version will list
> "--arch" among the command line options, but the fsf version
> will not (mine doesn't).
>
>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 20:10   ` n179911
@ 2009-10-07 20:20     ` Daniel Jacobowitz
  2009-10-07 20:21       ` n179911
  2009-10-07 20:26     ` n179911
  2009-10-07 21:04     ` Michael Snyder
  2 siblings, 1 reply; 18+ messages in thread
From: Daniel Jacobowitz @ 2009-10-07 20:20 UTC (permalink / raw)
  To: n179911; +Cc: Michael Snyder, gdb

On Wed, Oct 07, 2009 at 01:10:00PM -0700, n179911 wrote:
> Thank you. You are right.
> 
> The gdb comes with apple has '-arch'  option, but gdb 7.0 does not.
> 
>  $ /usr/bin/gdb --help
>   --translate        Debug applications running under translation.
>   -arch i386|armv6|x86_64|ppc     Specify a gdb targetting a specific
> architecture
> 
> So should I do what Joel Brobecker suggested in adding that option in
> gdb/main.c?

That is very unlikely to help.  Last I looked, you can't use the FSF
GDB with Xcode; Apple has made too many changes to their version.


-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 20:20     ` Daniel Jacobowitz
@ 2009-10-07 20:21       ` n179911
  2009-10-07 21:16         ` Stan Shebs
  0 siblings, 1 reply; 18+ messages in thread
From: n179911 @ 2009-10-07 20:21 UTC (permalink / raw)
  To: n179911, Michael Snyder, gdb

From

http://developer.apple.com/mac/library/documentation/DeveloperTools/Reference/XcodeUserDefaultRef/100-Xcode_User_Defaults/UserDefaultRef.html#//apple%5Fref/doc/uid/TP40005535-CH3-SW54

it mentions I can switch a different GDB in xcode.

On Wed, Oct 7, 2009 at 1:19 PM, Daniel Jacobowitz <drow@false.org> wrote:
> On Wed, Oct 07, 2009 at 01:10:00PM -0700, n179911 wrote:
>> Thank you. You are right.
>>
>> The gdb comes with apple has '-arch'  option, but gdb 7.0 does not.
>>
>>  $ /usr/bin/gdb --help
>>   --translate        Debug applications running under translation.
>>   -arch i386|armv6|x86_64|ppc     Specify a gdb targetting a specific
>> architecture
>>
>> So should I do what Joel Brobecker suggested in adding that option in
>> gdb/main.c?
>
> That is very unlikely to help.  Last I looked, you can't use the FSF
> GDB with Xcode; Apple has made too many changes to their version.
>
>
> --
> Daniel Jacobowitz
> CodeSourcery
>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 20:10   ` n179911
  2009-10-07 20:20     ` Daniel Jacobowitz
@ 2009-10-07 20:26     ` n179911
  2009-10-07 20:38       ` Matt Rice
  2009-10-07 21:07       ` Michael Snyder
  2009-10-07 21:04     ` Michael Snyder
  2 siblings, 2 replies; 18+ messages in thread
From: n179911 @ 2009-10-07 20:26 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb

I tried Joel Brobecker suggested in adding that option in gdb/main.c.

But my program still won't come up in my debugger.

[Session started at 2009-10-07 13:27:16 -0700.]
GNU gdb (GDB) 7.0
Copyright (C) 2009 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-darwin9.7.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Loading program into debugger…
No symbol table is loaded.  Use the "file" command.
No symbol table is loaded.  Use the "file" command.
No symbol table is loaded.  Use the "file" command.
No symbol table is loaded.  Use the "file" command.
Program loaded.
tty /dev/ttys008
(gdb) run
=thread-group-created,id="81191"
=thread-created,id="1",group-id="81191"



On Wed, Oct 7, 2009 at 1:10 PM, n179911 <n179911@gmail.com> wrote:
> Thank you. You are right.
>
> The gdb comes with apple has '-arch'  option, but gdb 7.0 does not.
>
>  $ /usr/bin/gdb --help
>  --translate        Debug applications running under translation.
>  -arch i386|armv6|x86_64|ppc     Specify a gdb targetting a specific
> architecture
>
> So should I do what Joel Brobecker suggested in adding that option in
> gdb/main.c?
>
> Thank you.
>
>
> On Wed, Oct 7, 2009 at 11:31 AM, Michael Snyder <msnyder@vmware.com> wrote:
>> n179911 wrote:
>>>
>>> Hi,
>>>
>>> I have compiled gdb 7.0 on Mac OS X. And I have configured XCode to
>>> use this new version of gdb 7.0.
>>>
>>> But when I start debug my XCode project it said gdb can't recognize
>>> the option '--arch=i386'. Here is the log of my error:
>>>
>>> [Session started at 2009-10-07 11:00:43 -0700.]
>>> /Users/n179911/bin/gdb/bin/gdb: unrecognized option `--arch=i386'
>>> Use `/Users/n179911/bin/gdb/bin/gdb --help' for a complete list of
>>> options.
>>>
>>> The Debugger has exited with status 1.The Debugger has exited with status
>>>
>>> Can you please tell me how to build gdb to support '--arch-i386' option?
>>
>> I don't think this has ever been a command line option in fsf gdb.
>> Maybe it is one that was added to Apple's version of gdb.
>>
>> Try running `/Users/n179911/bin/gdb/bin/gdb --help', and
>> then run the same command using your installed gdb that came
>> with Mac OS.  My guess is that the Mac version will list
>> "--arch" among the command line options, but the fsf version
>> will not (mine doesn't).
>>
>>
>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 20:26     ` n179911
@ 2009-10-07 20:38       ` Matt Rice
  2009-10-07 21:07       ` Michael Snyder
  1 sibling, 0 replies; 18+ messages in thread
From: Matt Rice @ 2009-10-07 20:38 UTC (permalink / raw)
  To: n179911; +Cc: Michael Snyder, gdb

On Wed, Oct 7, 2009 at 1:26 PM, n179911 <n179911@gmail.com> wrote:
> I tried Joel Brobecker suggested in adding that option in gdb/main.c.
>
> But my program still won't come up in my debugger.
>
> [Session started at 2009-10-07 13:27:16 -0700.]
> GNU gdb (GDB) 7.0
> Copyright (C) 2009 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-darwin9.7.0".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>.
> Loading program into debugger…
> No symbol table is loaded.  Use the "file" command.
> No symbol table is loaded.  Use the "file" command.
> No symbol table is loaded.  Use the "file" command.
> No symbol table is loaded.  Use the "file" command.
> Program loaded.
> tty /dev/ttys008
> (gdb) run
> =thread-group-created,id="81191"
> =thread-created,id="1",group-id="81191"
>

I'm guessing that a stub implementation of -arch may not be enough,
you may end up needing to backport the actual arch implementation, you
may also try stripping the unneeded architectures from the binary
you're trying to debug with the lipo command... (though I'm not sure
if that would actually work...)


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 18:09 How to configure gdb to support '--arch=i386' on Mac OS X n179911
  2009-10-07 18:32 ` Joel Brobecker
  2009-10-07 18:35 ` Michael Snyder
@ 2009-10-07 20:45 ` Jack Howarth
  2 siblings, 0 replies; 18+ messages in thread
From: Jack Howarth @ 2009-10-07 20:45 UTC (permalink / raw)
  To: n179911, y; +Cc: gdb

On Wed, Oct 07, 2009 at 11:09:39AM -0700, n179911 wrote:
> Hi,
> 
> I have compiled gdb 7.0 on Mac OS X. And I have configured XCode to
> use this new version of gdb 7.0.
> 
> But when I start debug my XCode project it said gdb can't recognize
> the option '--arch=i386'. Here is the log of my error:
> 
> [Session started at 2009-10-07 11:00:43 -0700.]
> /Users/n179911/bin/gdb/bin/gdb: unrecognized option `--arch=i386'
> Use `/Users/n179911/bin/gdb/bin/gdb --help' for a complete list of options.
> 
> The Debugger has exited with status 1.The Debugger has exited with status
> 
> Can you please tell me how to build gdb to support '--arch-i386' option?
> 
> Thank you.

   You don't indicate if you are running Snow Leopard are not. The gdb 7.0
release uses the latest config.guess which detects the architecture as
that of the default code generation for the system compiler (which is
x86_64 on EMT64 capable hardware). If you want to build the 32-bit gdb
under those conditions, you should explicitly pass the triplet
i386-apple-darwin10 or i686-apple-darwin10 to configure for --host/--build/--target.
I would note that currently for the x86_64-apple-darwin10 build, the
resulting gdb doesn't load i386 binaires (unlike the situation under Linux).
I haven't tested the i686-apple-darwin9 build to see if it can load x86_64
binaries yet.
                 Jack


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 20:10   ` n179911
  2009-10-07 20:20     ` Daniel Jacobowitz
  2009-10-07 20:26     ` n179911
@ 2009-10-07 21:04     ` Michael Snyder
  2009-10-07 21:15       ` Jack Howarth
  2 siblings, 1 reply; 18+ messages in thread
From: Michael Snyder @ 2009-10-07 21:04 UTC (permalink / raw)
  To: n179911; +Cc: gdb

n179911 wrote:
> Thank you. You are right.
> 
> The gdb comes with apple has '-arch'  option, but gdb 7.0 does not.
> 
>  $ /usr/bin/gdb --help
>   --translate        Debug applications running under translation.
>   -arch i386|armv6|x86_64|ppc     Specify a gdb targetting a specific
> architecture
> 
> So should I do what Joel Brobecker suggested in adding that option in
> gdb/main.c?

Or you could try to make XCode refrain from sending it.

Entirely up to you.  I don't think we are looking to add that
to the mainstream gdb.

> On Wed, Oct 7, 2009 at 11:31 AM, Michael Snyder <msnyder@vmware.com> wrote:
>> n179911 wrote:
>>> Hi,
>>>
>>> I have compiled gdb 7.0 on Mac OS X. And I have configured XCode to
>>> use this new version of gdb 7.0.
>>>
>>> But when I start debug my XCode project it said gdb can't recognize
>>> the option '--arch=i386'. Here is the log of my error:
>>>
>>> [Session started at 2009-10-07 11:00:43 -0700.]
>>> /Users/n179911/bin/gdb/bin/gdb: unrecognized option `--arch=i386'
>>> Use `/Users/n179911/bin/gdb/bin/gdb --help' for a complete list of
>>> options.
>>>
>>> The Debugger has exited with status 1.The Debugger has exited with status
>>>
>>> Can you please tell me how to build gdb to support '--arch-i386' option?
>> I don't think this has ever been a command line option in fsf gdb.
>> Maybe it is one that was added to Apple's version of gdb.
>>
>> Try running `/Users/n179911/bin/gdb/bin/gdb --help', and
>> then run the same command using your installed gdb that came
>> with Mac OS.  My guess is that the Mac version will list
>> "--arch" among the command line options, but the fsf version
>> will not (mine doesn't).
>>
>>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 20:26     ` n179911
  2009-10-07 20:38       ` Matt Rice
@ 2009-10-07 21:07       ` Michael Snyder
  2009-10-07 21:22         ` Stan Shebs
  1 sibling, 1 reply; 18+ messages in thread
From: Michael Snyder @ 2009-10-07 21:07 UTC (permalink / raw)
  To: n179911; +Cc: gdb

Yeahhhh, this isn't going to work.

Your binary is in... I forget what it's called -- oh, "mach-o" format.
Our (fsf) gdb does not know how to read that file format.  And it
would be a huge job to port over the changes in apple gdb that tell
it how to read mach-o files (besides the fact that they are "fat"
files, or at least potentially might be).

Sorry, I think you're out of luck.

n179911 wrote:
> I tried Joel Brobecker suggested in adding that option in gdb/main.c.
> 
> But my program still won't come up in my debugger.
> 
> [Session started at 2009-10-07 13:27:16 -0700.]
> GNU gdb (GDB) 7.0
> Copyright (C) 2009 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-darwin9.7.0".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>.
> Loading program into debuggerÂ…
> No symbol table is loaded.  Use the "file" command.
> No symbol table is loaded.  Use the "file" command.
> No symbol table is loaded.  Use the "file" command.
> No symbol table is loaded.  Use the "file" command.
> Program loaded.
> tty /dev/ttys008
> (gdb) run
> =thread-group-created,id="81191"
> =thread-created,id="1",group-id="81191"
> 
> 
> 
> On Wed, Oct 7, 2009 at 1:10 PM, n179911 <n179911@gmail.com> wrote:
>> Thank you. You are right.
>>
>> The gdb comes with apple has '-arch'  option, but gdb 7.0 does not.
>>
>>  $ /usr/bin/gdb --help
>>  --translate        Debug applications running under translation.
>>  -arch i386|armv6|x86_64|ppc     Specify a gdb targetting a specific
>> architecture
>>
>> So should I do what Joel Brobecker suggested in adding that option in
>> gdb/main.c?
>>
>> Thank you.
>>
>>
>> On Wed, Oct 7, 2009 at 11:31 AM, Michael Snyder <msnyder@vmware.com> wrote:
>>> n179911 wrote:
>>>> Hi,
>>>>
>>>> I have compiled gdb 7.0 on Mac OS X. And I have configured XCode to
>>>> use this new version of gdb 7.0.
>>>>
>>>> But when I start debug my XCode project it said gdb can't recognize
>>>> the option '--arch=i386'. Here is the log of my error:
>>>>
>>>> [Session started at 2009-10-07 11:00:43 -0700.]
>>>> /Users/n179911/bin/gdb/bin/gdb: unrecognized option `--arch=i386'
>>>> Use `/Users/n179911/bin/gdb/bin/gdb --help' for a complete list of
>>>> options.
>>>>
>>>> The Debugger has exited with status 1.The Debugger has exited with status
>>>>
>>>> Can you please tell me how to build gdb to support '--arch-i386' option?
>>> I don't think this has ever been a command line option in fsf gdb.
>>> Maybe it is one that was added to Apple's version of gdb.
>>>
>>> Try running `/Users/n179911/bin/gdb/bin/gdb --help', and
>>> then run the same command using your installed gdb that came
>>> with Mac OS.  My guess is that the Mac version will list
>>> "--arch" among the command line options, but the fsf version
>>> will not (mine doesn't).
>>>
>>>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 21:04     ` Michael Snyder
@ 2009-10-07 21:15       ` Jack Howarth
  0 siblings, 0 replies; 18+ messages in thread
From: Jack Howarth @ 2009-10-07 21:15 UTC (permalink / raw)
  To: Michael Snyder; +Cc: n179911, gdb

On Wed, Oct 07, 2009 at 02:00:38PM -0700, Michael Snyder wrote:
> n179911 wrote:
>> Thank you. You are right.
>>
>> The gdb comes with apple has '-arch'  option, but gdb 7.0 does not.
>>

Actually if you look at what Apple does, the gdb in /usr/bin (for
Leopard anyway) is just an executable shell script...

#! /bin/sh

host_architecture=""
requested_architecture="UNSET"
architecture_to_use=""

# classic-inferior-support
translate_mode=0
translate_binary=""

PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/bin

# gdb is setgid procmod and dyld will truncate any DYLD_FRAMEWORK_PATH etc
# settings on exec.  The user is really trying to set these things
# in their process, not gdb.  So we smuggle it over the setgid border in
# GDB_DYLD_* where it'll be laundered inside gdb before invoking the inferior.

unset GDB_DYLD_FRAMEWORK_PATH
unset GDB_DYLD_FALLBACK_FRAMEWORK_PATH
unset GDB_DYLD_LIBRARY_PATH
unset GDB_DYLD_FALLBACK_LIBRARY_PATH
unset GDB_DYLD_ROOT_PATH
unset GDB_DYLD_PATHS_ROOT
unset GDB_DYLD_IMAGE_SUFFIX
unset GDB_DYLD_INSERT_LIBRARIES
[ -n "$DYLD_FRAMEWORK_PATH" ] && GDB_DYLD_FRAMEWORK_PATH="$DYLD_FRAMEWORK_PATH"
[ -n "$DYLD_FALLBACK_FRAMEWORK_PATH" ] && GDB_DYLD_FALLBACK_FRAMEWORK_PATH="$DYLD_FALLBACK_FRAMEWORK_PATH"
[ -n "$DYLD_LIBRARY_PATH" ] && GDB_DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH"
[ -n "$DYLD_FALLBACK_LIBRARY_PATH" ] && GDB_DYLD_FALLBACK_LIBRARY_PATH="$DYLD_FALLBACK_LIBRARY_PATH"
[ -n "$DYLD_ROOT_PATH" ] && GDB_DYLD_ROOT_PATH="$DYLD_ROOT_PATH"
[ -n "$DYLD_PATHS_ROOT" ] && GDB_DYLD_PATHS_ROOT="$DYLD_PATHS_ROOT"
[ -n "$DYLD_IMAGE_SUFFIX" ] && GDB_DYLD_IMAGE_SUFFIX="$DYLD_IMAGE_SUFFIX"
[ -n "$DYLD_INSERT_LIBRARIES" ] && GDB_DYLD_INSERT_LIBRARIES="$DYLD_INSERT_LIBRARIES"
export GDB_DYLD_FRAMEWORK_PATH
export GDB_DYLD_FALLBACK_FRAMEWORK_PATH
export GDB_DYLD_LIBRARY_PATH
export GDB_DYLD_FALLBACK_LIBRARY_PATH
export GDB_DYLD_ROOT_PATH
export GDB_DYLD_PATHS_ROOT
export GDB_DYLD_IMAGE_SUFFIX
export GDB_DYLD_INSERT_LIBRARIES

# dyld will warn if any of these are set and the user invokes a setgid program
# like gdb.
unset DYLD_FRAMEWORK_PATH
unset DYLD_FALLBACK_FRAMEWORK_PATH
unset DYLD_LIBRARY_PATH
unset DYLD_FALLBACK_LIBRARY_PATH
unset DYLD_ROOT_PATH
unset DYLD_PATHS_ROOT
unset DYLD_IMAGE_SUFFIX
unset DYLD_INSERT_LIBRARIES

host_architecture=`/usr/bin/arch 2>/dev/null` || host_architecture=""

if [ -z "$host_architecture" ]; then
    echo "There was an error executing 'arch(1)'; assuming 'i386'.";
    host_architecture="i386";
fi


case "$1" in
 --help)
    echo "  --translate        Debug applications running under translation." >&2
    echo "  -arch i386|armv6|x86_64|ppc     Specify a gdb targetting a specific architecture" >&2
    ;;
  -arch=* | -a=* | --arch=*)
    requested_architecture=`echo "$1" | sed 's,^[^=]*=,,'`
    shift;;
  -arch | -a | --arch)
    shift
    requested_architecture="$1"
    shift;;
  -translate | --translate | -oah* | --oah*)
    translate_mode=1
    shift;;
esac

if [ -z "$requested_architecture" ]
then
  echo ERROR: No architecture specified with -arch argument. >&2
  exit 1
fi
[ "$requested_architecture" = "UNSET" ] && requested_architecture=""

if [ $translate_mode -eq 1 ]
then
  if [ "$host_architecture" = i386 -a -x /usr/libexec/oah/translate ]
  then
    requested_architecture="ppc"
    translate_binary="/usr/libexec/oah/translate -execOAH"
  else
    echo ERROR: translate not available.  Running in normal debugger mode. >&2
  fi
fi

if [ -n "$requested_architecture" ]
then
  case $requested_architecture in
    ppc* | i386 | x86_64 | arm*)
     ;;
    *)
      echo Unrecognized architecture \'$requested_architecture\', using host arch. >&2
      requested_architecture=""
      ;;
  esac
fi

if [ -n "$requested_architecture" ]
then
  architecture_to_use="$requested_architecture"
else
  # No architecture was specified. We will try to find the executable
  # or a core file in the list of arguments, and launch the correct
  # gdb for the job. If there are multiple architectures in the executable,
  # we will search for the architecture that matches the host architecture.
  # If all this searching doesn't produce a match, we will use a gdb that
  # matches the host architecture by default.
  best_arch=
  exec_file=
  core_file=
  for arg in "$@"
  do
    case "$arg" in
      -*)
        # Skip all option arguments
        ;;
      *)
        # Call file to determine the file type of the argument
        file_result=`file "$arg"`;
        case "$file_result" in
          *Mach-O*core*)
            core_file=$arg
            ;;
          *Mach-O*)
            exec_file=$arg
            ;;
          *)
            if [ -x "$arg" ]; then
              exec_file="$arg"
            fi
            ;;
        esac
        ;;
    esac
  done

  # Get a list of possible architectures in FILE_ARCHS.
  # If we have a core file, we must use it to determine the architecture,
  # else we use the architectures in the executable file.
  file_archs=
  if [ -n "$core_file" ]; then
    file_archs=`file "$core_file" | awk '{ print $NF }'`
  else
    if [ -n "$exec_file" ]; then
      file_archs=`file "$exec_file" | grep -v universal | awk '{ print $NF }'`
    fi
  fi

  # Iterate through the architectures and try and find the best match.
  for file_arch in $file_archs
  do
    # If we don't have any best architecture set yet, use this in case
    # none of them match the host architecture.
    if [ -z "$best_arch" ]; then
      best_arch="$file_arch"
    fi

    # See if the file architecture matches the host, and if so set the
    # best architecture to that.
    if [ "$file_arch" = "$host_architecture" ]; then
      best_arch="$file_arch"
    fi
  done

  case "$best_arch" in
    ppc* | i386 | x86_64 | arm*)
      # We found a plausible architecture and we will use it
      architecture_to_use="$best_arch"
      ;;
    *)
      # We did not find a plausible architecture, use the host architecture
      architecture_to_use="$host_architecture"
      ;;
  esac
fi

# If GDB_ROOT is not set, then figure it out
# from $0.  We need this for gdb's that are
# not installed in /usr/bin.

GDB_ROOT_SET=${GDB_ROOT:+set}
if [ "$GDB_ROOT_SET" != "set" ]
then
  gdb_bin="$0"
  if [ -L "$gdb_bin" ]
  then
    gdb_bin=`readlink "$gdb_bin"`
  fi
  gdb_bin_dirname=`dirname "$gdb_bin"`
  GDB_ROOT=`cd "$gdb_bin_dirname"/../.. ; pwd`
  if [ "$GDB_ROOT" = "/" ]
      then
        GDB_ROOT=
  fi
fi

case "$architecture_to_use" in
  ppc*)
    # Make sure we specify the architecture to gdb when launching if the
    # gdb can handle both 32 and 64 bit variants.
    if [ -z "$requested_architecture" ]; then
      requested_architecture=$architecture_to_use;
    fi
    gdb="${GDB_ROOT}/usr/libexec/gdb/gdb-powerpc-apple-darwin"
    ;;
  i386 | x86_64)
    # Make sure we specify the architecture to gdb when launching if the
    # gdb can handle both 32 and 64 bit variants.
    if [ -z "$requested_architecture" ]; then
      requested_architecture=$architecture_to_use;
    fi
    gdb="${GDB_ROOT}/usr/libexec/gdb/gdb-i386-apple-darwin"
    ;;
  arm*)
    gdb="${GDB_ROOT}/usr/libexec/gdb/gdb-arm-apple-darwin"
      case "$architecture_to_use" in
        armv6)
          osabiopts="--osabi DarwinV6"
          ;;
        *)
          # Make the REQUESTED_ARCHITECTURE the empty string so
          # we can let gdb auto-detect the cpu type and subtype
          requested_architecture=""
          ;;
      esac
      ;;
  *)
    echo "Unknown architecture '$architecture_to_use'; using 'ppc' instead.";
    gdb="${GDB_ROOT}/usr/libexec/gdb/gdb-powerpc-apple-darwin"
    ;;
esac

if [ ! -x "$gdb" ]; then
    echo "Unable to start GDB: cannot find binary in '$gdb'"
    exit 1
fi

if [ -n "$requested_architecture" -a $translate_mode -eq 0 ]
then
  exec $translate_binary "$gdb" --arch "$requested_architecture" "$@"
else
  exec $translate_binary "$gdb" $osabiopts "$@"
fi

So he could simply make a copy of that for /usr/local/bin and adjust it
to run the FSF gdb. Actually it might not be a bad idea since one
could script calling the gdb binary with sudo (as 10.5.8 or later
requires gdb to be run as root for now).
                   Jack
ps I wonder if there are any clues in this script that might help us
run FSF gdb as non-root?


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 20:21       ` n179911
@ 2009-10-07 21:16         ` Stan Shebs
  0 siblings, 0 replies; 18+ messages in thread
From: Stan Shebs @ 2009-10-07 21:16 UTC (permalink / raw)
  To: n179911; +Cc: gdb

n179911 wrote:
> From
>
> http://developer.apple.com/mac/library/documentation/DeveloperTools/Reference/XcodeUserDefaultRef/100-Xcode_User_Defaults/UserDefaultRef.html#//apple%5Fref/doc/uid/TP40005535-CH3-SW54
>
> it mentions I can switch a different GDB in xcode.
>   
In practice, that is mostly useful for using different versions/releases 
of Apple's GDB, or for cross development.  The --arch issue is just the 
tip of the iceberg of problems you are likely to experience with trying 
to use FSF GDB.  The command set is different, output from commands is 
different, and Xcode has lots of assumptions about what the debugger can 
do, especially for the native case.

Stan


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 21:07       ` Michael Snyder
@ 2009-10-07 21:22         ` Stan Shebs
  2009-10-07 23:18           ` Jack Howarth
  2009-10-08  7:54           ` Tristan Gingold
  0 siblings, 2 replies; 18+ messages in thread
From: Stan Shebs @ 2009-10-07 21:22 UTC (permalink / raw)
  To: Michael Snyder; +Cc: n179911, gdb

Michael Snyder wrote:
> Yeahhhh, this isn't going to work.
>
> Your binary is in... I forget what it's called -- oh, "mach-o" format.
> Our (fsf) gdb does not know how to read that file format.  And it
> would be a huge job to port over the changes in apple gdb that tell
> it how to read mach-o files (besides the fact that they are "fat"
> files, or at least potentially might be). m
The Mach-O part does work in 7.0, thanks to Tristan and AdaCore (check 
out gdb/machoread.c).  I don't think fatness-handling is there, although 
at the Xcode level one has to specifically ask for fat builds anyway, so 
one could avoid that particular obstacle and thus be well-positioned to 
smack one's face into the next wall. :-)

Stan



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 21:22         ` Stan Shebs
@ 2009-10-07 23:18           ` Jack Howarth
  2009-10-08  7:53             ` Tristan Gingold
  2009-10-08 12:48             ` Tristan Gingold
  2009-10-08  7:54           ` Tristan Gingold
  1 sibling, 2 replies; 18+ messages in thread
From: Jack Howarth @ 2009-10-07 23:18 UTC (permalink / raw)
  To: Stan Shebs; +Cc: Michael Snyder, n179911, gdb

On Wed, Oct 07, 2009 at 02:22:20PM -0700, Stan Shebs wrote:
> Michael Snyder wrote:
>> Yeahhhh, this isn't going to work.
>>
>> Your binary is in... I forget what it's called -- oh, "mach-o" format.
>> Our (fsf) gdb does not know how to read that file format.  And it
>> would be a huge job to port over the changes in apple gdb that tell
>> it how to read mach-o files (besides the fact that they are "fat"
>> files, or at least potentially might be). m
> The Mach-O part does work in 7.0, thanks to Tristan and AdaCore (check  
> out gdb/machoread.c).  I don't think fatness-handling is there, although  
> at the Xcode level one has to specifically ask for fat builds anyway, so  
> one could avoid that particular obstacle and thus be well-positioned to  
> smack one's face into the next wall. :-)
>
> Stan
>

Stan,
  I am puzzled about the fact that the current x86_64-apple-darwin10
build of FSF gdb 7.0 is unable to load i386 binaries like x86_64 gdb
can under linux. Do you think this should be possible without resorting
to fat-binaries for darwin?
           Jack


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 23:18           ` Jack Howarth
@ 2009-10-08  7:53             ` Tristan Gingold
  2009-10-08 12:48             ` Tristan Gingold
  1 sibling, 0 replies; 18+ messages in thread
From: Tristan Gingold @ 2009-10-08  7:53 UTC (permalink / raw)
  To: Jack Howarth; +Cc: Stan Shebs, Michael Snyder, n179911, gdb


On Oct 8, 2009, at 1:18 AM, Jack Howarth wrote:

> On Wed, Oct 07, 2009 at 02:22:20PM -0700, Stan Shebs wrote:
>> Michael Snyder wrote:
>>> Yeahhhh, this isn't going to work.
>>>
>>> Your binary is in... I forget what it's called -- oh, "mach-o"  
>>> format.
>>> Our (fsf) gdb does not know how to read that file format.  And it
>>> would be a huge job to port over the changes in apple gdb that tell
>>> it how to read mach-o files (besides the fact that they are "fat"
>>> files, or at least potentially might be). m
>> The Mach-O part does work in 7.0, thanks to Tristan and AdaCore  
>> (check
>> out gdb/machoread.c).  I don't think fatness-handling is there,  
>> although
>> at the Xcode level one has to specifically ask for fat builds  
>> anyway, so
>> one could avoid that particular obstacle and thus be well- 
>> positioned to
>> smack one's face into the next wall. :-)
>>
>> Stan
>>
>
> Stan,
>  I am puzzled about the fact that the current x86_64-apple-darwin10
> build of FSF gdb 7.0 is unable to load i386 binaries like x86_64 gdb
> can under linux. Do you think this should be possible without  
> resorting
> to fat-binaries for darwin?

That's unexpected.  It least it worked in the past.  Will try to fix  
that.

Tristan.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 21:22         ` Stan Shebs
  2009-10-07 23:18           ` Jack Howarth
@ 2009-10-08  7:54           ` Tristan Gingold
  1 sibling, 0 replies; 18+ messages in thread
From: Tristan Gingold @ 2009-10-08  7:54 UTC (permalink / raw)
  To: n179911; +Cc: Michael Snyder, gdb, Stan Shebs


On Oct 7, 2009, at 11:22 PM, Stan Shebs wrote:

> Michael Snyder wrote:
>> Yeahhhh, this isn't going to work.
>>
>> Your binary is in... I forget what it's called -- oh, "mach-o"  
>> format.
>> Our (fsf) gdb does not know how to read that file format.  And it
>> would be a huge job to port over the changes in apple gdb that tell
>> it how to read mach-o files (besides the fact that they are "fat"
>> files, or at least potentially might be). m
> The Mach-O part does work in 7.0, thanks to Tristan and AdaCore  
> (check out gdb/machoread.c).  I don't think fatness-handling is  
> there, although at the Xcode level one has to specifically ask for  
> fat builds anyway, so one could avoid that particular obstacle and  
> thus be well-positioned to smack one's face into the next wall. :-)

Right.  The work-around is not to build fat binaries.

Current FSF gdb can't handle fat executable.  I am not sure that we  
want to implement this, but feel free
to ask.  However gdb handles fat objects such as dylibs.

Tristan.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: How to configure gdb to support '--arch=i386' on Mac OS X
  2009-10-07 23:18           ` Jack Howarth
  2009-10-08  7:53             ` Tristan Gingold
@ 2009-10-08 12:48             ` Tristan Gingold
  1 sibling, 0 replies; 18+ messages in thread
From: Tristan Gingold @ 2009-10-08 12:48 UTC (permalink / raw)
  To: Jack Howarth; +Cc: Stan Shebs, Michael Snyder, n179911, gdb


On Oct 8, 2009, at 1:18 AM, Jack Howarth wrote:
>
> Stan,
>  I am puzzled about the fact that the current x86_64-apple-darwin10
> build of FSF gdb 7.0 is unable to load i386 binaries like x86_64 gdb
> can under linux. Do you think this should be possible without  
> resorting
> to fat-binaries for darwin?

Should now be fixed in trunk.  Thanks!

Tristan.


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2009-10-08 12:48 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-07 18:09 How to configure gdb to support '--arch=i386' on Mac OS X n179911
2009-10-07 18:32 ` Joel Brobecker
2009-10-07 18:35 ` Michael Snyder
2009-10-07 20:10   ` n179911
2009-10-07 20:20     ` Daniel Jacobowitz
2009-10-07 20:21       ` n179911
2009-10-07 21:16         ` Stan Shebs
2009-10-07 20:26     ` n179911
2009-10-07 20:38       ` Matt Rice
2009-10-07 21:07       ` Michael Snyder
2009-10-07 21:22         ` Stan Shebs
2009-10-07 23:18           ` Jack Howarth
2009-10-08  7:53             ` Tristan Gingold
2009-10-08 12:48             ` Tristan Gingold
2009-10-08  7:54           ` Tristan Gingold
2009-10-07 21:04     ` Michael Snyder
2009-10-07 21:15       ` Jack Howarth
2009-10-07 20:45 ` Jack Howarth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox