And who says Apple is always the one that has style?

So I was debugging some code a while back on Linux using gdb from the command line.

Oh yeah, old school.

Anyhow, during one of my runs I accidentally attached gdb to its own process. It went something kinda like this:

lammig@linux-mbp:~> gdb
GNU gdb 6.4
Copyright 2005 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 "i586-suse-linux".
(gdb) shell ps
PID TTY TIME CMD
4630 pts/1 00:00:00 bash
4713 pts/1 00:00:00 gdb
4714 pts/1 00:00:00 ps
(gdb) attach 4713

I refuse to debug myself!

(gdb)
lammig@linux-mbp:~>

Now that is one cool error message. In fact, that is quite possibly the best error message I’ve ever seen. This got to me wondering, is it the same for gdb on different platforms? Let’s take a look on FreeBSD…

cerebro/lammi:~ (1) gdb
GNU gdb 6.1.1 [FreeBSD]
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-marcel-freebsd".
(gdb) shell ps
PID TT STAT TIME COMMAND
66600 p4 Ss 0:00.04 -tcsh (tcsh)
66609 p4 S+ 0:00.01 gdb
66610 p4 S+ 0:00.01 tcsh -c ps
66611 p4 R+ 0:00.00 ps
(gdb) attach 66609

I refuse to debug myself!

(gdb)

Rock and roll, score two for the open source OS guys. Now this made me wonder, with all their crazy attention to detail, what would Apple do with something like this.

There’s only one way to find out…

lammi-mbp:~ lammig$ gdb
GNU gdb 6.3.50-20050815 (Apple version gdb-563) (Wed Jul 19 05:10:58 GMT 2006)
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) shell ps
PID TT STAT TIME COMMAND
261 p1 S 0:00.03 -bash
299 p1 S+ 0:00.03 /usr/libexec/gdb/gdb-i386-apple-darwin
(gdb) attach 299

unable to debug self

(gdb)

unable to debug self?

You’ve got to be kidding me. It’s not even a sentence. There’s not even capitialization or punctuation. Aye caramba.

Just for kicks let’s see how stodgy old Solaris talks to us…

bash-2.05$ /usr/local/bin/gdb
GNU gdb 6.0
Copyright 2003 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 "sparc-sun-solaris2.9".
(gdb) shell ps
PID TTY TIME CMD
1579 pts/1 0:00 bash
1585 pts/1 0:00 gdb
1586 pts/1 0:00 ps
(gdb) attach 1585

Attaching GDB to itself is not a good idea…

(gdb)

Come on Apple, even Sun of all places has a fun error message. I wonder if I should submit a bug to see if they can fix it in Leopard?

About Grant

I grew up on the mean cul-du-sacs of Troy, Ohio, USA. I first started "programming" at the age of five on an Atari 400 when I used BASIC to draw an ASCII picture of robot with wheels on his feet. Why the emphasis on feet with wheels? At the time it was a big deal, I didn't have wheels on my feet which forced me to walk everywhere. I would have been so much cooler to just skate around. Since then I've gone on to work on all manners of different technologies, but rest assured if I ever write another robot program he won't just be walking around. Perhaps some tank treads...
This entry was posted in Debugging. Bookmark the permalink.

One Response to And who says Apple is always the one that has style?

  1. Anonymous says:

    — src/gdb/macosx/macosx-nat-inferior.c 2005-05-03 20:13:33.000000000 -0400
    +++ macosx-nat-inferior.c 2006-08-24 01:44:16.000000000 -0400
    @@ -1185,7 +1185,7 @@

    if (itask == mach_task_self ())
    {
    - error (“unable to debug self”);
    + error (“My apologies Mr. Lammi! My bits don’t dance that way!”);
    }

    :) :) :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>