[Mesa-dev] [PATCH] glsl/list: Add an exec_list_validate function

Jason Ekstrand jason at jlekstrand.net
Wed Nov 5 17:12:37 PST 2014


On Wed, Nov 5, 2014 at 2:46 PM, Matt Turner <mattst88 at gmail.com> wrote:

> On Wed, Nov 5, 2014 at 2:00 PM, Jason Ekstrand <jason at jlekstrand.net>
> wrote:
> > This can be very useful for trying to debug list corruptions.
> >
> > Signed-off-by: Jason Ekstrand <jason.ekstrand at intel.com>
> > Cc: Ian Romanick <idr at freedesktop.org>
> > ---
> >  src/glsl/list.h | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> >
> > diff --git a/src/glsl/list.h b/src/glsl/list.h
> > index aac13fd..1d18ec9 100644
> > --- a/src/glsl/list.h
> > +++ b/src/glsl/list.h
> > @@ -521,6 +521,20 @@ exec_node_insert_list_before(struct exec_node *n,
> struct exec_list *before)
> >     exec_list_make_empty(before);
> >  }
> >
> > +static inline void
> > +exec_list_validate(struct exec_list *list)
> > +{
> > +   assert(list->head->prev == (struct exec_node *) &list->head);
> > +   assert(list->tail == NULL);
> > +   assert(list->tail_pred->next == (struct exec_node *) &list->tail);
> > +
> > +   for (struct exec_node *node = list->head;
> > +        node->next != NULL; node = node->next) {
>
> Just use foreach_in_list().
>

Sure, I can do that.

> +      assert(node->next->prev == node);
> > +      assert(node->prev->next == node);
> > +   }
> > +}
>
> Are you intending to call this from gdb? I'm having a hard time
> imagining committing code that *sometimes* corrupts lists, which seems
> like why this function would be useful to call from real code.
>

It is useful to call from gdb but I also call it all over nir_validate.c.
I spent most of today fighting linked list corruptions, and this was very
helpful for tracking them down.  Another option would be rename it to
exec_list_is_valid and make it return a bool.  Then the standard procedure
would be "assert(exec_list_is_valid(list))".  Would that be better?


> If you just want to call it from gdb, wrap the whole thing in #ifndef
> NDEBUG. I don't want to ever accidentally call this function and think
> it validated something when it actually did nothing.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141105/ffb6585c/attachment.html>


More information about the mesa-dev mailing list