On Sun, Jan 19, 2025 at 10:20:29PM -0500, Aaron Merey wrote:
>       * libdw/dwarf_filesrc.c (dwarf_filesrc): Use dwarf_lock.

I didn't got this patch till I saw 06/15 Add Dwarf member to
Dwarf_Lines and Dwarf_Files. So this patch should at least come after
that.

In general I find it a little difficult to understand the locking of
the Dwarf_Lines and Dwarf_Files structure of a Dwarf. Maybe some of
these patches need reordering and maybe squashing?

> diff --git a/libdw/dwarf_filesrc.c b/libdw/dwarf_filesrc.c
> index d866ce72..a0881f36 100644
> --- a/libdw/dwarf_filesrc.c
> +++ b/libdw/dwarf_filesrc.c
> @@ -38,14 +38,23 @@ const char *
>  dwarf_filesrc (Dwarf_Files *file, size_t idx, Dwarf_Word *mtime,
>              Dwarf_Word *length)
>  {
> -  if (file == NULL || idx >= file->nfiles)
> +  if (file == NULL)
>      return NULL;
>  
> +  mutex_lock (file->dbg->dwarf_lock);
> +  if (idx >= file->nfiles)
> +    {
> +      mutex_unlock (file->dbg->dwarf_lock);
> +      return NULL;
> +    }
> +
>    if (mtime != NULL)
>      *mtime = file->info[idx].mtime;
>  
>    if (length != NULL)
>      *length = file->info[idx].length;
>  
> -  return file->info[idx].name;
> +  const char *res = file->info[idx].name;
> +  mutex_unlock (file->dbg->dwarf_lock);
> +  return res;
>  }

If Dwarf_Files had a Dwarf dbg field then this should work
(locally). But I need to read the other patches to see if there are
any interactions.

Cheers,

Mark

Reply via email to