aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2013-07-05 13:50:34 +0100
committerMatt Fleming <matt.fleming@intel.com>2013-07-05 13:50:34 +0100
commit89794a3d0b8659e2a143faeffc77877b45754c52 (patch)
tree06d42da7f6e4f5a5d7f6327a0546459ce966a9a5 /com32/lib
parent27df69de0dea04dfcb6627cc55ffeeb93d698b26 (diff)
parent467666edae5bbdb4ab33ba397b70fe7209a7e633 (diff)
downloadsyslinux-89794a3d0b8659e2a143faeffc77877b45754c52.tar.gz
syslinux-89794a3d0b8659e2a143faeffc77877b45754c52.tar.xz
syslinux-89794a3d0b8659e2a143faeffc77877b45754c52.zip
Merge branch 'dynamic-debug' into elflinksyslinux-5.11-pre8
Diffstat (limited to 'com32/lib')
-rw-r--r--com32/lib/Makefile1
-rw-r--r--com32/lib/syslinux/debug.c95
2 files changed, 96 insertions, 0 deletions
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index a7cfe770..d1b6bf7f 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -176,6 +176,7 @@ CORELIBOBJS = \
libgcc/__negdi2.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o \
libgcc/__muldi3.o libgcc/__udivmoddi4.o libgcc/__umoddi3.o \
libgcc/__divdi3.o libgcc/__moddi3.o \
+ syslinux/debug.o \
$(LIBENTRY_OBJS) \
$(LIBMODULE_OBJS)
diff --git a/com32/lib/syslinux/debug.c b/com32/lib/syslinux/debug.c
new file mode 100644
index 00000000..d9ab863f
--- /dev/null
+++ b/com32/lib/syslinux/debug.c
@@ -0,0 +1,95 @@
+#include <linux/list.h>
+#include <string.h>
+#include <stdbool.h>
+
+#ifdef DYNAMIC_DEBUG
+
+static LIST_HEAD(debug_funcs);
+
+struct debug_func_entry {
+ const char *name;
+ struct list_head list;
+};
+
+static struct debug_func_entry *lookup_entry(const char *func)
+{
+ struct debug_func_entry *e, *entry = NULL;
+
+ list_for_each_entry(e, &debug_funcs, list) {
+ if (!strcmp(e->name, func)) {
+ entry = e;
+ break;
+ }
+ }
+
+ return entry;
+}
+
+bool __syslinux_debug_enabled(const char *func)
+{
+ struct debug_func_entry *entry;
+
+ entry = lookup_entry(func);
+ if (entry)
+ return true;
+
+ return false;
+}
+
+static int __enable(const char *func)
+{
+ struct debug_func_entry *entry;
+
+ entry = lookup_entry(func);
+ if (entry)
+ return 0; /* already enabled */
+
+ entry = malloc(sizeof(*entry));
+ if (!entry)
+ return -1;
+
+ entry->name = func;
+ list_add(&entry->list, &debug_funcs);
+ return 0;
+}
+
+static int __disable(const char *func)
+{
+ struct debug_func_entry *entry;
+
+ entry = lookup_entry(func);
+ if (!entry)
+ return 0; /* already disabled */
+
+ list_del(&entry->list);
+ free(entry);
+ return 0;
+}
+
+/*
+ * Enable or disable debug code for function 'func'.
+ */
+int syslinux_debug(const char *func, bool enable)
+{
+ int rv;
+
+ if (enable)
+ rv = __enable(func);
+ else
+ rv = __disable(func);
+
+ return rv;
+}
+
+#else
+
+int syslinux_debug(const char *func, bool enable)
+{
+ (void)func;
+ (void)enable;
+
+ printf("Dynamic debug unavailable\n");
+ return -1;
+}
+
+#endif /* DYNAMIC_DEBUG */