Remove blkdev warning triggered by using md
[linux-2.6/mini2440.git] / kernel / kgdb.c
blob14787de568b3c916320d06e5f73184e65966dfcc
1 /*
2 * KGDB stub.
4 * Maintainer: Jason Wessel <jason.wessel@windriver.com>
6 * Copyright (C) 2000-2001 VERITAS Software Corporation.
7 * Copyright (C) 2002-2004 Timesys Corporation
8 * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com>
9 * Copyright (C) 2004 Pavel Machek <pavel@suse.cz>
10 * Copyright (C) 2004-2006 Tom Rini <trini@kernel.crashing.org>
11 * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd.
12 * Copyright (C) 2005-2008 Wind River Systems, Inc.
13 * Copyright (C) 2007 MontaVista Software, Inc.
14 * Copyright (C) 2008 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
16 * Contributors at various stages not listed above:
17 * Jason Wessel ( jason.wessel@windriver.com )
18 * George Anzinger <george@mvista.com>
19 * Anurekh Saxena (anurekh.saxena@timesys.com)
20 * Lake Stevens Instrument Division (Glenn Engel)
21 * Jim Kingdon, Cygnus Support.
23 * Original KGDB stub: David Grothe <dave@gcom.com>,
24 * Tigran Aivazian <tigran@sco.com>
26 * This file is licensed under the terms of the GNU General Public License
27 * version 2. This program is licensed "as is" without any warranty of any
28 * kind, whether express or implied.
30 #include <linux/pid_namespace.h>
31 #include <linux/clocksource.h>
32 #include <linux/interrupt.h>
33 #include <linux/spinlock.h>
34 #include <linux/console.h>
35 #include <linux/threads.h>
36 #include <linux/uaccess.h>
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/ptrace.h>
40 #include <linux/reboot.h>
41 #include <linux/string.h>
42 #include <linux/delay.h>
43 #include <linux/sched.h>
44 #include <linux/sysrq.h>
45 #include <linux/init.h>
46 #include <linux/kgdb.h>
47 #include <linux/pid.h>
48 #include <linux/smp.h>
49 #include <linux/mm.h>
51 #include <asm/cacheflush.h>
52 #include <asm/byteorder.h>
53 #include <asm/atomic.h>
54 #include <asm/system.h>
56 static int kgdb_break_asap;
58 struct kgdb_state {
59 int ex_vector;
60 int signo;
61 int err_code;
62 int cpu;
63 int pass_exception;
64 unsigned long threadid;
65 long kgdb_usethreadid;
66 struct pt_regs *linux_regs;
69 static struct debuggerinfo_struct {
70 void *debuggerinfo;
71 struct task_struct *task;
72 } kgdb_info[NR_CPUS];
74 /**
75 * kgdb_connected - Is a host GDB connected to us?
77 int kgdb_connected;
78 EXPORT_SYMBOL_GPL(kgdb_connected);
80 /* All the KGDB handlers are installed */
81 static int kgdb_io_module_registered;
83 /* Guard for recursive entry */
84 static int exception_level;
86 static struct kgdb_io *kgdb_io_ops;
87 static DEFINE_SPINLOCK(kgdb_registration_lock);
89 /* kgdb console driver is loaded */
90 static int kgdb_con_registered;
91 /* determine if kgdb console output should be used */
92 static int kgdb_use_con;
94 static int __init opt_kgdb_con(char *str)
96 kgdb_use_con = 1;
97 return 0;
100 early_param("kgdbcon", opt_kgdb_con);
102 module_param(kgdb_use_con, int, 0644);
105 * Holds information about breakpoints in a kernel. These breakpoints are
106 * added and removed by gdb.
108 static struct kgdb_bkpt kgdb_break[KGDB_MAX_BREAKPOINTS] = {
109 [0 ... KGDB_MAX_BREAKPOINTS-1] = { .state = BP_UNDEFINED }
113 * The CPU# of the active CPU, or -1 if none:
115 atomic_t kgdb_active = ATOMIC_INIT(-1);
118 * We use NR_CPUs not PERCPU, in case kgdb is used to debug early
119 * bootup code (which might not have percpu set up yet):
121 static atomic_t passive_cpu_wait[NR_CPUS];
122 static atomic_t cpu_in_kgdb[NR_CPUS];
123 atomic_t kgdb_setting_breakpoint;
125 struct task_struct *kgdb_usethread;
126 struct task_struct *kgdb_contthread;
128 int kgdb_single_step;
130 /* Our I/O buffers. */
131 static char remcom_in_buffer[BUFMAX];
132 static char remcom_out_buffer[BUFMAX];
134 /* Storage for the registers, in GDB format. */
135 static unsigned long gdb_regs[(NUMREGBYTES +
136 sizeof(unsigned long) - 1) /
137 sizeof(unsigned long)];
139 /* to keep track of the CPU which is doing the single stepping*/
140 atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
143 * If you are debugging a problem where roundup (the collection of
144 * all other CPUs) is a problem [this should be extremely rare],
145 * then use the nokgdbroundup option to avoid roundup. In that case
146 * the other CPUs might interfere with your debugging context, so
147 * use this with care:
149 static int kgdb_do_roundup = 1;
151 static int __init opt_nokgdbroundup(char *str)
153 kgdb_do_roundup = 0;
155 return 0;
158 early_param("nokgdbroundup", opt_nokgdbroundup);
161 * Finally, some KGDB code :-)
165 * Weak aliases for breakpoint management,
166 * can be overriden by architectures when needed:
168 int __weak kgdb_validate_break_address(unsigned long addr)
170 char tmp_variable[BREAK_INSTR_SIZE];
172 return probe_kernel_read(tmp_variable, (char *)addr, BREAK_INSTR_SIZE);
175 int __weak kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr)
177 int err;
179 err = probe_kernel_read(saved_instr, (char *)addr, BREAK_INSTR_SIZE);
180 if (err)
181 return err;
183 return probe_kernel_write((char *)addr, arch_kgdb_ops.gdb_bpt_instr,
184 BREAK_INSTR_SIZE);
187 int __weak kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle)
189 return probe_kernel_write((char *)addr,
190 (char *)bundle, BREAK_INSTR_SIZE);
193 unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs)
195 return instruction_pointer(regs);
198 int __weak kgdb_arch_init(void)
200 return 0;
203 int __weak kgdb_skipexception(int exception, struct pt_regs *regs)
205 return 0;
208 void __weak
209 kgdb_post_primary_code(struct pt_regs *regs, int e_vector, int err_code)
211 return;
215 * kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
216 * @regs: Current &struct pt_regs.
218 * This function will be called if the particular architecture must
219 * disable hardware debugging while it is processing gdb packets or
220 * handling exception.
222 void __weak kgdb_disable_hw_debug(struct pt_regs *regs)
227 * GDB remote protocol parser:
230 static const char hexchars[] = "0123456789abcdef";
232 static int hex(char ch)
234 if ((ch >= 'a') && (ch <= 'f'))
235 return ch - 'a' + 10;
236 if ((ch >= '0') && (ch <= '9'))
237 return ch - '0';
238 if ((ch >= 'A') && (ch <= 'F'))
239 return ch - 'A' + 10;
240 return -1;
243 /* scan for the sequence $<data>#<checksum> */
244 static void get_packet(char *buffer)
246 unsigned char checksum;
247 unsigned char xmitcsum;
248 int count;
249 char ch;
251 do {
253 * Spin and wait around for the start character, ignore all
254 * other characters:
256 while ((ch = (kgdb_io_ops->read_char())) != '$')
257 /* nothing */;
259 kgdb_connected = 1;
260 checksum = 0;
261 xmitcsum = -1;
263 count = 0;
266 * now, read until a # or end of buffer is found:
268 while (count < (BUFMAX - 1)) {
269 ch = kgdb_io_ops->read_char();
270 if (ch == '#')
271 break;
272 checksum = checksum + ch;
273 buffer[count] = ch;
274 count = count + 1;
276 buffer[count] = 0;
278 if (ch == '#') {
279 xmitcsum = hex(kgdb_io_ops->read_char()) << 4;
280 xmitcsum += hex(kgdb_io_ops->read_char());
282 if (checksum != xmitcsum)
283 /* failed checksum */
284 kgdb_io_ops->write_char('-');
285 else
286 /* successful transfer */
287 kgdb_io_ops->write_char('+');
288 if (kgdb_io_ops->flush)
289 kgdb_io_ops->flush();
291 } while (checksum != xmitcsum);
295 * Send the packet in buffer.
296 * Check for gdb connection if asked for.
298 static void put_packet(char *buffer)
300 unsigned char checksum;
301 int count;
302 char ch;
305 * $<packet info>#<checksum>.
307 while (1) {
308 kgdb_io_ops->write_char('$');
309 checksum = 0;
310 count = 0;
312 while ((ch = buffer[count])) {
313 kgdb_io_ops->write_char(ch);
314 checksum += ch;
315 count++;
318 kgdb_io_ops->write_char('#');
319 kgdb_io_ops->write_char(hexchars[checksum >> 4]);
320 kgdb_io_ops->write_char(hexchars[checksum & 0xf]);
321 if (kgdb_io_ops->flush)
322 kgdb_io_ops->flush();
324 /* Now see what we get in reply. */
325 ch = kgdb_io_ops->read_char();
327 if (ch == 3)
328 ch = kgdb_io_ops->read_char();
330 /* If we get an ACK, we are done. */
331 if (ch == '+')
332 return;
335 * If we get the start of another packet, this means
336 * that GDB is attempting to reconnect. We will NAK
337 * the packet being sent, and stop trying to send this
338 * packet.
340 if (ch == '$') {
341 kgdb_io_ops->write_char('-');
342 if (kgdb_io_ops->flush)
343 kgdb_io_ops->flush();
344 return;
350 * Convert the memory pointed to by mem into hex, placing result in buf.
351 * Return a pointer to the last char put in buf (null). May return an error.
353 int kgdb_mem2hex(char *mem, char *buf, int count)
355 char *tmp;
356 int err;
359 * We use the upper half of buf as an intermediate buffer for the
360 * raw memory copy. Hex conversion will work against this one.
362 tmp = buf + count;
364 err = probe_kernel_read(tmp, mem, count);
365 if (!err) {
366 while (count > 0) {
367 buf = pack_hex_byte(buf, *tmp);
368 tmp++;
369 count--;
372 *buf = 0;
375 return err;
379 * Copy the binary array pointed to by buf into mem. Fix $, #, and
380 * 0x7d escaped with 0x7d. Return a pointer to the character after
381 * the last byte written.
383 static int kgdb_ebin2mem(char *buf, char *mem, int count)
385 int err = 0;
386 char c;
388 while (count-- > 0) {
389 c = *buf++;
390 if (c == 0x7d)
391 c = *buf++ ^ 0x20;
393 err = probe_kernel_write(mem, &c, 1);
394 if (err)
395 break;
397 mem++;
400 return err;
404 * Convert the hex array pointed to by buf into binary to be placed in mem.
405 * Return a pointer to the character AFTER the last byte written.
406 * May return an error.
408 int kgdb_hex2mem(char *buf, char *mem, int count)
410 char *tmp_raw;
411 char *tmp_hex;
414 * We use the upper half of buf as an intermediate buffer for the
415 * raw memory that is converted from hex.
417 tmp_raw = buf + count * 2;
419 tmp_hex = tmp_raw - 1;
420 while (tmp_hex >= buf) {
421 tmp_raw--;
422 *tmp_raw = hex(*tmp_hex--);
423 *tmp_raw |= hex(*tmp_hex--) << 4;
426 return probe_kernel_write(mem, tmp_raw, count);
430 * While we find nice hex chars, build a long_val.
431 * Return number of chars processed.
433 int kgdb_hex2long(char **ptr, unsigned long *long_val)
435 int hex_val;
436 int num = 0;
438 *long_val = 0;
440 while (**ptr) {
441 hex_val = hex(**ptr);
442 if (hex_val < 0)
443 break;
445 *long_val = (*long_val << 4) | hex_val;
446 num++;
447 (*ptr)++;
450 return num;
453 /* Write memory due to an 'M' or 'X' packet. */
454 static int write_mem_msg(int binary)
456 char *ptr = &remcom_in_buffer[1];
457 unsigned long addr;
458 unsigned long length;
459 int err;
461 if (kgdb_hex2long(&ptr, &addr) > 0 && *(ptr++) == ',' &&
462 kgdb_hex2long(&ptr, &length) > 0 && *(ptr++) == ':') {
463 if (binary)
464 err = kgdb_ebin2mem(ptr, (char *)addr, length);
465 else
466 err = kgdb_hex2mem(ptr, (char *)addr, length);
467 if (err)
468 return err;
469 if (CACHE_FLUSH_IS_SAFE)
470 flush_icache_range(addr, addr + length + 1);
471 return 0;
474 return -EINVAL;
477 static void error_packet(char *pkt, int error)
479 error = -error;
480 pkt[0] = 'E';
481 pkt[1] = hexchars[(error / 10)];
482 pkt[2] = hexchars[(error % 10)];
483 pkt[3] = '\0';
487 * Thread ID accessors. We represent a flat TID space to GDB, where
488 * the per CPU idle threads (which under Linux all have PID 0) are
489 * remapped to negative TIDs.
492 #define BUF_THREAD_ID_SIZE 16
494 static char *pack_threadid(char *pkt, unsigned char *id)
496 char *limit;
498 limit = pkt + BUF_THREAD_ID_SIZE;
499 while (pkt < limit)
500 pkt = pack_hex_byte(pkt, *id++);
502 return pkt;
505 static void int_to_threadref(unsigned char *id, int value)
507 unsigned char *scan;
508 int i = 4;
510 scan = (unsigned char *)id;
511 while (i--)
512 *scan++ = 0;
513 *scan++ = (value >> 24) & 0xff;
514 *scan++ = (value >> 16) & 0xff;
515 *scan++ = (value >> 8) & 0xff;
516 *scan++ = (value & 0xff);
519 static struct task_struct *getthread(struct pt_regs *regs, int tid)
522 * Non-positive TIDs are remapped idle tasks:
524 if (tid <= 0)
525 return idle_task(-tid);
528 * find_task_by_pid_ns() does not take the tasklist lock anymore
529 * but is nicely RCU locked - hence is a pretty resilient
530 * thing to use:
532 return find_task_by_pid_ns(tid, &init_pid_ns);
536 * CPU debug state control:
539 #ifdef CONFIG_SMP
540 static void kgdb_wait(struct pt_regs *regs)
542 unsigned long flags;
543 int cpu;
545 local_irq_save(flags);
546 cpu = raw_smp_processor_id();
547 kgdb_info[cpu].debuggerinfo = regs;
548 kgdb_info[cpu].task = current;
550 * Make sure the above info reaches the primary CPU before
551 * our cpu_in_kgdb[] flag setting does:
553 smp_wmb();
554 atomic_set(&cpu_in_kgdb[cpu], 1);
556 /* Wait till primary CPU is done with debugging */
557 while (atomic_read(&passive_cpu_wait[cpu]))
558 cpu_relax();
560 kgdb_info[cpu].debuggerinfo = NULL;
561 kgdb_info[cpu].task = NULL;
563 /* fix up hardware debug registers on local cpu */
564 if (arch_kgdb_ops.correct_hw_break)
565 arch_kgdb_ops.correct_hw_break();
567 /* Signal the primary CPU that we are done: */
568 atomic_set(&cpu_in_kgdb[cpu], 0);
569 clocksource_touch_watchdog();
570 local_irq_restore(flags);
572 #endif
575 * Some architectures need cache flushes when we set/clear a
576 * breakpoint:
578 static void kgdb_flush_swbreak_addr(unsigned long addr)
580 if (!CACHE_FLUSH_IS_SAFE)
581 return;
583 if (current->mm && current->mm->mmap_cache) {
584 flush_cache_range(current->mm->mmap_cache,
585 addr, addr + BREAK_INSTR_SIZE);
587 /* Force flush instruction cache if it was outside the mm */
588 flush_icache_range(addr, addr + BREAK_INSTR_SIZE);
592 * SW breakpoint management:
594 static int kgdb_activate_sw_breakpoints(void)
596 unsigned long addr;
597 int error = 0;
598 int i;
600 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
601 if (kgdb_break[i].state != BP_SET)
602 continue;
604 addr = kgdb_break[i].bpt_addr;
605 error = kgdb_arch_set_breakpoint(addr,
606 kgdb_break[i].saved_instr);
607 if (error)
608 return error;
610 kgdb_flush_swbreak_addr(addr);
611 kgdb_break[i].state = BP_ACTIVE;
613 return 0;
616 static int kgdb_set_sw_break(unsigned long addr)
618 int err = kgdb_validate_break_address(addr);
619 int breakno = -1;
620 int i;
622 if (err)
623 return err;
625 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
626 if ((kgdb_break[i].state == BP_SET) &&
627 (kgdb_break[i].bpt_addr == addr))
628 return -EEXIST;
630 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
631 if (kgdb_break[i].state == BP_REMOVED &&
632 kgdb_break[i].bpt_addr == addr) {
633 breakno = i;
634 break;
638 if (breakno == -1) {
639 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
640 if (kgdb_break[i].state == BP_UNDEFINED) {
641 breakno = i;
642 break;
647 if (breakno == -1)
648 return -E2BIG;
650 kgdb_break[breakno].state = BP_SET;
651 kgdb_break[breakno].type = BP_BREAKPOINT;
652 kgdb_break[breakno].bpt_addr = addr;
654 return 0;
657 static int kgdb_deactivate_sw_breakpoints(void)
659 unsigned long addr;
660 int error = 0;
661 int i;
663 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
664 if (kgdb_break[i].state != BP_ACTIVE)
665 continue;
666 addr = kgdb_break[i].bpt_addr;
667 error = kgdb_arch_remove_breakpoint(addr,
668 kgdb_break[i].saved_instr);
669 if (error)
670 return error;
672 kgdb_flush_swbreak_addr(addr);
673 kgdb_break[i].state = BP_SET;
675 return 0;
678 static int kgdb_remove_sw_break(unsigned long addr)
680 int i;
682 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
683 if ((kgdb_break[i].state == BP_SET) &&
684 (kgdb_break[i].bpt_addr == addr)) {
685 kgdb_break[i].state = BP_REMOVED;
686 return 0;
689 return -ENOENT;
692 int kgdb_isremovedbreak(unsigned long addr)
694 int i;
696 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
697 if ((kgdb_break[i].state == BP_REMOVED) &&
698 (kgdb_break[i].bpt_addr == addr))
699 return 1;
701 return 0;
704 static int remove_all_break(void)
706 unsigned long addr;
707 int error;
708 int i;
710 /* Clear memory breakpoints. */
711 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
712 if (kgdb_break[i].state != BP_ACTIVE)
713 goto setundefined;
714 addr = kgdb_break[i].bpt_addr;
715 error = kgdb_arch_remove_breakpoint(addr,
716 kgdb_break[i].saved_instr);
717 if (error)
718 printk(KERN_ERR "KGDB: breakpoint remove failed: %lx\n",
719 addr);
720 setundefined:
721 kgdb_break[i].state = BP_UNDEFINED;
724 /* Clear hardware breakpoints. */
725 if (arch_kgdb_ops.remove_all_hw_break)
726 arch_kgdb_ops.remove_all_hw_break();
728 return 0;
732 * Remap normal tasks to their real PID, idle tasks to -1 ... -NR_CPUs:
734 static inline int shadow_pid(int realpid)
736 if (realpid)
737 return realpid;
739 return -1-raw_smp_processor_id();
742 static char gdbmsgbuf[BUFMAX + 1];
744 static void kgdb_msg_write(const char *s, int len)
746 char *bufptr;
747 int wcount;
748 int i;
750 /* 'O'utput */
751 gdbmsgbuf[0] = 'O';
753 /* Fill and send buffers... */
754 while (len > 0) {
755 bufptr = gdbmsgbuf + 1;
757 /* Calculate how many this time */
758 if ((len << 1) > (BUFMAX - 2))
759 wcount = (BUFMAX - 2) >> 1;
760 else
761 wcount = len;
763 /* Pack in hex chars */
764 for (i = 0; i < wcount; i++)
765 bufptr = pack_hex_byte(bufptr, s[i]);
766 *bufptr = '\0';
768 /* Move up */
769 s += wcount;
770 len -= wcount;
772 /* Write packet */
773 put_packet(gdbmsgbuf);
778 * Return true if there is a valid kgdb I/O module. Also if no
779 * debugger is attached a message can be printed to the console about
780 * waiting for the debugger to attach.
782 * The print_wait argument is only to be true when called from inside
783 * the core kgdb_handle_exception, because it will wait for the
784 * debugger to attach.
786 static int kgdb_io_ready(int print_wait)
788 if (!kgdb_io_ops)
789 return 0;
790 if (kgdb_connected)
791 return 1;
792 if (atomic_read(&kgdb_setting_breakpoint))
793 return 1;
794 if (print_wait)
795 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
796 return 1;
800 * All the functions that start with gdb_cmd are the various
801 * operations to implement the handlers for the gdbserial protocol
802 * where KGDB is communicating with an external debugger
805 /* Handle the '?' status packets */
806 static void gdb_cmd_status(struct kgdb_state *ks)
809 * We know that this packet is only sent
810 * during initial connect. So to be safe,
811 * we clear out our breakpoints now in case
812 * GDB is reconnecting.
814 remove_all_break();
816 remcom_out_buffer[0] = 'S';
817 pack_hex_byte(&remcom_out_buffer[1], ks->signo);
820 /* Handle the 'g' get registers request */
821 static void gdb_cmd_getregs(struct kgdb_state *ks)
823 struct task_struct *thread;
824 void *local_debuggerinfo;
825 int i;
827 thread = kgdb_usethread;
828 if (!thread) {
829 thread = kgdb_info[ks->cpu].task;
830 local_debuggerinfo = kgdb_info[ks->cpu].debuggerinfo;
831 } else {
832 local_debuggerinfo = NULL;
833 for (i = 0; i < NR_CPUS; i++) {
835 * Try to find the task on some other
836 * or possibly this node if we do not
837 * find the matching task then we try
838 * to approximate the results.
840 if (thread == kgdb_info[i].task)
841 local_debuggerinfo = kgdb_info[i].debuggerinfo;
846 * All threads that don't have debuggerinfo should be
847 * in __schedule() sleeping, since all other CPUs
848 * are in kgdb_wait, and thus have debuggerinfo.
850 if (local_debuggerinfo) {
851 pt_regs_to_gdb_regs(gdb_regs, local_debuggerinfo);
852 } else {
854 * Pull stuff saved during switch_to; nothing
855 * else is accessible (or even particularly
856 * relevant).
858 * This should be enough for a stack trace.
860 sleeping_thread_to_gdb_regs(gdb_regs, thread);
862 kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer, NUMREGBYTES);
865 /* Handle the 'G' set registers request */
866 static void gdb_cmd_setregs(struct kgdb_state *ks)
868 kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs, NUMREGBYTES);
870 if (kgdb_usethread && kgdb_usethread != current) {
871 error_packet(remcom_out_buffer, -EINVAL);
872 } else {
873 gdb_regs_to_pt_regs(gdb_regs, ks->linux_regs);
874 strcpy(remcom_out_buffer, "OK");
878 /* Handle the 'm' memory read bytes */
879 static void gdb_cmd_memread(struct kgdb_state *ks)
881 char *ptr = &remcom_in_buffer[1];
882 unsigned long length;
883 unsigned long addr;
884 int err;
886 if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' &&
887 kgdb_hex2long(&ptr, &length) > 0) {
888 err = kgdb_mem2hex((char *)addr, remcom_out_buffer, length);
889 if (err)
890 error_packet(remcom_out_buffer, err);
891 } else {
892 error_packet(remcom_out_buffer, -EINVAL);
896 /* Handle the 'M' memory write bytes */
897 static void gdb_cmd_memwrite(struct kgdb_state *ks)
899 int err = write_mem_msg(0);
901 if (err)
902 error_packet(remcom_out_buffer, err);
903 else
904 strcpy(remcom_out_buffer, "OK");
907 /* Handle the 'X' memory binary write bytes */
908 static void gdb_cmd_binwrite(struct kgdb_state *ks)
910 int err = write_mem_msg(1);
912 if (err)
913 error_packet(remcom_out_buffer, err);
914 else
915 strcpy(remcom_out_buffer, "OK");
918 /* Handle the 'D' or 'k', detach or kill packets */
919 static void gdb_cmd_detachkill(struct kgdb_state *ks)
921 int error;
923 /* The detach case */
924 if (remcom_in_buffer[0] == 'D') {
925 error = remove_all_break();
926 if (error < 0) {
927 error_packet(remcom_out_buffer, error);
928 } else {
929 strcpy(remcom_out_buffer, "OK");
930 kgdb_connected = 0;
932 put_packet(remcom_out_buffer);
933 } else {
935 * Assume the kill case, with no exit code checking,
936 * trying to force detach the debugger:
938 remove_all_break();
939 kgdb_connected = 0;
943 /* Handle the 'R' reboot packets */
944 static int gdb_cmd_reboot(struct kgdb_state *ks)
946 /* For now, only honor R0 */
947 if (strcmp(remcom_in_buffer, "R0") == 0) {
948 printk(KERN_CRIT "Executing emergency reboot\n");
949 strcpy(remcom_out_buffer, "OK");
950 put_packet(remcom_out_buffer);
953 * Execution should not return from
954 * machine_emergency_restart()
956 machine_emergency_restart();
957 kgdb_connected = 0;
959 return 1;
961 return 0;
964 /* Handle the 'q' query packets */
965 static void gdb_cmd_query(struct kgdb_state *ks)
967 struct task_struct *thread;
968 unsigned char thref[8];
969 char *ptr;
970 int i;
972 switch (remcom_in_buffer[1]) {
973 case 's':
974 case 'f':
975 if (memcmp(remcom_in_buffer + 2, "ThreadInfo", 10)) {
976 error_packet(remcom_out_buffer, -EINVAL);
977 break;
980 if (remcom_in_buffer[1] == 'f')
981 ks->threadid = 1;
983 remcom_out_buffer[0] = 'm';
984 ptr = remcom_out_buffer + 1;
986 for (i = 0; i < 17; ks->threadid++) {
987 thread = getthread(ks->linux_regs, ks->threadid);
988 if (thread) {
989 int_to_threadref(thref, ks->threadid);
990 pack_threadid(ptr, thref);
991 ptr += BUF_THREAD_ID_SIZE;
992 *(ptr++) = ',';
993 i++;
996 *(--ptr) = '\0';
997 break;
999 case 'C':
1000 /* Current thread id */
1001 strcpy(remcom_out_buffer, "QC");
1002 ks->threadid = shadow_pid(current->pid);
1003 int_to_threadref(thref, ks->threadid);
1004 pack_threadid(remcom_out_buffer + 2, thref);
1005 break;
1006 case 'T':
1007 if (memcmp(remcom_in_buffer + 1, "ThreadExtraInfo,", 16)) {
1008 error_packet(remcom_out_buffer, -EINVAL);
1009 break;
1011 ks->threadid = 0;
1012 ptr = remcom_in_buffer + 17;
1013 kgdb_hex2long(&ptr, &ks->threadid);
1014 if (!getthread(ks->linux_regs, ks->threadid)) {
1015 error_packet(remcom_out_buffer, -EINVAL);
1016 break;
1018 if (ks->threadid > 0) {
1019 kgdb_mem2hex(getthread(ks->linux_regs,
1020 ks->threadid)->comm,
1021 remcom_out_buffer, 16);
1022 } else {
1023 static char tmpstr[23 + BUF_THREAD_ID_SIZE];
1025 sprintf(tmpstr, "Shadow task %d for pid 0",
1026 (int)(-ks->threadid-1));
1027 kgdb_mem2hex(tmpstr, remcom_out_buffer, strlen(tmpstr));
1029 break;
1033 /* Handle the 'H' task query packets */
1034 static void gdb_cmd_task(struct kgdb_state *ks)
1036 struct task_struct *thread;
1037 char *ptr;
1039 switch (remcom_in_buffer[1]) {
1040 case 'g':
1041 ptr = &remcom_in_buffer[2];
1042 kgdb_hex2long(&ptr, &ks->threadid);
1043 thread = getthread(ks->linux_regs, ks->threadid);
1044 if (!thread && ks->threadid > 0) {
1045 error_packet(remcom_out_buffer, -EINVAL);
1046 break;
1048 kgdb_usethread = thread;
1049 ks->kgdb_usethreadid = ks->threadid;
1050 strcpy(remcom_out_buffer, "OK");
1051 break;
1052 case 'c':
1053 ptr = &remcom_in_buffer[2];
1054 kgdb_hex2long(&ptr, &ks->threadid);
1055 if (!ks->threadid) {
1056 kgdb_contthread = NULL;
1057 } else {
1058 thread = getthread(ks->linux_regs, ks->threadid);
1059 if (!thread && ks->threadid > 0) {
1060 error_packet(remcom_out_buffer, -EINVAL);
1061 break;
1063 kgdb_contthread = thread;
1065 strcpy(remcom_out_buffer, "OK");
1066 break;
1070 /* Handle the 'T' thread query packets */
1071 static void gdb_cmd_thread(struct kgdb_state *ks)
1073 char *ptr = &remcom_in_buffer[1];
1074 struct task_struct *thread;
1076 kgdb_hex2long(&ptr, &ks->threadid);
1077 thread = getthread(ks->linux_regs, ks->threadid);
1078 if (thread)
1079 strcpy(remcom_out_buffer, "OK");
1080 else
1081 error_packet(remcom_out_buffer, -EINVAL);
1084 /* Handle the 'z' or 'Z' breakpoint remove or set packets */
1085 static void gdb_cmd_break(struct kgdb_state *ks)
1088 * Since GDB-5.3, it's been drafted that '0' is a software
1089 * breakpoint, '1' is a hardware breakpoint, so let's do that.
1091 char *bpt_type = &remcom_in_buffer[1];
1092 char *ptr = &remcom_in_buffer[2];
1093 unsigned long addr;
1094 unsigned long length;
1095 int error = 0;
1097 if (arch_kgdb_ops.set_hw_breakpoint && *bpt_type >= '1') {
1098 /* Unsupported */
1099 if (*bpt_type > '4')
1100 return;
1101 } else {
1102 if (*bpt_type != '0' && *bpt_type != '1')
1103 /* Unsupported. */
1104 return;
1108 * Test if this is a hardware breakpoint, and
1109 * if we support it:
1111 if (*bpt_type == '1' && !(arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT))
1112 /* Unsupported. */
1113 return;
1115 if (*(ptr++) != ',') {
1116 error_packet(remcom_out_buffer, -EINVAL);
1117 return;
1119 if (!kgdb_hex2long(&ptr, &addr)) {
1120 error_packet(remcom_out_buffer, -EINVAL);
1121 return;
1123 if (*(ptr++) != ',' ||
1124 !kgdb_hex2long(&ptr, &length)) {
1125 error_packet(remcom_out_buffer, -EINVAL);
1126 return;
1129 if (remcom_in_buffer[0] == 'Z' && *bpt_type == '0')
1130 error = kgdb_set_sw_break(addr);
1131 else if (remcom_in_buffer[0] == 'z' && *bpt_type == '0')
1132 error = kgdb_remove_sw_break(addr);
1133 else if (remcom_in_buffer[0] == 'Z')
1134 error = arch_kgdb_ops.set_hw_breakpoint(addr,
1135 (int)length, *bpt_type - '0');
1136 else if (remcom_in_buffer[0] == 'z')
1137 error = arch_kgdb_ops.remove_hw_breakpoint(addr,
1138 (int) length, *bpt_type - '0');
1140 if (error == 0)
1141 strcpy(remcom_out_buffer, "OK");
1142 else
1143 error_packet(remcom_out_buffer, error);
1146 /* Handle the 'C' signal / exception passing packets */
1147 static int gdb_cmd_exception_pass(struct kgdb_state *ks)
1149 /* C09 == pass exception
1150 * C15 == detach kgdb, pass exception
1152 if (remcom_in_buffer[1] == '0' && remcom_in_buffer[2] == '9') {
1154 ks->pass_exception = 1;
1155 remcom_in_buffer[0] = 'c';
1157 } else if (remcom_in_buffer[1] == '1' && remcom_in_buffer[2] == '5') {
1159 ks->pass_exception = 1;
1160 remcom_in_buffer[0] = 'D';
1161 remove_all_break();
1162 kgdb_connected = 0;
1163 return 1;
1165 } else {
1166 error_packet(remcom_out_buffer, -EINVAL);
1167 return 0;
1170 /* Indicate fall through */
1171 return -1;
1175 * This function performs all gdbserial command procesing
1177 static int gdb_serial_stub(struct kgdb_state *ks)
1179 int error = 0;
1180 int tmp;
1182 /* Clear the out buffer. */
1183 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
1185 if (kgdb_connected) {
1186 unsigned char thref[8];
1187 char *ptr;
1189 /* Reply to host that an exception has occurred */
1190 ptr = remcom_out_buffer;
1191 *ptr++ = 'T';
1192 ptr = pack_hex_byte(ptr, ks->signo);
1193 ptr += strlen(strcpy(ptr, "thread:"));
1194 int_to_threadref(thref, shadow_pid(current->pid));
1195 ptr = pack_threadid(ptr, thref);
1196 *ptr++ = ';';
1197 put_packet(remcom_out_buffer);
1200 kgdb_usethread = kgdb_info[ks->cpu].task;
1201 ks->kgdb_usethreadid = shadow_pid(kgdb_info[ks->cpu].task->pid);
1202 ks->pass_exception = 0;
1204 while (1) {
1205 error = 0;
1207 /* Clear the out buffer. */
1208 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
1210 get_packet(remcom_in_buffer);
1212 switch (remcom_in_buffer[0]) {
1213 case '?': /* gdbserial status */
1214 gdb_cmd_status(ks);
1215 break;
1216 case 'g': /* return the value of the CPU registers */
1217 gdb_cmd_getregs(ks);
1218 break;
1219 case 'G': /* set the value of the CPU registers - return OK */
1220 gdb_cmd_setregs(ks);
1221 break;
1222 case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
1223 gdb_cmd_memread(ks);
1224 break;
1225 case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */
1226 gdb_cmd_memwrite(ks);
1227 break;
1228 case 'X': /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */
1229 gdb_cmd_binwrite(ks);
1230 break;
1231 /* kill or detach. KGDB should treat this like a
1232 * continue.
1234 case 'D': /* Debugger detach */
1235 case 'k': /* Debugger detach via kill */
1236 gdb_cmd_detachkill(ks);
1237 goto default_handle;
1238 case 'R': /* Reboot */
1239 if (gdb_cmd_reboot(ks))
1240 goto default_handle;
1241 break;
1242 case 'q': /* query command */
1243 gdb_cmd_query(ks);
1244 break;
1245 case 'H': /* task related */
1246 gdb_cmd_task(ks);
1247 break;
1248 case 'T': /* Query thread status */
1249 gdb_cmd_thread(ks);
1250 break;
1251 case 'z': /* Break point remove */
1252 case 'Z': /* Break point set */
1253 gdb_cmd_break(ks);
1254 break;
1255 case 'C': /* Exception passing */
1256 tmp = gdb_cmd_exception_pass(ks);
1257 if (tmp > 0)
1258 goto default_handle;
1259 if (tmp == 0)
1260 break;
1261 /* Fall through on tmp < 0 */
1262 case 'c': /* Continue packet */
1263 case 's': /* Single step packet */
1264 if (kgdb_contthread && kgdb_contthread != current) {
1265 /* Can't switch threads in kgdb */
1266 error_packet(remcom_out_buffer, -EINVAL);
1267 break;
1269 kgdb_activate_sw_breakpoints();
1270 /* Fall through to default processing */
1271 default:
1272 default_handle:
1273 error = kgdb_arch_handle_exception(ks->ex_vector,
1274 ks->signo,
1275 ks->err_code,
1276 remcom_in_buffer,
1277 remcom_out_buffer,
1278 ks->linux_regs);
1280 * Leave cmd processing on error, detach,
1281 * kill, continue, or single step.
1283 if (error >= 0 || remcom_in_buffer[0] == 'D' ||
1284 remcom_in_buffer[0] == 'k') {
1285 error = 0;
1286 goto kgdb_exit;
1291 /* reply to the request */
1292 put_packet(remcom_out_buffer);
1295 kgdb_exit:
1296 if (ks->pass_exception)
1297 error = 1;
1298 return error;
1301 static int kgdb_reenter_check(struct kgdb_state *ks)
1303 unsigned long addr;
1305 if (atomic_read(&kgdb_active) != raw_smp_processor_id())
1306 return 0;
1308 /* Panic on recursive debugger calls: */
1309 exception_level++;
1310 addr = kgdb_arch_pc(ks->ex_vector, ks->linux_regs);
1311 kgdb_deactivate_sw_breakpoints();
1314 * If the break point removed ok at the place exception
1315 * occurred, try to recover and print a warning to the end
1316 * user because the user planted a breakpoint in a place that
1317 * KGDB needs in order to function.
1319 if (kgdb_remove_sw_break(addr) == 0) {
1320 exception_level = 0;
1321 kgdb_skipexception(ks->ex_vector, ks->linux_regs);
1322 kgdb_activate_sw_breakpoints();
1323 printk(KERN_CRIT "KGDB: re-enter error: breakpoint removed %lx\n",
1324 addr);
1325 WARN_ON_ONCE(1);
1327 return 1;
1329 remove_all_break();
1330 kgdb_skipexception(ks->ex_vector, ks->linux_regs);
1332 if (exception_level > 1) {
1333 dump_stack();
1334 panic("Recursive entry to debugger");
1337 printk(KERN_CRIT "KGDB: re-enter exception: ALL breakpoints killed\n");
1338 dump_stack();
1339 panic("Recursive entry to debugger");
1341 return 1;
1345 * kgdb_handle_exception() - main entry point from a kernel exception
1347 * Locking hierarchy:
1348 * interface locks, if any (begin_session)
1349 * kgdb lock (kgdb_active)
1352 kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs)
1354 struct kgdb_state kgdb_var;
1355 struct kgdb_state *ks = &kgdb_var;
1356 unsigned long flags;
1357 int error = 0;
1358 int i, cpu;
1360 ks->cpu = raw_smp_processor_id();
1361 ks->ex_vector = evector;
1362 ks->signo = signo;
1363 ks->ex_vector = evector;
1364 ks->err_code = ecode;
1365 ks->kgdb_usethreadid = 0;
1366 ks->linux_regs = regs;
1368 if (kgdb_reenter_check(ks))
1369 return 0; /* Ouch, double exception ! */
1371 acquirelock:
1373 * Interrupts will be restored by the 'trap return' code, except when
1374 * single stepping.
1376 local_irq_save(flags);
1378 cpu = raw_smp_processor_id();
1381 * Acquire the kgdb_active lock:
1383 while (atomic_cmpxchg(&kgdb_active, -1, cpu) != -1)
1384 cpu_relax();
1387 * Do not start the debugger connection on this CPU if the last
1388 * instance of the exception handler wanted to come into the
1389 * debugger on a different CPU via a single step
1391 if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
1392 atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
1394 atomic_set(&kgdb_active, -1);
1395 clocksource_touch_watchdog();
1396 local_irq_restore(flags);
1398 goto acquirelock;
1401 if (!kgdb_io_ready(1)) {
1402 error = 1;
1403 goto kgdb_restore; /* No I/O connection, so resume the system */
1407 * Don't enter if we have hit a removed breakpoint.
1409 if (kgdb_skipexception(ks->ex_vector, ks->linux_regs))
1410 goto kgdb_restore;
1412 /* Call the I/O driver's pre_exception routine */
1413 if (kgdb_io_ops->pre_exception)
1414 kgdb_io_ops->pre_exception();
1416 kgdb_info[ks->cpu].debuggerinfo = ks->linux_regs;
1417 kgdb_info[ks->cpu].task = current;
1419 kgdb_disable_hw_debug(ks->linux_regs);
1422 * Get the passive CPU lock which will hold all the non-primary
1423 * CPU in a spin state while the debugger is active
1425 if (!kgdb_single_step || !kgdb_contthread) {
1426 for (i = 0; i < NR_CPUS; i++)
1427 atomic_set(&passive_cpu_wait[i], 1);
1431 * spin_lock code is good enough as a barrier so we don't
1432 * need one here:
1434 atomic_set(&cpu_in_kgdb[ks->cpu], 1);
1436 #ifdef CONFIG_SMP
1437 /* Signal the other CPUs to enter kgdb_wait() */
1438 if ((!kgdb_single_step || !kgdb_contthread) && kgdb_do_roundup)
1439 kgdb_roundup_cpus(flags);
1440 #endif
1443 * Wait for the other CPUs to be notified and be waiting for us:
1445 for_each_online_cpu(i) {
1446 while (!atomic_read(&cpu_in_kgdb[i]))
1447 cpu_relax();
1451 * At this point the primary processor is completely
1452 * in the debugger and all secondary CPUs are quiescent
1454 kgdb_post_primary_code(ks->linux_regs, ks->ex_vector, ks->err_code);
1455 kgdb_deactivate_sw_breakpoints();
1456 kgdb_single_step = 0;
1457 kgdb_contthread = NULL;
1458 exception_level = 0;
1460 /* Talk to debugger with gdbserial protocol */
1461 error = gdb_serial_stub(ks);
1463 /* Call the I/O driver's post_exception routine */
1464 if (kgdb_io_ops->post_exception)
1465 kgdb_io_ops->post_exception();
1467 kgdb_info[ks->cpu].debuggerinfo = NULL;
1468 kgdb_info[ks->cpu].task = NULL;
1469 atomic_set(&cpu_in_kgdb[ks->cpu], 0);
1471 if (!kgdb_single_step || !kgdb_contthread) {
1472 for (i = NR_CPUS-1; i >= 0; i--)
1473 atomic_set(&passive_cpu_wait[i], 0);
1475 * Wait till all the CPUs have quit
1476 * from the debugger.
1478 for_each_online_cpu(i) {
1479 while (atomic_read(&cpu_in_kgdb[i]))
1480 cpu_relax();
1484 kgdb_restore:
1485 /* Free kgdb_active */
1486 atomic_set(&kgdb_active, -1);
1487 clocksource_touch_watchdog();
1488 local_irq_restore(flags);
1490 return error;
1493 int kgdb_nmicallback(int cpu, void *regs)
1495 #ifdef CONFIG_SMP
1496 if (!atomic_read(&cpu_in_kgdb[cpu]) &&
1497 atomic_read(&kgdb_active) != cpu &&
1498 atomic_read(&cpu_in_kgdb[atomic_read(&kgdb_active)])) {
1499 kgdb_wait((struct pt_regs *)regs);
1500 return 0;
1502 #endif
1503 return 1;
1506 void kgdb_console_write(struct console *co, const char *s, unsigned count)
1508 unsigned long flags;
1510 /* If we're debugging, or KGDB has not connected, don't try
1511 * and print. */
1512 if (!kgdb_connected || atomic_read(&kgdb_active) != -1)
1513 return;
1515 local_irq_save(flags);
1516 kgdb_msg_write(s, count);
1517 local_irq_restore(flags);
1520 static struct console kgdbcons = {
1521 .name = "kgdb",
1522 .write = kgdb_console_write,
1523 .flags = CON_PRINTBUFFER | CON_ENABLED,
1524 .index = -1,
1527 #ifdef CONFIG_MAGIC_SYSRQ
1528 static void sysrq_handle_gdb(int key, struct tty_struct *tty)
1530 if (!kgdb_io_ops) {
1531 printk(KERN_CRIT "ERROR: No KGDB I/O module available\n");
1532 return;
1534 if (!kgdb_connected)
1535 printk(KERN_CRIT "Entering KGDB\n");
1537 kgdb_breakpoint();
1540 static struct sysrq_key_op sysrq_gdb_op = {
1541 .handler = sysrq_handle_gdb,
1542 .help_msg = "Gdb",
1543 .action_msg = "GDB",
1545 #endif
1547 static void kgdb_register_callbacks(void)
1549 if (!kgdb_io_module_registered) {
1550 kgdb_io_module_registered = 1;
1551 kgdb_arch_init();
1552 #ifdef CONFIG_MAGIC_SYSRQ
1553 register_sysrq_key('g', &sysrq_gdb_op);
1554 #endif
1555 if (kgdb_use_con && !kgdb_con_registered) {
1556 register_console(&kgdbcons);
1557 kgdb_con_registered = 1;
1562 static void kgdb_unregister_callbacks(void)
1565 * When this routine is called KGDB should unregister from the
1566 * panic handler and clean up, making sure it is not handling any
1567 * break exceptions at the time.
1569 if (kgdb_io_module_registered) {
1570 kgdb_io_module_registered = 0;
1571 kgdb_arch_exit();
1572 #ifdef CONFIG_MAGIC_SYSRQ
1573 unregister_sysrq_key('g', &sysrq_gdb_op);
1574 #endif
1575 if (kgdb_con_registered) {
1576 unregister_console(&kgdbcons);
1577 kgdb_con_registered = 0;
1582 static void kgdb_initial_breakpoint(void)
1584 kgdb_break_asap = 0;
1586 printk(KERN_CRIT "kgdb: Waiting for connection from remote gdb...\n");
1587 kgdb_breakpoint();
1591 * kgdb_register_io_module - register KGDB IO module
1592 * @new_kgdb_io_ops: the io ops vector
1594 * Register it with the KGDB core.
1596 int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
1598 int err;
1600 spin_lock(&kgdb_registration_lock);
1602 if (kgdb_io_ops) {
1603 spin_unlock(&kgdb_registration_lock);
1605 printk(KERN_ERR "kgdb: Another I/O driver is already "
1606 "registered with KGDB.\n");
1607 return -EBUSY;
1610 if (new_kgdb_io_ops->init) {
1611 err = new_kgdb_io_ops->init();
1612 if (err) {
1613 spin_unlock(&kgdb_registration_lock);
1614 return err;
1618 kgdb_io_ops = new_kgdb_io_ops;
1620 spin_unlock(&kgdb_registration_lock);
1622 printk(KERN_INFO "kgdb: Registered I/O driver %s.\n",
1623 new_kgdb_io_ops->name);
1625 /* Arm KGDB now. */
1626 kgdb_register_callbacks();
1628 if (kgdb_break_asap)
1629 kgdb_initial_breakpoint();
1631 return 0;
1633 EXPORT_SYMBOL_GPL(kgdb_register_io_module);
1636 * kkgdb_unregister_io_module - unregister KGDB IO module
1637 * @old_kgdb_io_ops: the io ops vector
1639 * Unregister it with the KGDB core.
1641 void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
1643 BUG_ON(kgdb_connected);
1646 * KGDB is no longer able to communicate out, so
1647 * unregister our callbacks and reset state.
1649 kgdb_unregister_callbacks();
1651 spin_lock(&kgdb_registration_lock);
1653 WARN_ON_ONCE(kgdb_io_ops != old_kgdb_io_ops);
1654 kgdb_io_ops = NULL;
1656 spin_unlock(&kgdb_registration_lock);
1658 printk(KERN_INFO
1659 "kgdb: Unregistered I/O driver %s, debugger disabled.\n",
1660 old_kgdb_io_ops->name);
1662 EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
1665 * kgdb_breakpoint - generate breakpoint exception
1667 * This function will generate a breakpoint exception. It is used at the
1668 * beginning of a program to sync up with a debugger and can be used
1669 * otherwise as a quick means to stop program execution and "break" into
1670 * the debugger.
1672 void kgdb_breakpoint(void)
1674 atomic_set(&kgdb_setting_breakpoint, 1);
1675 wmb(); /* Sync point before breakpoint */
1676 arch_kgdb_breakpoint();
1677 wmb(); /* Sync point after breakpoint */
1678 atomic_set(&kgdb_setting_breakpoint, 0);
1680 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
1682 static int __init opt_kgdb_wait(char *str)
1684 kgdb_break_asap = 1;
1686 if (kgdb_io_module_registered)
1687 kgdb_initial_breakpoint();
1689 return 0;
1692 early_param("kgdbwait", opt_kgdb_wait);