I was trying to add some features to gdbinit and I needed global variables. I already knew that feature wasn’t working on Mac OS X gdb and I was puzzled why it didn’t work. Some quick tests on a Linux box couldn’t reproduce the same behaviour so something is wrong with Apple’s gdb version. I finally found how it happens !
A very simple .gdbinit to test things would be:
set $bugtest = 10 define bugtest output $bugtest end
Replacing our beloved .gdbinit with this simple version and let’s see what happens:
$ gdb GNU gdb 6.3.50-20050815 (Apple version gdb-696) (Sat Oct 20 18:16:54 GMT 2007) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin". warning: --arch option not supported in this gdb. (gdb) bugtest 10(gdb)
Now another test:
$ gdb antidebug GNU gdb 6.3.50-20050815 (Apple version gdb-696) (Sat Oct 20 18:16:54 GMT 2007) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin"... warning: --arch option not supported in this gdb. Reading symbols for shared libraries .. done (gdb) bugtest void(gdb)
Can you spot the difference ? This should help…
$ gdb GNU gdb 6.3.50-20050815 (Apple version gdb-696) (Sat Oct 20 18:16:54 GMT 2007) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin". warning: --arch option not supported in this gdb. (gdb) exec-file antidebug Reading symbols for shared libraries .. done (gdb) bugtest 10(gdb)
So for some reason (bug ?!?!?) the .gdbinit global variables are lost if we start gdb with a program as argument and they are kept if we start gdb without any argument. Attaching to an already running process has no problems. Using the same trick with one of those unmodified .gdbinit (7.0 or 7.1) and everything goes smooth, no errors
GDB source code is huge and the changelog might not be helpful to track this problem
I was trying to backport the memory search feature implemented in latest gdb versions but I gave up ! At least I have a workaround…
-
Thanks!
At least I have some clue why I’m getting this error message. -
I wish I had a list of ways in which the GDB on OS X doesn’t do what GDB on other platforms does. So far I have run into two ways (it won’t “find” things across a process’s memory, and it won’t “catch” the loading/unloading of libraries). And I’ve only been using it for a few weeks so who knows how many other ways it is broken.
-
I have mammon’s gdbinit 6.1 working fine here
(10.5.6 intel, gdb 6.3.50-20050815 ) so i think
the problem lies somewhere else.FYI the following works fine:
define bugtest
set $bugtest = 10
output $bugtest
endno matter if i run gdb without args etc
-
This is quite annoying. Here is an expect script to allow you to type “gdb file” and allow global variables to work:
$ cat gdbx
#!/usr/bin/expect
spawn gdb
expect “(gdb) ”
send “exec-file [lindex $argv 0]\n”
interact$ ./gdbx /bin/ls
spawn gdb
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i386-apple-darwin”.
(gdb) exec-file /bin/ls
Reading symbols for shared libraries …. done
(gdb) b *0x000023f0
Breakpoint 1 at 0x23f0
(gdb) r
Starting program: /bin/ls
Reading symbols for shared libraries ….. doneBreakpoint 1, 0x000023f0 in ?? ()
$1 = “test”
$2 = 10
$3 = 20
(gdb)

5 comments
Comments feed for this article
Trackback link: http://reverse.put.as/2008/11/28/apples-gdb-bug/trackback/