This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Ensure result of make_cleanup is never NULL.
- From: Pedro Alves <palves at redhat dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: Doug Evans <dje at sebabeach dot org>, gdb-patches at sourceware dot org
- Date: Mon, 16 Apr 2012 15:57:20 +0100
- Subject: Re: [RFA] Ensure result of make_cleanup is never NULL.
- References: <m3bomszayu.fsf@annie.sebabeach.org> <20120416144011.GH2852@adacore.com>
On 04/16/2012 03:40 PM, Joel Brobecker wrote:
>> +/* A fencepost used to mark the end of a cleanup chain.
>> + The value is chosen to be non-NULL so that make_cleanup never returns NULL,
>> + and cause a segv if dereferenced. */
>> +#define CLEANUP_FENCEPOST ((struct cleanup *) 1)
>
> Just a tiny idea, not really important, but JIC: Could we use an enum
> intead of a define so that GDB prints "CLEANUP_FENCEPOST" rather than
> a numeric value when we print a cleanup pointer that's the fencepost?
No, because what you'll be printing will have type struct cleanup pointer, not
whatever enum it was cast from.
I see at least two ways to get something like that:
- a gdb specific pretty printer for cleanups.
- Make the sentinel a real object:
static struct cleanup sentinel_cleanup;
#define CLEANUP_FENCEPOST &sentinel_cleanup
And get Tromey's "set print symbol" patch in, which IIRC/IIUC, the
latest version makes GDB print the symbol name corresponding
to addresses by default. Then gdb would print something like:
(gdb) p old_chain
$1 = 0xfoobar <sentinel_cleanup>
--
Pedro Alves