]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: add struct ha_caller to describe a calling location
authorWilly Tarreau <w@1wt.eu>
Tue, 6 Sep 2022 05:55:44 +0000 (07:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 8 Sep 2022 12:19:15 +0000 (14:19 +0200)
The purpose of this structure is to assemble all constant parts of a
generic calling point for a specific event. These ones are created by
the compiler as a static const element outside of the code path, so
they cost nothing in terms of CPU, and a pointer to that descriptor
can be passed to the place that needs it. This is very similar to what
is being done for the mem_stat stuff.

This will be useful to simplify and improve DEBUG_TASK.

include/haproxy/bug.h

index 60b24679368d9fd47398fb96b0fab8f537356032..45570027c499a63b8f614888fcfd0b685086176c 100644 (file)
@@ -193,6 +193,23 @@ static inline __attribute((always_inline)) void ha_crash_now(void)
                *__x = NULL;                                            \
        } while (0)
 
+/* describes a call place in the code, for example for tracing memory
+ * allocations or task wakeups. These must be declared static const.
+ */
+struct ha_caller {
+       const char *func;  // function name
+       const char *file;  // file name
+       uint16_t line;     // line number
+       uint8_t what;      // description of the call, usage specific
+       uint8_t arg8;      // optional argument, usage specific
+       uint32_t arg32;    // optional argument, usage specific
+};
+
+#define MK_CALLER(_what, _arg8, _arg32)                                        \
+       ({ static const struct ha_caller _ = {                          \
+               .func = __func__, .file = __FILE__, .line = __LINE__,   \
+               .what = _what, .arg8 = _arg8, .arg32 = _arg32 };        \
+               &_; })
 
 /* handle 'tainted' status */
 enum tainted_flags {