This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=2dbfda6cbe5968a98630744a20f8e0f37f13a1d1

commit 2dbfda6cbe5968a98630744a20f8e0f37f13a1d1
Author: Guillem Jover <[email protected]>
AuthorDate: Thu Aug 7 16:47:53 2025 +0200

    libdpkg: Add support for debug_at() to print debug messages at a function
    
    Rename the debug function to debug_print, so that we can add a new
    debug_at macro that prints a debug message with the current function
    name as context. This decouples the function name from the debug messages,
    so that renaming the function does not require touching all such messages,
    and means they will not get out of sync. Using «%s():» makes it more
    clear this is the function the debug message is being emitted from.
---
 lib/dpkg/debug.c     | 7 ++++++-
 lib/dpkg/debug.h     | 8 +++++++-
 lib/dpkg/libdpkg.map | 2 +-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/dpkg/debug.c b/lib/dpkg/debug.c
index 115d45545..660b65a49 100644
--- a/lib/dpkg/debug.c
+++ b/lib/dpkg/debug.c
@@ -98,9 +98,12 @@ debug_has_flag(int flag)
  *
  * The message will be printed to the previously specified output if the
  * specified flag is present in the current debugging mask.
+ *
+ * It can print the caller function name or a context name when passed
+ * in the @fn argument.
  */
 void
-debug(int flag, const char *fmt, ...)
+debug_print(int flag, const char *fn, const char *fmt, ...)
 {
        va_list args;
 
@@ -108,6 +111,8 @@ debug(int flag, const char *fmt, ...)
                return;
 
        fprintf(debug_output, "D0%05o: ", flag);
+       if (fn)
+               fprintf(debug_output, "%s(): ", fn);
        va_start(args, fmt);
        vfprintf(debug_output, fmt, args);
        va_end(args);
diff --git a/lib/dpkg/debug.h b/lib/dpkg/debug.h
index be4efacfa..111754b5c 100644
--- a/lib/dpkg/debug.h
+++ b/lib/dpkg/debug.h
@@ -59,7 +59,13 @@ void debug_set_output(FILE *output, const char *filename);
 void debug_set_mask(int mask);
 int debug_parse_mask(const char *str);
 bool debug_has_flag(int flag);
-void debug(int flag, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
+void
+debug_print(int flag, const char *fn, const char *fmt, ...)
+       DPKG_ATTR_PRINTF(3);
+#define debug(flag, ...) \
+       debug_print(flag, DPKG_NULL, __VA_ARGS__)
+#define debug_at(flag, ...) \
+       debug_print(flag, __func__, __VA_ARGS__)
 
 /** @} */
 
diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map
index 01033c821..7b5da5b53 100644
--- a/lib/dpkg/libdpkg.map
+++ b/lib/dpkg/libdpkg.map
@@ -75,7 +75,7 @@ LIBDPKG_PRIVATE {
        debug_set_mask;
        debug_parse_mask;
        debug_has_flag;
-       debug;
+       debug_print;
        dpkg_debug_init;
 
        # Generic cleanup

-- 
Dpkg.Org's dpkg

Reply via email to