[03/15] dwarf_filesrc.c: Add locking

Message ID 20250120032041.280173-3-amerey@redhat.com
State Superseded
Headers
Series [01/15] Add eu_search_tree_init |

Commit Message

Aaron Merey Jan. 20, 2025, 3:20 a.m. UTC
  * libdw/dwarf_filesrc.c (dwarf_filesrc): Use dwarf_lock.

Signed-off-by: Aaron Merey <amerey@redhat.com>

---
 libdw/dwarf_filesrc.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
  

Comments

Mark Wielaard Jan. 22, 2025, 10:10 p.m. UTC | #1
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
  
Aaron Merey Jan. 24, 2025, 2:14 a.m. UTC | #2
Hi Mark,

On Wed, Jan 22, 2025 at 5:10 PM Mark Wielaard <mark@klomp.org> wrote:
>
> 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.

Apologies, this patch should have been included after 06/15.  I will
address this in v2.

Aaron
  

Patch

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;
 }