Commit e78acf67ba7e32071e6eca14d8c39c7b1f130c31
Committed by
Jason Wessel
1 parent
f7c82d5a3c
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
kgdb/kgdbts: support ppc64
We can't look up the address of the entry point of the function simply via that function symbol for all architectures. For PPC64 ABI, actually there is a function descriptors structure. A function descriptor is a three doubleword data structure that contains the following values: * The first doubleword contains the address of the entry point of the function. * The second doubleword contains the TOC base address for the function. * The third doubleword contains the environment pointer for languages such as Pascal and PL/1. So we should call a wapperred dereference_function_descriptor() to get the address of the entry point of the function. Note this is also safe for other architecture after refer to "include/asm-generic/sections.h" since: dereference_function_descriptor(p) always is (p) if without arched definition. Signed-off-by: Tiejun Chen <tiejun.chen@windriver.com> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Showing 1 changed file with 2 additions and 0 deletions Inline Diff
drivers/misc/kgdbts.c
1 | /* | 1 | /* |
2 | * kgdbts is a test suite for kgdb for the sole purpose of validating | 2 | * kgdbts is a test suite for kgdb for the sole purpose of validating |
3 | * that key pieces of the kgdb internals are working properly such as | 3 | * that key pieces of the kgdb internals are working properly such as |
4 | * HW/SW breakpoints, single stepping, and NMI. | 4 | * HW/SW breakpoints, single stepping, and NMI. |
5 | * | 5 | * |
6 | * Created by: Jason Wessel <jason.wessel@windriver.com> | 6 | * Created by: Jason Wessel <jason.wessel@windriver.com> |
7 | * | 7 | * |
8 | * Copyright (c) 2008 Wind River Systems, Inc. | 8 | * Copyright (c) 2008 Wind River Systems, Inc. |
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or modify | 10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2 as | 11 | * it under the terms of the GNU General Public License version 2 as |
12 | * published by the Free Software Foundation. | 12 | * published by the Free Software Foundation. |
13 | * | 13 | * |
14 | * This program is distributed in the hope that it will be useful, | 14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | * See the GNU General Public License for more details. | 17 | * See the GNU General Public License for more details. |
18 | * | 18 | * |
19 | * You should have received a copy of the GNU General Public License | 19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software | 20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 | */ | 22 | */ |
23 | /* Information about the kgdb test suite. | 23 | /* Information about the kgdb test suite. |
24 | * ------------------------------------- | 24 | * ------------------------------------- |
25 | * | 25 | * |
26 | * The kgdb test suite is designed as a KGDB I/O module which | 26 | * The kgdb test suite is designed as a KGDB I/O module which |
27 | * simulates the communications that a debugger would have with kgdb. | 27 | * simulates the communications that a debugger would have with kgdb. |
28 | * The tests are broken up in to a line by line and referenced here as | 28 | * The tests are broken up in to a line by line and referenced here as |
29 | * a "get" which is kgdb requesting input and "put" which is kgdb | 29 | * a "get" which is kgdb requesting input and "put" which is kgdb |
30 | * sending a response. | 30 | * sending a response. |
31 | * | 31 | * |
32 | * The kgdb suite can be invoked from the kernel command line | 32 | * The kgdb suite can be invoked from the kernel command line |
33 | * arguments system or executed dynamically at run time. The test | 33 | * arguments system or executed dynamically at run time. The test |
34 | * suite uses the variable "kgdbts" to obtain the information about | 34 | * suite uses the variable "kgdbts" to obtain the information about |
35 | * which tests to run and to configure the verbosity level. The | 35 | * which tests to run and to configure the verbosity level. The |
36 | * following are the various characters you can use with the kgdbts= | 36 | * following are the various characters you can use with the kgdbts= |
37 | * line: | 37 | * line: |
38 | * | 38 | * |
39 | * When using the "kgdbts=" you only choose one of the following core | 39 | * When using the "kgdbts=" you only choose one of the following core |
40 | * test types: | 40 | * test types: |
41 | * A = Run all the core tests silently | 41 | * A = Run all the core tests silently |
42 | * V1 = Run all the core tests with minimal output | 42 | * V1 = Run all the core tests with minimal output |
43 | * V2 = Run all the core tests in debug mode | 43 | * V2 = Run all the core tests in debug mode |
44 | * | 44 | * |
45 | * You can also specify optional tests: | 45 | * You can also specify optional tests: |
46 | * N## = Go to sleep with interrupts of for ## seconds | 46 | * N## = Go to sleep with interrupts of for ## seconds |
47 | * to test the HW NMI watchdog | 47 | * to test the HW NMI watchdog |
48 | * F## = Break at do_fork for ## iterations | 48 | * F## = Break at do_fork for ## iterations |
49 | * S## = Break at sys_open for ## iterations | 49 | * S## = Break at sys_open for ## iterations |
50 | * I## = Run the single step test ## iterations | 50 | * I## = Run the single step test ## iterations |
51 | * | 51 | * |
52 | * NOTE: that the do_fork and sys_open tests are mutually exclusive. | 52 | * NOTE: that the do_fork and sys_open tests are mutually exclusive. |
53 | * | 53 | * |
54 | * To invoke the kgdb test suite from boot you use a kernel start | 54 | * To invoke the kgdb test suite from boot you use a kernel start |
55 | * argument as follows: | 55 | * argument as follows: |
56 | * kgdbts=V1 kgdbwait | 56 | * kgdbts=V1 kgdbwait |
57 | * Or if you wanted to perform the NMI test for 6 seconds and do_fork | 57 | * Or if you wanted to perform the NMI test for 6 seconds and do_fork |
58 | * test for 100 forks, you could use: | 58 | * test for 100 forks, you could use: |
59 | * kgdbts=V1N6F100 kgdbwait | 59 | * kgdbts=V1N6F100 kgdbwait |
60 | * | 60 | * |
61 | * The test suite can also be invoked at run time with: | 61 | * The test suite can also be invoked at run time with: |
62 | * echo kgdbts=V1N6F100 > /sys/module/kgdbts/parameters/kgdbts | 62 | * echo kgdbts=V1N6F100 > /sys/module/kgdbts/parameters/kgdbts |
63 | * Or as another example: | 63 | * Or as another example: |
64 | * echo kgdbts=V2 > /sys/module/kgdbts/parameters/kgdbts | 64 | * echo kgdbts=V2 > /sys/module/kgdbts/parameters/kgdbts |
65 | * | 65 | * |
66 | * When developing a new kgdb arch specific implementation or | 66 | * When developing a new kgdb arch specific implementation or |
67 | * using these tests for the purpose of regression testing, | 67 | * using these tests for the purpose of regression testing, |
68 | * several invocations are required. | 68 | * several invocations are required. |
69 | * | 69 | * |
70 | * 1) Boot with the test suite enabled by using the kernel arguments | 70 | * 1) Boot with the test suite enabled by using the kernel arguments |
71 | * "kgdbts=V1F100 kgdbwait" | 71 | * "kgdbts=V1F100 kgdbwait" |
72 | * ## If kgdb arch specific implementation has NMI use | 72 | * ## If kgdb arch specific implementation has NMI use |
73 | * "kgdbts=V1N6F100 | 73 | * "kgdbts=V1N6F100 |
74 | * | 74 | * |
75 | * 2) After the system boot run the basic test. | 75 | * 2) After the system boot run the basic test. |
76 | * echo kgdbts=V1 > /sys/module/kgdbts/parameters/kgdbts | 76 | * echo kgdbts=V1 > /sys/module/kgdbts/parameters/kgdbts |
77 | * | 77 | * |
78 | * 3) Run the concurrency tests. It is best to use n+1 | 78 | * 3) Run the concurrency tests. It is best to use n+1 |
79 | * while loops where n is the number of cpus you have | 79 | * while loops where n is the number of cpus you have |
80 | * in your system. The example below uses only two | 80 | * in your system. The example below uses only two |
81 | * loops. | 81 | * loops. |
82 | * | 82 | * |
83 | * ## This tests break points on sys_open | 83 | * ## This tests break points on sys_open |
84 | * while [ 1 ] ; do find / > /dev/null 2>&1 ; done & | 84 | * while [ 1 ] ; do find / > /dev/null 2>&1 ; done & |
85 | * while [ 1 ] ; do find / > /dev/null 2>&1 ; done & | 85 | * while [ 1 ] ; do find / > /dev/null 2>&1 ; done & |
86 | * echo kgdbts=V1S10000 > /sys/module/kgdbts/parameters/kgdbts | 86 | * echo kgdbts=V1S10000 > /sys/module/kgdbts/parameters/kgdbts |
87 | * fg # and hit control-c | 87 | * fg # and hit control-c |
88 | * fg # and hit control-c | 88 | * fg # and hit control-c |
89 | * ## This tests break points on do_fork | 89 | * ## This tests break points on do_fork |
90 | * while [ 1 ] ; do date > /dev/null ; done & | 90 | * while [ 1 ] ; do date > /dev/null ; done & |
91 | * while [ 1 ] ; do date > /dev/null ; done & | 91 | * while [ 1 ] ; do date > /dev/null ; done & |
92 | * echo kgdbts=V1F1000 > /sys/module/kgdbts/parameters/kgdbts | 92 | * echo kgdbts=V1F1000 > /sys/module/kgdbts/parameters/kgdbts |
93 | * fg # and hit control-c | 93 | * fg # and hit control-c |
94 | * | 94 | * |
95 | */ | 95 | */ |
96 | 96 | ||
97 | #include <linux/kernel.h> | 97 | #include <linux/kernel.h> |
98 | #include <linux/kgdb.h> | 98 | #include <linux/kgdb.h> |
99 | #include <linux/ctype.h> | 99 | #include <linux/ctype.h> |
100 | #include <linux/uaccess.h> | 100 | #include <linux/uaccess.h> |
101 | #include <linux/syscalls.h> | 101 | #include <linux/syscalls.h> |
102 | #include <linux/nmi.h> | 102 | #include <linux/nmi.h> |
103 | #include <linux/delay.h> | 103 | #include <linux/delay.h> |
104 | #include <linux/kthread.h> | 104 | #include <linux/kthread.h> |
105 | #include <linux/module.h> | 105 | #include <linux/module.h> |
106 | #include <asm/sections.h> | ||
106 | 107 | ||
107 | #define v1printk(a...) do { \ | 108 | #define v1printk(a...) do { \ |
108 | if (verbose) \ | 109 | if (verbose) \ |
109 | printk(KERN_INFO a); \ | 110 | printk(KERN_INFO a); \ |
110 | } while (0) | 111 | } while (0) |
111 | #define v2printk(a...) do { \ | 112 | #define v2printk(a...) do { \ |
112 | if (verbose > 1) \ | 113 | if (verbose > 1) \ |
113 | printk(KERN_INFO a); \ | 114 | printk(KERN_INFO a); \ |
114 | touch_nmi_watchdog(); \ | 115 | touch_nmi_watchdog(); \ |
115 | } while (0) | 116 | } while (0) |
116 | #define eprintk(a...) do { \ | 117 | #define eprintk(a...) do { \ |
117 | printk(KERN_ERR a); \ | 118 | printk(KERN_ERR a); \ |
118 | WARN_ON(1); \ | 119 | WARN_ON(1); \ |
119 | } while (0) | 120 | } while (0) |
120 | #define MAX_CONFIG_LEN 40 | 121 | #define MAX_CONFIG_LEN 40 |
121 | 122 | ||
122 | static struct kgdb_io kgdbts_io_ops; | 123 | static struct kgdb_io kgdbts_io_ops; |
123 | static char get_buf[BUFMAX]; | 124 | static char get_buf[BUFMAX]; |
124 | static int get_buf_cnt; | 125 | static int get_buf_cnt; |
125 | static char put_buf[BUFMAX]; | 126 | static char put_buf[BUFMAX]; |
126 | static int put_buf_cnt; | 127 | static int put_buf_cnt; |
127 | static char scratch_buf[BUFMAX]; | 128 | static char scratch_buf[BUFMAX]; |
128 | static int verbose; | 129 | static int verbose; |
129 | static int repeat_test; | 130 | static int repeat_test; |
130 | static int test_complete; | 131 | static int test_complete; |
131 | static int send_ack; | 132 | static int send_ack; |
132 | static int final_ack; | 133 | static int final_ack; |
133 | static int force_hwbrks; | 134 | static int force_hwbrks; |
134 | static int hwbreaks_ok; | 135 | static int hwbreaks_ok; |
135 | static int hw_break_val; | 136 | static int hw_break_val; |
136 | static int hw_break_val2; | 137 | static int hw_break_val2; |
137 | static int cont_instead_of_sstep; | 138 | static int cont_instead_of_sstep; |
138 | static unsigned long cont_thread_id; | 139 | static unsigned long cont_thread_id; |
139 | static unsigned long sstep_thread_id; | 140 | static unsigned long sstep_thread_id; |
140 | #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_SPARC) | 141 | #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_SPARC) |
141 | static int arch_needs_sstep_emulation = 1; | 142 | static int arch_needs_sstep_emulation = 1; |
142 | #else | 143 | #else |
143 | static int arch_needs_sstep_emulation; | 144 | static int arch_needs_sstep_emulation; |
144 | #endif | 145 | #endif |
145 | static unsigned long cont_addr; | 146 | static unsigned long cont_addr; |
146 | static unsigned long sstep_addr; | 147 | static unsigned long sstep_addr; |
147 | static int restart_from_top_after_write; | 148 | static int restart_from_top_after_write; |
148 | static int sstep_state; | 149 | static int sstep_state; |
149 | 150 | ||
150 | /* Storage for the registers, in GDB format. */ | 151 | /* Storage for the registers, in GDB format. */ |
151 | static unsigned long kgdbts_gdb_regs[(NUMREGBYTES + | 152 | static unsigned long kgdbts_gdb_regs[(NUMREGBYTES + |
152 | sizeof(unsigned long) - 1) / | 153 | sizeof(unsigned long) - 1) / |
153 | sizeof(unsigned long)]; | 154 | sizeof(unsigned long)]; |
154 | static struct pt_regs kgdbts_regs; | 155 | static struct pt_regs kgdbts_regs; |
155 | 156 | ||
156 | /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */ | 157 | /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */ |
157 | static int configured = -1; | 158 | static int configured = -1; |
158 | 159 | ||
159 | #ifdef CONFIG_KGDB_TESTS_BOOT_STRING | 160 | #ifdef CONFIG_KGDB_TESTS_BOOT_STRING |
160 | static char config[MAX_CONFIG_LEN] = CONFIG_KGDB_TESTS_BOOT_STRING; | 161 | static char config[MAX_CONFIG_LEN] = CONFIG_KGDB_TESTS_BOOT_STRING; |
161 | #else | 162 | #else |
162 | static char config[MAX_CONFIG_LEN]; | 163 | static char config[MAX_CONFIG_LEN]; |
163 | #endif | 164 | #endif |
164 | static struct kparam_string kps = { | 165 | static struct kparam_string kps = { |
165 | .string = config, | 166 | .string = config, |
166 | .maxlen = MAX_CONFIG_LEN, | 167 | .maxlen = MAX_CONFIG_LEN, |
167 | }; | 168 | }; |
168 | 169 | ||
169 | static void fill_get_buf(char *buf); | 170 | static void fill_get_buf(char *buf); |
170 | 171 | ||
171 | struct test_struct { | 172 | struct test_struct { |
172 | char *get; | 173 | char *get; |
173 | char *put; | 174 | char *put; |
174 | void (*get_handler)(char *); | 175 | void (*get_handler)(char *); |
175 | int (*put_handler)(char *, char *); | 176 | int (*put_handler)(char *, char *); |
176 | }; | 177 | }; |
177 | 178 | ||
178 | struct test_state { | 179 | struct test_state { |
179 | char *name; | 180 | char *name; |
180 | struct test_struct *tst; | 181 | struct test_struct *tst; |
181 | int idx; | 182 | int idx; |
182 | int (*run_test) (int, int); | 183 | int (*run_test) (int, int); |
183 | int (*validate_put) (char *); | 184 | int (*validate_put) (char *); |
184 | }; | 185 | }; |
185 | 186 | ||
186 | static struct test_state ts; | 187 | static struct test_state ts; |
187 | 188 | ||
188 | static int kgdbts_unreg_thread(void *ptr) | 189 | static int kgdbts_unreg_thread(void *ptr) |
189 | { | 190 | { |
190 | /* Wait until the tests are complete and then ungresiter the I/O | 191 | /* Wait until the tests are complete and then ungresiter the I/O |
191 | * driver. | 192 | * driver. |
192 | */ | 193 | */ |
193 | while (!final_ack) | 194 | while (!final_ack) |
194 | msleep_interruptible(1500); | 195 | msleep_interruptible(1500); |
195 | /* Pause for any other threads to exit after final ack. */ | 196 | /* Pause for any other threads to exit after final ack. */ |
196 | msleep_interruptible(1000); | 197 | msleep_interruptible(1000); |
197 | if (configured) | 198 | if (configured) |
198 | kgdb_unregister_io_module(&kgdbts_io_ops); | 199 | kgdb_unregister_io_module(&kgdbts_io_ops); |
199 | configured = 0; | 200 | configured = 0; |
200 | 201 | ||
201 | return 0; | 202 | return 0; |
202 | } | 203 | } |
203 | 204 | ||
204 | /* This is noinline such that it can be used for a single location to | 205 | /* This is noinline such that it can be used for a single location to |
205 | * place a breakpoint | 206 | * place a breakpoint |
206 | */ | 207 | */ |
207 | static noinline void kgdbts_break_test(void) | 208 | static noinline void kgdbts_break_test(void) |
208 | { | 209 | { |
209 | v2printk("kgdbts: breakpoint complete\n"); | 210 | v2printk("kgdbts: breakpoint complete\n"); |
210 | } | 211 | } |
211 | 212 | ||
212 | /* Lookup symbol info in the kernel */ | 213 | /* Lookup symbol info in the kernel */ |
213 | static unsigned long lookup_addr(char *arg) | 214 | static unsigned long lookup_addr(char *arg) |
214 | { | 215 | { |
215 | unsigned long addr = 0; | 216 | unsigned long addr = 0; |
216 | 217 | ||
217 | if (!strcmp(arg, "kgdbts_break_test")) | 218 | if (!strcmp(arg, "kgdbts_break_test")) |
218 | addr = (unsigned long)kgdbts_break_test; | 219 | addr = (unsigned long)kgdbts_break_test; |
219 | else if (!strcmp(arg, "sys_open")) | 220 | else if (!strcmp(arg, "sys_open")) |
220 | addr = (unsigned long)do_sys_open; | 221 | addr = (unsigned long)do_sys_open; |
221 | else if (!strcmp(arg, "do_fork")) | 222 | else if (!strcmp(arg, "do_fork")) |
222 | addr = (unsigned long)do_fork; | 223 | addr = (unsigned long)do_fork; |
223 | else if (!strcmp(arg, "hw_break_val")) | 224 | else if (!strcmp(arg, "hw_break_val")) |
224 | addr = (unsigned long)&hw_break_val; | 225 | addr = (unsigned long)&hw_break_val; |
226 | addr = (unsigned long) dereference_function_descriptor((void *)addr); | ||
225 | return addr; | 227 | return addr; |
226 | } | 228 | } |
227 | 229 | ||
228 | static void break_helper(char *bp_type, char *arg, unsigned long vaddr) | 230 | static void break_helper(char *bp_type, char *arg, unsigned long vaddr) |
229 | { | 231 | { |
230 | unsigned long addr; | 232 | unsigned long addr; |
231 | 233 | ||
232 | if (arg) | 234 | if (arg) |
233 | addr = lookup_addr(arg); | 235 | addr = lookup_addr(arg); |
234 | else | 236 | else |
235 | addr = vaddr; | 237 | addr = vaddr; |
236 | 238 | ||
237 | sprintf(scratch_buf, "%s,%lx,%i", bp_type, addr, | 239 | sprintf(scratch_buf, "%s,%lx,%i", bp_type, addr, |
238 | BREAK_INSTR_SIZE); | 240 | BREAK_INSTR_SIZE); |
239 | fill_get_buf(scratch_buf); | 241 | fill_get_buf(scratch_buf); |
240 | } | 242 | } |
241 | 243 | ||
242 | static void sw_break(char *arg) | 244 | static void sw_break(char *arg) |
243 | { | 245 | { |
244 | break_helper(force_hwbrks ? "Z1" : "Z0", arg, 0); | 246 | break_helper(force_hwbrks ? "Z1" : "Z0", arg, 0); |
245 | } | 247 | } |
246 | 248 | ||
247 | static void sw_rem_break(char *arg) | 249 | static void sw_rem_break(char *arg) |
248 | { | 250 | { |
249 | break_helper(force_hwbrks ? "z1" : "z0", arg, 0); | 251 | break_helper(force_hwbrks ? "z1" : "z0", arg, 0); |
250 | } | 252 | } |
251 | 253 | ||
252 | static void hw_break(char *arg) | 254 | static void hw_break(char *arg) |
253 | { | 255 | { |
254 | break_helper("Z1", arg, 0); | 256 | break_helper("Z1", arg, 0); |
255 | } | 257 | } |
256 | 258 | ||
257 | static void hw_rem_break(char *arg) | 259 | static void hw_rem_break(char *arg) |
258 | { | 260 | { |
259 | break_helper("z1", arg, 0); | 261 | break_helper("z1", arg, 0); |
260 | } | 262 | } |
261 | 263 | ||
262 | static void hw_write_break(char *arg) | 264 | static void hw_write_break(char *arg) |
263 | { | 265 | { |
264 | break_helper("Z2", arg, 0); | 266 | break_helper("Z2", arg, 0); |
265 | } | 267 | } |
266 | 268 | ||
267 | static void hw_rem_write_break(char *arg) | 269 | static void hw_rem_write_break(char *arg) |
268 | { | 270 | { |
269 | break_helper("z2", arg, 0); | 271 | break_helper("z2", arg, 0); |
270 | } | 272 | } |
271 | 273 | ||
272 | static void hw_access_break(char *arg) | 274 | static void hw_access_break(char *arg) |
273 | { | 275 | { |
274 | break_helper("Z4", arg, 0); | 276 | break_helper("Z4", arg, 0); |
275 | } | 277 | } |
276 | 278 | ||
277 | static void hw_rem_access_break(char *arg) | 279 | static void hw_rem_access_break(char *arg) |
278 | { | 280 | { |
279 | break_helper("z4", arg, 0); | 281 | break_helper("z4", arg, 0); |
280 | } | 282 | } |
281 | 283 | ||
282 | static void hw_break_val_access(void) | 284 | static void hw_break_val_access(void) |
283 | { | 285 | { |
284 | hw_break_val2 = hw_break_val; | 286 | hw_break_val2 = hw_break_val; |
285 | } | 287 | } |
286 | 288 | ||
287 | static void hw_break_val_write(void) | 289 | static void hw_break_val_write(void) |
288 | { | 290 | { |
289 | hw_break_val++; | 291 | hw_break_val++; |
290 | } | 292 | } |
291 | 293 | ||
292 | static int get_thread_id_continue(char *put_str, char *arg) | 294 | static int get_thread_id_continue(char *put_str, char *arg) |
293 | { | 295 | { |
294 | char *ptr = &put_str[11]; | 296 | char *ptr = &put_str[11]; |
295 | 297 | ||
296 | if (put_str[1] != 'T' || put_str[2] != '0') | 298 | if (put_str[1] != 'T' || put_str[2] != '0') |
297 | return 1; | 299 | return 1; |
298 | kgdb_hex2long(&ptr, &cont_thread_id); | 300 | kgdb_hex2long(&ptr, &cont_thread_id); |
299 | return 0; | 301 | return 0; |
300 | } | 302 | } |
301 | 303 | ||
302 | static int check_and_rewind_pc(char *put_str, char *arg) | 304 | static int check_and_rewind_pc(char *put_str, char *arg) |
303 | { | 305 | { |
304 | unsigned long addr = lookup_addr(arg); | 306 | unsigned long addr = lookup_addr(arg); |
305 | unsigned long ip; | 307 | unsigned long ip; |
306 | int offset = 0; | 308 | int offset = 0; |
307 | 309 | ||
308 | kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs, | 310 | kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs, |
309 | NUMREGBYTES); | 311 | NUMREGBYTES); |
310 | gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs); | 312 | gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs); |
311 | ip = instruction_pointer(&kgdbts_regs); | 313 | ip = instruction_pointer(&kgdbts_regs); |
312 | v2printk("Stopped at IP: %lx\n", ip); | 314 | v2printk("Stopped at IP: %lx\n", ip); |
313 | #ifdef GDB_ADJUSTS_BREAK_OFFSET | 315 | #ifdef GDB_ADJUSTS_BREAK_OFFSET |
314 | /* On some arches, a breakpoint stop requires it to be decremented */ | 316 | /* On some arches, a breakpoint stop requires it to be decremented */ |
315 | if (addr + BREAK_INSTR_SIZE == ip) | 317 | if (addr + BREAK_INSTR_SIZE == ip) |
316 | offset = -BREAK_INSTR_SIZE; | 318 | offset = -BREAK_INSTR_SIZE; |
317 | #endif | 319 | #endif |
318 | 320 | ||
319 | if (arch_needs_sstep_emulation && sstep_addr && | 321 | if (arch_needs_sstep_emulation && sstep_addr && |
320 | ip + offset == sstep_addr && | 322 | ip + offset == sstep_addr && |
321 | ((!strcmp(arg, "sys_open") || !strcmp(arg, "do_fork")))) { | 323 | ((!strcmp(arg, "sys_open") || !strcmp(arg, "do_fork")))) { |
322 | /* This is special case for emulated single step */ | 324 | /* This is special case for emulated single step */ |
323 | v2printk("Emul: rewind hit single step bp\n"); | 325 | v2printk("Emul: rewind hit single step bp\n"); |
324 | restart_from_top_after_write = 1; | 326 | restart_from_top_after_write = 1; |
325 | } else if (strcmp(arg, "silent") && ip + offset != addr) { | 327 | } else if (strcmp(arg, "silent") && ip + offset != addr) { |
326 | eprintk("kgdbts: BP mismatch %lx expected %lx\n", | 328 | eprintk("kgdbts: BP mismatch %lx expected %lx\n", |
327 | ip + offset, addr); | 329 | ip + offset, addr); |
328 | return 1; | 330 | return 1; |
329 | } | 331 | } |
330 | /* Readjust the instruction pointer if needed */ | 332 | /* Readjust the instruction pointer if needed */ |
331 | ip += offset; | 333 | ip += offset; |
332 | cont_addr = ip; | 334 | cont_addr = ip; |
333 | #ifdef GDB_ADJUSTS_BREAK_OFFSET | 335 | #ifdef GDB_ADJUSTS_BREAK_OFFSET |
334 | instruction_pointer_set(&kgdbts_regs, ip); | 336 | instruction_pointer_set(&kgdbts_regs, ip); |
335 | #endif | 337 | #endif |
336 | return 0; | 338 | return 0; |
337 | } | 339 | } |
338 | 340 | ||
339 | static int check_single_step(char *put_str, char *arg) | 341 | static int check_single_step(char *put_str, char *arg) |
340 | { | 342 | { |
341 | unsigned long addr = lookup_addr(arg); | 343 | unsigned long addr = lookup_addr(arg); |
342 | static int matched_id; | 344 | static int matched_id; |
343 | 345 | ||
344 | /* | 346 | /* |
345 | * From an arch indepent point of view the instruction pointer | 347 | * From an arch indepent point of view the instruction pointer |
346 | * should be on a different instruction | 348 | * should be on a different instruction |
347 | */ | 349 | */ |
348 | kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs, | 350 | kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs, |
349 | NUMREGBYTES); | 351 | NUMREGBYTES); |
350 | gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs); | 352 | gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs); |
351 | v2printk("Singlestep stopped at IP: %lx\n", | 353 | v2printk("Singlestep stopped at IP: %lx\n", |
352 | instruction_pointer(&kgdbts_regs)); | 354 | instruction_pointer(&kgdbts_regs)); |
353 | 355 | ||
354 | if (sstep_thread_id != cont_thread_id) { | 356 | if (sstep_thread_id != cont_thread_id) { |
355 | /* | 357 | /* |
356 | * Ensure we stopped in the same thread id as before, else the | 358 | * Ensure we stopped in the same thread id as before, else the |
357 | * debugger should continue until the original thread that was | 359 | * debugger should continue until the original thread that was |
358 | * single stepped is scheduled again, emulating gdb's behavior. | 360 | * single stepped is scheduled again, emulating gdb's behavior. |
359 | */ | 361 | */ |
360 | v2printk("ThrID does not match: %lx\n", cont_thread_id); | 362 | v2printk("ThrID does not match: %lx\n", cont_thread_id); |
361 | if (arch_needs_sstep_emulation) { | 363 | if (arch_needs_sstep_emulation) { |
362 | if (matched_id && | 364 | if (matched_id && |
363 | instruction_pointer(&kgdbts_regs) != addr) | 365 | instruction_pointer(&kgdbts_regs) != addr) |
364 | goto continue_test; | 366 | goto continue_test; |
365 | matched_id++; | 367 | matched_id++; |
366 | ts.idx -= 2; | 368 | ts.idx -= 2; |
367 | sstep_state = 0; | 369 | sstep_state = 0; |
368 | return 0; | 370 | return 0; |
369 | } | 371 | } |
370 | cont_instead_of_sstep = 1; | 372 | cont_instead_of_sstep = 1; |
371 | ts.idx -= 4; | 373 | ts.idx -= 4; |
372 | return 0; | 374 | return 0; |
373 | } | 375 | } |
374 | continue_test: | 376 | continue_test: |
375 | matched_id = 0; | 377 | matched_id = 0; |
376 | if (instruction_pointer(&kgdbts_regs) == addr) { | 378 | if (instruction_pointer(&kgdbts_regs) == addr) { |
377 | eprintk("kgdbts: SingleStep failed at %lx\n", | 379 | eprintk("kgdbts: SingleStep failed at %lx\n", |
378 | instruction_pointer(&kgdbts_regs)); | 380 | instruction_pointer(&kgdbts_regs)); |
379 | return 1; | 381 | return 1; |
380 | } | 382 | } |
381 | 383 | ||
382 | return 0; | 384 | return 0; |
383 | } | 385 | } |
384 | 386 | ||
385 | static void write_regs(char *arg) | 387 | static void write_regs(char *arg) |
386 | { | 388 | { |
387 | memset(scratch_buf, 0, sizeof(scratch_buf)); | 389 | memset(scratch_buf, 0, sizeof(scratch_buf)); |
388 | scratch_buf[0] = 'G'; | 390 | scratch_buf[0] = 'G'; |
389 | pt_regs_to_gdb_regs(kgdbts_gdb_regs, &kgdbts_regs); | 391 | pt_regs_to_gdb_regs(kgdbts_gdb_regs, &kgdbts_regs); |
390 | kgdb_mem2hex((char *)kgdbts_gdb_regs, &scratch_buf[1], NUMREGBYTES); | 392 | kgdb_mem2hex((char *)kgdbts_gdb_regs, &scratch_buf[1], NUMREGBYTES); |
391 | fill_get_buf(scratch_buf); | 393 | fill_get_buf(scratch_buf); |
392 | } | 394 | } |
393 | 395 | ||
394 | static void skip_back_repeat_test(char *arg) | 396 | static void skip_back_repeat_test(char *arg) |
395 | { | 397 | { |
396 | int go_back = simple_strtol(arg, NULL, 10); | 398 | int go_back = simple_strtol(arg, NULL, 10); |
397 | 399 | ||
398 | repeat_test--; | 400 | repeat_test--; |
399 | if (repeat_test <= 0) | 401 | if (repeat_test <= 0) |
400 | ts.idx++; | 402 | ts.idx++; |
401 | else | 403 | else |
402 | ts.idx -= go_back; | 404 | ts.idx -= go_back; |
403 | fill_get_buf(ts.tst[ts.idx].get); | 405 | fill_get_buf(ts.tst[ts.idx].get); |
404 | } | 406 | } |
405 | 407 | ||
406 | static int got_break(char *put_str, char *arg) | 408 | static int got_break(char *put_str, char *arg) |
407 | { | 409 | { |
408 | test_complete = 1; | 410 | test_complete = 1; |
409 | if (!strncmp(put_str+1, arg, 2)) { | 411 | if (!strncmp(put_str+1, arg, 2)) { |
410 | if (!strncmp(arg, "T0", 2)) | 412 | if (!strncmp(arg, "T0", 2)) |
411 | test_complete = 2; | 413 | test_complete = 2; |
412 | return 0; | 414 | return 0; |
413 | } | 415 | } |
414 | return 1; | 416 | return 1; |
415 | } | 417 | } |
416 | 418 | ||
417 | static void get_cont_catch(char *arg) | 419 | static void get_cont_catch(char *arg) |
418 | { | 420 | { |
419 | /* Always send detach because the test is completed at this point */ | 421 | /* Always send detach because the test is completed at this point */ |
420 | fill_get_buf("D"); | 422 | fill_get_buf("D"); |
421 | } | 423 | } |
422 | 424 | ||
423 | static int put_cont_catch(char *put_str, char *arg) | 425 | static int put_cont_catch(char *put_str, char *arg) |
424 | { | 426 | { |
425 | /* This is at the end of the test and we catch any and all input */ | 427 | /* This is at the end of the test and we catch any and all input */ |
426 | v2printk("kgdbts: cleanup task: %lx\n", sstep_thread_id); | 428 | v2printk("kgdbts: cleanup task: %lx\n", sstep_thread_id); |
427 | ts.idx--; | 429 | ts.idx--; |
428 | return 0; | 430 | return 0; |
429 | } | 431 | } |
430 | 432 | ||
431 | static int emul_reset(char *put_str, char *arg) | 433 | static int emul_reset(char *put_str, char *arg) |
432 | { | 434 | { |
433 | if (strncmp(put_str, "$OK", 3)) | 435 | if (strncmp(put_str, "$OK", 3)) |
434 | return 1; | 436 | return 1; |
435 | if (restart_from_top_after_write) { | 437 | if (restart_from_top_after_write) { |
436 | restart_from_top_after_write = 0; | 438 | restart_from_top_after_write = 0; |
437 | ts.idx = -1; | 439 | ts.idx = -1; |
438 | } | 440 | } |
439 | return 0; | 441 | return 0; |
440 | } | 442 | } |
441 | 443 | ||
442 | static void emul_sstep_get(char *arg) | 444 | static void emul_sstep_get(char *arg) |
443 | { | 445 | { |
444 | if (!arch_needs_sstep_emulation) { | 446 | if (!arch_needs_sstep_emulation) { |
445 | if (cont_instead_of_sstep) { | 447 | if (cont_instead_of_sstep) { |
446 | cont_instead_of_sstep = 0; | 448 | cont_instead_of_sstep = 0; |
447 | fill_get_buf("c"); | 449 | fill_get_buf("c"); |
448 | } else { | 450 | } else { |
449 | fill_get_buf(arg); | 451 | fill_get_buf(arg); |
450 | } | 452 | } |
451 | return; | 453 | return; |
452 | } | 454 | } |
453 | switch (sstep_state) { | 455 | switch (sstep_state) { |
454 | case 0: | 456 | case 0: |
455 | v2printk("Emulate single step\n"); | 457 | v2printk("Emulate single step\n"); |
456 | /* Start by looking at the current PC */ | 458 | /* Start by looking at the current PC */ |
457 | fill_get_buf("g"); | 459 | fill_get_buf("g"); |
458 | break; | 460 | break; |
459 | case 1: | 461 | case 1: |
460 | /* set breakpoint */ | 462 | /* set breakpoint */ |
461 | break_helper("Z0", NULL, sstep_addr); | 463 | break_helper("Z0", NULL, sstep_addr); |
462 | break; | 464 | break; |
463 | case 2: | 465 | case 2: |
464 | /* Continue */ | 466 | /* Continue */ |
465 | fill_get_buf("c"); | 467 | fill_get_buf("c"); |
466 | break; | 468 | break; |
467 | case 3: | 469 | case 3: |
468 | /* Clear breakpoint */ | 470 | /* Clear breakpoint */ |
469 | break_helper("z0", NULL, sstep_addr); | 471 | break_helper("z0", NULL, sstep_addr); |
470 | break; | 472 | break; |
471 | default: | 473 | default: |
472 | eprintk("kgdbts: ERROR failed sstep get emulation\n"); | 474 | eprintk("kgdbts: ERROR failed sstep get emulation\n"); |
473 | } | 475 | } |
474 | sstep_state++; | 476 | sstep_state++; |
475 | } | 477 | } |
476 | 478 | ||
477 | static int emul_sstep_put(char *put_str, char *arg) | 479 | static int emul_sstep_put(char *put_str, char *arg) |
478 | { | 480 | { |
479 | if (!arch_needs_sstep_emulation) { | 481 | if (!arch_needs_sstep_emulation) { |
480 | char *ptr = &put_str[11]; | 482 | char *ptr = &put_str[11]; |
481 | if (put_str[1] != 'T' || put_str[2] != '0') | 483 | if (put_str[1] != 'T' || put_str[2] != '0') |
482 | return 1; | 484 | return 1; |
483 | kgdb_hex2long(&ptr, &sstep_thread_id); | 485 | kgdb_hex2long(&ptr, &sstep_thread_id); |
484 | return 0; | 486 | return 0; |
485 | } | 487 | } |
486 | switch (sstep_state) { | 488 | switch (sstep_state) { |
487 | case 1: | 489 | case 1: |
488 | /* validate the "g" packet to get the IP */ | 490 | /* validate the "g" packet to get the IP */ |
489 | kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs, | 491 | kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs, |
490 | NUMREGBYTES); | 492 | NUMREGBYTES); |
491 | gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs); | 493 | gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs); |
492 | v2printk("Stopped at IP: %lx\n", | 494 | v2printk("Stopped at IP: %lx\n", |
493 | instruction_pointer(&kgdbts_regs)); | 495 | instruction_pointer(&kgdbts_regs)); |
494 | /* Want to stop at IP + break instruction size by default */ | 496 | /* Want to stop at IP + break instruction size by default */ |
495 | sstep_addr = cont_addr + BREAK_INSTR_SIZE; | 497 | sstep_addr = cont_addr + BREAK_INSTR_SIZE; |
496 | break; | 498 | break; |
497 | case 2: | 499 | case 2: |
498 | if (strncmp(put_str, "$OK", 3)) { | 500 | if (strncmp(put_str, "$OK", 3)) { |
499 | eprintk("kgdbts: failed sstep break set\n"); | 501 | eprintk("kgdbts: failed sstep break set\n"); |
500 | return 1; | 502 | return 1; |
501 | } | 503 | } |
502 | break; | 504 | break; |
503 | case 3: | 505 | case 3: |
504 | if (strncmp(put_str, "$T0", 3)) { | 506 | if (strncmp(put_str, "$T0", 3)) { |
505 | eprintk("kgdbts: failed continue sstep\n"); | 507 | eprintk("kgdbts: failed continue sstep\n"); |
506 | return 1; | 508 | return 1; |
507 | } else { | 509 | } else { |
508 | char *ptr = &put_str[11]; | 510 | char *ptr = &put_str[11]; |
509 | kgdb_hex2long(&ptr, &sstep_thread_id); | 511 | kgdb_hex2long(&ptr, &sstep_thread_id); |
510 | } | 512 | } |
511 | break; | 513 | break; |
512 | case 4: | 514 | case 4: |
513 | if (strncmp(put_str, "$OK", 3)) { | 515 | if (strncmp(put_str, "$OK", 3)) { |
514 | eprintk("kgdbts: failed sstep break unset\n"); | 516 | eprintk("kgdbts: failed sstep break unset\n"); |
515 | return 1; | 517 | return 1; |
516 | } | 518 | } |
517 | /* Single step is complete so continue on! */ | 519 | /* Single step is complete so continue on! */ |
518 | sstep_state = 0; | 520 | sstep_state = 0; |
519 | return 0; | 521 | return 0; |
520 | default: | 522 | default: |
521 | eprintk("kgdbts: ERROR failed sstep put emulation\n"); | 523 | eprintk("kgdbts: ERROR failed sstep put emulation\n"); |
522 | } | 524 | } |
523 | 525 | ||
524 | /* Continue on the same test line until emulation is complete */ | 526 | /* Continue on the same test line until emulation is complete */ |
525 | ts.idx--; | 527 | ts.idx--; |
526 | return 0; | 528 | return 0; |
527 | } | 529 | } |
528 | 530 | ||
529 | static int final_ack_set(char *put_str, char *arg) | 531 | static int final_ack_set(char *put_str, char *arg) |
530 | { | 532 | { |
531 | if (strncmp(put_str+1, arg, 2)) | 533 | if (strncmp(put_str+1, arg, 2)) |
532 | return 1; | 534 | return 1; |
533 | final_ack = 1; | 535 | final_ack = 1; |
534 | return 0; | 536 | return 0; |
535 | } | 537 | } |
536 | /* | 538 | /* |
537 | * Test to plant a breakpoint and detach, which should clear out the | 539 | * Test to plant a breakpoint and detach, which should clear out the |
538 | * breakpoint and restore the original instruction. | 540 | * breakpoint and restore the original instruction. |
539 | */ | 541 | */ |
540 | static struct test_struct plant_and_detach_test[] = { | 542 | static struct test_struct plant_and_detach_test[] = { |
541 | { "?", "S0*" }, /* Clear break points */ | 543 | { "?", "S0*" }, /* Clear break points */ |
542 | { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ | 544 | { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ |
543 | { "D", "OK" }, /* Detach */ | 545 | { "D", "OK" }, /* Detach */ |
544 | { "", "" }, | 546 | { "", "" }, |
545 | }; | 547 | }; |
546 | 548 | ||
547 | /* | 549 | /* |
548 | * Simple test to write in a software breakpoint, check for the | 550 | * Simple test to write in a software breakpoint, check for the |
549 | * correct stop location and detach. | 551 | * correct stop location and detach. |
550 | */ | 552 | */ |
551 | static struct test_struct sw_breakpoint_test[] = { | 553 | static struct test_struct sw_breakpoint_test[] = { |
552 | { "?", "S0*" }, /* Clear break points */ | 554 | { "?", "S0*" }, /* Clear break points */ |
553 | { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ | 555 | { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ |
554 | { "c", "T0*", }, /* Continue */ | 556 | { "c", "T0*", }, /* Continue */ |
555 | { "g", "kgdbts_break_test", NULL, check_and_rewind_pc }, | 557 | { "g", "kgdbts_break_test", NULL, check_and_rewind_pc }, |
556 | { "write", "OK", write_regs }, | 558 | { "write", "OK", write_regs }, |
557 | { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */ | 559 | { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */ |
558 | { "D", "OK" }, /* Detach */ | 560 | { "D", "OK" }, /* Detach */ |
559 | { "D", "OK", NULL, got_break }, /* On success we made it here */ | 561 | { "D", "OK", NULL, got_break }, /* On success we made it here */ |
560 | { "", "" }, | 562 | { "", "" }, |
561 | }; | 563 | }; |
562 | 564 | ||
563 | /* | 565 | /* |
564 | * Test a known bad memory read location to test the fault handler and | 566 | * Test a known bad memory read location to test the fault handler and |
565 | * read bytes 1-8 at the bad address | 567 | * read bytes 1-8 at the bad address |
566 | */ | 568 | */ |
567 | static struct test_struct bad_read_test[] = { | 569 | static struct test_struct bad_read_test[] = { |
568 | { "?", "S0*" }, /* Clear break points */ | 570 | { "?", "S0*" }, /* Clear break points */ |
569 | { "m0,1", "E*" }, /* read 1 byte at address 1 */ | 571 | { "m0,1", "E*" }, /* read 1 byte at address 1 */ |
570 | { "m0,2", "E*" }, /* read 1 byte at address 2 */ | 572 | { "m0,2", "E*" }, /* read 1 byte at address 2 */ |
571 | { "m0,3", "E*" }, /* read 1 byte at address 3 */ | 573 | { "m0,3", "E*" }, /* read 1 byte at address 3 */ |
572 | { "m0,4", "E*" }, /* read 1 byte at address 4 */ | 574 | { "m0,4", "E*" }, /* read 1 byte at address 4 */ |
573 | { "m0,5", "E*" }, /* read 1 byte at address 5 */ | 575 | { "m0,5", "E*" }, /* read 1 byte at address 5 */ |
574 | { "m0,6", "E*" }, /* read 1 byte at address 6 */ | 576 | { "m0,6", "E*" }, /* read 1 byte at address 6 */ |
575 | { "m0,7", "E*" }, /* read 1 byte at address 7 */ | 577 | { "m0,7", "E*" }, /* read 1 byte at address 7 */ |
576 | { "m0,8", "E*" }, /* read 1 byte at address 8 */ | 578 | { "m0,8", "E*" }, /* read 1 byte at address 8 */ |
577 | { "D", "OK" }, /* Detach which removes all breakpoints and continues */ | 579 | { "D", "OK" }, /* Detach which removes all breakpoints and continues */ |
578 | { "", "" }, | 580 | { "", "" }, |
579 | }; | 581 | }; |
580 | 582 | ||
581 | /* | 583 | /* |
582 | * Test for hitting a breakpoint, remove it, single step, plant it | 584 | * Test for hitting a breakpoint, remove it, single step, plant it |
583 | * again and detach. | 585 | * again and detach. |
584 | */ | 586 | */ |
585 | static struct test_struct singlestep_break_test[] = { | 587 | static struct test_struct singlestep_break_test[] = { |
586 | { "?", "S0*" }, /* Clear break points */ | 588 | { "?", "S0*" }, /* Clear break points */ |
587 | { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ | 589 | { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ |
588 | { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */ | 590 | { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */ |
589 | { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */ | 591 | { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */ |
590 | { "g", "kgdbts_break_test", NULL, check_and_rewind_pc }, | 592 | { "g", "kgdbts_break_test", NULL, check_and_rewind_pc }, |
591 | { "write", "OK", write_regs }, /* Write registers */ | 593 | { "write", "OK", write_regs }, /* Write registers */ |
592 | { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ | 594 | { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ |
593 | { "g", "kgdbts_break_test", NULL, check_single_step }, | 595 | { "g", "kgdbts_break_test", NULL, check_single_step }, |
594 | { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ | 596 | { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ |
595 | { "c", "T0*", }, /* Continue */ | 597 | { "c", "T0*", }, /* Continue */ |
596 | { "g", "kgdbts_break_test", NULL, check_and_rewind_pc }, | 598 | { "g", "kgdbts_break_test", NULL, check_and_rewind_pc }, |
597 | { "write", "OK", write_regs }, /* Write registers */ | 599 | { "write", "OK", write_regs }, /* Write registers */ |
598 | { "D", "OK" }, /* Remove all breakpoints and continues */ | 600 | { "D", "OK" }, /* Remove all breakpoints and continues */ |
599 | { "", "" }, | 601 | { "", "" }, |
600 | }; | 602 | }; |
601 | 603 | ||
602 | /* | 604 | /* |
603 | * Test for hitting a breakpoint at do_fork for what ever the number | 605 | * Test for hitting a breakpoint at do_fork for what ever the number |
604 | * of iterations required by the variable repeat_test. | 606 | * of iterations required by the variable repeat_test. |
605 | */ | 607 | */ |
606 | static struct test_struct do_fork_test[] = { | 608 | static struct test_struct do_fork_test[] = { |
607 | { "?", "S0*" }, /* Clear break points */ | 609 | { "?", "S0*" }, /* Clear break points */ |
608 | { "do_fork", "OK", sw_break, }, /* set sw breakpoint */ | 610 | { "do_fork", "OK", sw_break, }, /* set sw breakpoint */ |
609 | { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */ | 611 | { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */ |
610 | { "do_fork", "OK", sw_rem_break }, /*remove breakpoint */ | 612 | { "do_fork", "OK", sw_rem_break }, /*remove breakpoint */ |
611 | { "g", "do_fork", NULL, check_and_rewind_pc }, /* check location */ | 613 | { "g", "do_fork", NULL, check_and_rewind_pc }, /* check location */ |
612 | { "write", "OK", write_regs, emul_reset }, /* Write registers */ | 614 | { "write", "OK", write_regs, emul_reset }, /* Write registers */ |
613 | { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ | 615 | { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ |
614 | { "g", "do_fork", NULL, check_single_step }, | 616 | { "g", "do_fork", NULL, check_single_step }, |
615 | { "do_fork", "OK", sw_break, }, /* set sw breakpoint */ | 617 | { "do_fork", "OK", sw_break, }, /* set sw breakpoint */ |
616 | { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */ | 618 | { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */ |
617 | { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */ | 619 | { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */ |
618 | { "", "", get_cont_catch, put_cont_catch }, | 620 | { "", "", get_cont_catch, put_cont_catch }, |
619 | }; | 621 | }; |
620 | 622 | ||
621 | /* Test for hitting a breakpoint at sys_open for what ever the number | 623 | /* Test for hitting a breakpoint at sys_open for what ever the number |
622 | * of iterations required by the variable repeat_test. | 624 | * of iterations required by the variable repeat_test. |
623 | */ | 625 | */ |
624 | static struct test_struct sys_open_test[] = { | 626 | static struct test_struct sys_open_test[] = { |
625 | { "?", "S0*" }, /* Clear break points */ | 627 | { "?", "S0*" }, /* Clear break points */ |
626 | { "sys_open", "OK", sw_break, }, /* set sw breakpoint */ | 628 | { "sys_open", "OK", sw_break, }, /* set sw breakpoint */ |
627 | { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */ | 629 | { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */ |
628 | { "sys_open", "OK", sw_rem_break }, /*remove breakpoint */ | 630 | { "sys_open", "OK", sw_rem_break }, /*remove breakpoint */ |
629 | { "g", "sys_open", NULL, check_and_rewind_pc }, /* check location */ | 631 | { "g", "sys_open", NULL, check_and_rewind_pc }, /* check location */ |
630 | { "write", "OK", write_regs, emul_reset }, /* Write registers */ | 632 | { "write", "OK", write_regs, emul_reset }, /* Write registers */ |
631 | { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ | 633 | { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ |
632 | { "g", "sys_open", NULL, check_single_step }, | 634 | { "g", "sys_open", NULL, check_single_step }, |
633 | { "sys_open", "OK", sw_break, }, /* set sw breakpoint */ | 635 | { "sys_open", "OK", sw_break, }, /* set sw breakpoint */ |
634 | { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */ | 636 | { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */ |
635 | { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */ | 637 | { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */ |
636 | { "", "", get_cont_catch, put_cont_catch }, | 638 | { "", "", get_cont_catch, put_cont_catch }, |
637 | }; | 639 | }; |
638 | 640 | ||
639 | /* | 641 | /* |
640 | * Test for hitting a simple hw breakpoint | 642 | * Test for hitting a simple hw breakpoint |
641 | */ | 643 | */ |
642 | static struct test_struct hw_breakpoint_test[] = { | 644 | static struct test_struct hw_breakpoint_test[] = { |
643 | { "?", "S0*" }, /* Clear break points */ | 645 | { "?", "S0*" }, /* Clear break points */ |
644 | { "kgdbts_break_test", "OK", hw_break, }, /* set hw breakpoint */ | 646 | { "kgdbts_break_test", "OK", hw_break, }, /* set hw breakpoint */ |
645 | { "c", "T0*", }, /* Continue */ | 647 | { "c", "T0*", }, /* Continue */ |
646 | { "g", "kgdbts_break_test", NULL, check_and_rewind_pc }, | 648 | { "g", "kgdbts_break_test", NULL, check_and_rewind_pc }, |
647 | { "write", "OK", write_regs }, | 649 | { "write", "OK", write_regs }, |
648 | { "kgdbts_break_test", "OK", hw_rem_break }, /*remove breakpoint */ | 650 | { "kgdbts_break_test", "OK", hw_rem_break }, /*remove breakpoint */ |
649 | { "D", "OK" }, /* Detach */ | 651 | { "D", "OK" }, /* Detach */ |
650 | { "D", "OK", NULL, got_break }, /* On success we made it here */ | 652 | { "D", "OK", NULL, got_break }, /* On success we made it here */ |
651 | { "", "" }, | 653 | { "", "" }, |
652 | }; | 654 | }; |
653 | 655 | ||
654 | /* | 656 | /* |
655 | * Test for hitting a hw write breakpoint | 657 | * Test for hitting a hw write breakpoint |
656 | */ | 658 | */ |
657 | static struct test_struct hw_write_break_test[] = { | 659 | static struct test_struct hw_write_break_test[] = { |
658 | { "?", "S0*" }, /* Clear break points */ | 660 | { "?", "S0*" }, /* Clear break points */ |
659 | { "hw_break_val", "OK", hw_write_break, }, /* set hw breakpoint */ | 661 | { "hw_break_val", "OK", hw_write_break, }, /* set hw breakpoint */ |
660 | { "c", "T0*", NULL, got_break }, /* Continue */ | 662 | { "c", "T0*", NULL, got_break }, /* Continue */ |
661 | { "g", "silent", NULL, check_and_rewind_pc }, | 663 | { "g", "silent", NULL, check_and_rewind_pc }, |
662 | { "write", "OK", write_regs }, | 664 | { "write", "OK", write_regs }, |
663 | { "hw_break_val", "OK", hw_rem_write_break }, /*remove breakpoint */ | 665 | { "hw_break_val", "OK", hw_rem_write_break }, /*remove breakpoint */ |
664 | { "D", "OK" }, /* Detach */ | 666 | { "D", "OK" }, /* Detach */ |
665 | { "D", "OK", NULL, got_break }, /* On success we made it here */ | 667 | { "D", "OK", NULL, got_break }, /* On success we made it here */ |
666 | { "", "" }, | 668 | { "", "" }, |
667 | }; | 669 | }; |
668 | 670 | ||
669 | /* | 671 | /* |
670 | * Test for hitting a hw access breakpoint | 672 | * Test for hitting a hw access breakpoint |
671 | */ | 673 | */ |
672 | static struct test_struct hw_access_break_test[] = { | 674 | static struct test_struct hw_access_break_test[] = { |
673 | { "?", "S0*" }, /* Clear break points */ | 675 | { "?", "S0*" }, /* Clear break points */ |
674 | { "hw_break_val", "OK", hw_access_break, }, /* set hw breakpoint */ | 676 | { "hw_break_val", "OK", hw_access_break, }, /* set hw breakpoint */ |
675 | { "c", "T0*", NULL, got_break }, /* Continue */ | 677 | { "c", "T0*", NULL, got_break }, /* Continue */ |
676 | { "g", "silent", NULL, check_and_rewind_pc }, | 678 | { "g", "silent", NULL, check_and_rewind_pc }, |
677 | { "write", "OK", write_regs }, | 679 | { "write", "OK", write_regs }, |
678 | { "hw_break_val", "OK", hw_rem_access_break }, /*remove breakpoint */ | 680 | { "hw_break_val", "OK", hw_rem_access_break }, /*remove breakpoint */ |
679 | { "D", "OK" }, /* Detach */ | 681 | { "D", "OK" }, /* Detach */ |
680 | { "D", "OK", NULL, got_break }, /* On success we made it here */ | 682 | { "D", "OK", NULL, got_break }, /* On success we made it here */ |
681 | { "", "" }, | 683 | { "", "" }, |
682 | }; | 684 | }; |
683 | 685 | ||
684 | /* | 686 | /* |
685 | * Test for hitting a hw access breakpoint | 687 | * Test for hitting a hw access breakpoint |
686 | */ | 688 | */ |
687 | static struct test_struct nmi_sleep_test[] = { | 689 | static struct test_struct nmi_sleep_test[] = { |
688 | { "?", "S0*" }, /* Clear break points */ | 690 | { "?", "S0*" }, /* Clear break points */ |
689 | { "c", "T0*", NULL, got_break }, /* Continue */ | 691 | { "c", "T0*", NULL, got_break }, /* Continue */ |
690 | { "D", "OK" }, /* Detach */ | 692 | { "D", "OK" }, /* Detach */ |
691 | { "D", "OK", NULL, got_break }, /* On success we made it here */ | 693 | { "D", "OK", NULL, got_break }, /* On success we made it here */ |
692 | { "", "" }, | 694 | { "", "" }, |
693 | }; | 695 | }; |
694 | 696 | ||
695 | static void fill_get_buf(char *buf) | 697 | static void fill_get_buf(char *buf) |
696 | { | 698 | { |
697 | unsigned char checksum = 0; | 699 | unsigned char checksum = 0; |
698 | int count = 0; | 700 | int count = 0; |
699 | char ch; | 701 | char ch; |
700 | 702 | ||
701 | strcpy(get_buf, "$"); | 703 | strcpy(get_buf, "$"); |
702 | strcat(get_buf, buf); | 704 | strcat(get_buf, buf); |
703 | while ((ch = buf[count])) { | 705 | while ((ch = buf[count])) { |
704 | checksum += ch; | 706 | checksum += ch; |
705 | count++; | 707 | count++; |
706 | } | 708 | } |
707 | strcat(get_buf, "#"); | 709 | strcat(get_buf, "#"); |
708 | get_buf[count + 2] = hex_asc_hi(checksum); | 710 | get_buf[count + 2] = hex_asc_hi(checksum); |
709 | get_buf[count + 3] = hex_asc_lo(checksum); | 711 | get_buf[count + 3] = hex_asc_lo(checksum); |
710 | get_buf[count + 4] = '\0'; | 712 | get_buf[count + 4] = '\0'; |
711 | v2printk("get%i: %s\n", ts.idx, get_buf); | 713 | v2printk("get%i: %s\n", ts.idx, get_buf); |
712 | } | 714 | } |
713 | 715 | ||
714 | static int validate_simple_test(char *put_str) | 716 | static int validate_simple_test(char *put_str) |
715 | { | 717 | { |
716 | char *chk_str; | 718 | char *chk_str; |
717 | 719 | ||
718 | if (ts.tst[ts.idx].put_handler) | 720 | if (ts.tst[ts.idx].put_handler) |
719 | return ts.tst[ts.idx].put_handler(put_str, | 721 | return ts.tst[ts.idx].put_handler(put_str, |
720 | ts.tst[ts.idx].put); | 722 | ts.tst[ts.idx].put); |
721 | 723 | ||
722 | chk_str = ts.tst[ts.idx].put; | 724 | chk_str = ts.tst[ts.idx].put; |
723 | if (*put_str == '$') | 725 | if (*put_str == '$') |
724 | put_str++; | 726 | put_str++; |
725 | 727 | ||
726 | while (*chk_str != '\0' && *put_str != '\0') { | 728 | while (*chk_str != '\0' && *put_str != '\0') { |
727 | /* If someone does a * to match the rest of the string, allow | 729 | /* If someone does a * to match the rest of the string, allow |
728 | * it, or stop if the received string is complete. | 730 | * it, or stop if the received string is complete. |
729 | */ | 731 | */ |
730 | if (*put_str == '#' || *chk_str == '*') | 732 | if (*put_str == '#' || *chk_str == '*') |
731 | return 0; | 733 | return 0; |
732 | if (*put_str != *chk_str) | 734 | if (*put_str != *chk_str) |
733 | return 1; | 735 | return 1; |
734 | 736 | ||
735 | chk_str++; | 737 | chk_str++; |
736 | put_str++; | 738 | put_str++; |
737 | } | 739 | } |
738 | if (*chk_str == '\0' && (*put_str == '\0' || *put_str == '#')) | 740 | if (*chk_str == '\0' && (*put_str == '\0' || *put_str == '#')) |
739 | return 0; | 741 | return 0; |
740 | 742 | ||
741 | return 1; | 743 | return 1; |
742 | } | 744 | } |
743 | 745 | ||
744 | static int run_simple_test(int is_get_char, int chr) | 746 | static int run_simple_test(int is_get_char, int chr) |
745 | { | 747 | { |
746 | int ret = 0; | 748 | int ret = 0; |
747 | if (is_get_char) { | 749 | if (is_get_char) { |
748 | /* Send an ACK on the get if a prior put completed and set the | 750 | /* Send an ACK on the get if a prior put completed and set the |
749 | * send ack variable | 751 | * send ack variable |
750 | */ | 752 | */ |
751 | if (send_ack) { | 753 | if (send_ack) { |
752 | send_ack = 0; | 754 | send_ack = 0; |
753 | return '+'; | 755 | return '+'; |
754 | } | 756 | } |
755 | /* On the first get char, fill the transmit buffer and then | 757 | /* On the first get char, fill the transmit buffer and then |
756 | * take from the get_string. | 758 | * take from the get_string. |
757 | */ | 759 | */ |
758 | if (get_buf_cnt == 0) { | 760 | if (get_buf_cnt == 0) { |
759 | if (ts.tst[ts.idx].get_handler) | 761 | if (ts.tst[ts.idx].get_handler) |
760 | ts.tst[ts.idx].get_handler(ts.tst[ts.idx].get); | 762 | ts.tst[ts.idx].get_handler(ts.tst[ts.idx].get); |
761 | else | 763 | else |
762 | fill_get_buf(ts.tst[ts.idx].get); | 764 | fill_get_buf(ts.tst[ts.idx].get); |
763 | } | 765 | } |
764 | 766 | ||
765 | if (get_buf[get_buf_cnt] == '\0') { | 767 | if (get_buf[get_buf_cnt] == '\0') { |
766 | eprintk("kgdbts: ERROR GET: EOB on '%s' at %i\n", | 768 | eprintk("kgdbts: ERROR GET: EOB on '%s' at %i\n", |
767 | ts.name, ts.idx); | 769 | ts.name, ts.idx); |
768 | get_buf_cnt = 0; | 770 | get_buf_cnt = 0; |
769 | fill_get_buf("D"); | 771 | fill_get_buf("D"); |
770 | } | 772 | } |
771 | ret = get_buf[get_buf_cnt]; | 773 | ret = get_buf[get_buf_cnt]; |
772 | get_buf_cnt++; | 774 | get_buf_cnt++; |
773 | return ret; | 775 | return ret; |
774 | } | 776 | } |
775 | 777 | ||
776 | /* This callback is a put char which is when kgdb sends data to | 778 | /* This callback is a put char which is when kgdb sends data to |
777 | * this I/O module. | 779 | * this I/O module. |
778 | */ | 780 | */ |
779 | if (ts.tst[ts.idx].get[0] == '\0' && ts.tst[ts.idx].put[0] == '\0' && | 781 | if (ts.tst[ts.idx].get[0] == '\0' && ts.tst[ts.idx].put[0] == '\0' && |
780 | !ts.tst[ts.idx].get_handler) { | 782 | !ts.tst[ts.idx].get_handler) { |
781 | eprintk("kgdbts: ERROR: beyond end of test on" | 783 | eprintk("kgdbts: ERROR: beyond end of test on" |
782 | " '%s' line %i\n", ts.name, ts.idx); | 784 | " '%s' line %i\n", ts.name, ts.idx); |
783 | return 0; | 785 | return 0; |
784 | } | 786 | } |
785 | 787 | ||
786 | if (put_buf_cnt >= BUFMAX) { | 788 | if (put_buf_cnt >= BUFMAX) { |
787 | eprintk("kgdbts: ERROR: put buffer overflow on" | 789 | eprintk("kgdbts: ERROR: put buffer overflow on" |
788 | " '%s' line %i\n", ts.name, ts.idx); | 790 | " '%s' line %i\n", ts.name, ts.idx); |
789 | put_buf_cnt = 0; | 791 | put_buf_cnt = 0; |
790 | return 0; | 792 | return 0; |
791 | } | 793 | } |
792 | /* Ignore everything until the first valid packet start '$' */ | 794 | /* Ignore everything until the first valid packet start '$' */ |
793 | if (put_buf_cnt == 0 && chr != '$') | 795 | if (put_buf_cnt == 0 && chr != '$') |
794 | return 0; | 796 | return 0; |
795 | 797 | ||
796 | put_buf[put_buf_cnt] = chr; | 798 | put_buf[put_buf_cnt] = chr; |
797 | put_buf_cnt++; | 799 | put_buf_cnt++; |
798 | 800 | ||
799 | /* End of packet == #XX so look for the '#' */ | 801 | /* End of packet == #XX so look for the '#' */ |
800 | if (put_buf_cnt > 3 && put_buf[put_buf_cnt - 3] == '#') { | 802 | if (put_buf_cnt > 3 && put_buf[put_buf_cnt - 3] == '#') { |
801 | if (put_buf_cnt >= BUFMAX) { | 803 | if (put_buf_cnt >= BUFMAX) { |
802 | eprintk("kgdbts: ERROR: put buffer overflow on" | 804 | eprintk("kgdbts: ERROR: put buffer overflow on" |
803 | " '%s' line %i\n", ts.name, ts.idx); | 805 | " '%s' line %i\n", ts.name, ts.idx); |
804 | put_buf_cnt = 0; | 806 | put_buf_cnt = 0; |
805 | return 0; | 807 | return 0; |
806 | } | 808 | } |
807 | put_buf[put_buf_cnt] = '\0'; | 809 | put_buf[put_buf_cnt] = '\0'; |
808 | v2printk("put%i: %s\n", ts.idx, put_buf); | 810 | v2printk("put%i: %s\n", ts.idx, put_buf); |
809 | /* Trigger check here */ | 811 | /* Trigger check here */ |
810 | if (ts.validate_put && ts.validate_put(put_buf)) { | 812 | if (ts.validate_put && ts.validate_put(put_buf)) { |
811 | eprintk("kgdbts: ERROR PUT: end of test " | 813 | eprintk("kgdbts: ERROR PUT: end of test " |
812 | "buffer on '%s' line %i expected %s got %s\n", | 814 | "buffer on '%s' line %i expected %s got %s\n", |
813 | ts.name, ts.idx, ts.tst[ts.idx].put, put_buf); | 815 | ts.name, ts.idx, ts.tst[ts.idx].put, put_buf); |
814 | } | 816 | } |
815 | ts.idx++; | 817 | ts.idx++; |
816 | put_buf_cnt = 0; | 818 | put_buf_cnt = 0; |
817 | get_buf_cnt = 0; | 819 | get_buf_cnt = 0; |
818 | send_ack = 1; | 820 | send_ack = 1; |
819 | } | 821 | } |
820 | return 0; | 822 | return 0; |
821 | } | 823 | } |
822 | 824 | ||
823 | static void init_simple_test(void) | 825 | static void init_simple_test(void) |
824 | { | 826 | { |
825 | memset(&ts, 0, sizeof(ts)); | 827 | memset(&ts, 0, sizeof(ts)); |
826 | ts.run_test = run_simple_test; | 828 | ts.run_test = run_simple_test; |
827 | ts.validate_put = validate_simple_test; | 829 | ts.validate_put = validate_simple_test; |
828 | } | 830 | } |
829 | 831 | ||
830 | static void run_plant_and_detach_test(int is_early) | 832 | static void run_plant_and_detach_test(int is_early) |
831 | { | 833 | { |
832 | char before[BREAK_INSTR_SIZE]; | 834 | char before[BREAK_INSTR_SIZE]; |
833 | char after[BREAK_INSTR_SIZE]; | 835 | char after[BREAK_INSTR_SIZE]; |
834 | 836 | ||
835 | probe_kernel_read(before, (char *)kgdbts_break_test, | 837 | probe_kernel_read(before, (char *)kgdbts_break_test, |
836 | BREAK_INSTR_SIZE); | 838 | BREAK_INSTR_SIZE); |
837 | init_simple_test(); | 839 | init_simple_test(); |
838 | ts.tst = plant_and_detach_test; | 840 | ts.tst = plant_and_detach_test; |
839 | ts.name = "plant_and_detach_test"; | 841 | ts.name = "plant_and_detach_test"; |
840 | /* Activate test with initial breakpoint */ | 842 | /* Activate test with initial breakpoint */ |
841 | if (!is_early) | 843 | if (!is_early) |
842 | kgdb_breakpoint(); | 844 | kgdb_breakpoint(); |
843 | probe_kernel_read(after, (char *)kgdbts_break_test, | 845 | probe_kernel_read(after, (char *)kgdbts_break_test, |
844 | BREAK_INSTR_SIZE); | 846 | BREAK_INSTR_SIZE); |
845 | if (memcmp(before, after, BREAK_INSTR_SIZE)) { | 847 | if (memcmp(before, after, BREAK_INSTR_SIZE)) { |
846 | printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n"); | 848 | printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n"); |
847 | panic("kgdb memory corruption"); | 849 | panic("kgdb memory corruption"); |
848 | } | 850 | } |
849 | 851 | ||
850 | /* complete the detach test */ | 852 | /* complete the detach test */ |
851 | if (!is_early) | 853 | if (!is_early) |
852 | kgdbts_break_test(); | 854 | kgdbts_break_test(); |
853 | } | 855 | } |
854 | 856 | ||
855 | static void run_breakpoint_test(int is_hw_breakpoint) | 857 | static void run_breakpoint_test(int is_hw_breakpoint) |
856 | { | 858 | { |
857 | test_complete = 0; | 859 | test_complete = 0; |
858 | init_simple_test(); | 860 | init_simple_test(); |
859 | if (is_hw_breakpoint) { | 861 | if (is_hw_breakpoint) { |
860 | ts.tst = hw_breakpoint_test; | 862 | ts.tst = hw_breakpoint_test; |
861 | ts.name = "hw_breakpoint_test"; | 863 | ts.name = "hw_breakpoint_test"; |
862 | } else { | 864 | } else { |
863 | ts.tst = sw_breakpoint_test; | 865 | ts.tst = sw_breakpoint_test; |
864 | ts.name = "sw_breakpoint_test"; | 866 | ts.name = "sw_breakpoint_test"; |
865 | } | 867 | } |
866 | /* Activate test with initial breakpoint */ | 868 | /* Activate test with initial breakpoint */ |
867 | kgdb_breakpoint(); | 869 | kgdb_breakpoint(); |
868 | /* run code with the break point in it */ | 870 | /* run code with the break point in it */ |
869 | kgdbts_break_test(); | 871 | kgdbts_break_test(); |
870 | kgdb_breakpoint(); | 872 | kgdb_breakpoint(); |
871 | 873 | ||
872 | if (test_complete) | 874 | if (test_complete) |
873 | return; | 875 | return; |
874 | 876 | ||
875 | eprintk("kgdbts: ERROR %s test failed\n", ts.name); | 877 | eprintk("kgdbts: ERROR %s test failed\n", ts.name); |
876 | if (is_hw_breakpoint) | 878 | if (is_hw_breakpoint) |
877 | hwbreaks_ok = 0; | 879 | hwbreaks_ok = 0; |
878 | } | 880 | } |
879 | 881 | ||
880 | static void run_hw_break_test(int is_write_test) | 882 | static void run_hw_break_test(int is_write_test) |
881 | { | 883 | { |
882 | test_complete = 0; | 884 | test_complete = 0; |
883 | init_simple_test(); | 885 | init_simple_test(); |
884 | if (is_write_test) { | 886 | if (is_write_test) { |
885 | ts.tst = hw_write_break_test; | 887 | ts.tst = hw_write_break_test; |
886 | ts.name = "hw_write_break_test"; | 888 | ts.name = "hw_write_break_test"; |
887 | } else { | 889 | } else { |
888 | ts.tst = hw_access_break_test; | 890 | ts.tst = hw_access_break_test; |
889 | ts.name = "hw_access_break_test"; | 891 | ts.name = "hw_access_break_test"; |
890 | } | 892 | } |
891 | /* Activate test with initial breakpoint */ | 893 | /* Activate test with initial breakpoint */ |
892 | kgdb_breakpoint(); | 894 | kgdb_breakpoint(); |
893 | hw_break_val_access(); | 895 | hw_break_val_access(); |
894 | if (is_write_test) { | 896 | if (is_write_test) { |
895 | if (test_complete == 2) { | 897 | if (test_complete == 2) { |
896 | eprintk("kgdbts: ERROR %s broke on access\n", | 898 | eprintk("kgdbts: ERROR %s broke on access\n", |
897 | ts.name); | 899 | ts.name); |
898 | hwbreaks_ok = 0; | 900 | hwbreaks_ok = 0; |
899 | } | 901 | } |
900 | hw_break_val_write(); | 902 | hw_break_val_write(); |
901 | } | 903 | } |
902 | kgdb_breakpoint(); | 904 | kgdb_breakpoint(); |
903 | 905 | ||
904 | if (test_complete == 1) | 906 | if (test_complete == 1) |
905 | return; | 907 | return; |
906 | 908 | ||
907 | eprintk("kgdbts: ERROR %s test failed\n", ts.name); | 909 | eprintk("kgdbts: ERROR %s test failed\n", ts.name); |
908 | hwbreaks_ok = 0; | 910 | hwbreaks_ok = 0; |
909 | } | 911 | } |
910 | 912 | ||
911 | static void run_nmi_sleep_test(int nmi_sleep) | 913 | static void run_nmi_sleep_test(int nmi_sleep) |
912 | { | 914 | { |
913 | unsigned long flags; | 915 | unsigned long flags; |
914 | 916 | ||
915 | init_simple_test(); | 917 | init_simple_test(); |
916 | ts.tst = nmi_sleep_test; | 918 | ts.tst = nmi_sleep_test; |
917 | ts.name = "nmi_sleep_test"; | 919 | ts.name = "nmi_sleep_test"; |
918 | /* Activate test with initial breakpoint */ | 920 | /* Activate test with initial breakpoint */ |
919 | kgdb_breakpoint(); | 921 | kgdb_breakpoint(); |
920 | local_irq_save(flags); | 922 | local_irq_save(flags); |
921 | mdelay(nmi_sleep*1000); | 923 | mdelay(nmi_sleep*1000); |
922 | touch_nmi_watchdog(); | 924 | touch_nmi_watchdog(); |
923 | local_irq_restore(flags); | 925 | local_irq_restore(flags); |
924 | if (test_complete != 2) | 926 | if (test_complete != 2) |
925 | eprintk("kgdbts: ERROR nmi_test did not hit nmi\n"); | 927 | eprintk("kgdbts: ERROR nmi_test did not hit nmi\n"); |
926 | kgdb_breakpoint(); | 928 | kgdb_breakpoint(); |
927 | if (test_complete == 1) | 929 | if (test_complete == 1) |
928 | return; | 930 | return; |
929 | 931 | ||
930 | eprintk("kgdbts: ERROR %s test failed\n", ts.name); | 932 | eprintk("kgdbts: ERROR %s test failed\n", ts.name); |
931 | } | 933 | } |
932 | 934 | ||
933 | static void run_bad_read_test(void) | 935 | static void run_bad_read_test(void) |
934 | { | 936 | { |
935 | init_simple_test(); | 937 | init_simple_test(); |
936 | ts.tst = bad_read_test; | 938 | ts.tst = bad_read_test; |
937 | ts.name = "bad_read_test"; | 939 | ts.name = "bad_read_test"; |
938 | /* Activate test with initial breakpoint */ | 940 | /* Activate test with initial breakpoint */ |
939 | kgdb_breakpoint(); | 941 | kgdb_breakpoint(); |
940 | } | 942 | } |
941 | 943 | ||
942 | static void run_do_fork_test(void) | 944 | static void run_do_fork_test(void) |
943 | { | 945 | { |
944 | init_simple_test(); | 946 | init_simple_test(); |
945 | ts.tst = do_fork_test; | 947 | ts.tst = do_fork_test; |
946 | ts.name = "do_fork_test"; | 948 | ts.name = "do_fork_test"; |
947 | /* Activate test with initial breakpoint */ | 949 | /* Activate test with initial breakpoint */ |
948 | kgdb_breakpoint(); | 950 | kgdb_breakpoint(); |
949 | } | 951 | } |
950 | 952 | ||
951 | static void run_sys_open_test(void) | 953 | static void run_sys_open_test(void) |
952 | { | 954 | { |
953 | init_simple_test(); | 955 | init_simple_test(); |
954 | ts.tst = sys_open_test; | 956 | ts.tst = sys_open_test; |
955 | ts.name = "sys_open_test"; | 957 | ts.name = "sys_open_test"; |
956 | /* Activate test with initial breakpoint */ | 958 | /* Activate test with initial breakpoint */ |
957 | kgdb_breakpoint(); | 959 | kgdb_breakpoint(); |
958 | } | 960 | } |
959 | 961 | ||
960 | static void run_singlestep_break_test(void) | 962 | static void run_singlestep_break_test(void) |
961 | { | 963 | { |
962 | init_simple_test(); | 964 | init_simple_test(); |
963 | ts.tst = singlestep_break_test; | 965 | ts.tst = singlestep_break_test; |
964 | ts.name = "singlestep_breakpoint_test"; | 966 | ts.name = "singlestep_breakpoint_test"; |
965 | /* Activate test with initial breakpoint */ | 967 | /* Activate test with initial breakpoint */ |
966 | kgdb_breakpoint(); | 968 | kgdb_breakpoint(); |
967 | kgdbts_break_test(); | 969 | kgdbts_break_test(); |
968 | kgdbts_break_test(); | 970 | kgdbts_break_test(); |
969 | } | 971 | } |
970 | 972 | ||
971 | static void kgdbts_run_tests(void) | 973 | static void kgdbts_run_tests(void) |
972 | { | 974 | { |
973 | char *ptr; | 975 | char *ptr; |
974 | int fork_test = 0; | 976 | int fork_test = 0; |
975 | int do_sys_open_test = 0; | 977 | int do_sys_open_test = 0; |
976 | int sstep_test = 1000; | 978 | int sstep_test = 1000; |
977 | int nmi_sleep = 0; | 979 | int nmi_sleep = 0; |
978 | int i; | 980 | int i; |
979 | 981 | ||
980 | ptr = strchr(config, 'F'); | 982 | ptr = strchr(config, 'F'); |
981 | if (ptr) | 983 | if (ptr) |
982 | fork_test = simple_strtol(ptr + 1, NULL, 10); | 984 | fork_test = simple_strtol(ptr + 1, NULL, 10); |
983 | ptr = strchr(config, 'S'); | 985 | ptr = strchr(config, 'S'); |
984 | if (ptr) | 986 | if (ptr) |
985 | do_sys_open_test = simple_strtol(ptr + 1, NULL, 10); | 987 | do_sys_open_test = simple_strtol(ptr + 1, NULL, 10); |
986 | ptr = strchr(config, 'N'); | 988 | ptr = strchr(config, 'N'); |
987 | if (ptr) | 989 | if (ptr) |
988 | nmi_sleep = simple_strtol(ptr+1, NULL, 10); | 990 | nmi_sleep = simple_strtol(ptr+1, NULL, 10); |
989 | ptr = strchr(config, 'I'); | 991 | ptr = strchr(config, 'I'); |
990 | if (ptr) | 992 | if (ptr) |
991 | sstep_test = simple_strtol(ptr+1, NULL, 10); | 993 | sstep_test = simple_strtol(ptr+1, NULL, 10); |
992 | 994 | ||
993 | /* All HW break point tests */ | 995 | /* All HW break point tests */ |
994 | if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) { | 996 | if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) { |
995 | hwbreaks_ok = 1; | 997 | hwbreaks_ok = 1; |
996 | v1printk("kgdbts:RUN hw breakpoint test\n"); | 998 | v1printk("kgdbts:RUN hw breakpoint test\n"); |
997 | run_breakpoint_test(1); | 999 | run_breakpoint_test(1); |
998 | v1printk("kgdbts:RUN hw write breakpoint test\n"); | 1000 | v1printk("kgdbts:RUN hw write breakpoint test\n"); |
999 | run_hw_break_test(1); | 1001 | run_hw_break_test(1); |
1000 | v1printk("kgdbts:RUN access write breakpoint test\n"); | 1002 | v1printk("kgdbts:RUN access write breakpoint test\n"); |
1001 | run_hw_break_test(0); | 1003 | run_hw_break_test(0); |
1002 | } | 1004 | } |
1003 | 1005 | ||
1004 | /* required internal KGDB tests */ | 1006 | /* required internal KGDB tests */ |
1005 | v1printk("kgdbts:RUN plant and detach test\n"); | 1007 | v1printk("kgdbts:RUN plant and detach test\n"); |
1006 | run_plant_and_detach_test(0); | 1008 | run_plant_and_detach_test(0); |
1007 | v1printk("kgdbts:RUN sw breakpoint test\n"); | 1009 | v1printk("kgdbts:RUN sw breakpoint test\n"); |
1008 | run_breakpoint_test(0); | 1010 | run_breakpoint_test(0); |
1009 | v1printk("kgdbts:RUN bad memory access test\n"); | 1011 | v1printk("kgdbts:RUN bad memory access test\n"); |
1010 | run_bad_read_test(); | 1012 | run_bad_read_test(); |
1011 | v1printk("kgdbts:RUN singlestep test %i iterations\n", sstep_test); | 1013 | v1printk("kgdbts:RUN singlestep test %i iterations\n", sstep_test); |
1012 | for (i = 0; i < sstep_test; i++) { | 1014 | for (i = 0; i < sstep_test; i++) { |
1013 | run_singlestep_break_test(); | 1015 | run_singlestep_break_test(); |
1014 | if (i % 100 == 0) | 1016 | if (i % 100 == 0) |
1015 | v1printk("kgdbts:RUN singlestep [%i/%i]\n", | 1017 | v1printk("kgdbts:RUN singlestep [%i/%i]\n", |
1016 | i, sstep_test); | 1018 | i, sstep_test); |
1017 | } | 1019 | } |
1018 | 1020 | ||
1019 | /* ===Optional tests=== */ | 1021 | /* ===Optional tests=== */ |
1020 | 1022 | ||
1021 | if (nmi_sleep) { | 1023 | if (nmi_sleep) { |
1022 | v1printk("kgdbts:RUN NMI sleep %i seconds test\n", nmi_sleep); | 1024 | v1printk("kgdbts:RUN NMI sleep %i seconds test\n", nmi_sleep); |
1023 | run_nmi_sleep_test(nmi_sleep); | 1025 | run_nmi_sleep_test(nmi_sleep); |
1024 | } | 1026 | } |
1025 | 1027 | ||
1026 | /* If the do_fork test is run it will be the last test that is | 1028 | /* If the do_fork test is run it will be the last test that is |
1027 | * executed because a kernel thread will be spawned at the very | 1029 | * executed because a kernel thread will be spawned at the very |
1028 | * end to unregister the debug hooks. | 1030 | * end to unregister the debug hooks. |
1029 | */ | 1031 | */ |
1030 | if (fork_test) { | 1032 | if (fork_test) { |
1031 | repeat_test = fork_test; | 1033 | repeat_test = fork_test; |
1032 | printk(KERN_INFO "kgdbts:RUN do_fork for %i breakpoints\n", | 1034 | printk(KERN_INFO "kgdbts:RUN do_fork for %i breakpoints\n", |
1033 | repeat_test); | 1035 | repeat_test); |
1034 | kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg"); | 1036 | kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg"); |
1035 | run_do_fork_test(); | 1037 | run_do_fork_test(); |
1036 | return; | 1038 | return; |
1037 | } | 1039 | } |
1038 | 1040 | ||
1039 | /* If the sys_open test is run it will be the last test that is | 1041 | /* If the sys_open test is run it will be the last test that is |
1040 | * executed because a kernel thread will be spawned at the very | 1042 | * executed because a kernel thread will be spawned at the very |
1041 | * end to unregister the debug hooks. | 1043 | * end to unregister the debug hooks. |
1042 | */ | 1044 | */ |
1043 | if (do_sys_open_test) { | 1045 | if (do_sys_open_test) { |
1044 | repeat_test = do_sys_open_test; | 1046 | repeat_test = do_sys_open_test; |
1045 | printk(KERN_INFO "kgdbts:RUN sys_open for %i breakpoints\n", | 1047 | printk(KERN_INFO "kgdbts:RUN sys_open for %i breakpoints\n", |
1046 | repeat_test); | 1048 | repeat_test); |
1047 | kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg"); | 1049 | kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg"); |
1048 | run_sys_open_test(); | 1050 | run_sys_open_test(); |
1049 | return; | 1051 | return; |
1050 | } | 1052 | } |
1051 | /* Shutdown and unregister */ | 1053 | /* Shutdown and unregister */ |
1052 | kgdb_unregister_io_module(&kgdbts_io_ops); | 1054 | kgdb_unregister_io_module(&kgdbts_io_ops); |
1053 | configured = 0; | 1055 | configured = 0; |
1054 | } | 1056 | } |
1055 | 1057 | ||
1056 | static int kgdbts_option_setup(char *opt) | 1058 | static int kgdbts_option_setup(char *opt) |
1057 | { | 1059 | { |
1058 | if (strlen(opt) >= MAX_CONFIG_LEN) { | 1060 | if (strlen(opt) >= MAX_CONFIG_LEN) { |
1059 | printk(KERN_ERR "kgdbts: config string too long\n"); | 1061 | printk(KERN_ERR "kgdbts: config string too long\n"); |
1060 | return -ENOSPC; | 1062 | return -ENOSPC; |
1061 | } | 1063 | } |
1062 | strcpy(config, opt); | 1064 | strcpy(config, opt); |
1063 | 1065 | ||
1064 | verbose = 0; | 1066 | verbose = 0; |
1065 | if (strstr(config, "V1")) | 1067 | if (strstr(config, "V1")) |
1066 | verbose = 1; | 1068 | verbose = 1; |
1067 | if (strstr(config, "V2")) | 1069 | if (strstr(config, "V2")) |
1068 | verbose = 2; | 1070 | verbose = 2; |
1069 | 1071 | ||
1070 | return 0; | 1072 | return 0; |
1071 | } | 1073 | } |
1072 | 1074 | ||
1073 | __setup("kgdbts=", kgdbts_option_setup); | 1075 | __setup("kgdbts=", kgdbts_option_setup); |
1074 | 1076 | ||
1075 | static int configure_kgdbts(void) | 1077 | static int configure_kgdbts(void) |
1076 | { | 1078 | { |
1077 | int err = 0; | 1079 | int err = 0; |
1078 | 1080 | ||
1079 | if (!strlen(config) || isspace(config[0])) | 1081 | if (!strlen(config) || isspace(config[0])) |
1080 | goto noconfig; | 1082 | goto noconfig; |
1081 | err = kgdbts_option_setup(config); | 1083 | err = kgdbts_option_setup(config); |
1082 | if (err) | 1084 | if (err) |
1083 | goto noconfig; | 1085 | goto noconfig; |
1084 | 1086 | ||
1085 | final_ack = 0; | 1087 | final_ack = 0; |
1086 | run_plant_and_detach_test(1); | 1088 | run_plant_and_detach_test(1); |
1087 | 1089 | ||
1088 | err = kgdb_register_io_module(&kgdbts_io_ops); | 1090 | err = kgdb_register_io_module(&kgdbts_io_ops); |
1089 | if (err) { | 1091 | if (err) { |
1090 | configured = 0; | 1092 | configured = 0; |
1091 | return err; | 1093 | return err; |
1092 | } | 1094 | } |
1093 | configured = 1; | 1095 | configured = 1; |
1094 | kgdbts_run_tests(); | 1096 | kgdbts_run_tests(); |
1095 | 1097 | ||
1096 | return err; | 1098 | return err; |
1097 | 1099 | ||
1098 | noconfig: | 1100 | noconfig: |
1099 | config[0] = 0; | 1101 | config[0] = 0; |
1100 | configured = 0; | 1102 | configured = 0; |
1101 | 1103 | ||
1102 | return err; | 1104 | return err; |
1103 | } | 1105 | } |
1104 | 1106 | ||
1105 | static int __init init_kgdbts(void) | 1107 | static int __init init_kgdbts(void) |
1106 | { | 1108 | { |
1107 | /* Already configured? */ | 1109 | /* Already configured? */ |
1108 | if (configured == 1) | 1110 | if (configured == 1) |
1109 | return 0; | 1111 | return 0; |
1110 | 1112 | ||
1111 | return configure_kgdbts(); | 1113 | return configure_kgdbts(); |
1112 | } | 1114 | } |
1113 | 1115 | ||
1114 | static int kgdbts_get_char(void) | 1116 | static int kgdbts_get_char(void) |
1115 | { | 1117 | { |
1116 | int val = 0; | 1118 | int val = 0; |
1117 | 1119 | ||
1118 | if (ts.run_test) | 1120 | if (ts.run_test) |
1119 | val = ts.run_test(1, 0); | 1121 | val = ts.run_test(1, 0); |
1120 | 1122 | ||
1121 | return val; | 1123 | return val; |
1122 | } | 1124 | } |
1123 | 1125 | ||
1124 | static void kgdbts_put_char(u8 chr) | 1126 | static void kgdbts_put_char(u8 chr) |
1125 | { | 1127 | { |
1126 | if (ts.run_test) | 1128 | if (ts.run_test) |
1127 | ts.run_test(0, chr); | 1129 | ts.run_test(0, chr); |
1128 | } | 1130 | } |
1129 | 1131 | ||
1130 | static int param_set_kgdbts_var(const char *kmessage, struct kernel_param *kp) | 1132 | static int param_set_kgdbts_var(const char *kmessage, struct kernel_param *kp) |
1131 | { | 1133 | { |
1132 | int len = strlen(kmessage); | 1134 | int len = strlen(kmessage); |
1133 | 1135 | ||
1134 | if (len >= MAX_CONFIG_LEN) { | 1136 | if (len >= MAX_CONFIG_LEN) { |
1135 | printk(KERN_ERR "kgdbts: config string too long\n"); | 1137 | printk(KERN_ERR "kgdbts: config string too long\n"); |
1136 | return -ENOSPC; | 1138 | return -ENOSPC; |
1137 | } | 1139 | } |
1138 | 1140 | ||
1139 | /* Only copy in the string if the init function has not run yet */ | 1141 | /* Only copy in the string if the init function has not run yet */ |
1140 | if (configured < 0) { | 1142 | if (configured < 0) { |
1141 | strcpy(config, kmessage); | 1143 | strcpy(config, kmessage); |
1142 | return 0; | 1144 | return 0; |
1143 | } | 1145 | } |
1144 | 1146 | ||
1145 | if (configured == 1) { | 1147 | if (configured == 1) { |
1146 | printk(KERN_ERR "kgdbts: ERROR: Already configured and running.\n"); | 1148 | printk(KERN_ERR "kgdbts: ERROR: Already configured and running.\n"); |
1147 | return -EBUSY; | 1149 | return -EBUSY; |
1148 | } | 1150 | } |
1149 | 1151 | ||
1150 | strcpy(config, kmessage); | 1152 | strcpy(config, kmessage); |
1151 | /* Chop out \n char as a result of echo */ | 1153 | /* Chop out \n char as a result of echo */ |
1152 | if (config[len - 1] == '\n') | 1154 | if (config[len - 1] == '\n') |
1153 | config[len - 1] = '\0'; | 1155 | config[len - 1] = '\0'; |
1154 | 1156 | ||
1155 | /* Go and configure with the new params. */ | 1157 | /* Go and configure with the new params. */ |
1156 | return configure_kgdbts(); | 1158 | return configure_kgdbts(); |
1157 | } | 1159 | } |
1158 | 1160 | ||
1159 | static void kgdbts_pre_exp_handler(void) | 1161 | static void kgdbts_pre_exp_handler(void) |
1160 | { | 1162 | { |
1161 | /* Increment the module count when the debugger is active */ | 1163 | /* Increment the module count when the debugger is active */ |
1162 | if (!kgdb_connected) | 1164 | if (!kgdb_connected) |
1163 | try_module_get(THIS_MODULE); | 1165 | try_module_get(THIS_MODULE); |
1164 | } | 1166 | } |
1165 | 1167 | ||
1166 | static void kgdbts_post_exp_handler(void) | 1168 | static void kgdbts_post_exp_handler(void) |
1167 | { | 1169 | { |
1168 | /* decrement the module count when the debugger detaches */ | 1170 | /* decrement the module count when the debugger detaches */ |
1169 | if (!kgdb_connected) | 1171 | if (!kgdb_connected) |
1170 | module_put(THIS_MODULE); | 1172 | module_put(THIS_MODULE); |
1171 | } | 1173 | } |
1172 | 1174 | ||
1173 | static struct kgdb_io kgdbts_io_ops = { | 1175 | static struct kgdb_io kgdbts_io_ops = { |
1174 | .name = "kgdbts", | 1176 | .name = "kgdbts", |
1175 | .read_char = kgdbts_get_char, | 1177 | .read_char = kgdbts_get_char, |
1176 | .write_char = kgdbts_put_char, | 1178 | .write_char = kgdbts_put_char, |
1177 | .pre_exception = kgdbts_pre_exp_handler, | 1179 | .pre_exception = kgdbts_pre_exp_handler, |
1178 | .post_exception = kgdbts_post_exp_handler, | 1180 | .post_exception = kgdbts_post_exp_handler, |
1179 | }; | 1181 | }; |
1180 | 1182 | ||
1181 | module_init(init_kgdbts); | 1183 | module_init(init_kgdbts); |
1182 | module_param_call(kgdbts, param_set_kgdbts_var, param_get_string, &kps, 0644); | 1184 | module_param_call(kgdbts, param_set_kgdbts_var, param_get_string, &kps, 0644); |
1183 | MODULE_PARM_DESC(kgdbts, "<A|V1|V2>[F#|S#][N#]"); | 1185 | MODULE_PARM_DESC(kgdbts, "<A|V1|V2>[F#|S#][N#]"); |
1184 | MODULE_DESCRIPTION("KGDB Test Suite"); | 1186 | MODULE_DESCRIPTION("KGDB Test Suite"); |
1185 | MODULE_LICENSE("GPL"); | 1187 | MODULE_LICENSE("GPL"); |
1186 | MODULE_AUTHOR("Wind River Systems, Inc."); | 1188 | MODULE_AUTHOR("Wind River Systems, Inc."); |
1187 | 1189 | ||
1188 | 1190 |