#define UK_S_ARG_FMT_LONGX(type, arg) "(" STRINGIFY(type) ") 0x%lx"
#define __UK_SYSCALL_PRINTD(x, rtype, fname, ...) \
- _uk_printd(__STR_LIBNAME__, __STR_BASENAME__, __LINE__, \
+ _uk_printd(uk_libid_self(), __STR_BASENAME__, __LINE__, \
"(" STRINGIFY(rtype) ") " STRINGIFY(fname) \
"(" UK_ARG_FMT_MAPx(x, UK_S_ARG_FMT_LONGX, __VA_ARGS__) ")\n" \
UK_ARG_EMAPx(x, UK_S_ARG_CAST_LONG, __VA_ARGS__) )
_uk_syscall_return_addr = r->rip;
#if CONFIG_LIBSYSCALL_SHIM_DEBUG_HANDLER
- _uk_printd(__STR_LIBNAME__, __STR_BASENAME__, __LINE__,
+ _uk_printd(uk_libid_self(), __STR_BASENAME__, __LINE__,
"Binary system call request \"%s\" (%lu) at ip:%p (arg0=0x%lx, arg1=0x%lx, ...)\n",
uk_syscall_name(r->rsyscall), r->rsyscall,
(void *) r->rip, r->rarg0, r->rarg1);
menuconfig LIBUKDEBUG
bool "ukdebug: Debugging and tracing"
depends on (HAVE_LIBC || LIBNOLIBC)
+ select LIBUKLIBID
default y
if LIBUKDEBUG
#error No supported disassembler backend available.
#endif /* CONFIG_LIBZYDIS */
-void _uk_asmdumpd(const char *libname, const char *srcname,
+void _uk_asmdumpd(__u16 libid, const char *srcname,
unsigned int srcline, const void *instr,
unsigned int instr_count)
{
struct out_dev o;
- out_dev_init_debug(&o, libname, srcname, srcline);
+ out_dev_init_debug(&o, libid, srcname, srcline);
_asmdump(&o, instr, instr_count);
}
-void _uk_asmndumpd(const char *libname, const char *srcname,
+void _uk_asmndumpd(__u16 libid, const char *srcname,
unsigned int srcline, const void *instr,
size_t len)
{
struct out_dev o;
- out_dev_init_debug(&o, libname, srcname, srcline);
+ out_dev_init_debug(&o, libid, srcname, srcline);
_asmndump(&o, instr, len);
}
#if CONFIG_LIBUKDEBUG_PRINTK
-void _uk_asmdumpk(int lvl, const char *libname,
+void _uk_asmdumpk(int lvl, __u16 libid,
const char *srcname, unsigned int srcline,
const void *instr, unsigned int instr_count)
{
struct out_dev o;
- out_dev_init_kern(&o, lvl, libname, srcname, srcline);
+ out_dev_init_kern(&o, lvl, libid, srcname, srcline);
_asmdump(&o, instr, instr_count);
}
-void _uk_asmndumpk(int lvl, const char *libname,
+void _uk_asmndumpk(int lvl, __u16 libid,
const char *srcname, unsigned int srcline,
const void *instr, size_t len)
{
struct out_dev o;
- out_dev_init_kern(&o, lvl, libname, srcname, srcline);
+ out_dev_init_kern(&o, lvl, libid, srcname, srcline);
_asmndump(&o, instr, len);
}
#endif /* CONFIG_LIBUKDEBUG_PRINTK */
return _hxd(&o, data, len, addr0, flags, grps_per_line, line_prefix);
}
-void _uk_hexdumpd(const char *libname, const char *srcname,
+void _uk_hexdumpd(__u16 libid, const char *srcname,
unsigned int srcline, const void *data, size_t len,
size_t addr0, int flags, unsigned int grps_per_line,
const char *line_prefix)
{
struct out_dev o;
- out_dev_init_debug(&o, libname, srcname, srcline);
+ out_dev_init_debug(&o, libid, srcname, srcline);
_hxd(&o, data, len, addr0, flags, grps_per_line, line_prefix);
}
#if CONFIG_LIBUKDEBUG_PRINTK
-void _uk_hexdumpk(int lvl, const char *libname, const char *srcname,
+void _uk_hexdumpk(int lvl, __u16 libid, const char *srcname,
unsigned int srcline, const void *data, size_t len,
size_t addr0, int flags, unsigned int grps_per_line,
const char *line_prefix)
{
struct out_dev o;
- out_dev_init_kern(&o, lvl, libname, srcname, srcline);
+ out_dev_init_kern(&o, lvl, libid, srcname, srcline);
_hxd(&o, data, len, addr0, flags, grps_per_line, line_prefix);
}
#endif
*/
#include <stdio.h>
+#include <uk/arch/types.h>
#include <uk/print.h>
#ifdef __cplusplus
#if (defined UK_DEBUG) || CONFIG_LIBUKDEBUG_PRINTD
/* Please use uk_asmdumpd() instead */
-void _uk_asmdumpd(const char *libname, const char *srcname,
+void _uk_asmdumpd(__u16 libid, const char *srcname,
unsigned int srcline, const void *instr,
unsigned int instr_count);
#define uk_asmdumpd(instr, instr_count) \
- _uk_asmdumpd(__STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_asmdumpd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (instr), (instr_count))
-void _uk_asmndumpd(const char *libname, const char *srcname,
+void _uk_asmndumpd(__u16 libid, const char *srcname,
unsigned int srcline, const void *instr,
size_t len);
#define uk_asmndumpd(instr, len) \
- _uk_asmndumpd(__STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_asmndumpd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (instr), (len))
#else /* (defined UK_DEBUG) || CONFIG_LIBUKDEBUG_PRINTD */
static inline void uk_asmdumpd(const void *instr __unused,
#if CONFIG_LIBUKDEBUG_PRINTK
/* Please use uk_asmdumpk() instead */
-void _uk_asmdumpk(int lvl, const char *libname, const char *srcname,
+void _uk_asmdumpk(int lvl, __u16 libid, const char *srcname,
unsigned int srcline, const void *instr,
unsigned int instr_count);
#define uk_asmdumpk(lvl, instr, instr_count) \
do { \
if ((lvl) <= KLVL_MAX) \
- _uk_asmdumpk((lvl), __STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_asmdumpk((lvl), uk_libid_self(), __STR_BASENAME__, \
__LINE__, (instr), (instr_count)); \
} while (0)
-void _uk_asmndumpk(int lvl, const char *libname, const char *srcname,
+void _uk_asmndumpk(int lvl, __u16 libid, const char *srcname,
unsigned int srcline, const void *instr,
size_t len);
#define uk_asmndumpk(lvl, instr, len) \
do { \
if ((lvl) <= KLVL_MAX) \
- _uk_asmdumpk((lvl), __STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_asmdumpk((lvl), uk_libid_self(), __STR_BASENAME__, \
__LINE__, (instr), (len)); \
} while (0)
#else /* CONFIG_LIBUKDEBUG_PRINTK */
#define __UKDEBUG_HEXDUMP_H__
#include <stdio.h>
+#include <uk/arch/types.h>
#include <uk/print.h>
#ifdef __cplusplus
#if (defined UK_DEBUG) || CONFIG_LIBUKDEBUG_PRINTD
/* Please use uk_hexdumpd() instead */
-void _uk_hexdumpd(const char *libname, const char *srcname,
+void _uk_hexdumpd(__u16 libid, const char *srcname,
unsigned int srcline, const void *data, size_t len,
size_t addr0, int flags, unsigned int grps_per_line,
const char *line_prefix);
* @return Returns the number of printed characters to output fp
*/
#define uk_hexdumpd(data, len, flags, grps_per_line) \
- _uk_hexdumpd(__STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_hexdumpd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (data), (len), \
((size_t)(data)), (flags), \
(grps_per_line), STRINGIFY(data) ": ")
#if CONFIG_LIBUKDEBUG_PRINTK
/* Please use uk_hexdumpk() instead */
-void _uk_hexdumpk(int lvl, const char *libname, const char *srcname,
+void _uk_hexdumpk(int lvl, __u16 libid, const char *srcname,
unsigned int srcline, const void *data, size_t len,
size_t addr0, int flags, unsigned int grps_per_line,
const char *line_prefix);
#define uk_hexdumpk(lvl, data, len, flags, grps_per_line) \
do { \
if ((lvl) <= KLVL_MAX) \
- _uk_hexdumpk((lvl), __STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_hexdumpk((lvl), uk_libid_self(), __STR_BASENAME__, \
__LINE__, (data), (len), \
((size_t)(data)), (flags), \
(grps_per_line), STRINGIFY(data) ": "); \
#define __UKDEBUG_PRINT_H__
#include <stdarg.h>
+#include <uk/libid.h>
#include <uk/arch/lcpu.h>
#include <uk/essentials.h>
#include <uk/config.h>
extern "C" {
#endif
-#ifdef __LIBNAME__
-#define __STR_LIBNAME__ STRINGIFY(__LIBNAME__)
-#else
-#define __STR_LIBNAME__ (NULL)
-#endif
-
#ifdef __BASENAME__
#define __STR_BASENAME__ STRINGIFY(__BASENAME__)
#else
* by other libraries with an own debug print switch
* (e.g., hexdump, syscall_shim)
*/
-void _uk_vprintd(const char *libname, const char *srcname,
+void _uk_vprintd(__u16 libid, const char *srcname,
unsigned int srcline, const char *fmt, va_list ap);
-void _uk_printd(const char *libname, const char *srcname,
+void _uk_printd(__u16 libid, const char *srcname,
unsigned int srcline, const char *fmt, ...) __printf(4, 5);
#ifdef __IN_LIBUKDEBUG__
#if defined UK_DEBUG || CONFIG_LIBUKDEBUG_PRINTD
#define uk_vprintd(fmt, ap) \
do { \
- _uk_vprintd(__STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_vprintd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ap); \
} while (0)
do { \
static int __x; \
if (unlikely(!__x)) { \
- _uk_vprintd(__STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_vprintd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ap); \
__x = 1; \
} \
#define uk_printd(fmt, ...) \
do { \
- _uk_printd(__STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_printd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ##__VA_ARGS__); \
} while (0)
do { \
static int __x; \
if (unlikely(!__x)) { \
- _uk_printd(__STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_printd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ##__VA_ARGS__); \
__x = 1; \
} \
* they compile in the function calls only if the configured
* debug level requires it
*/
-void _uk_vprintk(int lvl, const char *libname, const char *srcname,
+void _uk_vprintk(int lvl, __u16 libid, const char *srcname,
unsigned int srcline, const char *fmt, va_list ap);
-void _uk_printk(int lvl, const char *libname, const char *srcname,
+void _uk_printk(int lvl, __u16 libid, const char *srcname,
unsigned int srcline, const char *fmt, ...) __printf(5, 6);
#define uk_vprintk(lvl, fmt, ap) \
do { \
if ((lvl) <= KLVL_MAX) \
- _uk_vprintk((lvl), __STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_vprintk((lvl), uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ap); \
} while (0)
if ((lvl) <= KLVL_MAX) { \
static int __x; \
if (unlikely(!__x)) { \
- _uk_vprintk((lvl), __STR_LIBNAME__, \
+ _uk_vprintk((lvl), uk_libid_self(), \
__STR_BASENAME__, \
__LINE__, (fmt), ap); \
__x = 1; \
#define uk_printk(lvl, fmt, ...) \
do { \
if ((lvl) <= KLVL_MAX) \
- _uk_printk((lvl), __STR_LIBNAME__, __STR_BASENAME__, \
+ _uk_printk((lvl), uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ##__VA_ARGS__); \
} while (0)
if ((lvl) <= KLVL_MAX) { \
static int __x; \
if (unlikely(!__x)) { \
- _uk_printk((lvl), __STR_LIBNAME__, \
+ _uk_printk((lvl), uk_libid_self(), \
__STR_BASENAME__, \
__LINE__, (fmt), ##__VA_ARGS__); \
__x = 1; \
}
break;
case OUTDEV_DEBUG:
- _uk_vprintd(dev->uk_pr.libname,
+ _uk_vprintd(dev->uk_pr.libid,
dev->uk_pr.srcname, dev->uk_pr.srcline,
fmt, ap);
break;
#if CONFIG_LIBUKDEBUG_PRINTK
case OUTDEV_KERN:
- _uk_vprintk(dev->uk_pr.lvl, dev->uk_pr.libname,
+ _uk_vprintk(dev->uk_pr.lvl, dev->uk_pr.libid,
dev->uk_pr.srcname, dev->uk_pr.srcline,
fmt, ap);
break;
#include <uk/config.h>
#include <inttypes.h>
#include <stdio.h>
+#include <uk/libid.h>
enum out_dev_type {
OUTDEV_FILE = 0,
/* OUTDEV_KERN, OUTDEV_DEBUG */
struct {
int lvl; /* OUTDEV_KERN only */
- const char *libname;
+ __u16 libid;
const char *srcname;
unsigned int srcline;
} uk_pr;
} while (0)
#if CONFIG_LIBUKDEBUG_PRINTK
-#define out_dev_init_kern(dev, lvl, libname, srcname, srcline) \
+#define out_dev_init_kern(dev, lvl, libid, srcname, srcline) \
do { \
(dev)->type = OUTDEV_KERN; \
(dev)->uk_pr.lvl = (lvl); \
- (dev)->uk_pr.libname = (libname); \
+ (dev)->uk_pr.libid = (libid); \
(dev)->uk_pr.srcname = (srcname); \
(dev)->uk_pr.srcline = (srcline); \
} while (0)
#endif
-#define out_dev_init_debug(dev, libname, srcname, srcline) \
+#define out_dev_init_debug(dev, libid, srcname, srcline) \
do { \
(dev)->type = OUTDEV_DEBUG; \
- (dev)->uk_pr.libname = (libname); \
+ (dev)->uk_pr.libid = (libid); \
(dev)->uk_pr.srcname = (srcname); \
(dev)->uk_pr.srcline = (srcline); \
} while (0)
#endif /* CONFIG_LIBUKDEBUG_PRINT_CALLER */
static void _vprint(struct _vprint_console *cons,
- int lvl, const char *libname,
+ int lvl, __u16 libid,
#if CONFIG_LIBUKDEBUG_PRINT_SRCNAME
const char *srcname,
unsigned int srcline,
const char *msghdr = NULL;
const char *lptr = NULL;
const char *nlptr = NULL;
+ const char *libname = uk_libname(libid);
/*
* Note: We reset the console colors earlier in order to exclude
#define _VPRINT_ARGS_CALLER()
#endif /* CONFIG_LIBUKDEBUG_PRINT_CALLER */
-void _uk_vprintd(const char *libname, const char *srcname __maybe_unused,
+void _uk_vprintd(__u16 libid, const char *srcname __maybe_unused,
unsigned int srcline __maybe_unused, const char *fmt,
va_list ap)
{
#if CONFIG_LIBUKDEBUG_REDIR_PRINTD
- _vprint(&kern, KLVL_DEBUG, libname,
+ _vprint(&kern, KLVL_DEBUG, libid,
_VPRINT_ARGS_SRCNAME(srcname, srcline)
_VPRINT_ARGS_CALLER()
fmt, ap);
#else
- _vprint(&debug, KLVL_DEBUG, libname,
+ _vprint(&debug, KLVL_DEBUG, libid,
_VPRINT_ARGS_SRCNAME(srcname, srcline)
_VPRINT_ARGS_CALLER()
fmt, ap);
#endif /* !CONFIG_LIBUKDEBUG_REDIR_PRINTD */
}
-void _uk_printd(const char *libname, const char *srcname __maybe_unused,
+void _uk_printd(__u16 libid, const char *srcname __maybe_unused,
unsigned int srcline __maybe_unused, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
#if CONFIG_LIBUKDEBUG_REDIR_PRINTD
- _vprint(&kern, KLVL_DEBUG, libname,
+ _vprint(&kern, KLVL_DEBUG, libid,
_VPRINT_ARGS_SRCNAME(srcname, srcline)
_VPRINT_ARGS_CALLER()
fmt, ap);
#else
- _vprint(&debug, KLVL_DEBUG, libname,
+ _vprint(&debug, KLVL_DEBUG, libid,
_VPRINT_ARGS_SRCNAME(srcname, srcline)
_VPRINT_ARGS_CALLER()
fmt, ap);
* enabled.
*/
#if CONFIG_LIBUKDEBUG_PRINTK
-void _uk_vprintk(int lvl, const char *libname,
+void _uk_vprintk(int lvl, __u16 libid,
const char *srcname __maybe_unused,
unsigned int srcline __maybe_unused,
const char *fmt, va_list ap)
{
#if CONFIG_LIBUKDEBUG_REDIR_PRINTK
- _vprint(&debug, lvl, libname,
+ _vprint(&debug, lvl, libid,
_VPRINT_ARGS_SRCNAME(srcname, srcline)
_VPRINT_ARGS_CALLER()
fmt, ap);
#else
- _vprint(&kern, lvl, libname,
+ _vprint(&kern, lvl, libid,
_VPRINT_ARGS_SRCNAME(srcname, srcline)
_VPRINT_ARGS_CALLER()
fmt, ap);
#endif /* !CONFIG_LIBUKDEBUG_REDIR_PRINTK */
}
-void _uk_printk(int lvl, const char *libname,
+void _uk_printk(int lvl, __u16 libid,
const char *srcname __maybe_unused,
unsigned int srcline __maybe_unused,
const char *fmt, ...)
va_start(ap, fmt);
#if CONFIG_LIBUKDEBUG_REDIR_PRINTK
- _vprint(&debug, lvl, libname,
+ _vprint(&debug, lvl, libid,
_VPRINT_ARGS_SRCNAME(srcname, srcline)
_VPRINT_ARGS_CALLER()
fmt, ap);
#else
- _vprint(&kern, lvl, libname,
+ _vprint(&kern, lvl, libid,
_VPRINT_ARGS_SRCNAME(srcname, srcline)
_VPRINT_ARGS_CALLER()
fmt, ap);
config LIBUKLIBID
bool "uklibid: Library identifier"
default n
- select LIBUKDEBUG
+ # FIXME: We actually depend on <uk/assert.h> but lib/ukdebug also
+ # depends on us. If we specify the dependency here, it creates a
+ # circular dependency that KConfig doesn't like. However, we
+ # can currently assume that lib/ukdebug is always part of a
+ # build, so we comment out the dependency here. Of course, this
+ # is not accurate.
+ #select LIBUKDEBUG
/* Custom print method. */
#define uk_test_printf(fmt, ...) \
- _uk_printk(KLVL_INFO, __NULL, __NULL, 0x0, \
+ _uk_printk(KLVL_INFO, UKLIBID_NONE, __NULL, 0x0, \
"\t" fmt, ##__VA_ARGS__)
#endif /* CONFIG_LIBUKTEST_LOG_STATS */
#ifdef CONFIG_LIBUKTEST_LOG_TESTS
- _uk_printk(KLVL_INFO, __NULL, __NULL, 0x0,
- (LVLC_TESTNAME "test:" UK_ANSI_MOD_RESET
- " %s->%s"), suite->name, esac->name);
+ _uk_printk(KLVL_INFO, UKLIBID_NONE, __NULL, 0x0,
+ (LVLC_TESTNAME "test:" UK_ANSI_MOD_RESET
+ " %s->%s"), suite->name, esac->name);
if (esac->desc != NULL)
- _uk_printk(KLVL_INFO, __NULL, __NULL, 0x0, ": %s\n",
- esac->desc);
+ _uk_printk(KLVL_INFO, UKLIBID_NONE, __NULL, 0x0,
+ ": %s\n", esac->desc);
else
- _uk_printk(KLVL_INFO, __NULL, __NULL, 0x0, "\n");
+ _uk_printk(KLVL_INFO, UKLIBID_NONE, __NULL, 0x0, "\n");
#endif /* CONFIG_LIBUKTEST_LOG_TESTS */
esac->func(esac);