Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Dec 2004 13:20:03 -0500
From:      Garance A Drosihn <drosih@rpi.edu>
To:        Peter Edwards <peadar.edwards@gmail.com>, "Greg 'groggy' Lehey" <grog@freebsd.org>, FreeBSD Architecture Mailing List <arch@freebsd.org>
Subject:   Re: Header files with enums instead of defines?
Message-ID:  <p0620078abdef6999e4ee@[128.113.24.47]>
In-Reply-To: <34cb7c8404122205002bd7de18@mail.gmail.com>
References:  <20041222010143.GS53357@wantadilla.lemis.com>	 <20041222090855.GO79646@cirb503493.alcatel.com.au>	 <20041222103844.GI801@straylight.m.ringlet.net> <34cb7c8404122205002bd7de18@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
At 1:00 PM +0000 12/22/04, Peter Edwards wrote:
>As an alternative to Peter Jeremy's suggestion of using a GDB
>macro, you could, of course, define a type as:
>
>typedef enum {
>     err_EPERM = EPERM,
>     err_ENOENT = ENOENT,
>     /* .... */
>} errno_t
>
>Then within gdb:
>
>Breakpoint 1, main (argc=1, argv=0xbfbfe55c) at e.c:21
>21          int rc = write(-1, "X", 1);
>(gdb) n
>22          pause();
>(gdb) p (errno_t)errno
>$1 = err_EBADF
>(gdb)

Ooo, that's a nice trick.

>(Note if you actually try this, you need to define at least one
>object of the errno_t type in your program to generate the type
>in the executable output.)

This note made me think of another possible trick:

(gdb) printf "== '%s'\n", strerror(errno)
== 'No such file or directory'

I recommend the extra baggage in the print statement.  Initially I
happened to test this by trying:

(gdb) printf "%s\n", strerror(4)
Interrupted system call

And I kept thinking that *gdb* was telling me the 'printf' call was
getting interrupted.  For a few minutes, I thought I had stumbled
across some serious bug!

I expect this only works if your program references strerror(),
but I haven't tried it in other situations.

-- 
Garance Alistair Drosehn            =   gad@gilead.netel.rpi.edu
Senior Systems Programmer           or  gad@freebsd.org
Rensselaer Polytechnic Institute    or  drosih@rpi.edu



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p0620078abdef6999e4ee>