This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Use thread_info and inferior pointers more throughout
- From: Tom Tromey <tom at tromey dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Thu, 07 Jun 2018 12:28:15 -0600
- Subject: Re: [PATCH] Use thread_info and inferior pointers more throughout
- References: <20180607180704.3991-1-palves@redhat.com>
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
Pedro> In many cases though, we already have the thread_info or inferior
Pedro> pointer handy, but we "lose" it somewhere along the call stack, only
Pedro> to look it up again by ptid_t/pid. Since thread_info or inferior
Pedro> objects know their parent target, if we pass around thread_info or
Pedro> inferior pointers when possible, we avoid having to add extra
Pedro> target_ops parameters to many functions, and also, we eliminate a
Pedro> number of by ptid_t/int lookups.
This seems like a good idea. I've sometimes wondered why ptid was used
rather than object pointers; but now it seems that there was no deep
reason :)
Pedro> - Related, there's a spot where using a RAII object to handle the
Pedro> refcount would be handy, so a new scoped_inc_dec_ref class is added
Pedro> to common/refcounted-object.h.
It seems to me that this could be done via gdb::ref_ptr plus a simple
policy class that interfaces it to refcounted_object.
Pedro> +/* A RAII type that increments/decrements the refcount of an object on
Pedro> + enter/exit of a scope. */
Pedro> +
Pedro> +class scoped_inc_dec_ref
Pedro> +{
Pedro> +public:
Pedro> + explicit scoped_inc_dec_ref (refcounted_object *obj)
Pedro> + : m_obj (obj)
Pedro> + {
Pedro> + m_obj->incref ();
Pedro> + }
Pedro> +
Pedro> + ~scoped_inc_dec_ref ()
Pedro> + {
Pedro> + m_obj->decref ();
Pedro> + }
... if you do keep this it probably needs DISABLE_COPY_AND_ASSIGN.
Tom