[PATCH] Introduce public dwfl_get_debuginfod_client API

2022-07-07 Thread Milian Wolff
Dwfl can use debuginfod internally, which was so far totally opaque
to the outside. While the functionality is great for users of the
dwfl API, the long wait times induced by downloading of data over
debuginfod lead to complaints by endusers. To offer them a bit more
insight into the internal ongoings, one can now use e.g.
`debuginfod_set_progressfn` on the handle returned by
`dwfl_get_debuginfod_client` to report download progress.

Rename get_client to dwfl_get_debuginfod_client and make it public.
Unconditionally compile debuginfod-client.c and stub the new public
function and always return NULL when debuginfod integration was
disabled.

Signed-off-by: Milian Wolff 
---
 libdw/libdw.map |  5 +
 libdwfl/ChangeLog   |  5 +
 libdwfl/Makefile.am |  5 +
 libdwfl/debuginfod-client.c | 23 ++-
 libdwfl/libdwfl.h   | 10 ++
 libdwfl/libdwflP.h  |  1 +
 6 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/libdw/libdw.map b/libdw/libdw.map
index 4f530378..3fdf3f93 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -366,3 +366,8 @@ ELFUTILS_0.186 {
 dwarf_linecontext;
 dwarf_linefunctionname;
 } ELFUTILS_0.177;
+
+ELFUTILS_0.187 {
+  global:
+dwfl_get_debuginfod_client;
+} ELFUTILS_0.186;
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index b3ca56cb..890df156 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2022-06-22  Milian Wolff 
+
+   * libdwfl.h, debuginfod-client.c (dwfl_get_debuginfod_client):
+   Rename get_client to dwfl_get_debuginfod_client and make it public.
+
 2022-05-15  Mark Wielaard  
 
* libdwfl.h (dwfl_module_addrinfo): Update docs and nonnull
diff --git a/libdwfl/Makefile.am b/libdwfl/Makefile.am
index a0013e41..3278358d 100644
--- a/libdwfl/Makefile.am
+++ b/libdwfl/Makefile.am
@@ -70,7 +70,7 @@ libdwfl_a_SOURCES = dwfl_begin.c dwfl_end.c dwfl_error.c 
dwfl_version.c \
link_map.c core-file.c open.c image-header.c \
dwfl_frame.c frame_unwind.c dwfl_frame_pc.c \
linux-pid-attach.c linux-core-attach.c dwfl_frame_regs.c \
-   gzip.c
+   gzip.c debuginfod-client.c
 
 if BZLIB
 libdwfl_a_SOURCES += bzip2.c
@@ -81,9 +81,6 @@ endif
 if ZSTD
 libdwfl_a_SOURCES += zstd.c
 endif
-if LIBDEBUGINFOD
-libdwfl_a_SOURCES += debuginfod-client.c
-endif
 
 libdwfl = $(libdw)
 libdw = ../libdw/libdw.so
diff --git a/libdwfl/debuginfod-client.c b/libdwfl/debuginfod-client.c
index 153260c3..813043b1 100644
--- a/libdwfl/debuginfod-client.c
+++ b/libdwfl/debuginfod-client.c
@@ -32,6 +32,9 @@
 #endif
 
 #include "libdwflP.h"
+
+#ifdef ENABLE_LIBDEBUGINFOD
+
 #include 
 #include 
 
@@ -46,8 +49,8 @@ static pthread_once_t init_control = PTHREAD_ONCE_INIT;
 
 /* NB: this is slightly thread-unsafe */
 
-static debuginfod_client *
-get_client (Dwfl *dwfl)
+debuginfod_client *
+dwfl_get_debuginfod_client (Dwfl *dwfl)
 {
   if (dwfl->debuginfod != NULL)
 return dwfl->debuginfod;
@@ -71,7 +74,7 @@ __libdwfl_debuginfod_find_executable (Dwfl *dwfl,
   int fd = -1;
   if (build_id_len > 0)
 {
-  debuginfod_client *c = get_client (dwfl);
+  debuginfod_client *c = dwfl_get_debuginfod_client (dwfl);
   if (c != NULL)
fd = (*fp_debuginfod_find_executable) (c, build_id_bits,
   build_id_len, NULL);
@@ -88,7 +91,7 @@ __libdwfl_debuginfod_find_debuginfo (Dwfl *dwfl,
   int fd = -1;
   if (build_id_len > 0)
 {
-  debuginfod_client *c = get_client (dwfl);
+  debuginfod_client *c = dwfl_get_debuginfod_client (dwfl);
   if (c != NULL)
fd = (*fp_debuginfod_find_debuginfo) (c, build_id_bits,
  build_id_len, NULL);
@@ -105,7 +108,7 @@ __libdwfl_debuginfod_end (debuginfod_client *c)
 }
 
 /* Try to get the libdebuginfod library functions.
-   Only needs to be called once from get_client.  */
+   Only needs to be called once from dwfl_get_debuginfod_client.  */
 static void
 __libdwfl_debuginfod_init (void)
 {
@@ -134,3 +137,13 @@ __libdwfl_debuginfod_init (void)
}
 }
 }
+
+#else // ENABLE_LIBDEBUGINFOD
+
+debuginfod_client *
+dwfl_get_debuginfod_client (Dwfl *)
+{
+  return NULL;
+}
+
+#endif // ENABLE_LIBDEBUGINFOD
diff --git a/libdwfl/libdwfl.h b/libdwfl/libdwfl.h
index c55a8eaa..b323e8fb 100644
--- a/libdwfl/libdwfl.h
+++ b/libdwfl/libdwfl.h
@@ -49,6 +49,9 @@ typedef struct Dwfl_Thread Dwfl_Thread;
PC location described by an FDE belonging to Dwfl_Thread.  */
 typedef struct Dwfl_Frame Dwfl_Frame;
 
+/* Handle for debuginfod-client connection.  */
+typedef struct debuginfod_client debuginfod_client;
+
 /* Callbacks.  */
 typedef struct
 {
@@ -795,6 +798,13 @@ int dwfl_getthread_frames (Dwfl *dwfl, pid_t tid,
 bool dwfl_frame_pc (Dwfl_Frame *state, Dwarf_Addr *pc, bool *isactivation)
   __nonnull_attribute__ (1, 2);
 
+/* Return the internal debuginfo

Re: [PATCH] Introduce public dwfl_get_debuginfod_client API

2022-07-07 Thread Aaron Merey via Elfutils-devel
Hi Milian,

On Thu, Jul 7, 2022 at 10:47 AM Milian Wolff  wrote:
>
> Dwfl can use debuginfod internally, which was so far totally opaque
> to the outside. While the functionality is great for users of the
> dwfl API, the long wait times induced by downloading of data over
> debuginfod lead to complaints by endusers. To offer them a bit more
> insight into the internal ongoings, one can now use e.g.
> `debuginfod_set_progressfn` on the handle returned by
> `dwfl_get_debuginfod_client` to report download progress.
>
> Rename get_client to dwfl_get_debuginfod_client and make it public.
> Unconditionally compile debuginfod-client.c and stub the new public
> function and always return NULL when debuginfod integration was
> disabled.

Thanks for the patch. This looks ok and I was able to successfully
run the testsuite with and without debuginfod enabled.

> @@ -70,7 +70,7 @@ libdwfl_a_SOURCES = dwfl_begin.c dwfl_end.c dwfl_error.c
> dwfl_version.c \

Some line breaks may have accidentally snuck into the patch. I had to
manually remove the line break right after "dwfl_error.c" for git to
apply the patch without error.

> +/* Return the internal debuginfod-client connection handle for the DWFL
> session.
> +   When the client connection has not yet been initialized, it will be done
> on the
> +   first call to this function. If elfutils is compiled without support for
> debuginfod,

Same goes for these line breaks.

Aaron



Re: [PATCH] Introduce public dwfl_get_debuginfod_client API

2022-07-07 Thread Milian Wolff
On Donnerstag, 7. Juli 2022 18:40:05 CEST Aaron Merey wrote:
> Hi Milian,
> 
> On Thu, Jul 7, 2022 at 10:47 AM Milian Wolff  wrote:
> > Dwfl can use debuginfod internally, which was so far totally opaque
> > to the outside. While the functionality is great for users of the
> > dwfl API, the long wait times induced by downloading of data over
> > debuginfod lead to complaints by endusers. To offer them a bit more
> > insight into the internal ongoings, one can now use e.g.
> > `debuginfod_set_progressfn` on the handle returned by
> > `dwfl_get_debuginfod_client` to report download progress.
> > 
> > Rename get_client to dwfl_get_debuginfod_client and make it public.
> > Unconditionally compile debuginfod-client.c and stub the new public
> > function and always return NULL when debuginfod integration was
> > disabled.
> 
> Thanks for the patch. This looks ok and I was able to successfully
> run the testsuite with and without debuginfod enabled.
> 
> > @@ -70,7 +70,7 @@ libdwfl_a_SOURCES = dwfl_begin.c dwfl_end.c dwfl_error.c
> > dwfl_version.c \
> 
> Some line breaks may have accidentally snuck into the patch. I had to
> manually remove the line break right after "dwfl_error.c" for git to
> apply the patch without error.

Ah yes sorry, I did not think about that when copy'n'pasting the git format-
patch output into my mail client. Should I resend with the line breaks fixed?

Cheers
-- 
Milian Wolff
m...@milianw.de
http://milianw.de

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH] Introduce public dwfl_get_debuginfod_client API

2022-07-07 Thread Aaron Merey via Elfutils-devel
On Thu, Jul 7, 2022 at 12:59 PM Milian Wolff  wrote:
>
> On Donnerstag, 7. Juli 2022 18:40:05 CEST Aaron Merey wrote:
>>
> > Some line breaks may have accidentally snuck into the patch. I had to
> > manually remove the line break right after "dwfl_error.c" for git to
> > apply the patch without error.
>
> Ah yes sorry, I did not think about that when copy'n'pasting the git format-
> patch output into my mail client. Should I resend with the line breaks fixed?

Sure might as well resend.

Aaron



[PATCH] Introduce public dwfl_get_debuginfod_client API

2022-07-07 Thread Milian Wolff
Dwfl can use debuginfod internally, which was so far totally opaque
to the outside. While the functionality is great for users of the
dwfl API, the long wait times induced by downloading of data over
debuginfod lead to complaints by endusers. To offer them a bit more
insight into the internal ongoings, one can now use e.g.
`debuginfod_set_progressfn` on the handle returned by
`dwfl_get_debuginfod_client` to report download progress.

Rename get_client to dwfl_get_debuginfod_client and make it public.
Unconditionally compile debuginfod-client.c and stub the new public
function and always return NULL when debuginfod integration was
disabled.

Signed-off-by: Milian Wolff 
---
 libdw/libdw.map |  5 +
 libdwfl/ChangeLog   |  5 +
 libdwfl/Makefile.am |  5 +
 libdwfl/debuginfod-client.c | 23 ++-
 libdwfl/libdwfl.h   | 10 ++
 libdwfl/libdwflP.h  |  1 +
 6 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/libdw/libdw.map b/libdw/libdw.map
index 4f530378..3fdf3f93 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -366,3 +366,8 @@ ELFUTILS_0.186 {
 dwarf_linecontext;
 dwarf_linefunctionname;
 } ELFUTILS_0.177;
+
+ELFUTILS_0.187 {
+  global:
+dwfl_get_debuginfod_client;
+} ELFUTILS_0.186;
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index b3ca56cb..890df156 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2022-06-22  Milian Wolff 
+
+   * libdwfl.h, debuginfod-client.c (dwfl_get_debuginfod_client):
+   Rename get_client to dwfl_get_debuginfod_client and make it public.
+
 2022-05-15  Mark Wielaard  
 
* libdwfl.h (dwfl_module_addrinfo): Update docs and nonnull
diff --git a/libdwfl/Makefile.am b/libdwfl/Makefile.am
index a0013e41..3278358d 100644
--- a/libdwfl/Makefile.am
+++ b/libdwfl/Makefile.am
@@ -70,7 +70,7 @@ libdwfl_a_SOURCES = dwfl_begin.c dwfl_end.c dwfl_error.c 
dwfl_version.c \
link_map.c core-file.c open.c image-header.c \
dwfl_frame.c frame_unwind.c dwfl_frame_pc.c \
linux-pid-attach.c linux-core-attach.c dwfl_frame_regs.c \
-   gzip.c
+   gzip.c debuginfod-client.c
 
 if BZLIB
 libdwfl_a_SOURCES += bzip2.c
@@ -81,9 +81,6 @@ endif
 if ZSTD
 libdwfl_a_SOURCES += zstd.c
 endif
-if LIBDEBUGINFOD
-libdwfl_a_SOURCES += debuginfod-client.c
-endif
 
 libdwfl = $(libdw)
 libdw = ../libdw/libdw.so
diff --git a/libdwfl/debuginfod-client.c b/libdwfl/debuginfod-client.c
index 153260c3..813043b1 100644
--- a/libdwfl/debuginfod-client.c
+++ b/libdwfl/debuginfod-client.c
@@ -32,6 +32,9 @@
 #endif
 
 #include "libdwflP.h"
+
+#ifdef ENABLE_LIBDEBUGINFOD
+
 #include 
 #include 
 
@@ -46,8 +49,8 @@ static pthread_once_t init_control = PTHREAD_ONCE_INIT;
 
 /* NB: this is slightly thread-unsafe */
 
-static debuginfod_client *
-get_client (Dwfl *dwfl)
+debuginfod_client *
+dwfl_get_debuginfod_client (Dwfl *dwfl)
 {
   if (dwfl->debuginfod != NULL)
 return dwfl->debuginfod;
@@ -71,7 +74,7 @@ __libdwfl_debuginfod_find_executable (Dwfl *dwfl,
   int fd = -1;
   if (build_id_len > 0)
 {
-  debuginfod_client *c = get_client (dwfl);
+  debuginfod_client *c = dwfl_get_debuginfod_client (dwfl);
   if (c != NULL)
fd = (*fp_debuginfod_find_executable) (c, build_id_bits,
   build_id_len, NULL);
@@ -88,7 +91,7 @@ __libdwfl_debuginfod_find_debuginfo (Dwfl *dwfl,
   int fd = -1;
   if (build_id_len > 0)
 {
-  debuginfod_client *c = get_client (dwfl);
+  debuginfod_client *c = dwfl_get_debuginfod_client (dwfl);
   if (c != NULL)
fd = (*fp_debuginfod_find_debuginfo) (c, build_id_bits,
  build_id_len, NULL);
@@ -105,7 +108,7 @@ __libdwfl_debuginfod_end (debuginfod_client *c)
 }
 
 /* Try to get the libdebuginfod library functions.
-   Only needs to be called once from get_client.  */
+   Only needs to be called once from dwfl_get_debuginfod_client.  */
 static void
 __libdwfl_debuginfod_init (void)
 {
@@ -134,3 +137,13 @@ __libdwfl_debuginfod_init (void)
}
 }
 }
+
+#else // ENABLE_LIBDEBUGINFOD
+
+debuginfod_client *
+dwfl_get_debuginfod_client (Dwfl *)
+{
+  return NULL;
+}
+
+#endif // ENABLE_LIBDEBUGINFOD
diff --git a/libdwfl/libdwfl.h b/libdwfl/libdwfl.h
index c55a8eaa..b323e8fb 100644
--- a/libdwfl/libdwfl.h
+++ b/libdwfl/libdwfl.h
@@ -49,6 +49,9 @@ typedef struct Dwfl_Thread Dwfl_Thread;
PC location described by an FDE belonging to Dwfl_Thread.  */
 typedef struct Dwfl_Frame Dwfl_Frame;
 
+/* Handle for debuginfod-client connection.  */
+typedef struct debuginfod_client debuginfod_client;
+
 /* Callbacks.  */
 typedef struct
 {
@@ -795,6 +798,13 @@ int dwfl_getthread_frames (Dwfl *dwfl, pid_t tid,
 bool dwfl_frame_pc (Dwfl_Frame *state, Dwarf_Addr *pc, bool *isactivation)
   __nonnull_attribute__ (1, 2);
 
+/* Return the internal debuginfo

Re: [PATCH] Introduce public dwfl_get_debuginfod_client API

2022-07-07 Thread Aaron Merey via Elfutils-devel
Thanks. Let's wait for a maintainer to give it the ok before merging.

Aaron