Commit 974460c5 authored by Jason Wessel's avatar Jason Wessel Committed by Ingo Molnar

kgdb: allow static kgdbts boot configuration

This patch adds in the ability to compile the kgdb internal test
string into the kernel so as to run the tests at boot without changing
the kernel boot arguments.  This patch also changes all the error
paths to invoke WARN_ON(1) which will emit the line number of the file
and dump the kernel stack when an error occurs.

You can disable the tests in a kernel that is built this way
using "kgdbts="
Signed-off-by: default avatarJason Wessel <jason.wessel@windriver.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent e3e2aaf7
...@@ -112,6 +112,10 @@ ...@@ -112,6 +112,10 @@
printk(KERN_INFO a); \ printk(KERN_INFO a); \
touch_nmi_watchdog(); \ touch_nmi_watchdog(); \
} while (0) } while (0)
#define eprintk(a...) do { \
printk(KERN_ERR a); \
WARN_ON(1); \
} while (0)
#define MAX_CONFIG_LEN 40 #define MAX_CONFIG_LEN 40
static const char hexchars[] = "0123456789abcdef"; static const char hexchars[] = "0123456789abcdef";
...@@ -145,7 +149,11 @@ static struct pt_regs kgdbts_regs; ...@@ -145,7 +149,11 @@ static struct pt_regs kgdbts_regs;
/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */ /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
static int configured = -1; static int configured = -1;
#ifdef CONFIG_KGDB_TESTS_BOOT_STRING
static char config[MAX_CONFIG_LEN] = CONFIG_KGDB_TESTS_BOOT_STRING;
#else
static char config[MAX_CONFIG_LEN]; static char config[MAX_CONFIG_LEN];
#endif
static struct kparam_string kps = { static struct kparam_string kps = {
.string = config, .string = config,
.maxlen = MAX_CONFIG_LEN, .maxlen = MAX_CONFIG_LEN,
...@@ -289,7 +297,7 @@ static int check_and_rewind_pc(char *put_str, char *arg) ...@@ -289,7 +297,7 @@ static int check_and_rewind_pc(char *put_str, char *arg)
#endif #endif
if (strcmp(arg, "silent") && if (strcmp(arg, "silent") &&
instruction_pointer(&kgdbts_regs) + offset != addr) { instruction_pointer(&kgdbts_regs) + offset != addr) {
printk(KERN_ERR "kgdbts: BP mismatch %lx expected %lx\n", eprintk("kgdbts: BP mismatch %lx expected %lx\n",
instruction_pointer(&kgdbts_regs) + offset, addr); instruction_pointer(&kgdbts_regs) + offset, addr);
return 1; return 1;
} }
...@@ -313,7 +321,7 @@ static int check_single_step(char *put_str, char *arg) ...@@ -313,7 +321,7 @@ static int check_single_step(char *put_str, char *arg)
v2printk("Singlestep stopped at IP: %lx\n", v2printk("Singlestep stopped at IP: %lx\n",
instruction_pointer(&kgdbts_regs)); instruction_pointer(&kgdbts_regs));
if (instruction_pointer(&kgdbts_regs) == addr) { if (instruction_pointer(&kgdbts_regs) == addr) {
printk(KERN_ERR "kgdbts: SingleStep failed at %lx\n", eprintk("kgdbts: SingleStep failed at %lx\n",
instruction_pointer(&kgdbts_regs)); instruction_pointer(&kgdbts_regs));
return 1; return 1;
} }
...@@ -378,7 +386,7 @@ static void emul_sstep_get(char *arg) ...@@ -378,7 +386,7 @@ static void emul_sstep_get(char *arg)
break_helper("z0", 0, sstep_addr); break_helper("z0", 0, sstep_addr);
break; break;
default: default:
printk(KERN_ERR "kgdbts: ERROR failed sstep get emulation\n"); eprintk("kgdbts: ERROR failed sstep get emulation\n");
} }
sstep_state++; sstep_state++;
} }
...@@ -404,26 +412,26 @@ static int emul_sstep_put(char *put_str, char *arg) ...@@ -404,26 +412,26 @@ static int emul_sstep_put(char *put_str, char *arg)
break; break;
case 2: case 2:
if (strncmp(put_str, "$OK", 3)) { if (strncmp(put_str, "$OK", 3)) {
printk(KERN_ERR "kgdbts: failed sstep break set\n"); eprintk("kgdbts: failed sstep break set\n");
return 1; return 1;
} }
break; break;
case 3: case 3:
if (strncmp(put_str, "$T0", 3)) { if (strncmp(put_str, "$T0", 3)) {
printk(KERN_ERR "kgdbts: failed continue sstep\n"); eprintk("kgdbts: failed continue sstep\n");
return 1; return 1;
} }
break; break;
case 4: case 4:
if (strncmp(put_str, "$OK", 3)) { if (strncmp(put_str, "$OK", 3)) {
printk(KERN_ERR "kgdbts: failed sstep break unset\n"); eprintk("kgdbts: failed sstep break unset\n");
return 1; return 1;
} }
/* Single step is complete so continue on! */ /* Single step is complete so continue on! */
sstep_state = 0; sstep_state = 0;
return 0; return 0;
default: default:
printk(KERN_ERR "kgdbts: ERROR failed sstep put emulation\n"); eprintk("kgdbts: ERROR failed sstep put emulation\n");
} }
/* Continue on the same test line until emulation is complete */ /* Continue on the same test line until emulation is complete */
...@@ -668,8 +676,7 @@ static int run_simple_test(int is_get_char, int chr) ...@@ -668,8 +676,7 @@ static int run_simple_test(int is_get_char, int chr)
} }
if (get_buf[get_buf_cnt] == '\0') { if (get_buf[get_buf_cnt] == '\0') {
printk(KERN_ERR eprintk("kgdbts: ERROR GET: EOB on '%s' at %i\n",
"kgdbts: ERROR GET: end of buffer on '%s' at %i\n",
ts.name, ts.idx); ts.name, ts.idx);
get_buf_cnt = 0; get_buf_cnt = 0;
fill_get_buf("D"); fill_get_buf("D");
...@@ -684,13 +691,13 @@ static int run_simple_test(int is_get_char, int chr) ...@@ -684,13 +691,13 @@ static int run_simple_test(int is_get_char, int chr)
*/ */
if (ts.tst[ts.idx].get[0] == '\0' && if (ts.tst[ts.idx].get[0] == '\0' &&
ts.tst[ts.idx].put[0] == '\0') { ts.tst[ts.idx].put[0] == '\0') {
printk(KERN_ERR "kgdbts: ERROR: beyond end of test on" eprintk("kgdbts: ERROR: beyond end of test on"
" '%s' line %i\n", ts.name, ts.idx); " '%s' line %i\n", ts.name, ts.idx);
return 0; return 0;
} }
if (put_buf_cnt >= BUFMAX) { if (put_buf_cnt >= BUFMAX) {
printk(KERN_ERR "kgdbts: ERROR: put buffer overflow on" eprintk("kgdbts: ERROR: put buffer overflow on"
" '%s' line %i\n", ts.name, ts.idx); " '%s' line %i\n", ts.name, ts.idx);
put_buf_cnt = 0; put_buf_cnt = 0;
return 0; return 0;
...@@ -708,7 +715,7 @@ static int run_simple_test(int is_get_char, int chr) ...@@ -708,7 +715,7 @@ static int run_simple_test(int is_get_char, int chr)
v2printk("put%i: %s\n", ts.idx, put_buf); v2printk("put%i: %s\n", ts.idx, put_buf);
/* Trigger check here */ /* Trigger check here */
if (ts.validate_put && ts.validate_put(put_buf)) { if (ts.validate_put && ts.validate_put(put_buf)) {
printk(KERN_ERR "kgdbts: ERROR PUT: end of test " eprintk("kgdbts: ERROR PUT: end of test "
"buffer on '%s' line %i expected %s got %s\n", "buffer on '%s' line %i expected %s got %s\n",
ts.name, ts.idx, ts.tst[ts.idx].put, put_buf); ts.name, ts.idx, ts.tst[ts.idx].put, put_buf);
} }
...@@ -772,7 +779,7 @@ static void run_breakpoint_test(int is_hw_breakpoint) ...@@ -772,7 +779,7 @@ static void run_breakpoint_test(int is_hw_breakpoint)
if (test_complete) if (test_complete)
return; return;
printk(KERN_ERR "kgdbts: ERROR %s test failed\n", ts.name); eprintk("kgdbts: ERROR %s test failed\n", ts.name);
} }
static void run_hw_break_test(int is_write_test) static void run_hw_break_test(int is_write_test)
...@@ -791,7 +798,7 @@ static void run_hw_break_test(int is_write_test) ...@@ -791,7 +798,7 @@ static void run_hw_break_test(int is_write_test)
hw_break_val_access(); hw_break_val_access();
if (is_write_test) { if (is_write_test) {
if (test_complete == 2) if (test_complete == 2)
printk(KERN_ERR "kgdbts: ERROR %s broke on access\n", eprintk("kgdbts: ERROR %s broke on access\n",
ts.name); ts.name);
hw_break_val_write(); hw_break_val_write();
} }
...@@ -800,7 +807,7 @@ static void run_hw_break_test(int is_write_test) ...@@ -800,7 +807,7 @@ static void run_hw_break_test(int is_write_test)
if (test_complete == 1) if (test_complete == 1)
return; return;
printk(KERN_ERR "kgdbts: ERROR %s test failed\n", ts.name); eprintk("kgdbts: ERROR %s test failed\n", ts.name);
} }
static void run_nmi_sleep_test(int nmi_sleep) static void run_nmi_sleep_test(int nmi_sleep)
...@@ -817,12 +824,12 @@ static void run_nmi_sleep_test(int nmi_sleep) ...@@ -817,12 +824,12 @@ static void run_nmi_sleep_test(int nmi_sleep)
touch_nmi_watchdog(); touch_nmi_watchdog();
local_irq_restore(flags); local_irq_restore(flags);
if (test_complete != 2) if (test_complete != 2)
printk(KERN_ERR "kgdbts: ERROR nmi_test did not hit nmi\n"); eprintk("kgdbts: ERROR nmi_test did not hit nmi\n");
kgdb_breakpoint(); kgdb_breakpoint();
if (test_complete == 1) if (test_complete == 1)
return; return;
printk(KERN_ERR "kgdbts: ERROR %s test failed\n", ts.name); eprintk("kgdbts: ERROR %s test failed\n", ts.name);
} }
static void run_bad_read_test(void) static void run_bad_read_test(void)
......
...@@ -38,3 +38,21 @@ config KGDB_TESTS ...@@ -38,3 +38,21 @@ config KGDB_TESTS
See the drivers/misc/kgdbts.c for the details about See the drivers/misc/kgdbts.c for the details about
the tests. The most basic of this I/O module is to boot the tests. The most basic of this I/O module is to boot
a kernel boot arguments "kgdbwait kgdbts=V1F100" a kernel boot arguments "kgdbwait kgdbts=V1F100"
config KGDB_TESTS_ON_BOOT
bool "KGDB: Run tests on boot"
depends on KGDB_TESTS
default n
help
Run the kgdb tests on boot up automatically without the need
to pass in a kernel parameter
config KGDB_TESTS_BOOT_STRING
string "KGDB: which internal kgdb tests to run"
depends on KGDB_TESTS_ON_BOOT
default "V1F100"
help
This is the command string to send the kgdb test suite on
boot. See the drivers/misc/kgdbts.c for detailed
information about other strings you could use beyond the
default of V1F100.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment