aboutsummaryrefslogtreecommitdiff
path: root/com32/lib/syslinux/debug.c
blob: d9ab863fc74aecfa991173dd68548392b47bda1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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 */