printk()
Support Macros¶
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -528,4 +528,8 @@ static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
}
#endif
+#define PK() PKR("")
+#define PKS(str) PKR(": %s", str)
+#define PKF(fmt, args...) PKR(": " fmt, ##args)
+#define PKV(fmt, var) PKR(": " #var ": " fmt, var)
+#define PKVB(fmt, var) PKR(": " #var ": [" fmt "]", var)
+#define PKR(fmt, args...) printk(KERN_INFO "ATTIE: %s:%d %s()" fmt, __FILE__, __LINE__, __FUNCTION__, ##args)
+
#endif
Usage:
void fn(void) {
/* just print a message with filename, line and function name */
PK();
/* print a message with a plain string only */
PKS("hello");
/* print a message with a format string and arguments */
int var = 42;
PKF("var: %d", var);
/* print the value of a variable, with a given format
example output: ... fn(): var2: 123 */
int var2 = 123;
PKV("%d", var2);
/* print the value of a variable, bounded with braces (useful for strings!)
example output: ... fn(): var3: [hello ] */
char *var3 = "hello ";
PKVB("%s", var3);
}
User-Space¶
```c tab="pk.h"
ifndef PK_H¶
define PK_H¶
define PK() PKR("")¶
define PKS(str) PKR(": %s", str)¶
define PKF(fmt, args...) PKR(": " fmt, ##args)¶
define PKV(fmt, var) PKR(": " #var ": " fmt, var)¶
define PKVB(fmt, var) PKR(": " #var ": [" fmt "]", var)¶
define PKR(fmt, args...) fprintf(stderr, "ATTIE: %s:%d %s()" fmt "\n", FILE, LINE, FUNCTION, ##args)¶
endif / PK_H /¶
```