Header files with enums instead of defines?
Garance A Drosihn
drosih at rpi.edu
Wed Dec 22 10:20:06 PST 2004
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 at gilead.netel.rpi.edu
Senior Systems Programmer or gad at freebsd.org
Rensselaer Polytechnic Institute or drosih at rpi.edu
More information about the freebsd-arch
mailing list