Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7030bbc authored by Jason Wessel's avatar Jason Wessel
Browse files

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: default avatarJason Wessel <jason.wessel@windriver.com>
parent fb70b588
Loading
Loading
Loading
Loading
+43 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,41 @@ extern int kdb_poll_idx;
extern int kdb_initial_cpu;
extern int kdb_initial_cpu;
extern atomic_t kdb_event;
extern atomic_t kdb_event;


/* Types and messages used for dynamically added kdb shell commands */

#define KDB_MAXARGS    16 /* Maximum number of arguments to a function  */

typedef enum {
	KDB_REPEAT_NONE = 0,	/* Do not repeat this command */
	KDB_REPEAT_NO_ARGS,	/* Repeat the command without arguments */
	KDB_REPEAT_WITH_ARGS,	/* Repeat the command including its arguments */
} kdb_repeat_t;

typedef int (*kdb_func_t)(int, const char **);

/* KDB return codes from a command or internal kdb function */
#define KDB_NOTFOUND	(-1)
#define KDB_ARGCOUNT	(-2)
#define KDB_BADWIDTH	(-3)
#define KDB_BADRADIX	(-4)
#define KDB_NOTENV	(-5)
#define KDB_NOENVVALUE	(-6)
#define KDB_NOTIMP	(-7)
#define KDB_ENVFULL	(-8)
#define KDB_ENVBUFFULL	(-9)
#define KDB_TOOMANYBPT	(-10)
#define KDB_TOOMANYDBREGS (-11)
#define KDB_DUPBPT	(-12)
#define KDB_BPTNOTFOUND	(-13)
#define KDB_BADMODE	(-14)
#define KDB_BADINT	(-15)
#define KDB_INVADDRFMT  (-16)
#define KDB_BADREG      (-17)
#define KDB_BADCPUNUM   (-18)
#define KDB_BADLENGTH	(-19)
#define KDB_NOBP	(-20)
#define KDB_BADADDR	(-21)

/*
/*
 * kdb_diemsg
 * kdb_diemsg
 *
 *
@@ -105,9 +140,17 @@ int kdb_process_cpu(const struct task_struct *p)
/* kdb access to register set for stack dumping */
/* kdb access to register set for stack dumping */
extern struct pt_regs *kdb_current_regs;
extern struct pt_regs *kdb_current_regs;


/* Dynamic kdb shell command registration */
extern int kdb_register(char *, kdb_func_t, char *, char *, short);
extern int kdb_register_repeat(char *, kdb_func_t, char *, char *,
			       short, kdb_repeat_t);
extern int kdb_unregister(char *);
#else /* ! CONFIG_KGDB_KDB */
#else /* ! CONFIG_KGDB_KDB */
#define kdb_printf(...)
#define kdb_printf(...)
#define kdb_init(x)
#define kdb_init(x)
#define kdb_register(...)
#define kdb_register_repeat(...)
#define kdb_uregister(x)
#endif	/* CONFIG_KGDB_KDB */
#endif	/* CONFIG_KGDB_KDB */
enum {
enum {
	KDB_NOT_INITIALIZED,
	KDB_NOT_INITIALIZED,
+1 −1
Original line number Original line Diff line number Diff line
@@ -823,4 +823,4 @@ int kdb_printf(const char *fmt, ...)


	return r;
	return r;
}
}
EXPORT_SYMBOL_GPL(kdb_printf);
+4 −0
Original line number Original line Diff line number Diff line
@@ -2783,6 +2783,8 @@ int kdb_register_repeat(char *cmd,


	return 0;
	return 0;
}
}
EXPORT_SYMBOL_GPL(kdb_register_repeat);



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


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


/* Initialize the kdb command table. */
/* Initialize the kdb command table. */
static void __init kdb_inittab(void)
static void __init kdb_inittab(void)
+0 −39
Original line number Original line Diff line number Diff line
@@ -15,29 +15,6 @@
#include <linux/kgdb.h>
#include <linux/kgdb.h>
#include "../debug_core.h"
#include "../debug_core.h"


/* Kernel Debugger Error codes.  Must not overlap with command codes. */
#define KDB_NOTFOUND	(-1)
#define KDB_ARGCOUNT	(-2)
#define KDB_BADWIDTH	(-3)
#define KDB_BADRADIX	(-4)
#define KDB_NOTENV	(-5)
#define KDB_NOENVVALUE	(-6)
#define KDB_NOTIMP	(-7)
#define KDB_ENVFULL	(-8)
#define KDB_ENVBUFFULL	(-9)
#define KDB_TOOMANYBPT	(-10)
#define KDB_TOOMANYDBREGS (-11)
#define KDB_DUPBPT	(-12)
#define KDB_BPTNOTFOUND	(-13)
#define KDB_BADMODE	(-14)
#define KDB_BADINT	(-15)
#define KDB_INVADDRFMT  (-16)
#define KDB_BADREG      (-17)
#define KDB_BADCPUNUM   (-18)
#define KDB_BADLENGTH	(-19)
#define KDB_NOBP	(-20)
#define KDB_BADADDR	(-21)

/* Kernel Debugger Command codes.  Must not overlap with error codes. */
/* Kernel Debugger Command codes.  Must not overlap with error codes. */
#define KDB_CMD_GO	(-1001)
#define KDB_CMD_GO	(-1001)
#define KDB_CMD_CPU	(-1002)
#define KDB_CMD_CPU	(-1002)
@@ -93,17 +70,6 @@
 */
 */
#define KDB_MAXBPT	16
#define KDB_MAXBPT	16


/* Maximum number of arguments to a function  */
#define KDB_MAXARGS    16

typedef enum {
	KDB_REPEAT_NONE = 0,	/* Do not repeat this command */
	KDB_REPEAT_NO_ARGS,	/* Repeat the command without arguments */
	KDB_REPEAT_WITH_ARGS,	/* Repeat the command including its arguments */
} kdb_repeat_t;

typedef int (*kdb_func_t)(int, const char **);

/* Symbol table format returned by kallsyms. */
/* Symbol table format returned by kallsyms. */
typedef struct __ksymtab {
typedef struct __ksymtab {
		unsigned long value;	/* Address of symbol */
		unsigned long value;	/* Address of symbol */
@@ -123,11 +89,6 @@ extern int kallsyms_symbol_next(char *prefix_name, int flag);
extern int kallsyms_symbol_complete(char *prefix_name, int max_len);
extern int kallsyms_symbol_complete(char *prefix_name, int max_len);


/* Exported Symbols for kernel loadable modules to use. */
/* Exported Symbols for kernel loadable modules to use. */
extern int kdb_register(char *, kdb_func_t, char *, char *, short);
extern int kdb_register_repeat(char *, kdb_func_t, char *, char *,
			       short, kdb_repeat_t);
extern int kdb_unregister(char *);

extern int kdb_getarea_size(void *, unsigned long, size_t);
extern int kdb_getarea_size(void *, unsigned long, size_t);
extern int kdb_putarea_size(unsigned long, void *, size_t);
extern int kdb_putarea_size(unsigned long, void *, size_t);