summaryrefslogtreecommitdiffstats
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
parent27df69de0dea04dfcb6627cc55ffeeb93d698b26 (diff)
parent467666edae5bbdb4ab33ba397b70fe7209a7e633 (diff)
downloadsyslinux-5.11-pre8.tar.gz
Merge branch 'dynamic-debug' into elflinksyslinux-5.11-pre8
-rw-r--r--NEWS4
-rw-r--r--com32/include/dprintf.h10
-rw-r--r--com32/include/syslinux/debug.h15
-rw-r--r--com32/lib/Makefile1
-rw-r--r--com32/lib/syslinux/debug.c95
-rw-r--r--com32/modules/Makefile2
-rw-r--r--com32/modules/debug.c54
-rw-r--r--com32/modules/prdhcp.c4
-rw-r--r--mk/devel.mk1
-rw-r--r--mk/elf.mk2
10 files changed, 182 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 56f9d93d..a1c56177 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ Starting with 1.47, changes marked with SYSLINUX, PXELINUX, ISOLINUX
or EXTLINUX apply to that specific program only; other changes apply
to all derivatives.
+Changes in 5.11:
+ * Dynamic debug support: Add new module, debug.c32, that allows
+ debug code to be dynamically enabled and disabled at runtime.
+
Changes in 5.10:
* PXELINUX: An entirely new network implementation based on
the lwIP embedded TCP/IP stack. As a result, plain PXELINUX
diff --git a/com32/include/dprintf.h b/com32/include/dprintf.h
index 26ca734b..51d5c61d 100644
--- a/com32/include/dprintf.h
+++ b/com32/include/dprintf.h
@@ -5,6 +5,8 @@
#ifndef _DPRINTF_H
#define _DPRINTF_H
+#include <syslinux/debug.h>
+
#if !defined(DEBUG_PORT) && !defined(DEBUG_STDIO)
# undef DEBUG
#endif
@@ -23,8 +25,12 @@ void vdprintf(const char *, va_list);
#else
-# define dprintf(fmt, ...) ((void)(0))
-# define vdprintf(fmt, ap) ((void)(0))
+#define dprintf(...) \
+ if (syslinux_debug_enabled) \
+ printf(__VA_ARGS__)
+#define vdprintf(fmt, ap) \
+ if (syslinux_debug_enabled) \
+ vprintf(fmt, ap)
#endif /* DEBUG */
diff --git a/com32/include/syslinux/debug.h b/com32/include/syslinux/debug.h
new file mode 100644
index 00000000..aee6fdbb
--- /dev/null
+++ b/com32/include/syslinux/debug.h
@@ -0,0 +1,15 @@
+#ifndef DEBUG_H
+#define DEBUG_H
+
+#include <stdbool.h>
+
+#ifdef DYNAMIC_DEBUG
+#define syslinux_debug_enabled __syslinux_debug_enabled(__func__)
+extern bool __syslinux_debug_enabled(const char *func);
+#else
+#define syslinux_debug_enabled (0)
+#endif /* DYNAMIC_DEBUG */
+
+extern int syslinux_debug(const char *str, bool enable);
+
+#endif /* DEBUG_H */
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 */
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index 682e1b22..d801a260 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -25,7 +25,7 @@ MODULES = config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \
kbdmap.c32 cmd.c32 vpdtest.c32 host.c32 ls.c32 gpxecmd.c32 \
ifcpu.c32 cpuid.c32 cat.c32 pwd.c32 ifplop.c32 zzjson.c32 \
whichsys.c32 prdhcp.c32 pxechn.c32 kontron_wdt.c32 ifmemdsk.c32 \
- hexdump.c32 poweroff.c32 cptime.c32
+ hexdump.c32 poweroff.c32 cptime.c32 debug.c32
TESTFILES =
diff --git a/com32/modules/debug.c b/com32/modules/debug.c
new file mode 100644
index 00000000..1026ebf3
--- /dev/null
+++ b/com32/modules/debug.c
@@ -0,0 +1,54 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2013 Intel Corporation; author: Matt Fleming
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston MA 02110-1301, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include <syslinux/debug.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static char *progname;
+
+static void usage(void)
+{
+ fprintf(stderr, "Usage: %s [-e|-d] <func1> [<func2>, ...]\n", progname);
+}
+
+int main(int argc, char *argv[])
+{
+ bool enable;
+ int i;
+
+ progname = argv[0];
+
+ if (argc < 3) {
+ usage();
+ return -1;
+ }
+
+ if (!strncmp(argv[1], "-e", 2))
+ enable = true;
+ else if (!strncmp(argv[1], "-d", 2))
+ enable = false;
+ else {
+ usage();
+ return -1;
+ }
+
+ for (i = 2; i < argc; i++) {
+ char *str = argv[i];
+
+ if (syslinux_debug(str, enable) < 0)
+ fprintf(stderr, "Failed to debug symbol \"%s\"\n", str);
+ }
+
+ return 0;
+}
diff --git a/com32/modules/prdhcp.c b/com32/modules/prdhcp.c
index e1785a03..4ae295e8 100644
--- a/com32/modules/prdhcp.c
+++ b/com32/modules/prdhcp.c
@@ -39,11 +39,11 @@
#include <unistd.h>
#include <getkey.h>
-#define DEBUG 0
+#define PRDHCP_DEBUG 0
#define dprintf0(f, ...) ((void)0)
-#ifdef DEBUG
+#ifdef PRDHCP_DEBUG
# define dpressanykey pressanykey
# define dprintf printf
# define dprint_pxe_bootp_t print_pxe_bootp_t
diff --git a/mk/devel.mk b/mk/devel.mk
index d1a5fff2..041e876e 100644
--- a/mk/devel.mk
+++ b/mk/devel.mk
@@ -2,3 +2,4 @@
GCCWARN += -Wno-clobbered
#GCCWARN += -DDEBUG_MALLOC
# GCCWARN += -DDEBUG_PORT=0x3f8 -DDEBUG=1
+GCCWARN += -DDYNAMIC_DEBUG
diff --git a/mk/elf.mk b/mk/elf.mk
index 109e0a65..8bc6be08 100644
--- a/mk/elf.mk
+++ b/mk/elf.mk
@@ -42,7 +42,7 @@ GPLLIB =
GPLINCLUDE =
endif
-CFLAGS = $(GCCOPT) -W -Wall -march=i386 \
+CFLAGS = $(GCCOPT) $(GCCWARN) -W -Wall -march=i386 \
-fomit-frame-pointer -D__COM32__ -DDYNAMIC_MODULE \
-nostdinc -iwithprefix include \
-I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE) \