Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Doug Evans <dje@google.com>
To: Pedro Alves <palves@redhat.com>, Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [RFA] Ensure result of make_cleanup is never NULL.
Date: Wed, 18 Apr 2012 01:06:00 -0000	[thread overview]
Message-ID: <CADPb22S_CJ-in8Hw9+LPU=ZYw=0tv-VTxGC-116gJL6YsUdpqQ@mail.gmail.com> (raw)
In-Reply-To: <CADPb22Qbp=7zsRFe=by5O3zV8VBaecYhwMjGHWA9Z_jCoTSjtQ@mail.gmail.com>

On Tue, Apr 17, 2012 at 4:00 PM, Doug Evans <dje@google.com> wrote:
> On Mon, Apr 16, 2012 at 8:21 AM, Doug Evans <dje@google.com> wrote:
>>
>> On Apr 16, 2012 7:58 AM, "Pedro Alves" <palves@redhat.com> wrote:
>>>
>>> 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
>>
>> That was my other plan.  I can do that instead.
>
> How about this?
>
>
> 2012-04-17  Doug Evans  <dje@google.com>
>
>        * cleanups.h (struct cleanup): Move to cleanups.c.
>        (make_cleanup_dtor_ftype): New typedef.
>        (make_cleanup_dtor): Use it.
>        (ALL_CLEANUPS): Replace with ...
>        (all_cleanups): ... this.  Declare.  All uses updated.
>        * cleanups.c (cleanup_sentinel): New static global.
>        (CLEANUP_SENTINEL): Define.
>        (cleanup_chain, final_cleanup_chain): Initialize to CLEANUP_SENTINEL.
>        (make_my_cleanup2): Assert result is non-NULL.
>        (all_cleanups): New function.
>        (save_my_cleanups): Initialize new chain to CLEANUP_SENTINEL instead
>        of NULL.

btw, I thought about making cleanup_sentinel const here, for a bit of
extra robustness.


  reply	other threads:[~2012-04-18  0:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-16  5:01 Doug Evans
2012-04-16 10:58 ` Pedro Alves
2012-04-16 14:44 ` Joel Brobecker
2012-04-16 14:58   ` Jan Kratochvil
2012-04-16 15:03   ` Pedro Alves
2012-04-16 20:16     ` Tom Tromey
     [not found]     ` <CADPb22SfUk5s9JSSBvUTWVyhoiEqO4Gi+VNO-9MwH6rqW8qQ3g@mail.gmail.com>
2012-04-17 23:12       ` Doug Evans
2012-04-18  1:06         ` Doug Evans [this message]
2012-04-18  1:58           ` Joel Brobecker
2012-04-18  9:21             ` Pedro Alves
2012-04-18  9:29           ` Pedro Alves
2012-04-18 14:14             ` Doug Evans
2012-04-18 14:25               ` Pedro Alves
2012-04-18 14:32                 ` Doug Evans
2012-04-18 14:36                   ` Pedro Alves
2012-04-18 14:38                 ` Tom Tromey
2012-04-19 19:24                   ` Doug Evans
2012-04-18  9:26         ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADPb22S_CJ-in8Hw9+LPU=ZYw=0tv-VTxGC-116gJL6YsUdpqQ@mail.gmail.com' \
    --to=dje@google.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox