3 This kgdb will get called and will trap almost any kernel
4 fault WITHOUT BEING ARMED.
6 It is entered at boot time via "kgdb" in the boot string,
7 not "gdb". This entry occurs when the first setup on the
8 boot string is called, not sometime later. You will not
9 find a "waiting for gdb" on your console, as the console has
10 not yet been enabled at this time. (Note, this early stuff
11 is a bit fragile as the full trap table has yet to be
12 loaded, something I might address, sometime... So don't try
13 to look at memory that can not be reached, for example.
14 Once the full trap table is loaded this restriction goes
17 If you hard code it, you can put a breakpoint() as the FIRST
20 It does NOT use the serial driver, but if the serial driver
21 is loaded, it tells it to release the port to avoid
24 The threads stuff is not configurable, does not require
25 redirection of schedule() calls and does back track to the
26 first non schedule() caller on the info threads command. If
27 you switch to the thread, however, it will show it in the
28 switch code (as it should).
30 It is MUCH more aggressive and paranoid about grabbing the
31 other cpus on entry. It issues a "send_nmi_all_but_self()"
32 rather than depending on them to interrupt or hit an NMI
33 sometime in the distant future. If a cpu does not come to
34 the party, it will continue without it so all is not lost.
36 It does not have anything to do with IOCTL calls, but does
37 do the control-C thing.
39 There is a LOT of info in the patch which ends up in
40 .../Documentation/i386/kgdb/*
42 There is a nifty little thing call kgdb_ts() (kgdb time
43 stamp) which is a function you can code calls to which puts
44 some useful stuff in a circular buffer which can be examined
45 with the supplied gdb macros.
47 It also allows you do to do "p foobar(...)" i.e. to call a
48 function from gdb, just like gdb allows in program
51 In an SMP system, you can choose to "hold" any given set of
52 cpus. It also defaults to holding other cpus on single step
53 (this can be overridden).
55 This said, you can imagine my consternation when I found it
56 "lost it" on continues on 2.5. I found and fixed this this
57 early pm, a hold cpu on exit goof on my part.
59 Oh, and a final point, the configure options are more
60 extensive (the serial port is set up here, for example, (can
61 not wait for a command line to do this)). There is one to
62 do system call exit tests. This is VERY new and causes the
63 kernel to hit a hard "int 3" if a system call attempts to
64 exit with preempt count other than zero. This is a fault,
65 of course, but the current 2.5 is full of them so I don't
66 recommend turning this on.
72 From: Ingo Molnar <mingo@elte.hu>
74 this patch fixes a deprecated use of asm input operands. (and shuts up a
78 kgdb buffer overflow fix
80 From: George Anzinger <george@mvista.com>
86 From: Ingo Molnar <mingo@elte.hu>
88 this patch fixes a deprecated use of asm input operands. (and shuts up a
92 kgdb: CONFIG_DEBUG_INFO fix
94 From: Thomas Schlichter <schlicht@uni-mannheim.de>
96 that patch sets DEBUG_INFO to y by default, even if whether DEBUG_KERNEL nor
97 KGDB is enabled. The attached patch changes this to enable DEBUG_INFO by
98 default only if KGDB is enabled.
105 Fix x86_64 for kgdb. We forget why.
107 correct kgdb.txt Documentation link (against 2.6.1-rc1-mm2)
109 From: Jesper Juhl <juhl-lkml@dif.dk>
111 The help text for "config KGDB" in arch/i386/Kconfig refers to
112 Documentation/i386/kgdb.txt - the actual location is
113 Documentation/i386/kgdb/kgdb.txt - patch below to fix that.
116 kgdb: fix for recent gcc
119 arch/i386/kernel/traps.c:97: error: conflicting types for 'int3'
120 arch/i386/kernel/traps.c:77: error: previous declaration of 'int3' was here
121 arch/i386/kernel/traps.c:97: error: conflicting types for 'int3'
122 arch/i386/kernel/traps.c:77: error: previous declaration of 'int3' was here
123 arch/i386/kernel/traps.c:99: error: conflicting types for 'debug'
124 arch/i386/kernel/traps.c:75: error: previous declaration of 'debug' was here
125 arch/i386/kernel/traps.c:99: error: conflicting types for 'debug'
126 arch/i386/kernel/traps.c:75: error: previous declaration of 'debug' was here
132 arch/i386/kernel/kgdb_stub.c:1306: warning: 'time' might be used uninitialized in this function
133 arch/i386/kernel/kgdb_stub.c:1306: warning: 'dum' might be used uninitialized in this function
135 THREAD_SIZE fixes for kgdb
137 From: Matt Mackall <mpm@selenic.com>
139 Noticed the THREAD_SIZE clean-ups are in -mm now. Here are the missing
140 bits for kgdb, tested in -tiny with 4k stacks.
142 Fix stack overflow test for non-8k stacks
144 From: Matt Mackall <mpm@selenic.com>
146 This is needed to work properly with 4k and 16k stacks.
148 kgdb-ga.patch fix for i386 single-step into sysenter
150 From: Roland McGrath <roland@redhat.com>
152 Using kgdb-ga.patch from -mm, if userland single-steps (PTRACE_SINGLESTEP)
153 into the `sysenter' instruction, kgdb reports a bogus trap:
155 Program received signal SIGTRAP, Trace/breakpoint trap.
156 sysenter_past_esp () at arch/i386/kernel/entry.S:249
157 1: x/i $pc 0xc0106023 <sysenter_past_esp>: sti
160 The hackery in the "FIX_STACK" macro in entry.S changes the saved PC for a
161 the spurious kernel-mode debug trap when TF was set on user-mode execution
162 of `sysenter', so sysenter_past_esp is where it actually lies in this case.
163 The following patch removes the kgdb hiccup when userland
164 PTRACE_SINGLESTEP's into sysenter.
166 fix TRAP_BAD_SYSCALL_EXITS on i386
168 From: Andy Whitcroft <apw@shadowen.org>
170 We are not using the right offset name, nor the right address when checking
171 for a non-zero preempt count. Move to TI_preempt_count(%ebp).
173 Signed-off-by: Andy Whitcroft <apw@shadowen.org>
175 add TRAP_BAD_SYSCALL_EXITS config for i386
177 From: Andy Whitcroft <apw@shadowen.org>
179 There seems to be code recently added to -bk and thereby -mm which supports
180 extra debug for preempt on system call exit. Oddly there doesn't seem to
181 be configuration options to enable them. Below is a possible patch to
182 allow enabling this on i386. Sadly the most obvious menu to add this to is
183 the Kernel Hacking menu, but that is defined in architecture specific
184 configuration. If this makes sense I could patch the other arches?
186 Add a configuration option to allow enabling TRAP_BAD_SYSCALL_EXITS to the
189 Signed-off-by: Andy Whitcroft <apw@shadowen.org>
191 kgdb-is-incompatible-with-kprobes
199 Signed-off-by: Andrew Morton <akpm@osdl.org>
200 Index: linux-2.6.10/include/asm-i386/kgdb_local.h
201 ===================================================================
202 --- linux-2.6.10.orig/include/asm-i386/kgdb_local.h 2005-04-05 19:01:49.158500672 +0800
203 +++ linux-2.6.10/include/asm-i386/kgdb_local.h 2005-04-05 12:48:05.371600472 +0800
205 +#ifndef __KGDB_LOCAL
206 +#define ___KGDB_LOCAL
207 +#include <linux/config.h>
208 +#include <linux/types.h>
209 +#include <linux/serial.h>
210 +#include <linux/serialP.h>
211 +#include <linux/spinlock.h>
212 +#include <asm/processor.h>
213 +#include <asm/msr.h>
214 +#include <asm/kgdb.h>
217 +#ifdef CONFIG_KGDB_PORT
219 +#define PORT CONFIG_KGDB_PORT
222 +#ifdef CONFIG_KGDB_IRQ
224 +#define IRQ CONFIG_KGDB_IRQ
226 +#define SB_CLOCK 1843200
227 +#define SB_BASE (SB_CLOCK/16)
228 +#define SB_BAUD9600 SB_BASE/9600
229 +#define SB_BAUD192 SB_BASE/19200
230 +#define SB_BAUD384 SB_BASE/38400
231 +#define SB_BAUD576 SB_BASE/57600
232 +#define SB_BAUD1152 SB_BASE/115200
233 +#ifdef CONFIG_KGDB_9600BAUD
234 +#define SB_BAUD SB_BAUD9600
236 +#ifdef CONFIG_KGDB_19200BAUD
237 +#define SB_BAUD SB_BAUD192
239 +#ifdef CONFIG_KGDB_38400BAUD
240 +#define SB_BAUD SB_BAUD384
242 +#ifdef CONFIG_KGDB_57600BAUD
243 +#define SB_BAUD SB_BAUD576
245 +#ifdef CONFIG_KGDB_115200BAUD
246 +#define SB_BAUD SB_BAUD1152
249 +#define SB_BAUD SB_BAUD1152 /* Start with this if not given */
252 +#ifndef CONFIG_X86_TSC
254 +#define rdtsc(a,b) if (a++ > 10000){a = 0; b++;}
256 +#define rdtscll(s) s++
259 +#ifdef _raw_read_unlock /* must use a name that is "define"ed, not an inline */
263 +#define spin_lock _raw_spin_lock
264 +#define spin_trylock _raw_spin_trylock
265 +#define spin_unlock _raw_spin_unlock
268 +#undef spin_unlock_wait
269 +#define spin_unlock_wait(x) do { cpu_relax(); barrier();} \
270 + while(spin_is_locked(x))
273 +#define SB_MCR UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS
276 +#define SB_STATE { \
277 + magic: SSTATE_MAGIC, \
278 + baud_base: SB_BASE, \
282 + custom_divisor:SB_BAUD}
284 + magic: SERIAL_MAGIC, \
285 + port: PORT,0,FLAGS, \
287 + tty: (struct tty_struct *)&state, \
290 +extern void putDebugChar(int);
291 +/* RTAI support needs us to really stop/start interrupts */
293 +#define kgdb_sti() __asm__ __volatile__("sti": : :"memory")
294 +#define kgdb_cli() __asm__ __volatile__("cli": : :"memory")
295 +#define kgdb_local_save_flags(x) __asm__ __volatile__(\
296 + "pushfl ; popl %0":"=g" (x): /* no input */)
297 +#define kgdb_local_irq_restore(x) __asm__ __volatile__(\
298 + "pushl %0 ; popfl": \
299 + /* no output */ :"g" (x):"memory", "cc")
300 +#define kgdb_local_irq_save(x) kgdb_local_save_flags(x); kgdb_cli()
302 +#ifdef CONFIG_SERIAL
303 +extern void shutdown_for_kgdb(struct async_struct *info);
305 +#define INIT_KDEBUG putDebugChar("+");
306 +#endif /* __KGDB_LOCAL */
307 Index: linux-2.6.10/include/asm-i386/kgdb.h
308 ===================================================================
309 --- linux-2.6.10.orig/include/asm-i386/kgdb.h 2005-04-05 19:01:49.158500672 +0800
310 +++ linux-2.6.10/include/asm-i386/kgdb.h 2005-04-05 12:48:05.399596216 +0800
316 + * This file should not include ANY others. This makes it usable
317 + * most anywhere without the fear of include order or inclusion.
320 + * This file may be included all the time. It is only active if
321 + * CONFIG_KGDB is defined, otherwise it stubs out all the macros
322 + * and entry points.
324 +#if defined(CONFIG_KGDB) && !defined(__ASSEMBLY__)
326 +extern void breakpoint(void);
327 +#define INIT_KGDB_INTS kgdb_enable_ints()
330 +#define BREAKPOINT asm(" int $3")
333 + * GDB debug stub (or any debug stub) can point the 'linux_debug_hook'
334 + * pointer to its routine and it will be entered as the first thing
335 + * when a trap occurs.
337 + * Return values are, at present, undefined.
339 + * The debug hook routine does not necessarily return to its caller.
340 + * It has the register image and thus may choose to resume execution
341 + * anywhere it pleases.
345 +extern int kgdb_handle_exception(int trapno,
346 + int signo, int err_code, struct pt_regs *regs);
347 +extern int in_kgdb(struct pt_regs *regs);
349 +#ifdef CONFIG_KGDB_TS
350 +void kgdb_tstamp(int line, char *source, int data0, int data1);
352 + * This is the time stamp function. The macro adds the source info and
353 + * does a cast on the data to allow most any 32-bit value.
356 +#define kgdb_ts(data0,data1) kgdb_tstamp(__LINE__,__FILE__,(int)data0,(int)data1)
358 +#define kgdb_ts(data0,data1)
360 +#else /* CONFIG_KGDB && ! __ASSEMBLY__ ,stubs follow... */
364 +#define kgdb_ts(data0,data1)
366 +#define kgdb_handle_exception
368 +#define INIT_KGDB_INTS
371 Index: linux-2.6.10/include/asm-i386/bugs.h
372 ===================================================================
373 --- linux-2.6.10.orig/include/asm-i386/bugs.h 2004-12-25 05:34:01.000000000 +0800
374 +++ linux-2.6.10/include/asm-i386/bugs.h 2005-04-05 12:48:05.398596368 +0800
377 * include/asm-i386/bugs.h
379 - * Copyright (C) 1994 Linus Torvalds
380 + * Copyright (C) 1994 Linus Torvalds
382 * Cyrix stuff, June 1998 by:
383 * - Rafael R. Reilova (moved everything from head.S),
384 - * <rreilova@ececs.uc.edu>
385 + * <rreilova@ececs.uc.edu>
386 * - Channing Corn (tests & fixes),
387 * - Andrew D. Balsa (code cleanup).
390 #include <asm/processor.h>
391 #include <asm/i387.h>
396 + * Provied the command line "gdb" initial break
398 +int __init kgdb_initial_break(char * str)
406 +__setup("gdb",kgdb_initial_break);
408 static int __init no_halt(char *s)
410 boot_cpu_data.hlt_works_ok = 0;
413 /* If this fails, it means that any user program may lock the CPU hard. Too bad. */
414 if (res != 12345678) printk( "Buggy.\n" );
415 - else printk( "OK.\n" );
416 + else printk( "OK.\n" );
420 Index: linux-2.6.10/include/linux/serial_core.h
421 ===================================================================
422 --- linux-2.6.10.orig/include/linux/serial_core.h 2004-12-25 05:34:00.000000000 +0800
423 +++ linux-2.6.10/include/linux/serial_core.h 2005-04-05 12:48:05.367601080 +0800
425 unsigned char x_char; /* xon/xoff char */
426 unsigned char regshift; /* reg offset shift */
427 unsigned char iotype; /* io access style */
429 #define UPIO_PORT (0)
430 #define UPIO_HUB6 (1)
432 Index: linux-2.6.10/include/linux/dwarf2.h
433 ===================================================================
434 --- linux-2.6.10.orig/include/linux/dwarf2.h 2005-04-05 19:01:49.158500672 +0800
435 +++ linux-2.6.10/include/linux/dwarf2.h 2005-04-05 12:48:05.369600776 +0800
437 +/* Declarations and definitions of codes relating to the DWARF2 symbolic
438 + debugging information format.
439 + Copyright (C) 1992, 1993, 1995, 1996, 1997, 1999, 2000, 2001, 2002
440 + Free Software Foundation, Inc.
442 + Written by Gary Funck (gary@intrepid.com) The Ada Joint Program
443 + Office (AJPO), Florida State Unviversity and Silicon Graphics Inc.
444 + provided support for this effort -- June 21, 1995.
446 + Derived from the DWARF 1 implementation written by Ron Guilmette
447 + (rfg@netcom.com), November 1990.
449 + This file is part of GCC.
451 + GCC is free software; you can redistribute it and/or modify it under
452 + the terms of the GNU General Public License as published by the Free
453 + Software Foundation; either version 2, or (at your option) any later
456 + GCC is distributed in the hope that it will be useful, but WITHOUT
457 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
458 + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
459 + License for more details.
461 + You should have received a copy of the GNU General Public License
462 + along with GCC; see the file COPYING. If not, write to the Free
463 + Software Foundation, 59 Temple Place - Suite 330, Boston, MA
464 + 02111-1307, USA. */
466 +/* This file is derived from the DWARF specification (a public document)
467 + Revision 2.0.0 (July 27, 1993) developed by the UNIX International
468 + Programming Languages Special Interest Group (UI/PLSIG) and distributed
469 + by UNIX International. Copies of this specification are available from
470 + UNIX International, 20 Waterview Boulevard, Parsippany, NJ, 07054.
472 + This file also now contains definitions from the DWARF 3 specification. */
474 +/* This file is shared between GCC and GDB, and should not contain
477 +#ifndef _ELF_DWARF2_H
478 +#define _ELF_DWARF2_H
480 +/* Structure found in the .debug_line section. */
481 +#ifndef __ASSEMBLY__
484 + unsigned char li_length [4];
485 + unsigned char li_version [2];
486 + unsigned char li_prologue_length [4];
487 + unsigned char li_min_insn_length [1];
488 + unsigned char li_default_is_stmt [1];
489 + unsigned char li_line_base [1];
490 + unsigned char li_line_range [1];
491 + unsigned char li_opcode_base [1];
493 +DWARF2_External_LineInfo;
497 + unsigned long li_length;
498 + unsigned short li_version;
499 + unsigned int li_prologue_length;
500 + unsigned char li_min_insn_length;
501 + unsigned char li_default_is_stmt;
503 + unsigned char li_line_range;
504 + unsigned char li_opcode_base;
506 +DWARF2_Internal_LineInfo;
508 +/* Structure found in .debug_pubnames section. */
511 + unsigned char pn_length [4];
512 + unsigned char pn_version [2];
513 + unsigned char pn_offset [4];
514 + unsigned char pn_size [4];
516 +DWARF2_External_PubNames;
520 + unsigned long pn_length;
521 + unsigned short pn_version;
522 + unsigned long pn_offset;
523 + unsigned long pn_size;
525 +DWARF2_Internal_PubNames;
527 +/* Structure found in .debug_info section. */
530 + unsigned char cu_length [4];
531 + unsigned char cu_version [2];
532 + unsigned char cu_abbrev_offset [4];
533 + unsigned char cu_pointer_size [1];
535 +DWARF2_External_CompUnit;
539 + unsigned long cu_length;
540 + unsigned short cu_version;
541 + unsigned long cu_abbrev_offset;
542 + unsigned char cu_pointer_size;
544 +DWARF2_Internal_CompUnit;
548 + unsigned char ar_length [4];
549 + unsigned char ar_version [2];
550 + unsigned char ar_info_offset [4];
551 + unsigned char ar_pointer_size [1];
552 + unsigned char ar_segment_size [1];
554 +DWARF2_External_ARange;
558 + unsigned long ar_length;
559 + unsigned short ar_version;
560 + unsigned long ar_info_offset;
561 + unsigned char ar_pointer_size;
562 + unsigned char ar_segment_size;
564 +DWARF2_Internal_ARange;
566 +#define ENUM(name) enum name {
567 +#define IF_NOT_ASM(a) a
571 +#define IF_NOT_ASM(a)
576 +/* Tag names and codes. */
579 + DW_TAG_padding = 0x00 COMMA
580 + DW_TAG_array_type = 0x01 COMMA
581 + DW_TAG_class_type = 0x02 COMMA
582 + DW_TAG_entry_point = 0x03 COMMA
583 + DW_TAG_enumeration_type = 0x04 COMMA
584 + DW_TAG_formal_parameter = 0x05 COMMA
585 + DW_TAG_imported_declaration = 0x08 COMMA
586 + DW_TAG_label = 0x0a COMMA
587 + DW_TAG_lexical_block = 0x0b COMMA
588 + DW_TAG_member = 0x0d COMMA
589 + DW_TAG_pointer_type = 0x0f COMMA
590 + DW_TAG_reference_type = 0x10 COMMA
591 + DW_TAG_compile_unit = 0x11 COMMA
592 + DW_TAG_string_type = 0x12 COMMA
593 + DW_TAG_structure_type = 0x13 COMMA
594 + DW_TAG_subroutine_type = 0x15 COMMA
595 + DW_TAG_typedef = 0x16 COMMA
596 + DW_TAG_union_type = 0x17 COMMA
597 + DW_TAG_unspecified_parameters = 0x18 COMMA
598 + DW_TAG_variant = 0x19 COMMA
599 + DW_TAG_common_block = 0x1a COMMA
600 + DW_TAG_common_inclusion = 0x1b COMMA
601 + DW_TAG_inheritance = 0x1c COMMA
602 + DW_TAG_inlined_subroutine = 0x1d COMMA
603 + DW_TAG_module = 0x1e COMMA
604 + DW_TAG_ptr_to_member_type = 0x1f COMMA
605 + DW_TAG_set_type = 0x20 COMMA
606 + DW_TAG_subrange_type = 0x21 COMMA
607 + DW_TAG_with_stmt = 0x22 COMMA
608 + DW_TAG_access_declaration = 0x23 COMMA
609 + DW_TAG_base_type = 0x24 COMMA
610 + DW_TAG_catch_block = 0x25 COMMA
611 + DW_TAG_const_type = 0x26 COMMA
612 + DW_TAG_constant = 0x27 COMMA
613 + DW_TAG_enumerator = 0x28 COMMA
614 + DW_TAG_file_type = 0x29 COMMA
615 + DW_TAG_friend = 0x2a COMMA
616 + DW_TAG_namelist = 0x2b COMMA
617 + DW_TAG_namelist_item = 0x2c COMMA
618 + DW_TAG_packed_type = 0x2d COMMA
619 + DW_TAG_subprogram = 0x2e COMMA
620 + DW_TAG_template_type_param = 0x2f COMMA
621 + DW_TAG_template_value_param = 0x30 COMMA
622 + DW_TAG_thrown_type = 0x31 COMMA
623 + DW_TAG_try_block = 0x32 COMMA
624 + DW_TAG_variant_part = 0x33 COMMA
625 + DW_TAG_variable = 0x34 COMMA
626 + DW_TAG_volatile_type = 0x35 COMMA
628 + DW_TAG_dwarf_procedure = 0x36 COMMA
629 + DW_TAG_restrict_type = 0x37 COMMA
630 + DW_TAG_interface_type = 0x38 COMMA
631 + DW_TAG_namespace = 0x39 COMMA
632 + DW_TAG_imported_module = 0x3a COMMA
633 + DW_TAG_unspecified_type = 0x3b COMMA
634 + DW_TAG_partial_unit = 0x3c COMMA
635 + DW_TAG_imported_unit = 0x3d COMMA
636 + /* SGI/MIPS Extensions. */
637 + DW_TAG_MIPS_loop = 0x4081 COMMA
638 + /* GNU extensions. */
639 + DW_TAG_format_label = 0x4101 COMMA /* For FORTRAN 77 and Fortran 90. */
640 + DW_TAG_function_template = 0x4102 COMMA /* For C++. */
641 + DW_TAG_class_template = 0x4103 COMMA /* For C++. */
642 + DW_TAG_GNU_BINCL = 0x4104 COMMA
643 + DW_TAG_GNU_EINCL = 0x4105 COMMA
644 + /* Extensions for UPC. See: http://upc.gwu.edu/~upc. */
645 + DW_TAG_upc_shared_type = 0x8765 COMMA
646 + DW_TAG_upc_strict_type = 0x8766 COMMA
647 + DW_TAG_upc_relaxed_type = 0x8767
650 +#define DW_TAG_lo_user 0x4080
651 +#define DW_TAG_hi_user 0xffff
653 +/* Flag that tells whether entry has a child or not. */
654 +#define DW_children_no 0
655 +#define DW_children_yes 1
657 +/* Form names and codes. */
660 + DW_FORM_addr = 0x01 COMMA
661 + DW_FORM_block2 = 0x03 COMMA
662 + DW_FORM_block4 = 0x04 COMMA
663 + DW_FORM_data2 = 0x05 COMMA
664 + DW_FORM_data4 = 0x06 COMMA
665 + DW_FORM_data8 = 0x07 COMMA
666 + DW_FORM_string = 0x08 COMMA
667 + DW_FORM_block = 0x09 COMMA
668 + DW_FORM_block1 = 0x0a COMMA
669 + DW_FORM_data1 = 0x0b COMMA
670 + DW_FORM_flag = 0x0c COMMA
671 + DW_FORM_sdata = 0x0d COMMA
672 + DW_FORM_strp = 0x0e COMMA
673 + DW_FORM_udata = 0x0f COMMA
674 + DW_FORM_ref_addr = 0x10 COMMA
675 + DW_FORM_ref1 = 0x11 COMMA
676 + DW_FORM_ref2 = 0x12 COMMA
677 + DW_FORM_ref4 = 0x13 COMMA
678 + DW_FORM_ref8 = 0x14 COMMA
679 + DW_FORM_ref_udata = 0x15 COMMA
680 + DW_FORM_indirect = 0x16
683 +/* Attribute names and codes. */
685 +ENUM(dwarf_attribute)
687 + DW_AT_sibling = 0x01 COMMA
688 + DW_AT_location = 0x02 COMMA
689 + DW_AT_name = 0x03 COMMA
690 + DW_AT_ordering = 0x09 COMMA
691 + DW_AT_subscr_data = 0x0a COMMA
692 + DW_AT_byte_size = 0x0b COMMA
693 + DW_AT_bit_offset = 0x0c COMMA
694 + DW_AT_bit_size = 0x0d COMMA
695 + DW_AT_element_list = 0x0f COMMA
696 + DW_AT_stmt_list = 0x10 COMMA
697 + DW_AT_low_pc = 0x11 COMMA
698 + DW_AT_high_pc = 0x12 COMMA
699 + DW_AT_language = 0x13 COMMA
700 + DW_AT_member = 0x14 COMMA
701 + DW_AT_discr = 0x15 COMMA
702 + DW_AT_discr_value = 0x16 COMMA
703 + DW_AT_visibility = 0x17 COMMA
704 + DW_AT_import = 0x18 COMMA
705 + DW_AT_string_length = 0x19 COMMA
706 + DW_AT_common_reference = 0x1a COMMA
707 + DW_AT_comp_dir = 0x1b COMMA
708 + DW_AT_const_value = 0x1c COMMA
709 + DW_AT_containing_type = 0x1d COMMA
710 + DW_AT_default_value = 0x1e COMMA
711 + DW_AT_inline = 0x20 COMMA
712 + DW_AT_is_optional = 0x21 COMMA
713 + DW_AT_lower_bound = 0x22 COMMA
714 + DW_AT_producer = 0x25 COMMA
715 + DW_AT_prototyped = 0x27 COMMA
716 + DW_AT_return_addr = 0x2a COMMA
717 + DW_AT_start_scope = 0x2c COMMA
718 + DW_AT_stride_size = 0x2e COMMA
719 + DW_AT_upper_bound = 0x2f COMMA
720 + DW_AT_abstract_origin = 0x31 COMMA
721 + DW_AT_accessibility = 0x32 COMMA
722 + DW_AT_address_class = 0x33 COMMA
723 + DW_AT_artificial = 0x34 COMMA
724 + DW_AT_base_types = 0x35 COMMA
725 + DW_AT_calling_convention = 0x36 COMMA
726 + DW_AT_count = 0x37 COMMA
727 + DW_AT_data_member_location = 0x38 COMMA
728 + DW_AT_decl_column = 0x39 COMMA
729 + DW_AT_decl_file = 0x3a COMMA
730 + DW_AT_decl_line = 0x3b COMMA
731 + DW_AT_declaration = 0x3c COMMA
732 + DW_AT_discr_list = 0x3d COMMA
733 + DW_AT_encoding = 0x3e COMMA
734 + DW_AT_external = 0x3f COMMA
735 + DW_AT_frame_base = 0x40 COMMA
736 + DW_AT_friend = 0x41 COMMA
737 + DW_AT_identifier_case = 0x42 COMMA
738 + DW_AT_macro_info = 0x43 COMMA
739 + DW_AT_namelist_items = 0x44 COMMA
740 + DW_AT_priority = 0x45 COMMA
741 + DW_AT_segment = 0x46 COMMA
742 + DW_AT_specification = 0x47 COMMA
743 + DW_AT_static_link = 0x48 COMMA
744 + DW_AT_type = 0x49 COMMA
745 + DW_AT_use_location = 0x4a COMMA
746 + DW_AT_variable_parameter = 0x4b COMMA
747 + DW_AT_virtuality = 0x4c COMMA
748 + DW_AT_vtable_elem_location = 0x4d COMMA
749 + /* DWARF 3 values. */
750 + DW_AT_allocated = 0x4e COMMA
751 + DW_AT_associated = 0x4f COMMA
752 + DW_AT_data_location = 0x50 COMMA
753 + DW_AT_stride = 0x51 COMMA
754 + DW_AT_entry_pc = 0x52 COMMA
755 + DW_AT_use_UTF8 = 0x53 COMMA
756 + DW_AT_extension = 0x54 COMMA
757 + DW_AT_ranges = 0x55 COMMA
758 + DW_AT_trampoline = 0x56 COMMA
759 + DW_AT_call_column = 0x57 COMMA
760 + DW_AT_call_file = 0x58 COMMA
761 + DW_AT_call_line = 0x59 COMMA
762 + /* SGI/MIPS extensions. */
763 + DW_AT_MIPS_fde = 0x2001 COMMA
764 + DW_AT_MIPS_loop_begin = 0x2002 COMMA
765 + DW_AT_MIPS_tail_loop_begin = 0x2003 COMMA
766 + DW_AT_MIPS_epilog_begin = 0x2004 COMMA
767 + DW_AT_MIPS_loop_unroll_factor = 0x2005 COMMA
768 + DW_AT_MIPS_software_pipeline_depth = 0x2006 COMMA
769 + DW_AT_MIPS_linkage_name = 0x2007 COMMA
770 + DW_AT_MIPS_stride = 0x2008 COMMA
771 + DW_AT_MIPS_abstract_name = 0x2009 COMMA
772 + DW_AT_MIPS_clone_origin = 0x200a COMMA
773 + DW_AT_MIPS_has_inlines = 0x200b COMMA
774 + /* GNU extensions. */
775 + DW_AT_sf_names = 0x2101 COMMA
776 + DW_AT_src_info = 0x2102 COMMA
777 + DW_AT_mac_info = 0x2103 COMMA
778 + DW_AT_src_coords = 0x2104 COMMA
779 + DW_AT_body_begin = 0x2105 COMMA
780 + DW_AT_body_end = 0x2106 COMMA
781 + DW_AT_GNU_vector = 0x2107 COMMA
782 + /* VMS extensions. */
783 + DW_AT_VMS_rtnbeg_pd_address = 0x2201 COMMA
784 + /* UPC extension. */
785 + DW_AT_upc_threads_scaled = 0x3210
788 +#define DW_AT_lo_user 0x2000 /* Implementation-defined range start. */
789 +#define DW_AT_hi_user 0x3ff0 /* Implementation-defined range end. */
791 +/* Location atom names and codes. */
792 +ENUM(dwarf_location_atom)
794 + DW_OP_addr = 0x03 COMMA
795 + DW_OP_deref = 0x06 COMMA
796 + DW_OP_const1u = 0x08 COMMA
797 + DW_OP_const1s = 0x09 COMMA
798 + DW_OP_const2u = 0x0a COMMA
799 + DW_OP_const2s = 0x0b COMMA
800 + DW_OP_const4u = 0x0c COMMA
801 + DW_OP_const4s = 0x0d COMMA
802 + DW_OP_const8u = 0x0e COMMA
803 + DW_OP_const8s = 0x0f COMMA
804 + DW_OP_constu = 0x10 COMMA
805 + DW_OP_consts = 0x11 COMMA
806 + DW_OP_dup = 0x12 COMMA
807 + DW_OP_drop = 0x13 COMMA
808 + DW_OP_over = 0x14 COMMA
809 + DW_OP_pick = 0x15 COMMA
810 + DW_OP_swap = 0x16 COMMA
811 + DW_OP_rot = 0x17 COMMA
812 + DW_OP_xderef = 0x18 COMMA
813 + DW_OP_abs = 0x19 COMMA
814 + DW_OP_and = 0x1a COMMA
815 + DW_OP_div = 0x1b COMMA
816 + DW_OP_minus = 0x1c COMMA
817 + DW_OP_mod = 0x1d COMMA
818 + DW_OP_mul = 0x1e COMMA
819 + DW_OP_neg = 0x1f COMMA
820 + DW_OP_not = 0x20 COMMA
821 + DW_OP_or = 0x21 COMMA
822 + DW_OP_plus = 0x22 COMMA
823 + DW_OP_plus_uconst = 0x23 COMMA
824 + DW_OP_shl = 0x24 COMMA
825 + DW_OP_shr = 0x25 COMMA
826 + DW_OP_shra = 0x26 COMMA
827 + DW_OP_xor = 0x27 COMMA
828 + DW_OP_bra = 0x28 COMMA
829 + DW_OP_eq = 0x29 COMMA
830 + DW_OP_ge = 0x2a COMMA
831 + DW_OP_gt = 0x2b COMMA
832 + DW_OP_le = 0x2c COMMA
833 + DW_OP_lt = 0x2d COMMA
834 + DW_OP_ne = 0x2e COMMA
835 + DW_OP_skip = 0x2f COMMA
836 + DW_OP_lit0 = 0x30 COMMA
837 + DW_OP_lit1 = 0x31 COMMA
838 + DW_OP_lit2 = 0x32 COMMA
839 + DW_OP_lit3 = 0x33 COMMA
840 + DW_OP_lit4 = 0x34 COMMA
841 + DW_OP_lit5 = 0x35 COMMA
842 + DW_OP_lit6 = 0x36 COMMA
843 + DW_OP_lit7 = 0x37 COMMA
844 + DW_OP_lit8 = 0x38 COMMA
845 + DW_OP_lit9 = 0x39 COMMA
846 + DW_OP_lit10 = 0x3a COMMA
847 + DW_OP_lit11 = 0x3b COMMA
848 + DW_OP_lit12 = 0x3c COMMA
849 + DW_OP_lit13 = 0x3d COMMA
850 + DW_OP_lit14 = 0x3e COMMA
851 + DW_OP_lit15 = 0x3f COMMA
852 + DW_OP_lit16 = 0x40 COMMA
853 + DW_OP_lit17 = 0x41 COMMA
854 + DW_OP_lit18 = 0x42 COMMA
855 + DW_OP_lit19 = 0x43 COMMA
856 + DW_OP_lit20 = 0x44 COMMA
857 + DW_OP_lit21 = 0x45 COMMA
858 + DW_OP_lit22 = 0x46 COMMA
859 + DW_OP_lit23 = 0x47 COMMA
860 + DW_OP_lit24 = 0x48 COMMA
861 + DW_OP_lit25 = 0x49 COMMA
862 + DW_OP_lit26 = 0x4a COMMA
863 + DW_OP_lit27 = 0x4b COMMA
864 + DW_OP_lit28 = 0x4c COMMA
865 + DW_OP_lit29 = 0x4d COMMA
866 + DW_OP_lit30 = 0x4e COMMA
867 + DW_OP_lit31 = 0x4f COMMA
868 + DW_OP_reg0 = 0x50 COMMA
869 + DW_OP_reg1 = 0x51 COMMA
870 + DW_OP_reg2 = 0x52 COMMA
871 + DW_OP_reg3 = 0x53 COMMA
872 + DW_OP_reg4 = 0x54 COMMA
873 + DW_OP_reg5 = 0x55 COMMA
874 + DW_OP_reg6 = 0x56 COMMA
875 + DW_OP_reg7 = 0x57 COMMA
876 + DW_OP_reg8 = 0x58 COMMA
877 + DW_OP_reg9 = 0x59 COMMA
878 + DW_OP_reg10 = 0x5a COMMA
879 + DW_OP_reg11 = 0x5b COMMA
880 + DW_OP_reg12 = 0x5c COMMA
881 + DW_OP_reg13 = 0x5d COMMA
882 + DW_OP_reg14 = 0x5e COMMA
883 + DW_OP_reg15 = 0x5f COMMA
884 + DW_OP_reg16 = 0x60 COMMA
885 + DW_OP_reg17 = 0x61 COMMA
886 + DW_OP_reg18 = 0x62 COMMA
887 + DW_OP_reg19 = 0x63 COMMA
888 + DW_OP_reg20 = 0x64 COMMA
889 + DW_OP_reg21 = 0x65 COMMA
890 + DW_OP_reg22 = 0x66 COMMA
891 + DW_OP_reg23 = 0x67 COMMA
892 + DW_OP_reg24 = 0x68 COMMA
893 + DW_OP_reg25 = 0x69 COMMA
894 + DW_OP_reg26 = 0x6a COMMA
895 + DW_OP_reg27 = 0x6b COMMA
896 + DW_OP_reg28 = 0x6c COMMA
897 + DW_OP_reg29 = 0x6d COMMA
898 + DW_OP_reg30 = 0x6e COMMA
899 + DW_OP_reg31 = 0x6f COMMA
900 + DW_OP_breg0 = 0x70 COMMA
901 + DW_OP_breg1 = 0x71 COMMA
902 + DW_OP_breg2 = 0x72 COMMA
903 + DW_OP_breg3 = 0x73 COMMA
904 + DW_OP_breg4 = 0x74 COMMA
905 + DW_OP_breg5 = 0x75 COMMA
906 + DW_OP_breg6 = 0x76 COMMA
907 + DW_OP_breg7 = 0x77 COMMA
908 + DW_OP_breg8 = 0x78 COMMA
909 + DW_OP_breg9 = 0x79 COMMA
910 + DW_OP_breg10 = 0x7a COMMA
911 + DW_OP_breg11 = 0x7b COMMA
912 + DW_OP_breg12 = 0x7c COMMA
913 + DW_OP_breg13 = 0x7d COMMA
914 + DW_OP_breg14 = 0x7e COMMA
915 + DW_OP_breg15 = 0x7f COMMA
916 + DW_OP_breg16 = 0x80 COMMA
917 + DW_OP_breg17 = 0x81 COMMA
918 + DW_OP_breg18 = 0x82 COMMA
919 + DW_OP_breg19 = 0x83 COMMA
920 + DW_OP_breg20 = 0x84 COMMA
921 + DW_OP_breg21 = 0x85 COMMA
922 + DW_OP_breg22 = 0x86 COMMA
923 + DW_OP_breg23 = 0x87 COMMA
924 + DW_OP_breg24 = 0x88 COMMA
925 + DW_OP_breg25 = 0x89 COMMA
926 + DW_OP_breg26 = 0x8a COMMA
927 + DW_OP_breg27 = 0x8b COMMA
928 + DW_OP_breg28 = 0x8c COMMA
929 + DW_OP_breg29 = 0x8d COMMA
930 + DW_OP_breg30 = 0x8e COMMA
931 + DW_OP_breg31 = 0x8f COMMA
932 + DW_OP_regx = 0x90 COMMA
933 + DW_OP_fbreg = 0x91 COMMA
934 + DW_OP_bregx = 0x92 COMMA
935 + DW_OP_piece = 0x93 COMMA
936 + DW_OP_deref_size = 0x94 COMMA
937 + DW_OP_xderef_size = 0x95 COMMA
938 + DW_OP_nop = 0x96 COMMA
939 + /* DWARF 3 extensions. */
940 + DW_OP_push_object_address = 0x97 COMMA
941 + DW_OP_call2 = 0x98 COMMA
942 + DW_OP_call4 = 0x99 COMMA
943 + DW_OP_call_ref = 0x9a COMMA
944 + /* GNU extensions. */
945 + DW_OP_GNU_push_tls_address = 0xe0
948 +#define DW_OP_lo_user 0xe0 /* Implementation-defined range start. */
949 +#define DW_OP_hi_user 0xff /* Implementation-defined range end. */
951 +/* Type encodings. */
954 + DW_ATE_void = 0x0 COMMA
955 + DW_ATE_address = 0x1 COMMA
956 + DW_ATE_boolean = 0x2 COMMA
957 + DW_ATE_complex_float = 0x3 COMMA
958 + DW_ATE_float = 0x4 COMMA
959 + DW_ATE_signed = 0x5 COMMA
960 + DW_ATE_signed_char = 0x6 COMMA
961 + DW_ATE_unsigned = 0x7 COMMA
962 + DW_ATE_unsigned_char = 0x8 COMMA
964 + DW_ATE_imaginary_float = 0x9
967 +#define DW_ATE_lo_user 0x80
968 +#define DW_ATE_hi_user 0xff
970 +/* Array ordering names and codes. */
971 +ENUM(dwarf_array_dim_ordering)
973 + DW_ORD_row_major = 0 COMMA
974 + DW_ORD_col_major = 1
977 +/* Access attribute. */
978 +ENUM(dwarf_access_attribute)
980 + DW_ACCESS_public = 1 COMMA
981 + DW_ACCESS_protected = 2 COMMA
982 + DW_ACCESS_private = 3
986 +ENUM(dwarf_visibility_attribute)
988 + DW_VIS_local = 1 COMMA
989 + DW_VIS_exported = 2 COMMA
990 + DW_VIS_qualified = 3
994 +ENUM(dwarf_virtuality_attribute)
996 + DW_VIRTUALITY_none = 0 COMMA
997 + DW_VIRTUALITY_virtual = 1 COMMA
998 + DW_VIRTUALITY_pure_virtual = 2
1001 +/* Case sensitivity. */
1002 +ENUM(dwarf_id_case)
1004 + DW_ID_case_sensitive = 0 COMMA
1005 + DW_ID_up_case = 1 COMMA
1006 + DW_ID_down_case = 2 COMMA
1007 + DW_ID_case_insensitive = 3
1010 +/* Calling convention. */
1011 +ENUM(dwarf_calling_convention)
1013 + DW_CC_normal = 0x1 COMMA
1014 + DW_CC_program = 0x2 COMMA
1015 + DW_CC_nocall = 0x3
1018 +#define DW_CC_lo_user 0x40
1019 +#define DW_CC_hi_user 0xff
1021 +/* Inline attribute. */
1022 +ENUM(dwarf_inline_attribute)
1024 + DW_INL_not_inlined = 0 COMMA
1025 + DW_INL_inlined = 1 COMMA
1026 + DW_INL_declared_not_inlined = 2 COMMA
1027 + DW_INL_declared_inlined = 3
1030 +/* Discriminant lists. */
1031 +ENUM(dwarf_discrim_list)
1033 + DW_DSC_label = 0 COMMA
1037 +/* Line number opcodes. */
1038 +ENUM(dwarf_line_number_ops)
1040 + DW_LNS_extended_op = 0 COMMA
1041 + DW_LNS_copy = 1 COMMA
1042 + DW_LNS_advance_pc = 2 COMMA
1043 + DW_LNS_advance_line = 3 COMMA
1044 + DW_LNS_set_file = 4 COMMA
1045 + DW_LNS_set_column = 5 COMMA
1046 + DW_LNS_negate_stmt = 6 COMMA
1047 + DW_LNS_set_basic_block = 7 COMMA
1048 + DW_LNS_const_add_pc = 8 COMMA
1049 + DW_LNS_fixed_advance_pc = 9 COMMA
1051 + DW_LNS_set_prologue_end = 10 COMMA
1052 + DW_LNS_set_epilogue_begin = 11 COMMA
1053 + DW_LNS_set_isa = 12
1056 +/* Line number extended opcodes. */
1057 +ENUM(dwarf_line_number_x_ops)
1059 + DW_LNE_end_sequence = 1 COMMA
1060 + DW_LNE_set_address = 2 COMMA
1061 + DW_LNE_define_file = 3
1064 +/* Call frame information. */
1065 +ENUM(dwarf_call_frame_info)
1067 + DW_CFA_advance_loc = 0x40 COMMA
1068 + DW_CFA_offset = 0x80 COMMA
1069 + DW_CFA_restore = 0xc0 COMMA
1070 + DW_CFA_nop = 0x00 COMMA
1071 + DW_CFA_set_loc = 0x01 COMMA
1072 + DW_CFA_advance_loc1 = 0x02 COMMA
1073 + DW_CFA_advance_loc2 = 0x03 COMMA
1074 + DW_CFA_advance_loc4 = 0x04 COMMA
1075 + DW_CFA_offset_extended = 0x05 COMMA
1076 + DW_CFA_restore_extended = 0x06 COMMA
1077 + DW_CFA_undefined = 0x07 COMMA
1078 + DW_CFA_same_value = 0x08 COMMA
1079 + DW_CFA_register = 0x09 COMMA
1080 + DW_CFA_remember_state = 0x0a COMMA
1081 + DW_CFA_restore_state = 0x0b COMMA
1082 + DW_CFA_def_cfa = 0x0c COMMA
1083 + DW_CFA_def_cfa_register = 0x0d COMMA
1084 + DW_CFA_def_cfa_offset = 0x0e COMMA
1087 + DW_CFA_def_cfa_expression = 0x0f COMMA
1088 + DW_CFA_expression = 0x10 COMMA
1089 + DW_CFA_offset_extended_sf = 0x11 COMMA
1090 + DW_CFA_def_cfa_sf = 0x12 COMMA
1091 + DW_CFA_def_cfa_offset_sf = 0x13 COMMA
1093 + /* SGI/MIPS specific. */
1094 + DW_CFA_MIPS_advance_loc8 = 0x1d COMMA
1096 + /* GNU extensions. */
1097 + DW_CFA_GNU_window_save = 0x2d COMMA
1098 + DW_CFA_GNU_args_size = 0x2e COMMA
1099 + DW_CFA_GNU_negative_offset_extended = 0x2f
1102 +#define DW_CIE_ID 0xffffffff
1103 +#define DW_CIE_VERSION 1
1105 +#define DW_CFA_extended 0
1106 +#define DW_CFA_lo_user 0x1c
1107 +#define DW_CFA_hi_user 0x3f
1109 +#define DW_CHILDREN_no 0x00
1110 +#define DW_CHILDREN_yes 0x01
1112 +#define DW_ADDR_none 0
1114 +/* Source language names and codes. */
1115 +ENUM(dwarf_source_language)
1117 + DW_LANG_C89 = 0x0001 COMMA
1118 + DW_LANG_C = 0x0002 COMMA
1119 + DW_LANG_Ada83 = 0x0003 COMMA
1120 + DW_LANG_C_plus_plus = 0x0004 COMMA
1121 + DW_LANG_Cobol74 = 0x0005 COMMA
1122 + DW_LANG_Cobol85 = 0x0006 COMMA
1123 + DW_LANG_Fortran77 = 0x0007 COMMA
1124 + DW_LANG_Fortran90 = 0x0008 COMMA
1125 + DW_LANG_Pascal83 = 0x0009 COMMA
1126 + DW_LANG_Modula2 = 0x000a COMMA
1127 + DW_LANG_Java = 0x000b COMMA
1129 + DW_LANG_C99 = 0x000c COMMA
1130 + DW_LANG_Ada95 = 0x000d COMMA
1131 + DW_LANG_Fortran95 = 0x000e COMMA
1133 + DW_LANG_Mips_Assembler = 0x8001 COMMA
1135 + DW_LANG_Upc = 0x8765
1138 +#define DW_LANG_lo_user 0x8000 /* Implementation-defined range start. */
1139 +#define DW_LANG_hi_user 0xffff /* Implementation-defined range start. */
1141 +/* Names and codes for macro information. */
1142 +ENUM(dwarf_macinfo_record_type)
1144 + DW_MACINFO_define = 1 COMMA
1145 + DW_MACINFO_undef = 2 COMMA
1146 + DW_MACINFO_start_file = 3 COMMA
1147 + DW_MACINFO_end_file = 4 COMMA
1148 + DW_MACINFO_vendor_ext = 255
1151 +/* @@@ For use with GNU frame unwind information. */
1153 +#define DW_EH_PE_absptr 0x00
1154 +#define DW_EH_PE_omit 0xff
1156 +#define DW_EH_PE_uleb128 0x01
1157 +#define DW_EH_PE_udata2 0x02
1158 +#define DW_EH_PE_udata4 0x03
1159 +#define DW_EH_PE_udata8 0x04
1160 +#define DW_EH_PE_sleb128 0x09
1161 +#define DW_EH_PE_sdata2 0x0A
1162 +#define DW_EH_PE_sdata4 0x0B
1163 +#define DW_EH_PE_sdata8 0x0C
1164 +#define DW_EH_PE_signed 0x08
1166 +#define DW_EH_PE_pcrel 0x10
1167 +#define DW_EH_PE_textrel 0x20
1168 +#define DW_EH_PE_datarel 0x30
1169 +#define DW_EH_PE_funcrel 0x40
1170 +#define DW_EH_PE_aligned 0x50
1172 +#define DW_EH_PE_indirect 0x80
1174 +#endif /* _ELF_DWARF2_H */
1175 Index: linux-2.6.10/include/linux/spinlock.h
1176 ===================================================================
1177 --- linux-2.6.10.orig/include/linux/spinlock.h 2005-03-31 15:35:27.000000000 +0800
1178 +++ linux-2.6.10/include/linux/spinlock.h 2005-04-05 12:48:05.365601384 +0800
1181 #include <asm/processor.h> /* for cpu relax */
1182 #include <asm/system.h>
1184 +#include <asm/current.h>
1185 +#define SET_WHO(x, him) (x)->who = him;
1187 +#define SET_WHO(x, him)
1191 * Must define these before including other files, inline functions need them
1197 + struct task_struct *who;
1200 #define SPIN_LOCK_UNLOCKED (spinlock_t) { SPINLOCK_MAGIC, 0, 10, __FILE__ , NULL, 0}
1203 (x)->module = __FILE__; \
1204 (x)->owner = NULL; \
1206 + SET_WHO(x, NULL) \
1209 #define CHECK_LOCK(x) \
1212 (x)->owner = __FILE__; \
1213 (x)->oline = __LINE__; \
1214 + SET_WHO(x, current) \
1217 /* without debugging, spin_is_locked on UP always says
1220 (x)->owner = __FILE__; \
1221 (x)->oline = __LINE__; \
1222 + SET_WHO(x, current) \
1226 Index: linux-2.6.10/include/linux/config.h
1227 ===================================================================
1228 --- linux-2.6.10.orig/include/linux/config.h 2005-03-31 15:35:27.000000000 +0800
1229 +++ linux-2.6.10/include/linux/config.h 2005-04-05 12:48:42.303985896 +0800
1231 #define _LINUX_CONFIG_H
1233 #include <linux/autoconf.h>
1234 +#if defined(__i386__) && !defined(IN_BOOTLOADER) && defined(CONFIG_KGDB)
1235 +#include <asm/kgdb.h>
1238 #if !defined (__KERNEL__) && !defined(__KERNGLUE__)
1239 #error including kernel header in userspace; use the glibc headers instead!
1241 Index: linux-2.6.10/include/linux/dwarf2-lang.h
1242 ===================================================================
1243 --- linux-2.6.10.orig/include/linux/dwarf2-lang.h 2005-04-05 19:01:49.158500672 +0800
1244 +++ linux-2.6.10/include/linux/dwarf2-lang.h 2005-04-05 12:48:05.370600624 +0800
1246 +#ifndef DWARF2_LANG
1247 +#define DWARF2_LANG
1248 +#include <linux/dwarf2.h>
1251 + * This is free software; you can redistribute it and/or modify it under
1252 + * the terms of the GNU General Public License as published by the Free
1253 + * Software Foundation; either version 2, or (at your option) any later
1257 + * This file defines macros that allow generation of DWARF debug records
1258 + * for asm files. This file is platform independent. Register numbers
1259 + * (which are about the only thing that is platform dependent) are to be
1260 + * supplied by a platform defined file.
1262 +#define DWARF_preamble() .section .debug_frame,"",@progbits
1264 + * This macro starts a debug frame section. The debug_frame describes
1265 + * where to find the registers that the enclosing function saved on
1268 + * ORD is use by the label generator and should be the same as what is
1269 + * passed to CFI_postamble.
1271 + * pc, pc register gdb ordinal.
1273 + * code_align this is the factor used to define locations or regions
1274 + * where the given definitions apply. If you use labels to define these
1275 + * this should be 1.
1277 + * data_align this is the factor used to define register offsets. If
1278 + * you use struct offset, this should be the size of the register in
1279 + * bytes or the negative of that. This is how it is used: you will
1280 + * define a register as the reference register, say the stack pointer,
1281 + * then you will say where a register is located relative to this
1282 + * reference registers value, say 40 for register 3 (the gdb register
1283 + * number). The <40> will be multiplied by <data_align> to define the
1284 + * byte offset of the given register (3, in this example). So if your
1285 + * <40> is the byte offset and the reference register points at the
1286 + * begining, you would want 1 for the data_offset. If <40> was the 40th
1287 + * 4-byte element in that structure you would want 4. And if your
1288 + * reference register points at the end of the structure you would want
1289 + * a negative data_align value(and you would have to do other math as
1293 +#define CFI_preamble(ORD, pc, code_align, data_align) \
1294 +.section .debug_frame,"",@progbits ; \
1295 +frame/**/_/**/ORD: \
1296 + .long end/**/_/**/ORD-start/**/_/**/ORD; \
1297 +start/**/_/**/ORD: \
1298 + .long DW_CIE_ID; \
1299 + .byte DW_CIE_VERSION; \
1301 + .uleb128 code_align; \
1302 + .sleb128 data_align; \
1306 + * After the above macro and prior to the CFI_postamble, you need to
1307 + * define the initial state. This starts with defining the reference
1308 + * register and, usually the pc. Here are some helper macros:
1311 +#define CFA_define_reference(reg, offset) \
1312 + .byte DW_CFA_def_cfa; \
1314 + .uleb128 (offset);
1316 +#define CFA_define_offset(reg, offset) \
1317 + .byte (DW_CFA_offset + reg); \
1318 + .uleb128 (offset);
1320 +#define CFI_postamble(ORD) \
1324 + * So now your code pushs stuff on the stack, you need a new location
1325 + * and the rules for what to do. This starts a running description of
1326 + * the call frame. You need to describe what changes with respect to
1327 + * the call registers as the location of the pc moves through the code.
1328 + * The following builds an FDE (fram descriptor entry?). Like the
1329 + * above, it has a preamble and a postamble. It also is tied to the CFI
1331 + * The first entry after the preamble must be the location in the code
1332 + * that the call frame is being described for.
1334 +#define FDE_preamble(ORD, fde_no, initial_address, length) \
1335 + .long FDE_end/**/_/**/fde_no-FDE_start/**/_/**/fde_no; \
1336 +FDE_start/**/_/**/fde_no: \
1337 + .long frame/**/_/**/ORD; \
1338 + .long initial_address; \
1341 +#define FDE_postamble(fde_no) \
1343 +FDE_end/**/_/**/fde_no:
1345 + * That done, you can now add registers, subtract registers, move the
1346 + * reference and even change the reference. You can also define a new
1347 + * area of code the info applies to. For discontinuous bits you should
1348 + * start a new FDE. You may have as many as you like.
1352 + * To advance the address by <bytes>
1355 +#define FDE_advance(bytes) \
1356 + .byte DW_CFA_advance_loc4 \
1362 + * With the above you can define all the register locations. But
1363 + * suppose the reference register moves... Takes the new offset NOT an
1364 + * increment. This is how esp is tracked if it is not saved.
1367 +#define CFA_define_cfa_offset(offset) \
1368 + .byte $DW_CFA_def_cfa_offset; \
1369 + .uleb128 (offset);
1371 + * Or suppose you want to use a different reference register...
1373 +#define CFA_define_cfa_register(reg) \
1374 + .byte DW_CFA_def_cfa_register; \
1378 Index: linux-2.6.10/kernel/pid.c
1379 ===================================================================
1380 --- linux-2.6.10.orig/kernel/pid.c 2005-03-31 15:35:27.000000000 +0800
1381 +++ linux-2.6.10/kernel/pid.c 2005-04-05 12:48:05.363601688 +0800
1383 * machine. From a minimum of 16 slots up to 4096 slots at one gigabyte or
1387 +int kgdb_pid_init_done; /* so we don't call prior to... */
1389 void __init pidhash_init(void)
1391 int i, j, pidhash_size;
1393 for (j = 0; j < pidhash_size; j++)
1394 INIT_HLIST_HEAD(&pid_hash[i][j]);
1397 + kgdb_pid_init_done++;
1401 void __init pidmap_init(void)
1402 Index: linux-2.6.10/kernel/sched.c
1403 ===================================================================
1404 --- linux-2.6.10.orig/kernel/sched.c 2005-03-31 15:57:21.000000000 +0800
1405 +++ linux-2.6.10/kernel/sched.c 2005-04-05 12:48:05.362601840 +0800
1406 @@ -2991,6 +2991,13 @@
1408 EXPORT_SYMBOL(set_user_nice);
1411 +struct task_struct *kgdb_get_idle(int this_cpu)
1413 + return cpu_rq(this_cpu)->idle;
1417 #ifdef __ARCH_WANT_SYS_NICE
1420 Index: linux-2.6.10/Documentation/i386/kgdb/gdbinit
1421 ===================================================================
1422 --- linux-2.6.10.orig/Documentation/i386/kgdb/gdbinit 2005-04-05 19:01:49.158500672 +0800
1423 +++ linux-2.6.10/Documentation/i386/kgdb/gdbinit 2005-04-05 12:48:05.263616888 +0800
1425 +shell echo -e "\003" >/dev/ttyS0
1426 +set remotebaud 38400
1427 +target remote /dev/ttyS0
1430 +printf "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n", $eax, $ebx, $ecx, $edx
1431 +printf "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n", $esi, $edi, $ebp, $esp
1436 +printf "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n", $eax, $ebx, $ecx, $edx
1437 +printf "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n", $esi, $edi, $ebp, $esp
1439 Index: linux-2.6.10/Documentation/i386/kgdb/kgdb.txt
1440 ===================================================================
1441 --- linux-2.6.10.orig/Documentation/i386/kgdb/kgdb.txt 2005-04-05 19:01:49.158500672 +0800
1442 +++ linux-2.6.10/Documentation/i386/kgdb/kgdb.txt 2005-04-05 12:48:05.271615672 +0800
1444 +Last edit: <20030806.1637.12>
1445 +This file has information specific to the i386 kgdb option. Other
1446 +platforms with the kgdb option may behave in a similar fashion.
1451 +This version was made against the 2.6.0-test2 kernel. We have made the
1454 +- The getthread() code in the stub calls find_task_by_pid(). It fails
1455 + if we are early in the bring up such that the pid arrays have yet to
1456 + be allocated. We have added a line to kernel/pid.c to make
1457 + "kgdb_pid_init_done" true once the arrays are allocated. This way the
1458 + getthread() code knows not to call. This is only used by the thread
1459 + debugging stuff and threads will not yet exist at this point in the
1462 +- For some reason, gdb was not asking for a new thread list when the
1463 + "info thread" command was given. We changed to the newer version of
1464 + the thread info command and gdb now seems to ask when needed. Result,
1465 + we now get all threads in the thread list.
1467 +- We now respond to the ThreadExtraInfo request from gdb with the thread
1468 + name from task_struct .comm. This then appears in the thread list.
1469 + Thoughts on additional options for this are welcome. Things such as
1470 + "has BKL" and "Preempted" come to mind. I think we could have a flag
1471 + word that could enable different bits of info here.
1473 +- We now honor, sort of, the C and S commands. These are continue and
1474 + single set after delivering a signal. We ignore the signal and do the
1475 + requested action. This only happens when we told gdb that a signal
1476 + was the reason for entry, which is only done on memory faults. The
1477 + result is that you can now continue into the Oops.
1479 +- We changed the -g to -gdwarf-2. This seems to be the same as -ggdb,
1480 + but it is more exact on what language to use.
1482 +- We added two dwarf2 include files and a bit of code at the end of
1483 + entry.S. This does not yet work, so it is disabled. Still we want to
1484 + keep track of the code and "maybe" someone out there can fix it.
1486 +- Randy Dunlap sent some fix ups for this file which are now merged.
1488 +- Hugh Dickins sent a fix to a bit of code in traps.c that prevents a
1489 + compiler warning if CONFIG_KGDB is off (now who would do that :).
1491 +- Andrew Morton sent a fix for the serial driver which is now merged.
1493 +- Andrew also sent a change to the stub around the cpu managment code
1494 + which is also merged.
1496 +- Andrew also sent a patch to make "f" as well as "g" work as SysRq
1497 + commands to enter kgdb, merged.
1499 +- If CONFIG_KGDB and CONFIG_DEBUG_SPINLOCKS are both set we added a
1500 + "who" field to the spinlock data struct. This is filled with
1501 + "current" when ever the spinlock suceeds. Useful if you want to know
1504 +_ And last, but not least, we fixed the "get_cu" macro to properly get
1505 + the current value of "current".
1510 +We are starting to align with the sourceforge version, at least in
1511 +commands. To this end, the boot command string to start kgdb at
1512 +boot time has been changed from "kgdb" to "gdb".
1514 +Andrew Morton sent a couple of patches which are now included as follows:
1515 +1.) We now return a flag to the interrupt handler.
1516 +2.) We no longer use smp_num_cpus (a conflict with the lock meter).
1517 +3.) And from William Lee Irwin III <wli@holomorphy.com> code to make
1518 + sure high-mem is set up before we attempt to register our interrupt
1520 +We now include asm/kgdb.h from config.h so you will most likely never
1521 +have to include it. It also 'NULLS' the kgdb macros you might have in
1522 +your code when CONFIG_KGDB is not defined. This allows you to just
1523 +turn off CONFIG_KGDB to turn off all the kgdb_ts() calls and such.
1524 +This include is conditioned on the machine being an x86 so as to not
1525 +mess with other archs.
1528 +This is currently the version for the 2.4.18 (and beyond?) kernel.
1530 +We have several new "features" beginning with this version:
1532 +1.) Kgdb now syncs the "other" CPUs with a cross-CPU NMI. No more
1533 + waiting and it will pull that guy out of an IRQ off spin lock :)
1535 +2.) We doctored up the code that tells where a task is waiting and
1536 + included it so that the "info thread" command will show a bit more
1537 + than "schedule()". Try it...
1539 +3.) Added the ability to call a function from gdb. All the standard gdb
1540 + issues apply, i.e. if you hit a breakpoint in the function, you are
1541 + not allowed to call another (gdb limitation, not kgdb). To help
1542 + this capability we added a memory allocation function. Gdb does not
1543 + return this memory (it is used for strings that you pass to that function
1544 + you are calling from gdb) so we fixed up a way to allow you to
1545 + manually return the memory (see below).
1547 +4.) Kgdb time stamps (kgdb_ts()) are enhanced to expand what was the
1548 + interrupt flag to now also include the preemption count and the
1549 + "in_interrupt" info. The flag is now called "with_pif" to indicate
1550 + the order, preempt_count, in_interrupt, flag. The preempt_count is
1551 + shifted left by 4 bits so you can read the count in hex by dropping
1552 + the low order digit. In_interrupt is in bit 1, and the flag is in
1555 +5.) The command: "p kgdb_info" is now expanded and prints something
1558 +$2 = {used_malloc = 0, called_from = 0xc0107506, entry_tsc = 67468627259,
1559 + errcode = 0, vector = 3, print_debug_info = 0, hold_on_sstep = 1,
1560 + cpus_waiting = {{task = 0xc027a000, pid = 32768, hold = 0,
1561 + regs = 0xc027bf84}, {task = 0x0, pid = 0, hold = 0, regs = 0x0}}}
1563 + Things to note here: a.) used_malloc is the amount of memory that
1564 + has been malloc'ed to do calls from gdb. You can reclaim this
1565 + memory like this: "p kgdb_info.used_malloc=0" Cool, huh? b.)
1566 + cpus_waiting is now "sized" by the number of CPUs you enter at
1567 + configure time in the kgdb configure section. This is NOT used
1568 + anywhere else in the system, but it is "nice" here. c.) The task's
1569 + "pid" is now in the structure. This is the pid you will need to use
1570 + to decode to the thread id to get gdb to look at that thread.
1571 + Remember that the "info thread" command prints a list of threads
1572 + wherein it numbers each thread with its reference number followed
1573 + by the thread's pid. Note that the per-CPU idle threads actually
1574 + have pids of 0 (yes, there is more than one pid 0 in an SMP system).
1575 + To avoid confusion, kgdb numbers these threads with numbers beyond
1576 + the MAX_PID. That is why you see 32768 and above.
1578 +6.) A subtle change, we now provide the complete register set for tasks
1579 + that are active on the other CPUs. This allows better trace back on
1582 + And, let's mention what we could not fix. Back-trace from all but the
1583 + thread that we trapped will, most likely, have a bogus entry in it.
1584 + The problem is that gdb does not recognize the entry code for
1585 + functions that use "current" near (at all?) the entry. The compiler
1586 + is putting the "current" decode as the first two instructions of the
1587 + function where gdb expects to find %ebp changing code. Back trace
1588 + also has trouble with interrupt frames. I am talking with Daniel
1589 + Jacobowitz about some way to fix this, but don't hold your breath.
1592 +Major enhancement with this version is the ability to hold one or more
1593 +CPUs in an SMP system while allowing the others to continue. Also, by
1594 +default only the current CPU is enabled on single-step commands (please
1595 +note that gdb issues single-step commands at times other than when you
1596 +use the si command).
1598 +Another change is to collect some useful information in
1599 +a global structure called "kgdb_info". You should be able to just:
1603 +although I have seen cases where the first time this is done gdb just
1604 +prints the first member but prints the whole structure if you then enter
1605 +CR (carriage return or enter). This also works:
1611 +$4 = {called_from = 0xc010732c, entry_tsc = 32804123790856, errcode = 0,
1612 + vector = 3, print_debug_info = 0}
1614 +"Called_from" is the return address from the current entry into kgdb.
1615 +Sometimes it is useful to know why you are in kgdb, for example, was
1616 +it an NMI or a real breakpoint? The simple way to interrogate this
1621 +which will print the surrounding few lines of source code.
1623 +"Entry_tsc" is the CPU TSC on entry to kgdb (useful to compare to the
1626 +"errcode" and "vector" are other entry parameters which may be helpful on
1629 +"print_debug_info" is the internal debugging kgdb print enable flag. Yes,
1632 +In SMP systems kgdb_info also includes the "cpus_waiting" structure and
1636 +$7 = {called_from = 0xc0112739, entry_tsc = 1034936624074, errcode = 0,
1637 + vector = 2, print_debug_info = 0, hold_on_sstep = 1, cpus_waiting = {{
1638 + task = 0x0, hold = 0, regs = 0x0}, {task = 0xc71b8000, hold = 0,
1639 + regs = 0xc71b9f70}, {task = 0x0, hold = 0, regs = 0x0}, {task = 0x0,
1640 + hold = 0, regs = 0x0}, {task = 0x0, hold = 0, regs = 0x0}, {task = 0x0,
1641 + hold = 0, regs = 0x0}, {task = 0x0, hold = 0, regs = 0x0}, {task = 0x0,
1642 + hold = 0, regs = 0x0}}}
1644 +"Cpus_waiting" has an entry for each CPU other than the current one that
1645 +has been stopped. Each entry contains the task_struct address for that
1646 +CPU, the address of the regs for that task and a hold flag. All these
1647 +have the proper typing so that, for example:
1649 +p *kgdb_info.cpus_waiting[1].regs
1651 +will print the registers for CPU 1.
1653 +"Hold_on_sstep" is a new feature with this version and comes up set or
1654 +true. What this means is that whenever kgdb is asked to single-step all
1655 +other CPUs are held (i.e. not allowed to execute). The flag applies to
1656 +all but the current CPU and, again, can be changed:
1658 +p kgdb_info.hold_on_sstep=0
1660 +restores the old behavior of letting all CPUs run during single-stepping.
1662 +Likewise, each CPU has a "hold" flag, which if set, locks that CPU out
1663 +of execution. Note that this has some risk in cases where the CPUs need
1664 +to communicate with each other. If kgdb finds no CPU available on exit,
1665 +it will push a message thru gdb and stay in kgdb. Note that it is legal
1666 +to hold the current CPU as long as at least one CPU can execute.
1669 +This version implements an event queue. Events are signaled by calling
1670 +a function in the kgdb stub and may be examined from gdb. See EVENTS
1671 +below for details. This version also tightens up the interrupt and SMP
1672 +handling to not allow interrupts on the way to kgdb from a breakpoint
1673 +trap. It is fine to allow these interrupts for user code, but not
1679 +This version of the kgdb package was developed and tested on
1680 +kernel version 2.4.16. It will not install on any earlier kernels.
1681 +It is possible that it will continue to work on later versions
1682 +of 2.4 and then versions of 2.5 (I hope).
1688 +Designate one machine as the "development" machine. This is the
1689 +machine on which you run your compiles and which has your source
1690 +code for the kernel. Designate a second machine as the "target"
1691 +machine. This is the machine that will run your experimental
1694 +The two machines will be connected together via a serial line out
1695 +one or the other of the COM ports of the PC. You will need the
1696 +appropriate modem eliminator (null modem) cable(s) for this.
1698 +Decide on which tty port you want the machines to communicate, then
1699 +connect them up back-to-back using the null modem cable. COM1 is
1700 +/dev/ttyS0 and COM2 is /dev/ttyS1. You should test this connection
1701 +with the two machines prior to trying to debug a kernel. Once you
1702 +have it working, on the TARGET machine, enter:
1704 +setserial /dev/ttyS0 (or what ever tty you are using)
1706 +and record the port address and the IRQ number.
1708 +On the DEVELOPMENT machine you need to apply the patch for the kgdb
1709 +hooks. You have probably already done that if you are reading this
1712 +On your DEVELOPMENT machine, go to your kernel source directory and do
1713 +"make Xconfig" where X is one of "x", "menu", or "". If you are
1714 +configuring in the standard serial driver, it must not be a module.
1715 +Either yes or no is ok, but making the serial driver a module means it
1716 +will initialize after kgdb has set up the UART interrupt code and may
1717 +cause a failure of the control-C option discussed below. The configure
1718 +question for the serial driver is under the "Character devices" heading
1721 +"Standard/generic (8250/16550 and compatible UARTs) serial support"
1723 +Go down to the kernel debugging menu item and open it up. Enable the
1724 +kernel kgdb stub code by selecting that item. You can also choose to
1725 +turn on the "-ggdb -O1" compile options. The -ggdb causes the compiler
1726 +to put more debug info (like local symbols) in the object file. On the
1727 +i386 -g and -ggdb are the same so this option just reduces to "O1". The
1728 +-O1 reduces the optimization level. This may be helpful in some cases,
1729 +be aware, however, that this may also mask the problem you are looking
1732 +The baud rate. Default is 115200. What ever you choose be sure that
1733 +the host machine is set to the same speed. I recommend the default.
1735 +The port. This is the I/O address of the serial UART that you should
1736 +have gotten using setserial as described above. The standard COM1 port
1737 +(3f8) using IRQ 4 is default. COM2 is 2f8 which by convention uses IRQ
1740 +The port IRQ (see above).
1742 +Stack overflow test. This option makes a minor change in the trap,
1743 +system call and interrupt code to detect stack overflow and transfer
1744 +control to kgdb if it happens. (Some platforms have this in the
1745 +baseline code, but the i386 does not.)
1747 +You can also configure the system to recognize the boot option
1748 +"console=kgdb" which if given will cause all console output during
1749 +booting to be put thru gdb as well as other consoles. This option
1750 +requires that gdb and kgdb be connected prior to sending console output
1751 +so, if they are not, a breakpoint is executed to force the connection.
1752 +This will happen before any kernel output (it is going thru gdb, right),
1753 +and will stall the boot until the connection is made.
1755 +You can also configure in a patch to SysRq to enable the kGdb SysRq.
1756 +This request generates a breakpoint. Since the serial port IRQ line is
1757 +set up after any serial drivers, it is possible that this command will
1758 +work when the control-C will not.
1760 +Save and exit the Xconfig program. Then do "make clean" , "make dep"
1761 +and "make bzImage" (or whatever target you want to make). This gets the
1762 +kernel compiled with the "-g" option set -- necessary for debugging.
1764 +You have just built the kernel on your DEVELOPMENT machine that you
1765 +intend to run on your TARGET machine.
1767 +To install this new kernel, use the following installation procedure.
1768 +Remember, you are on the DEVELOPMENT machine patching the kernel source
1769 +for the kernel that you intend to run on the TARGET machine.
1771 +Copy this kernel to your target machine using your usual procedures. I
1772 +usually arrange to copy development:
1773 +/usr/src/linux/arch/i386/boot/bzImage to /vmlinuz on the TARGET machine
1774 +via a LAN based NFS access. That is, I run the cp command on the target
1775 +and copy from the development machine via the LAN. Run Lilo (see "man
1776 +lilo" for details on how to set this up) on the new kernel on the target
1777 +machine so that it will boot! Then boot the kernel on the target
1780 +On the DEVELOPMENT machine, create a file called .gdbinit in the
1781 +directory /usr/src/linux. An example .gdbinit file looks like this:
1783 +shell echo -e "\003" >/dev/ttyS0
1784 +set remotebaud 38400 (or what ever speed you have chosen)
1785 +target remote /dev/ttyS0
1788 +Change the "echo" and "target" definition so that it specifies the tty
1789 +port that you intend to use. Change the "remotebaud" definition to
1790 +match the data rate that you are going to use for the com line.
1792 +You are now ready to try it out.
1794 +Boot your target machine with "kgdb" in the boot command i.e. something
1799 +or if you also want console output thru gdb:
1801 +lilo> test kgdb console=kgdb
1803 +You should see the lilo message saying it has loaded the kernel and then
1804 +all output stops. The kgdb stub is trying to connect with gdb. Start
1805 +gdb something like this:
1808 +On your DEVELOPMENT machine, cd /usr/src/linux and enter "gdb vmlinux".
1809 +When gdb gets the symbols loaded it will read your .gdbinit file and, if
1810 +everything is working correctly, you should see gdb print out a few
1811 +lines indicating that a breakpoint has been taken. It will actually
1812 +show a line of code in the target kernel inside the kgdb activation
1815 +The gdb interaction should look something like this:
1817 + linux-dev:/usr/src/linux# gdb vmlinux
1818 + GDB is free software and you are welcome to distribute copies of it
1819 + under certain conditions; type "show copying" to see the conditions.
1820 + There is absolutely no warranty for GDB; type "show warranty" for details.
1821 + GDB 4.15.1 (i486-slackware-linux),
1822 + Copyright 1995 Free Software Foundation, Inc...
1823 + breakpoint () at i386-stub.c:750
1827 +You can now use whatever gdb commands you like to set breakpoints.
1828 +Enter "continue" to start your target machine executing again. At this
1829 +point the target system will run at full speed until it encounters
1830 +your breakpoint or gets a segment violation in the kernel, or whatever.
1832 +If you have the kgdb console enabled when you continue, gdb will print
1833 +out all the console messages.
1835 +The above example caused a breakpoint relatively early in the boot
1836 +process. For the i386 kgdb it is possible to code a break instruction
1837 +as the first C-language point in init/main.c, i.e. as the first instruction
1838 +in start_kernel(). This could be done as follows:
1840 +#include <asm/kgdb.h>
1843 +This breakpoint() is really a function that sets up the breakpoint and
1844 +single-step hardware trap cells and then executes a breakpoint. Any
1845 +early hard coded breakpoint will need to use this function. Once the
1846 +trap cells are set up they need not be set again, but doing it again
1847 +does not hurt anything, so you don't need to be concerned about which
1848 +breakpoint is hit first. Once the trap cells are set up (and the kernel
1849 +sets them up in due course even if breakpoint() is never called) the
1854 +will generate an inline breakpoint. This may be more useful as it stops
1855 +the processor at the instruction instead of in a function a step removed
1856 +from the location of interest. In either case <asm/kgdb.h> must be
1857 +included to define both breakpoint() and BREAKPOINT.
1859 +Triggering kgdbstub at other times
1860 +==================================
1862 +Often you don't need to enter the debugger until much later in the boot
1863 +or even after the machine has been running for some time. Once the
1864 +kernel is booted and interrupts are on, you can force the system to
1865 +enter the debugger by sending a control-C to the debug port. This is
1866 +what the first line of the recommended .gdbinit file does. This allows
1867 +you to start gdb any time after the system is up as well as when the
1868 +system is already at a breakpoint. (In the case where the system is
1869 +already at a breakpoint the control-C is not needed, however, it will
1870 +be ignored by the target so no harm is done. Also note the the echo
1871 +command assumes that the port speed is already set. This will be true
1872 +once gdb has connected, but it is best to set the port speed before you
1875 +Another simple way to do this is to put the following file in you ~/bin
1879 +echo -e "\003" > /dev/ttyS0
1881 +Here, the ttyS0 should be replaced with what ever port you are using.
1882 +The "\003" is control-C. Once you are connected with gdb, you can enter
1883 +control-C at the command prompt.
1885 +An alternative way to get control to the debugger is to enable the kGdb
1886 +SysRq command. Then you would enter Alt-SysRq-g (all three keys at the
1887 +same time, but push them down in the order given). To refresh your
1888 +memory of the available SysRq commands try Alt-SysRq-=. Actually any
1889 +undefined command could replace the "=", but I like to KNOW that what I
1890 +am pushing will never be defined.
1895 +You can break into the target machine at any time from the development
1896 +machine by typing ^C (see above paragraph). If the target machine has
1897 +interrupts enabled this will stop it in the kernel and enter the
1900 +There is unfortunately no way of breaking into the kernel if it is
1901 +in a loop with interrupts disabled, so if this happens to you then
1902 +you need to place exploratory breakpoints or printk's into the kernel
1903 +to find out where it is looping. The exploratory breakpoints can be
1904 +entered either thru gdb or hard coded into the source. This is very
1905 +handy if you do something like:
1907 +if (<it hurts>) BREAKPOINT;
1910 +There is a copy of an e-mail in the Documentation/i386/kgdb/ directory
1911 +(debug-nmi.txt) which describes how to create an NMI on an ISA bus
1912 +machine using a paper clip. I have a sophisticated version of this made
1913 +by wiring a push button switch into a PC104/ISA bus adapter card. The
1914 +adapter card nicely furnishes wire wrap pins for all the ISA bus
1917 +When you are done debugging the kernel on the target machine it is a
1918 +good idea to leave it in a running state. This makes reboots faster,
1919 +bypassing the fsck. So do a gdb "continue" as the last gdb command if
1920 +this is possible. To terminate gdb itself on the development machine
1921 +and leave the target machine running, first clear all breakpoints and
1922 +continue, then type ^Z to suspend gdb and then kill it with "kill %1" or
1925 +If gdbstub Does Not Work
1926 +========================
1928 +If it doesn't work, you will have to troubleshoot it. Do the easy
1929 +things first like double checking your cabling and data rates. You
1930 +might try some non-kernel based programs to see if the back-to-back
1931 +connection works properly. Just something simple like cat /etc/hosts
1932 +>/dev/ttyS0 on one machine and cat /dev/ttyS0 on the other will tell you
1933 +if you can send data from one machine to the other. Make sure it works
1934 +in both directions. There is no point in tearing out your hair in the
1935 +kernel if the line doesn't work.
1937 +All of the real action takes place in the file
1938 +/usr/src/linux/arch/i386/kernel/kgdb_stub.c. That is the code on the target
1939 +machine that interacts with gdb on the development machine. In gdb you can
1940 +turn on a debug switch with the following command:
1944 +This will print out the protocol messages that gdb is exchanging with
1945 +the target machine.
1947 +Another place to look is /usr/src/arch/i386/lib/kgdb_serial.c. This is
1948 +the code that talks to the serial port on the target side. There might
1949 +be a problem there. In particular there is a section of this code that
1950 +tests the UART which will tell you what UART you have if you define
1951 +"PRNT" (just remove "_off" from the #define PRNT_off). To view this
1952 +report you will need to boot the system without any beakpoints. This
1953 +allows the kernel to run to the point where it calls kgdb to set up
1954 +interrupts. At this time kgdb will test the UART and print out the type
1955 +it finds. (You need to wait so that the printks are actually being
1956 +printed. Early in the boot they are cached, waiting for the console to
1957 +be enabled. Also, if kgdb is entered thru a breakpoint it is possible
1958 +to cause a dead lock by calling printk when the console is locked. The
1959 +stub thus avoids doing printks from breakpoints, especially in the
1960 +serial code.) At this time, if the UART fails to do the expected thing,
1961 +kgdb will print out (using printk) information on what failed. (These
1962 +messages will be buried in all the other boot up messages. Look for
1963 +lines that start with "gdb_hook_interrupt:". You may want to use dmesg
1964 +once the system is up to view the log. If this fails or if you still
1965 +don't connect, review your answers for the port address. Use:
1967 +setserial /dev/ttyS0
1969 +to get the current port and IRQ information. This command will also
1970 +tell you what the system found for the UART type. The stub recognizes
1971 +the following UART types:
1973 +16450, 16550, and 16550A
1975 +If you are really desperate you can use printk debugging in the
1976 +kgdbstub code in the target kernel until you get it working. In particular,
1977 +there is a global variable in /usr/src/linux/arch/i386/kernel/kgdb_stub.c
1978 +named "remote_debug". Compile your kernel with this set to 1, rather
1979 +than 0 and the debug stub will print out lots of stuff as it does
1980 +what it does. Likewise there are debug printks in the kgdb_serial.c
1981 +code that can be turned on with simple changes in the macro defines.
1984 +Debugging Loadable Modules
1985 +==========================
1987 +This technique comes courtesy of Edouard Parmelan
1988 +<Edouard.Parmelan@quadratec.fr>
1990 +When you run gdb, enter the command
1992 +source gdbinit-modules
1994 +This will read in a file of gdb macros that was installed in your
1995 +kernel source directory when kgdb was installed. This file implements
1996 +the following commands:
1999 + Lists the loaded modules in the form <module-address> <module-name>
2001 +mod-print-symbols <module-address>
2002 + Prints all the symbols in the indicated module.
2004 +mod-add-symbols <module-address> <object-file-path-name>
2005 + Loads the symbols from the object file and associates them
2006 + with the indicated module.
2008 +After you have loaded the module that you want to debug, use the command
2009 +mod-list to find the <module-address> of your module. Then use that
2010 +address in the mod-add-symbols command to load your module's symbols.
2011 +From that point onward you can debug your module as if it were a part
2014 +The file gdbinit-modules also contains a command named mod-add-lis as
2015 +an example of how to construct a command of your own to load your
2016 +favorite module. The idea is to "can" the pathname of the module
2017 +in the command so you don't have to type so much.
2022 +Each process in a target machine is seen as a gdb thread. gdb thread
2023 +related commands (info threads, thread n) can be used.
2025 +ia-32 hardware breakpoints
2026 +==========================
2028 +kgdb stub contains support for hardware breakpoints using debugging features
2029 +of ia-32(x86) processors. These breakpoints do not need code modification.
2030 +They use debugging registers. 4 hardware breakpoints are available in ia-32
2033 +Each hardware breakpoint can be of one of the following three types.
2035 +1. Execution breakpoint - An Execution breakpoint is triggered when code
2036 + at the breakpoint address is executed.
2038 + As limited number of hardware breakpoints are available, it is
2039 + advisable to use software breakpoints ( break command ) instead
2040 + of execution hardware breakpoints, unless modification of code
2043 +2. Write breakpoint - A write breakpoint is triggered when memory
2044 + location at the breakpoint address is written.
2046 + A write or can be placed for data of variable length. Length of
2047 + a write breakpoint indicates length of the datatype to be
2048 + watched. Length is 1 for 1 byte data , 2 for 2 byte data, 3 for
2051 +3. Access breakpoint - An access breakpoint is triggered when memory
2052 + location at the breakpoint address is either read or written.
2054 + Access breakpoints also have lengths similar to write breakpoints.
2056 +IO breakpoints in ia-32 are not supported.
2058 +Since gdb stub at present does not use the protocol used by gdb for hardware
2059 +breakpoints, hardware breakpoints are accessed through gdb macros. gdb macros
2060 +for hardware breakpoints are described below.
2062 +hwebrk - Places an execution breakpoint
2063 + hwebrk breakpointno address
2064 +hwwbrk - Places a write breakpoint
2065 + hwwbrk breakpointno length address
2066 +hwabrk - Places an access breakpoint
2067 + hwabrk breakpointno length address
2068 +hwrmbrk - Removes a breakpoint
2069 + hwrmbrk breakpointno
2070 +exinfo - Tells whether a software or hardware breakpoint has occurred.
2071 + Prints number of the hardware breakpoint if a hardware breakpoint has
2074 +Arguments required by these commands are as follows
2075 +breakpointno - 0 to 3
2077 +address - Memory location in hex digits ( without 0x ) e.g c015e9bc
2082 +When a breakpoint occurs or user issues a break ( Ctrl + C ) to gdb
2083 +client, all the processors are forced to enter the debugger. Current
2084 +thread corresponds to the thread running on the processor where
2085 +breakpoint occurred. Threads running on other processor(s) appear
2086 +similar to other non-running threads in the 'info threads' output.
2087 +Within the kgdb stub there is a structure "waiting_cpus" in which kgdb
2088 +records the values of "current" and "regs" for each CPU other than the
2089 +one that hit the breakpoint. "current" is a pointer to the task
2090 +structure for the task that CPU is running, while "regs" points to the
2091 +saved registers for the task. This structure can be examined with the
2094 +ia-32 hardware debugging registers on all processors are set to same
2095 +values. Hence any hardware breakpoints may occur on any processor.
2097 +gdb troubleshooting
2098 +===================
2101 +Kill it. restart gdb. Connect to target machine.
2103 +2. gdb cannot connect to target machine (after killing a gdb and
2104 +restarting another) If the target machine was not inside debugger when
2105 +you killed gdb, gdb cannot connect because the target machine won't
2106 +respond. In this case echo "Ctrl+C"(ASCII 3) to the serial line.
2107 +e.g. echo -e "\003" > /dev/ttyS1
2108 +This forces that target machine into the debugger, after which you
2111 +3. gdb cannot connect even after echoing Ctrl+C into serial line
2112 +Try changing serial line settings min to 1 and time to 0
2113 +e.g. stty min 1 time 0 < /dev/ttyS1
2116 +Check serial line speed and set it to correct value if required
2117 +e.g. stty ispeed 115200 ospeed 115200 < /dev/ttyS1
2122 +Ever want to know the order of things happening? Which CPU did what and
2123 +when? How did the spinlock get the way it is? Then events are for
2124 +you. Events are defined by calls to an event collection interface and
2125 +saved for later examination. In this case, kgdb events are saved by a
2126 +very fast bit of code in kgdb which is fully SMP and interrupt protected
2127 +and they are examined by using gdb to display them. Kgdb keeps only
2128 +the last N events, where N must be a power of two and is defined at
2132 +Events are signaled to kgdb by calling:
2134 +kgdb_ts(data0,data1)
2136 +For each call kgdb records each call in an array along with other info.
2137 +Here is the array definition:
2139 +struct kgdb_and_then_struct {
2143 + long long at_time;
2152 +For SMP machines the CPU is recorded, for all machines the TSC is
2153 +recorded (gets a time stamp) as well as the line number and source file
2154 +the call was made from. The address of the (from), the "if" (interrupt
2155 +flag) and the two data items are also recorded. The macro kgdb_ts casts
2156 +the types to int, so you can put any 32-bit values here. There is a
2157 +configure option to select the number of events you want to keep. A
2158 +nice number might be 128, but you can keep up to 1024 if you want. The
2159 +number must be a power of two. An "andthen" macro library is provided
2160 +for gdb to help you look at these events. It is also possible to define
2161 +a different structure for the event storage and cast the data to this
2162 +structure. For example the following structure is defined in kgdb:
2164 +struct kgdb_and_then_struct2 {
2168 + long long at_time;
2173 + struct task_struct *t1;
2174 + struct task_struct *t2;
2177 +If you use this for display, the data elements will be displayed as
2178 +pointers to task_struct entries. You may want to define your own
2179 +structure to use in casting. You should only change the last two items
2180 +and you must keep the structure size the same. Kgdb will handle these
2181 +as 32-bit ints, but within that constraint you can define a structure to
2182 +cast to any 32-bit quantity. This need only be available to gdb and is
2183 +only used for casting in the display code.
2188 +I picked up this code from Amit S. Kale and enhanced it.
2190 +If you make some really cool modification to this stuff, or if you
2191 +fix a bug, please let me know.
2194 +<george@mvista.com>
2197 +<akale@veritas.com>
2199 +(First kgdb by David Grothe <dave@gcom.com>)
2201 +(modified by Tigran Aivazian <tigran@sco.com>)
2202 + Putting gdbstub into the kernel config menu.
2204 +(modified by Scott Foehner <sfoehner@engr.sgi.com>)
2205 + Hooks for entering gdbstub at boot time.
2207 +(modified by Amit S. Kale <akale@veritas.com>)
2208 + Threads, ia-32 hw debugging, mp support, console support,
2209 + nmi watchdog handling.
2211 +(modified by George Anzinger <george@mvista.com>)
2212 + Extended threads to include the idle threads.
2213 + Enhancements to allow breakpoint() at first C code.
2214 + Use of module_init() and __setup() to automate the configure.
2215 + Enhanced the cpu "collection" code to work in early bring-up.
2216 + Added ability to call functions from gdb
2217 + Print info thread stuff without going back to schedule()
2218 + Now collect the "other" cpus with an IPI/ NMI.
2219 Index: linux-2.6.10/Documentation/i386/kgdb/gdbinit.hw
2220 ===================================================================
2221 --- linux-2.6.10.orig/Documentation/i386/kgdb/gdbinit.hw 2005-04-05 19:01:49.158500672 +0800
2222 +++ linux-2.6.10/Documentation/i386/kgdb/gdbinit.hw 2005-04-05 12:48:05.273615368 +0800
2225 +#Using ia-32 hardware breakpoints.
2227 +#4 hardware breakpoints are available in ia-32 processors. These breakpoints
2228 +#do not need code modification. They are set using debug registers.
2230 +#Each hardware breakpoint can be of one of the
2231 +#three types: execution, write, access.
2232 +#1. An Execution breakpoint is triggered when code at the breakpoint address is
2234 +#2. A write breakpoint ( aka watchpoints ) is triggered when memory location
2235 +#at the breakpoint address is written.
2236 +#3. An access breakpoint is triggered when memory location at the breakpoint
2237 +#address is either read or written.
2239 +#As hardware breakpoints are available in limited number, use software
2240 +#breakpoints ( br command in gdb ) instead of execution hardware breakpoints.
2242 +#Length of an access or a write breakpoint defines length of the datatype to
2243 +#be watched. Length is 1 for char, 2 short , 3 int.
2245 +#For placing execution, write and access breakpoints, use commands
2246 +#hwebrk, hwwbrk, hwabrk
2247 +#To remove a breakpoint use hwrmbrk command.
2249 +#These commands take following types of arguments. For arguments associated
2250 +#with each command, use help command.
2251 +#1. breakpointno: 0 to 3
2253 +#3. address: Memory location in hex ( without 0x ) e.g c015e9bc
2255 +#Use the command exinfo to find which hardware breakpoint occured.
2257 +#hwebrk breakpointno address
2259 + maintenance packet Y$arg0,0,0,$arg1
2262 + hwebrk <breakpointno> <address>
2263 + Places a hardware execution breakpoint
2264 + <breakpointno> = 0 - 3
2265 + <address> = Hex digits without leading "0x".
2268 +#hwwbrk breakpointno length address
2270 + maintenance packet Y$arg0,1,$arg1,$arg2
2273 + hwwbrk <breakpointno> <length> <address>
2274 + Places a hardware write breakpoint
2275 + <breakpointno> = 0 - 3
2276 + <length> = 1 (1 byte), 2 (2 byte), 3 (4 byte)
2277 + <address> = Hex digits without leading "0x".
2280 +#hwabrk breakpointno length address
2282 + maintenance packet Y$arg0,1,$arg1,$arg2
2285 + hwabrk <breakpointno> <length> <address>
2286 + Places a hardware access breakpoint
2287 + <breakpointno> = 0 - 3
2288 + <length> = 1 (1 byte), 2 (2 byte), 3 (4 byte)
2289 + <address> = Hex digits without leading "0x".
2292 +#hwrmbrk breakpointno
2294 + maintenance packet y$arg0
2297 + hwrmbrk <breakpointno>
2298 + <breakpointno> = 0 - 3
2299 + Removes a hardware breakpoint
2303 + maintenance packet r
2307 + maintenance packet qE
2311 + Gives information about a breakpoint.
2314 + p $th=(struct thread_info *)((int)$esp & ~8191)
2318 + Gets and prints the current thread_info pointer, Defines th to be it.
2321 + p $cu=((struct thread_info *)((int)$esp & ~8191))->task
2325 + Gets and print the "current" value. Defines $cu to be it.
2328 + set var $flags=$eflags
2329 + set $eflags=$eflags&~0x200
2332 + set var $eflags|=$flags&0x200
2335 + saves the current interrupt state and clears the processor interrupt
2336 + flag. Use int_on to restore the saved flag.
2339 + Restores the interrupt flag saved by int_off.
2341 Index: linux-2.6.10/Documentation/i386/kgdb/gdb-globals.txt
2342 ===================================================================
2343 --- linux-2.6.10.orig/Documentation/i386/kgdb/gdb-globals.txt 2005-04-05 19:01:49.158500672 +0800
2344 +++ linux-2.6.10/Documentation/i386/kgdb/gdb-globals.txt 2005-04-05 12:48:05.260617344 +0800
2346 +Sender: akale@veritas.com
2347 +Date: Fri, 23 Jun 2000 19:26:35 +0530
2348 +From: "Amit S. Kale" <akale@veritas.com>
2349 +Organization: Veritas Software (India)
2350 +To: Dave Grothe <dave@gcom.com>, linux-kernel@vger.rutgers.edu
2351 +CC: David Milburn <dmilburn@wirespeed.com>,
2352 + "Edouard G. Parmelan" <Edouard.Parmelan@quadratec.fr>,
2353 + ezannoni@cygnus.com, Keith Owens <kaos@ocs.com.au>
2354 +Subject: Re: Module debugging using kgdb
2360 +> There is a 2.4.0 version of kgdb on our ftp site:
2361 +> ftp://ftp.gcom.com/pub/linux/src/kgdb. I mirrored your version of gdb
2362 +> and loadmodule.sh there.
2364 +> Have a look at the README file and see if I go it right. If not, send
2365 +> me some corrections and I will update it.
2367 +> Does your version of gdb solve the global variable problem?
2370 +Thanks to Elena Zanoni, gdb (developement version) can now calculate
2371 +correctly addresses of dynamically loaded object files. I have not been
2372 +following gdb developement for sometime and am not sure when symbol
2373 +address calculation fix is going to appear in a gdb stable version.
2375 +Elena, any idea when the fix will make it to a prebuilt gdb from a
2378 +For the time being I have built a gdb developement version. It can be
2379 +used for module debugging with loadmodule.sh script.
2381 +The problem with calculating of module addresses with previous versions
2382 +of gdb was as follows:
2383 +gdb did not use base address of a section while calculating address of
2384 +a symbol in the section in an object file loaded via 'add-symbol-file'.
2385 +It used address of .text segment instead. Due to this addresses of
2386 +symbols in .data, .bss etc. (e.g. global variables) were calculated incorrectly.
2388 +Above mentioned fix allow gdb to use base address of a segment while
2389 +calculating address of a symbol in it. It adds a parameter '-s' to
2390 +'add-symbol-file' command for specifying base address of a segment.
2392 +loadmodule.sh script works as follows.
2394 +1. Copy a module file to target machine.
2395 +2. Load the module on the target machine using insmod with -m parameter.
2396 +insmod produces a module load map which contains base addresses of all
2397 +sections in the module and addresses of symbols in the module file.
2398 +3. Find all sections and their base addresses in the module from
2400 +4. Generate a script that loads the module file. The script uses
2401 +'add-symbol-file' and specifies address of text segment followed by
2402 +addresses of all segments in the module.
2404 +Here is an example gdb script produced by loadmodule.sh script.
2406 +add-symbol-file foo 0xd082c060 -s .text.lock 0xd08cbfb5
2407 +-s .fixup 0xd08cfbdf -s .rodata 0xd08cfde0 -s __ex_table 0xd08e3b38
2408 +-s .data 0xd08e3d00 -s .bss 0xd08ec8c0 -s __ksymtab 0xd08ee838
2410 +With this command gdb can calculate addresses of symbols in ANY segment
2416 +Veritas Software ( http://www.veritas.com )
2417 Index: linux-2.6.10/Documentation/i386/kgdb/gdbinit-modules
2418 ===================================================================
2419 --- linux-2.6.10.orig/Documentation/i386/kgdb/gdbinit-modules 2005-04-05 19:01:49.158500672 +0800
2420 +++ linux-2.6.10/Documentation/i386/kgdb/gdbinit-modules 2005-04-05 12:48:05.262617040 +0800
2423 +# Usefull GDB user-command to debug Linux Kernel Modules with gdbstub.
2425 +# This don't work for Linux-2.0 or older.
2427 +# Author Edouard G. Parmelan <Edouard.Parmelan@quadratec.fr>
2430 +# Fri Apr 30 20:33:29 CEST 1999
2431 +# First public release.
2433 +# Major cleanup after experiment Linux-2.0 kernel without success.
2434 +# Symbols of a module are not in the correct order, I can't explain
2437 +# Fri Mar 19 15:41:40 CET 1999
2440 +# Thu Jan 6 16:29:03 CST 2000
2441 +# A little fixing by Dave Grothe <dave@gcom.com>
2443 +# Mon Jun 19 09:33:13 CDT 2000
2444 +# Alignment changes from Edouard Parmelan
2446 +# The basic idea is to find where insmod load the module and inform
2447 +# GDB to load the symbol table of the module with the GDB command
2448 +# ``add-symbol-file <object> <address>''.
2450 +# The Linux kernel holds the list of all loaded modules in module_list,
2451 +# this list end with &kernel_module (exactly with module->next == NULL,
2452 +# but the last module is not a real module).
2454 +# Insmod allocates the struct module before the object file. Since
2455 +# Linux-2.1, this structure contain his size. The real address of
2456 +# the object file is then (char*)module + module->size_of_struct.
2458 +# You can use three user functions ``mod-list'', ``mod-print-symbols''
2459 +# and ``add-module-symbols''.
2461 +# mod-list list all loaded modules with the format:
2462 +# <module-address> <module-name>
2464 +# As soon as you have found the address of your module, you can
2465 +# print its exported symbols (mod-print-symbols) or inform GDB to add
2466 +# symbols from your module file (mod-add-symbols).
2468 +# The argument that you give to mod-print-symbols or mod-add-symbols
2469 +# is the <module-address> from the mod-list command.
2471 +# When using the mod-add-symbols command you must also give the full
2472 +# pathname of the modules object code file.
2474 +# The command mod-add-lis is an example of how to make this easier.
2475 +# You can edit this macro to contain the path name of your own
2476 +# favorite module and then use it as a shorthand to load it. You
2477 +# still need the module-address, however.
2479 +# The internal function ``mod-validate'' set the GDB variable $mod
2480 +# as a ``struct module*'' if the kernel known the module otherwise
2481 +# $mod is set to NULL. This ensure to not add symbols for a wrong
2484 +# Have a nice hacking day !
2488 + set $mod = (struct module*)module_list
2489 + # the last module is the kernel, ignore it
2490 + while $mod != &kernel_module
2491 + printf "%p\t%s\n", (long)$mod, ($mod)->name
2492 + set $mod = $mod->next
2496 +List all modules in the form: <module-address> <module-name>
2497 +Use the <module-address> as the argument for the other
2498 +mod-commands: mod-print-symbols, mod-add-symbols.
2501 +define mod-validate
2502 + set $mod = (struct module*)module_list
2503 + while ($mod != $arg0) && ($mod != &kernel_module)
2504 + set $mod = $mod->next
2506 + if $mod == &kernel_module
2508 + printf "%p is not a module\n", $arg0
2511 +document mod-validate
2512 +mod-validate <module-address>
2513 +Internal user-command used to validate the module parameter.
2514 +If <module> is a real loaded module, set $mod to it otherwise set $mod to 0.
2518 +define mod-print-symbols
2519 + mod-validate $arg0
2522 + while $i < $mod->nsyms
2523 + set $sym = $mod->syms[$i]
2524 + printf "%p\t%s\n", $sym->value, $sym->name
2529 +document mod-print-symbols
2530 +mod-print-symbols <module-address>
2531 +Print all exported symbols of the module. see mod-list
2535 +define mod-add-symbols-align
2536 + mod-validate $arg0
2538 + set $mod_base = ($mod->size_of_struct + (long)$mod)
2539 + if ($arg2 != 0) && (($mod_base & ($arg2 - 1)) != 0)
2540 + set $mod_base = ($mod_base | ($arg2 - 1)) + 1
2542 + add-symbol-file $arg1 $mod_base
2545 +document mod-add-symbols-align
2546 +mod-add-symbols-align <module-address> <object file path name> <align>
2547 +Load the symbols table of the module from the object file where
2548 +first section aligment is <align>.
2549 +To retreive alignment, use `objdump -h <object file path name>'.
2552 +define mod-add-symbols
2553 + mod-add-symbols-align $arg0 $arg1 sizeof(long)
2555 +document mod-add-symbols
2556 +mod-add-symbols <module-address> <object file path name>
2557 +Load the symbols table of the module from the object file.
2558 +Default alignment is 4. See mod-add-symbols-align.
2562 + mod-add-symbols-align $arg0 /usr/src/LiS/streams.o 16
2564 +document mod-add-lis
2565 +mod-add-lis <module-address>
2566 +Does mod-add-symbols <module-address> /usr/src/LiS/streams.o
2568 Index: linux-2.6.10/Documentation/i386/kgdb/debug-nmi.txt
2569 ===================================================================
2570 --- linux-2.6.10.orig/Documentation/i386/kgdb/debug-nmi.txt 2005-04-05 19:01:49.158500672 +0800
2571 +++ linux-2.6.10/Documentation/i386/kgdb/debug-nmi.txt 2005-04-05 12:48:05.261617192 +0800
2573 +Subject: Debugging with NMI
2574 +Date: Mon, 12 Jul 1999 11:28:31 -0500
2575 +From: David Grothe <dave@gcom.com>
2576 +Organization: Gcom, Inc
2577 +To: David Grothe <dave@gcom.com>
2581 +Maybe this is old hat, but it is new to me --
2583 +On an ISA bus machine, if you short out the A1 and B1 pins of an ISA
2584 +slot you will generate an NMI to the CPU. This interrupts even a
2585 +machine that is hung in a loop with interrupts disabled. Used in
2586 +conjunction with kgdb <
2587 +ftp://ftp.gcom.com/pub/linux/src/kgdb-2.3.35/kgdb-2.3.35.tgz > you can
2588 +gain debugger control of a machine that is hung in the kernel! Even
2589 +without kgdb the kernel will print a stack trace so you can find out
2592 +The A1/B1 pins are directly opposite one another and the farthest pins
2593 +towards the bracket end of the ISA bus socket. You can stick a paper
2594 +clip or multi-meter probe between them to short them out.
2596 +I had a spare ISA bus to PC104 bus adapter around. The PC104 end of the
2597 +board consists of two rows of wire wrap pins. So I wired a push button
2598 +between the A1/B1 pins and now have an ISA board that I can stick into
2599 +any ISA bus slot for debugger entry.
2601 +Microsoft has a circuit diagram of a PCI card at
2602 +http://www.microsoft.com/hwdev/DEBUGGING/DMPSW.HTM. If you want to
2603 +build one you will have to mail them and ask for the PAL equations.
2604 +Nobody makes one comercially.
2606 +[THIS TIP COMES WITH NO WARRANTY WHATSOEVER. It works for me, but if
2607 +your machine catches fire, it is your problem, not mine.]
2609 +-- Dave (the kgdb guy)
2610 Index: linux-2.6.10/Documentation/i386/kgdb/loadmodule.sh
2611 ===================================================================
2612 --- linux-2.6.10.orig/Documentation/i386/kgdb/loadmodule.sh 2005-04-05 19:01:49.158500672 +0800
2613 +++ linux-2.6.10/Documentation/i386/kgdb/loadmodule.sh 2005-04-05 12:48:05.274615216 +0800
2616 +# This script loads a module on a target machine and generates a gdb script.
2617 +# source generated gdb script to load the module file at appropriate addresses
2621 +# Loading the module on target machine and generating gdb script)
2622 +# [foo]$ loadmodule.sh <modulename>
2624 +# Loading the module file into gdb
2625 +# (gdb) source <gdbscriptpath>
2627 +# Modify following variables according to your setup.
2628 +# TESTMACHINE - Name of the target machine
2629 +# GDBSCRIPTS - The directory where a gdb script will be generated
2631 +# Author: Amit S. Kale (akale@veritas.com).
2633 +# If you run into problems, please check files pointed to by following
2635 +# ERRFILE - /tmp/<modulename>.errs contains stderr output of insmod
2636 +# MAPFILE - /tmp/<modulename>.map contains stdout output of insmod
2637 +# GDBSCRIPT - $GDBSCRIPTS/load<modulename> gdb script.
2640 +GDBSCRIPTS=/home/bar
2642 +if [ $# -lt 1 ] ; then {
2643 + echo Usage: $0 modulefile
2648 +MODULEFILEBASENAME=`basename $1`
2650 +if [ $MODULEFILE = $MODULEFILEBASENAME ] ; then {
2651 + MODULEFILE=`pwd`/$MODULEFILE
2654 +ERRFILE=/tmp/$MODULEFILEBASENAME.errs
2655 +MAPFILE=/tmp/$MODULEFILEBASENAME.map
2656 +GDBSCRIPT=$GDBSCRIPTS/load$MODULEFILEBASENAME
2658 +function findaddr() {
2659 + local ADDR=0x$(echo "$SEGMENTS" | \
2660 + grep "$1" | sed 's/^[^ ]*[ ]*[^ ]*[ ]*//' | \
2661 + sed 's/[ ]*[^ ]*$//')
2665 +function checkerrs() {
2666 + if [ "`cat $ERRFILE`" != "" ] ; then {
2673 +echo Copying $MODULEFILE to $TESTMACHINE
2674 +rcp $MODULEFILE root@${TESTMACHINE}:
2676 +echo Loading module $MODULEFILE
2677 +rsh -l root $TESTMACHINE /sbin/insmod -m ./`basename $MODULEFILE` \
2678 + > $MAPFILE 2> $ERRFILE
2681 +SEGMENTS=`head -n 11 $MAPFILE | tail -n 10`
2682 +TEXTADDR=$(findaddr "\\.text[^.]")
2683 +LOADSTRING="add-symbol-file $MODULEFILE $TEXTADDR"
2684 +SEGADDRS=`echo "$SEGMENTS" | awk '//{
2685 + if ($1 != ".text" && $1 != ".this" &&
2686 + $1 != ".kstrtab" && $1 != ".kmodtab") {
2687 + print " -s " $1 " 0x" $3 " "
2690 +LOADSTRING="$LOADSTRING $SEGADDRS"
2691 +echo Generating script $GDBSCRIPT
2692 +echo $LOADSTRING > $GDBSCRIPT
2693 Index: linux-2.6.10/Documentation/i386/kgdb/andthen
2694 ===================================================================
2695 --- linux-2.6.10.orig/Documentation/i386/kgdb/andthen 2005-04-05 19:01:49.158500672 +0800
2696 +++ linux-2.6.10/Documentation/i386/kgdb/andthen 2005-04-05 12:48:05.272615520 +0800
2701 + set var $thp=(struct kgdb_and_then_struct *)&kgdb_data[0]
2702 + set var $at_size = (sizeof kgdb_data)/(sizeof *$thp)
2703 + set var $at_oc=kgdb_and_then_count
2704 + set var $at_cc=$at_oc
2707 +define andthen_next
2708 + set var $at_cc=$arg0
2713 + if ($at_cc >= $at_oc)
2714 + printf "Outside window. Window size is %d\n",($at_oc-$at_low)
2716 + printf "%d: ",$at_cc
2717 + output *($thp+($at_cc++ % $at_size ))
2721 +define andthen_set_edge
2722 + set var $at_oc=kgdb_and_then_count
2723 + set var $at_low = $at_oc - $at_size
2725 + set var $at_low = 0
2727 + if (( $at_cc > $at_oc) || ($at_cc < $at_low))
2728 + printf "Count outside of window, setting count to "
2729 + if ($at_cc >= $at_oc)
2730 + set var $at_cc = $at_oc
2732 + set var $at_cc = $at_low
2734 + printf "%d\n",$at_cc
2740 + if ($at_cc <= $at_low)
2741 + printf "Outside window. Window size is %d\n",($at_oc-$at_low)
2743 + printf "%d: ",$at_cc-1
2744 + output *($thp+(--$at_cc % $at_size ))
2749 +document andthen_next
2750 + andthen_next <count>
2751 + . sets the number of the event to display next. If this event
2752 + . is not in the event pool, either andthen or beforethat will
2753 + . correct it to the nearest event pool edge. The event pool
2754 + . ends at the last event recorded and begins <number of events>
2755 + . prior to that. If beforethat is used next, it will display
2756 + . event <count> -1.
2758 + andthen commands are: set_andthen, andthen_next, andthen and beforethat
2764 +. displays the next event in the list. <set_andthen> sets up to display
2765 +. the oldest saved event first.
2766 +. <count> (optional) count of the event to display.
2767 +. note the number of events saved is specified at configure time.
2768 +. if events are saved between calls to andthen the index will change
2769 +. but the displayed event will be the next one (unless the event buffer
2772 +. andthen commands are: set_andthen, andthen_next, andthen and beforethat
2775 +document set_andthen
2777 +. sets up to use the <andthen> and <beforethat> commands.
2778 +. if you have defined your own struct, use the above and
2779 +. then enter the following:
2780 +. p $thp=(struct kgdb_and_then_structX *)&kgdb_data[0]
2781 +. where <kgdb_and_then_structX> is the name of your structure.
2783 +. andthen commands are: set_andthen, andthen_next, andthen and beforethat
2786 +document beforethat
2788 +. displays the next prior event in the list. <set_andthen> sets up to
2789 +. display the last occuring event first.
2791 +. note the number of events saved is specified at configure time.
2792 +. if events are saved between calls to beforethat the index will change
2793 +. but the displayed event will be the next one (unless the event buffer
2796 +. andthen commands are: set_andthen, andthen_next, andthen and beforethat
2798 Index: linux-2.6.10/arch/i386/lib/kgdb_serial.c
2799 ===================================================================
2800 --- linux-2.6.10.orig/arch/i386/lib/kgdb_serial.c 2005-04-05 19:01:49.158500672 +0800
2801 +++ linux-2.6.10/arch/i386/lib/kgdb_serial.c 2005-04-05 12:48:05.193627528 +0800
2804 + * Serial interface GDB stub
2806 + * Written (hacked together) by David Grothe (dave@gcom.com)
2807 + * Modified to allow invokation early in boot see also
2808 + * kgdb.h for instructions by George Anzinger(george@mvista.com)
2812 +#include <linux/module.h>
2813 +#include <linux/errno.h>
2814 +#include <linux/signal.h>
2815 +#include <linux/sched.h>
2816 +#include <linux/timer.h>
2817 +#include <linux/interrupt.h>
2818 +#include <linux/tty.h>
2819 +#include <linux/tty_flip.h>
2820 +#include <linux/serial.h>
2821 +#include <linux/serial_reg.h>
2822 +#include <linux/config.h>
2823 +#include <linux/major.h>
2824 +#include <linux/string.h>
2825 +#include <linux/fcntl.h>
2826 +#include <linux/ptrace.h>
2827 +#include <linux/ioport.h>
2828 +#include <linux/mm.h>
2829 +#include <linux/init.h>
2830 +#include <linux/highmem.h>
2831 +#include <asm/system.h>
2832 +#include <asm/io.h>
2833 +#include <asm/segment.h>
2834 +#include <asm/bitops.h>
2835 +#include <asm/system.h>
2836 +#include <asm/kgdb_local.h>
2837 +#ifdef CONFIG_KGDB_USER_CONSOLE
2838 +extern void kgdb_console_finit(void);
2841 +#define TEST_EXISTANCE
2843 +#define dbprintk(s) printk s
2845 +#define dbprintk(s)
2847 +#define TEST_INTERRUPT_off
2848 +#ifdef TEST_INTERRUPT
2849 +#define intprintk(s) printk s
2851 +#define intprintk(s)
2854 +#define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
2856 +#define GDB_BUF_SIZE 512 /* power of 2, please */
2858 +static char gdb_buf[GDB_BUF_SIZE];
2859 +static int gdb_buf_in_inx;
2860 +static atomic_t gdb_buf_in_cnt;
2861 +static int gdb_buf_out_inx;
2863 +struct async_struct *gdb_async_info;
2864 +static int gdb_async_irq;
2866 +#define outb_px(a,b) outb_p(b,a)
2868 +static void program_uart(struct async_struct *info);
2869 +static void write_char(struct async_struct *info, int chr);
2871 + * Get a byte from the hardware data buffer and return it
2874 +read_data_bfr(struct async_struct *info)
2876 + char it = inb_p(info->port + UART_LSR);
2878 + if (it & UART_LSR_DR)
2879 + return (inb_p(info->port + UART_RX));
2881 + * If we have a framing error assume somebody messed with
2882 + * our uart. Reprogram it and send '-' both ways...
2885 + program_uart(info);
2886 + write_char(info, '-');
2891 +} /* read_data_bfr */
2894 + * Get a char if available, return -1 if nothing available.
2895 + * Empty the receive buffer first, then look at the interface hardware.
2897 + * Locking here is a bit of a problem. We MUST not lock out communication
2898 + * if we are trying to talk to gdb about a kgdb entry. ON the other hand
2899 + * we can loose chars in the console pass thru if we don't lock. It is also
2900 + * possible that we could hold the lock or be waiting for it when kgdb
2901 + * NEEDS to talk. Since kgdb locks down the world, it does not need locks.
2902 + * We do, of course have possible issues with interrupting a uart operation,
2903 + * but we will just depend on the uart status to help keep that straight.
2906 +static spinlock_t uart_interrupt_lock = SPIN_LOCK_UNLOCKED;
2908 +extern spinlock_t kgdb_spinlock;
2912 +read_char(struct async_struct *info)
2915 + unsigned long flags;
2916 + local_irq_save(flags);
2918 + if (!spin_is_locked(&kgdb_spinlock)) {
2919 + spin_lock(&uart_interrupt_lock);
2922 + if (atomic_read(&gdb_buf_in_cnt) != 0) { /* intr routine has q'd chars */
2923 + chr = gdb_buf[gdb_buf_out_inx++];
2924 + gdb_buf_out_inx &= (GDB_BUF_SIZE - 1);
2925 + atomic_dec(&gdb_buf_in_cnt);
2927 + chr = read_data_bfr(info);
2930 + if (!spin_is_locked(&kgdb_spinlock)) {
2931 + spin_unlock(&uart_interrupt_lock);
2934 + local_irq_restore(flags);
2939 + * Wait until the interface can accept a char, then write it.
2942 +write_char(struct async_struct *info, int chr)
2944 + while (!(inb_p(info->port + UART_LSR) & UART_LSR_THRE)) ;
2946 + outb_p(chr, info->port + UART_TX);
2951 + * Mostly we don't need a spinlock, but since the console goes
2952 + * thru here with interrutps on, well, we need to catch those
2956 + * This is the receiver interrupt routine for the GDB stub.
2957 + * It will receive a limited number of characters of input
2958 + * from the gdb host machine and save them up in a buffer.
2960 + * When the gdb stub routine getDebugChar() is called it
2961 + * draws characters out of the buffer until it is empty and
2962 + * then reads directly from the serial port.
2964 + * We do not attempt to write chars from the interrupt routine
2965 + * since the stubs do all of that via putDebugChar() which
2966 + * writes one byte after waiting for the interface to become
2969 + * The debug stubs like to run with interrupts disabled since,
2970 + * after all, they run as a consequence of a breakpoint in
2973 + * Perhaps someone who knows more about the tty driver than I
2974 + * care to learn can make this work for any low level serial
2978 +gdb_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2980 + struct async_struct *info;
2981 + unsigned long flags;
2983 + info = gdb_async_info;
2984 + if (!info || !info->tty || irq != gdb_async_irq)
2987 + local_irq_save(flags);
2988 + spin_lock(&uart_interrupt_lock);
2990 + int chr = read_data_bfr(info);
2991 + intprintk(("Debug char on int: %x hex\n", chr));
2995 + if (chr == 3) { /* Ctrl-C means remote interrupt */
3000 + if (atomic_read(&gdb_buf_in_cnt) >= GDB_BUF_SIZE) {
3001 + /* buffer overflow tosses early char */
3004 + gdb_buf[gdb_buf_in_inx++] = chr;
3005 + gdb_buf_in_inx &= (GDB_BUF_SIZE - 1);
3006 + } while (inb_p(info->port + UART_IIR) & UART_IIR_RDI);
3007 + spin_unlock(&uart_interrupt_lock);
3008 + local_irq_restore(flags);
3009 + return IRQ_HANDLED;
3010 +} /* gdb_interrupt */
3013 + * Just a NULL routine for testing.
3020 +/* These structure are filled in with values defined in asm/kgdb_local.h
3022 +static struct serial_state state = SB_STATE;
3023 +static struct async_struct local_info = SB_INFO;
3024 +static int ok_to_enable_ints = 0;
3025 +static void kgdb_enable_ints_now(void);
3027 +extern char *kgdb_version;
3029 + * Hook an IRQ for KGDB.
3031 + * This routine is called from putDebugChar, below.
3033 +static int ints_disabled = 1;
3035 +gdb_hook_interrupt(struct async_struct *info, int verb)
3037 + struct serial_state *state = info->state;
3038 + unsigned long flags;
3040 +#ifdef TEST_EXISTANCE
3041 + int scratch, scratch2;
3044 + /* The above fails if memory managment is not set up yet.
3045 + * Rather than fail the set up, just keep track of the fact
3046 + * and pick up the interrupt thing later.
3048 + gdb_async_info = info;
3049 + port = gdb_async_info->port;
3050 + gdb_async_irq = state->irq;
3052 + printk("kgdb %s : port =%x, IRQ=%d, divisor =%d\n",
3055 + gdb_async_irq, gdb_async_info->state->custom_divisor);
3057 + local_irq_save(flags);
3058 +#ifdef TEST_EXISTANCE
3059 + /* Existance test */
3060 + /* Should not need all this, but just in case.... */
3062 + scratch = inb_p(port + UART_IER);
3063 + outb_px(port + UART_IER, 0);
3064 + outb_px(0xff, 0x080);
3065 + scratch2 = inb_p(port + UART_IER);
3066 + outb_px(port + UART_IER, scratch);
3069 + ("gdb_hook_interrupt: Could not clear IER, not a UART!\n");
3070 + local_irq_restore(flags);
3071 + return 1; /* We failed; there's nothing here */
3073 + scratch2 = inb_p(port + UART_LCR);
3074 + outb_px(port + UART_LCR, 0xBF); /* set up for StarTech test */
3075 + outb_px(port + UART_EFR, 0); /* EFR is the same as FCR */
3076 + outb_px(port + UART_LCR, 0);
3077 + outb_px(port + UART_FCR, UART_FCR_ENABLE_FIFO);
3078 + scratch = inb_p(port + UART_IIR) >> 6;
3079 + if (scratch == 1) {
3080 + printk("gdb_hook_interrupt: Undefined UART type!"
3081 + " Not a UART! \n");
3082 + local_irq_restore(flags);
3085 + dbprintk(("gdb_hook_interrupt: UART type "
3086 + "is %d where 0=16450, 2=16550 3=16550A\n", scratch));
3088 + scratch = inb_p(port + UART_MCR);
3089 + outb_px(port + UART_MCR, UART_MCR_LOOP | scratch);
3090 + outb_px(port + UART_MCR, UART_MCR_LOOP | 0x0A);
3091 + scratch2 = inb_p(port + UART_MSR) & 0xF0;
3092 + outb_px(port + UART_MCR, scratch);
3093 + if (scratch2 != 0x90) {
3094 + printk("gdb_hook_interrupt: "
3095 + "Loop back test failed! Not a UART!\n");
3096 + local_irq_restore(flags);
3097 + return scratch2 + 1000; /* force 0 to fail */
3099 +#endif /* test existance */
3100 + program_uart(info);
3101 + local_irq_restore(flags);
3105 +} /* gdb_hook_interrupt */
3108 +program_uart(struct async_struct *info)
3110 + int port = info->port;
3112 + (void) inb_p(port + UART_RX);
3113 + outb_px(port + UART_IER, 0);
3115 + (void) inb_p(port + UART_RX); /* serial driver comments say */
3116 + (void) inb_p(port + UART_IIR); /* this clears the interrupt regs */
3117 + (void) inb_p(port + UART_MSR);
3118 + outb_px(port + UART_LCR, UART_LCR_WLEN8 | UART_LCR_DLAB);
3119 + outb_px(port + UART_DLL, info->state->custom_divisor & 0xff); /* LS */
3120 + outb_px(port + UART_DLM, info->state->custom_divisor >> 8); /* MS */
3121 + outb_px(port + UART_MCR, info->MCR);
3123 + outb_px(port + UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1 | UART_FCR_CLEAR_XMIT | UART_FCR_CLEAR_RCVR); /* set fcr */
3124 + outb_px(port + UART_LCR, UART_LCR_WLEN8); /* reset DLAB */
3125 + outb_px(port + UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1); /* set fcr */
3126 + if (!ints_disabled) {
3127 + intprintk(("KGDB: Sending %d to port %x offset %d\n",
3128 + gdb_async_info->IER,
3129 + (int) gdb_async_info->port, UART_IER));
3130 + outb_px(gdb_async_info->port + UART_IER, gdb_async_info->IER);
3138 + * This is a GDB stub routine. It waits for a character from the
3139 + * serial interface and then returns it. If there is no serial
3140 + * interface connection then it returns a bogus value which will
3141 + * almost certainly cause the system to hang. In the
3143 +int kgdb_in_isr = 0;
3144 +int kgdb_in_lsr = 0;
3145 +extern spinlock_t kgdb_spinlock;
3147 +/* Caller takes needed protections */
3152 + volatile int chr, dum, time, end_time;
3154 + dbprintk(("getDebugChar(port %x): ", gdb_async_info->port));
3156 + if (gdb_async_info == NULL) {
3157 + gdb_hook_interrupt(&local_info, 0);
3160 + * This trick says if we wait a very long time and get
3161 + * no char, return the -1 and let the upper level deal
3165 + end_time = time + 2;
3166 + while (((chr = read_char(gdb_async_info)) == -1) &&
3167 + (end_time - time) > 0) {
3171 + * This covers our butts if some other code messes with
3172 + * our uart, hay, it happens :o)
3175 + program_uart(gdb_async_info);
3177 + dbprintk(("%c\n", chr > ' ' && chr < 0x7F ? chr : ' '));
3180 +} /* getDebugChar */
3182 +static int count = 3;
3183 +static spinlock_t one_at_atime = SPIN_LOCK_UNLOCKED;
3186 +kgdb_enable_ints(void)
3188 + if (gdb_async_info == NULL) {
3189 + gdb_hook_interrupt(&local_info, 1);
3191 + ok_to_enable_ints = 1;
3192 + kgdb_enable_ints_now();
3193 +#ifdef CONFIG_KGDB_USER_CONSOLE
3194 + kgdb_console_finit();
3199 +#ifdef CONFIG_SERIAL_8250
3200 +void shutdown_for_kgdb(struct async_struct *gdb_async_info);
3203 +#ifdef CONFIG_DISCONTIGMEM
3204 +static inline int kgdb_mem_init_done(void)
3206 + return highmem_start_page != NULL;
3209 +static inline int kgdb_mem_init_done(void)
3211 + return max_mapnr != 0;
3216 +kgdb_enable_ints_now(void)
3218 + if (!spin_trylock(&one_at_atime))
3220 + if (!ints_disabled)
3222 + if (kgdb_mem_init_done() &&
3223 + ints_disabled) { /* don't try till mem init */
3224 +#ifdef CONFIG_SERIAL_8250
3226 + * The ifdef here allows the system to be configured
3227 + * without the serial driver.
3228 + * Don't make it a module, however, it will steal the port
3230 + shutdown_for_kgdb(gdb_async_info);
3232 + ints_disabled = request_irq(gdb_async_info->state->irq,
3234 + IRQ_T(gdb_async_info),
3235 + "KGDB-stub", NULL);
3236 + intprintk(("KGDB: request_irq returned %d\n", ints_disabled));
3238 + if (!ints_disabled) {
3239 + intprintk(("KGDB: Sending %d to port %x offset %d\n",
3240 + gdb_async_info->IER,
3241 + (int) gdb_async_info->port, UART_IER));
3242 + outb_px(gdb_async_info->port + UART_IER, gdb_async_info->IER);
3245 + spin_unlock(&one_at_atime);
3251 + * This is a GDB stub routine. It waits until the interface is ready
3252 + * to transmit a char and then sends it. If there is no serial
3253 + * interface connection then it simply returns to its caller, having
3254 + * pretended to send the char. Caller takes needed protections.
3257 +putDebugChar(int chr)
3259 + dbprintk(("putDebugChar(port %x): chr=%02x '%c', ints_on=%d\n",
3260 + gdb_async_info->port,
3262 + chr > ' ' && chr < 0x7F ? chr : ' ', ints_disabled ? 0 : 1));
3264 + if (gdb_async_info == NULL) {
3265 + gdb_hook_interrupt(&local_info, 0);
3268 + write_char(gdb_async_info, chr); /* this routine will wait */
3269 + count = (chr == '#') ? 0 : count + 1;
3270 + if ((count == 2)) { /* try to enable after */
3271 + if (ints_disabled & ok_to_enable_ints)
3272 + kgdb_enable_ints_now(); /* try to enable after */
3274 + /* We do this a lot because, well we really want to get these
3275 + * interrupts. The serial driver will clear these bits when it
3276 + * initializes the chip. Every thing else it does is ok,
3279 + if (!ints_disabled) {
3280 + outb_px(gdb_async_info->port + UART_IER,
3281 + gdb_async_info->IER);
3285 +} /* putDebugChar */
3287 +module_init(kgdb_enable_ints);
3288 Index: linux-2.6.10/arch/i386/lib/Makefile
3289 ===================================================================
3290 --- linux-2.6.10.orig/arch/i386/lib/Makefile 2004-12-25 05:33:50.000000000 +0800
3291 +++ linux-2.6.10/arch/i386/lib/Makefile 2005-04-05 12:48:05.194627376 +0800
3294 lib-$(CONFIG_X86_USE_3DNOW) += mmx.o
3295 lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o
3296 +lib-$(CONFIG_KGDB) += kgdb_serial.o
3297 Index: linux-2.6.10/arch/i386/Kconfig.debug
3298 ===================================================================
3299 --- linux-2.6.10.orig/arch/i386/Kconfig.debug 2004-12-25 05:34:45.000000000 +0800
3300 +++ linux-2.6.10/arch/i386/Kconfig.debug 2005-04-05 12:48:05.204625856 +0800
3302 depends on X86_LOCAL_APIC && !X86_VISWS
3305 +source "arch/i386/Kconfig.kgdb"
3308 Index: linux-2.6.10/arch/i386/kernel/entry.S
3309 ===================================================================
3310 --- linux-2.6.10.orig/arch/i386/kernel/entry.S 2005-04-05 12:48:03.413898088 +0800
3311 +++ linux-2.6.10/arch/i386/kernel/entry.S 2005-04-05 12:48:05.244619776 +0800
3313 #include <asm/smp.h>
3314 #include <asm/page.h>
3315 #include "irq_vectors.h"
3316 + /* We do not recover from a stack overflow, but at least
3317 + * we know it happened and should be able to track it down.
3319 +#ifdef CONFIG_STACK_OVERFLOW_TEST
3320 +#define STACK_OVERFLOW_TEST \
3321 + testl $(THREAD_SIZE - 512),%esp; \
3323 + call stack_overflow; \
3326 +#define STACK_OVERFLOW_TEST
3329 #define nr_syscalls ((syscall_table_size)/4)
3333 movl $(__USER_DS), %edx; \
3337 + STACK_OVERFLOW_TEST
3339 #define RESTORE_INT_REGS \
3342 # sysenter call handler stub
3343 ENTRY(sysenter_entry)
3344 movl TSS_sysenter_esp0(%esp),%esp
3345 + .globl sysenter_past_esp
3349 @@ -261,6 +275,19 @@
3350 testw $_TIF_ALLWORK_MASK, %cx # current->work
3351 jne syscall_exit_work
3353 +#ifdef CONFIG_TRAP_BAD_SYSCALL_EXITS
3354 + movl EFLAGS(%esp), %eax # mix EFLAGS and CS
3355 + movb CS(%esp), %al
3356 + testl $(VM_MASK | 3), %eax
3357 + jz resume_kernelX # returning to kernel or vm86-space
3359 + cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
3368 # perform work that needs to be done immediately before resumption
3369 Index: linux-2.6.10/arch/i386/kernel/traps.c
3370 ===================================================================
3371 --- linux-2.6.10.orig/arch/i386/kernel/traps.c 2005-03-31 16:20:09.000000000 +0800
3372 +++ linux-2.6.10/arch/i386/kernel/traps.c 2005-04-05 12:48:05.221623272 +0800
3373 @@ -105,6 +105,39 @@
3378 +extern void sysenter_past_esp(void);
3379 +#include <asm/kgdb.h>
3380 +#include <linux/init.h>
3381 +void set_intr_gate(unsigned int n, void *addr);
3382 +static void set_intr_usr_gate(unsigned int n, void *addr);
3384 + * Should be able to call this breakpoint() very early in
3385 + * bring up. Just hard code the call where needed.
3386 + * The breakpoint() code is here because set_?_gate() functions
3387 + * are local (static) to trap.c. They need be done only once,
3388 + * but it does not hurt to do them over.
3390 +void breakpoint(void)
3392 + set_intr_usr_gate(3,&int3); /* disable ints on trap */
3393 + set_intr_gate(1,&debug);
3394 + set_intr_gate(14,&page_fault);
3398 +#define CHK_REMOTE_DEBUG(trapnr,signr,error_code,regs,after) \
3400 + if (!user_mode(regs) ) \
3402 + kgdb_handle_exception(trapnr, signr, error_code, regs); \
3404 + } else if ((trapnr == 3) && (regs->eflags &0x200)) local_irq_enable(); \
3407 +#define CHK_REMOTE_DEBUG(trapnr,signr,error_code,regs,after)
3410 static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
3412 return p > (void *)tinfo &&
3413 @@ -332,6 +365,15 @@
3418 + /* This is about the only place we want to go to kgdb even if in
3419 + * user mode. But we must go in via a trap so within kgdb we will
3420 + * always be in kernel mode.
3422 + if (user_mode(regs))
3425 + CHK_REMOTE_DEBUG(0,SIGTRAP,err,regs,)
3426 notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
3427 show_registers(regs);
3430 #define DO_ERROR(trapnr, signr, str, name) \
3431 fastcall void do_##name(struct pt_regs * regs, long error_code) \
3433 + CHK_REMOTE_DEBUG(trapnr,signr,error_code,regs,) \
3434 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
3438 #define DO_VM86_ERROR(trapnr, signr, str, name) \
3439 fastcall void do_##name(struct pt_regs * regs, long error_code) \
3441 + CHK_REMOTE_DEBUG(trapnr, signr, error_code,regs, return) \
3442 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
3448 if (!fixup_exception(regs)) {
3449 + CHK_REMOTE_DEBUG(13,SIGSEGV,error_code,regs,)
3450 if (notify_die(DIE_GPF, "general protection fault", regs,
3451 error_code, 13, SIGSEGV) == NOTIFY_STOP)
3453 @@ -716,12 +761,35 @@
3454 * allowing programs to debug themselves without the ptrace()
3457 - if ((regs->xcs & 3) == 0)
3458 - goto clear_TF_reenable;
3461 + * I think this is the only "real" case of a TF in the kernel
3462 + * that really belongs to user space. Others are
3463 + * "Ours all ours!"
3465 + if (((regs->xcs & 3) == 0) && ((void *)regs->eip == sysenter_past_esp))
3466 + goto clear_TF_reenable;
3468 + if ((regs->xcs & 3) == 0)
3469 + goto clear_TF_reenable;
3471 if ((tsk->ptrace & (PT_DTRACE|PT_PTRACED)) == PT_DTRACE)
3477 + * If this is a kernel mode trap, we need to reset db7 to allow us
3478 + * to continue sanely ALSO skip the signal delivery
3480 + if ((regs->xcs & 3) == 0)
3483 + /* if not kernel, allow ints but only if they were on */
3484 + if (regs->eflags & 0x200)
3485 + local_irq_enable();
3488 /* Ok, finally something we can handle */
3489 tsk->thread.trap_no = 1;
3490 tsk->thread.error_code = error_code;
3492 __asm__("movl %0,%%db7"
3495 + CHK_REMOTE_DEBUG(1,SIGTRAP,error_code,regs,)
3499 @@ -999,6 +1068,12 @@
3501 _set_gate(idt_table+n,5,0,0,(gdt_entry<<3));
3504 +void set_intr_usr_gate(unsigned int n, void *addr)
3506 + _set_gate(idt_table+n,14,3,addr,__KERNEL_CS);
3511 void __init trap_init(void)
3512 @@ -1016,7 +1091,11 @@
3513 set_trap_gate(0,÷_error);
3514 set_intr_gate(1,&debug);
3515 set_intr_gate(2,&nmi);
3516 +#ifndef CONFIG_KGDB
3517 set_system_intr_gate(3, &int3); /* int3-5 can be called from all */
3519 + set_intr_usr_gate(3,&int3); /* int3-5 can be called from all */
3521 set_system_gate(4,&overflow);
3522 set_system_gate(5,&bounds);
3523 set_trap_gate(6,&invalid_op);
3524 Index: linux-2.6.10/arch/i386/kernel/nmi.c
3525 ===================================================================
3526 --- linux-2.6.10.orig/arch/i386/kernel/nmi.c 2005-03-31 15:57:19.000000000 +0800
3527 +++ linux-2.6.10/arch/i386/kernel/nmi.c 2005-04-05 12:48:05.222623120 +0800
3530 #include "mach_traps.h"
3533 +#include <asm/kgdb.h>
3535 +unsigned int nmi_watchdog = NMI_IO_APIC;
3537 +unsigned int nmi_watchdog = NMI_LOCAL_APIC;
3540 unsigned int nmi_watchdog = NMI_NONE;
3543 extern int unknown_nmi_panic;
3544 static unsigned int nmi_hz = HZ;
3545 static unsigned int nmi_perfctr_msr; /* the MSR to reset in NMI handler */
3547 for (i = 0; i < NR_CPUS; i++)
3548 alert_counter[i] = 0;
3551 +int tune_watchdog = 5*HZ;
3554 extern void die_nmi(struct pt_regs *, const char *msg);
3556 @@ -480,14 +493,25 @@
3557 int sum, cpu = smp_processor_id();
3559 sum = irq_stat[cpu].apic_timer_irqs;
3561 - if (last_irq_sums[cpu] == sum) {
3563 + if (!in_kgdb(regs) && last_irq_sums[cpu] == sum) {
3566 + if (last_irq_sums[cpu] == sum) {
3569 * Ayiee, looks like this CPU is stuck ...
3570 * wait a few IRQs (5 seconds) before doing the oops ...
3572 alert_counter[cpu]++;
3573 - if (alert_counter[cpu] == 30*nmi_hz)
3575 + if (alert_counter[cpu] == tune_watchdog) {
3576 + kgdb_handle_exception(2, SIGPWR, 0, regs);
3577 + last_irq_sums[cpu] = sum;
3578 + alert_counter[cpu] = 0;
3581 + if (alert_counter[cpu] == 5*nmi_hz)
3582 die_nmi(regs, "NMI Watchdog detected LOCKUP");
3584 last_irq_sums[cpu] = sum;
3585 Index: linux-2.6.10/arch/i386/kernel/kgdb_stub.c
3586 ===================================================================
3587 --- linux-2.6.10.orig/arch/i386/kernel/kgdb_stub.c 2005-04-05 19:01:49.158500672 +0800
3588 +++ linux-2.6.10/arch/i386/kernel/kgdb_stub.c 2005-04-05 12:48:05.242620080 +0800
3592 + * This program is free software; you can redistribute it and/or modify it
3593 + * under the terms of the GNU General Public License as published by the
3594 + * Free Software Foundation; either version 2, or (at your option) any
3597 + * This program is distributed in the hope that it will be useful, but
3598 + * WITHOUT ANY WARRANTY; without even the implied warranty of
3599 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3600 + * General Public License for more details.
3605 + * Copyright (c) 2000 VERITAS Software Corporation.
3608 +/****************************************************************************
3609 + * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
3611 + * Module name: remcom.c $
3612 + * Revision: 1.34 $
3613 + * Date: 91/03/09 12:29:49 $
3614 + * Contributor: Lake Stevens Instrument Division$
3616 + * Description: low level support for gdb debugger. $
3618 + * Considerations: only works on target hardware $
3620 + * Written by: Glenn Engel $
3621 + * Updated by: David Grothe <dave@gcom.com>
3622 + * ModuleState: Experimental $
3624 + * NOTES: See Below $
3626 + * Modified for 386 by Jim Kingdon, Cygnus Support.
3627 + * Compatibility with 2.1.xx kernel by David Grothe <dave@gcom.com>
3629 + * Changes to allow auto initilization. All that is needed is that it
3630 + * be linked with the kernel and a break point (int 3) be executed.
3631 + * The header file <asm/kgdb.h> defines BREAKPOINT to allow one to do
3632 + * this. It should also be possible, once the interrupt system is up, to
3633 + * call putDebugChar("+"). Once this is done, the remote debugger should
3634 + * get our attention by sending a ^C in a packet. George Anzinger
3635 + * <george@mvista.com>
3636 + * Integrated into 2.2.5 kernel by Tigran Aivazian <tigran@sco.com>
3637 + * Added thread support, support for multiple processors,
3638 + * support for ia-32(x86) hardware debugging.
3639 + * Amit S. Kale ( akale@veritas.com )
3642 + * To enable debugger support, two things need to happen. One, a
3643 + * call to set_debug_traps() is necessary in order to allow any breakpoints
3644 + * or error conditions to be properly intercepted and reported to gdb.
3645 + * Two, a breakpoint needs to be generated to begin communication. This
3646 + * is most easily accomplished by a call to breakpoint(). Breakpoint()
3647 + * simulates a breakpoint by executing an int 3.
3651 + * The following gdb commands are supported:
3653 + * command function Return value
3655 + * g return the value of the CPU registers hex data or ENN
3656 + * G set the value of the CPU registers OK or ENN
3658 + * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
3659 + * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN
3661 + * c Resume at current address SNN ( signal NN)
3662 + * cAA..AA Continue at address AA..AA SNN
3664 + * s Step one instruction SNN
3665 + * sAA..AA Step one instruction from AA..AA SNN
3669 + * ? What was the last sigval ? SNN (signal NN)
3671 + * All commands and responses are sent with a packet which includes a
3672 + * checksum. A packet consists of
3674 + * $<packet info>#<checksum>.
3677 + * <packet info> :: <characters representing the command or response>
3678 + * <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>>
3680 + * When a packet is received, it is first acknowledged with either '+' or '-'.
3681 + * '+' indicates a successful transfer. '-' indicates a failed transfer.
3686 + * $m0,10#2a +$00010203040506070809101112131415#42
3688 + ****************************************************************************/
3689 +#define KGDB_VERSION "<20030915.1651.33>"
3690 +#include <linux/config.h>
3691 +#include <linux/types.h>
3692 +#include <asm/string.h> /* for strcpy */
3693 +#include <linux/kernel.h>
3694 +#include <linux/sched.h>
3695 +#include <asm/vm86.h>
3696 +#include <asm/system.h>
3697 +#include <asm/ptrace.h> /* for linux pt_regs struct */
3698 +#include <asm/kgdb_local.h>
3699 +#include <linux/list.h>
3700 +#include <asm/atomic.h>
3701 +#include <asm/processor.h>
3702 +#include <linux/irq.h>
3703 +#include <asm/desc.h>
3705 +/************************************************************************
3707 + * external low-level support routines
3709 +typedef void (*Function) (void); /* pointer to a function */
3711 +/* Thread reference */
3712 +typedef unsigned char threadref[8];
3714 +extern void putDebugChar(int); /* write a single character */
3715 +extern int getDebugChar(void); /* read and return a single char */
3717 +/************************************************************************/
3718 +/* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
3719 +/* at least NUMREGBYTES*2 are needed for register packets */
3720 +/* Longer buffer is needed to list all threads */
3723 +char *kgdb_version = KGDB_VERSION;
3725 +/* debug > 0 prints ill-formed commands in valid packets & checksum errors */
3726 +int debug_regs = 0; /* set to non-zero to print registers */
3728 +/* filled in by an external module */
3729 +char *gdb_module_offsets;
3731 +static const char hexchars[] = "0123456789abcdef";
3733 +/* Number of bytes of registers. */
3734 +#define NUMREGBYTES 64
3736 + * Note that this register image is in a different order than
3737 + * the register image that Linux produces at interrupt time.
3739 + * Linux's register image is defined by struct pt_regs in ptrace.h.
3740 + * Just why GDB uses a different order is a historical mystery.
3742 +enum regnames { _EAX, /* 0 */
3750 + _PC /* 8 also known as eip */ ,
3751 + _PS /* 9 also known as eflags */ ,
3760 +/*************************** ASSEMBLY CODE MACROS *************************/
3762 + * Put the error code here just in case the user cares.
3763 + * Likewise, the vector number here (since GDB only gets the signal
3764 + * number through the usual means, and that's not very specific).
3765 + * The called_from is the return address so he can tell how we entered kgdb.
3766 + * This will allow him to seperate out the various possible entries.
3768 +#define REMOTE_DEBUG 0 /* set != to turn on printing (also available in info) */
3770 +#define PID_MAX PID_MAX_DEFAULT
3773 +void smp_send_nmi_allbutself(void);
3774 +#define IF_SMP(x) x
3776 +#ifndef CONFIG_NO_KGDB_CPUS
3777 +#define CONFIG_NO_KGDB_CPUS 2
3779 +#if CONFIG_NO_KGDB_CPUS > NR_CPUS
3780 +#define MAX_NO_CPUS NR_CPUS
3782 +#define MAX_NO_CPUS CONFIG_NO_KGDB_CPUS
3784 +#define hold_init hold_on_sstep: 1,
3785 +#define MAX_CPU_MASK (unsigned long)((1LL << MAX_NO_CPUS) - 1LL)
3786 +#define NUM_CPUS num_online_cpus()
3791 +#define MAX_NO_CPUS 1
3794 +#define NOCPU (struct task_struct *)0xbad1fbad
3798 + void *called_from;
3799 + long long entry_tsc;
3802 + int print_debug_info;
3804 + int hold_on_sstep;
3806 + volatile struct task_struct *task;
3809 + struct pt_regs *regs;
3810 + } cpus_waiting[MAX_NO_CPUS];
3812 +} kgdb_info = {hold_init print_debug_info:REMOTE_DEBUG, vector:-1};
3816 +#define used_m kgdb_info.used_malloc
3818 + * This is little area we set aside to contain the stack we
3819 + * need to build to allow gdb to call functions. We use one
3820 + * per cpu to avoid locking issues. We will do all this work
3821 + * with interrupts off so that should take care of the protection
3824 +#define LOOKASIDE_SIZE 200 /* should be more than enough */
3825 +#define MALLOC_MAX 200 /* Max malloc size */
3828 + int array[LOOKASIDE_SIZE];
3829 +} fn_call_lookaside[MAX_NO_CPUS];
3831 +static int trap_cpu;
3832 +static unsigned int OLD_esp;
3834 +#define END_OF_LOOKASIDE &fn_call_lookaside[trap_cpu].array[LOOKASIDE_SIZE]
3835 +#define IF_BIT 0x200
3836 +#define TF_BIT 0x100
3838 +#define MALLOC_ROUND 8-1
3840 +static char malloc_array[MALLOC_MAX];
3841 +IF_SMP(static void to_gdb(const char *mess));
3846 + if (size <= (MALLOC_MAX - used_m)) {
3847 + int old_used = used_m;
3848 + used_m += ((size + MALLOC_ROUND) & (~MALLOC_ROUND));
3849 + return &malloc_array[old_used];
3856 + * Gdb calls functions by pushing agruments, including a return address
3857 + * on the stack and the adjusting EIP to point to the function. The
3858 + * whole assumption in GDB is that we are on a different stack than the
3859 + * one the "user" i.e. code that hit the break point, is on. This, of
3860 + * course is not true in the kernel. Thus various dodges are needed to
3861 + * do the call without directly messing with EIP (which we can not change
3862 + * as it is just a location and not a register. To adjust it would then
3863 + * require that we move every thing below EIP up or down as needed. This
3864 + * will not work as we may well have stack relative pointer on the stack
3865 + * (such as the pointer to regs, for example).
3867 + * So here is what we do:
3868 + * We detect gdb attempting to store into the stack area and instead, store
3869 + * into the fn_call_lookaside.array at the same relative location as if it
3870 + * were the area ESP pointed at. We also trap ESP modifications
3871 + * and uses these to adjust fn_call_lookaside.esp. On entry
3872 + * fn_call_lookaside.esp will be set to point at the last entry in
3873 + * fn_call_lookaside.array. This allows us to check if it has changed, and
3874 + * if so, on exit, we add the registers we will use to do the move and a
3875 + * trap/ interrupt return exit sequence. We then adjust the eflags in the
3876 + * regs array (remember we now have a copy in the fn_call_lookaside.array) to
3877 + * kill the interrupt bit, AND we change EIP to point at our set up stub.
3878 + * As part of the register set up we preset the registers to point at the
3879 + * begining and end of the fn_call_lookaside.array, so all the stub needs to
3880 + * do is move words from the array to the stack until ESP= the desired value
3881 + * then do the rti. This will then transfer to the desired function with
3882 + * all the correct registers. Nifty huh?
3884 +extern asmlinkage void fn_call_stub(void);
3885 +extern asmlinkage void fn_rtn_stub(void);
3887 +__asm__("fn_rtn_stub:\n\t"
3888 + "movl %eax,%esp\n\t"
3889 + "fn_call_stub:\n\t"
3891 + "addl $-4,%ebx\n\t"
3892 + "movl (%ebx), %eax\n\t"
3894 + "cmpl %esp,%ecx\n\t"
3901 +#define gdb_i386vector kgdb_info.vector
3902 +#define gdb_i386errcode kgdb_info.errcode
3903 +#define waiting_cpus kgdb_info.cpus_waiting
3904 +#define remote_debug kgdb_info.print_debug_info
3905 +#define hold_cpu(cpu) kgdb_info.cpus_waiting[cpu].hold
3909 +static int in_kgdb_called;
3910 +static spinlock_t waitlocks[MAX_NO_CPUS] =
3911 + {[0 ... MAX_NO_CPUS - 1] = SPIN_LOCK_UNLOCKED };
3913 + * The following array has the thread pointer of each of the "other"
3914 + * cpus. We make it global so it can be seen by gdb.
3916 +volatile int in_kgdb_entry_log[MAX_NO_CPUS];
3917 +volatile struct pt_regs *in_kgdb_here_log[MAX_NO_CPUS];
3919 +static spinlock_t continuelocks[MAX_NO_CPUS];
3921 +spinlock_t kgdb_spinlock = SPIN_LOCK_UNLOCKED;
3922 +/* waiters on our spinlock plus us */
3923 +static atomic_t spinlock_waiters = ATOMIC_INIT(1);
3924 +static int spinlock_count = 0;
3925 +static int spinlock_cpu = 0;
3927 + * Note we use nested spin locks to account for the case where a break
3928 + * point is encountered when calling a function by user direction from
3929 + * kgdb. Also there is the memory exception recursion to account for.
3930 + * Well, yes, but this lets other cpus thru too. Lets add a
3931 + * cpu id to the lock.
3933 +#define KGDB_SPIN_LOCK(x) if( spinlock_count == 0 || \
3934 + spinlock_cpu != smp_processor_id()){\
3935 + atomic_inc(&spinlock_waiters); \
3936 + while (! spin_trylock(x)) {\
3939 + atomic_dec(&spinlock_waiters); \
3940 + spinlock_count = 1; \
3941 + spinlock_cpu = smp_processor_id(); \
3943 + spinlock_count++; \
3945 +#define KGDB_SPIN_UNLOCK(x) if( --spinlock_count == 0) spin_unlock(x)
3947 +unsigned kgdb_spinlock = 0;
3948 +#define KGDB_SPIN_LOCK(x) --*x
3949 +#define KGDB_SPIN_UNLOCK(x) ++*x
3955 + if ((ch >= 'a') && (ch <= 'f'))
3956 + return (ch - 'a' + 10);
3957 + if ((ch >= '0') && (ch <= '9'))
3958 + return (ch - '0');
3959 + if ((ch >= 'A') && (ch <= 'F'))
3960 + return (ch - 'A' + 10);
3964 +/* scan for the sequence $<data>#<checksum> */
3966 +getpacket(char *buffer)
3968 + unsigned char checksum;
3969 + unsigned char xmitcsum;
3975 + /* wait around for the start character, ignore all other characters */
3976 + while ((ch = (getDebugChar() & 0x7f)) != '$') ;
3982 + /* now, read until a # or end of buffer is found */
3983 + while (count < BUFMAX) {
3984 + ch = getDebugChar() & 0x7f;
3987 + checksum = checksum + ch;
3988 + buffer[count] = ch;
3989 + count = count + 1;
3991 + buffer[count] = 0;
3994 + xmitcsum = hex(getDebugChar() & 0x7f) << 4;
3995 + xmitcsum += hex(getDebugChar() & 0x7f);
3996 + if ((remote_debug) && (checksum != xmitcsum)) {
3998 + ("bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n",
3999 + checksum, xmitcsum, buffer);
4002 + if (checksum != xmitcsum)
4003 + putDebugChar('-'); /* failed checksum */
4005 + putDebugChar('+'); /* successful transfer */
4006 + /* if a sequence char is present, reply the sequence ID */
4007 + if (buffer[2] == ':') {
4008 + putDebugChar(buffer[0]);
4009 + putDebugChar(buffer[1]);
4010 + /* remove sequence chars from buffer */
4011 + count = strlen(buffer);
4012 + for (i = 3; i <= count; i++)
4013 + buffer[i - 3] = buffer[i];
4017 + } while (checksum != xmitcsum);
4020 + printk("R:%s\n", buffer);
4023 +/* send the packet in buffer. */
4026 +putpacket(char *buffer)
4028 + unsigned char checksum;
4032 + /* $<packet info>#<checksum>. */
4035 + printk("T:%s\n", buffer);
4036 + putDebugChar('$');
4040 + while ((ch = buffer[count])) {
4046 + putDebugChar('#');
4047 + putDebugChar(hexchars[checksum >> 4]);
4048 + putDebugChar(hexchars[checksum % 16]);
4050 + } while ((getDebugChar() & 0x7f) != '+');
4054 +static char remcomInBuffer[BUFMAX];
4055 +static char remcomOutBuffer[BUFMAX];
4056 +static short error;
4059 +debug_error(char *format, char *parm)
4062 + printk(format, parm);
4066 +print_regs(struct pt_regs *regs)
4068 + printk("EAX=%08lx ", regs->eax);
4069 + printk("EBX=%08lx ", regs->ebx);
4070 + printk("ECX=%08lx ", regs->ecx);
4071 + printk("EDX=%08lx ", regs->edx);
4073 + printk("ESI=%08lx ", regs->esi);
4074 + printk("EDI=%08lx ", regs->edi);
4075 + printk("EBP=%08lx ", regs->ebp);
4076 + printk("ESP=%08lx ", (long) ®s->esp);
4078 + printk(" DS=%08x ", regs->xds);
4079 + printk(" ES=%08x ", regs->xes);
4080 + printk(" SS=%08x ", __KERNEL_DS);
4081 + printk(" FL=%08lx ", regs->eflags);
4083 + printk(" CS=%08x ", regs->xcs);
4084 + printk(" IP=%08lx ", regs->eip);
4086 + printk(" FS=%08x ", regs->fs);
4087 + printk(" GS=%08x ", regs->gs);
4093 +#define NEW_esp fn_call_lookaside[trap_cpu].esp
4096 +regs_to_gdb_regs(int *gdb_regs, struct pt_regs *regs)
4098 + gdb_regs[_EAX] = regs->eax;
4099 + gdb_regs[_EBX] = regs->ebx;
4100 + gdb_regs[_ECX] = regs->ecx;
4101 + gdb_regs[_EDX] = regs->edx;
4102 + gdb_regs[_ESI] = regs->esi;
4103 + gdb_regs[_EDI] = regs->edi;
4104 + gdb_regs[_EBP] = regs->ebp;
4105 + gdb_regs[_DS] = regs->xds;
4106 + gdb_regs[_ES] = regs->xes;
4107 + gdb_regs[_PS] = regs->eflags;
4108 + gdb_regs[_CS] = regs->xcs;
4109 + gdb_regs[_PC] = regs->eip;
4110 + /* Note, as we are a debugging the kernel, we will always
4111 + * trap in kernel code, this means no priviledge change,
4112 + * and so the pt_regs structure is not completely valid. In a non
4113 + * privilege change trap, only EFLAGS, CS and EIP are put on the stack,
4114 + * SS and ESP are not stacked, this means that the last 2 elements of
4115 + * pt_regs is not valid (they would normally refer to the user stack)
4116 + * also, using regs+1 is no good because you end up will a value that is
4117 + * 2 longs (8) too high. This used to cause stepping over functions
4118 + * to fail, so my fix is to use the address of regs->esp, which
4119 + * should point at the end of the stack frame. Note I have ignored
4120 + * completely exceptions that cause an error code to be stacked, such
4121 + * as double fault. Stuart Hughes, Zentropix.
4122 + * original code: gdb_regs[_ESP] = (int) (regs + 1) ;
4124 + * this is now done on entry and moved to OLD_esp (as well as NEW_esp).
4126 + gdb_regs[_ESP] = NEW_esp;
4127 + gdb_regs[_SS] = __KERNEL_DS;
4128 + gdb_regs[_FS] = 0xFFFF;
4129 + gdb_regs[_GS] = 0xFFFF;
4130 +} /* regs_to_gdb_regs */
4133 +gdb_regs_to_regs(int *gdb_regs, struct pt_regs *regs)
4135 + regs->eax = gdb_regs[_EAX];
4136 + regs->ebx = gdb_regs[_EBX];
4137 + regs->ecx = gdb_regs[_ECX];
4138 + regs->edx = gdb_regs[_EDX];
4139 + regs->esi = gdb_regs[_ESI];
4140 + regs->edi = gdb_regs[_EDI];
4141 + regs->ebp = gdb_regs[_EBP];
4142 + regs->xds = gdb_regs[_DS];
4143 + regs->xes = gdb_regs[_ES];
4144 + regs->eflags = gdb_regs[_PS];
4145 + regs->xcs = gdb_regs[_CS];
4146 + regs->eip = gdb_regs[_PC];
4147 + NEW_esp = gdb_regs[_ESP]; /* keep the value */
4148 +#if 0 /* can't change these */
4149 + regs->esp = gdb_regs[_ESP];
4150 + regs->xss = gdb_regs[_SS];
4151 + regs->fs = gdb_regs[_FS];
4152 + regs->gs = gdb_regs[_GS];
4155 +} /* gdb_regs_to_regs */
4157 +int thread_list = 0;
4160 +get_gdb_regs(struct task_struct *p, struct pt_regs *regs, int *gdb_regs)
4162 + unsigned long stack_page;
4165 + if (!p || p == current) {
4166 + regs_to_gdb_regs(gdb_regs, regs);
4170 + for (i = 0; i < MAX_NO_CPUS; i++) {
4171 + if (p == kgdb_info.cpus_waiting[i].task) {
4172 + regs_to_gdb_regs(gdb_regs,
4173 + kgdb_info.cpus_waiting[i].regs);
4175 + (int) &kgdb_info.cpus_waiting[i].regs->esp;
4181 + memset(gdb_regs, 0, NUMREGBYTES);
4182 + gdb_regs[_ESP] = p->thread.esp;
4183 + gdb_regs[_PC] = p->thread.eip;
4184 + gdb_regs[_EBP] = *(int *) gdb_regs[_ESP];
4185 + gdb_regs[_EDI] = *(int *) (gdb_regs[_ESP] + 4);
4186 + gdb_regs[_ESI] = *(int *) (gdb_regs[_ESP] + 8);
4189 + * This code is to give a more informative notion of where a process
4190 + * is waiting. It is used only when the user asks for a thread info
4191 + * list. If he then switches to the thread, s/he will find the task
4192 + * is in schedule, but a back trace should show the same info we come
4193 + * up with. This code was shamelessly purloined from process.c. It was
4194 + * then enhanced to provide more registers than simply the program
4198 + if (!thread_list) {
4202 + if (p->state == TASK_RUNNING)
4204 + stack_page = (unsigned long) p->thread_info;
4205 + if (gdb_regs[_ESP] < stack_page || gdb_regs[_ESP] >
4206 + THREAD_SIZE - sizeof(long) + stack_page)
4208 + /* include/asm-i386/system.h:switch_to() pushes ebp last. */
4210 + if (gdb_regs[_EBP] < stack_page ||
4211 + gdb_regs[_EBP] > THREAD_SIZE - 2*sizeof(long) + stack_page)
4213 + gdb_regs[_PC] = *(unsigned long *) (gdb_regs[_EBP] + 4);
4214 + gdb_regs[_ESP] = gdb_regs[_EBP] + 8;
4215 + gdb_regs[_EBP] = *(unsigned long *) gdb_regs[_EBP];
4216 + if (!in_sched_functions(gdb_regs[_PC]))
4218 + } while (count++ < 16);
4222 +/* Indicate to caller of mem2hex or hex2mem that there has been an
4224 +static volatile int mem_err = 0;
4225 +static volatile int mem_err_expected = 0;
4226 +static volatile int mem_err_cnt = 0;
4227 +static int garbage_loc = -1;
4230 +get_char(char *addr)
4236 +set_char(char *addr, int val, int may_fault)
4239 + * This code traps references to the area mapped to the kernel
4240 + * stack as given by the regs and, instead, stores to the
4241 + * fn_call_lookaside[cpu].array
4244 + (unsigned int) addr < OLD_esp &&
4245 + ((unsigned int) addr > (OLD_esp - (unsigned int) LOOKASIDE_SIZE))) {
4246 + addr = (char *) END_OF_LOOKASIDE - ((char *) OLD_esp - addr);
4251 +/* convert the memory pointed to by mem into hex, placing result in buf */
4252 +/* return a pointer to the last char put in buf (null) */
4253 +/* If MAY_FAULT is non-zero, then we should set mem_err in response to
4254 + a fault; if zero treat a fault like any other fault in the stub. */
4256 +mem2hex(char *mem, char *buf, int count, int may_fault)
4262 + mem_err_expected = 1;
4265 + for (i = 0; i < count; i++) {
4266 + /* printk("%lx = ", mem) ; */
4268 + ch = get_char(mem++);
4270 + /* printk("%02x\n", ch & 0xFF) ; */
4271 + if (may_fault && mem_err) {
4273 + printk("Mem fault fetching from addr %lx\n",
4274 + (long) (mem - 1));
4275 + *buf = 0; /* truncate buffer */
4278 + *buf++ = hexchars[ch >> 4];
4279 + *buf++ = hexchars[ch % 16];
4283 + mem_err_expected = 0;
4287 +/* convert the hex array pointed to by buf into binary to be placed in mem */
4288 +/* return a pointer to the character AFTER the last byte written */
4289 +/* NOTE: We use the may fault flag to also indicate if the write is to
4290 + * the registers (0) or "other" memory (!=0)
4293 +hex2mem(char *buf, char *mem, int count, int may_fault)
4299 + mem_err_expected = 1;
4302 + for (i = 0; i < count; i++) {
4303 + ch = hex(*buf++) << 4;
4304 + ch = ch + hex(*buf++);
4305 + set_char(mem++, ch, may_fault);
4307 + if (may_fault && mem_err) {
4309 + printk("Mem fault storing to addr %lx\n",
4310 + (long) (mem - 1));
4315 + mem_err_expected = 0;
4319 +/**********************************************/
4320 +/* WHILE WE FIND NICE HEX CHARS, BUILD AN INT */
4321 +/* RETURN NUMBER OF CHARS PROCESSED */
4322 +/**********************************************/
4324 +hexToInt(char **ptr, int *intValue)
4332 + hexValue = hex(**ptr);
4333 + if (hexValue >= 0) {
4334 + *intValue = (*intValue << 4) | hexValue;
4342 + return (numChars);
4345 +#define stubhex(h) hex(h)
4346 +#ifdef old_thread_list
4349 +stub_unpack_int(char *buff, int fieldlength)
4354 + while (fieldlength) {
4355 + nibble = stubhex(*buff++);
4359 + retval = retval << 4;
4365 +pack_hex_byte(char *pkt, int byte)
4367 + *pkt++ = hexchars[(byte >> 4) & 0xf];
4368 + *pkt++ = hexchars[(byte & 0xf)];
4372 +#define BUF_THREAD_ID_SIZE 16
4375 +pack_threadid(char *pkt, threadref * id)
4378 + unsigned char *altid;
4380 + altid = (unsigned char *) id;
4381 + limit = pkt + BUF_THREAD_ID_SIZE;
4382 + while (pkt < limit)
4383 + pkt = pack_hex_byte(pkt, *altid++);
4387 +#ifdef old_thread_list
4389 +unpack_byte(char *buf, int *value)
4391 + *value = stub_unpack_int(buf, 2);
4396 +unpack_threadid(char *inbuf, threadref * id)
4399 + char *limit = inbuf + BUF_THREAD_ID_SIZE;
4402 + altref = (char *) id;
4404 + while (inbuf < limit) {
4405 + x = stubhex(*inbuf++);
4406 + y = stubhex(*inbuf++);
4407 + *altref++ = (x << 4) | y;
4413 +int_to_threadref(threadref * id, int value)
4415 + unsigned char *scan;
4417 + scan = (unsigned char *) id;
4423 + *scan++ = (value >> 24) & 0xff;
4424 + *scan++ = (value >> 16) & 0xff;
4425 + *scan++ = (value >> 8) & 0xff;
4426 + *scan++ = (value & 0xff);
4429 +int_to_hex_v(unsigned char * id, int value)
4431 + unsigned char *start = id;
4435 + for (shift = 28; shift >= 0; shift -= 4) {
4436 + if ((ch = (value >> shift) & 0xf) || (id != start)) {
4437 + *id = hexchars[ch];
4443 + return id - start;
4445 +#ifdef old_thread_list
4448 +threadref_to_int(threadref * ref)
4451 + unsigned char *scan;
4453 + scan = (char *) ref;
4457 + value = (value << 8) | ((*scan++) & 0xff);
4462 +cmp_str(char *s1, char *s2, int count)
4465 + if (*s1++ != *s2++)
4471 +#if 1 /* this is a hold over from 2.4 where O(1) was "sometimes" */
4472 +extern struct task_struct *kgdb_get_idle(int cpu);
4473 +#define idle_task(cpu) kgdb_get_idle(cpu)
4475 +#define idle_task(cpu) init_tasks[cpu]
4478 +extern int kgdb_pid_init_done;
4480 +struct task_struct *
4483 + struct task_struct *thread;
4484 + if (pid >= PID_MAX && pid <= (PID_MAX + MAX_NO_CPUS)) {
4486 + return idle_task(pid - PID_MAX);
4489 + * find_task_by_pid is relatively safe all the time
4490 + * Other pid functions require lock downs which imply
4491 + * that we may be interrupting them (as we get here
4492 + * in the middle of most any lock down).
4493 + * Still we don't want to call until the table exists!
4495 + if (kgdb_pid_init_done){
4496 + thread = find_task_by_pid(pid);
4505 +struct hw_breakpoint {
4510 +} breakinfo[4] = { {enabled:0},
4515 +unsigned hw_breakpoint_status;
4517 +correct_hw_break(void)
4524 + asm volatile ("movl %%db7, %0\n":"=r" (dr7)
4526 + /* *INDENT-OFF* */
4528 + unsigned addr0, addr1, addr2, addr3;
4529 + asm volatile ("movl %%db0, %0\n"
4530 + "movl %%db1, %1\n"
4531 + "movl %%db2, %2\n"
4532 + "movl %%db3, %3\n"
4533 + :"=r" (addr0), "=r"(addr1),
4534 + "=r"(addr2), "=r"(addr3)
4539 + for (breakno = 0; breakno < 3; breakno++) {
4540 + breakbit = 2 << (breakno << 1);
4541 + if (!(dr7 & breakbit) && breakinfo[breakno].enabled) {
4544 + dr7 &= ~(0xf0000 << (breakno << 2));
4545 + dr7 |= (((breakinfo[breakno].len << 2) |
4546 + breakinfo[breakno].type) << 16) <<
4548 + switch (breakno) {
4550 + asm volatile ("movl %0, %%dr0\n"::"r"
4551 + (breakinfo[breakno].addr));
4555 + asm volatile ("movl %0, %%dr1\n"::"r"
4556 + (breakinfo[breakno].addr));
4560 + asm volatile ("movl %0, %%dr2\n"::"r"
4561 + (breakinfo[breakno].addr));
4565 + asm volatile ("movl %0, %%dr3\n"::"r"
4566 + (breakinfo[breakno].addr));
4569 + } else if ((dr7 & breakbit) && !breakinfo[breakno].enabled) {
4572 + dr7 &= ~(0xf0000 << (breakno << 2));
4576 + asm volatile ("movl %0, %%db7\n"::"r" (dr7));
4581 +remove_hw_break(unsigned breakno)
4583 + if (!breakinfo[breakno].enabled) {
4586 + breakinfo[breakno].enabled = 0;
4591 +set_hw_break(unsigned breakno, unsigned type, unsigned len, unsigned addr)
4593 + if (breakinfo[breakno].enabled) {
4596 + breakinfo[breakno].enabled = 1;
4597 + breakinfo[breakno].type = type;
4598 + breakinfo[breakno].len = len;
4599 + breakinfo[breakno].addr = addr;
4604 +static int in_kgdb_console = 0;
4607 +in_kgdb(struct pt_regs *regs)
4610 + int cpu = smp_processor_id();
4611 + in_kgdb_called = 1;
4612 + if (!spin_is_locked(&kgdb_spinlock)) {
4613 + if (in_kgdb_here_log[cpu] || /* we are holding this cpu */
4614 + in_kgdb_console) { /* or we are doing slow i/o */
4620 + /* As I see it the only reason not to let all cpus spin on
4621 + * the same spin_lock is to allow selected ones to proceed.
4622 + * This would be a good thing, so we leave it this way.
4623 + * Maybe someday.... Done !
4625 + * in_kgdb() is called from an NMI so we don't pretend
4626 + * to have any resources, like printk() for example.
4629 + kgdb_local_irq_save(flags); /* only local here, to avoid hanging */
4631 + * log arival of this cpu
4632 + * The NMI keeps on ticking. Protect against recurring more
4633 + * than once, and ignor the cpu that has the kgdb lock
4635 + in_kgdb_entry_log[cpu]++;
4636 + in_kgdb_here_log[cpu] = regs;
4637 + if (cpu == spinlock_cpu || waiting_cpus[cpu].task) {
4638 + goto exit_in_kgdb;
4641 + * For protection of the initilization of the spin locks by kgdb
4642 + * it locks the kgdb spinlock before it gets the wait locks set
4643 + * up. We wait here for the wait lock to be taken. If the
4644 + * kgdb lock goes away first?? Well, it could be a slow exit
4645 + * sequence where the wait lock is removed prior to the kgdb lock
4646 + * so if kgdb gets unlocked, we just exit.
4648 + while (spin_is_locked(&kgdb_spinlock) &&
4649 + !spin_is_locked(waitlocks + cpu)) ;
4650 + if (!spin_is_locked(&kgdb_spinlock)) {
4651 + goto exit_in_kgdb;
4653 + waiting_cpus[cpu].task = current;
4654 + waiting_cpus[cpu].pid = (current->pid) ? : (PID_MAX + cpu);
4655 + waiting_cpus[cpu].regs = regs;
4657 + spin_unlock_wait(waitlocks + cpu);
4659 + * log departure of this cpu
4661 + waiting_cpus[cpu].task = 0;
4662 + waiting_cpus[cpu].pid = 0;
4663 + waiting_cpus[cpu].regs = 0;
4664 + correct_hw_break();
4666 + in_kgdb_here_log[cpu] = 0;
4667 + kgdb_local_irq_restore(flags);
4670 + spin_unlock(continuelocks + smp_processor_id());
4675 +smp__in_kgdb(struct pt_regs regs)
4682 +in_kgdb(struct pt_regs *regs)
4684 + return (kgdb_spinlock);
4689 +printexceptioninfo(int exceptionNo, int errorcode, char *buffer)
4693 + switch (exceptionNo) {
4694 + case 1: /* debug exception */
4696 + case 3: /* breakpoint */
4697 + sprintf(buffer, "Software breakpoint");
4700 + sprintf(buffer, "Details not available");
4703 + asm volatile ("movl %%db6, %0\n":"=r" (dr6)
4705 + if (dr6 & 0x4000) {
4706 + sprintf(buffer, "Single step");
4709 + for (i = 0; i < 4; ++i) {
4710 + if (dr6 & (1 << i)) {
4711 + sprintf(buffer, "Hardware breakpoint %d", i);
4715 + sprintf(buffer, "Unknown trap");
4720 + * This function does all command procesing for interfacing to gdb.
4722 + * NOTE: The INT nn instruction leaves the state of the interrupt
4723 + * enable flag UNCHANGED. That means that when this routine
4724 + * is entered via a breakpoint (INT 3) instruction from code
4725 + * that has interrupts enabled, then interrupts will STILL BE
4726 + * enabled when this routine is entered. The first thing that
4727 + * we do here is disable interrupts so as to prevent recursive
4728 + * entries and bothersome serial interrupts while we are
4729 + * trying to run the serial port in polled mode.
4731 + * For kernel version 2.1.xx the kgdb_cli() actually gets a spin lock so
4732 + * it is always necessary to do a restore_flags before returning
4733 + * so as to let go of that lock.
4736 +kgdb_handle_exception(int exceptionVector,
4737 + int signo, int err_code, struct pt_regs *linux_regs)
4739 + struct task_struct *usethread = NULL;
4740 + struct task_struct *thread_list_start = 0, *thread = NULL;
4742 + int breakno, breaktype;
4747 + int thread_min = PID_MAX + MAX_NO_CPUS;
4748 +#ifdef old_thread_list
4752 + unsigned long flags;
4753 + int gdb_regs[NUMREGBYTES / 4];
4755 + IF_SMP(int entry_state = 0); /* 0, ok, 1, no nmi, 2 sync failed */
4758 +#define regs (*linux_regs)
4759 +#define NUMREGS NUMREGBYTES/4
4761 + * If the entry is not from the kernel then return to the Linux
4762 + * trap handler and let it process the interrupt normally.
4764 + if ((linux_regs->eflags & VM_MASK) || (3 & linux_regs->xcs)) {
4765 + printk("ignoring non-kernel exception\n");
4766 + print_regs(®s);
4770 + kgdb_local_irq_save(flags);
4772 + /* Get kgdb spinlock */
4774 + KGDB_SPIN_LOCK(&kgdb_spinlock);
4775 + rdtscll(kgdb_info.entry_tsc);
4777 + * We depend on this spinlock and the NMI watch dog to control the
4778 + * other cpus. They will arrive at "in_kgdb()" as a result of the
4779 + * NMI and will wait there for the following spin locks to be
4785 + if (cpu_callout_map & ~MAX_CPU_MASK) {
4786 + printk("kgdb : too many cpus, possibly not mapped"
4787 + " in contiguous space, change MAX_NO_CPUS"
4788 + " in kgdb_stub and make new kernel.\n"
4789 + " cpu_callout_map is %lx\n", cpu_callout_map);
4790 + goto exit_just_unlock;
4793 + if (spinlock_count == 1) {
4794 + int time = 0, end_time, dum = 0;
4796 + int cpu_logged_in[MAX_NO_CPUS] = {[0 ... MAX_NO_CPUS - 1] = (0)
4798 + if (remote_debug) {
4799 + printk("kgdb : cpu %d entry, syncing others\n",
4800 + smp_processor_id());
4802 + for (i = 0; i < MAX_NO_CPUS; i++) {
4804 + * Use trylock as we may already hold the lock if
4805 + * we are holding the cpu. Net result is all
4808 + spin_trylock(&waitlocks[i]);
4810 + for (i = 0; i < MAX_NO_CPUS; i++)
4811 + cpu_logged_in[i] = 0;
4813 + * Wait for their arrival. We know the watch dog is active if
4814 + * in_kgdb() has ever been called, as it is always called on a
4818 + end_time = time + 2; /* Note: we use the High order bits! */
4820 + if (num_online_cpus() > 1) {
4821 + int me_in_kgdb = in_kgdb_entry_log[smp_processor_id()];
4822 + smp_send_nmi_allbutself();
4823 + while (i < num_online_cpus() && time != end_time) {
4825 + for (j = 0; j < MAX_NO_CPUS; j++) {
4826 + if (waiting_cpus[j].task &&
4827 + !cpu_logged_in[j]) {
4829 + cpu_logged_in[j] = 1;
4830 + if (remote_debug) {
4832 + ("kgdb : cpu %d arrived at kgdb\n",
4836 + } else if (!waiting_cpus[j].task &&
4838 + waiting_cpus[j].task = NOCPU;
4839 + cpu_logged_in[j] = 1;
4840 + waiting_cpus[j].hold = 1;
4843 + if (!waiting_cpus[j].task &&
4844 + in_kgdb_here_log[j]) {
4846 + int wait = 100000;
4848 + if (!waiting_cpus[j].task &&
4849 + in_kgdb_here_log[j]) {
4851 + ("kgdb : cpu %d stall"
4855 + cpu_logged_in[j] = 1;
4856 + waiting_cpus[j].task =
4857 + (struct task_struct
4863 + if (in_kgdb_entry_log[smp_processor_id()] >
4864 + (me_in_kgdb + 10)) {
4870 + if (i < num_online_cpus()) {
4872 + ("kgdb : time out, proceeding without sync\n");
4874 + printk("kgdb : Waiting_cpus: 0 = %d, 1 = %d\n",
4875 + waiting_cpus[0].task != 0,
4876 + waiting_cpus[1].task != 0);
4877 + printk("kgdb : Cpu_logged in: 0 = %d, 1 = %d\n",
4878 + cpu_logged_in[0], cpu_logged_in[1]);
4880 + ("kgdb : in_kgdb_here_log in: 0 = %d, 1 = %d\n",
4881 + in_kgdb_here_log[0] != 0,
4882 + in_kgdb_here_log[1] != 0);
4884 + entry_state = NO_SYNC;
4888 + in_kgdb_entry_log[smp_processor_id()] -
4890 + printk("kgdb : sync after %d entries\n", ent);
4894 + if (remote_debug) {
4896 + ("kgdb : %d cpus, but watchdog not active\n"
4897 + "proceeding without locking down other cpus\n",
4898 + num_online_cpus());
4899 + entry_state = NO_NMI;
4905 + if (remote_debug) {
4906 + unsigned long *lp = (unsigned long *) &linux_regs;
4908 + printk("handle_exception(exceptionVector=%d, "
4909 + "signo=%d, err_code=%d, linux_regs=%p)\n",
4910 + exceptionVector, signo, err_code, linux_regs);
4912 + print_regs(®s);
4913 + printk("Stk: %8lx %8lx %8lx %8lx"
4914 + " %8lx %8lx %8lx %8lx\n",
4915 + lp[0], lp[1], lp[2], lp[3],
4916 + lp[4], lp[5], lp[6], lp[7]);
4917 + printk(" %8lx %8lx %8lx %8lx"
4918 + " %8lx %8lx %8lx %8lx\n",
4919 + lp[8], lp[9], lp[10], lp[11],
4920 + lp[12], lp[13], lp[14], lp[15]);
4921 + printk(" %8lx %8lx %8lx %8lx "
4922 + "%8lx %8lx %8lx %8lx\n",
4923 + lp[16], lp[17], lp[18], lp[19],
4924 + lp[20], lp[21], lp[22], lp[23]);
4925 + printk(" %8lx %8lx %8lx %8lx "
4926 + "%8lx %8lx %8lx %8lx\n",
4927 + lp[24], lp[25], lp[26], lp[27],
4928 + lp[28], lp[29], lp[30], lp[31]);
4932 + /* Disable hardware debugging while we are in kgdb */
4933 + /* Get the debug register status register */
4935 + __asm__("movl %0,%%db7"
4939 + asm volatile ("movl %%db6, %0\n"
4940 + :"=r" (hw_breakpoint_status)
4944 + switch (exceptionVector) {
4945 + case 0: /* divide error */
4946 + case 1: /* debug exception */
4948 + case 3: /* breakpoint */
4949 + case 4: /* overflow */
4950 + case 5: /* bounds check */
4951 + case 6: /* invalid opcode */
4952 + case 7: /* device not available */
4953 + case 8: /* double fault (errcode) */
4954 + case 10: /* invalid TSS (errcode) */
4955 + case 12: /* stack fault (errcode) */
4956 + case 16: /* floating point error */
4957 + case 17: /* alignment check (errcode) */
4958 + default: /* any undocumented */
4960 + case 11: /* segment not present (errcode) */
4961 + case 13: /* general protection (errcode) */
4962 + case 14: /* page fault (special errcode) */
4963 + case 19: /* cache flush denied */
4964 + if (mem_err_expected) {
4966 + * This fault occured because of the
4967 + * get_char or set_char routines. These
4968 + * two routines use either eax of edx to
4969 + * indirectly reference the location in
4970 + * memory that they are working with.
4971 + * For a page fault, when we return the
4972 + * instruction will be retried, so we
4973 + * have to make sure that these
4974 + * registers point to valid memory.
4976 + mem_err = 1; /* set mem error flag */
4977 + mem_err_expected = 0;
4978 + mem_err_cnt++; /* helps in debugging */
4979 + /* make valid address */
4980 + regs.eax = (long) &garbage_loc;
4981 + /* make valid address */
4982 + regs.edx = (long) &garbage_loc;
4984 + printk("Return after memory error: "
4985 + "mem_err_cnt=%d\n", mem_err_cnt);
4987 + print_regs(®s);
4993 + printk("kgdb : entered kgdb on cpu %d\n", smp_processor_id());
4995 + gdb_i386vector = exceptionVector;
4996 + gdb_i386errcode = err_code;
4997 + kgdb_info.called_from = __builtin_return_address(0);
5000 + * OK, we can now communicate, lets tell gdb about the sync.
5001 + * but only if we had a problem.
5003 + switch (entry_state) {
5005 + to_gdb("NMI not active, other cpus not stopped\n");
5008 + to_gdb("Some cpus not stopped, see 'kgdb_info' for details\n");
5014 + * Set up the gdb function call area.
5016 + trap_cpu = smp_processor_id();
5017 + OLD_esp = NEW_esp = (int) (&linux_regs->esp);
5019 + IF_SMP(once_again:)
5020 + /* reply to host that an exception has occurred */
5021 + remcomOutBuffer[0] = 'S';
5022 + remcomOutBuffer[1] = hexchars[signo >> 4];
5023 + remcomOutBuffer[2] = hexchars[signo % 16];
5024 + remcomOutBuffer[3] = 0;
5026 + putpacket(remcomOutBuffer);
5030 + remcomOutBuffer[0] = 0;
5031 + getpacket(remcomInBuffer);
5032 + switch (remcomInBuffer[0]) {
5034 + remcomOutBuffer[0] = 'S';
5035 + remcomOutBuffer[1] = hexchars[signo >> 4];
5036 + remcomOutBuffer[2] = hexchars[signo % 16];
5037 + remcomOutBuffer[3] = 0;
5040 + remote_debug = !(remote_debug); /* toggle debug flag */
5041 + printk("Remote debug %s\n",
5042 + remote_debug ? "on" : "off");
5044 + case 'g': /* return the value of the CPU registers */
5045 + get_gdb_regs(usethread, ®s, gdb_regs);
5046 + mem2hex((char *) gdb_regs,
5047 + remcomOutBuffer, NUMREGBYTES, 0);
5049 + case 'G': /* set the value of the CPU registers - return OK */
5050 + hex2mem(&remcomInBuffer[1],
5051 + (char *) gdb_regs, NUMREGBYTES, 0);
5052 + if (!usethread || usethread == current) {
5053 + gdb_regs_to_regs(gdb_regs, ®s);
5054 + strcpy(remcomOutBuffer, "OK");
5056 + strcpy(remcomOutBuffer, "E00");
5060 + case 'P':{ /* set the value of a single CPU register -
5063 + * For some reason, gdb wants to talk about psudo
5064 + * registers (greater than 15). These may have
5065 + * meaning for ptrace, but for us it is safe to
5066 + * ignor them. We do this by dumping them into
5067 + * _GS which we also ignor, but do have memory for.
5071 + ptr = &remcomInBuffer[1];
5072 + regs_to_gdb_regs(gdb_regs, ®s);
5073 + if ((!usethread || usethread == current) &&
5074 + hexToInt(&ptr, ®no) &&
5075 + *ptr++ == '=' && (regno >= 0)) {
5077 + (regno >= NUMREGS ? _GS : regno);
5078 + hex2mem(ptr, (char *) &gdb_regs[regno],
5080 + gdb_regs_to_regs(gdb_regs, ®s);
5081 + strcpy(remcomOutBuffer, "OK");
5084 + strcpy(remcomOutBuffer, "E01");
5088 + /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
5090 + /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */
5091 + ptr = &remcomInBuffer[1];
5092 + if (hexToInt(&ptr, &addr) &&
5093 + (*(ptr++) == ',') && (hexToInt(&ptr, &length))) {
5096 + * hex doubles the byte count
5098 + if (length > (BUFMAX / 2))
5099 + length = BUFMAX / 2;
5100 + mem2hex((char *) addr,
5101 + remcomOutBuffer, length, 1);
5103 + strcpy(remcomOutBuffer, "E03");
5104 + debug_error("memory fault\n", NULL);
5109 + strcpy(remcomOutBuffer, "E01");
5111 + ("malformed read memory command: %s\n",
5117 + Write LLLL bytes at address AA.AA return OK */
5119 + /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */
5120 + ptr = &remcomInBuffer[1];
5121 + if (hexToInt(&ptr, &addr) &&
5122 + (*(ptr++) == ',') &&
5123 + (hexToInt(&ptr, &length)) && (*(ptr++) == ':')) {
5124 + hex2mem(ptr, (char *) addr, length, 1);
5127 + strcpy(remcomOutBuffer, "E03");
5128 + debug_error("memory fault\n", NULL);
5130 + strcpy(remcomOutBuffer, "OK");
5136 + strcpy(remcomOutBuffer, "E02");
5138 + ("malformed write memory command: %s\n",
5143 + remcomInBuffer[0] = 's';
5145 + /* Csig;AA..AA where ;AA..AA is optional
5146 + * continue with signal
5147 + * Since signals are meaning less to us, delete that
5148 + * part and then fall into the 'c' code.
5150 + ptr = &remcomInBuffer[1];
5152 + while (*ptr && *ptr != ';') {
5159 + *(ptr - length++) = *ptr;
5162 + remcomInBuffer[1] = 0;
5165 + /* cAA..AA Continue at address AA..AA(optional) */
5166 + /* sAA..AA Step one instruction from AA..AA(optional) */
5167 + /* D detach, reply OK and then continue */
5172 + /* try to read optional parameter,
5173 + pc unchanged if no parm */
5174 + ptr = &remcomInBuffer[1];
5175 + if (hexToInt(&ptr, &addr)) {
5177 + printk("Changing EIP to 0x%x\n", addr);
5184 + /* clear the trace bit */
5185 + regs.eflags &= 0xfffffeff;
5187 + /* set the trace bit if we're stepping */
5188 + if (remcomInBuffer[0] == 's')
5189 + regs.eflags |= 0x100;
5191 + /* detach is a friendly version of continue. Note that
5192 + debugging is still enabled (e.g hit control C)
5194 + if (remcomInBuffer[0] == 'D') {
5195 + strcpy(remcomOutBuffer, "OK");
5196 + putpacket(remcomOutBuffer);
5199 + if (remote_debug) {
5200 + printk("Resuming execution\n");
5201 + print_regs(®s);
5203 + asm volatile ("movl %%db6, %0\n":"=r" (dr6)
5205 + if (!(dr6 & 0x4000)) {
5206 + for (breakno = 0; breakno < 4; ++breakno) {
5207 + if (dr6 & (1 << breakno) &&
5208 + (breakinfo[breakno].type == 0)) {
5209 + /* Set restore flag */
5210 + regs.eflags |= 0x10000;
5215 + correct_hw_break();
5216 + asm volatile ("movl %0, %%db6\n"::"r" (0));
5219 + /* kill the program */
5220 + case 'k': /* do nothing */
5226 + switch (remcomInBuffer[1]) {
5230 + thread_list_start = (usethread ? : current);
5232 + if (!cmp_str(&remcomInBuffer[2],
5233 + "ThreadInfo", 10))
5236 + remcomOutBuffer[nothreads++] = 'm';
5237 + for (; threadid < PID_MAX + MAX_NO_CPUS;
5239 + thread = getthread(threadid);
5241 + nothreads += int_to_hex_v(
5245 + if (thread_min > threadid)
5246 + thread_min = threadid;
5250 + if (nothreads > BUFMAX - 10)
5254 + if (remcomOutBuffer[nothreads - 1] == 'm') {
5255 + remcomOutBuffer[nothreads - 1] = 'l';
5259 + remcomOutBuffer[nothreads] = 0;
5262 +#ifdef old_thread_list /* Old thread info request */
5264 + /* List threads */
5266 + thread_list_start = (usethread ? : current);
5267 + unpack_byte(remcomInBuffer + 3, &maxthreads);
5268 + unpack_threadid(remcomInBuffer + 5, &thref);
5270 + int buf_thread_limit =
5271 + (BUFMAX - 22) / BUF_THREAD_ID_SIZE;
5272 + if (maxthreads > buf_thread_limit) {
5273 + maxthreads = buf_thread_limit;
5276 + remcomOutBuffer[0] = 'q';
5277 + remcomOutBuffer[1] = 'M';
5278 + remcomOutBuffer[4] = '0';
5279 + pack_threadid(remcomOutBuffer + 5, &thref);
5281 + threadid = threadref_to_int(&thref);
5282 + for (nothreads = 0;
5283 + nothreads < maxthreads &&
5284 + threadid < PID_MAX + MAX_NO_CPUS;
5286 + thread = getthread(threadid);
5288 + int_to_threadref(&thref,
5290 + pack_threadid(remcomOutBuffer +
5295 + if (thread_min > threadid)
5296 + thread_min = threadid;
5300 + if (threadid == PID_MAX + MAX_NO_CPUS) {
5301 + remcomOutBuffer[4] = '1';
5303 + pack_hex_byte(remcomOutBuffer + 2, nothreads);
5304 + remcomOutBuffer[21 + nothreads * 16] = '\0';
5308 + /* Current thread id */
5309 + remcomOutBuffer[0] = 'Q';
5310 + remcomOutBuffer[1] = 'C';
5311 + threadid = current->pid;
5316 + for (threadid = PID_MAX;
5317 + threadid < PID_MAX + MAX_NO_CPUS;
5320 + idle_task(threadid -
5325 + int_to_threadref(&thref, threadid);
5326 + pack_threadid(remcomOutBuffer + 2, &thref);
5327 + remcomOutBuffer[18] = '\0';
5331 + /* Print exception info */
5332 + printexceptioninfo(exceptionVector,
5333 + err_code, remcomOutBuffer);
5337 + /* Thread extra info */
5338 + if (!cmp_str(&remcomInBuffer[2],
5339 + "hreadExtraInfo,", 15)) {
5342 + ptr = &remcomInBuffer[17];
5343 + hexToInt(&ptr, &threadid);
5344 + thread = getthread(threadid);
5345 + nptr = &thread->comm[0];
5347 + ptr = &remcomOutBuffer[0];
5350 + ptr = pack_hex_byte(ptr, *nptr++);
5351 + } while (*nptr && length < 16);
5353 + * would like that 16 to be the size of
5354 + * task_struct.comm but don't know the
5362 + /* task related */
5364 + switch (remcomInBuffer[1]) {
5366 + ptr = &remcomInBuffer[2];
5367 + hexToInt(&ptr, &threadid);
5368 + thread = getthread(threadid);
5370 + remcomOutBuffer[0] = 'E';
5371 + remcomOutBuffer[1] = '\0';
5375 + * Just in case I forget what this is all about,
5376 + * the "thread info" command to gdb causes it
5377 + * to ask for a thread list. It then switches
5378 + * to each thread and asks for the registers.
5379 + * For this (and only this) usage, we want to
5380 + * fudge the registers of tasks not on the run
5381 + * list (i.e. waiting) to show the routine that
5382 + * called schedule. Also, gdb, is a minimalist
5383 + * in that if the current thread is the last
5384 + * it will not re-read the info when done.
5385 + * This means that in this case we must show
5386 + * the real registers. So here is how we do it:
5387 + * Each entry we keep track of the min
5388 + * thread in the list (the last that gdb will)
5389 + * get info for. We also keep track of the
5390 + * starting thread.
5391 + * "thread_list" is cleared when switching back
5392 + * to the min thread if it is was current, or
5393 + * if it was not current, thread_list is set
5394 + * to 1. When the switch to current comes,
5395 + * if thread_list is 1, clear it, else do
5398 + usethread = thread;
5399 + if ((thread_list == 1) &&
5400 + (thread == thread_list_start)) {
5403 + if (thread_list && (threadid == thread_min)) {
5404 + if (thread == thread_list_start) {
5410 + /* follow through */
5412 + remcomOutBuffer[0] = 'O';
5413 + remcomOutBuffer[1] = 'K';
5414 + remcomOutBuffer[2] = '\0';
5419 + /* Query thread status */
5421 + ptr = &remcomInBuffer[1];
5422 + hexToInt(&ptr, &threadid);
5423 + thread = getthread(threadid);
5425 + remcomOutBuffer[0] = 'O';
5426 + remcomOutBuffer[1] = 'K';
5427 + remcomOutBuffer[2] = '\0';
5428 + if (thread_min > threadid)
5429 + thread_min = threadid;
5431 + remcomOutBuffer[0] = 'E';
5432 + remcomOutBuffer[1] = '\0';
5436 + case 'Y': /* set up a hardware breakpoint */
5437 + ptr = &remcomInBuffer[1];
5438 + hexToInt(&ptr, &breakno);
5440 + hexToInt(&ptr, &breaktype);
5442 + hexToInt(&ptr, &length);
5444 + hexToInt(&ptr, &addr);
5445 + if (set_hw_break(breakno & 0x3,
5447 + length & 0x3, addr) == 0) {
5448 + strcpy(remcomOutBuffer, "OK");
5450 + strcpy(remcomOutBuffer, "ERROR");
5454 + /* Remove hardware breakpoint */
5456 + ptr = &remcomInBuffer[1];
5457 + hexToInt(&ptr, &breakno);
5458 + if (remove_hw_break(breakno & 0x3) == 0) {
5459 + strcpy(remcomOutBuffer, "OK");
5461 + strcpy(remcomOutBuffer, "ERROR");
5465 + case 'r': /* reboot */
5466 + strcpy(remcomOutBuffer, "OK");
5467 + putpacket(remcomOutBuffer);
5468 + /*to_gdb("Rebooting\n"); */
5469 + /* triplefault no return from here */
5471 + static long no_idt[2];
5472 + __asm__ __volatile__("lidt %0"::"m"(no_idt[0]));
5478 + /* reply to the request */
5479 + putpacket(remcomOutBuffer);
5480 + } /* while(1==1) */
5482 + * reached by goto only.
5486 + * Here is where we set up to trap a gdb function call. NEW_esp
5487 + * will be changed if we are trying to do this. We handle both
5488 + * adding and subtracting, thus allowing gdb to put grung on
5489 + * the stack which it removes later.
5491 + if (NEW_esp != OLD_esp) {
5492 + int *ptr = END_OF_LOOKASIDE;
5493 + if (NEW_esp < OLD_esp)
5494 + ptr -= (OLD_esp - NEW_esp) / sizeof (int);
5495 + *--ptr = linux_regs->eflags;
5496 + *--ptr = linux_regs->xcs;
5497 + *--ptr = linux_regs->eip;
5498 + *--ptr = linux_regs->ecx;
5499 + *--ptr = linux_regs->ebx;
5500 + *--ptr = linux_regs->eax;
5501 + linux_regs->ecx = NEW_esp - (sizeof (int) * 6);
5502 + linux_regs->ebx = (unsigned int) END_OF_LOOKASIDE;
5503 + if (NEW_esp < OLD_esp) {
5504 + linux_regs->eip = (unsigned int) fn_call_stub;
5506 + linux_regs->eip = (unsigned int) fn_rtn_stub;
5507 + linux_regs->eax = NEW_esp;
5509 + linux_regs->eflags &= ~(IF_BIT | TF_BIT);
5513 + * Release gdb wait locks
5514 + * Sanity check time. Must have at least one cpu to run. Also single
5515 + * step must not be done if the current cpu is on hold.
5517 + if (spinlock_count == 1) {
5518 + int ss_hold = (regs.eflags & 0x100) && kgdb_info.hold_on_sstep;
5519 + int cpu_avail = 0;
5522 + for (i = 0; i < MAX_NO_CPUS; i++) {
5523 + if (!cpu_online(i))
5525 + if (!hold_cpu(i)) {
5530 + * Early in the bring up there will be NO cpus on line...
5532 + if (!cpu_avail && !cpus_empty(cpu_online_map)) {
5533 + to_gdb("No cpus unblocked, see 'kgdb_info.hold_cpu'\n");
5536 + if (hold_cpu(smp_processor_id()) && (regs.eflags & 0x100)) {
5538 + ("Current cpu must be unblocked to single step\n");
5543 + for (i = 0; i < MAX_NO_CPUS; i++) {
5544 + if (!hold_cpu(i)) {
5545 + spin_unlock(&waitlocks[i]);
5549 + spin_unlock(&waitlocks[smp_processor_id()]);
5551 + /* Release kgdb spinlock */
5552 + KGDB_SPIN_UNLOCK(&kgdb_spinlock);
5554 + * If this cpu is on hold, this is where we
5555 + * do it. Note, the NMI will pull us out of here,
5556 + * but will return as the above lock is not held.
5557 + * We will stay here till another cpu releases the lock for us.
5559 + spin_unlock_wait(waitlocks + smp_processor_id());
5560 + kgdb_local_irq_restore(flags);
5567 + /* Release kgdb spinlock */
5568 + KGDB_SPIN_UNLOCK(&kgdb_spinlock);
5569 + kgdb_local_irq_restore(flags);
5573 +/* this function is used to set up exception handlers for tracing and
5575 + * This function is not needed as the above line does all that is needed.
5576 + * We leave it for backward compatitability...
5579 +set_debug_traps(void)
5582 + * linux_debug_hook is defined in traps.c. We store a pointer
5583 + * to our own exception handler into it.
5585 + * But really folks, every hear of labeled common, an old Fortran
5586 + * concept. Lots of folks can reference it and it is define if
5587 + * anyone does. Only one can initialize it at link time. We do
5588 + * this with the hook. See the statement above. No need for any
5589 + * executable code and it is ready as soon as the kernel is
5590 + * loaded. Very desirable in kernel debugging.
5592 + linux_debug_hook = handle_exception ;
5595 + /* In case GDB is started before us, ack any packets (presumably
5596 + "$?#xx") sitting there.
5597 + putDebugChar ('+');
5603 +/* This function will generate a breakpoint exception. It is used at the
5604 + beginning of a program to sync up with a debugger and can be used
5605 + otherwise as a quick means to stop program execution and "break" into
5607 +/* But really, just use the BREAKPOINT macro. We will handle the int stuff
5612 + * possibly we should not go thru the traps.c code at all? Someday.
5615 +do_kgdb_int3(struct pt_regs *regs, long error_code)
5617 + kgdb_handle_exception(3, 5, error_code, regs);
5622 +#ifdef CONFIG_TRAP_BAD_SYSCALL_EXITS
5624 +bad_sys_call_exit(int stuff)
5626 + struct pt_regs *regs = (struct pt_regs *) &stuff;
5627 + printk("Sys call %d return with %x preempt_count\n",
5628 + (int) regs->orig_eax, preempt_count());
5631 +#ifdef CONFIG_STACK_OVERFLOW_TEST
5632 +#include <asm/kgdb.h>
5634 +stack_overflow(void)
5639 + printk("Kernel stack overflow, looping forever\n");
5646 +#if defined(CONFIG_SMP) || defined(CONFIG_KGDB_CONSOLE)
5647 +char gdbconbuf[BUFMAX];
5650 +kgdb_gdb_message(const char *s, unsigned count)
5656 + * This takes care of NMI while spining out chars to gdb
5658 + IF_SMP(in_kgdb_console = 1);
5659 + gdbconbuf[0] = 'O';
5660 + bufptr = gdbconbuf + 1;
5661 + while (count > 0) {
5662 + if ((count << 1) > (BUFMAX - 2)) {
5663 + wcount = (BUFMAX - 2) >> 1;
5668 + for (i = 0; i < wcount; i++) {
5669 + bufptr = pack_hex_byte(bufptr, s[i]);
5674 + putpacket(gdbconbuf);
5677 + IF_SMP(in_kgdb_console = 0);
5682 +to_gdb(const char *s)
5685 + while (s[count] && (count++ < BUFMAX)) ;
5686 + kgdb_gdb_message(s, count);
5689 +#ifdef CONFIG_KGDB_CONSOLE
5690 +#include <linux/console.h>
5691 +#include <linux/init.h>
5692 +#include <linux/fs.h>
5693 +#include <asm/uaccess.h>
5694 +#include <asm/semaphore.h>
5697 +kgdb_console_write(struct console *co, const char *s, unsigned count)
5700 + if (gdb_i386vector == -1) {
5702 + * We have not yet talked to gdb. What to do...
5703 + * lets break, on continue we can do the write.
5704 + * But first tell him whats up. Uh, well no can do,
5705 + * as this IS the console. Oh well...
5706 + * We do need to wait or the messages will be lost.
5707 + * Other option would be to tell the above code to
5708 + * ignore this breakpoint and do an auto return,
5709 + * but that might confuse gdb. Also this happens
5710 + * early enough in boot up that we don't have the traps
5711 + * set up yet, so...
5715 + kgdb_gdb_message(s, count);
5719 + * ------------------------------------------------------------
5720 + * Serial KGDB driver
5721 + * ------------------------------------------------------------
5724 +static struct console kgdbcons = {
5726 + write:kgdb_console_write,
5727 +#ifdef CONFIG_KGDB_USER_CONSOLE
5728 + device:kgdb_console_device,
5730 + flags:CON_PRINTBUFFER | CON_ENABLED,
5735 + * The trick here is that this file gets linked before printk.o
5736 + * That means we get to peer at the console info in the command
5737 + * line before it does. If we are up, we register, otherwise,
5738 + * do nothing. By returning 0, we allow printk to look also.
5740 +static int kgdb_console_enabled;
5743 +kgdb_console_init(char *str)
5745 + if ((strncmp(str, "kgdb", 4) == 0) || (strncmp(str, "gdb", 3) == 0)) {
5746 + register_console(&kgdbcons);
5747 + kgdb_console_enabled = 1;
5749 + return 0; /* let others look at the string */
5752 +__setup("console=", kgdb_console_init);
5754 +#ifdef CONFIG_KGDB_USER_CONSOLE
5755 +static kdev_t kgdb_console_device(struct console *c);
5756 +/* This stuff sort of works, but it knocks out telnet devices
5757 + * we are leaving it here in case we (or you) find time to figure it out
5762 + * We need a real char device as well for when the console is opened for user
5763 + * space activities.
5767 +kgdb_consdev_open(struct inode *inode, struct file *file)
5773 +kgdb_consdev_write(struct file *file, const char *buf,
5774 + size_t count, loff_t * ppos)
5776 + int size, ret = 0;
5777 + static char kbuf[128];
5778 + static DECLARE_MUTEX(sem);
5780 + /* We are not reentrant... */
5781 + if (down_interruptible(&sem))
5782 + return -ERESTARTSYS;
5784 + while (count > 0) {
5785 + /* need to copy the data from user space */
5787 + if (size > sizeof (kbuf))
5788 + size = sizeof (kbuf);
5789 + if (copy_from_user(kbuf, buf, size)) {
5793 + kgdb_console_write(&kgdbcons, kbuf, size);
5804 +struct file_operations kgdb_consdev_fops = {
5805 + open:kgdb_consdev_open,
5806 + write:kgdb_consdev_write
5809 +kgdb_console_device(struct console *c)
5811 + return MKDEV(TTYAUX_MAJOR, 1);
5815 + * This routine gets called from the serial stub in the i386/lib
5816 + * This is so it is done late in bring up (just before the console open).
5819 +kgdb_console_finit(void)
5821 + if (kgdb_console_enabled) {
5822 + char *cptr = cdevname(MKDEV(TTYAUX_MAJOR, 1));
5824 + while (*cptr && *cptr != '(')
5827 + unregister_chrdev(TTYAUX_MAJOR, cp);
5828 + register_chrdev(TTYAUX_MAJOR, "kgdb", &kgdb_consdev_fops);
5833 +#ifdef CONFIG_KGDB_TS
5834 +#include <asm/msr.h> /* time stamp code */
5835 +#include <asm/hardirq.h> /* in_interrupt */
5836 +#ifdef CONFIG_KGDB_TS_64
5837 +#define DATA_POINTS 64
5839 +#ifdef CONFIG_KGDB_TS_128
5840 +#define DATA_POINTS 128
5842 +#ifdef CONFIG_KGDB_TS_256
5843 +#define DATA_POINTS 256
5845 +#ifdef CONFIG_KGDB_TS_512
5846 +#define DATA_POINTS 512
5848 +#ifdef CONFIG_KGDB_TS_1024
5849 +#define DATA_POINTS 1024
5851 +#ifndef DATA_POINTS
5852 +#define DATA_POINTS 128 /* must be a power of two */
5854 +#define INDEX_MASK (DATA_POINTS - 1)
5855 +#if (INDEX_MASK & DATA_POINTS)
5856 +#error "CONFIG_KGDB_TS_COUNT must be a power of 2"
5858 +struct kgdb_and_then_struct {
5862 + struct task_struct *task;
5863 + long long at_time;
5871 +struct kgdb_and_then_struct2 {
5875 + struct task_struct *task;
5876 + long long at_time;
5881 + struct task_struct *t1;
5882 + struct task_struct *t2;
5884 +struct kgdb_and_then_struct kgdb_data[DATA_POINTS];
5886 +struct kgdb_and_then_struct *kgdb_and_then = &kgdb_data[0];
5887 +int kgdb_and_then_count;
5890 +kgdb_tstamp(int line, char *source, int data0, int data1)
5892 + static spinlock_t ts_spin = SPIN_LOCK_UNLOCKED;
5894 + kgdb_local_irq_save(flags);
5895 + spin_lock(&ts_spin);
5896 + rdtscll(kgdb_and_then->at_time);
5898 + kgdb_and_then->on_cpu = smp_processor_id();
5900 + kgdb_and_then->task = current;
5901 + kgdb_and_then->from_ln = line;
5902 + kgdb_and_then->in_src = source;
5903 + kgdb_and_then->from = __builtin_return_address(0);
5904 + kgdb_and_then->with_shpf = (int *) (((flags & IF_BIT) >> 9) |
5905 + (preempt_count() << 8));
5906 + kgdb_and_then->data0 = data0;
5907 + kgdb_and_then->data1 = data1;
5908 + kgdb_and_then = &kgdb_data[++kgdb_and_then_count & INDEX_MASK];
5909 + spin_unlock(&ts_spin);
5910 + kgdb_local_irq_restore(flags);
5911 +#ifdef CONFIG_PREEMPT
5917 +typedef int gdb_debug_hook(int exceptionVector,
5918 + int signo, int err_code, struct pt_regs *linux_regs);
5919 +gdb_debug_hook *linux_debug_hook = &kgdb_handle_exception; /* histerical reasons... */
5920 Index: linux-2.6.10/arch/i386/kernel/Makefile
5921 ===================================================================
5922 --- linux-2.6.10.orig/arch/i386/kernel/Makefile 2005-03-31 15:35:23.000000000 +0800
5923 +++ linux-2.6.10/arch/i386/kernel/Makefile 2005-04-05 12:48:05.254618256 +0800
5925 obj-$(CONFIG_ACPI_BOOT) += acpi/
5926 obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o
5927 obj-$(CONFIG_MCA) += mca.o
5928 +obj-$(CONFIG_KGDB) += kgdb_stub.o
5929 obj-$(CONFIG_X86_MSR) += msr.o
5930 obj-$(CONFIG_X86_CPUID) += cpuid.o
5931 obj-$(CONFIG_MICROCODE) += microcode.o
5932 Index: linux-2.6.10/arch/i386/kernel/smp.c
5933 ===================================================================
5934 --- linux-2.6.10.orig/arch/i386/kernel/smp.c 2005-03-31 16:20:11.000000000 +0800
5935 +++ linux-2.6.10/arch/i386/kernel/smp.c 2005-04-05 12:48:05.218623728 +0800
5936 @@ -466,7 +466,17 @@
5938 on_each_cpu(do_flush_tlb_all, NULL, 1, 1);
5943 + * By using the NMI code instead of a vector we just sneak thru the
5944 + * word generator coming out with just what we want. AND it does
5945 + * not matter if clustered_apic_mode is set or not.
5947 +void smp_send_nmi_allbutself(void)
5949 + send_IPI_allbutself(APIC_DM_NMI);
5953 * this function sends a 'reschedule' IPI to another CPU.
5954 * it goes straight through and wastes no time serializing
5955 Index: linux-2.6.10/arch/i386/Kconfig.kgdb
5956 ===================================================================
5957 --- linux-2.6.10.orig/arch/i386/Kconfig.kgdb 2005-04-05 19:01:49.158500672 +0800
5958 +++ linux-2.6.10/arch/i386/Kconfig.kgdb 2005-04-05 12:48:05.205625704 +0800
5961 + bool "Include kgdb kernel debugger"
5962 + depends on DEBUG_KERNEL && !KPROBES
5964 + If you say Y here, the system will be compiled with the debug
5965 + option (-g) and a debugging stub will be included in the
5966 + kernel. This stub communicates with gdb on another (host)
5967 + computer via a serial port. The host computer should have
5968 + access to the kernel binary file (vmlinux) and a serial port
5969 + that is connected to the target machine. Gdb can be made to
5970 + configure the serial port or you can use stty and setserial to
5971 + do this. See the 'target' command in gdb. This option also
5972 + configures in the ability to request a breakpoint early in the
5973 + boot process. To request the breakpoint just include 'kgdb'
5974 + as a boot option when booting the target machine. The system
5975 + will then break as soon as it looks at the boot options. This
5976 + option also installs a breakpoint in panic and sends any
5977 + kernel faults to the debugger. For more information see the
5978 + Documentation/i386/kgdb/kgdb.txt file.
5982 + prompt "Debug serial port BAUD"
5983 + default KGDB_115200BAUD
5985 + Gdb and the kernel stub need to agree on the baud rate to be
5986 + used. Some systems (x86 family at this writing) allow this to
5989 +config KGDB_9600BAUD
5992 +config KGDB_19200BAUD
5995 +config KGDB_38400BAUD
5998 +config KGDB_57600BAUD
6001 +config KGDB_115200BAUD
6006 + hex "hex I/O port address of the debug serial port"
6010 + Some systems (x86 family at this writing) allow the port
6011 + address to be configured. The number entered is assumed to be
6012 + hex, don't put 0x in front of it. The standard address are:
6013 + COM1 3f8 , irq 4 and COM2 2f8 irq 3. Setserial /dev/ttySx
6014 + will tell you what you have. It is good to test the serial
6015 + connection with a live system before trying to debug.
6018 + int "IRQ of the debug serial port"
6022 + This is the irq for the debug port. If everything is working
6023 + correctly and the kernel has interrupts on a control C to the
6024 + port should cause a break into the kernel debug stub.
6032 + bool "Add any additional compile options"
6036 + Saying yes here turns on the ability to enter additional
6040 +config KGDB_OPTIONS
6041 + depends on KGDB_MORE
6042 + string "Additional compile arguments"
6045 + This option allows you enter additional compile options for
6046 + the whole kernel compile. Each platform will have a default
6047 + that seems right for it. For example on PPC "-ggdb -O1", and
6048 + for i386 "-O1". Note that by configuring KGDB "-g" is already
6049 + turned on. In addition, on i386 platforms
6050 + "-fomit-frame-pointer" is deleted from the standard compile
6053 +config NO_KGDB_CPUS
6054 + int "Number of CPUs"
6055 + depends on KGDB && SMP
6059 + This option sets the number of cpus for kgdb ONLY. It is used
6060 + to prune some internal structures so they look "nice" when
6061 + displayed with gdb. This is to overcome possibly larger
6062 + numbers that may have been entered above. Enter the real
6063 + number to get nice clean kgdb_info displays.
6066 + bool "Enable kgdb time stamp macros?"
6070 + Kgdb event macros allow you to instrument your code with calls
6071 + to the kgdb event recording function. The event log may be
6072 + examined with gdb at a break point. Turning on this
6073 + capability also allows you to choose how many events to
6074 + keep. Kgdb always keeps the lastest events.
6077 + depends on KGDB_TS
6078 + prompt "Max number of time stamps to save?"
6079 + default KGDB_TS_128
6093 +config KGDB_TS_1024
6098 +config STACK_OVERFLOW_TEST
6099 + bool "Turn on kernel stack overflow testing?"
6103 + This option enables code in the front line interrupt handlers
6104 + to check for kernel stack overflow on interrupts and system
6105 + calls. This is part of the kgdb code on x86 systems.
6107 +config KGDB_CONSOLE
6108 + bool "Enable serial console thru kgdb port"
6112 + This option enables the command line "console=kgdb" option.
6113 + When the system is booted with this option in the command line
6114 + all kernel printk output is sent to gdb (as well as to other
6115 + consoles). For this to work gdb must be connected. For this
6116 + reason, this command line option will generate a breakpoint if
6117 + gdb has not yet connected. After the gdb continue command is
6118 + given all pent up console output will be printed by gdb on the
6119 + host machine. Neither this option, nor KGDB require the
6120 + serial driver to be configured.
6123 + bool "Turn on SysRq 'G' command to do a break?"
6127 + This option includes an option in the SysRq code that allows
6128 + you to enter SysRq G which generates a breakpoint to the KGDB
6129 + stub. This will work if the keyboard is alive and can
6130 + interrupt the system. Because of constraints on when the
6131 + serial port interrupt can be enabled, this code may allow you
6132 + to interrupt the system before the serial port control C is
6133 + available. Just say yes here.
6135 Index: linux-2.6.10/arch/i386/mm/fault.c
6136 ===================================================================
6137 --- linux-2.6.10.orig/arch/i386/mm/fault.c 2004-12-25 05:33:48.000000000 +0800
6138 +++ linux-2.6.10/arch/i386/mm/fault.c 2005-04-05 12:48:05.196627072 +0800
6139 @@ -430,6 +430,12 @@
6140 * Oops. The kernel tried to access some bad page. We'll have to
6141 * terminate things with extreme prejudice.
6144 + if (!user_mode(regs)){
6145 + kgdb_handle_exception(14,SIGBUS, error_code, regs);
6152 Index: linux-2.6.10/arch/i386/Kconfig
6153 ===================================================================
6154 --- linux-2.6.10.orig/arch/i386/Kconfig 2005-04-05 12:48:03.417897480 +0800
6155 +++ linux-2.6.10/arch/i386/Kconfig 2005-04-05 12:48:05.257617800 +0800
6156 @@ -1196,6 +1196,14 @@
6158 source "fs/Kconfig.binfmt"
6160 +config TRAP_BAD_SYSCALL_EXITS
6161 + bool "Debug bad system call exits"
6164 + If you say Y here the kernel will check for system calls which
6165 + return without clearing preempt.
6170 source "drivers/Kconfig"
6171 Index: linux-2.6.10/arch/i386/Makefile
6172 ===================================================================
6173 --- linux-2.6.10.orig/arch/i386/Makefile 2005-03-31 15:35:27.000000000 +0800
6174 +++ linux-2.6.10/arch/i386/Makefile 2005-04-05 12:48:05.255618104 +0800
6176 # default subarch .h files
6177 mflags-y += -Iinclude/asm-i386/mach-default
6179 +mflags-$(CONFIG_KGDB) += -gdwarf-2
6180 +mflags-$(CONFIG_KGDB_MORE) += $(shell echo $(CONFIG_KGDB_OPTIONS) | sed -e 's/"//g')
6182 head-y := arch/i386/kernel/head.o arch/i386/kernel/init_task.o
6184 libs-y += arch/i386/lib/
6185 Index: linux-2.6.10/arch/x86_64/boot/compressed/head.S
6186 ===================================================================
6187 --- linux-2.6.10.orig/arch/x86_64/boot/compressed/head.S 2004-12-25 05:35:39.000000000 +0800
6188 +++ linux-2.6.10/arch/x86_64/boot/compressed/head.S 2005-04-05 12:48:05.258617648 +0800
6193 +#define IN_BOOTLOADER
6194 #include <linux/linkage.h>
6195 #include <asm/segment.h>
6197 Index: linux-2.6.10/arch/x86_64/boot/compressed/misc.c
6198 ===================================================================
6199 --- linux-2.6.10.orig/arch/x86_64/boot/compressed/misc.c 2004-12-25 05:34:32.000000000 +0800
6200 +++ linux-2.6.10/arch/x86_64/boot/compressed/misc.c 2005-04-05 12:48:05.259617496 +0800
6202 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
6205 +#define IN_BOOTLOADER
6206 #include "miscsetup.h"
6209 Index: linux-2.6.10/MAINTAINERS
6210 ===================================================================
6211 --- linux-2.6.10.orig/MAINTAINERS 2005-03-31 15:35:24.000000000 +0800
6212 +++ linux-2.6.10/MAINTAINERS 2005-04-05 12:48:05.181629352 +0800
6213 @@ -1245,6 +1245,12 @@
6214 W: http://developer.osdl.org/rddunlap/kj-patches/
6217 +KGDB FOR I386 PLATFORM
6219 +M: george@mvista.com
6220 +L: linux-net@vger.kernel.org
6225 M: neilb@cse.unsw.edu.au
6226 Index: linux-2.6.10/drivers/char/sysrq.c
6227 ===================================================================
6228 --- linux-2.6.10.orig/drivers/char/sysrq.c 2005-03-31 15:57:20.000000000 +0800
6229 +++ linux-2.6.10/drivers/char/sysrq.c 2005-04-05 12:48:05.191627832 +0800
6231 #include <linux/spinlock.h>
6233 #include <asm/ptrace.h>
6234 +#ifdef CONFIG_KGDB_SYSRQ
6236 +#define GDB_OP &kgdb_op
6237 +static void kgdb_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty)
6239 + printk("kgdb sysrq\n");
6243 +static struct sysrq_key_op kgdb_op = {
6244 + .handler = kgdb_sysrq,
6245 + .help_msg = "kGdb|Fgdb",
6246 + .action_msg = "Debug breakpoint\n",
6250 +#define GDB_OP NULL
6254 extern void reset_vc(unsigned int);
6258 /* e */ &sysrq_term_op,
6263 /* i */ &sysrq_kill_op,
6265 Index: linux-2.6.10/drivers/char/keyboard.c
6266 ===================================================================
6267 --- linux-2.6.10.orig/drivers/char/keyboard.c 2004-12-25 05:35:50.000000000 +0800
6268 +++ linux-2.6.10/drivers/char/keyboard.c 2005-04-05 12:48:05.190627984 +0800
6269 @@ -1078,6 +1078,9 @@
6271 if (sysrq_down && down && !rep) {
6272 handle_sysrq(kbd_sysrq_xlate[keycode], regs, tty);
6273 +#ifdef CONFIG_KGDB_SYSRQ
6274 + sysrq_down = 0; /* in case we miss the "up" event */
6279 Index: linux-2.6.10/drivers/serial/serial_core.c
6280 ===================================================================
6281 --- linux-2.6.10.orig/drivers/serial/serial_core.c 2004-12-25 05:34:26.000000000 +0800
6282 +++ linux-2.6.10/drivers/serial/serial_core.c 2005-04-05 12:48:05.188628288 +0800
6283 @@ -1924,6 +1924,15 @@
6289 + extern int kgdb_irq;
6291 + if (port->irq == kgdb_irq)
6297 * If there isn't a port here, don't do anything further.
6299 Index: linux-2.6.10/drivers/serial/8250.c
6300 ===================================================================
6301 --- linux-2.6.10.orig/drivers/serial/8250.c 2004-12-25 05:33:50.000000000 +0800
6302 +++ linux-2.6.10/drivers/serial/8250.c 2005-04-05 12:48:05.185628744 +0800
6303 @@ -1350,12 +1350,21 @@
6304 spin_unlock_irqrestore(&up->port.lock, flags);
6311 static int serial8250_startup(struct uart_port *port)
6313 struct uart_8250_port *up = (struct uart_8250_port *)port;
6314 unsigned long flags;
6318 + if (up->port.irq == kgdb_irq)
6322 up->capabilities = uart_config[up->port.type].flags;
6325 @@ -2438,6 +2447,33 @@
6327 EXPORT_SYMBOL(serial8250_unregister_port);
6330 +#include <linux/serialP.h>
6333 + * Find all the ports using the given irq and shut them down.
6334 + * Result should be that the irq will be released.
6336 +void shutdown_for_kgdb(struct async_struct * info)
6338 + int irq = info->state->irq;
6339 + struct uart_8250_port *up;
6342 + kgdb_irq = irq; /* save for later init */
6343 + for (ttyS = 0; ttyS < UART_NR; ttyS++){
6344 + up = &serial8250_ports[ttyS];
6345 + if (up->port.irq == irq && (irq_lists + irq)->head) {
6346 +#ifdef CONFIG_DEBUG_SPINLOCK /* ugly business... */
6347 + if(up->port.lock.magic != SPINLOCK_MAGIC)
6348 + spin_lock_init(&up->port.lock);
6350 + serial8250_shutdown(&up->port);
6354 +#endif /* CONFIG_KGDB */
6356 static int __init serial8250_init(void)