Skip to content

Commit f7030bb

Browse files
committed
kdb: Allow kernel loadable modules to add kdb shell functions
In order to allow kernel modules to dynamically add a command to the kdb shell the kdb_register, kdb_register_repeat, kdb_unregister, and kdb_printf need to be exported as GPL symbols. Any kernel module that adds a dynamic kdb shell function should only need to include linux/kdb.h. Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
1 parent fb70b58 commit f7030bb

4 files changed

Lines changed: 48 additions & 40 deletions

File tree

‎include/linux/kdb.h‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,41 @@ extern int kdb_poll_idx;
2828
extern int kdb_initial_cpu;
2929
extern atomic_t kdb_event;
3030

31+
/* Types and messages used for dynamically added kdb shell commands */
32+
33+
#define KDB_MAXARGS 16 /* Maximum number of arguments to a function */
34+
35+
typedef enum {
36+
KDB_REPEAT_NONE = 0, /* Do not repeat this command */
37+
KDB_REPEAT_NO_ARGS, /* Repeat the command without arguments */
38+
KDB_REPEAT_WITH_ARGS, /* Repeat the command including its arguments */
39+
} kdb_repeat_t;
40+
41+
typedef int (*kdb_func_t)(int, const char **);
42+
43+
/* KDB return codes from a command or internal kdb function */
44+
#define KDB_NOTFOUND (-1)
45+
#define KDB_ARGCOUNT (-2)
46+
#define KDB_BADWIDTH (-3)
47+
#define KDB_BADRADIX (-4)
48+
#define KDB_NOTENV (-5)
49+
#define KDB_NOENVVALUE (-6)
50+
#define KDB_NOTIMP (-7)
51+
#define KDB_ENVFULL (-8)
52+
#define KDB_ENVBUFFULL (-9)
53+
#define KDB_TOOMANYBPT (-10)
54+
#define KDB_TOOMANYDBREGS (-11)
55+
#define KDB_DUPBPT (-12)
56+
#define KDB_BPTNOTFOUND (-13)
57+
#define KDB_BADMODE (-14)
58+
#define KDB_BADINT (-15)
59+
#define KDB_INVADDRFMT (-16)
60+
#define KDB_BADREG (-17)
61+
#define KDB_BADCPUNUM (-18)
62+
#define KDB_BADLENGTH (-19)
63+
#define KDB_NOBP (-20)
64+
#define KDB_BADADDR (-21)
65+
3166
/*
3267
* kdb_diemsg
3368
*
@@ -105,9 +140,17 @@ int kdb_process_cpu(const struct task_struct *p)
105140
/* kdb access to register set for stack dumping */
106141
extern struct pt_regs *kdb_current_regs;
107142

143+
/* Dynamic kdb shell command registration */
144+
extern int kdb_register(char *, kdb_func_t, char *, char *, short);
145+
extern int kdb_register_repeat(char *, kdb_func_t, char *, char *,
146+
short, kdb_repeat_t);
147+
extern int kdb_unregister(char *);
108148
#else /* ! CONFIG_KGDB_KDB */
109149
#define kdb_printf(...)
110150
#define kdb_init(x)
151+
#define kdb_register(...)
152+
#define kdb_register_repeat(...)
153+
#define kdb_uregister(x)
111154
#endif /* CONFIG_KGDB_KDB */
112155
enum {
113156
KDB_NOT_INITIALIZED,

‎kernel/debug/kdb/kdb_io.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,4 +823,4 @@ int kdb_printf(const char *fmt, ...)
823823

824824
return r;
825825
}
826-
826+
EXPORT_SYMBOL_GPL(kdb_printf);

‎kernel/debug/kdb/kdb_main.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,6 +2783,8 @@ int kdb_register_repeat(char *cmd,
27832783

27842784
return 0;
27852785
}
2786+
EXPORT_SYMBOL_GPL(kdb_register_repeat);
2787+
27862788

27872789
/*
27882790
* kdb_register - Compatibility register function for commands that do
@@ -2805,6 +2807,7 @@ int kdb_register(char *cmd,
28052807
return kdb_register_repeat(cmd, func, usage, help, minlen,
28062808
KDB_REPEAT_NONE);
28072809
}
2810+
EXPORT_SYMBOL_GPL(kdb_register);
28082811

28092812
/*
28102813
* kdb_unregister - This function is used to unregister a kernel
@@ -2833,6 +2836,7 @@ int kdb_unregister(char *cmd)
28332836
/* Couldn't find it. */
28342837
return 1;
28352838
}
2839+
EXPORT_SYMBOL_GPL(kdb_unregister);
28362840

28372841
/* Initialize the kdb command table. */
28382842
static void __init kdb_inittab(void)

‎kernel/debug/kdb/kdb_private.h‎

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,6 @@
1515
#include <linux/kgdb.h>
1616
#include "../debug_core.h"
1717

18-
/* Kernel Debugger Error codes. Must not overlap with command codes. */
19-
#define KDB_NOTFOUND (-1)
20-
#define KDB_ARGCOUNT (-2)
21-
#define KDB_BADWIDTH (-3)
22-
#define KDB_BADRADIX (-4)
23-
#define KDB_NOTENV (-5)
24-
#define KDB_NOENVVALUE (-6)
25-
#define KDB_NOTIMP (-7)
26-
#define KDB_ENVFULL (-8)
27-
#define KDB_ENVBUFFULL (-9)
28-
#define KDB_TOOMANYBPT (-10)
29-
#define KDB_TOOMANYDBREGS (-11)
30-
#define KDB_DUPBPT (-12)
31-
#define KDB_BPTNOTFOUND (-13)
32-
#define KDB_BADMODE (-14)
33-
#define KDB_BADINT (-15)
34-
#define KDB_INVADDRFMT (-16)
35-
#define KDB_BADREG (-17)
36-
#define KDB_BADCPUNUM (-18)
37-
#define KDB_BADLENGTH (-19)
38-
#define KDB_NOBP (-20)
39-
#define KDB_BADADDR (-21)
40-
4118
/* Kernel Debugger Command codes. Must not overlap with error codes. */
4219
#define KDB_CMD_GO (-1001)
4320
#define KDB_CMD_CPU (-1002)
@@ -93,17 +70,6 @@
9370
*/
9471
#define KDB_MAXBPT 16
9572

96-
/* Maximum number of arguments to a function */
97-
#define KDB_MAXARGS 16
98-
99-
typedef enum {
100-
KDB_REPEAT_NONE = 0, /* Do not repeat this command */
101-
KDB_REPEAT_NO_ARGS, /* Repeat the command without arguments */
102-
KDB_REPEAT_WITH_ARGS, /* Repeat the command including its arguments */
103-
} kdb_repeat_t;
104-
105-
typedef int (*kdb_func_t)(int, const char **);
106-
10773
/* Symbol table format returned by kallsyms. */
10874
typedef struct __ksymtab {
10975
unsigned long value; /* Address of symbol */
@@ -123,11 +89,6 @@ extern int kallsyms_symbol_next(char *prefix_name, int flag);
12389
extern int kallsyms_symbol_complete(char *prefix_name, int max_len);
12490

12591
/* Exported Symbols for kernel loadable modules to use. */
126-
extern int kdb_register(char *, kdb_func_t, char *, char *, short);
127-
extern int kdb_register_repeat(char *, kdb_func_t, char *, char *,
128-
short, kdb_repeat_t);
129-
extern int kdb_unregister(char *);
130-
13192
extern int kdb_getarea_size(void *, unsigned long, size_t);
13293
extern int kdb_putarea_size(unsigned long, void *, size_t);
13394

0 commit comments

Comments
 (0)