[MTD] physmap: resume already suspended chips on failure to suspend
[linux-2.6/mini2440.git] / kernel / kgdb.c
blob3ec23c3ec97fae75910a399b4b7200fb6a9169c6
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>
55 #include <asm/unaligned.h>
57 static int kgdb_break_asap;
59 struct kgdb_state {
60 int ex_vector;
61 int signo;
62 int err_code;
63 int cpu;
64 int pass_exception;
65 unsigned long threadid;
66 long kgdb_usethreadid;
67 struct pt_regs *linux_regs;
70 static struct debuggerinfo_struct {
71 void *debuggerinfo;
72 struct task_struct *task;
73 } kgdb_info[NR_CPUS];
75 /**
76 * kgdb_connected - Is a host GDB connected to us?
78 int kgdb_connected;
79 EXPORT_SYMBOL_GPL(kgdb_connected);
81 /* All the KGDB handlers are installed */
82 static int kgdb_io_module_registered;
84 /* Guard for recursive entry */
85 static int exception_level;
87 static struct kgdb_io *kgdb_io_ops;
88 static DEFINE_SPINLOCK(kgdb_registration_lock);
90 /* kgdb console driver is loaded */
91 static int kgdb_con_registered;
92 /* determine if kgdb console output should be used */
93 static int kgdb_use_con;
95 static int __init opt_kgdb_con(char *str)
97 kgdb_use_con = 1;
98 return 0;
101 early_param("kgdbcon", opt_kgdb_con);
103 module_param(kgdb_use_con, int, 0644);
106 * Holds information about breakpoints in a kernel. These breakpoints are
107 * added and removed by gdb.
109 static struct kgdb_bkpt kgdb_break[KGDB_MAX_BREAKPOINTS] = {
110 [0 ... KGDB_MAX_BREAKPOINTS-1] = { .state = BP_UNDEFINED }
114 * The CPU# of the active CPU, or -1 if none:
116 atomic_t kgdb_active = ATOMIC_INIT(-1);
119 * We use NR_CPUs not PERCPU, in case kgdb is used to debug early
120 * bootup code (which might not have percpu set up yet):
122 static atomic_t passive_cpu_wait[NR_CPUS];
123 static atomic_t cpu_in_kgdb[NR_CPUS];
124 atomic_t kgdb_setting_breakpoint;
126 struct task_struct *kgdb_usethread;
127 struct task_struct *kgdb_contthread;
129 int kgdb_single_step;
131 /* Our I/O buffers. */
132 static char remcom_in_buffer[BUFMAX];
133 static char remcom_out_buffer[BUFMAX];
135 /* Storage for the registers, in GDB format. */
136 static unsigned long gdb_regs[(NUMREGBYTES +
137 sizeof(unsigned long) - 1) /
138 sizeof(unsigned long)];
140 /* to keep track of the CPU which is doing the single stepping*/
141 atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
144 * If you are debugging a problem where roundup (the collection of
145 * all other CPUs) is a problem [this should be extremely rare],
146 * then use the nokgdbroundup option to avoid roundup. In that case
147 * the other CPUs might interfere with your debugging context, so
148 * use this with care:
150 static int kgdb_do_roundup = 1;
152 static int __init opt_nokgdbroundup(char *str)
154 kgdb_do_roundup = 0;
156 return 0;
159 early_param("nokgdbroundup", opt_nokgdbroundup);
162 * Finally, some KGDB code :-)
166 * Weak aliases for breakpoint management,
167 * can be overriden by architectures when needed:
169 int __weak kgdb_validate_break_address(unsigned long addr)
171 char tmp_variable[BREAK_INSTR_SIZE];
173 return probe_kernel_read(tmp_variable, (char *)addr, BREAK_INSTR_SIZE);
176 int __weak kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr)
178 int err;
180 err = probe_kernel_read(saved_instr, (char *)addr, BREAK_INSTR_SIZE);
181 if (err)
182 return err;
184 return probe_kernel_write((char *)addr, arch_kgdb_ops.gdb_bpt_instr,
185 BREAK_INSTR_SIZE);
188 int __weak kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle)
190 return probe_kernel_write((char *)addr,
191 (char *)bundle, BREAK_INSTR_SIZE);
194 unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs)
196 return instruction_pointer(regs);
199 int __weak kgdb_arch_init(void)
201 return 0;
204 int __weak kgdb_skipexception(int exception, struct pt_regs *regs)
206 return 0;
209 void __weak
210 kgdb_post_primary_code(struct pt_regs *regs, int e_vector, int err_code)
212 return;
216 * kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
217 * @regs: Current &struct pt_regs.
219 * This function will be called if the particular architecture must
220 * disable hardware debugging while it is processing gdb packets or
221 * handling exception.
223 void __weak kgdb_disable_hw_debug(struct pt_regs *regs)
228 * GDB remote protocol parser:
231 static int hex(char ch)
233 if ((ch >= 'a') && (ch <= 'f'))
234 return ch - 'a' + 10;
235 if ((ch >= '0') && (ch <= '9'))
236 return ch - '0';
237 if ((ch >= 'A') && (ch <= 'F'))
238 return ch - 'A' + 10;
239 return -1;
242 /* scan for the sequence $<data>#<checksum> */
243 static void get_packet(char *buffer)
245 unsigned char checksum;
246 unsigned char xmitcsum;
247 int count;
248 char ch;
250 do {
252 * Spin and wait around for the start character, ignore all
253 * other characters:
255 while ((ch = (kgdb_io_ops->read_char())) != '$')
256 /* nothing */;
258 kgdb_connected = 1;
259 checksum = 0;
260 xmitcsum = -1;
262 count = 0;
265 * now, read until a # or end of buffer is found:
267 while (count < (BUFMAX - 1)) {
268 ch = kgdb_io_ops->read_char();
269 if (ch == '#')
270 break;
271 checksum = checksum + ch;
272 buffer[count] = ch;
273 count = count + 1;
275 buffer[count] = 0;
277 if (ch == '#') {
278 xmitcsum = hex(kgdb_io_ops->read_char()) << 4;
279 xmitcsum += hex(kgdb_io_ops->read_char());
281 if (checksum != xmitcsum)
282 /* failed checksum */
283 kgdb_io_ops->write_char('-');
284 else
285 /* successful transfer */
286 kgdb_io_ops->write_char('+');
287 if (kgdb_io_ops->flush)
288 kgdb_io_ops->flush();
290 } while (checksum != xmitcsum);
294 * Send the packet in buffer.
295 * Check for gdb connection if asked for.
297 static void put_packet(char *buffer)
299 unsigned char checksum;
300 int count;
301 char ch;
304 * $<packet info>#<checksum>.
306 while (1) {
307 kgdb_io_ops->write_char('$');
308 checksum = 0;
309 count = 0;
311 while ((ch = buffer[count])) {
312 kgdb_io_ops->write_char(ch);
313 checksum += ch;
314 count++;
317 kgdb_io_ops->write_char('#');
318 kgdb_io_ops->write_char(hex_asc_hi(checksum));
319 kgdb_io_ops->write_char(hex_asc_lo(checksum));
320 if (kgdb_io_ops->flush)
321 kgdb_io_ops->flush();
323 /* Now see what we get in reply. */
324 ch = kgdb_io_ops->read_char();
326 if (ch == 3)
327 ch = kgdb_io_ops->read_char();
329 /* If we get an ACK, we are done. */
330 if (ch == '+')
331 return;
334 * If we get the start of another packet, this means
335 * that GDB is attempting to reconnect. We will NAK
336 * the packet being sent, and stop trying to send this
337 * packet.
339 if (ch == '$') {
340 kgdb_io_ops->write_char('-');
341 if (kgdb_io_ops->flush)
342 kgdb_io_ops->flush();
343 return;
349 * Convert the memory pointed to by mem into hex, placing result in buf.
350 * Return a pointer to the last char put in buf (null). May return an error.
352 int kgdb_mem2hex(char *mem, char *buf, int count)
354 char *tmp;
355 int err;
358 * We use the upper half of buf as an intermediate buffer for the
359 * raw memory copy. Hex conversion will work against this one.
361 tmp = buf + count;
363 err = probe_kernel_read(tmp, mem, count);
364 if (!err) {
365 while (count > 0) {
366 buf = pack_hex_byte(buf, *tmp);
367 tmp++;
368 count--;
371 *buf = 0;
374 return err;
378 * Copy the binary array pointed to by buf into mem. Fix $, #, and
379 * 0x7d escaped with 0x7d. Return a pointer to the character after
380 * the last byte written.
382 static int kgdb_ebin2mem(char *buf, char *mem, int count)
384 int err = 0;
385 char c;
387 while (count-- > 0) {
388 c = *buf++;
389 if (c == 0x7d)
390 c = *buf++ ^ 0x20;
392 err = probe_kernel_write(mem, &c, 1);
393 if (err)
394 break;
396 mem++;
399 return err;
403 * Convert the hex array pointed to by buf into binary to be placed in mem.
404 * Return a pointer to the character AFTER the last byte written.
405 * May return an error.
407 int kgdb_hex2mem(char *buf, char *mem, int count)
409 char *tmp_raw;
410 char *tmp_hex;
413 * We use the upper half of buf as an intermediate buffer for the
414 * raw memory that is converted from hex.
416 tmp_raw = buf + count * 2;
418 tmp_hex = tmp_raw - 1;
419 while (tmp_hex >= buf) {
420 tmp_raw--;
421 *tmp_raw = hex(*tmp_hex--);
422 *tmp_raw |= hex(*tmp_hex--) << 4;
425 return probe_kernel_write(mem, tmp_raw, count);
429 * While we find nice hex chars, build a long_val.
430 * Return number of chars processed.
432 int kgdb_hex2long(char **ptr, unsigned long *long_val)
434 int hex_val;
435 int num = 0;
437 *long_val = 0;
439 while (**ptr) {
440 hex_val = hex(**ptr);
441 if (hex_val < 0)
442 break;
444 *long_val = (*long_val << 4) | hex_val;
445 num++;
446 (*ptr)++;
449 return num;
452 /* Write memory due to an 'M' or 'X' packet. */
453 static int write_mem_msg(int binary)
455 char *ptr = &remcom_in_buffer[1];
456 unsigned long addr;
457 unsigned long length;
458 int err;
460 if (kgdb_hex2long(&ptr, &addr) > 0 && *(ptr++) == ',' &&
461 kgdb_hex2long(&ptr, &length) > 0 && *(ptr++) == ':') {
462 if (binary)
463 err = kgdb_ebin2mem(ptr, (char *)addr, length);
464 else
465 err = kgdb_hex2mem(ptr, (char *)addr, length);
466 if (err)
467 return err;
468 if (CACHE_FLUSH_IS_SAFE)
469 flush_icache_range(addr, addr + length + 1);
470 return 0;
473 return -EINVAL;
476 static void error_packet(char *pkt, int error)
478 error = -error;
479 pkt[0] = 'E';
480 pkt[1] = hex_asc[(error / 10)];
481 pkt[2] = hex_asc[(error % 10)];
482 pkt[3] = '\0';
486 * Thread ID accessors. We represent a flat TID space to GDB, where
487 * the per CPU idle threads (which under Linux all have PID 0) are
488 * remapped to negative TIDs.
491 #define BUF_THREAD_ID_SIZE 16
493 static char *pack_threadid(char *pkt, unsigned char *id)
495 char *limit;
497 limit = pkt + BUF_THREAD_ID_SIZE;
498 while (pkt < limit)
499 pkt = pack_hex_byte(pkt, *id++);
501 return pkt;
504 static void int_to_threadref(unsigned char *id, int value)
506 unsigned char *scan;
507 int i = 4;
509 scan = (unsigned char *)id;
510 while (i--)
511 *scan++ = 0;
512 put_unaligned_be32(value, scan);
515 static struct task_struct *getthread(struct pt_regs *regs, int tid)
518 * Non-positive TIDs are remapped idle tasks:
520 if (tid <= 0)
521 return idle_task(-tid);
524 * find_task_by_pid_ns() does not take the tasklist lock anymore
525 * but is nicely RCU locked - hence is a pretty resilient
526 * thing to use:
528 return find_task_by_pid_ns(tid, &init_pid_ns);
532 * CPU debug state control:
535 #ifdef CONFIG_SMP
536 static void kgdb_wait(struct pt_regs *regs)
538 unsigned long flags;
539 int cpu;
541 local_irq_save(flags);
542 cpu = raw_smp_processor_id();
543 kgdb_info[cpu].debuggerinfo = regs;
544 kgdb_info[cpu].task = current;
546 * Make sure the above info reaches the primary CPU before
547 * our cpu_in_kgdb[] flag setting does:
549 smp_wmb();
550 atomic_set(&cpu_in_kgdb[cpu], 1);
552 /* Wait till primary CPU is done with debugging */
553 while (atomic_read(&passive_cpu_wait[cpu]))
554 cpu_relax();
556 kgdb_info[cpu].debuggerinfo = NULL;
557 kgdb_info[cpu].task = NULL;
559 /* fix up hardware debug registers on local cpu */
560 if (arch_kgdb_ops.correct_hw_break)
561 arch_kgdb_ops.correct_hw_break();
563 /* Signal the primary CPU that we are done: */
564 atomic_set(&cpu_in_kgdb[cpu], 0);
565 clocksource_touch_watchdog();
566 local_irq_restore(flags);
568 #endif
571 * Some architectures need cache flushes when we set/clear a
572 * breakpoint:
574 static void kgdb_flush_swbreak_addr(unsigned long addr)
576 if (!CACHE_FLUSH_IS_SAFE)
577 return;
579 if (current->mm && current->mm->mmap_cache) {
580 flush_cache_range(current->mm->mmap_cache,
581 addr, addr + BREAK_INSTR_SIZE);
583 /* Force flush instruction cache if it was outside the mm */
584 flush_icache_range(addr, addr + BREAK_INSTR_SIZE);
588 * SW breakpoint management:
590 static int kgdb_activate_sw_breakpoints(void)
592 unsigned long addr;
593 int error = 0;
594 int i;
596 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
597 if (kgdb_break[i].state != BP_SET)
598 continue;
600 addr = kgdb_break[i].bpt_addr;
601 error = kgdb_arch_set_breakpoint(addr,
602 kgdb_break[i].saved_instr);
603 if (error)
604 return error;
606 kgdb_flush_swbreak_addr(addr);
607 kgdb_break[i].state = BP_ACTIVE;
609 return 0;
612 static int kgdb_set_sw_break(unsigned long addr)
614 int err = kgdb_validate_break_address(addr);
615 int breakno = -1;
616 int i;
618 if (err)
619 return err;
621 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
622 if ((kgdb_break[i].state == BP_SET) &&
623 (kgdb_break[i].bpt_addr == addr))
624 return -EEXIST;
626 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
627 if (kgdb_break[i].state == BP_REMOVED &&
628 kgdb_break[i].bpt_addr == addr) {
629 breakno = i;
630 break;
634 if (breakno == -1) {
635 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
636 if (kgdb_break[i].state == BP_UNDEFINED) {
637 breakno = i;
638 break;
643 if (breakno == -1)
644 return -E2BIG;
646 kgdb_break[breakno].state = BP_SET;
647 kgdb_break[breakno].type = BP_BREAKPOINT;
648 kgdb_break[breakno].bpt_addr = addr;
650 return 0;
653 static int kgdb_deactivate_sw_breakpoints(void)
655 unsigned long addr;
656 int error = 0;
657 int i;
659 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
660 if (kgdb_break[i].state != BP_ACTIVE)
661 continue;
662 addr = kgdb_break[i].bpt_addr;
663 error = kgdb_arch_remove_breakpoint(addr,
664 kgdb_break[i].saved_instr);
665 if (error)
666 return error;
668 kgdb_flush_swbreak_addr(addr);
669 kgdb_break[i].state = BP_SET;
671 return 0;
674 static int kgdb_remove_sw_break(unsigned long addr)
676 int i;
678 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
679 if ((kgdb_break[i].state == BP_SET) &&
680 (kgdb_break[i].bpt_addr == addr)) {
681 kgdb_break[i].state = BP_REMOVED;
682 return 0;
685 return -ENOENT;
688 int kgdb_isremovedbreak(unsigned long addr)
690 int i;
692 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
693 if ((kgdb_break[i].state == BP_REMOVED) &&
694 (kgdb_break[i].bpt_addr == addr))
695 return 1;
697 return 0;
700 static int remove_all_break(void)
702 unsigned long addr;
703 int error;
704 int i;
706 /* Clear memory breakpoints. */
707 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
708 if (kgdb_break[i].state != BP_ACTIVE)
709 goto setundefined;
710 addr = kgdb_break[i].bpt_addr;
711 error = kgdb_arch_remove_breakpoint(addr,
712 kgdb_break[i].saved_instr);
713 if (error)
714 printk(KERN_ERR "KGDB: breakpoint remove failed: %lx\n",
715 addr);
716 setundefined:
717 kgdb_break[i].state = BP_UNDEFINED;
720 /* Clear hardware breakpoints. */
721 if (arch_kgdb_ops.remove_all_hw_break)
722 arch_kgdb_ops.remove_all_hw_break();
724 return 0;
728 * Remap normal tasks to their real PID, idle tasks to -1 ... -NR_CPUs:
730 static inline int shadow_pid(int realpid)
732 if (realpid)
733 return realpid;
735 return -1-raw_smp_processor_id();
738 static char gdbmsgbuf[BUFMAX + 1];
740 static void kgdb_msg_write(const char *s, int len)
742 char *bufptr;
743 int wcount;
744 int i;
746 /* 'O'utput */
747 gdbmsgbuf[0] = 'O';
749 /* Fill and send buffers... */
750 while (len > 0) {
751 bufptr = gdbmsgbuf + 1;
753 /* Calculate how many this time */
754 if ((len << 1) > (BUFMAX - 2))
755 wcount = (BUFMAX - 2) >> 1;
756 else
757 wcount = len;
759 /* Pack in hex chars */
760 for (i = 0; i < wcount; i++)
761 bufptr = pack_hex_byte(bufptr, s[i]);
762 *bufptr = '\0';
764 /* Move up */
765 s += wcount;
766 len -= wcount;
768 /* Write packet */
769 put_packet(gdbmsgbuf);
774 * Return true if there is a valid kgdb I/O module. Also if no
775 * debugger is attached a message can be printed to the console about
776 * waiting for the debugger to attach.
778 * The print_wait argument is only to be true when called from inside
779 * the core kgdb_handle_exception, because it will wait for the
780 * debugger to attach.
782 static int kgdb_io_ready(int print_wait)
784 if (!kgdb_io_ops)
785 return 0;
786 if (kgdb_connected)
787 return 1;
788 if (atomic_read(&kgdb_setting_breakpoint))
789 return 1;
790 if (print_wait)
791 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
792 return 1;
796 * All the functions that start with gdb_cmd are the various
797 * operations to implement the handlers for the gdbserial protocol
798 * where KGDB is communicating with an external debugger
801 /* Handle the '?' status packets */
802 static void gdb_cmd_status(struct kgdb_state *ks)
805 * We know that this packet is only sent
806 * during initial connect. So to be safe,
807 * we clear out our breakpoints now in case
808 * GDB is reconnecting.
810 remove_all_break();
812 remcom_out_buffer[0] = 'S';
813 pack_hex_byte(&remcom_out_buffer[1], ks->signo);
816 /* Handle the 'g' get registers request */
817 static void gdb_cmd_getregs(struct kgdb_state *ks)
819 struct task_struct *thread;
820 void *local_debuggerinfo;
821 int i;
823 thread = kgdb_usethread;
824 if (!thread) {
825 thread = kgdb_info[ks->cpu].task;
826 local_debuggerinfo = kgdb_info[ks->cpu].debuggerinfo;
827 } else {
828 local_debuggerinfo = NULL;
829 for (i = 0; i < NR_CPUS; i++) {
831 * Try to find the task on some other
832 * or possibly this node if we do not
833 * find the matching task then we try
834 * to approximate the results.
836 if (thread == kgdb_info[i].task)
837 local_debuggerinfo = kgdb_info[i].debuggerinfo;
842 * All threads that don't have debuggerinfo should be
843 * in __schedule() sleeping, since all other CPUs
844 * are in kgdb_wait, and thus have debuggerinfo.
846 if (local_debuggerinfo) {
847 pt_regs_to_gdb_regs(gdb_regs, local_debuggerinfo);
848 } else {
850 * Pull stuff saved during switch_to; nothing
851 * else is accessible (or even particularly
852 * relevant).
854 * This should be enough for a stack trace.
856 sleeping_thread_to_gdb_regs(gdb_regs, thread);
858 kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer, NUMREGBYTES);
861 /* Handle the 'G' set registers request */
862 static void gdb_cmd_setregs(struct kgdb_state *ks)
864 kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs, NUMREGBYTES);
866 if (kgdb_usethread && kgdb_usethread != current) {
867 error_packet(remcom_out_buffer, -EINVAL);
868 } else {
869 gdb_regs_to_pt_regs(gdb_regs, ks->linux_regs);
870 strcpy(remcom_out_buffer, "OK");
874 /* Handle the 'm' memory read bytes */
875 static void gdb_cmd_memread(struct kgdb_state *ks)
877 char *ptr = &remcom_in_buffer[1];
878 unsigned long length;
879 unsigned long addr;
880 int err;
882 if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' &&
883 kgdb_hex2long(&ptr, &length) > 0) {
884 err = kgdb_mem2hex((char *)addr, remcom_out_buffer, length);
885 if (err)
886 error_packet(remcom_out_buffer, err);
887 } else {
888 error_packet(remcom_out_buffer, -EINVAL);
892 /* Handle the 'M' memory write bytes */
893 static void gdb_cmd_memwrite(struct kgdb_state *ks)
895 int err = write_mem_msg(0);
897 if (err)
898 error_packet(remcom_out_buffer, err);
899 else
900 strcpy(remcom_out_buffer, "OK");
903 /* Handle the 'X' memory binary write bytes */
904 static void gdb_cmd_binwrite(struct kgdb_state *ks)
906 int err = write_mem_msg(1);
908 if (err)
909 error_packet(remcom_out_buffer, err);
910 else
911 strcpy(remcom_out_buffer, "OK");
914 /* Handle the 'D' or 'k', detach or kill packets */
915 static void gdb_cmd_detachkill(struct kgdb_state *ks)
917 int error;
919 /* The detach case */
920 if (remcom_in_buffer[0] == 'D') {
921 error = remove_all_break();
922 if (error < 0) {
923 error_packet(remcom_out_buffer, error);
924 } else {
925 strcpy(remcom_out_buffer, "OK");
926 kgdb_connected = 0;
928 put_packet(remcom_out_buffer);
929 } else {
931 * Assume the kill case, with no exit code checking,
932 * trying to force detach the debugger:
934 remove_all_break();
935 kgdb_connected = 0;
939 /* Handle the 'R' reboot packets */
940 static int gdb_cmd_reboot(struct kgdb_state *ks)
942 /* For now, only honor R0 */
943 if (strcmp(remcom_in_buffer, "R0") == 0) {
944 printk(KERN_CRIT "Executing emergency reboot\n");
945 strcpy(remcom_out_buffer, "OK");
946 put_packet(remcom_out_buffer);
949 * Execution should not return from
950 * machine_emergency_restart()
952 machine_emergency_restart();
953 kgdb_connected = 0;
955 return 1;
957 return 0;
960 /* Handle the 'q' query packets */
961 static void gdb_cmd_query(struct kgdb_state *ks)
963 struct task_struct *thread;
964 unsigned char thref[8];
965 char *ptr;
966 int i;
968 switch (remcom_in_buffer[1]) {
969 case 's':
970 case 'f':
971 if (memcmp(remcom_in_buffer + 2, "ThreadInfo", 10)) {
972 error_packet(remcom_out_buffer, -EINVAL);
973 break;
976 if (remcom_in_buffer[1] == 'f')
977 ks->threadid = 1;
979 remcom_out_buffer[0] = 'm';
980 ptr = remcom_out_buffer + 1;
982 for (i = 0; i < 17; ks->threadid++) {
983 thread = getthread(ks->linux_regs, ks->threadid);
984 if (thread) {
985 int_to_threadref(thref, ks->threadid);
986 pack_threadid(ptr, thref);
987 ptr += BUF_THREAD_ID_SIZE;
988 *(ptr++) = ',';
989 i++;
992 *(--ptr) = '\0';
993 break;
995 case 'C':
996 /* Current thread id */
997 strcpy(remcom_out_buffer, "QC");
998 ks->threadid = shadow_pid(current->pid);
999 int_to_threadref(thref, ks->threadid);
1000 pack_threadid(remcom_out_buffer + 2, thref);
1001 break;
1002 case 'T':
1003 if (memcmp(remcom_in_buffer + 1, "ThreadExtraInfo,", 16)) {
1004 error_packet(remcom_out_buffer, -EINVAL);
1005 break;
1007 ks->threadid = 0;
1008 ptr = remcom_in_buffer + 17;
1009 kgdb_hex2long(&ptr, &ks->threadid);
1010 if (!getthread(ks->linux_regs, ks->threadid)) {
1011 error_packet(remcom_out_buffer, -EINVAL);
1012 break;
1014 if (ks->threadid > 0) {
1015 kgdb_mem2hex(getthread(ks->linux_regs,
1016 ks->threadid)->comm,
1017 remcom_out_buffer, 16);
1018 } else {
1019 static char tmpstr[23 + BUF_THREAD_ID_SIZE];
1021 sprintf(tmpstr, "Shadow task %d for pid 0",
1022 (int)(-ks->threadid-1));
1023 kgdb_mem2hex(tmpstr, remcom_out_buffer, strlen(tmpstr));
1025 break;
1029 /* Handle the 'H' task query packets */
1030 static void gdb_cmd_task(struct kgdb_state *ks)
1032 struct task_struct *thread;
1033 char *ptr;
1035 switch (remcom_in_buffer[1]) {
1036 case 'g':
1037 ptr = &remcom_in_buffer[2];
1038 kgdb_hex2long(&ptr, &ks->threadid);
1039 thread = getthread(ks->linux_regs, ks->threadid);
1040 if (!thread && ks->threadid > 0) {
1041 error_packet(remcom_out_buffer, -EINVAL);
1042 break;
1044 kgdb_usethread = thread;
1045 ks->kgdb_usethreadid = ks->threadid;
1046 strcpy(remcom_out_buffer, "OK");
1047 break;
1048 case 'c':
1049 ptr = &remcom_in_buffer[2];
1050 kgdb_hex2long(&ptr, &ks->threadid);
1051 if (!ks->threadid) {
1052 kgdb_contthread = NULL;
1053 } else {
1054 thread = getthread(ks->linux_regs, ks->threadid);
1055 if (!thread && ks->threadid > 0) {
1056 error_packet(remcom_out_buffer, -EINVAL);
1057 break;
1059 kgdb_contthread = thread;
1061 strcpy(remcom_out_buffer, "OK");
1062 break;
1066 /* Handle the 'T' thread query packets */
1067 static void gdb_cmd_thread(struct kgdb_state *ks)
1069 char *ptr = &remcom_in_buffer[1];
1070 struct task_struct *thread;
1072 kgdb_hex2long(&ptr, &ks->threadid);
1073 thread = getthread(ks->linux_regs, ks->threadid);
1074 if (thread)
1075 strcpy(remcom_out_buffer, "OK");
1076 else
1077 error_packet(remcom_out_buffer, -EINVAL);
1080 /* Handle the 'z' or 'Z' breakpoint remove or set packets */
1081 static void gdb_cmd_break(struct kgdb_state *ks)
1084 * Since GDB-5.3, it's been drafted that '0' is a software
1085 * breakpoint, '1' is a hardware breakpoint, so let's do that.
1087 char *bpt_type = &remcom_in_buffer[1];
1088 char *ptr = &remcom_in_buffer[2];
1089 unsigned long addr;
1090 unsigned long length;
1091 int error = 0;
1093 if (arch_kgdb_ops.set_hw_breakpoint && *bpt_type >= '1') {
1094 /* Unsupported */
1095 if (*bpt_type > '4')
1096 return;
1097 } else {
1098 if (*bpt_type != '0' && *bpt_type != '1')
1099 /* Unsupported. */
1100 return;
1104 * Test if this is a hardware breakpoint, and
1105 * if we support it:
1107 if (*bpt_type == '1' && !(arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT))
1108 /* Unsupported. */
1109 return;
1111 if (*(ptr++) != ',') {
1112 error_packet(remcom_out_buffer, -EINVAL);
1113 return;
1115 if (!kgdb_hex2long(&ptr, &addr)) {
1116 error_packet(remcom_out_buffer, -EINVAL);
1117 return;
1119 if (*(ptr++) != ',' ||
1120 !kgdb_hex2long(&ptr, &length)) {
1121 error_packet(remcom_out_buffer, -EINVAL);
1122 return;
1125 if (remcom_in_buffer[0] == 'Z' && *bpt_type == '0')
1126 error = kgdb_set_sw_break(addr);
1127 else if (remcom_in_buffer[0] == 'z' && *bpt_type == '0')
1128 error = kgdb_remove_sw_break(addr);
1129 else if (remcom_in_buffer[0] == 'Z')
1130 error = arch_kgdb_ops.set_hw_breakpoint(addr,
1131 (int)length, *bpt_type - '0');
1132 else if (remcom_in_buffer[0] == 'z')
1133 error = arch_kgdb_ops.remove_hw_breakpoint(addr,
1134 (int) length, *bpt_type - '0');
1136 if (error == 0)
1137 strcpy(remcom_out_buffer, "OK");
1138 else
1139 error_packet(remcom_out_buffer, error);
1142 /* Handle the 'C' signal / exception passing packets */
1143 static int gdb_cmd_exception_pass(struct kgdb_state *ks)
1145 /* C09 == pass exception
1146 * C15 == detach kgdb, pass exception
1148 if (remcom_in_buffer[1] == '0' && remcom_in_buffer[2] == '9') {
1150 ks->pass_exception = 1;
1151 remcom_in_buffer[0] = 'c';
1153 } else if (remcom_in_buffer[1] == '1' && remcom_in_buffer[2] == '5') {
1155 ks->pass_exception = 1;
1156 remcom_in_buffer[0] = 'D';
1157 remove_all_break();
1158 kgdb_connected = 0;
1159 return 1;
1161 } else {
1162 error_packet(remcom_out_buffer, -EINVAL);
1163 return 0;
1166 /* Indicate fall through */
1167 return -1;
1171 * This function performs all gdbserial command procesing
1173 static int gdb_serial_stub(struct kgdb_state *ks)
1175 int error = 0;
1176 int tmp;
1178 /* Clear the out buffer. */
1179 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
1181 if (kgdb_connected) {
1182 unsigned char thref[8];
1183 char *ptr;
1185 /* Reply to host that an exception has occurred */
1186 ptr = remcom_out_buffer;
1187 *ptr++ = 'T';
1188 ptr = pack_hex_byte(ptr, ks->signo);
1189 ptr += strlen(strcpy(ptr, "thread:"));
1190 int_to_threadref(thref, shadow_pid(current->pid));
1191 ptr = pack_threadid(ptr, thref);
1192 *ptr++ = ';';
1193 put_packet(remcom_out_buffer);
1196 kgdb_usethread = kgdb_info[ks->cpu].task;
1197 ks->kgdb_usethreadid = shadow_pid(kgdb_info[ks->cpu].task->pid);
1198 ks->pass_exception = 0;
1200 while (1) {
1201 error = 0;
1203 /* Clear the out buffer. */
1204 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
1206 get_packet(remcom_in_buffer);
1208 switch (remcom_in_buffer[0]) {
1209 case '?': /* gdbserial status */
1210 gdb_cmd_status(ks);
1211 break;
1212 case 'g': /* return the value of the CPU registers */
1213 gdb_cmd_getregs(ks);
1214 break;
1215 case 'G': /* set the value of the CPU registers - return OK */
1216 gdb_cmd_setregs(ks);
1217 break;
1218 case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
1219 gdb_cmd_memread(ks);
1220 break;
1221 case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */
1222 gdb_cmd_memwrite(ks);
1223 break;
1224 case 'X': /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */
1225 gdb_cmd_binwrite(ks);
1226 break;
1227 /* kill or detach. KGDB should treat this like a
1228 * continue.
1230 case 'D': /* Debugger detach */
1231 case 'k': /* Debugger detach via kill */
1232 gdb_cmd_detachkill(ks);
1233 goto default_handle;
1234 case 'R': /* Reboot */
1235 if (gdb_cmd_reboot(ks))
1236 goto default_handle;
1237 break;
1238 case 'q': /* query command */
1239 gdb_cmd_query(ks);
1240 break;
1241 case 'H': /* task related */
1242 gdb_cmd_task(ks);
1243 break;
1244 case 'T': /* Query thread status */
1245 gdb_cmd_thread(ks);
1246 break;
1247 case 'z': /* Break point remove */
1248 case 'Z': /* Break point set */
1249 gdb_cmd_break(ks);
1250 break;
1251 case 'C': /* Exception passing */
1252 tmp = gdb_cmd_exception_pass(ks);
1253 if (tmp > 0)
1254 goto default_handle;
1255 if (tmp == 0)
1256 break;
1257 /* Fall through on tmp < 0 */
1258 case 'c': /* Continue packet */
1259 case 's': /* Single step packet */
1260 if (kgdb_contthread && kgdb_contthread != current) {
1261 /* Can't switch threads in kgdb */
1262 error_packet(remcom_out_buffer, -EINVAL);
1263 break;
1265 kgdb_activate_sw_breakpoints();
1266 /* Fall through to default processing */
1267 default:
1268 default_handle:
1269 error = kgdb_arch_handle_exception(ks->ex_vector,
1270 ks->signo,
1271 ks->err_code,
1272 remcom_in_buffer,
1273 remcom_out_buffer,
1274 ks->linux_regs);
1276 * Leave cmd processing on error, detach,
1277 * kill, continue, or single step.
1279 if (error >= 0 || remcom_in_buffer[0] == 'D' ||
1280 remcom_in_buffer[0] == 'k') {
1281 error = 0;
1282 goto kgdb_exit;
1287 /* reply to the request */
1288 put_packet(remcom_out_buffer);
1291 kgdb_exit:
1292 if (ks->pass_exception)
1293 error = 1;
1294 return error;
1297 static int kgdb_reenter_check(struct kgdb_state *ks)
1299 unsigned long addr;
1301 if (atomic_read(&kgdb_active) != raw_smp_processor_id())
1302 return 0;
1304 /* Panic on recursive debugger calls: */
1305 exception_level++;
1306 addr = kgdb_arch_pc(ks->ex_vector, ks->linux_regs);
1307 kgdb_deactivate_sw_breakpoints();
1310 * If the break point removed ok at the place exception
1311 * occurred, try to recover and print a warning to the end
1312 * user because the user planted a breakpoint in a place that
1313 * KGDB needs in order to function.
1315 if (kgdb_remove_sw_break(addr) == 0) {
1316 exception_level = 0;
1317 kgdb_skipexception(ks->ex_vector, ks->linux_regs);
1318 kgdb_activate_sw_breakpoints();
1319 printk(KERN_CRIT "KGDB: re-enter error: breakpoint removed %lx\n",
1320 addr);
1321 WARN_ON_ONCE(1);
1323 return 1;
1325 remove_all_break();
1326 kgdb_skipexception(ks->ex_vector, ks->linux_regs);
1328 if (exception_level > 1) {
1329 dump_stack();
1330 panic("Recursive entry to debugger");
1333 printk(KERN_CRIT "KGDB: re-enter exception: ALL breakpoints killed\n");
1334 dump_stack();
1335 panic("Recursive entry to debugger");
1337 return 1;
1341 * kgdb_handle_exception() - main entry point from a kernel exception
1343 * Locking hierarchy:
1344 * interface locks, if any (begin_session)
1345 * kgdb lock (kgdb_active)
1348 kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs)
1350 struct kgdb_state kgdb_var;
1351 struct kgdb_state *ks = &kgdb_var;
1352 unsigned long flags;
1353 int error = 0;
1354 int i, cpu;
1356 ks->cpu = raw_smp_processor_id();
1357 ks->ex_vector = evector;
1358 ks->signo = signo;
1359 ks->ex_vector = evector;
1360 ks->err_code = ecode;
1361 ks->kgdb_usethreadid = 0;
1362 ks->linux_regs = regs;
1364 if (kgdb_reenter_check(ks))
1365 return 0; /* Ouch, double exception ! */
1367 acquirelock:
1369 * Interrupts will be restored by the 'trap return' code, except when
1370 * single stepping.
1372 local_irq_save(flags);
1374 cpu = raw_smp_processor_id();
1377 * Acquire the kgdb_active lock:
1379 while (atomic_cmpxchg(&kgdb_active, -1, cpu) != -1)
1380 cpu_relax();
1383 * Do not start the debugger connection on this CPU if the last
1384 * instance of the exception handler wanted to come into the
1385 * debugger on a different CPU via a single step
1387 if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
1388 atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
1390 atomic_set(&kgdb_active, -1);
1391 clocksource_touch_watchdog();
1392 local_irq_restore(flags);
1394 goto acquirelock;
1397 if (!kgdb_io_ready(1)) {
1398 error = 1;
1399 goto kgdb_restore; /* No I/O connection, so resume the system */
1403 * Don't enter if we have hit a removed breakpoint.
1405 if (kgdb_skipexception(ks->ex_vector, ks->linux_regs))
1406 goto kgdb_restore;
1408 /* Call the I/O driver's pre_exception routine */
1409 if (kgdb_io_ops->pre_exception)
1410 kgdb_io_ops->pre_exception();
1412 kgdb_info[ks->cpu].debuggerinfo = ks->linux_regs;
1413 kgdb_info[ks->cpu].task = current;
1415 kgdb_disable_hw_debug(ks->linux_regs);
1418 * Get the passive CPU lock which will hold all the non-primary
1419 * CPU in a spin state while the debugger is active
1421 if (!kgdb_single_step || !kgdb_contthread) {
1422 for (i = 0; i < NR_CPUS; i++)
1423 atomic_set(&passive_cpu_wait[i], 1);
1427 * spin_lock code is good enough as a barrier so we don't
1428 * need one here:
1430 atomic_set(&cpu_in_kgdb[ks->cpu], 1);
1432 #ifdef CONFIG_SMP
1433 /* Signal the other CPUs to enter kgdb_wait() */
1434 if ((!kgdb_single_step || !kgdb_contthread) && kgdb_do_roundup)
1435 kgdb_roundup_cpus(flags);
1436 #endif
1439 * Wait for the other CPUs to be notified and be waiting for us:
1441 for_each_online_cpu(i) {
1442 while (!atomic_read(&cpu_in_kgdb[i]))
1443 cpu_relax();
1447 * At this point the primary processor is completely
1448 * in the debugger and all secondary CPUs are quiescent
1450 kgdb_post_primary_code(ks->linux_regs, ks->ex_vector, ks->err_code);
1451 kgdb_deactivate_sw_breakpoints();
1452 kgdb_single_step = 0;
1453 kgdb_contthread = NULL;
1454 exception_level = 0;
1456 /* Talk to debugger with gdbserial protocol */
1457 error = gdb_serial_stub(ks);
1459 /* Call the I/O driver's post_exception routine */
1460 if (kgdb_io_ops->post_exception)
1461 kgdb_io_ops->post_exception();
1463 kgdb_info[ks->cpu].debuggerinfo = NULL;
1464 kgdb_info[ks->cpu].task = NULL;
1465 atomic_set(&cpu_in_kgdb[ks->cpu], 0);
1467 if (!kgdb_single_step || !kgdb_contthread) {
1468 for (i = NR_CPUS-1; i >= 0; i--)
1469 atomic_set(&passive_cpu_wait[i], 0);
1471 * Wait till all the CPUs have quit
1472 * from the debugger.
1474 for_each_online_cpu(i) {
1475 while (atomic_read(&cpu_in_kgdb[i]))
1476 cpu_relax();
1480 kgdb_restore:
1481 /* Free kgdb_active */
1482 atomic_set(&kgdb_active, -1);
1483 clocksource_touch_watchdog();
1484 local_irq_restore(flags);
1486 return error;
1489 int kgdb_nmicallback(int cpu, void *regs)
1491 #ifdef CONFIG_SMP
1492 if (!atomic_read(&cpu_in_kgdb[cpu]) &&
1493 atomic_read(&kgdb_active) != cpu &&
1494 atomic_read(&cpu_in_kgdb[atomic_read(&kgdb_active)])) {
1495 kgdb_wait((struct pt_regs *)regs);
1496 return 0;
1498 #endif
1499 return 1;
1502 static void kgdb_console_write(struct console *co, const char *s,
1503 unsigned count)
1505 unsigned long flags;
1507 /* If we're debugging, or KGDB has not connected, don't try
1508 * and print. */
1509 if (!kgdb_connected || atomic_read(&kgdb_active) != -1)
1510 return;
1512 local_irq_save(flags);
1513 kgdb_msg_write(s, count);
1514 local_irq_restore(flags);
1517 static struct console kgdbcons = {
1518 .name = "kgdb",
1519 .write = kgdb_console_write,
1520 .flags = CON_PRINTBUFFER | CON_ENABLED,
1521 .index = -1,
1524 #ifdef CONFIG_MAGIC_SYSRQ
1525 static void sysrq_handle_gdb(int key, struct tty_struct *tty)
1527 if (!kgdb_io_ops) {
1528 printk(KERN_CRIT "ERROR: No KGDB I/O module available\n");
1529 return;
1531 if (!kgdb_connected)
1532 printk(KERN_CRIT "Entering KGDB\n");
1534 kgdb_breakpoint();
1537 static struct sysrq_key_op sysrq_gdb_op = {
1538 .handler = sysrq_handle_gdb,
1539 .help_msg = "Gdb",
1540 .action_msg = "GDB",
1542 #endif
1544 static void kgdb_register_callbacks(void)
1546 if (!kgdb_io_module_registered) {
1547 kgdb_io_module_registered = 1;
1548 kgdb_arch_init();
1549 #ifdef CONFIG_MAGIC_SYSRQ
1550 register_sysrq_key('g', &sysrq_gdb_op);
1551 #endif
1552 if (kgdb_use_con && !kgdb_con_registered) {
1553 register_console(&kgdbcons);
1554 kgdb_con_registered = 1;
1559 static void kgdb_unregister_callbacks(void)
1562 * When this routine is called KGDB should unregister from the
1563 * panic handler and clean up, making sure it is not handling any
1564 * break exceptions at the time.
1566 if (kgdb_io_module_registered) {
1567 kgdb_io_module_registered = 0;
1568 kgdb_arch_exit();
1569 #ifdef CONFIG_MAGIC_SYSRQ
1570 unregister_sysrq_key('g', &sysrq_gdb_op);
1571 #endif
1572 if (kgdb_con_registered) {
1573 unregister_console(&kgdbcons);
1574 kgdb_con_registered = 0;
1579 static void kgdb_initial_breakpoint(void)
1581 kgdb_break_asap = 0;
1583 printk(KERN_CRIT "kgdb: Waiting for connection from remote gdb...\n");
1584 kgdb_breakpoint();
1588 * kgdb_register_io_module - register KGDB IO module
1589 * @new_kgdb_io_ops: the io ops vector
1591 * Register it with the KGDB core.
1593 int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
1595 int err;
1597 spin_lock(&kgdb_registration_lock);
1599 if (kgdb_io_ops) {
1600 spin_unlock(&kgdb_registration_lock);
1602 printk(KERN_ERR "kgdb: Another I/O driver is already "
1603 "registered with KGDB.\n");
1604 return -EBUSY;
1607 if (new_kgdb_io_ops->init) {
1608 err = new_kgdb_io_ops->init();
1609 if (err) {
1610 spin_unlock(&kgdb_registration_lock);
1611 return err;
1615 kgdb_io_ops = new_kgdb_io_ops;
1617 spin_unlock(&kgdb_registration_lock);
1619 printk(KERN_INFO "kgdb: Registered I/O driver %s.\n",
1620 new_kgdb_io_ops->name);
1622 /* Arm KGDB now. */
1623 kgdb_register_callbacks();
1625 if (kgdb_break_asap)
1626 kgdb_initial_breakpoint();
1628 return 0;
1630 EXPORT_SYMBOL_GPL(kgdb_register_io_module);
1633 * kkgdb_unregister_io_module - unregister KGDB IO module
1634 * @old_kgdb_io_ops: the io ops vector
1636 * Unregister it with the KGDB core.
1638 void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
1640 BUG_ON(kgdb_connected);
1643 * KGDB is no longer able to communicate out, so
1644 * unregister our callbacks and reset state.
1646 kgdb_unregister_callbacks();
1648 spin_lock(&kgdb_registration_lock);
1650 WARN_ON_ONCE(kgdb_io_ops != old_kgdb_io_ops);
1651 kgdb_io_ops = NULL;
1653 spin_unlock(&kgdb_registration_lock);
1655 printk(KERN_INFO
1656 "kgdb: Unregistered I/O driver %s, debugger disabled.\n",
1657 old_kgdb_io_ops->name);
1659 EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
1662 * kgdb_breakpoint - generate breakpoint exception
1664 * This function will generate a breakpoint exception. It is used at the
1665 * beginning of a program to sync up with a debugger and can be used
1666 * otherwise as a quick means to stop program execution and "break" into
1667 * the debugger.
1669 void kgdb_breakpoint(void)
1671 atomic_set(&kgdb_setting_breakpoint, 1);
1672 wmb(); /* Sync point before breakpoint */
1673 arch_kgdb_breakpoint();
1674 wmb(); /* Sync point after breakpoint */
1675 atomic_set(&kgdb_setting_breakpoint, 0);
1677 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
1679 static int __init opt_kgdb_wait(char *str)
1681 kgdb_break_asap = 1;
1683 if (kgdb_io_module_registered)
1684 kgdb_initial_breakpoint();
1686 return 0;
1689 early_param("kgdbwait", opt_kgdb_wait);