This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v7] Events when inferior is modified
- From: Doug Evans <dje at google dot com>
- To: Nick Bull <nicholaspbull at gmail dot com>
- Cc: Pedro Alves <palves at redhat dot com>, gdb-patches at sourceware dot org
- Date: Fri, 17 Oct 2014 13:00:52 -0700
- Subject: Re: [PATCH v7] Events when inferior is modified
- Authentication-results: sourceware.org; auth=none
- References: <5419C597 dot 4000300 at gmail dot com> <542C3F4D dot 70104 at redhat dot com> <5441432B dot 5040103 at gmail dot com> <21569 dot 29405 dot 219428 dot 940000 at ruffy dot mtv dot corp dot google dot com>
Doug Evans writes:
> [...]
> Alas our use of thread ids is a bit, umm, confusing
> (in more ways than one! :-().
> Here, it's not guaranteed that ptid.lwp has something useful,
> and it may be that the target uses ptid.tid instead.
>
> See python/py-infthread.c:thpy_get_ptid.
> I think we should make that non-static and use that here.
Well, more specifically, split it into two and export a routine
that builds a python ptid tuple from a ptid_t.
> IOW, pass the whole ptid_t to the event.
>
> > + if (tid_obj == NULL)
> > + goto fail;
> > + make_cleanup_py_decref (tid_obj);
> > +
> > + failed = evpy_add_attribute (event, "tid", tid_obj) < 0;
> > + if (failed)
> > + goto fail;
> > +
> > + addr_obj = PyLong_FromLongLong (addr);
> > + if (addr_obj == NULL)
> > + goto fail;
> > + make_cleanup_py_decref (addr_obj);
> > +
> > + failed = evpy_add_attribute (event, "address", addr_obj) < 0;
> > + if (failed)
> > + goto fail;
> > +
>
> Run the cleanups here as well as for the fail case.
Well, more specifically (bleah) ...
E.g., the addr_obj attribute will have two references when we return
here. We want it to only have one: when the event goes away
we want addr_obj to go away too.
Obviously we don't want to decref the event object itself.
This applies to my other "Run the cleanups ..." comments below.
>
> > + return event;
> > +
> > + fail:
> > + do_cleanups (cleanups);
> > + return NULL;
> > +}
> > +
> > +/* Construct a gdb.RegisterChangedEvent containing the affected
> > + register number. */
> > +
> > +static PyObject *
> > +create_register_changed_event_object (struct frame_info *frame,
> > + short regnum)
> > +{
> > + PyObject * event;
> > + PyObject *frame_obj = NULL;
> > + PyObject *regnum_obj = NULL;
> > + int failed;
> > + struct cleanup *cleanups;
> > +
> > + event = create_event_object (®ister_changed_event_object_type);
> > + if (event == NULL)
> > + return NULL;
> > +
> > + cleanups = make_cleanup_py_decref (event);
> > +
> > + frame_obj = frame_info_to_frame_object (frame);
> > + if (frame_obj == NULL)
> > + goto fail;
> > + make_cleanup_py_decref (frame_obj);
> > +
> > + failed = evpy_add_attribute (event, "frame", frame_obj) < 0;
> > + if (failed)
> > + goto fail;
> > +
> > + regnum_obj = PyLong_FromLongLong (regnum);
> > + if (regnum_obj == NULL)
> > + goto fail;
> > + make_cleanup_py_decref (regnum_obj);
> > +
> > + failed = evpy_add_attribute (event, "regnum", regnum_obj) < 0;
> > + if (failed)
> > + goto fail;
> > +
>
> Run the cleanups here as well as for the fail case.
>
> > + return event;
> > +
> > + fail:
> > + do_cleanups (cleanups);
> > + return NULL;
> > +}
> > +
> > +/* Construct a gdb.MemoryChangedEvent describing the extent of the
> > + affected memory. */
> > +
> > +static PyObject *
> > +create_memory_changed_event_object (CORE_ADDR addr, ssize_t len)
> > +{
> > + PyObject * event;
> > + PyObject *addr_obj = NULL;
> > + PyObject *len_obj = NULL;
> > + int failed;
> > + struct cleanup *cleanups;
> > +
> > + event = create_event_object (&memory_changed_event_object_type);
> > +
> > + if (event == NULL)
> > + return NULL;
> > + cleanups = make_cleanup_py_decref (event);
> > +
> > + addr_obj = PyLong_FromLongLong (addr);
> > + if (addr_obj == NULL)
> > + goto fail;
> > + make_cleanup_py_decref (addr_obj);
> > +
> > + failed = evpy_add_attribute (event, "address", addr_obj) < 0;
> > + if (failed)
> > + goto fail;
> > +
> > + len_obj = PyLong_FromLong (len);
> > + if (len_obj == NULL)
> > + goto fail;
> > + make_cleanup_py_decref (len_obj);
> > +
> > + failed = evpy_add_attribute (event, "length", len_obj) < 0;
> > + if (failed)
> > + goto fail;
> > +
>
> Run the cleanups here as well as for the fail case.
>
> > + return event;
> > +
> > + fail:
> > + do_cleanups (cleanups);
> > + return NULL;
> > +}
> > +
> [...]