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>
190 Signed-off-by: Andrew Morton <akpm@osdl.org>
193 25-akpm/Documentation/i386/kgdb/andthen | 100 +
194 25-akpm/Documentation/i386/kgdb/debug-nmi.txt | 37
195 25-akpm/Documentation/i386/kgdb/gdb-globals.txt | 71
196 25-akpm/Documentation/i386/kgdb/gdbinit | 14
197 25-akpm/Documentation/i386/kgdb/gdbinit-modules | 146 +
198 25-akpm/Documentation/i386/kgdb/gdbinit.hw | 117 +
199 25-akpm/Documentation/i386/kgdb/kgdb.txt | 775 +++++++
200 25-akpm/Documentation/i386/kgdb/loadmodule.sh | 78
201 25-akpm/MAINTAINERS | 6
202 25-akpm/arch/i386/Kconfig | 8
203 25-akpm/arch/i386/Kconfig.debug | 2
204 25-akpm/arch/i386/Kconfig.kgdb | 175 +
205 25-akpm/arch/i386/Makefile | 3
206 25-akpm/arch/i386/kernel/Makefile | 1
207 25-akpm/arch/i386/kernel/entry.S | 29
208 25-akpm/arch/i386/kernel/kgdb_stub.c | 2330 ++++++++++++++++++++++++
209 25-akpm/arch/i386/kernel/nmi.c | 25
210 25-akpm/arch/i386/kernel/smp.c | 12
211 25-akpm/arch/i386/kernel/traps.c | 77
212 25-akpm/arch/i386/lib/Makefile | 1
213 25-akpm/arch/i386/lib/kgdb_serial.c | 485 ++++
214 25-akpm/arch/i386/mm/fault.c | 6
215 25-akpm/arch/x86_64/boot/compressed/head.S | 1
216 25-akpm/arch/x86_64/boot/compressed/misc.c | 1
217 25-akpm/drivers/char/keyboard.c | 3
218 25-akpm/drivers/char/sysrq.c | 23
219 25-akpm/drivers/serial/8250.c | 40
220 25-akpm/drivers/serial/serial_core.c | 5
221 25-akpm/include/asm-i386/bugs.h | 21
222 25-akpm/include/asm-i386/kgdb.h | 59
223 25-akpm/include/asm-i386/kgdb_local.h | 102 +
224 25-akpm/include/linux/config.h | 3
225 25-akpm/include/linux/dwarf2-lang.h | 132 +
226 25-akpm/include/linux/dwarf2.h | 738 +++++++
227 25-akpm/include/linux/serial_core.h | 4
228 25-akpm/include/linux/spinlock.h | 12
229 25-akpm/kernel/pid.c | 6
230 25-akpm/kernel/sched.c | 7
231 38 files changed, 5645 insertions(+), 10 deletions(-)
233 diff -puN arch/i386/Kconfig~kgdb-ga arch/i386/Kconfig
234 --- 25/arch/i386/Kconfig~kgdb-ga 2004-10-21 14:54:15.256604136 -0700
235 +++ 25-akpm/arch/i386/Kconfig 2004-10-21 14:54:15.295598208 -0700
236 @@ -1184,6 +1184,14 @@ menu "Executable file formats"
238 source "fs/Kconfig.binfmt"
240 +config TRAP_BAD_SYSCALL_EXITS
241 + bool "Debug bad system call exits"
244 + If you say Y here the kernel will check for system calls which
245 + return without clearing preempt.
250 source "drivers/Kconfig"
251 diff -puN arch/i386/kernel/entry.S~kgdb-ga arch/i386/kernel/entry.S
252 --- 25/arch/i386/kernel/entry.S~kgdb-ga 2004-10-21 14:54:15.257603984 -0700
253 +++ 25-akpm/arch/i386/kernel/entry.S 2004-10-21 14:54:15.296598056 -0700
256 #include <asm/page.h>
257 #include "irq_vectors.h"
258 + /* We do not recover from a stack overflow, but at least
259 + * we know it happened and should be able to track it down.
261 +#ifdef CONFIG_STACK_OVERFLOW_TEST
262 +#define STACK_OVERFLOW_TEST \
263 + testl $(THREAD_SIZE - 512),%esp; \
265 + call stack_overflow; \
268 +#define STACK_OVERFLOW_TEST
271 #define nr_syscalls ((syscall_table_size)/4)
273 @@ -94,7 +106,8 @@ VM_MASK = 0x00020000
275 movl $(__USER_DS), %edx; \
279 + STACK_OVERFLOW_TEST
281 #define RESTORE_INT_REGS \
283 @@ -198,6 +211,7 @@ need_resched:
284 # sysenter call handler stub
285 ENTRY(sysenter_entry)
286 movl TSS_sysenter_esp0(%esp),%esp
287 + .globl sysenter_past_esp
291 @@ -260,6 +274,19 @@ syscall_exit:
292 testw $_TIF_ALLWORK_MASK, %cx # current->work
293 jne syscall_exit_work
295 +#ifdef CONFIG_TRAP_BAD_SYSCALL_EXITS
296 + movl EFLAGS(%esp), %eax # mix EFLAGS and CS
298 + testl $(VM_MASK | 3), %eax
299 + jz resume_kernelX # returning to kernel or vm86-space
301 + cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
310 # perform work that needs to be done immediately before resumption
311 diff -puN /dev/null arch/i386/kernel/kgdb_stub.c
312 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
313 +++ 25-akpm/arch/i386/kernel/kgdb_stub.c 2004-10-21 14:54:15.307596384 -0700
317 + * This program is free software; you can redistribute it and/or modify it
318 + * under the terms of the GNU General Public License as published by the
319 + * Free Software Foundation; either version 2, or (at your option) any
322 + * This program is distributed in the hope that it will be useful, but
323 + * WITHOUT ANY WARRANTY; without even the implied warranty of
324 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
325 + * General Public License for more details.
330 + * Copyright (c) 2000 VERITAS Software Corporation.
333 +/****************************************************************************
334 + * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
336 + * Module name: remcom.c $
338 + * Date: 91/03/09 12:29:49 $
339 + * Contributor: Lake Stevens Instrument Division$
341 + * Description: low level support for gdb debugger. $
343 + * Considerations: only works on target hardware $
345 + * Written by: Glenn Engel $
346 + * Updated by: David Grothe <dave@gcom.com>
347 + * ModuleState: Experimental $
349 + * NOTES: See Below $
351 + * Modified for 386 by Jim Kingdon, Cygnus Support.
352 + * Compatibility with 2.1.xx kernel by David Grothe <dave@gcom.com>
354 + * Changes to allow auto initilization. All that is needed is that it
355 + * be linked with the kernel and a break point (int 3) be executed.
356 + * The header file <asm/kgdb.h> defines BREAKPOINT to allow one to do
357 + * this. It should also be possible, once the interrupt system is up, to
358 + * call putDebugChar("+"). Once this is done, the remote debugger should
359 + * get our attention by sending a ^C in a packet. George Anzinger
360 + * <george@mvista.com>
361 + * Integrated into 2.2.5 kernel by Tigran Aivazian <tigran@sco.com>
362 + * Added thread support, support for multiple processors,
363 + * support for ia-32(x86) hardware debugging.
364 + * Amit S. Kale ( akale@veritas.com )
367 + * To enable debugger support, two things need to happen. One, a
368 + * call to set_debug_traps() is necessary in order to allow any breakpoints
369 + * or error conditions to be properly intercepted and reported to gdb.
370 + * Two, a breakpoint needs to be generated to begin communication. This
371 + * is most easily accomplished by a call to breakpoint(). Breakpoint()
372 + * simulates a breakpoint by executing an int 3.
376 + * The following gdb commands are supported:
378 + * command function Return value
380 + * g return the value of the CPU registers hex data or ENN
381 + * G set the value of the CPU registers OK or ENN
383 + * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
384 + * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN
386 + * c Resume at current address SNN ( signal NN)
387 + * cAA..AA Continue at address AA..AA SNN
389 + * s Step one instruction SNN
390 + * sAA..AA Step one instruction from AA..AA SNN
394 + * ? What was the last sigval ? SNN (signal NN)
396 + * All commands and responses are sent with a packet which includes a
397 + * checksum. A packet consists of
399 + * $<packet info>#<checksum>.
402 + * <packet info> :: <characters representing the command or response>
403 + * <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>>
405 + * When a packet is received, it is first acknowledged with either '+' or '-'.
406 + * '+' indicates a successful transfer. '-' indicates a failed transfer.
411 + * $m0,10#2a +$00010203040506070809101112131415#42
413 + ****************************************************************************/
414 +#define KGDB_VERSION "<20030915.1651.33>"
415 +#include <linux/config.h>
416 +#include <linux/types.h>
417 +#include <asm/string.h> /* for strcpy */
418 +#include <linux/kernel.h>
419 +#include <linux/sched.h>
420 +#include <asm/vm86.h>
421 +#include <asm/system.h>
422 +#include <asm/ptrace.h> /* for linux pt_regs struct */
423 +#include <asm/kgdb_local.h>
424 +#include <linux/list.h>
425 +#include <asm/atomic.h>
426 +#include <asm/processor.h>
427 +#include <linux/irq.h>
428 +#include <asm/desc.h>
430 +/************************************************************************
432 + * external low-level support routines
434 +typedef void (*Function) (void); /* pointer to a function */
436 +/* Thread reference */
437 +typedef unsigned char threadref[8];
439 +extern void putDebugChar(int); /* write a single character */
440 +extern int getDebugChar(void); /* read and return a single char */
442 +/************************************************************************/
443 +/* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
444 +/* at least NUMREGBYTES*2 are needed for register packets */
445 +/* Longer buffer is needed to list all threads */
448 +char *kgdb_version = KGDB_VERSION;
450 +/* debug > 0 prints ill-formed commands in valid packets & checksum errors */
451 +int debug_regs = 0; /* set to non-zero to print registers */
453 +/* filled in by an external module */
454 +char *gdb_module_offsets;
456 +static const char hexchars[] = "0123456789abcdef";
458 +/* Number of bytes of registers. */
459 +#define NUMREGBYTES 64
461 + * Note that this register image is in a different order than
462 + * the register image that Linux produces at interrupt time.
464 + * Linux's register image is defined by struct pt_regs in ptrace.h.
465 + * Just why GDB uses a different order is a historical mystery.
467 +enum regnames { _EAX, /* 0 */
475 + _PC /* 8 also known as eip */ ,
476 + _PS /* 9 also known as eflags */ ,
485 +/*************************** ASSEMBLY CODE MACROS *************************/
487 + * Put the error code here just in case the user cares.
488 + * Likewise, the vector number here (since GDB only gets the signal
489 + * number through the usual means, and that's not very specific).
490 + * The called_from is the return address so he can tell how we entered kgdb.
491 + * This will allow him to seperate out the various possible entries.
493 +#define REMOTE_DEBUG 0 /* set != to turn on printing (also available in info) */
495 +#define PID_MAX PID_MAX_DEFAULT
498 +void smp_send_nmi_allbutself(void);
501 +#ifndef CONFIG_NO_KGDB_CPUS
502 +#define CONFIG_NO_KGDB_CPUS 2
504 +#if CONFIG_NO_KGDB_CPUS > NR_CPUS
505 +#define MAX_NO_CPUS NR_CPUS
507 +#define MAX_NO_CPUS CONFIG_NO_KGDB_CPUS
509 +#define hold_init hold_on_sstep: 1,
510 +#define MAX_CPU_MASK (unsigned long)((1LL << MAX_NO_CPUS) - 1LL)
511 +#define NUM_CPUS num_online_cpus()
516 +#define MAX_NO_CPUS 1
519 +#define NOCPU (struct task_struct *)0xbad1fbad
524 + long long entry_tsc;
527 + int print_debug_info;
531 + volatile struct task_struct *task;
534 + struct pt_regs *regs;
535 + } cpus_waiting[MAX_NO_CPUS];
537 +} kgdb_info = {hold_init print_debug_info:REMOTE_DEBUG, vector:-1};
541 +#define used_m kgdb_info.used_malloc
543 + * This is little area we set aside to contain the stack we
544 + * need to build to allow gdb to call functions. We use one
545 + * per cpu to avoid locking issues. We will do all this work
546 + * with interrupts off so that should take care of the protection
549 +#define LOOKASIDE_SIZE 200 /* should be more than enough */
550 +#define MALLOC_MAX 200 /* Max malloc size */
553 + int array[LOOKASIDE_SIZE];
554 +} fn_call_lookaside[MAX_NO_CPUS];
556 +static int trap_cpu;
557 +static unsigned int OLD_esp;
559 +#define END_OF_LOOKASIDE &fn_call_lookaside[trap_cpu].array[LOOKASIDE_SIZE]
560 +#define IF_BIT 0x200
561 +#define TF_BIT 0x100
563 +#define MALLOC_ROUND 8-1
565 +static char malloc_array[MALLOC_MAX];
566 +IF_SMP(static void to_gdb(const char *mess));
571 + if (size <= (MALLOC_MAX - used_m)) {
572 + int old_used = used_m;
573 + used_m += ((size + MALLOC_ROUND) & (~MALLOC_ROUND));
574 + return &malloc_array[old_used];
581 + * Gdb calls functions by pushing agruments, including a return address
582 + * on the stack and the adjusting EIP to point to the function. The
583 + * whole assumption in GDB is that we are on a different stack than the
584 + * one the "user" i.e. code that hit the break point, is on. This, of
585 + * course is not true in the kernel. Thus various dodges are needed to
586 + * do the call without directly messing with EIP (which we can not change
587 + * as it is just a location and not a register. To adjust it would then
588 + * require that we move every thing below EIP up or down as needed. This
589 + * will not work as we may well have stack relative pointer on the stack
590 + * (such as the pointer to regs, for example).
592 + * So here is what we do:
593 + * We detect gdb attempting to store into the stack area and instead, store
594 + * into the fn_call_lookaside.array at the same relative location as if it
595 + * were the area ESP pointed at. We also trap ESP modifications
596 + * and uses these to adjust fn_call_lookaside.esp. On entry
597 + * fn_call_lookaside.esp will be set to point at the last entry in
598 + * fn_call_lookaside.array. This allows us to check if it has changed, and
599 + * if so, on exit, we add the registers we will use to do the move and a
600 + * trap/ interrupt return exit sequence. We then adjust the eflags in the
601 + * regs array (remember we now have a copy in the fn_call_lookaside.array) to
602 + * kill the interrupt bit, AND we change EIP to point at our set up stub.
603 + * As part of the register set up we preset the registers to point at the
604 + * begining and end of the fn_call_lookaside.array, so all the stub needs to
605 + * do is move words from the array to the stack until ESP= the desired value
606 + * then do the rti. This will then transfer to the desired function with
607 + * all the correct registers. Nifty huh?
609 +extern asmlinkage void fn_call_stub(void);
610 +extern asmlinkage void fn_rtn_stub(void);
612 +__asm__("fn_rtn_stub:\n\t"
613 + "movl %eax,%esp\n\t"
614 + "fn_call_stub:\n\t"
616 + "addl $-4,%ebx\n\t"
617 + "movl (%ebx), %eax\n\t"
619 + "cmpl %esp,%ecx\n\t"
626 +#define gdb_i386vector kgdb_info.vector
627 +#define gdb_i386errcode kgdb_info.errcode
628 +#define waiting_cpus kgdb_info.cpus_waiting
629 +#define remote_debug kgdb_info.print_debug_info
630 +#define hold_cpu(cpu) kgdb_info.cpus_waiting[cpu].hold
634 +static int in_kgdb_called;
635 +static spinlock_t waitlocks[MAX_NO_CPUS] =
636 + {[0 ... MAX_NO_CPUS - 1] = SPIN_LOCK_UNLOCKED };
638 + * The following array has the thread pointer of each of the "other"
639 + * cpus. We make it global so it can be seen by gdb.
641 +volatile int in_kgdb_entry_log[MAX_NO_CPUS];
642 +volatile struct pt_regs *in_kgdb_here_log[MAX_NO_CPUS];
644 +static spinlock_t continuelocks[MAX_NO_CPUS];
646 +spinlock_t kgdb_spinlock = SPIN_LOCK_UNLOCKED;
647 +/* waiters on our spinlock plus us */
648 +static atomic_t spinlock_waiters = ATOMIC_INIT(1);
649 +static int spinlock_count = 0;
650 +static int spinlock_cpu = 0;
652 + * Note we use nested spin locks to account for the case where a break
653 + * point is encountered when calling a function by user direction from
654 + * kgdb. Also there is the memory exception recursion to account for.
655 + * Well, yes, but this lets other cpus thru too. Lets add a
656 + * cpu id to the lock.
658 +#define KGDB_SPIN_LOCK(x) if( spinlock_count == 0 || \
659 + spinlock_cpu != smp_processor_id()){\
660 + atomic_inc(&spinlock_waiters); \
661 + while (! spin_trylock(x)) {\
664 + atomic_dec(&spinlock_waiters); \
665 + spinlock_count = 1; \
666 + spinlock_cpu = smp_processor_id(); \
668 + spinlock_count++; \
670 +#define KGDB_SPIN_UNLOCK(x) if( --spinlock_count == 0) spin_unlock(x)
672 +unsigned kgdb_spinlock = 0;
673 +#define KGDB_SPIN_LOCK(x) --*x
674 +#define KGDB_SPIN_UNLOCK(x) ++*x
680 + if ((ch >= 'a') && (ch <= 'f'))
681 + return (ch - 'a' + 10);
682 + if ((ch >= '0') && (ch <= '9'))
684 + if ((ch >= 'A') && (ch <= 'F'))
685 + return (ch - 'A' + 10);
689 +/* scan for the sequence $<data>#<checksum> */
691 +getpacket(char *buffer)
693 + unsigned char checksum;
694 + unsigned char xmitcsum;
700 + /* wait around for the start character, ignore all other characters */
701 + while ((ch = (getDebugChar() & 0x7f)) != '$') ;
707 + /* now, read until a # or end of buffer is found */
708 + while (count < BUFMAX) {
709 + ch = getDebugChar() & 0x7f;
712 + checksum = checksum + ch;
713 + buffer[count] = ch;
719 + xmitcsum = hex(getDebugChar() & 0x7f) << 4;
720 + xmitcsum += hex(getDebugChar() & 0x7f);
721 + if ((remote_debug) && (checksum != xmitcsum)) {
723 + ("bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n",
724 + checksum, xmitcsum, buffer);
727 + if (checksum != xmitcsum)
728 + putDebugChar('-'); /* failed checksum */
730 + putDebugChar('+'); /* successful transfer */
731 + /* if a sequence char is present, reply the sequence ID */
732 + if (buffer[2] == ':') {
733 + putDebugChar(buffer[0]);
734 + putDebugChar(buffer[1]);
735 + /* remove sequence chars from buffer */
736 + count = strlen(buffer);
737 + for (i = 3; i <= count; i++)
738 + buffer[i - 3] = buffer[i];
742 + } while (checksum != xmitcsum);
745 + printk("R:%s\n", buffer);
748 +/* send the packet in buffer. */
751 +putpacket(char *buffer)
753 + unsigned char checksum;
757 + /* $<packet info>#<checksum>. */
760 + printk("T:%s\n", buffer);
765 + while ((ch = buffer[count])) {
772 + putDebugChar(hexchars[checksum >> 4]);
773 + putDebugChar(hexchars[checksum % 16]);
775 + } while ((getDebugChar() & 0x7f) != '+');
779 +static char remcomInBuffer[BUFMAX];
780 +static char remcomOutBuffer[BUFMAX];
784 +debug_error(char *format, char *parm)
787 + printk(format, parm);
791 +print_regs(struct pt_regs *regs)
793 + printk("EAX=%08lx ", regs->eax);
794 + printk("EBX=%08lx ", regs->ebx);
795 + printk("ECX=%08lx ", regs->ecx);
796 + printk("EDX=%08lx ", regs->edx);
798 + printk("ESI=%08lx ", regs->esi);
799 + printk("EDI=%08lx ", regs->edi);
800 + printk("EBP=%08lx ", regs->ebp);
801 + printk("ESP=%08lx ", (long) ®s->esp);
803 + printk(" DS=%08x ", regs->xds);
804 + printk(" ES=%08x ", regs->xes);
805 + printk(" SS=%08x ", __KERNEL_DS);
806 + printk(" FL=%08lx ", regs->eflags);
808 + printk(" CS=%08x ", regs->xcs);
809 + printk(" IP=%08lx ", regs->eip);
811 + printk(" FS=%08x ", regs->fs);
812 + printk(" GS=%08x ", regs->gs);
818 +#define NEW_esp fn_call_lookaside[trap_cpu].esp
821 +regs_to_gdb_regs(int *gdb_regs, struct pt_regs *regs)
823 + gdb_regs[_EAX] = regs->eax;
824 + gdb_regs[_EBX] = regs->ebx;
825 + gdb_regs[_ECX] = regs->ecx;
826 + gdb_regs[_EDX] = regs->edx;
827 + gdb_regs[_ESI] = regs->esi;
828 + gdb_regs[_EDI] = regs->edi;
829 + gdb_regs[_EBP] = regs->ebp;
830 + gdb_regs[_DS] = regs->xds;
831 + gdb_regs[_ES] = regs->xes;
832 + gdb_regs[_PS] = regs->eflags;
833 + gdb_regs[_CS] = regs->xcs;
834 + gdb_regs[_PC] = regs->eip;
835 + /* Note, as we are a debugging the kernel, we will always
836 + * trap in kernel code, this means no priviledge change,
837 + * and so the pt_regs structure is not completely valid. In a non
838 + * privilege change trap, only EFLAGS, CS and EIP are put on the stack,
839 + * SS and ESP are not stacked, this means that the last 2 elements of
840 + * pt_regs is not valid (they would normally refer to the user stack)
841 + * also, using regs+1 is no good because you end up will a value that is
842 + * 2 longs (8) too high. This used to cause stepping over functions
843 + * to fail, so my fix is to use the address of regs->esp, which
844 + * should point at the end of the stack frame. Note I have ignored
845 + * completely exceptions that cause an error code to be stacked, such
846 + * as double fault. Stuart Hughes, Zentropix.
847 + * original code: gdb_regs[_ESP] = (int) (regs + 1) ;
849 + * this is now done on entry and moved to OLD_esp (as well as NEW_esp).
851 + gdb_regs[_ESP] = NEW_esp;
852 + gdb_regs[_SS] = __KERNEL_DS;
853 + gdb_regs[_FS] = 0xFFFF;
854 + gdb_regs[_GS] = 0xFFFF;
855 +} /* regs_to_gdb_regs */
858 +gdb_regs_to_regs(int *gdb_regs, struct pt_regs *regs)
860 + regs->eax = gdb_regs[_EAX];
861 + regs->ebx = gdb_regs[_EBX];
862 + regs->ecx = gdb_regs[_ECX];
863 + regs->edx = gdb_regs[_EDX];
864 + regs->esi = gdb_regs[_ESI];
865 + regs->edi = gdb_regs[_EDI];
866 + regs->ebp = gdb_regs[_EBP];
867 + regs->xds = gdb_regs[_DS];
868 + regs->xes = gdb_regs[_ES];
869 + regs->eflags = gdb_regs[_PS];
870 + regs->xcs = gdb_regs[_CS];
871 + regs->eip = gdb_regs[_PC];
872 + NEW_esp = gdb_regs[_ESP]; /* keep the value */
873 +#if 0 /* can't change these */
874 + regs->esp = gdb_regs[_ESP];
875 + regs->xss = gdb_regs[_SS];
876 + regs->fs = gdb_regs[_FS];
877 + regs->gs = gdb_regs[_GS];
880 +} /* gdb_regs_to_regs */
882 +int thread_list = 0;
885 +get_gdb_regs(struct task_struct *p, struct pt_regs *regs, int *gdb_regs)
887 + unsigned long stack_page;
890 + if (!p || p == current) {
891 + regs_to_gdb_regs(gdb_regs, regs);
895 + for (i = 0; i < MAX_NO_CPUS; i++) {
896 + if (p == kgdb_info.cpus_waiting[i].task) {
897 + regs_to_gdb_regs(gdb_regs,
898 + kgdb_info.cpus_waiting[i].regs);
900 + (int) &kgdb_info.cpus_waiting[i].regs->esp;
906 + memset(gdb_regs, 0, NUMREGBYTES);
907 + gdb_regs[_ESP] = p->thread.esp;
908 + gdb_regs[_PC] = p->thread.eip;
909 + gdb_regs[_EBP] = *(int *) gdb_regs[_ESP];
910 + gdb_regs[_EDI] = *(int *) (gdb_regs[_ESP] + 4);
911 + gdb_regs[_ESI] = *(int *) (gdb_regs[_ESP] + 8);
914 + * This code is to give a more informative notion of where a process
915 + * is waiting. It is used only when the user asks for a thread info
916 + * list. If he then switches to the thread, s/he will find the task
917 + * is in schedule, but a back trace should show the same info we come
918 + * up with. This code was shamelessly purloined from process.c. It was
919 + * then enhanced to provide more registers than simply the program
923 + if (!thread_list) {
927 + if (p->state == TASK_RUNNING)
929 + stack_page = (unsigned long) p->thread_info;
930 + if (gdb_regs[_ESP] < stack_page || gdb_regs[_ESP] >
931 + THREAD_SIZE - sizeof(long) + stack_page)
933 + /* include/asm-i386/system.h:switch_to() pushes ebp last. */
935 + if (gdb_regs[_EBP] < stack_page ||
936 + gdb_regs[_EBP] > THREAD_SIZE - 2*sizeof(long) + stack_page)
938 + gdb_regs[_PC] = *(unsigned long *) (gdb_regs[_EBP] + 4);
939 + gdb_regs[_ESP] = gdb_regs[_EBP] + 8;
940 + gdb_regs[_EBP] = *(unsigned long *) gdb_regs[_EBP];
941 + if (!in_sched_functions(gdb_regs[_PC]))
943 + } while (count++ < 16);
947 +/* Indicate to caller of mem2hex or hex2mem that there has been an
949 +static volatile int mem_err = 0;
950 +static volatile int mem_err_expected = 0;
951 +static volatile int mem_err_cnt = 0;
952 +static int garbage_loc = -1;
955 +get_char(char *addr)
961 +set_char(char *addr, int val, int may_fault)
964 + * This code traps references to the area mapped to the kernel
965 + * stack as given by the regs and, instead, stores to the
966 + * fn_call_lookaside[cpu].array
969 + (unsigned int) addr < OLD_esp &&
970 + ((unsigned int) addr > (OLD_esp - (unsigned int) LOOKASIDE_SIZE))) {
971 + addr = (char *) END_OF_LOOKASIDE - ((char *) OLD_esp - addr);
976 +/* convert the memory pointed to by mem into hex, placing result in buf */
977 +/* return a pointer to the last char put in buf (null) */
978 +/* If MAY_FAULT is non-zero, then we should set mem_err in response to
979 + a fault; if zero treat a fault like any other fault in the stub. */
981 +mem2hex(char *mem, char *buf, int count, int may_fault)
987 + mem_err_expected = 1;
990 + for (i = 0; i < count; i++) {
991 + /* printk("%lx = ", mem) ; */
993 + ch = get_char(mem++);
995 + /* printk("%02x\n", ch & 0xFF) ; */
996 + if (may_fault && mem_err) {
998 + printk("Mem fault fetching from addr %lx\n",
1000 + *buf = 0; /* truncate buffer */
1003 + *buf++ = hexchars[ch >> 4];
1004 + *buf++ = hexchars[ch % 16];
1008 + mem_err_expected = 0;
1012 +/* convert the hex array pointed to by buf into binary to be placed in mem */
1013 +/* return a pointer to the character AFTER the last byte written */
1014 +/* NOTE: We use the may fault flag to also indicate if the write is to
1015 + * the registers (0) or "other" memory (!=0)
1018 +hex2mem(char *buf, char *mem, int count, int may_fault)
1024 + mem_err_expected = 1;
1027 + for (i = 0; i < count; i++) {
1028 + ch = hex(*buf++) << 4;
1029 + ch = ch + hex(*buf++);
1030 + set_char(mem++, ch, may_fault);
1032 + if (may_fault && mem_err) {
1034 + printk("Mem fault storing to addr %lx\n",
1035 + (long) (mem - 1));
1040 + mem_err_expected = 0;
1044 +/**********************************************/
1045 +/* WHILE WE FIND NICE HEX CHARS, BUILD AN INT */
1046 +/* RETURN NUMBER OF CHARS PROCESSED */
1047 +/**********************************************/
1049 +hexToInt(char **ptr, int *intValue)
1057 + hexValue = hex(**ptr);
1058 + if (hexValue >= 0) {
1059 + *intValue = (*intValue << 4) | hexValue;
1067 + return (numChars);
1070 +#define stubhex(h) hex(h)
1071 +#ifdef old_thread_list
1074 +stub_unpack_int(char *buff, int fieldlength)
1079 + while (fieldlength) {
1080 + nibble = stubhex(*buff++);
1084 + retval = retval << 4;
1090 +pack_hex_byte(char *pkt, int byte)
1092 + *pkt++ = hexchars[(byte >> 4) & 0xf];
1093 + *pkt++ = hexchars[(byte & 0xf)];
1097 +#define BUF_THREAD_ID_SIZE 16
1100 +pack_threadid(char *pkt, threadref * id)
1103 + unsigned char *altid;
1105 + altid = (unsigned char *) id;
1106 + limit = pkt + BUF_THREAD_ID_SIZE;
1107 + while (pkt < limit)
1108 + pkt = pack_hex_byte(pkt, *altid++);
1112 +#ifdef old_thread_list
1114 +unpack_byte(char *buf, int *value)
1116 + *value = stub_unpack_int(buf, 2);
1121 +unpack_threadid(char *inbuf, threadref * id)
1124 + char *limit = inbuf + BUF_THREAD_ID_SIZE;
1127 + altref = (char *) id;
1129 + while (inbuf < limit) {
1130 + x = stubhex(*inbuf++);
1131 + y = stubhex(*inbuf++);
1132 + *altref++ = (x << 4) | y;
1138 +int_to_threadref(threadref * id, int value)
1140 + unsigned char *scan;
1142 + scan = (unsigned char *) id;
1148 + *scan++ = (value >> 24) & 0xff;
1149 + *scan++ = (value >> 16) & 0xff;
1150 + *scan++ = (value >> 8) & 0xff;
1151 + *scan++ = (value & 0xff);
1154 +int_to_hex_v(unsigned char * id, int value)
1156 + unsigned char *start = id;
1160 + for (shift = 28; shift >= 0; shift -= 4) {
1161 + if ((ch = (value >> shift) & 0xf) || (id != start)) {
1162 + *id = hexchars[ch];
1168 + return id - start;
1170 +#ifdef old_thread_list
1173 +threadref_to_int(threadref * ref)
1176 + unsigned char *scan;
1178 + scan = (char *) ref;
1182 + value = (value << 8) | ((*scan++) & 0xff);
1187 +cmp_str(char *s1, char *s2, int count)
1190 + if (*s1++ != *s2++)
1196 +#if 1 /* this is a hold over from 2.4 where O(1) was "sometimes" */
1197 +extern struct task_struct *kgdb_get_idle(int cpu);
1198 +#define idle_task(cpu) kgdb_get_idle(cpu)
1200 +#define idle_task(cpu) init_tasks[cpu]
1203 +extern int kgdb_pid_init_done;
1205 +struct task_struct *
1208 + struct task_struct *thread;
1209 + if (pid >= PID_MAX && pid <= (PID_MAX + MAX_NO_CPUS)) {
1211 + return idle_task(pid - PID_MAX);
1214 + * find_task_by_pid is relatively safe all the time
1215 + * Other pid functions require lock downs which imply
1216 + * that we may be interrupting them (as we get here
1217 + * in the middle of most any lock down).
1218 + * Still we don't want to call until the table exists!
1220 + if (kgdb_pid_init_done){
1221 + thread = find_task_by_pid(pid);
1230 +struct hw_breakpoint {
1235 +} breakinfo[4] = { {enabled:0},
1240 +unsigned hw_breakpoint_status;
1242 +correct_hw_break(void)
1249 + asm volatile ("movl %%db7, %0\n":"=r" (dr7)
1251 + /* *INDENT-OFF* */
1253 + unsigned addr0, addr1, addr2, addr3;
1254 + asm volatile ("movl %%db0, %0\n"
1255 + "movl %%db1, %1\n"
1256 + "movl %%db2, %2\n"
1257 + "movl %%db3, %3\n"
1258 + :"=r" (addr0), "=r"(addr1),
1259 + "=r"(addr2), "=r"(addr3)
1264 + for (breakno = 0; breakno < 3; breakno++) {
1265 + breakbit = 2 << (breakno << 1);
1266 + if (!(dr7 & breakbit) && breakinfo[breakno].enabled) {
1269 + dr7 &= ~(0xf0000 << (breakno << 2));
1270 + dr7 |= (((breakinfo[breakno].len << 2) |
1271 + breakinfo[breakno].type) << 16) <<
1273 + switch (breakno) {
1275 + asm volatile ("movl %0, %%dr0\n"::"r"
1276 + (breakinfo[breakno].addr));
1280 + asm volatile ("movl %0, %%dr1\n"::"r"
1281 + (breakinfo[breakno].addr));
1285 + asm volatile ("movl %0, %%dr2\n"::"r"
1286 + (breakinfo[breakno].addr));
1290 + asm volatile ("movl %0, %%dr3\n"::"r"
1291 + (breakinfo[breakno].addr));
1294 + } else if ((dr7 & breakbit) && !breakinfo[breakno].enabled) {
1297 + dr7 &= ~(0xf0000 << (breakno << 2));
1301 + asm volatile ("movl %0, %%db7\n"::"r" (dr7));
1306 +remove_hw_break(unsigned breakno)
1308 + if (!breakinfo[breakno].enabled) {
1311 + breakinfo[breakno].enabled = 0;
1316 +set_hw_break(unsigned breakno, unsigned type, unsigned len, unsigned addr)
1318 + if (breakinfo[breakno].enabled) {
1321 + breakinfo[breakno].enabled = 1;
1322 + breakinfo[breakno].type = type;
1323 + breakinfo[breakno].len = len;
1324 + breakinfo[breakno].addr = addr;
1329 +static int in_kgdb_console = 0;
1332 +in_kgdb(struct pt_regs *regs)
1335 + int cpu = smp_processor_id();
1336 + in_kgdb_called = 1;
1337 + if (!spin_is_locked(&kgdb_spinlock)) {
1338 + if (in_kgdb_here_log[cpu] || /* we are holding this cpu */
1339 + in_kgdb_console) { /* or we are doing slow i/o */
1345 + /* As I see it the only reason not to let all cpus spin on
1346 + * the same spin_lock is to allow selected ones to proceed.
1347 + * This would be a good thing, so we leave it this way.
1348 + * Maybe someday.... Done !
1350 + * in_kgdb() is called from an NMI so we don't pretend
1351 + * to have any resources, like printk() for example.
1354 + kgdb_local_irq_save(flags); /* only local here, to avoid hanging */
1356 + * log arival of this cpu
1357 + * The NMI keeps on ticking. Protect against recurring more
1358 + * than once, and ignor the cpu that has the kgdb lock
1360 + in_kgdb_entry_log[cpu]++;
1361 + in_kgdb_here_log[cpu] = regs;
1362 + if (cpu == spinlock_cpu || waiting_cpus[cpu].task) {
1363 + goto exit_in_kgdb;
1366 + * For protection of the initilization of the spin locks by kgdb
1367 + * it locks the kgdb spinlock before it gets the wait locks set
1368 + * up. We wait here for the wait lock to be taken. If the
1369 + * kgdb lock goes away first?? Well, it could be a slow exit
1370 + * sequence where the wait lock is removed prior to the kgdb lock
1371 + * so if kgdb gets unlocked, we just exit.
1373 + while (spin_is_locked(&kgdb_spinlock) &&
1374 + !spin_is_locked(waitlocks + cpu)) ;
1375 + if (!spin_is_locked(&kgdb_spinlock)) {
1376 + goto exit_in_kgdb;
1378 + waiting_cpus[cpu].task = current;
1379 + waiting_cpus[cpu].pid = (current->pid) ? : (PID_MAX + cpu);
1380 + waiting_cpus[cpu].regs = regs;
1382 + spin_unlock_wait(waitlocks + cpu);
1384 + * log departure of this cpu
1386 + waiting_cpus[cpu].task = 0;
1387 + waiting_cpus[cpu].pid = 0;
1388 + waiting_cpus[cpu].regs = 0;
1389 + correct_hw_break();
1391 + in_kgdb_here_log[cpu] = 0;
1392 + kgdb_local_irq_restore(flags);
1395 + spin_unlock(continuelocks + smp_processor_id());
1400 +smp__in_kgdb(struct pt_regs regs)
1407 +in_kgdb(struct pt_regs *regs)
1409 + return (kgdb_spinlock);
1414 +printexceptioninfo(int exceptionNo, int errorcode, char *buffer)
1418 + switch (exceptionNo) {
1419 + case 1: /* debug exception */
1421 + case 3: /* breakpoint */
1422 + sprintf(buffer, "Software breakpoint");
1425 + sprintf(buffer, "Details not available");
1428 + asm volatile ("movl %%db6, %0\n":"=r" (dr6)
1430 + if (dr6 & 0x4000) {
1431 + sprintf(buffer, "Single step");
1434 + for (i = 0; i < 4; ++i) {
1435 + if (dr6 & (1 << i)) {
1436 + sprintf(buffer, "Hardware breakpoint %d", i);
1440 + sprintf(buffer, "Unknown trap");
1445 + * This function does all command procesing for interfacing to gdb.
1447 + * NOTE: The INT nn instruction leaves the state of the interrupt
1448 + * enable flag UNCHANGED. That means that when this routine
1449 + * is entered via a breakpoint (INT 3) instruction from code
1450 + * that has interrupts enabled, then interrupts will STILL BE
1451 + * enabled when this routine is entered. The first thing that
1452 + * we do here is disable interrupts so as to prevent recursive
1453 + * entries and bothersome serial interrupts while we are
1454 + * trying to run the serial port in polled mode.
1456 + * For kernel version 2.1.xx the kgdb_cli() actually gets a spin lock so
1457 + * it is always necessary to do a restore_flags before returning
1458 + * so as to let go of that lock.
1461 +kgdb_handle_exception(int exceptionVector,
1462 + int signo, int err_code, struct pt_regs *linux_regs)
1464 + struct task_struct *usethread = NULL;
1465 + struct task_struct *thread_list_start = 0, *thread = NULL;
1467 + int breakno, breaktype;
1472 + int thread_min = PID_MAX + MAX_NO_CPUS;
1473 +#ifdef old_thread_list
1477 + unsigned long flags;
1478 + int gdb_regs[NUMREGBYTES / 4];
1480 + IF_SMP(int entry_state = 0); /* 0, ok, 1, no nmi, 2 sync failed */
1483 +#define regs (*linux_regs)
1484 +#define NUMREGS NUMREGBYTES/4
1486 + * If the entry is not from the kernel then return to the Linux
1487 + * trap handler and let it process the interrupt normally.
1489 + if ((linux_regs->eflags & VM_MASK) || (3 & linux_regs->xcs)) {
1490 + printk("ignoring non-kernel exception\n");
1491 + print_regs(®s);
1495 + kgdb_local_irq_save(flags);
1497 + /* Get kgdb spinlock */
1499 + KGDB_SPIN_LOCK(&kgdb_spinlock);
1500 + rdtscll(kgdb_info.entry_tsc);
1502 + * We depend on this spinlock and the NMI watch dog to control the
1503 + * other cpus. They will arrive at "in_kgdb()" as a result of the
1504 + * NMI and will wait there for the following spin locks to be
1510 + if (cpu_callout_map & ~MAX_CPU_MASK) {
1511 + printk("kgdb : too many cpus, possibly not mapped"
1512 + " in contiguous space, change MAX_NO_CPUS"
1513 + " in kgdb_stub and make new kernel.\n"
1514 + " cpu_callout_map is %lx\n", cpu_callout_map);
1515 + goto exit_just_unlock;
1518 + if (spinlock_count == 1) {
1519 + int time = 0, end_time, dum = 0;
1521 + int cpu_logged_in[MAX_NO_CPUS] = {[0 ... MAX_NO_CPUS - 1] = (0)
1523 + if (remote_debug) {
1524 + printk("kgdb : cpu %d entry, syncing others\n",
1525 + smp_processor_id());
1527 + for (i = 0; i < MAX_NO_CPUS; i++) {
1529 + * Use trylock as we may already hold the lock if
1530 + * we are holding the cpu. Net result is all
1533 + spin_trylock(&waitlocks[i]);
1535 + for (i = 0; i < MAX_NO_CPUS; i++)
1536 + cpu_logged_in[i] = 0;
1538 + * Wait for their arrival. We know the watch dog is active if
1539 + * in_kgdb() has ever been called, as it is always called on a
1543 + end_time = time + 2; /* Note: we use the High order bits! */
1545 + if (num_online_cpus() > 1) {
1546 + int me_in_kgdb = in_kgdb_entry_log[smp_processor_id()];
1547 + smp_send_nmi_allbutself();
1548 + while (i < num_online_cpus() && time != end_time) {
1550 + for (j = 0; j < MAX_NO_CPUS; j++) {
1551 + if (waiting_cpus[j].task &&
1552 + !cpu_logged_in[j]) {
1554 + cpu_logged_in[j] = 1;
1555 + if (remote_debug) {
1557 + ("kgdb : cpu %d arrived at kgdb\n",
1561 + } else if (!waiting_cpus[j].task &&
1563 + waiting_cpus[j].task = NOCPU;
1564 + cpu_logged_in[j] = 1;
1565 + waiting_cpus[j].hold = 1;
1568 + if (!waiting_cpus[j].task &&
1569 + in_kgdb_here_log[j]) {
1571 + int wait = 100000;
1573 + if (!waiting_cpus[j].task &&
1574 + in_kgdb_here_log[j]) {
1576 + ("kgdb : cpu %d stall"
1580 + cpu_logged_in[j] = 1;
1581 + waiting_cpus[j].task =
1582 + (struct task_struct
1588 + if (in_kgdb_entry_log[smp_processor_id()] >
1589 + (me_in_kgdb + 10)) {
1595 + if (i < num_online_cpus()) {
1597 + ("kgdb : time out, proceeding without sync\n");
1599 + printk("kgdb : Waiting_cpus: 0 = %d, 1 = %d\n",
1600 + waiting_cpus[0].task != 0,
1601 + waiting_cpus[1].task != 0);
1602 + printk("kgdb : Cpu_logged in: 0 = %d, 1 = %d\n",
1603 + cpu_logged_in[0], cpu_logged_in[1]);
1605 + ("kgdb : in_kgdb_here_log in: 0 = %d, 1 = %d\n",
1606 + in_kgdb_here_log[0] != 0,
1607 + in_kgdb_here_log[1] != 0);
1609 + entry_state = NO_SYNC;
1613 + in_kgdb_entry_log[smp_processor_id()] -
1615 + printk("kgdb : sync after %d entries\n", ent);
1619 + if (remote_debug) {
1621 + ("kgdb : %d cpus, but watchdog not active\n"
1622 + "proceeding without locking down other cpus\n",
1623 + num_online_cpus());
1624 + entry_state = NO_NMI;
1630 + if (remote_debug) {
1631 + unsigned long *lp = (unsigned long *) &linux_regs;
1633 + printk("handle_exception(exceptionVector=%d, "
1634 + "signo=%d, err_code=%d, linux_regs=%p)\n",
1635 + exceptionVector, signo, err_code, linux_regs);
1637 + print_regs(®s);
1638 + printk("Stk: %8lx %8lx %8lx %8lx"
1639 + " %8lx %8lx %8lx %8lx\n",
1640 + lp[0], lp[1], lp[2], lp[3],
1641 + lp[4], lp[5], lp[6], lp[7]);
1642 + printk(" %8lx %8lx %8lx %8lx"
1643 + " %8lx %8lx %8lx %8lx\n",
1644 + lp[8], lp[9], lp[10], lp[11],
1645 + lp[12], lp[13], lp[14], lp[15]);
1646 + printk(" %8lx %8lx %8lx %8lx "
1647 + "%8lx %8lx %8lx %8lx\n",
1648 + lp[16], lp[17], lp[18], lp[19],
1649 + lp[20], lp[21], lp[22], lp[23]);
1650 + printk(" %8lx %8lx %8lx %8lx "
1651 + "%8lx %8lx %8lx %8lx\n",
1652 + lp[24], lp[25], lp[26], lp[27],
1653 + lp[28], lp[29], lp[30], lp[31]);
1657 + /* Disable hardware debugging while we are in kgdb */
1658 + /* Get the debug register status register */
1660 + __asm__("movl %0,%%db7"
1664 + asm volatile ("movl %%db6, %0\n"
1665 + :"=r" (hw_breakpoint_status)
1669 + switch (exceptionVector) {
1670 + case 0: /* divide error */
1671 + case 1: /* debug exception */
1673 + case 3: /* breakpoint */
1674 + case 4: /* overflow */
1675 + case 5: /* bounds check */
1676 + case 6: /* invalid opcode */
1677 + case 7: /* device not available */
1678 + case 8: /* double fault (errcode) */
1679 + case 10: /* invalid TSS (errcode) */
1680 + case 12: /* stack fault (errcode) */
1681 + case 16: /* floating point error */
1682 + case 17: /* alignment check (errcode) */
1683 + default: /* any undocumented */
1685 + case 11: /* segment not present (errcode) */
1686 + case 13: /* general protection (errcode) */
1687 + case 14: /* page fault (special errcode) */
1688 + case 19: /* cache flush denied */
1689 + if (mem_err_expected) {
1691 + * This fault occured because of the
1692 + * get_char or set_char routines. These
1693 + * two routines use either eax of edx to
1694 + * indirectly reference the location in
1695 + * memory that they are working with.
1696 + * For a page fault, when we return the
1697 + * instruction will be retried, so we
1698 + * have to make sure that these
1699 + * registers point to valid memory.
1701 + mem_err = 1; /* set mem error flag */
1702 + mem_err_expected = 0;
1703 + mem_err_cnt++; /* helps in debugging */
1704 + /* make valid address */
1705 + regs.eax = (long) &garbage_loc;
1706 + /* make valid address */
1707 + regs.edx = (long) &garbage_loc;
1709 + printk("Return after memory error: "
1710 + "mem_err_cnt=%d\n", mem_err_cnt);
1712 + print_regs(®s);
1718 + printk("kgdb : entered kgdb on cpu %d\n", smp_processor_id());
1720 + gdb_i386vector = exceptionVector;
1721 + gdb_i386errcode = err_code;
1722 + kgdb_info.called_from = __builtin_return_address(0);
1725 + * OK, we can now communicate, lets tell gdb about the sync.
1726 + * but only if we had a problem.
1728 + switch (entry_state) {
1730 + to_gdb("NMI not active, other cpus not stopped\n");
1733 + to_gdb("Some cpus not stopped, see 'kgdb_info' for details\n");
1739 + * Set up the gdb function call area.
1741 + trap_cpu = smp_processor_id();
1742 + OLD_esp = NEW_esp = (int) (&linux_regs->esp);
1744 + IF_SMP(once_again:)
1745 + /* reply to host that an exception has occurred */
1746 + remcomOutBuffer[0] = 'S';
1747 + remcomOutBuffer[1] = hexchars[signo >> 4];
1748 + remcomOutBuffer[2] = hexchars[signo % 16];
1749 + remcomOutBuffer[3] = 0;
1751 + putpacket(remcomOutBuffer);
1755 + remcomOutBuffer[0] = 0;
1756 + getpacket(remcomInBuffer);
1757 + switch (remcomInBuffer[0]) {
1759 + remcomOutBuffer[0] = 'S';
1760 + remcomOutBuffer[1] = hexchars[signo >> 4];
1761 + remcomOutBuffer[2] = hexchars[signo % 16];
1762 + remcomOutBuffer[3] = 0;
1765 + remote_debug = !(remote_debug); /* toggle debug flag */
1766 + printk("Remote debug %s\n",
1767 + remote_debug ? "on" : "off");
1769 + case 'g': /* return the value of the CPU registers */
1770 + get_gdb_regs(usethread, ®s, gdb_regs);
1771 + mem2hex((char *) gdb_regs,
1772 + remcomOutBuffer, NUMREGBYTES, 0);
1774 + case 'G': /* set the value of the CPU registers - return OK */
1775 + hex2mem(&remcomInBuffer[1],
1776 + (char *) gdb_regs, NUMREGBYTES, 0);
1777 + if (!usethread || usethread == current) {
1778 + gdb_regs_to_regs(gdb_regs, ®s);
1779 + strcpy(remcomOutBuffer, "OK");
1781 + strcpy(remcomOutBuffer, "E00");
1785 + case 'P':{ /* set the value of a single CPU register -
1788 + * For some reason, gdb wants to talk about psudo
1789 + * registers (greater than 15). These may have
1790 + * meaning for ptrace, but for us it is safe to
1791 + * ignor them. We do this by dumping them into
1792 + * _GS which we also ignor, but do have memory for.
1796 + ptr = &remcomInBuffer[1];
1797 + regs_to_gdb_regs(gdb_regs, ®s);
1798 + if ((!usethread || usethread == current) &&
1799 + hexToInt(&ptr, ®no) &&
1800 + *ptr++ == '=' && (regno >= 0)) {
1802 + (regno >= NUMREGS ? _GS : regno);
1803 + hex2mem(ptr, (char *) &gdb_regs[regno],
1805 + gdb_regs_to_regs(gdb_regs, ®s);
1806 + strcpy(remcomOutBuffer, "OK");
1809 + strcpy(remcomOutBuffer, "E01");
1813 + /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
1815 + /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */
1816 + ptr = &remcomInBuffer[1];
1817 + if (hexToInt(&ptr, &addr) &&
1818 + (*(ptr++) == ',') && (hexToInt(&ptr, &length))) {
1821 + * hex doubles the byte count
1823 + if (length > (BUFMAX / 2))
1824 + length = BUFMAX / 2;
1825 + mem2hex((char *) addr,
1826 + remcomOutBuffer, length, 1);
1828 + strcpy(remcomOutBuffer, "E03");
1829 + debug_error("memory fault\n", NULL);
1834 + strcpy(remcomOutBuffer, "E01");
1836 + ("malformed read memory command: %s\n",
1842 + Write LLLL bytes at address AA.AA return OK */
1844 + /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */
1845 + ptr = &remcomInBuffer[1];
1846 + if (hexToInt(&ptr, &addr) &&
1847 + (*(ptr++) == ',') &&
1848 + (hexToInt(&ptr, &length)) && (*(ptr++) == ':')) {
1849 + hex2mem(ptr, (char *) addr, length, 1);
1852 + strcpy(remcomOutBuffer, "E03");
1853 + debug_error("memory fault\n", NULL);
1855 + strcpy(remcomOutBuffer, "OK");
1861 + strcpy(remcomOutBuffer, "E02");
1863 + ("malformed write memory command: %s\n",
1868 + remcomInBuffer[0] = 's';
1870 + /* Csig;AA..AA where ;AA..AA is optional
1871 + * continue with signal
1872 + * Since signals are meaning less to us, delete that
1873 + * part and then fall into the 'c' code.
1875 + ptr = &remcomInBuffer[1];
1877 + while (*ptr && *ptr != ';') {
1884 + *(ptr - length++) = *ptr;
1887 + remcomInBuffer[1] = 0;
1890 + /* cAA..AA Continue at address AA..AA(optional) */
1891 + /* sAA..AA Step one instruction from AA..AA(optional) */
1892 + /* D detach, reply OK and then continue */
1897 + /* try to read optional parameter,
1898 + pc unchanged if no parm */
1899 + ptr = &remcomInBuffer[1];
1900 + if (hexToInt(&ptr, &addr)) {
1902 + printk("Changing EIP to 0x%x\n", addr);
1909 + /* clear the trace bit */
1910 + regs.eflags &= 0xfffffeff;
1912 + /* set the trace bit if we're stepping */
1913 + if (remcomInBuffer[0] == 's')
1914 + regs.eflags |= 0x100;
1916 + /* detach is a friendly version of continue. Note that
1917 + debugging is still enabled (e.g hit control C)
1919 + if (remcomInBuffer[0] == 'D') {
1920 + strcpy(remcomOutBuffer, "OK");
1921 + putpacket(remcomOutBuffer);
1924 + if (remote_debug) {
1925 + printk("Resuming execution\n");
1926 + print_regs(®s);
1928 + asm volatile ("movl %%db6, %0\n":"=r" (dr6)
1930 + if (!(dr6 & 0x4000)) {
1931 + for (breakno = 0; breakno < 4; ++breakno) {
1932 + if (dr6 & (1 << breakno) &&
1933 + (breakinfo[breakno].type == 0)) {
1934 + /* Set restore flag */
1935 + regs.eflags |= 0x10000;
1940 + correct_hw_break();
1941 + asm volatile ("movl %0, %%db6\n"::"r" (0));
1944 + /* kill the program */
1945 + case 'k': /* do nothing */
1951 + switch (remcomInBuffer[1]) {
1955 + thread_list_start = (usethread ? : current);
1957 + if (!cmp_str(&remcomInBuffer[2],
1958 + "ThreadInfo", 10))
1961 + remcomOutBuffer[nothreads++] = 'm';
1962 + for (; threadid < PID_MAX + MAX_NO_CPUS;
1964 + thread = getthread(threadid);
1966 + nothreads += int_to_hex_v(
1970 + if (thread_min > threadid)
1971 + thread_min = threadid;
1975 + if (nothreads > BUFMAX - 10)
1979 + if (remcomOutBuffer[nothreads - 1] == 'm') {
1980 + remcomOutBuffer[nothreads - 1] = 'l';
1984 + remcomOutBuffer[nothreads] = 0;
1987 +#ifdef old_thread_list /* Old thread info request */
1989 + /* List threads */
1991 + thread_list_start = (usethread ? : current);
1992 + unpack_byte(remcomInBuffer + 3, &maxthreads);
1993 + unpack_threadid(remcomInBuffer + 5, &thref);
1995 + int buf_thread_limit =
1996 + (BUFMAX - 22) / BUF_THREAD_ID_SIZE;
1997 + if (maxthreads > buf_thread_limit) {
1998 + maxthreads = buf_thread_limit;
2001 + remcomOutBuffer[0] = 'q';
2002 + remcomOutBuffer[1] = 'M';
2003 + remcomOutBuffer[4] = '0';
2004 + pack_threadid(remcomOutBuffer + 5, &thref);
2006 + threadid = threadref_to_int(&thref);
2007 + for (nothreads = 0;
2008 + nothreads < maxthreads &&
2009 + threadid < PID_MAX + MAX_NO_CPUS;
2011 + thread = getthread(threadid);
2013 + int_to_threadref(&thref,
2015 + pack_threadid(remcomOutBuffer +
2020 + if (thread_min > threadid)
2021 + thread_min = threadid;
2025 + if (threadid == PID_MAX + MAX_NO_CPUS) {
2026 + remcomOutBuffer[4] = '1';
2028 + pack_hex_byte(remcomOutBuffer + 2, nothreads);
2029 + remcomOutBuffer[21 + nothreads * 16] = '\0';
2033 + /* Current thread id */
2034 + remcomOutBuffer[0] = 'Q';
2035 + remcomOutBuffer[1] = 'C';
2036 + threadid = current->pid;
2041 + for (threadid = PID_MAX;
2042 + threadid < PID_MAX + MAX_NO_CPUS;
2045 + idle_task(threadid -
2050 + int_to_threadref(&thref, threadid);
2051 + pack_threadid(remcomOutBuffer + 2, &thref);
2052 + remcomOutBuffer[18] = '\0';
2056 + /* Print exception info */
2057 + printexceptioninfo(exceptionVector,
2058 + err_code, remcomOutBuffer);
2062 + /* Thread extra info */
2063 + if (!cmp_str(&remcomInBuffer[2],
2064 + "hreadExtraInfo,", 15)) {
2067 + ptr = &remcomInBuffer[17];
2068 + hexToInt(&ptr, &threadid);
2069 + thread = getthread(threadid);
2070 + nptr = &thread->comm[0];
2072 + ptr = &remcomOutBuffer[0];
2075 + ptr = pack_hex_byte(ptr, *nptr++);
2076 + } while (*nptr && length < 16);
2078 + * would like that 16 to be the size of
2079 + * task_struct.comm but don't know the
2087 + /* task related */
2089 + switch (remcomInBuffer[1]) {
2091 + ptr = &remcomInBuffer[2];
2092 + hexToInt(&ptr, &threadid);
2093 + thread = getthread(threadid);
2095 + remcomOutBuffer[0] = 'E';
2096 + remcomOutBuffer[1] = '\0';
2100 + * Just in case I forget what this is all about,
2101 + * the "thread info" command to gdb causes it
2102 + * to ask for a thread list. It then switches
2103 + * to each thread and asks for the registers.
2104 + * For this (and only this) usage, we want to
2105 + * fudge the registers of tasks not on the run
2106 + * list (i.e. waiting) to show the routine that
2107 + * called schedule. Also, gdb, is a minimalist
2108 + * in that if the current thread is the last
2109 + * it will not re-read the info when done.
2110 + * This means that in this case we must show
2111 + * the real registers. So here is how we do it:
2112 + * Each entry we keep track of the min
2113 + * thread in the list (the last that gdb will)
2114 + * get info for. We also keep track of the
2115 + * starting thread.
2116 + * "thread_list" is cleared when switching back
2117 + * to the min thread if it is was current, or
2118 + * if it was not current, thread_list is set
2119 + * to 1. When the switch to current comes,
2120 + * if thread_list is 1, clear it, else do
2123 + usethread = thread;
2124 + if ((thread_list == 1) &&
2125 + (thread == thread_list_start)) {
2128 + if (thread_list && (threadid == thread_min)) {
2129 + if (thread == thread_list_start) {
2135 + /* follow through */
2137 + remcomOutBuffer[0] = 'O';
2138 + remcomOutBuffer[1] = 'K';
2139 + remcomOutBuffer[2] = '\0';
2144 + /* Query thread status */
2146 + ptr = &remcomInBuffer[1];
2147 + hexToInt(&ptr, &threadid);
2148 + thread = getthread(threadid);
2150 + remcomOutBuffer[0] = 'O';
2151 + remcomOutBuffer[1] = 'K';
2152 + remcomOutBuffer[2] = '\0';
2153 + if (thread_min > threadid)
2154 + thread_min = threadid;
2156 + remcomOutBuffer[0] = 'E';
2157 + remcomOutBuffer[1] = '\0';
2161 + case 'Y': /* set up a hardware breakpoint */
2162 + ptr = &remcomInBuffer[1];
2163 + hexToInt(&ptr, &breakno);
2165 + hexToInt(&ptr, &breaktype);
2167 + hexToInt(&ptr, &length);
2169 + hexToInt(&ptr, &addr);
2170 + if (set_hw_break(breakno & 0x3,
2172 + length & 0x3, addr) == 0) {
2173 + strcpy(remcomOutBuffer, "OK");
2175 + strcpy(remcomOutBuffer, "ERROR");
2179 + /* Remove hardware breakpoint */
2181 + ptr = &remcomInBuffer[1];
2182 + hexToInt(&ptr, &breakno);
2183 + if (remove_hw_break(breakno & 0x3) == 0) {
2184 + strcpy(remcomOutBuffer, "OK");
2186 + strcpy(remcomOutBuffer, "ERROR");
2190 + case 'r': /* reboot */
2191 + strcpy(remcomOutBuffer, "OK");
2192 + putpacket(remcomOutBuffer);
2193 + /*to_gdb("Rebooting\n"); */
2194 + /* triplefault no return from here */
2196 + static long no_idt[2];
2197 + __asm__ __volatile__("lidt %0"::"m"(no_idt[0]));
2203 + /* reply to the request */
2204 + putpacket(remcomOutBuffer);
2205 + } /* while(1==1) */
2207 + * reached by goto only.
2211 + * Here is where we set up to trap a gdb function call. NEW_esp
2212 + * will be changed if we are trying to do this. We handle both
2213 + * adding and subtracting, thus allowing gdb to put grung on
2214 + * the stack which it removes later.
2216 + if (NEW_esp != OLD_esp) {
2217 + int *ptr = END_OF_LOOKASIDE;
2218 + if (NEW_esp < OLD_esp)
2219 + ptr -= (OLD_esp - NEW_esp) / sizeof (int);
2220 + *--ptr = linux_regs->eflags;
2221 + *--ptr = linux_regs->xcs;
2222 + *--ptr = linux_regs->eip;
2223 + *--ptr = linux_regs->ecx;
2224 + *--ptr = linux_regs->ebx;
2225 + *--ptr = linux_regs->eax;
2226 + linux_regs->ecx = NEW_esp - (sizeof (int) * 6);
2227 + linux_regs->ebx = (unsigned int) END_OF_LOOKASIDE;
2228 + if (NEW_esp < OLD_esp) {
2229 + linux_regs->eip = (unsigned int) fn_call_stub;
2231 + linux_regs->eip = (unsigned int) fn_rtn_stub;
2232 + linux_regs->eax = NEW_esp;
2234 + linux_regs->eflags &= ~(IF_BIT | TF_BIT);
2238 + * Release gdb wait locks
2239 + * Sanity check time. Must have at least one cpu to run. Also single
2240 + * step must not be done if the current cpu is on hold.
2242 + if (spinlock_count == 1) {
2243 + int ss_hold = (regs.eflags & 0x100) && kgdb_info.hold_on_sstep;
2244 + int cpu_avail = 0;
2247 + for (i = 0; i < MAX_NO_CPUS; i++) {
2248 + if (!cpu_online(i))
2250 + if (!hold_cpu(i)) {
2255 + * Early in the bring up there will be NO cpus on line...
2257 + if (!cpu_avail && !cpus_empty(cpu_online_map)) {
2258 + to_gdb("No cpus unblocked, see 'kgdb_info.hold_cpu'\n");
2261 + if (hold_cpu(smp_processor_id()) && (regs.eflags & 0x100)) {
2263 + ("Current cpu must be unblocked to single step\n");
2268 + for (i = 0; i < MAX_NO_CPUS; i++) {
2269 + if (!hold_cpu(i)) {
2270 + spin_unlock(&waitlocks[i]);
2274 + spin_unlock(&waitlocks[smp_processor_id()]);
2276 + /* Release kgdb spinlock */
2277 + KGDB_SPIN_UNLOCK(&kgdb_spinlock);
2279 + * If this cpu is on hold, this is where we
2280 + * do it. Note, the NMI will pull us out of here,
2281 + * but will return as the above lock is not held.
2282 + * We will stay here till another cpu releases the lock for us.
2284 + spin_unlock_wait(waitlocks + smp_processor_id());
2285 + kgdb_local_irq_restore(flags);
2292 + /* Release kgdb spinlock */
2293 + KGDB_SPIN_UNLOCK(&kgdb_spinlock);
2294 + kgdb_local_irq_restore(flags);
2298 +/* this function is used to set up exception handlers for tracing and
2300 + * This function is not needed as the above line does all that is needed.
2301 + * We leave it for backward compatitability...
2304 +set_debug_traps(void)
2307 + * linux_debug_hook is defined in traps.c. We store a pointer
2308 + * to our own exception handler into it.
2310 + * But really folks, every hear of labeled common, an old Fortran
2311 + * concept. Lots of folks can reference it and it is define if
2312 + * anyone does. Only one can initialize it at link time. We do
2313 + * this with the hook. See the statement above. No need for any
2314 + * executable code and it is ready as soon as the kernel is
2315 + * loaded. Very desirable in kernel debugging.
2317 + linux_debug_hook = handle_exception ;
2320 + /* In case GDB is started before us, ack any packets (presumably
2321 + "$?#xx") sitting there.
2322 + putDebugChar ('+');
2328 +/* This function will generate a breakpoint exception. It is used at the
2329 + beginning of a program to sync up with a debugger and can be used
2330 + otherwise as a quick means to stop program execution and "break" into
2332 +/* But really, just use the BREAKPOINT macro. We will handle the int stuff
2337 + * possibly we should not go thru the traps.c code at all? Someday.
2340 +do_kgdb_int3(struct pt_regs *regs, long error_code)
2342 + kgdb_handle_exception(3, 5, error_code, regs);
2347 +#ifdef CONFIG_TRAP_BAD_SYSCALL_EXITS
2349 +bad_sys_call_exit(int stuff)
2351 + struct pt_regs *regs = (struct pt_regs *) &stuff;
2352 + printk("Sys call %d return with %x preempt_count\n",
2353 + (int) regs->orig_eax, preempt_count());
2356 +#ifdef CONFIG_STACK_OVERFLOW_TEST
2357 +#include <asm/kgdb.h>
2359 +stack_overflow(void)
2364 + printk("Kernel stack overflow, looping forever\n");
2371 +#if defined(CONFIG_SMP) || defined(CONFIG_KGDB_CONSOLE)
2372 +char gdbconbuf[BUFMAX];
2375 +kgdb_gdb_message(const char *s, unsigned count)
2381 + * This takes care of NMI while spining out chars to gdb
2383 + IF_SMP(in_kgdb_console = 1);
2384 + gdbconbuf[0] = 'O';
2385 + bufptr = gdbconbuf + 1;
2386 + while (count > 0) {
2387 + if ((count << 1) > (BUFMAX - 2)) {
2388 + wcount = (BUFMAX - 2) >> 1;
2393 + for (i = 0; i < wcount; i++) {
2394 + bufptr = pack_hex_byte(bufptr, s[i]);
2399 + putpacket(gdbconbuf);
2402 + IF_SMP(in_kgdb_console = 0);
2407 +to_gdb(const char *s)
2410 + while (s[count] && (count++ < BUFMAX)) ;
2411 + kgdb_gdb_message(s, count);
2414 +#ifdef CONFIG_KGDB_CONSOLE
2415 +#include <linux/console.h>
2416 +#include <linux/init.h>
2417 +#include <linux/fs.h>
2418 +#include <asm/uaccess.h>
2419 +#include <asm/semaphore.h>
2422 +kgdb_console_write(struct console *co, const char *s, unsigned count)
2425 + if (gdb_i386vector == -1) {
2427 + * We have not yet talked to gdb. What to do...
2428 + * lets break, on continue we can do the write.
2429 + * But first tell him whats up. Uh, well no can do,
2430 + * as this IS the console. Oh well...
2431 + * We do need to wait or the messages will be lost.
2432 + * Other option would be to tell the above code to
2433 + * ignore this breakpoint and do an auto return,
2434 + * but that might confuse gdb. Also this happens
2435 + * early enough in boot up that we don't have the traps
2436 + * set up yet, so...
2440 + kgdb_gdb_message(s, count);
2444 + * ------------------------------------------------------------
2445 + * Serial KGDB driver
2446 + * ------------------------------------------------------------
2449 +static struct console kgdbcons = {
2451 + write:kgdb_console_write,
2452 +#ifdef CONFIG_KGDB_USER_CONSOLE
2453 + device:kgdb_console_device,
2455 + flags:CON_PRINTBUFFER | CON_ENABLED,
2460 + * The trick here is that this file gets linked before printk.o
2461 + * That means we get to peer at the console info in the command
2462 + * line before it does. If we are up, we register, otherwise,
2463 + * do nothing. By returning 0, we allow printk to look also.
2465 +static int kgdb_console_enabled;
2468 +kgdb_console_init(char *str)
2470 + if ((strncmp(str, "kgdb", 4) == 0) || (strncmp(str, "gdb", 3) == 0)) {
2471 + register_console(&kgdbcons);
2472 + kgdb_console_enabled = 1;
2474 + return 0; /* let others look at the string */
2477 +__setup("console=", kgdb_console_init);
2479 +#ifdef CONFIG_KGDB_USER_CONSOLE
2480 +static kdev_t kgdb_console_device(struct console *c);
2481 +/* This stuff sort of works, but it knocks out telnet devices
2482 + * we are leaving it here in case we (or you) find time to figure it out
2487 + * We need a real char device as well for when the console is opened for user
2488 + * space activities.
2492 +kgdb_consdev_open(struct inode *inode, struct file *file)
2498 +kgdb_consdev_write(struct file *file, const char *buf,
2499 + size_t count, loff_t * ppos)
2501 + int size, ret = 0;
2502 + static char kbuf[128];
2503 + static DECLARE_MUTEX(sem);
2505 + /* We are not reentrant... */
2506 + if (down_interruptible(&sem))
2507 + return -ERESTARTSYS;
2509 + while (count > 0) {
2510 + /* need to copy the data from user space */
2512 + if (size > sizeof (kbuf))
2513 + size = sizeof (kbuf);
2514 + if (copy_from_user(kbuf, buf, size)) {
2518 + kgdb_console_write(&kgdbcons, kbuf, size);
2529 +struct file_operations kgdb_consdev_fops = {
2530 + open:kgdb_consdev_open,
2531 + write:kgdb_consdev_write
2534 +kgdb_console_device(struct console *c)
2536 + return MKDEV(TTYAUX_MAJOR, 1);
2540 + * This routine gets called from the serial stub in the i386/lib
2541 + * This is so it is done late in bring up (just before the console open).
2544 +kgdb_console_finit(void)
2546 + if (kgdb_console_enabled) {
2547 + char *cptr = cdevname(MKDEV(TTYAUX_MAJOR, 1));
2549 + while (*cptr && *cptr != '(')
2552 + unregister_chrdev(TTYAUX_MAJOR, cp);
2553 + register_chrdev(TTYAUX_MAJOR, "kgdb", &kgdb_consdev_fops);
2558 +#ifdef CONFIG_KGDB_TS
2559 +#include <asm/msr.h> /* time stamp code */
2560 +#include <asm/hardirq.h> /* in_interrupt */
2561 +#ifdef CONFIG_KGDB_TS_64
2562 +#define DATA_POINTS 64
2564 +#ifdef CONFIG_KGDB_TS_128
2565 +#define DATA_POINTS 128
2567 +#ifdef CONFIG_KGDB_TS_256
2568 +#define DATA_POINTS 256
2570 +#ifdef CONFIG_KGDB_TS_512
2571 +#define DATA_POINTS 512
2573 +#ifdef CONFIG_KGDB_TS_1024
2574 +#define DATA_POINTS 1024
2576 +#ifndef DATA_POINTS
2577 +#define DATA_POINTS 128 /* must be a power of two */
2579 +#define INDEX_MASK (DATA_POINTS - 1)
2580 +#if (INDEX_MASK & DATA_POINTS)
2581 +#error "CONFIG_KGDB_TS_COUNT must be a power of 2"
2583 +struct kgdb_and_then_struct {
2587 + struct task_struct *task;
2588 + long long at_time;
2596 +struct kgdb_and_then_struct2 {
2600 + struct task_struct *task;
2601 + long long at_time;
2606 + struct task_struct *t1;
2607 + struct task_struct *t2;
2609 +struct kgdb_and_then_struct kgdb_data[DATA_POINTS];
2611 +struct kgdb_and_then_struct *kgdb_and_then = &kgdb_data[0];
2612 +int kgdb_and_then_count;
2615 +kgdb_tstamp(int line, char *source, int data0, int data1)
2617 + static spinlock_t ts_spin = SPIN_LOCK_UNLOCKED;
2619 + kgdb_local_irq_save(flags);
2620 + spin_lock(&ts_spin);
2621 + rdtscll(kgdb_and_then->at_time);
2623 + kgdb_and_then->on_cpu = smp_processor_id();
2625 + kgdb_and_then->task = current;
2626 + kgdb_and_then->from_ln = line;
2627 + kgdb_and_then->in_src = source;
2628 + kgdb_and_then->from = __builtin_return_address(0);
2629 + kgdb_and_then->with_shpf = (int *) (((flags & IF_BIT) >> 9) |
2630 + (preempt_count() << 8));
2631 + kgdb_and_then->data0 = data0;
2632 + kgdb_and_then->data1 = data1;
2633 + kgdb_and_then = &kgdb_data[++kgdb_and_then_count & INDEX_MASK];
2634 + spin_unlock(&ts_spin);
2635 + kgdb_local_irq_restore(flags);
2636 +#ifdef CONFIG_PREEMPT
2642 +typedef int gdb_debug_hook(int exceptionVector,
2643 + int signo, int err_code, struct pt_regs *linux_regs);
2644 +gdb_debug_hook *linux_debug_hook = &kgdb_handle_exception; /* histerical reasons... */
2645 diff -puN arch/i386/kernel/Makefile~kgdb-ga arch/i386/kernel/Makefile
2646 --- 25/arch/i386/kernel/Makefile~kgdb-ga 2004-10-21 14:54:15.259603680 -0700
2647 +++ 25-akpm/arch/i386/kernel/Makefile 2004-10-21 14:54:15.308596232 -0700
2648 @@ -14,6 +14,7 @@ obj-y += timers/
2649 obj-$(CONFIG_ACPI_BOOT) += acpi/
2650 obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o
2651 obj-$(CONFIG_MCA) += mca.o
2652 +obj-$(CONFIG_KGDB) += kgdb_stub.o
2653 obj-$(CONFIG_X86_MSR) += msr.o
2654 obj-$(CONFIG_X86_CPUID) += cpuid.o
2655 obj-$(CONFIG_MICROCODE) += microcode.o
2656 diff -puN arch/i386/kernel/nmi.c~kgdb-ga arch/i386/kernel/nmi.c
2657 --- 25/arch/i386/kernel/nmi.c~kgdb-ga 2004-10-21 14:54:15.261603376 -0700
2658 +++ 25-akpm/arch/i386/kernel/nmi.c 2004-10-21 14:54:15.308596232 -0700
2661 #include "mach_traps.h"
2664 +#include <asm/kgdb.h>
2666 +unsigned int nmi_watchdog = NMI_IO_APIC;
2668 +unsigned int nmi_watchdog = NMI_LOCAL_APIC;
2671 unsigned int nmi_watchdog = NMI_NONE;
2674 extern int unknown_nmi_panic;
2675 static unsigned int nmi_hz = HZ;
2676 static unsigned int nmi_perfctr_msr; /* the MSR to reset in NMI handler */
2677 @@ -466,6 +476,9 @@ void touch_nmi_watchdog (void)
2678 for (i = 0; i < NR_CPUS; i++)
2679 alert_counter[i] = 0;
2682 +int tune_watchdog = 5*HZ;
2685 extern void die_nmi(struct pt_regs *, const char *msg);
2687 @@ -481,12 +494,24 @@ void nmi_watchdog_tick (struct pt_regs *
2689 sum = irq_stat[cpu].apic_timer_irqs;
2692 + if (!in_kgdb(regs) && last_irq_sums[cpu] == sum) {
2695 if (last_irq_sums[cpu] == sum) {
2698 * Ayiee, looks like this CPU is stuck ...
2699 * wait a few IRQs (5 seconds) before doing the oops ...
2701 alert_counter[cpu]++;
2703 + if (alert_counter[cpu] == tune_watchdog) {
2704 + kgdb_handle_exception(2, SIGPWR, 0, regs);
2705 + last_irq_sums[cpu] = sum;
2706 + alert_counter[cpu] = 0;
2709 if (alert_counter[cpu] == 30*nmi_hz)
2710 die_nmi(regs, "NMI Watchdog detected LOCKUP");
2712 diff -puN arch/i386/kernel/smp.c~kgdb-ga arch/i386/kernel/smp.c
2713 --- 25/arch/i386/kernel/smp.c~kgdb-ga 2004-10-21 14:54:15.262603224 -0700
2714 +++ 25-akpm/arch/i386/kernel/smp.c 2004-10-21 14:54:15.309596080 -0700
2715 @@ -466,7 +466,17 @@ void flush_tlb_all(void)
2717 on_each_cpu(do_flush_tlb_all, NULL, 1, 1);
2722 + * By using the NMI code instead of a vector we just sneak thru the
2723 + * word generator coming out with just what we want. AND it does
2724 + * not matter if clustered_apic_mode is set or not.
2726 +void smp_send_nmi_allbutself(void)
2728 + send_IPI_allbutself(APIC_DM_NMI);
2732 * this function sends a 'reschedule' IPI to another CPU.
2733 * it goes straight through and wastes no time serializing
2734 diff -puN arch/i386/kernel/traps.c~kgdb-ga arch/i386/kernel/traps.c
2735 --- 25/arch/i386/kernel/traps.c~kgdb-ga 2004-10-21 14:54:15.264602920 -0700
2736 +++ 25-akpm/arch/i386/kernel/traps.c 2004-10-21 14:54:15.311595776 -0700
2737 @@ -105,6 +105,39 @@ int register_die_notifier(struct notifie
2742 +extern void sysenter_past_esp(void);
2743 +#include <asm/kgdb.h>
2744 +#include <linux/init.h>
2745 +void set_intr_gate(unsigned int n, void *addr);
2746 +static void set_intr_usr_gate(unsigned int n, void *addr);
2748 + * Should be able to call this breakpoint() very early in
2749 + * bring up. Just hard code the call where needed.
2750 + * The breakpoint() code is here because set_?_gate() functions
2751 + * are local (static) to trap.c. They need be done only once,
2752 + * but it does not hurt to do them over.
2754 +void breakpoint(void)
2756 + set_intr_usr_gate(3,&int3); /* disable ints on trap */
2757 + set_intr_gate(1,&debug);
2758 + set_intr_gate(14,&page_fault);
2762 +#define CHK_REMOTE_DEBUG(trapnr,signr,error_code,regs,after) \
2764 + if (!user_mode(regs) ) \
2766 + kgdb_handle_exception(trapnr, signr, error_code, regs); \
2768 + } else if ((trapnr == 3) && (regs->eflags &0x200)) local_irq_enable(); \
2771 +#define CHK_REMOTE_DEBUG(trapnr,signr,error_code,regs,after)
2774 static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
2776 return p > (void *)tinfo &&
2777 @@ -332,6 +365,15 @@ void die(const char * str, struct pt_reg
2782 + /* This is about the only place we want to go to kgdb even if in
2783 + * user mode. But we must go in via a trap so within kgdb we will
2784 + * always be in kernel mode.
2786 + if (user_mode(regs))
2789 + CHK_REMOTE_DEBUG(0,SIGTRAP,err,regs,)
2790 notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
2791 show_registers(regs);
2793 @@ -406,6 +448,7 @@ static inline void do_trap(int trapnr, i
2794 #define DO_ERROR(trapnr, signr, str, name) \
2795 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
2797 + CHK_REMOTE_DEBUG(trapnr,signr,error_code,regs,) \
2798 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
2801 @@ -429,6 +472,7 @@ asmlinkage void do_##name(struct pt_regs
2802 #define DO_VM86_ERROR(trapnr, signr, str, name) \
2803 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
2805 + CHK_REMOTE_DEBUG(trapnr, signr, error_code,regs, return) \
2806 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
2809 @@ -512,7 +556,8 @@ gp_in_vm86:
2812 if (!fixup_exception(regs)) {
2814 + CHK_REMOTE_DEBUG(13,SIGSEGV,error_code,regs,)
2815 if (notify_die(DIE_GPF, "general protection fault", regs,
2816 error_code, 13, SIGSEGV) == NOTIFY_STOP)
2818 @@ -721,8 +766,18 @@ asmlinkage void do_debug(struct pt_regs
2819 * allowing programs to debug themselves without the ptrace()
2824 + * I think this is the only "real" case of a TF in the kernel
2825 + * that really belongs to user space. Others are
2826 + * "Ours all ours!"
2828 + if (((regs->xcs & 3) == 0) && ((void *)regs->eip == sysenter_past_esp))
2829 + goto clear_TF_reenable;
2831 if ((regs->xcs & 3) == 0)
2832 goto clear_TF_reenable;
2834 if ((tsk->ptrace & (PT_DTRACE|PT_PTRACED)) == PT_DTRACE)
2837 @@ -734,6 +789,17 @@ asmlinkage void do_debug(struct pt_regs
2839 info.si_code = TRAP_BRKPT;
2843 + * If this is a kernel mode trap, we need to reset db7 to allow us
2844 + * to continue sanely ALSO skip the signal delivery
2846 + if ((regs->xcs & 3) == 0)
2849 + /* if not kernel, allow ints but only if they were on */
2850 + if ( regs->eflags & 0x200) local_irq_enable();
2852 /* If this is a kernel mode trap, save the user PC on entry to
2853 * the kernel, that's what the debugger can make sense of.
2855 @@ -748,6 +814,7 @@ clear_dr7:
2856 __asm__("movl %0,%%db7"
2859 + CHK_REMOTE_DEBUG(1,SIGTRAP,error_code,regs,)
2863 @@ -1004,6 +1071,12 @@ static void __init set_task_gate(unsigne
2865 _set_gate(idt_table+n,5,0,0,(gdt_entry<<3));
2868 +void set_intr_usr_gate(unsigned int n, void *addr)
2870 + _set_gate(idt_table+n,14,3,addr,__KERNEL_CS);
2875 void __init trap_init(void)
2876 @@ -1021,7 +1094,11 @@ void __init trap_init(void)
2877 set_trap_gate(0,÷_error);
2878 set_intr_gate(1,&debug);
2879 set_intr_gate(2,&nmi);
2880 +#ifndef CONFIG_KGDB
2881 set_system_intr_gate(3, &int3); /* int3-5 can be called from all */
2883 + set_intr_usr_gate(3,&int3); /* int3-5 can be called from all */
2885 set_system_gate(4,&overflow);
2886 set_system_gate(5,&bounds);
2887 set_trap_gate(6,&invalid_op);
2888 diff -puN /dev/null arch/i386/lib/kgdb_serial.c
2889 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
2890 +++ 25-akpm/arch/i386/lib/kgdb_serial.c 2004-10-21 14:54:15.313595472 -0700
2893 + * Serial interface GDB stub
2895 + * Written (hacked together) by David Grothe (dave@gcom.com)
2896 + * Modified to allow invokation early in boot see also
2897 + * kgdb.h for instructions by George Anzinger(george@mvista.com)
2901 +#include <linux/module.h>
2902 +#include <linux/errno.h>
2903 +#include <linux/signal.h>
2904 +#include <linux/sched.h>
2905 +#include <linux/timer.h>
2906 +#include <linux/interrupt.h>
2907 +#include <linux/tty.h>
2908 +#include <linux/tty_flip.h>
2909 +#include <linux/serial.h>
2910 +#include <linux/serial_reg.h>
2911 +#include <linux/config.h>
2912 +#include <linux/major.h>
2913 +#include <linux/string.h>
2914 +#include <linux/fcntl.h>
2915 +#include <linux/ptrace.h>
2916 +#include <linux/ioport.h>
2917 +#include <linux/mm.h>
2918 +#include <linux/init.h>
2919 +#include <linux/highmem.h>
2920 +#include <asm/system.h>
2921 +#include <asm/io.h>
2922 +#include <asm/segment.h>
2923 +#include <asm/bitops.h>
2924 +#include <asm/system.h>
2925 +#include <asm/kgdb_local.h>
2926 +#ifdef CONFIG_KGDB_USER_CONSOLE
2927 +extern void kgdb_console_finit(void);
2930 +#define TEST_EXISTANCE
2932 +#define dbprintk(s) printk s
2934 +#define dbprintk(s)
2936 +#define TEST_INTERRUPT_off
2937 +#ifdef TEST_INTERRUPT
2938 +#define intprintk(s) printk s
2940 +#define intprintk(s)
2943 +#define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
2945 +#define GDB_BUF_SIZE 512 /* power of 2, please */
2947 +static char gdb_buf[GDB_BUF_SIZE];
2948 +static int gdb_buf_in_inx;
2949 +static atomic_t gdb_buf_in_cnt;
2950 +static int gdb_buf_out_inx;
2952 +struct async_struct *gdb_async_info;
2953 +static int gdb_async_irq;
2955 +#define outb_px(a,b) outb_p(b,a)
2957 +static void program_uart(struct async_struct *info);
2958 +static void write_char(struct async_struct *info, int chr);
2960 + * Get a byte from the hardware data buffer and return it
2963 +read_data_bfr(struct async_struct *info)
2965 + char it = inb_p(info->port + UART_LSR);
2967 + if (it & UART_LSR_DR)
2968 + return (inb_p(info->port + UART_RX));
2970 + * If we have a framing error assume somebody messed with
2971 + * our uart. Reprogram it and send '-' both ways...
2974 + program_uart(info);
2975 + write_char(info, '-');
2980 +} /* read_data_bfr */
2983 + * Get a char if available, return -1 if nothing available.
2984 + * Empty the receive buffer first, then look at the interface hardware.
2986 + * Locking here is a bit of a problem. We MUST not lock out communication
2987 + * if we are trying to talk to gdb about a kgdb entry. ON the other hand
2988 + * we can loose chars in the console pass thru if we don't lock. It is also
2989 + * possible that we could hold the lock or be waiting for it when kgdb
2990 + * NEEDS to talk. Since kgdb locks down the world, it does not need locks.
2991 + * We do, of course have possible issues with interrupting a uart operation,
2992 + * but we will just depend on the uart status to help keep that straight.
2995 +static spinlock_t uart_interrupt_lock = SPIN_LOCK_UNLOCKED;
2997 +extern spinlock_t kgdb_spinlock;
3001 +read_char(struct async_struct *info)
3004 + unsigned long flags;
3005 + local_irq_save(flags);
3007 + if (!spin_is_locked(&kgdb_spinlock)) {
3008 + spin_lock(&uart_interrupt_lock);
3011 + if (atomic_read(&gdb_buf_in_cnt) != 0) { /* intr routine has q'd chars */
3012 + chr = gdb_buf[gdb_buf_out_inx++];
3013 + gdb_buf_out_inx &= (GDB_BUF_SIZE - 1);
3014 + atomic_dec(&gdb_buf_in_cnt);
3016 + chr = read_data_bfr(info);
3019 + if (!spin_is_locked(&kgdb_spinlock)) {
3020 + spin_unlock(&uart_interrupt_lock);
3023 + local_irq_restore(flags);
3028 + * Wait until the interface can accept a char, then write it.
3031 +write_char(struct async_struct *info, int chr)
3033 + while (!(inb_p(info->port + UART_LSR) & UART_LSR_THRE)) ;
3035 + outb_p(chr, info->port + UART_TX);
3040 + * Mostly we don't need a spinlock, but since the console goes
3041 + * thru here with interrutps on, well, we need to catch those
3045 + * This is the receiver interrupt routine for the GDB stub.
3046 + * It will receive a limited number of characters of input
3047 + * from the gdb host machine and save them up in a buffer.
3049 + * When the gdb stub routine getDebugChar() is called it
3050 + * draws characters out of the buffer until it is empty and
3051 + * then reads directly from the serial port.
3053 + * We do not attempt to write chars from the interrupt routine
3054 + * since the stubs do all of that via putDebugChar() which
3055 + * writes one byte after waiting for the interface to become
3058 + * The debug stubs like to run with interrupts disabled since,
3059 + * after all, they run as a consequence of a breakpoint in
3062 + * Perhaps someone who knows more about the tty driver than I
3063 + * care to learn can make this work for any low level serial
3067 +gdb_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3069 + struct async_struct *info;
3070 + unsigned long flags;
3072 + info = gdb_async_info;
3073 + if (!info || !info->tty || irq != gdb_async_irq)
3076 + local_irq_save(flags);
3077 + spin_lock(&uart_interrupt_lock);
3079 + int chr = read_data_bfr(info);
3080 + intprintk(("Debug char on int: %x hex\n", chr));
3084 + if (chr == 3) { /* Ctrl-C means remote interrupt */
3089 + if (atomic_read(&gdb_buf_in_cnt) >= GDB_BUF_SIZE) {
3090 + /* buffer overflow tosses early char */
3093 + gdb_buf[gdb_buf_in_inx++] = chr;
3094 + gdb_buf_in_inx &= (GDB_BUF_SIZE - 1);
3095 + } while (inb_p(info->port + UART_IIR) & UART_IIR_RDI);
3096 + spin_unlock(&uart_interrupt_lock);
3097 + local_irq_restore(flags);
3098 + return IRQ_HANDLED;
3099 +} /* gdb_interrupt */
3102 + * Just a NULL routine for testing.
3109 +/* These structure are filled in with values defined in asm/kgdb_local.h
3111 +static struct serial_state state = SB_STATE;
3112 +static struct async_struct local_info = SB_INFO;
3113 +static int ok_to_enable_ints = 0;
3114 +static void kgdb_enable_ints_now(void);
3116 +extern char *kgdb_version;
3118 + * Hook an IRQ for KGDB.
3120 + * This routine is called from putDebugChar, below.
3122 +static int ints_disabled = 1;
3124 +gdb_hook_interrupt(struct async_struct *info, int verb)
3126 + struct serial_state *state = info->state;
3127 + unsigned long flags;
3129 +#ifdef TEST_EXISTANCE
3130 + int scratch, scratch2;
3133 + /* The above fails if memory managment is not set up yet.
3134 + * Rather than fail the set up, just keep track of the fact
3135 + * and pick up the interrupt thing later.
3137 + gdb_async_info = info;
3138 + port = gdb_async_info->port;
3139 + gdb_async_irq = state->irq;
3141 + printk("kgdb %s : port =%x, IRQ=%d, divisor =%d\n",
3144 + gdb_async_irq, gdb_async_info->state->custom_divisor);
3146 + local_irq_save(flags);
3147 +#ifdef TEST_EXISTANCE
3148 + /* Existance test */
3149 + /* Should not need all this, but just in case.... */
3151 + scratch = inb_p(port + UART_IER);
3152 + outb_px(port + UART_IER, 0);
3153 + outb_px(0xff, 0x080);
3154 + scratch2 = inb_p(port + UART_IER);
3155 + outb_px(port + UART_IER, scratch);
3158 + ("gdb_hook_interrupt: Could not clear IER, not a UART!\n");
3159 + local_irq_restore(flags);
3160 + return 1; /* We failed; there's nothing here */
3162 + scratch2 = inb_p(port + UART_LCR);
3163 + outb_px(port + UART_LCR, 0xBF); /* set up for StarTech test */
3164 + outb_px(port + UART_EFR, 0); /* EFR is the same as FCR */
3165 + outb_px(port + UART_LCR, 0);
3166 + outb_px(port + UART_FCR, UART_FCR_ENABLE_FIFO);
3167 + scratch = inb_p(port + UART_IIR) >> 6;
3168 + if (scratch == 1) {
3169 + printk("gdb_hook_interrupt: Undefined UART type!"
3170 + " Not a UART! \n");
3171 + local_irq_restore(flags);
3174 + dbprintk(("gdb_hook_interrupt: UART type "
3175 + "is %d where 0=16450, 2=16550 3=16550A\n", scratch));
3177 + scratch = inb_p(port + UART_MCR);
3178 + outb_px(port + UART_MCR, UART_MCR_LOOP | scratch);
3179 + outb_px(port + UART_MCR, UART_MCR_LOOP | 0x0A);
3180 + scratch2 = inb_p(port + UART_MSR) & 0xF0;
3181 + outb_px(port + UART_MCR, scratch);
3182 + if (scratch2 != 0x90) {
3183 + printk("gdb_hook_interrupt: "
3184 + "Loop back test failed! Not a UART!\n");
3185 + local_irq_restore(flags);
3186 + return scratch2 + 1000; /* force 0 to fail */
3188 +#endif /* test existance */
3189 + program_uart(info);
3190 + local_irq_restore(flags);
3194 +} /* gdb_hook_interrupt */
3197 +program_uart(struct async_struct *info)
3199 + int port = info->port;
3201 + (void) inb_p(port + UART_RX);
3202 + outb_px(port + UART_IER, 0);
3204 + (void) inb_p(port + UART_RX); /* serial driver comments say */
3205 + (void) inb_p(port + UART_IIR); /* this clears the interrupt regs */
3206 + (void) inb_p(port + UART_MSR);
3207 + outb_px(port + UART_LCR, UART_LCR_WLEN8 | UART_LCR_DLAB);
3208 + outb_px(port + UART_DLL, info->state->custom_divisor & 0xff); /* LS */
3209 + outb_px(port + UART_DLM, info->state->custom_divisor >> 8); /* MS */
3210 + outb_px(port + UART_MCR, info->MCR);
3212 + outb_px(port + UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1 | UART_FCR_CLEAR_XMIT | UART_FCR_CLEAR_RCVR); /* set fcr */
3213 + outb_px(port + UART_LCR, UART_LCR_WLEN8); /* reset DLAB */
3214 + outb_px(port + UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1); /* set fcr */
3215 + if (!ints_disabled) {
3216 + intprintk(("KGDB: Sending %d to port %x offset %d\n",
3217 + gdb_async_info->IER,
3218 + (int) gdb_async_info->port, UART_IER));
3219 + outb_px(gdb_async_info->port + UART_IER, gdb_async_info->IER);
3227 + * This is a GDB stub routine. It waits for a character from the
3228 + * serial interface and then returns it. If there is no serial
3229 + * interface connection then it returns a bogus value which will
3230 + * almost certainly cause the system to hang. In the
3232 +int kgdb_in_isr = 0;
3233 +int kgdb_in_lsr = 0;
3234 +extern spinlock_t kgdb_spinlock;
3236 +/* Caller takes needed protections */
3241 + volatile int chr, dum, time, end_time;
3243 + dbprintk(("getDebugChar(port %x): ", gdb_async_info->port));
3245 + if (gdb_async_info == NULL) {
3246 + gdb_hook_interrupt(&local_info, 0);
3249 + * This trick says if we wait a very long time and get
3250 + * no char, return the -1 and let the upper level deal
3254 + end_time = time + 2;
3255 + while (((chr = read_char(gdb_async_info)) == -1) &&
3256 + (end_time - time) > 0) {
3260 + * This covers our butts if some other code messes with
3261 + * our uart, hay, it happens :o)
3264 + program_uart(gdb_async_info);
3266 + dbprintk(("%c\n", chr > ' ' && chr < 0x7F ? chr : ' '));
3269 +} /* getDebugChar */
3271 +static int count = 3;
3272 +static spinlock_t one_at_atime = SPIN_LOCK_UNLOCKED;
3275 +kgdb_enable_ints(void)
3277 + if (gdb_async_info == NULL) {
3278 + gdb_hook_interrupt(&local_info, 1);
3280 + ok_to_enable_ints = 1;
3281 + kgdb_enable_ints_now();
3282 +#ifdef CONFIG_KGDB_USER_CONSOLE
3283 + kgdb_console_finit();
3288 +#ifdef CONFIG_SERIAL_8250
3289 +void shutdown_for_kgdb(struct async_struct *gdb_async_info);
3292 +#ifdef CONFIG_DISCONTIGMEM
3293 +static inline int kgdb_mem_init_done(void)
3295 + return highmem_start_page != NULL;
3298 +static inline int kgdb_mem_init_done(void)
3300 + return max_mapnr != 0;
3305 +kgdb_enable_ints_now(void)
3307 + if (!spin_trylock(&one_at_atime))
3309 + if (!ints_disabled)
3311 + if (kgdb_mem_init_done() &&
3312 + ints_disabled) { /* don't try till mem init */
3313 +#ifdef CONFIG_SERIAL_8250
3315 + * The ifdef here allows the system to be configured
3316 + * without the serial driver.
3317 + * Don't make it a module, however, it will steal the port
3319 + shutdown_for_kgdb(gdb_async_info);
3321 + ints_disabled = request_irq(gdb_async_info->state->irq,
3323 + IRQ_T(gdb_async_info),
3324 + "KGDB-stub", NULL);
3325 + intprintk(("KGDB: request_irq returned %d\n", ints_disabled));
3327 + if (!ints_disabled) {
3328 + intprintk(("KGDB: Sending %d to port %x offset %d\n",
3329 + gdb_async_info->IER,
3330 + (int) gdb_async_info->port, UART_IER));
3331 + outb_px(gdb_async_info->port + UART_IER, gdb_async_info->IER);
3334 + spin_unlock(&one_at_atime);
3340 + * This is a GDB stub routine. It waits until the interface is ready
3341 + * to transmit a char and then sends it. If there is no serial
3342 + * interface connection then it simply returns to its caller, having
3343 + * pretended to send the char. Caller takes needed protections.
3346 +putDebugChar(int chr)
3348 + dbprintk(("putDebugChar(port %x): chr=%02x '%c', ints_on=%d\n",
3349 + gdb_async_info->port,
3351 + chr > ' ' && chr < 0x7F ? chr : ' ', ints_disabled ? 0 : 1));
3353 + if (gdb_async_info == NULL) {
3354 + gdb_hook_interrupt(&local_info, 0);
3357 + write_char(gdb_async_info, chr); /* this routine will wait */
3358 + count = (chr == '#') ? 0 : count + 1;
3359 + if ((count == 2)) { /* try to enable after */
3360 + if (ints_disabled & ok_to_enable_ints)
3361 + kgdb_enable_ints_now(); /* try to enable after */
3363 + /* We do this a lot because, well we really want to get these
3364 + * interrupts. The serial driver will clear these bits when it
3365 + * initializes the chip. Every thing else it does is ok,
3368 + if (!ints_disabled) {
3369 + outb_px(gdb_async_info->port + UART_IER,
3370 + gdb_async_info->IER);
3374 +} /* putDebugChar */
3376 +module_init(kgdb_enable_ints);
3377 diff -puN arch/i386/lib/Makefile~kgdb-ga arch/i386/lib/Makefile
3378 --- 25/arch/i386/lib/Makefile~kgdb-ga 2004-10-21 14:54:15.265602768 -0700
3379 +++ 25-akpm/arch/i386/lib/Makefile 2004-10-21 14:54:15.313595472 -0700
3380 @@ -8,3 +8,4 @@ lib-y = checksum.o delay.o usercopy.o ge
3382 lib-$(CONFIG_X86_USE_3DNOW) += mmx.o
3383 lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o
3384 +lib-$(CONFIG_KGDB) += kgdb_serial.o
3385 diff -puN arch/i386/Makefile~kgdb-ga arch/i386/Makefile
3386 --- 25/arch/i386/Makefile~kgdb-ga 2004-10-21 14:54:15.266602616 -0700
3387 +++ 25-akpm/arch/i386/Makefile 2004-10-21 14:54:15.314595320 -0700
3388 @@ -99,6 +99,9 @@ core-$(CONFIG_X86_ES7000) := arch/i386/m
3389 # default subarch .h files
3390 mflags-y += -Iinclude/asm-i386/mach-default
3392 +mflags-$(CONFIG_KGDB) += -gdwarf-2
3393 +mflags-$(CONFIG_KGDB_MORE) += $(shell echo $(CONFIG_KGDB_OPTIONS) | sed -e 's/"//g')
3395 head-y := arch/i386/kernel/head.o arch/i386/kernel/init_task.o
3397 libs-y += arch/i386/lib/
3398 diff -puN arch/i386/mm/fault.c~kgdb-ga arch/i386/mm/fault.c
3399 --- 25/arch/i386/mm/fault.c~kgdb-ga 2004-10-21 14:54:15.268602312 -0700
3400 +++ 25-akpm/arch/i386/mm/fault.c 2004-10-21 14:54:15.314595320 -0700
3401 @@ -430,6 +430,12 @@ no_context:
3402 * Oops. The kernel tried to access some bad page. We'll have to
3403 * terminate things with extreme prejudice.
3406 + if (!user_mode(regs)){
3407 + kgdb_handle_exception(14,SIGBUS, error_code, regs);
3414 diff -puN arch/x86_64/boot/compressed/head.S~kgdb-ga arch/x86_64/boot/compressed/head.S
3415 --- 25/arch/x86_64/boot/compressed/head.S~kgdb-ga 2004-10-21 14:54:15.269602160 -0700
3416 +++ 25-akpm/arch/x86_64/boot/compressed/head.S 2004-10-21 14:54:15.315595168 -0700
3421 +#define IN_BOOTLOADER
3422 #include <linux/linkage.h>
3423 #include <asm/segment.h>
3425 diff -puN arch/x86_64/boot/compressed/misc.c~kgdb-ga arch/x86_64/boot/compressed/misc.c
3426 --- 25/arch/x86_64/boot/compressed/misc.c~kgdb-ga 2004-10-21 14:54:15.270602008 -0700
3427 +++ 25-akpm/arch/x86_64/boot/compressed/misc.c 2004-10-21 14:54:15.315595168 -0700
3429 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
3432 +#define IN_BOOTLOADER
3433 #include "miscsetup.h"
3436 diff -puN /dev/null Documentation/i386/kgdb/andthen
3437 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
3438 +++ 25-akpm/Documentation/i386/kgdb/andthen 2004-10-21 14:54:15.316595016 -0700
3443 + set var $thp=(struct kgdb_and_then_struct *)&kgdb_data[0]
3444 + set var $at_size = (sizeof kgdb_data)/(sizeof *$thp)
3445 + set var $at_oc=kgdb_and_then_count
3446 + set var $at_cc=$at_oc
3449 +define andthen_next
3450 + set var $at_cc=$arg0
3455 + if ($at_cc >= $at_oc)
3456 + printf "Outside window. Window size is %d\n",($at_oc-$at_low)
3458 + printf "%d: ",$at_cc
3459 + output *($thp+($at_cc++ % $at_size ))
3463 +define andthen_set_edge
3464 + set var $at_oc=kgdb_and_then_count
3465 + set var $at_low = $at_oc - $at_size
3467 + set var $at_low = 0
3469 + if (( $at_cc > $at_oc) || ($at_cc < $at_low))
3470 + printf "Count outside of window, setting count to "
3471 + if ($at_cc >= $at_oc)
3472 + set var $at_cc = $at_oc
3474 + set var $at_cc = $at_low
3476 + printf "%d\n",$at_cc
3482 + if ($at_cc <= $at_low)
3483 + printf "Outside window. Window size is %d\n",($at_oc-$at_low)
3485 + printf "%d: ",$at_cc-1
3486 + output *($thp+(--$at_cc % $at_size ))
3491 +document andthen_next
3492 + andthen_next <count>
3493 + . sets the number of the event to display next. If this event
3494 + . is not in the event pool, either andthen or beforethat will
3495 + . correct it to the nearest event pool edge. The event pool
3496 + . ends at the last event recorded and begins <number of events>
3497 + . prior to that. If beforethat is used next, it will display
3498 + . event <count> -1.
3500 + andthen commands are: set_andthen, andthen_next, andthen and beforethat
3506 +. displays the next event in the list. <set_andthen> sets up to display
3507 +. the oldest saved event first.
3508 +. <count> (optional) count of the event to display.
3509 +. note the number of events saved is specified at configure time.
3510 +. if events are saved between calls to andthen the index will change
3511 +. but the displayed event will be the next one (unless the event buffer
3514 +. andthen commands are: set_andthen, andthen_next, andthen and beforethat
3517 +document set_andthen
3519 +. sets up to use the <andthen> and <beforethat> commands.
3520 +. if you have defined your own struct, use the above and
3521 +. then enter the following:
3522 +. p $thp=(struct kgdb_and_then_structX *)&kgdb_data[0]
3523 +. where <kgdb_and_then_structX> is the name of your structure.
3525 +. andthen commands are: set_andthen, andthen_next, andthen and beforethat
3528 +document beforethat
3530 +. displays the next prior event in the list. <set_andthen> sets up to
3531 +. display the last occuring event first.
3533 +. note the number of events saved is specified at configure time.
3534 +. if events are saved between calls to beforethat the index will change
3535 +. but the displayed event will be the next one (unless the event buffer
3538 +. andthen commands are: set_andthen, andthen_next, andthen and beforethat
3540 diff -puN /dev/null Documentation/i386/kgdb/debug-nmi.txt
3541 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
3542 +++ 25-akpm/Documentation/i386/kgdb/debug-nmi.txt 2004-10-21 14:54:15.316595016 -0700
3544 +Subject: Debugging with NMI
3545 +Date: Mon, 12 Jul 1999 11:28:31 -0500
3546 +From: David Grothe <dave@gcom.com>
3547 +Organization: Gcom, Inc
3548 +To: David Grothe <dave@gcom.com>
3552 +Maybe this is old hat, but it is new to me --
3554 +On an ISA bus machine, if you short out the A1 and B1 pins of an ISA
3555 +slot you will generate an NMI to the CPU. This interrupts even a
3556 +machine that is hung in a loop with interrupts disabled. Used in
3557 +conjunction with kgdb <
3558 +ftp://ftp.gcom.com/pub/linux/src/kgdb-2.3.35/kgdb-2.3.35.tgz > you can
3559 +gain debugger control of a machine that is hung in the kernel! Even
3560 +without kgdb the kernel will print a stack trace so you can find out
3563 +The A1/B1 pins are directly opposite one another and the farthest pins
3564 +towards the bracket end of the ISA bus socket. You can stick a paper
3565 +clip or multi-meter probe between them to short them out.
3567 +I had a spare ISA bus to PC104 bus adapter around. The PC104 end of the
3568 +board consists of two rows of wire wrap pins. So I wired a push button
3569 +between the A1/B1 pins and now have an ISA board that I can stick into
3570 +any ISA bus slot for debugger entry.
3572 +Microsoft has a circuit diagram of a PCI card at
3573 +http://www.microsoft.com/hwdev/DEBUGGING/DMPSW.HTM. If you want to
3574 +build one you will have to mail them and ask for the PAL equations.
3575 +Nobody makes one comercially.
3577 +[THIS TIP COMES WITH NO WARRANTY WHATSOEVER. It works for me, but if
3578 +your machine catches fire, it is your problem, not mine.]
3580 +-- Dave (the kgdb guy)
3581 diff -puN /dev/null Documentation/i386/kgdb/gdb-globals.txt
3582 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
3583 +++ 25-akpm/Documentation/i386/kgdb/gdb-globals.txt 2004-10-21 14:54:15.317594864 -0700
3585 +Sender: akale@veritas.com
3586 +Date: Fri, 23 Jun 2000 19:26:35 +0530
3587 +From: "Amit S. Kale" <akale@veritas.com>
3588 +Organization: Veritas Software (India)
3589 +To: Dave Grothe <dave@gcom.com>, linux-kernel@vger.rutgers.edu
3590 +CC: David Milburn <dmilburn@wirespeed.com>,
3591 + "Edouard G. Parmelan" <Edouard.Parmelan@quadratec.fr>,
3592 + ezannoni@cygnus.com, Keith Owens <kaos@ocs.com.au>
3593 +Subject: Re: Module debugging using kgdb
3599 +> There is a 2.4.0 version of kgdb on our ftp site:
3600 +> ftp://ftp.gcom.com/pub/linux/src/kgdb. I mirrored your version of gdb
3601 +> and loadmodule.sh there.
3603 +> Have a look at the README file and see if I go it right. If not, send
3604 +> me some corrections and I will update it.
3606 +> Does your version of gdb solve the global variable problem?
3609 +Thanks to Elena Zanoni, gdb (developement version) can now calculate
3610 +correctly addresses of dynamically loaded object files. I have not been
3611 +following gdb developement for sometime and am not sure when symbol
3612 +address calculation fix is going to appear in a gdb stable version.
3614 +Elena, any idea when the fix will make it to a prebuilt gdb from a
3617 +For the time being I have built a gdb developement version. It can be
3618 +used for module debugging with loadmodule.sh script.
3620 +The problem with calculating of module addresses with previous versions
3621 +of gdb was as follows:
3622 +gdb did not use base address of a section while calculating address of
3623 +a symbol in the section in an object file loaded via 'add-symbol-file'.
3624 +It used address of .text segment instead. Due to this addresses of
3625 +symbols in .data, .bss etc. (e.g. global variables) were calculated incorrectly.
3627 +Above mentioned fix allow gdb to use base address of a segment while
3628 +calculating address of a symbol in it. It adds a parameter '-s' to
3629 +'add-symbol-file' command for specifying base address of a segment.
3631 +loadmodule.sh script works as follows.
3633 +1. Copy a module file to target machine.
3634 +2. Load the module on the target machine using insmod with -m parameter.
3635 +insmod produces a module load map which contains base addresses of all
3636 +sections in the module and addresses of symbols in the module file.
3637 +3. Find all sections and their base addresses in the module from
3639 +4. Generate a script that loads the module file. The script uses
3640 +'add-symbol-file' and specifies address of text segment followed by
3641 +addresses of all segments in the module.
3643 +Here is an example gdb script produced by loadmodule.sh script.
3645 +add-symbol-file foo 0xd082c060 -s .text.lock 0xd08cbfb5
3646 +-s .fixup 0xd08cfbdf -s .rodata 0xd08cfde0 -s __ex_table 0xd08e3b38
3647 +-s .data 0xd08e3d00 -s .bss 0xd08ec8c0 -s __ksymtab 0xd08ee838
3649 +With this command gdb can calculate addresses of symbols in ANY segment
3655 +Veritas Software ( http://www.veritas.com )
3656 diff -puN /dev/null Documentation/i386/kgdb/gdbinit
3657 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
3658 +++ 25-akpm/Documentation/i386/kgdb/gdbinit 2004-10-21 14:54:15.317594864 -0700
3660 +shell echo -e "\003" >/dev/ttyS0
3661 +set remotebaud 38400
3662 +target remote /dev/ttyS0
3665 +printf "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n", $eax, $ebx, $ecx, $edx
3666 +printf "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n", $esi, $edi, $ebp, $esp
3671 +printf "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n", $eax, $ebx, $ecx, $edx
3672 +printf "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n", $esi, $edi, $ebp, $esp
3674 diff -puN /dev/null Documentation/i386/kgdb/gdbinit.hw
3675 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
3676 +++ 25-akpm/Documentation/i386/kgdb/gdbinit.hw 2004-10-21 14:54:15.318594712 -0700
3679 +#Using ia-32 hardware breakpoints.
3681 +#4 hardware breakpoints are available in ia-32 processors. These breakpoints
3682 +#do not need code modification. They are set using debug registers.
3684 +#Each hardware breakpoint can be of one of the
3685 +#three types: execution, write, access.
3686 +#1. An Execution breakpoint is triggered when code at the breakpoint address is
3688 +#2. A write breakpoint ( aka watchpoints ) is triggered when memory location
3689 +#at the breakpoint address is written.
3690 +#3. An access breakpoint is triggered when memory location at the breakpoint
3691 +#address is either read or written.
3693 +#As hardware breakpoints are available in limited number, use software
3694 +#breakpoints ( br command in gdb ) instead of execution hardware breakpoints.
3696 +#Length of an access or a write breakpoint defines length of the datatype to
3697 +#be watched. Length is 1 for char, 2 short , 3 int.
3699 +#For placing execution, write and access breakpoints, use commands
3700 +#hwebrk, hwwbrk, hwabrk
3701 +#To remove a breakpoint use hwrmbrk command.
3703 +#These commands take following types of arguments. For arguments associated
3704 +#with each command, use help command.
3705 +#1. breakpointno: 0 to 3
3707 +#3. address: Memory location in hex ( without 0x ) e.g c015e9bc
3709 +#Use the command exinfo to find which hardware breakpoint occured.
3711 +#hwebrk breakpointno address
3713 + maintenance packet Y$arg0,0,0,$arg1
3716 + hwebrk <breakpointno> <address>
3717 + Places a hardware execution breakpoint
3718 + <breakpointno> = 0 - 3
3719 + <address> = Hex digits without leading "0x".
3722 +#hwwbrk breakpointno length address
3724 + maintenance packet Y$arg0,1,$arg1,$arg2
3727 + hwwbrk <breakpointno> <length> <address>
3728 + Places a hardware write breakpoint
3729 + <breakpointno> = 0 - 3
3730 + <length> = 1 (1 byte), 2 (2 byte), 3 (4 byte)
3731 + <address> = Hex digits without leading "0x".
3734 +#hwabrk breakpointno length address
3736 + maintenance packet Y$arg0,1,$arg1,$arg2
3739 + hwabrk <breakpointno> <length> <address>
3740 + Places a hardware access breakpoint
3741 + <breakpointno> = 0 - 3
3742 + <length> = 1 (1 byte), 2 (2 byte), 3 (4 byte)
3743 + <address> = Hex digits without leading "0x".
3746 +#hwrmbrk breakpointno
3748 + maintenance packet y$arg0
3751 + hwrmbrk <breakpointno>
3752 + <breakpointno> = 0 - 3
3753 + Removes a hardware breakpoint
3757 + maintenance packet r
3761 + maintenance packet qE
3765 + Gives information about a breakpoint.
3768 + p $th=(struct thread_info *)((int)$esp & ~8191)
3772 + Gets and prints the current thread_info pointer, Defines th to be it.
3775 + p $cu=((struct thread_info *)((int)$esp & ~8191))->task
3779 + Gets and print the "current" value. Defines $cu to be it.
3782 + set var $flags=$eflags
3783 + set $eflags=$eflags&~0x200
3786 + set var $eflags|=$flags&0x200
3789 + saves the current interrupt state and clears the processor interrupt
3790 + flag. Use int_on to restore the saved flag.
3793 + Restores the interrupt flag saved by int_off.
3795 diff -puN /dev/null Documentation/i386/kgdb/gdbinit-modules
3796 --- /dev/null Thu Apr 11 07:25:15 2002
3797 +++ 25-akpm/Documentation/i386/kgdb/gdbinit-modules Fri Jan 13 17:54:25 2006
3800 +# Usefull GDB user-command to debug Linux Kernel Modules with gdbstub.
3802 +# This don't work for Linux-2.0 or older.
3804 +# Author Edouard G. Parmelan <Edouard.Parmelan@quadratec.fr>
3807 +# Fri Apr 30 20:33:29 CEST 1999
3808 +# First public release.
3810 +# Major cleanup after experiment Linux-2.0 kernel without success.
3811 +# Symbols of a module are not in the correct order, I can't explain
3814 +# Fri Mar 19 15:41:40 CET 1999
3817 +# Thu Jan 6 16:29:03 CST 2000
3818 +# A little fixing by Dave Grothe <dave@gcom.com>
3820 +# Mon Jun 19 09:33:13 CDT 2000
3821 +# Alignment changes from Edouard Parmelan
3823 +# The basic idea is to find where insmod load the module and inform
3824 +# GDB to load the symbol table of the module with the GDB command
3825 +# ``add-symbol-file <object> <address>''.
3827 +# The Linux kernel holds the list of all loaded modules in module_list,
3828 +# this list end with &kernel_module (exactly with module->next == NULL,
3829 +# but the last module is not a real module).
3831 +# Insmod allocates the struct module before the object file. Since
3832 +# Linux-2.1, this structure contain his size. The real address of
3833 +# the object file is then (char*)module + module->size_of_struct.
3835 +# You can use three user functions ``mod-list'', ``mod-print-symbols''
3836 +# and ``add-module-symbols''.
3838 +# mod-list list all loaded modules with the format:
3839 +# <module-address> <module-name>
3841 +# As soon as you have found the address of your module, you can
3842 +# print its exported symbols (mod-print-symbols) or inform GDB to add
3843 +# symbols from your module file (mod-add-symbols).
3845 +# The argument that you give to mod-print-symbols or mod-add-symbols
3846 +# is the <module-address> from the mod-list command.
3848 +# When using the mod-add-symbols command you must also give the full
3849 +# pathname of the modules object code file.
3851 +# The command mod-add-lis is an example of how to make this easier.
3852 +# You can edit this macro to contain the path name of your own
3853 +# favorite module and then use it as a shorthand to load it. You
3854 +# still need the module-address, however.
3856 +# The internal function ``mod-validate'' set the GDB variable $mod
3857 +# as a ``struct module*'' if the kernel known the module otherwise
3858 +# $mod is set to NULL. This ensure to not add symbols for a wrong
3862 +# Sat Feb 12 20:05:47 CET 2005
3864 +# Adapted to the 2.6.* module data structure.
3865 +# (Getting miffed at gdb for not having "offsetof" in the process :-/ )
3867 +# Autogenerate add-symbol-file statements from the module list instead
3868 +# of relying on a no-longer-working loadmodule.sh program.
3870 +# Matthias Urlichs <smurf@debian.org>
3873 +# Have a nice hacking day !
3877 + set $lmod = modules->next
3878 + # This is a circular data structure
3879 + while $lmod != &modules
3880 + set $mod = (struct module *)(((char *)$lmod) - ((int)&(((struct module *)0) -> list)))
3881 + printf "%p\t%s\n", $mod, $mod->name
3882 + set $lmod = $lmod->next
3887 +List all modules in the form: <module-address> <module-name>
3888 +Use the <module-address> as the argument for the other
3889 +mod-commands: mod-print-symbols, mod-add-symbols.
3892 +define mod-list-syms
3893 + set $lmod = modules->next
3894 + # This is a circular data structure
3895 + while $lmod != &modules
3896 + set $mod = (struct module *)(((char *)$lmod) - ((int)&(((struct module *)0) -> list)))
3897 + printf "add-symbol-file %s.ko %p\n", $mod->name, $mod->module_core
3898 + set $lmod = $lmod->next
3901 +document mod-list-syms
3903 +List all modules in the form: add-symbol-file <module-path> <module-core>
3904 +for adding modules' symbol tables without loadmodule.sh.
3907 +define mod-validate
3908 + set $lmod = modules->next
3909 + set $mod = (struct module *)(((char *)$lmod) - ((int)&(((struct module *)0) -> list)))
3910 + while ($lmod != &modules) && ($mod != $arg0)
3911 + set $lmod = $lmod->next
3912 + set $mod = (struct module *)(((char *)$lmod) - ((int)&(((struct module *)0) -> list)))
3914 + if $lmod == &modules
3916 + printf "%p is not a module\n", $arg0
3919 +document mod-validate
3920 +mod-validate <module-address>
3921 +Internal user-command used to validate the module parameter.
3922 +If <module> is a real loaded module, set $mod to it, otherwise set $mod
3926 +define mod-print-symbols
3927 + mod-validate $arg0
3930 + while $i < $mod->num_syms
3931 + set $sym = $mod->syms[$i]
3932 + printf "%p\t%s\n", $sym->value, $sym->name
3936 + while $i < $mod->num_gpl_syms
3937 + set $sym = $mod->gpl_syms[$i]
3938 + printf "%p\t%s\n", $sym->value, $sym->name
3943 +document mod-print-symbols
3944 +mod-print-symbols <module-address>
3945 +Print all exported symbols of the module. See mod-list
3948 diff -puN /dev/null Documentation/i386/kgdb/kgdb.txt
3949 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
3950 +++ 25-akpm/Documentation/i386/kgdb/kgdb.txt 2004-10-21 14:54:15.324593800 -0700
3952 +Last edit: <20030806.1637.12>
3953 +This file has information specific to the i386 kgdb option. Other
3954 +platforms with the kgdb option may behave in a similar fashion.
3959 +This version was made against the 2.6.0-test2 kernel. We have made the
3962 +- The getthread() code in the stub calls find_task_by_pid(). It fails
3963 + if we are early in the bring up such that the pid arrays have yet to
3964 + be allocated. We have added a line to kernel/pid.c to make
3965 + "kgdb_pid_init_done" true once the arrays are allocated. This way the
3966 + getthread() code knows not to call. This is only used by the thread
3967 + debugging stuff and threads will not yet exist at this point in the
3970 +- For some reason, gdb was not asking for a new thread list when the
3971 + "info thread" command was given. We changed to the newer version of
3972 + the thread info command and gdb now seems to ask when needed. Result,
3973 + we now get all threads in the thread list.
3975 +- We now respond to the ThreadExtraInfo request from gdb with the thread
3976 + name from task_struct .comm. This then appears in the thread list.
3977 + Thoughts on additional options for this are welcome. Things such as
3978 + "has BKL" and "Preempted" come to mind. I think we could have a flag
3979 + word that could enable different bits of info here.
3981 +- We now honor, sort of, the C and S commands. These are continue and
3982 + single set after delivering a signal. We ignore the signal and do the
3983 + requested action. This only happens when we told gdb that a signal
3984 + was the reason for entry, which is only done on memory faults. The
3985 + result is that you can now continue into the Oops.
3987 +- We changed the -g to -gdwarf-2. This seems to be the same as -ggdb,
3988 + but it is more exact on what language to use.
3990 +- We added two dwarf2 include files and a bit of code at the end of
3991 + entry.S. This does not yet work, so it is disabled. Still we want to
3992 + keep track of the code and "maybe" someone out there can fix it.
3994 +- Randy Dunlap sent some fix ups for this file which are now merged.
3996 +- Hugh Dickins sent a fix to a bit of code in traps.c that prevents a
3997 + compiler warning if CONFIG_KGDB is off (now who would do that :).
3999 +- Andrew Morton sent a fix for the serial driver which is now merged.
4001 +- Andrew also sent a change to the stub around the cpu managment code
4002 + which is also merged.
4004 +- Andrew also sent a patch to make "f" as well as "g" work as SysRq
4005 + commands to enter kgdb, merged.
4007 +- If CONFIG_KGDB and CONFIG_DEBUG_SPINLOCKS are both set we added a
4008 + "who" field to the spinlock data struct. This is filled with
4009 + "current" when ever the spinlock suceeds. Useful if you want to know
4012 +_ And last, but not least, we fixed the "get_cu" macro to properly get
4013 + the current value of "current".
4018 +We are starting to align with the sourceforge version, at least in
4019 +commands. To this end, the boot command string to start kgdb at
4020 +boot time has been changed from "kgdb" to "gdb".
4022 +Andrew Morton sent a couple of patches which are now included as follows:
4023 +1.) We now return a flag to the interrupt handler.
4024 +2.) We no longer use smp_num_cpus (a conflict with the lock meter).
4025 +3.) And from William Lee Irwin III <wli@holomorphy.com> code to make
4026 + sure high-mem is set up before we attempt to register our interrupt
4028 +We now include asm/kgdb.h from config.h so you will most likely never
4029 +have to include it. It also 'NULLS' the kgdb macros you might have in
4030 +your code when CONFIG_KGDB is not defined. This allows you to just
4031 +turn off CONFIG_KGDB to turn off all the kgdb_ts() calls and such.
4032 +This include is conditioned on the machine being an x86 so as to not
4033 +mess with other archs.
4036 +This is currently the version for the 2.4.18 (and beyond?) kernel.
4038 +We have several new "features" beginning with this version:
4040 +1.) Kgdb now syncs the "other" CPUs with a cross-CPU NMI. No more
4041 + waiting and it will pull that guy out of an IRQ off spin lock :)
4043 +2.) We doctored up the code that tells where a task is waiting and
4044 + included it so that the "info thread" command will show a bit more
4045 + than "schedule()". Try it...
4047 +3.) Added the ability to call a function from gdb. All the standard gdb
4048 + issues apply, i.e. if you hit a breakpoint in the function, you are
4049 + not allowed to call another (gdb limitation, not kgdb). To help
4050 + this capability we added a memory allocation function. Gdb does not
4051 + return this memory (it is used for strings that you pass to that function
4052 + you are calling from gdb) so we fixed up a way to allow you to
4053 + manually return the memory (see below).
4055 +4.) Kgdb time stamps (kgdb_ts()) are enhanced to expand what was the
4056 + interrupt flag to now also include the preemption count and the
4057 + "in_interrupt" info. The flag is now called "with_pif" to indicate
4058 + the order, preempt_count, in_interrupt, flag. The preempt_count is
4059 + shifted left by 4 bits so you can read the count in hex by dropping
4060 + the low order digit. In_interrupt is in bit 1, and the flag is in
4063 +5.) The command: "p kgdb_info" is now expanded and prints something
4066 +$2 = {used_malloc = 0, called_from = 0xc0107506, entry_tsc = 67468627259,
4067 + errcode = 0, vector = 3, print_debug_info = 0, hold_on_sstep = 1,
4068 + cpus_waiting = {{task = 0xc027a000, pid = 32768, hold = 0,
4069 + regs = 0xc027bf84}, {task = 0x0, pid = 0, hold = 0, regs = 0x0}}}
4071 + Things to note here: a.) used_malloc is the amount of memory that
4072 + has been malloc'ed to do calls from gdb. You can reclaim this
4073 + memory like this: "p kgdb_info.used_malloc=0" Cool, huh? b.)
4074 + cpus_waiting is now "sized" by the number of CPUs you enter at
4075 + configure time in the kgdb configure section. This is NOT used
4076 + anywhere else in the system, but it is "nice" here. c.) The task's
4077 + "pid" is now in the structure. This is the pid you will need to use
4078 + to decode to the thread id to get gdb to look at that thread.
4079 + Remember that the "info thread" command prints a list of threads
4080 + wherein it numbers each thread with its reference number followed
4081 + by the thread's pid. Note that the per-CPU idle threads actually
4082 + have pids of 0 (yes, there is more than one pid 0 in an SMP system).
4083 + To avoid confusion, kgdb numbers these threads with numbers beyond
4084 + the MAX_PID. That is why you see 32768 and above.
4086 +6.) A subtle change, we now provide the complete register set for tasks
4087 + that are active on the other CPUs. This allows better trace back on
4090 + And, let's mention what we could not fix. Back-trace from all but the
4091 + thread that we trapped will, most likely, have a bogus entry in it.
4092 + The problem is that gdb does not recognize the entry code for
4093 + functions that use "current" near (at all?) the entry. The compiler
4094 + is putting the "current" decode as the first two instructions of the
4095 + function where gdb expects to find %ebp changing code. Back trace
4096 + also has trouble with interrupt frames. I am talking with Daniel
4097 + Jacobowitz about some way to fix this, but don't hold your breath.
4100 +Major enhancement with this version is the ability to hold one or more
4101 +CPUs in an SMP system while allowing the others to continue. Also, by
4102 +default only the current CPU is enabled on single-step commands (please
4103 +note that gdb issues single-step commands at times other than when you
4104 +use the si command).
4106 +Another change is to collect some useful information in
4107 +a global structure called "kgdb_info". You should be able to just:
4111 +although I have seen cases where the first time this is done gdb just
4112 +prints the first member but prints the whole structure if you then enter
4113 +CR (carriage return or enter). This also works:
4119 +$4 = {called_from = 0xc010732c, entry_tsc = 32804123790856, errcode = 0,
4120 + vector = 3, print_debug_info = 0}
4122 +"Called_from" is the return address from the current entry into kgdb.
4123 +Sometimes it is useful to know why you are in kgdb, for example, was
4124 +it an NMI or a real breakpoint? The simple way to interrogate this
4129 +which will print the surrounding few lines of source code.
4131 +"Entry_tsc" is the CPU TSC on entry to kgdb (useful to compare to the
4134 +"errcode" and "vector" are other entry parameters which may be helpful on
4137 +"print_debug_info" is the internal debugging kgdb print enable flag. Yes,
4140 +In SMP systems kgdb_info also includes the "cpus_waiting" structure and
4144 +$7 = {called_from = 0xc0112739, entry_tsc = 1034936624074, errcode = 0,
4145 + vector = 2, print_debug_info = 0, hold_on_sstep = 1, cpus_waiting = {{
4146 + task = 0x0, hold = 0, regs = 0x0}, {task = 0xc71b8000, hold = 0,
4147 + regs = 0xc71b9f70}, {task = 0x0, hold = 0, regs = 0x0}, {task = 0x0,
4148 + hold = 0, regs = 0x0}, {task = 0x0, hold = 0, regs = 0x0}, {task = 0x0,
4149 + hold = 0, regs = 0x0}, {task = 0x0, hold = 0, regs = 0x0}, {task = 0x0,
4150 + hold = 0, regs = 0x0}}}
4152 +"Cpus_waiting" has an entry for each CPU other than the current one that
4153 +has been stopped. Each entry contains the task_struct address for that
4154 +CPU, the address of the regs for that task and a hold flag. All these
4155 +have the proper typing so that, for example:
4157 +p *kgdb_info.cpus_waiting[1].regs
4159 +will print the registers for CPU 1.
4161 +"Hold_on_sstep" is a new feature with this version and comes up set or
4162 +true. What this means is that whenever kgdb is asked to single-step all
4163 +other CPUs are held (i.e. not allowed to execute). The flag applies to
4164 +all but the current CPU and, again, can be changed:
4166 +p kgdb_info.hold_on_sstep=0
4168 +restores the old behavior of letting all CPUs run during single-stepping.
4170 +Likewise, each CPU has a "hold" flag, which if set, locks that CPU out
4171 +of execution. Note that this has some risk in cases where the CPUs need
4172 +to communicate with each other. If kgdb finds no CPU available on exit,
4173 +it will push a message thru gdb and stay in kgdb. Note that it is legal
4174 +to hold the current CPU as long as at least one CPU can execute.
4177 +This version implements an event queue. Events are signaled by calling
4178 +a function in the kgdb stub and may be examined from gdb. See EVENTS
4179 +below for details. This version also tightens up the interrupt and SMP
4180 +handling to not allow interrupts on the way to kgdb from a breakpoint
4181 +trap. It is fine to allow these interrupts for user code, but not
4187 +This version of the kgdb package was developed and tested on
4188 +kernel version 2.4.16. It will not install on any earlier kernels.
4189 +It is possible that it will continue to work on later versions
4190 +of 2.4 and then versions of 2.5 (I hope).
4196 +Designate one machine as the "development" machine. This is the
4197 +machine on which you run your compiles and which has your source
4198 +code for the kernel. Designate a second machine as the "target"
4199 +machine. This is the machine that will run your experimental
4202 +The two machines will be connected together via a serial line out
4203 +one or the other of the COM ports of the PC. You will need the
4204 +appropriate modem eliminator (null modem) cable(s) for this.
4206 +Decide on which tty port you want the machines to communicate, then
4207 +connect them up back-to-back using the null modem cable. COM1 is
4208 +/dev/ttyS0 and COM2 is /dev/ttyS1. You should test this connection
4209 +with the two machines prior to trying to debug a kernel. Once you
4210 +have it working, on the TARGET machine, enter:
4212 +setserial /dev/ttyS0 (or what ever tty you are using)
4214 +and record the port address and the IRQ number.
4216 +On the DEVELOPMENT machine you need to apply the patch for the kgdb
4217 +hooks. You have probably already done that if you are reading this
4220 +On your DEVELOPMENT machine, go to your kernel source directory and do
4221 +"make Xconfig" where X is one of "x", "menu", or "". If you are
4222 +configuring in the standard serial driver, it must not be a module.
4223 +Either yes or no is ok, but making the serial driver a module means it
4224 +will initialize after kgdb has set up the UART interrupt code and may
4225 +cause a failure of the control-C option discussed below. The configure
4226 +question for the serial driver is under the "Character devices" heading
4229 +"Standard/generic (8250/16550 and compatible UARTs) serial support"
4231 +Go down to the kernel debugging menu item and open it up. Enable the
4232 +kernel kgdb stub code by selecting that item. You can also choose to
4233 +turn on the "-ggdb -O1" compile options. The -ggdb causes the compiler
4234 +to put more debug info (like local symbols) in the object file. On the
4235 +i386 -g and -ggdb are the same so this option just reduces to "O1". The
4236 +-O1 reduces the optimization level. This may be helpful in some cases,
4237 +be aware, however, that this may also mask the problem you are looking
4240 +The baud rate. Default is 115200. What ever you choose be sure that
4241 +the host machine is set to the same speed. I recommend the default.
4243 +The port. This is the I/O address of the serial UART that you should
4244 +have gotten using setserial as described above. The standard COM1 port
4245 +(3f8) using IRQ 4 is default. COM2 is 2f8 which by convention uses IRQ
4248 +The port IRQ (see above).
4250 +Stack overflow test. This option makes a minor change in the trap,
4251 +system call and interrupt code to detect stack overflow and transfer
4252 +control to kgdb if it happens. (Some platforms have this in the
4253 +baseline code, but the i386 does not.)
4255 +You can also configure the system to recognize the boot option
4256 +"console=kgdb" which if given will cause all console output during
4257 +booting to be put thru gdb as well as other consoles. This option
4258 +requires that gdb and kgdb be connected prior to sending console output
4259 +so, if they are not, a breakpoint is executed to force the connection.
4260 +This will happen before any kernel output (it is going thru gdb, right),
4261 +and will stall the boot until the connection is made.
4263 +You can also configure in a patch to SysRq to enable the kGdb SysRq.
4264 +This request generates a breakpoint. Since the serial port IRQ line is
4265 +set up after any serial drivers, it is possible that this command will
4266 +work when the control-C will not.
4268 +Save and exit the Xconfig program. Then do "make clean" , "make dep"
4269 +and "make bzImage" (or whatever target you want to make). This gets the
4270 +kernel compiled with the "-g" option set -- necessary for debugging.
4272 +You have just built the kernel on your DEVELOPMENT machine that you
4273 +intend to run on your TARGET machine.
4275 +To install this new kernel, use the following installation procedure.
4276 +Remember, you are on the DEVELOPMENT machine patching the kernel source
4277 +for the kernel that you intend to run on the TARGET machine.
4279 +Copy this kernel to your target machine using your usual procedures. I
4280 +usually arrange to copy development:
4281 +/usr/src/linux/arch/i386/boot/bzImage to /vmlinuz on the TARGET machine
4282 +via a LAN based NFS access. That is, I run the cp command on the target
4283 +and copy from the development machine via the LAN. Run Lilo (see "man
4284 +lilo" for details on how to set this up) on the new kernel on the target
4285 +machine so that it will boot! Then boot the kernel on the target
4288 +On the DEVELOPMENT machine, create a file called .gdbinit in the
4289 +directory /usr/src/linux. An example .gdbinit file looks like this:
4291 +shell echo -e "\003" >/dev/ttyS0
4292 +set remotebaud 38400 (or what ever speed you have chosen)
4293 +target remote /dev/ttyS0
4296 +Change the "echo" and "target" definition so that it specifies the tty
4297 +port that you intend to use. Change the "remotebaud" definition to
4298 +match the data rate that you are going to use for the com line.
4300 +You are now ready to try it out.
4302 +Boot your target machine with "kgdb" in the boot command i.e. something
4307 +or if you also want console output thru gdb:
4309 +lilo> test kgdb console=kgdb
4311 +You should see the lilo message saying it has loaded the kernel and then
4312 +all output stops. The kgdb stub is trying to connect with gdb. Start
4313 +gdb something like this:
4316 +On your DEVELOPMENT machine, cd /usr/src/linux and enter "gdb vmlinux".
4317 +When gdb gets the symbols loaded it will read your .gdbinit file and, if
4318 +everything is working correctly, you should see gdb print out a few
4319 +lines indicating that a breakpoint has been taken. It will actually
4320 +show a line of code in the target kernel inside the kgdb activation
4323 +The gdb interaction should look something like this:
4325 + linux-dev:/usr/src/linux# gdb vmlinux
4326 + GDB is free software and you are welcome to distribute copies of it
4327 + under certain conditions; type "show copying" to see the conditions.
4328 + There is absolutely no warranty for GDB; type "show warranty" for details.
4329 + GDB 4.15.1 (i486-slackware-linux),
4330 + Copyright 1995 Free Software Foundation, Inc...
4331 + breakpoint () at i386-stub.c:750
4335 +You can now use whatever gdb commands you like to set breakpoints.
4336 +Enter "continue" to start your target machine executing again. At this
4337 +point the target system will run at full speed until it encounters
4338 +your breakpoint or gets a segment violation in the kernel, or whatever.
4340 +If you have the kgdb console enabled when you continue, gdb will print
4341 +out all the console messages.
4343 +The above example caused a breakpoint relatively early in the boot
4344 +process. For the i386 kgdb it is possible to code a break instruction
4345 +as the first C-language point in init/main.c, i.e. as the first instruction
4346 +in start_kernel(). This could be done as follows:
4348 +#include <asm/kgdb.h>
4351 +This breakpoint() is really a function that sets up the breakpoint and
4352 +single-step hardware trap cells and then executes a breakpoint. Any
4353 +early hard coded breakpoint will need to use this function. Once the
4354 +trap cells are set up they need not be set again, but doing it again
4355 +does not hurt anything, so you don't need to be concerned about which
4356 +breakpoint is hit first. Once the trap cells are set up (and the kernel
4357 +sets them up in due course even if breakpoint() is never called) the
4362 +will generate an inline breakpoint. This may be more useful as it stops
4363 +the processor at the instruction instead of in a function a step removed
4364 +from the location of interest. In either case <asm/kgdb.h> must be
4365 +included to define both breakpoint() and BREAKPOINT.
4367 +Triggering kgdbstub at other times
4368 +==================================
4370 +Often you don't need to enter the debugger until much later in the boot
4371 +or even after the machine has been running for some time. Once the
4372 +kernel is booted and interrupts are on, you can force the system to
4373 +enter the debugger by sending a control-C to the debug port. This is
4374 +what the first line of the recommended .gdbinit file does. This allows
4375 +you to start gdb any time after the system is up as well as when the
4376 +system is already at a breakpoint. (In the case where the system is
4377 +already at a breakpoint the control-C is not needed, however, it will
4378 +be ignored by the target so no harm is done. Also note the the echo
4379 +command assumes that the port speed is already set. This will be true
4380 +once gdb has connected, but it is best to set the port speed before you
4383 +Another simple way to do this is to put the following file in you ~/bin
4387 +echo -e "\003" > /dev/ttyS0
4389 +Here, the ttyS0 should be replaced with what ever port you are using.
4390 +The "\003" is control-C. Once you are connected with gdb, you can enter
4391 +control-C at the command prompt.
4393 +An alternative way to get control to the debugger is to enable the kGdb
4394 +SysRq command. Then you would enter Alt-SysRq-g (all three keys at the
4395 +same time, but push them down in the order given). To refresh your
4396 +memory of the available SysRq commands try Alt-SysRq-=. Actually any
4397 +undefined command could replace the "=", but I like to KNOW that what I
4398 +am pushing will never be defined.
4403 +You can break into the target machine at any time from the development
4404 +machine by typing ^C (see above paragraph). If the target machine has
4405 +interrupts enabled this will stop it in the kernel and enter the
4408 +There is unfortunately no way of breaking into the kernel if it is
4409 +in a loop with interrupts disabled, so if this happens to you then
4410 +you need to place exploratory breakpoints or printk's into the kernel
4411 +to find out where it is looping. The exploratory breakpoints can be
4412 +entered either thru gdb or hard coded into the source. This is very
4413 +handy if you do something like:
4415 +if (<it hurts>) BREAKPOINT;
4418 +There is a copy of an e-mail in the Documentation/i386/kgdb/ directory
4419 +(debug-nmi.txt) which describes how to create an NMI on an ISA bus
4420 +machine using a paper clip. I have a sophisticated version of this made
4421 +by wiring a push button switch into a PC104/ISA bus adapter card. The
4422 +adapter card nicely furnishes wire wrap pins for all the ISA bus
4425 +When you are done debugging the kernel on the target machine it is a
4426 +good idea to leave it in a running state. This makes reboots faster,
4427 +bypassing the fsck. So do a gdb "continue" as the last gdb command if
4428 +this is possible. To terminate gdb itself on the development machine
4429 +and leave the target machine running, first clear all breakpoints and
4430 +continue, then type ^Z to suspend gdb and then kill it with "kill %1" or
4433 +If gdbstub Does Not Work
4434 +========================
4436 +If it doesn't work, you will have to troubleshoot it. Do the easy
4437 +things first like double checking your cabling and data rates. You
4438 +might try some non-kernel based programs to see if the back-to-back
4439 +connection works properly. Just something simple like cat /etc/hosts
4440 +>/dev/ttyS0 on one machine and cat /dev/ttyS0 on the other will tell you
4441 +if you can send data from one machine to the other. Make sure it works
4442 +in both directions. There is no point in tearing out your hair in the
4443 +kernel if the line doesn't work.
4445 +All of the real action takes place in the file
4446 +/usr/src/linux/arch/i386/kernel/kgdb_stub.c. That is the code on the target
4447 +machine that interacts with gdb on the development machine. In gdb you can
4448 +turn on a debug switch with the following command:
4452 +This will print out the protocol messages that gdb is exchanging with
4453 +the target machine.
4455 +Another place to look is /usr/src/arch/i386/lib/kgdb_serial.c. This is
4456 +the code that talks to the serial port on the target side. There might
4457 +be a problem there. In particular there is a section of this code that
4458 +tests the UART which will tell you what UART you have if you define
4459 +"PRNT" (just remove "_off" from the #define PRNT_off). To view this
4460 +report you will need to boot the system without any beakpoints. This
4461 +allows the kernel to run to the point where it calls kgdb to set up
4462 +interrupts. At this time kgdb will test the UART and print out the type
4463 +it finds. (You need to wait so that the printks are actually being
4464 +printed. Early in the boot they are cached, waiting for the console to
4465 +be enabled. Also, if kgdb is entered thru a breakpoint it is possible
4466 +to cause a dead lock by calling printk when the console is locked. The
4467 +stub thus avoids doing printks from breakpoints, especially in the
4468 +serial code.) At this time, if the UART fails to do the expected thing,
4469 +kgdb will print out (using printk) information on what failed. (These
4470 +messages will be buried in all the other boot up messages. Look for
4471 +lines that start with "gdb_hook_interrupt:". You may want to use dmesg
4472 +once the system is up to view the log. If this fails or if you still
4473 +don't connect, review your answers for the port address. Use:
4475 +setserial /dev/ttyS0
4477 +to get the current port and IRQ information. This command will also
4478 +tell you what the system found for the UART type. The stub recognizes
4479 +the following UART types:
4481 +16450, 16550, and 16550A
4483 +If you are really desperate you can use printk debugging in the
4484 +kgdbstub code in the target kernel until you get it working. In particular,
4485 +there is a global variable in /usr/src/linux/arch/i386/kernel/kgdb_stub.c
4486 +named "remote_debug". Compile your kernel with this set to 1, rather
4487 +than 0 and the debug stub will print out lots of stuff as it does
4488 +what it does. Likewise there are debug printks in the kgdb_serial.c
4489 +code that can be turned on with simple changes in the macro defines.
4492 +Debugging Loadable Modules
4493 +==========================
4495 +This technique comes courtesy of Edouard Parmelan
4496 +<Edouard.Parmelan@quadratec.fr>
4498 +When you run gdb, enter the command
4500 +source gdbinit-modules
4502 +This will read in a file of gdb macros that was installed in your
4503 +kernel source directory when kgdb was installed. This file implements
4504 +the following commands:
4507 + Lists the loaded modules in the form <module-address> <module-name>
4509 +mod-print-symbols <module-address>
4510 + Prints all the symbols in the indicated module.
4512 +mod-add-symbols <module-address> <object-file-path-name>
4513 + Loads the symbols from the object file and associates them
4514 + with the indicated module.
4516 +After you have loaded the module that you want to debug, use the command
4517 +mod-list to find the <module-address> of your module. Then use that
4518 +address in the mod-add-symbols command to load your module's symbols.
4519 +From that point onward you can debug your module as if it were a part
4522 +The file gdbinit-modules also contains a command named mod-add-lis as
4523 +an example of how to construct a command of your own to load your
4524 +favorite module. The idea is to "can" the pathname of the module
4525 +in the command so you don't have to type so much.
4530 +Each process in a target machine is seen as a gdb thread. gdb thread
4531 +related commands (info threads, thread n) can be used.
4533 +ia-32 hardware breakpoints
4534 +==========================
4536 +kgdb stub contains support for hardware breakpoints using debugging features
4537 +of ia-32(x86) processors. These breakpoints do not need code modification.
4538 +They use debugging registers. 4 hardware breakpoints are available in ia-32
4541 +Each hardware breakpoint can be of one of the following three types.
4543 +1. Execution breakpoint - An Execution breakpoint is triggered when code
4544 + at the breakpoint address is executed.
4546 + As limited number of hardware breakpoints are available, it is
4547 + advisable to use software breakpoints ( break command ) instead
4548 + of execution hardware breakpoints, unless modification of code
4551 +2. Write breakpoint - A write breakpoint is triggered when memory
4552 + location at the breakpoint address is written.
4554 + A write or can be placed for data of variable length. Length of
4555 + a write breakpoint indicates length of the datatype to be
4556 + watched. Length is 1 for 1 byte data , 2 for 2 byte data, 3 for
4559 +3. Access breakpoint - An access breakpoint is triggered when memory
4560 + location at the breakpoint address is either read or written.
4562 + Access breakpoints also have lengths similar to write breakpoints.
4564 +IO breakpoints in ia-32 are not supported.
4566 +Since gdb stub at present does not use the protocol used by gdb for hardware
4567 +breakpoints, hardware breakpoints are accessed through gdb macros. gdb macros
4568 +for hardware breakpoints are described below.
4570 +hwebrk - Places an execution breakpoint
4571 + hwebrk breakpointno address
4572 +hwwbrk - Places a write breakpoint
4573 + hwwbrk breakpointno length address
4574 +hwabrk - Places an access breakpoint
4575 + hwabrk breakpointno length address
4576 +hwrmbrk - Removes a breakpoint
4577 + hwrmbrk breakpointno
4578 +exinfo - Tells whether a software or hardware breakpoint has occurred.
4579 + Prints number of the hardware breakpoint if a hardware breakpoint has
4582 +Arguments required by these commands are as follows
4583 +breakpointno - 0 to 3
4585 +address - Memory location in hex digits ( without 0x ) e.g c015e9bc
4590 +When a breakpoint occurs or user issues a break ( Ctrl + C ) to gdb
4591 +client, all the processors are forced to enter the debugger. Current
4592 +thread corresponds to the thread running on the processor where
4593 +breakpoint occurred. Threads running on other processor(s) appear
4594 +similar to other non-running threads in the 'info threads' output.
4595 +Within the kgdb stub there is a structure "waiting_cpus" in which kgdb
4596 +records the values of "current" and "regs" for each CPU other than the
4597 +one that hit the breakpoint. "current" is a pointer to the task
4598 +structure for the task that CPU is running, while "regs" points to the
4599 +saved registers for the task. This structure can be examined with the
4602 +ia-32 hardware debugging registers on all processors are set to same
4603 +values. Hence any hardware breakpoints may occur on any processor.
4605 +gdb troubleshooting
4606 +===================
4609 +Kill it. restart gdb. Connect to target machine.
4611 +2. gdb cannot connect to target machine (after killing a gdb and
4612 +restarting another) If the target machine was not inside debugger when
4613 +you killed gdb, gdb cannot connect because the target machine won't
4614 +respond. In this case echo "Ctrl+C"(ASCII 3) to the serial line.
4615 +e.g. echo -e "\003" > /dev/ttyS1
4616 +This forces that target machine into the debugger, after which you
4619 +3. gdb cannot connect even after echoing Ctrl+C into serial line
4620 +Try changing serial line settings min to 1 and time to 0
4621 +e.g. stty min 1 time 0 < /dev/ttyS1
4624 +Check serial line speed and set it to correct value if required
4625 +e.g. stty ispeed 115200 ospeed 115200 < /dev/ttyS1
4630 +Ever want to know the order of things happening? Which CPU did what and
4631 +when? How did the spinlock get the way it is? Then events are for
4632 +you. Events are defined by calls to an event collection interface and
4633 +saved for later examination. In this case, kgdb events are saved by a
4634 +very fast bit of code in kgdb which is fully SMP and interrupt protected
4635 +and they are examined by using gdb to display them. Kgdb keeps only
4636 +the last N events, where N must be a power of two and is defined at
4640 +Events are signaled to kgdb by calling:
4642 +kgdb_ts(data0,data1)
4644 +For each call kgdb records each call in an array along with other info.
4645 +Here is the array definition:
4647 +struct kgdb_and_then_struct {
4651 + long long at_time;
4660 +For SMP machines the CPU is recorded, for all machines the TSC is
4661 +recorded (gets a time stamp) as well as the line number and source file
4662 +the call was made from. The address of the (from), the "if" (interrupt
4663 +flag) and the two data items are also recorded. The macro kgdb_ts casts
4664 +the types to int, so you can put any 32-bit values here. There is a
4665 +configure option to select the number of events you want to keep. A
4666 +nice number might be 128, but you can keep up to 1024 if you want. The
4667 +number must be a power of two. An "andthen" macro library is provided
4668 +for gdb to help you look at these events. It is also possible to define
4669 +a different structure for the event storage and cast the data to this
4670 +structure. For example the following structure is defined in kgdb:
4672 +struct kgdb_and_then_struct2 {
4676 + long long at_time;
4681 + struct task_struct *t1;
4682 + struct task_struct *t2;
4685 +If you use this for display, the data elements will be displayed as
4686 +pointers to task_struct entries. You may want to define your own
4687 +structure to use in casting. You should only change the last two items
4688 +and you must keep the structure size the same. Kgdb will handle these
4689 +as 32-bit ints, but within that constraint you can define a structure to
4690 +cast to any 32-bit quantity. This need only be available to gdb and is
4691 +only used for casting in the display code.
4696 +I picked up this code from Amit S. Kale and enhanced it.
4698 +If you make some really cool modification to this stuff, or if you
4699 +fix a bug, please let me know.
4702 +<george@mvista.com>
4705 +<akale@veritas.com>
4707 +(First kgdb by David Grothe <dave@gcom.com>)
4709 +(modified by Tigran Aivazian <tigran@sco.com>)
4710 + Putting gdbstub into the kernel config menu.
4712 +(modified by Scott Foehner <sfoehner@engr.sgi.com>)
4713 + Hooks for entering gdbstub at boot time.
4715 +(modified by Amit S. Kale <akale@veritas.com>)
4716 + Threads, ia-32 hw debugging, mp support, console support,
4717 + nmi watchdog handling.
4719 +(modified by George Anzinger <george@mvista.com>)
4720 + Extended threads to include the idle threads.
4721 + Enhancements to allow breakpoint() at first C code.
4722 + Use of module_init() and __setup() to automate the configure.
4723 + Enhanced the cpu "collection" code to work in early bring-up.
4724 + Added ability to call functions from gdb
4725 + Print info thread stuff without going back to schedule()
4726 + Now collect the "other" cpus with an IPI/ NMI.
4727 diff -puN /dev/null Documentation/i386/kgdb/loadmodule.sh
4728 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
4729 +++ 25-akpm/Documentation/i386/kgdb/loadmodule.sh 2004-10-21 14:54:15.325593648 -0700
4732 +# This script loads a module on a target machine and generates a gdb script.
4733 +# source generated gdb script to load the module file at appropriate addresses
4737 +# Loading the module on target machine and generating gdb script)
4738 +# [foo]$ loadmodule.sh <modulename>
4740 +# Loading the module file into gdb
4741 +# (gdb) source <gdbscriptpath>
4743 +# Modify following variables according to your setup.
4744 +# TESTMACHINE - Name of the target machine
4745 +# GDBSCRIPTS - The directory where a gdb script will be generated
4747 +# Author: Amit S. Kale (akale@veritas.com).
4749 +# If you run into problems, please check files pointed to by following
4751 +# ERRFILE - /tmp/<modulename>.errs contains stderr output of insmod
4752 +# MAPFILE - /tmp/<modulename>.map contains stdout output of insmod
4753 +# GDBSCRIPT - $GDBSCRIPTS/load<modulename> gdb script.
4756 +GDBSCRIPTS=/home/bar
4758 +if [ $# -lt 1 ] ; then {
4759 + echo Usage: $0 modulefile
4764 +MODULEFILEBASENAME=`basename $1`
4766 +if [ $MODULEFILE = $MODULEFILEBASENAME ] ; then {
4767 + MODULEFILE=`pwd`/$MODULEFILE
4770 +ERRFILE=/tmp/$MODULEFILEBASENAME.errs
4771 +MAPFILE=/tmp/$MODULEFILEBASENAME.map
4772 +GDBSCRIPT=$GDBSCRIPTS/load$MODULEFILEBASENAME
4774 +function findaddr() {
4775 + local ADDR=0x$(echo "$SEGMENTS" | \
4776 + grep "$1" | sed 's/^[^ ]*[ ]*[^ ]*[ ]*//' | \
4777 + sed 's/[ ]*[^ ]*$//')
4781 +function checkerrs() {
4782 + if [ "`cat $ERRFILE`" != "" ] ; then {
4789 +echo Copying $MODULEFILE to $TESTMACHINE
4790 +rcp $MODULEFILE root@${TESTMACHINE}:
4792 +echo Loading module $MODULEFILE
4793 +rsh -l root $TESTMACHINE /sbin/insmod -m ./`basename $MODULEFILE` \
4794 + > $MAPFILE 2> $ERRFILE
4797 +SEGMENTS=`head -n 11 $MAPFILE | tail -n 10`
4798 +TEXTADDR=$(findaddr "\\.text[^.]")
4799 +LOADSTRING="add-symbol-file $MODULEFILE $TEXTADDR"
4800 +SEGADDRS=`echo "$SEGMENTS" | awk '//{
4801 + if ($1 != ".text" && $1 != ".this" &&
4802 + $1 != ".kstrtab" && $1 != ".kmodtab") {
4803 + print " -s " $1 " 0x" $3 " "
4806 +LOADSTRING="$LOADSTRING $SEGADDRS"
4807 +echo Generating script $GDBSCRIPT
4808 +echo $LOADSTRING > $GDBSCRIPT
4809 diff -puN drivers/char/keyboard.c~kgdb-ga drivers/char/keyboard.c
4810 --- 25/drivers/char/keyboard.c~kgdb-ga 2004-10-21 14:54:15.273601552 -0700
4811 +++ 25-akpm/drivers/char/keyboard.c 2004-10-21 14:54:15.326593496 -0700
4812 @@ -1081,6 +1081,9 @@ void kbd_keycode(unsigned int keycode, i
4814 if (sysrq_down && down && !rep) {
4815 handle_sysrq(kbd_sysrq_xlate[keycode], regs, tty);
4816 +#ifdef CONFIG_KGDB_SYSRQ
4817 + sysrq_down = 0; /* in case we miss the "up" event */
4822 diff -puN drivers/char/sysrq.c~kgdb-ga drivers/char/sysrq.c
4823 --- 25/drivers/char/sysrq.c~kgdb-ga 2004-10-21 14:54:15.275601248 -0700
4824 +++ 25-akpm/drivers/char/sysrq.c 2004-10-21 14:54:15.326593496 -0700
4826 #include <linux/spinlock.h>
4828 #include <asm/ptrace.h>
4829 +#ifdef CONFIG_KGDB_SYSRQ
4831 +#define GDB_OP &kgdb_op
4832 +static void kgdb_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty)
4834 + printk("kgdb sysrq\n");
4838 +static struct sysrq_key_op kgdb_op = {
4839 + .handler = kgdb_sysrq,
4840 + .help_msg = "kGdb|Fgdb",
4841 + .action_msg = "Debug breakpoint\n",
4845 +#define GDB_OP NULL
4849 extern void reset_vc(unsigned int);
4851 @@ -238,8 +257,8 @@ static struct sysrq_key_op *sysrq_key_ta
4854 /* e */ &sysrq_term_op,
4860 /* i */ &sysrq_kill_op,
4862 diff -puN drivers/serial/8250.c~kgdb-ga drivers/serial/8250.c
4863 --- 25/drivers/serial/8250.c~kgdb-ga 2004-10-21 14:54:15.276601096 -0700
4864 +++ 25-akpm/drivers/serial/8250.c 2004-10-21 14:54:15.328593192 -0700
4865 @@ -983,7 +983,7 @@ receive_chars(struct uart_8250_port *up,
4866 if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
4867 tty->flip.work.func((void *)tty);
4868 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
4869 - return; // if TTY_DONT_FLIP is set
4870 + return; /* if TTY_DONT_FLIP is set */
4872 ch = serial_inp(up, UART_RX);
4873 *tty->flip.char_buf_ptr = ch;
4874 @@ -1348,12 +1348,21 @@ static void serial8250_break_ctl(struct
4875 spin_unlock_irqrestore(&up->port.lock, flags);
4879 +static int kgdb_irq = -1;
4882 static int serial8250_startup(struct uart_port *port)
4884 struct uart_8250_port *up = (struct uart_8250_port *)port;
4885 unsigned long flags;
4889 + if (up->port.irq == kgdb_irq)
4893 up->capabilities = uart_config[up->port.type].flags;
4896 @@ -1990,6 +1999,10 @@ serial8250_register_ports(struct uart_dr
4897 for (i = 0; i < UART_NR; i++) {
4898 struct uart_8250_port *up = &serial8250_ports[i];
4901 + if (up->port.irq == kgdb_irq)
4902 + up->port.kgdb = 1;
4905 up->port.ops = &serial8250_pops;
4907 @@ -2376,6 +2389,31 @@ void serial8250_unregister_port(int line
4909 EXPORT_SYMBOL(serial8250_unregister_port);
4913 + * Find all the ports using the given irq and shut them down.
4914 + * Result should be that the irq will be released.
4916 +void shutdown_for_kgdb(struct async_struct * info)
4918 + int irq = info->state->irq;
4919 + struct uart_8250_port *up;
4922 + kgdb_irq = irq; /* save for later init */
4923 + for (ttyS = 0; ttyS < UART_NR; ttyS++){
4924 + up = &serial8250_ports[ttyS];
4925 + if (up->port.irq == irq && (irq_lists + irq)->head) {
4926 +#ifdef CONFIG_DEBUG_SPINLOCK /* ugly business... */
4927 + if(up->port.lock.magic != SPINLOCK_MAGIC)
4928 + spin_lock_init(&up->port.lock);
4930 + serial8250_shutdown(&up->port);
4934 +#endif /* CONFIG_KGDB */
4936 static int __init serial8250_init(void)
4939 diff -puN drivers/serial/serial_core.c~kgdb-ga drivers/serial/serial_core.c
4940 --- 25/drivers/serial/serial_core.c~kgdb-ga 2004-10-21 14:54:15.278600792 -0700
4941 +++ 25-akpm/drivers/serial/serial_core.c 2004-10-21 14:54:15.330592888 -0700
4942 @@ -1976,6 +1976,11 @@ uart_configure_port(struct uart_driver *
4952 * If there isn't a port here, don't do anything further.
4954 diff -puN include/asm-i386/bugs.h~kgdb-ga include/asm-i386/bugs.h
4955 --- 25/include/asm-i386/bugs.h~kgdb-ga 2004-10-21 14:54:15.279600640 -0700
4956 +++ 25-akpm/include/asm-i386/bugs.h 2004-10-21 14:54:15.331592736 -0700
4959 * include/asm-i386/bugs.h
4961 - * Copyright (C) 1994 Linus Torvalds
4962 + * Copyright (C) 1994 Linus Torvalds
4964 * Cyrix stuff, June 1998 by:
4965 * - Rafael R. Reilova (moved everything from head.S),
4966 - * <rreilova@ececs.uc.edu>
4967 + * <rreilova@ececs.uc.edu>
4968 * - Channing Corn (tests & fixes),
4969 * - Andrew D. Balsa (code cleanup).
4972 #include <asm/processor.h>
4973 #include <asm/i387.h>
4974 #include <asm/msr.h>
4978 + * Provied the command line "gdb" initial break
4980 +int __init kgdb_initial_break(char * str)
4982 + if (*str == '\0'){
4988 +__setup("gdb",kgdb_initial_break);
4990 static int __init no_halt(char *s)
4992 boot_cpu_data.hlt_works_ok = 0;
4993 @@ -140,7 +153,7 @@ static void __init check_popad(void)
4995 /* If this fails, it means that any user program may lock the CPU hard. Too bad. */
4996 if (res != 12345678) printk( "Buggy.\n" );
4997 - else printk( "OK.\n" );
4998 + else printk( "OK.\n" );
5002 diff -puN /dev/null include/asm-i386/kgdb.h
5003 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
5004 +++ 25-akpm/include/asm-i386/kgdb.h 2004-10-21 14:54:15.331592736 -0700
5010 + * This file should not include ANY others. This makes it usable
5011 + * most anywhere without the fear of include order or inclusion.
5014 + * This file may be included all the time. It is only active if
5015 + * CONFIG_KGDB is defined, otherwise it stubs out all the macros
5016 + * and entry points.
5018 +#if defined(CONFIG_KGDB) && !defined(__ASSEMBLY__)
5020 +extern void breakpoint(void);
5021 +#define INIT_KGDB_INTS kgdb_enable_ints()
5024 +#define BREAKPOINT asm(" int $3")
5027 + * GDB debug stub (or any debug stub) can point the 'linux_debug_hook'
5028 + * pointer to its routine and it will be entered as the first thing
5029 + * when a trap occurs.
5031 + * Return values are, at present, undefined.
5033 + * The debug hook routine does not necessarily return to its caller.
5034 + * It has the register image and thus may choose to resume execution
5035 + * anywhere it pleases.
5039 +extern int kgdb_handle_exception(int trapno,
5040 + int signo, int err_code, struct pt_regs *regs);
5041 +extern int in_kgdb(struct pt_regs *regs);
5043 +#ifdef CONFIG_KGDB_TS
5044 +void kgdb_tstamp(int line, char *source, int data0, int data1);
5046 + * This is the time stamp function. The macro adds the source info and
5047 + * does a cast on the data to allow most any 32-bit value.
5050 +#define kgdb_ts(data0,data1) kgdb_tstamp(__LINE__,__FILE__,(int)data0,(int)data1)
5052 +#define kgdb_ts(data0,data1)
5054 +#else /* CONFIG_KGDB && ! __ASSEMBLY__ ,stubs follow... */
5058 +#define kgdb_ts(data0,data1)
5060 +#define kgdb_handle_exception
5062 +#define INIT_KGDB_INTS
5064 +#endif /* __KGDB */
5065 diff -puN /dev/null include/asm-i386/kgdb_local.h
5066 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
5067 +++ 25-akpm/include/asm-i386/kgdb_local.h 2004-10-21 14:54:15.332592584 -0700
5069 +#ifndef __KGDB_LOCAL
5070 +#define ___KGDB_LOCAL
5071 +#include <linux/config.h>
5072 +#include <linux/types.h>
5073 +#include <linux/serial.h>
5074 +#include <linux/serialP.h>
5075 +#include <linux/spinlock.h>
5076 +#include <asm/processor.h>
5077 +#include <asm/msr.h>
5078 +#include <asm/kgdb.h>
5081 +#ifdef CONFIG_KGDB_PORT
5083 +#define PORT CONFIG_KGDB_PORT
5086 +#ifdef CONFIG_KGDB_IRQ
5088 +#define IRQ CONFIG_KGDB_IRQ
5090 +#define SB_CLOCK 1843200
5091 +#define SB_BASE (SB_CLOCK/16)
5092 +#define SB_BAUD9600 SB_BASE/9600
5093 +#define SB_BAUD192 SB_BASE/19200
5094 +#define SB_BAUD384 SB_BASE/38400
5095 +#define SB_BAUD576 SB_BASE/57600
5096 +#define SB_BAUD1152 SB_BASE/115200
5097 +#ifdef CONFIG_KGDB_9600BAUD
5098 +#define SB_BAUD SB_BAUD9600
5100 +#ifdef CONFIG_KGDB_19200BAUD
5101 +#define SB_BAUD SB_BAUD192
5103 +#ifdef CONFIG_KGDB_38400BAUD
5104 +#define SB_BAUD SB_BAUD384
5106 +#ifdef CONFIG_KGDB_57600BAUD
5107 +#define SB_BAUD SB_BAUD576
5109 +#ifdef CONFIG_KGDB_115200BAUD
5110 +#define SB_BAUD SB_BAUD1152
5113 +#define SB_BAUD SB_BAUD1152 /* Start with this if not given */
5116 +#ifndef CONFIG_X86_TSC
5118 +#define rdtsc(a,b) if (a++ > 10000){a = 0; b++;}
5120 +#define rdtscll(s) s++
5123 +#ifdef _raw_read_unlock /* must use a name that is "define"ed, not an inline */
5125 +#undef spin_trylock
5127 +#define spin_lock _raw_spin_lock
5128 +#define spin_trylock _raw_spin_trylock
5129 +#define spin_unlock _raw_spin_unlock
5132 +#undef spin_unlock_wait
5133 +#define spin_unlock_wait(x) do { cpu_relax(); barrier();} \
5134 + while(spin_is_locked(x))
5137 +#define SB_MCR UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS
5140 +#define SB_STATE { \
5141 + magic: SSTATE_MAGIC, \
5142 + baud_base: SB_BASE, \
5146 + custom_divisor:SB_BAUD}
5147 +#define SB_INFO { \
5148 + magic: SERIAL_MAGIC, \
5149 + port: PORT,0,FLAGS, \
5151 + tty: (struct tty_struct *)&state, \
5154 +extern void putDebugChar(int);
5155 +/* RTAI support needs us to really stop/start interrupts */
5157 +#define kgdb_sti() __asm__ __volatile__("sti": : :"memory")
5158 +#define kgdb_cli() __asm__ __volatile__("cli": : :"memory")
5159 +#define kgdb_local_save_flags(x) __asm__ __volatile__(\
5160 + "pushfl ; popl %0":"=g" (x): /* no input */)
5161 +#define kgdb_local_irq_restore(x) __asm__ __volatile__(\
5162 + "pushl %0 ; popfl": \
5163 + /* no output */ :"g" (x):"memory", "cc")
5164 +#define kgdb_local_irq_save(x) kgdb_local_save_flags(x); kgdb_cli()
5166 +#ifdef CONFIG_SERIAL
5167 +extern void shutdown_for_kgdb(struct async_struct *info);
5169 +#define INIT_KDEBUG putDebugChar("+");
5170 +#endif /* __KGDB_LOCAL */
5171 diff -puN include/linux/config.h~kgdb-ga include/linux/config.h
5172 --- 25/include/linux/config.h~kgdb-ga 2004-10-21 14:54:15.281600336 -0700
5173 +++ 25-akpm/include/linux/config.h 2004-10-21 14:54:15.332592584 -0700
5175 #define _LINUX_CONFIG_H
5177 #include <linux/autoconf.h>
5178 +#if defined(__i386__) && !defined(IN_BOOTLOADER)
5179 +#include <asm/kgdb.h>
5181 #if !defined (__KERNEL__) && !defined(__KERNGLUE__)
5182 #error including kernel header in userspace; use the glibc headers instead!
5184 diff -puN /dev/null include/linux/dwarf2.h
5185 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
5186 +++ 25-akpm/include/linux/dwarf2.h 2004-10-21 14:54:15.336591976 -0700
5188 +/* Declarations and definitions of codes relating to the DWARF2 symbolic
5189 + debugging information format.
5190 + Copyright (C) 1992, 1993, 1995, 1996, 1997, 1999, 2000, 2001, 2002
5191 + Free Software Foundation, Inc.
5193 + Written by Gary Funck (gary@intrepid.com) The Ada Joint Program
5194 + Office (AJPO), Florida State Unviversity and Silicon Graphics Inc.
5195 + provided support for this effort -- June 21, 1995.
5197 + Derived from the DWARF 1 implementation written by Ron Guilmette
5198 + (rfg@netcom.com), November 1990.
5200 + This file is part of GCC.
5202 + GCC is free software; you can redistribute it and/or modify it under
5203 + the terms of the GNU General Public License as published by the Free
5204 + Software Foundation; either version 2, or (at your option) any later
5207 + GCC is distributed in the hope that it will be useful, but WITHOUT
5208 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
5209 + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
5210 + License for more details.
5212 + You should have received a copy of the GNU General Public License
5213 + along with GCC; see the file COPYING. If not, write to the Free
5214 + Software Foundation, 59 Temple Place - Suite 330, Boston, MA
5215 + 02111-1307, USA. */
5217 +/* This file is derived from the DWARF specification (a public document)
5218 + Revision 2.0.0 (July 27, 1993) developed by the UNIX International
5219 + Programming Languages Special Interest Group (UI/PLSIG) and distributed
5220 + by UNIX International. Copies of this specification are available from
5221 + UNIX International, 20 Waterview Boulevard, Parsippany, NJ, 07054.
5223 + This file also now contains definitions from the DWARF 3 specification. */
5225 +/* This file is shared between GCC and GDB, and should not contain
5228 +#ifndef _ELF_DWARF2_H
5229 +#define _ELF_DWARF2_H
5231 +/* Structure found in the .debug_line section. */
5232 +#ifndef __ASSEMBLY__
5235 + unsigned char li_length [4];
5236 + unsigned char li_version [2];
5237 + unsigned char li_prologue_length [4];
5238 + unsigned char li_min_insn_length [1];
5239 + unsigned char li_default_is_stmt [1];
5240 + unsigned char li_line_base [1];
5241 + unsigned char li_line_range [1];
5242 + unsigned char li_opcode_base [1];
5244 +DWARF2_External_LineInfo;
5248 + unsigned long li_length;
5249 + unsigned short li_version;
5250 + unsigned int li_prologue_length;
5251 + unsigned char li_min_insn_length;
5252 + unsigned char li_default_is_stmt;
5254 + unsigned char li_line_range;
5255 + unsigned char li_opcode_base;
5257 +DWARF2_Internal_LineInfo;
5259 +/* Structure found in .debug_pubnames section. */
5262 + unsigned char pn_length [4];
5263 + unsigned char pn_version [2];
5264 + unsigned char pn_offset [4];
5265 + unsigned char pn_size [4];
5267 +DWARF2_External_PubNames;
5271 + unsigned long pn_length;
5272 + unsigned short pn_version;
5273 + unsigned long pn_offset;
5274 + unsigned long pn_size;
5276 +DWARF2_Internal_PubNames;
5278 +/* Structure found in .debug_info section. */
5281 + unsigned char cu_length [4];
5282 + unsigned char cu_version [2];
5283 + unsigned char cu_abbrev_offset [4];
5284 + unsigned char cu_pointer_size [1];
5286 +DWARF2_External_CompUnit;
5290 + unsigned long cu_length;
5291 + unsigned short cu_version;
5292 + unsigned long cu_abbrev_offset;
5293 + unsigned char cu_pointer_size;
5295 +DWARF2_Internal_CompUnit;
5299 + unsigned char ar_length [4];
5300 + unsigned char ar_version [2];
5301 + unsigned char ar_info_offset [4];
5302 + unsigned char ar_pointer_size [1];
5303 + unsigned char ar_segment_size [1];
5305 +DWARF2_External_ARange;
5309 + unsigned long ar_length;
5310 + unsigned short ar_version;
5311 + unsigned long ar_info_offset;
5312 + unsigned char ar_pointer_size;
5313 + unsigned char ar_segment_size;
5315 +DWARF2_Internal_ARange;
5317 +#define ENUM(name) enum name {
5318 +#define IF_NOT_ASM(a) a
5322 +#define IF_NOT_ASM(a)
5327 +/* Tag names and codes. */
5330 + DW_TAG_padding = 0x00 COMMA
5331 + DW_TAG_array_type = 0x01 COMMA
5332 + DW_TAG_class_type = 0x02 COMMA
5333 + DW_TAG_entry_point = 0x03 COMMA
5334 + DW_TAG_enumeration_type = 0x04 COMMA
5335 + DW_TAG_formal_parameter = 0x05 COMMA
5336 + DW_TAG_imported_declaration = 0x08 COMMA
5337 + DW_TAG_label = 0x0a COMMA
5338 + DW_TAG_lexical_block = 0x0b COMMA
5339 + DW_TAG_member = 0x0d COMMA
5340 + DW_TAG_pointer_type = 0x0f COMMA
5341 + DW_TAG_reference_type = 0x10 COMMA
5342 + DW_TAG_compile_unit = 0x11 COMMA
5343 + DW_TAG_string_type = 0x12 COMMA
5344 + DW_TAG_structure_type = 0x13 COMMA
5345 + DW_TAG_subroutine_type = 0x15 COMMA
5346 + DW_TAG_typedef = 0x16 COMMA
5347 + DW_TAG_union_type = 0x17 COMMA
5348 + DW_TAG_unspecified_parameters = 0x18 COMMA
5349 + DW_TAG_variant = 0x19 COMMA
5350 + DW_TAG_common_block = 0x1a COMMA
5351 + DW_TAG_common_inclusion = 0x1b COMMA
5352 + DW_TAG_inheritance = 0x1c COMMA
5353 + DW_TAG_inlined_subroutine = 0x1d COMMA
5354 + DW_TAG_module = 0x1e COMMA
5355 + DW_TAG_ptr_to_member_type = 0x1f COMMA
5356 + DW_TAG_set_type = 0x20 COMMA
5357 + DW_TAG_subrange_type = 0x21 COMMA
5358 + DW_TAG_with_stmt = 0x22 COMMA
5359 + DW_TAG_access_declaration = 0x23 COMMA
5360 + DW_TAG_base_type = 0x24 COMMA
5361 + DW_TAG_catch_block = 0x25 COMMA
5362 + DW_TAG_const_type = 0x26 COMMA
5363 + DW_TAG_constant = 0x27 COMMA
5364 + DW_TAG_enumerator = 0x28 COMMA
5365 + DW_TAG_file_type = 0x29 COMMA
5366 + DW_TAG_friend = 0x2a COMMA
5367 + DW_TAG_namelist = 0x2b COMMA
5368 + DW_TAG_namelist_item = 0x2c COMMA
5369 + DW_TAG_packed_type = 0x2d COMMA
5370 + DW_TAG_subprogram = 0x2e COMMA
5371 + DW_TAG_template_type_param = 0x2f COMMA
5372 + DW_TAG_template_value_param = 0x30 COMMA
5373 + DW_TAG_thrown_type = 0x31 COMMA
5374 + DW_TAG_try_block = 0x32 COMMA
5375 + DW_TAG_variant_part = 0x33 COMMA
5376 + DW_TAG_variable = 0x34 COMMA
5377 + DW_TAG_volatile_type = 0x35 COMMA
5379 + DW_TAG_dwarf_procedure = 0x36 COMMA
5380 + DW_TAG_restrict_type = 0x37 COMMA
5381 + DW_TAG_interface_type = 0x38 COMMA
5382 + DW_TAG_namespace = 0x39 COMMA
5383 + DW_TAG_imported_module = 0x3a COMMA
5384 + DW_TAG_unspecified_type = 0x3b COMMA
5385 + DW_TAG_partial_unit = 0x3c COMMA
5386 + DW_TAG_imported_unit = 0x3d COMMA
5387 + /* SGI/MIPS Extensions. */
5388 + DW_TAG_MIPS_loop = 0x4081 COMMA
5389 + /* GNU extensions. */
5390 + DW_TAG_format_label = 0x4101 COMMA /* For FORTRAN 77 and Fortran 90. */
5391 + DW_TAG_function_template = 0x4102 COMMA /* For C++. */
5392 + DW_TAG_class_template = 0x4103 COMMA /* For C++. */
5393 + DW_TAG_GNU_BINCL = 0x4104 COMMA
5394 + DW_TAG_GNU_EINCL = 0x4105 COMMA
5395 + /* Extensions for UPC. See: http://upc.gwu.edu/~upc. */
5396 + DW_TAG_upc_shared_type = 0x8765 COMMA
5397 + DW_TAG_upc_strict_type = 0x8766 COMMA
5398 + DW_TAG_upc_relaxed_type = 0x8767
5401 +#define DW_TAG_lo_user 0x4080
5402 +#define DW_TAG_hi_user 0xffff
5404 +/* Flag that tells whether entry has a child or not. */
5405 +#define DW_children_no 0
5406 +#define DW_children_yes 1
5408 +/* Form names and codes. */
5411 + DW_FORM_addr = 0x01 COMMA
5412 + DW_FORM_block2 = 0x03 COMMA
5413 + DW_FORM_block4 = 0x04 COMMA
5414 + DW_FORM_data2 = 0x05 COMMA
5415 + DW_FORM_data4 = 0x06 COMMA
5416 + DW_FORM_data8 = 0x07 COMMA
5417 + DW_FORM_string = 0x08 COMMA
5418 + DW_FORM_block = 0x09 COMMA
5419 + DW_FORM_block1 = 0x0a COMMA
5420 + DW_FORM_data1 = 0x0b COMMA
5421 + DW_FORM_flag = 0x0c COMMA
5422 + DW_FORM_sdata = 0x0d COMMA
5423 + DW_FORM_strp = 0x0e COMMA
5424 + DW_FORM_udata = 0x0f COMMA
5425 + DW_FORM_ref_addr = 0x10 COMMA
5426 + DW_FORM_ref1 = 0x11 COMMA
5427 + DW_FORM_ref2 = 0x12 COMMA
5428 + DW_FORM_ref4 = 0x13 COMMA
5429 + DW_FORM_ref8 = 0x14 COMMA
5430 + DW_FORM_ref_udata = 0x15 COMMA
5431 + DW_FORM_indirect = 0x16
5434 +/* Attribute names and codes. */
5436 +ENUM(dwarf_attribute)
5438 + DW_AT_sibling = 0x01 COMMA
5439 + DW_AT_location = 0x02 COMMA
5440 + DW_AT_name = 0x03 COMMA
5441 + DW_AT_ordering = 0x09 COMMA
5442 + DW_AT_subscr_data = 0x0a COMMA
5443 + DW_AT_byte_size = 0x0b COMMA
5444 + DW_AT_bit_offset = 0x0c COMMA
5445 + DW_AT_bit_size = 0x0d COMMA
5446 + DW_AT_element_list = 0x0f COMMA
5447 + DW_AT_stmt_list = 0x10 COMMA
5448 + DW_AT_low_pc = 0x11 COMMA
5449 + DW_AT_high_pc = 0x12 COMMA
5450 + DW_AT_language = 0x13 COMMA
5451 + DW_AT_member = 0x14 COMMA
5452 + DW_AT_discr = 0x15 COMMA
5453 + DW_AT_discr_value = 0x16 COMMA
5454 + DW_AT_visibility = 0x17 COMMA
5455 + DW_AT_import = 0x18 COMMA
5456 + DW_AT_string_length = 0x19 COMMA
5457 + DW_AT_common_reference = 0x1a COMMA
5458 + DW_AT_comp_dir = 0x1b COMMA
5459 + DW_AT_const_value = 0x1c COMMA
5460 + DW_AT_containing_type = 0x1d COMMA
5461 + DW_AT_default_value = 0x1e COMMA
5462 + DW_AT_inline = 0x20 COMMA
5463 + DW_AT_is_optional = 0x21 COMMA
5464 + DW_AT_lower_bound = 0x22 COMMA
5465 + DW_AT_producer = 0x25 COMMA
5466 + DW_AT_prototyped = 0x27 COMMA
5467 + DW_AT_return_addr = 0x2a COMMA
5468 + DW_AT_start_scope = 0x2c COMMA
5469 + DW_AT_stride_size = 0x2e COMMA
5470 + DW_AT_upper_bound = 0x2f COMMA
5471 + DW_AT_abstract_origin = 0x31 COMMA
5472 + DW_AT_accessibility = 0x32 COMMA
5473 + DW_AT_address_class = 0x33 COMMA
5474 + DW_AT_artificial = 0x34 COMMA
5475 + DW_AT_base_types = 0x35 COMMA
5476 + DW_AT_calling_convention = 0x36 COMMA
5477 + DW_AT_count = 0x37 COMMA
5478 + DW_AT_data_member_location = 0x38 COMMA
5479 + DW_AT_decl_column = 0x39 COMMA
5480 + DW_AT_decl_file = 0x3a COMMA
5481 + DW_AT_decl_line = 0x3b COMMA
5482 + DW_AT_declaration = 0x3c COMMA
5483 + DW_AT_discr_list = 0x3d COMMA
5484 + DW_AT_encoding = 0x3e COMMA
5485 + DW_AT_external = 0x3f COMMA
5486 + DW_AT_frame_base = 0x40 COMMA
5487 + DW_AT_friend = 0x41 COMMA
5488 + DW_AT_identifier_case = 0x42 COMMA
5489 + DW_AT_macro_info = 0x43 COMMA
5490 + DW_AT_namelist_items = 0x44 COMMA
5491 + DW_AT_priority = 0x45 COMMA
5492 + DW_AT_segment = 0x46 COMMA
5493 + DW_AT_specification = 0x47 COMMA
5494 + DW_AT_static_link = 0x48 COMMA
5495 + DW_AT_type = 0x49 COMMA
5496 + DW_AT_use_location = 0x4a COMMA
5497 + DW_AT_variable_parameter = 0x4b COMMA
5498 + DW_AT_virtuality = 0x4c COMMA
5499 + DW_AT_vtable_elem_location = 0x4d COMMA
5500 + /* DWARF 3 values. */
5501 + DW_AT_allocated = 0x4e COMMA
5502 + DW_AT_associated = 0x4f COMMA
5503 + DW_AT_data_location = 0x50 COMMA
5504 + DW_AT_stride = 0x51 COMMA
5505 + DW_AT_entry_pc = 0x52 COMMA
5506 + DW_AT_use_UTF8 = 0x53 COMMA
5507 + DW_AT_extension = 0x54 COMMA
5508 + DW_AT_ranges = 0x55 COMMA
5509 + DW_AT_trampoline = 0x56 COMMA
5510 + DW_AT_call_column = 0x57 COMMA
5511 + DW_AT_call_file = 0x58 COMMA
5512 + DW_AT_call_line = 0x59 COMMA
5513 + /* SGI/MIPS extensions. */
5514 + DW_AT_MIPS_fde = 0x2001 COMMA
5515 + DW_AT_MIPS_loop_begin = 0x2002 COMMA
5516 + DW_AT_MIPS_tail_loop_begin = 0x2003 COMMA
5517 + DW_AT_MIPS_epilog_begin = 0x2004 COMMA
5518 + DW_AT_MIPS_loop_unroll_factor = 0x2005 COMMA
5519 + DW_AT_MIPS_software_pipeline_depth = 0x2006 COMMA
5520 + DW_AT_MIPS_linkage_name = 0x2007 COMMA
5521 + DW_AT_MIPS_stride = 0x2008 COMMA
5522 + DW_AT_MIPS_abstract_name = 0x2009 COMMA
5523 + DW_AT_MIPS_clone_origin = 0x200a COMMA
5524 + DW_AT_MIPS_has_inlines = 0x200b COMMA
5525 + /* GNU extensions. */
5526 + DW_AT_sf_names = 0x2101 COMMA
5527 + DW_AT_src_info = 0x2102 COMMA
5528 + DW_AT_mac_info = 0x2103 COMMA
5529 + DW_AT_src_coords = 0x2104 COMMA
5530 + DW_AT_body_begin = 0x2105 COMMA
5531 + DW_AT_body_end = 0x2106 COMMA
5532 + DW_AT_GNU_vector = 0x2107 COMMA
5533 + /* VMS extensions. */
5534 + DW_AT_VMS_rtnbeg_pd_address = 0x2201 COMMA
5535 + /* UPC extension. */
5536 + DW_AT_upc_threads_scaled = 0x3210
5539 +#define DW_AT_lo_user 0x2000 /* Implementation-defined range start. */
5540 +#define DW_AT_hi_user 0x3ff0 /* Implementation-defined range end. */
5542 +/* Location atom names and codes. */
5543 +ENUM(dwarf_location_atom)
5545 + DW_OP_addr = 0x03 COMMA
5546 + DW_OP_deref = 0x06 COMMA
5547 + DW_OP_const1u = 0x08 COMMA
5548 + DW_OP_const1s = 0x09 COMMA
5549 + DW_OP_const2u = 0x0a COMMA
5550 + DW_OP_const2s = 0x0b COMMA
5551 + DW_OP_const4u = 0x0c COMMA
5552 + DW_OP_const4s = 0x0d COMMA
5553 + DW_OP_const8u = 0x0e COMMA
5554 + DW_OP_const8s = 0x0f COMMA
5555 + DW_OP_constu = 0x10 COMMA
5556 + DW_OP_consts = 0x11 COMMA
5557 + DW_OP_dup = 0x12 COMMA
5558 + DW_OP_drop = 0x13 COMMA
5559 + DW_OP_over = 0x14 COMMA
5560 + DW_OP_pick = 0x15 COMMA
5561 + DW_OP_swap = 0x16 COMMA
5562 + DW_OP_rot = 0x17 COMMA
5563 + DW_OP_xderef = 0x18 COMMA
5564 + DW_OP_abs = 0x19 COMMA
5565 + DW_OP_and = 0x1a COMMA
5566 + DW_OP_div = 0x1b COMMA
5567 + DW_OP_minus = 0x1c COMMA
5568 + DW_OP_mod = 0x1d COMMA
5569 + DW_OP_mul = 0x1e COMMA
5570 + DW_OP_neg = 0x1f COMMA
5571 + DW_OP_not = 0x20 COMMA
5572 + DW_OP_or = 0x21 COMMA
5573 + DW_OP_plus = 0x22 COMMA
5574 + DW_OP_plus_uconst = 0x23 COMMA
5575 + DW_OP_shl = 0x24 COMMA
5576 + DW_OP_shr = 0x25 COMMA
5577 + DW_OP_shra = 0x26 COMMA
5578 + DW_OP_xor = 0x27 COMMA
5579 + DW_OP_bra = 0x28 COMMA
5580 + DW_OP_eq = 0x29 COMMA
5581 + DW_OP_ge = 0x2a COMMA
5582 + DW_OP_gt = 0x2b COMMA
5583 + DW_OP_le = 0x2c COMMA
5584 + DW_OP_lt = 0x2d COMMA
5585 + DW_OP_ne = 0x2e COMMA
5586 + DW_OP_skip = 0x2f COMMA
5587 + DW_OP_lit0 = 0x30 COMMA
5588 + DW_OP_lit1 = 0x31 COMMA
5589 + DW_OP_lit2 = 0x32 COMMA
5590 + DW_OP_lit3 = 0x33 COMMA
5591 + DW_OP_lit4 = 0x34 COMMA
5592 + DW_OP_lit5 = 0x35 COMMA
5593 + DW_OP_lit6 = 0x36 COMMA
5594 + DW_OP_lit7 = 0x37 COMMA
5595 + DW_OP_lit8 = 0x38 COMMA
5596 + DW_OP_lit9 = 0x39 COMMA
5597 + DW_OP_lit10 = 0x3a COMMA
5598 + DW_OP_lit11 = 0x3b COMMA
5599 + DW_OP_lit12 = 0x3c COMMA
5600 + DW_OP_lit13 = 0x3d COMMA
5601 + DW_OP_lit14 = 0x3e COMMA
5602 + DW_OP_lit15 = 0x3f COMMA
5603 + DW_OP_lit16 = 0x40 COMMA
5604 + DW_OP_lit17 = 0x41 COMMA
5605 + DW_OP_lit18 = 0x42 COMMA
5606 + DW_OP_lit19 = 0x43 COMMA
5607 + DW_OP_lit20 = 0x44 COMMA
5608 + DW_OP_lit21 = 0x45 COMMA
5609 + DW_OP_lit22 = 0x46 COMMA
5610 + DW_OP_lit23 = 0x47 COMMA
5611 + DW_OP_lit24 = 0x48 COMMA
5612 + DW_OP_lit25 = 0x49 COMMA
5613 + DW_OP_lit26 = 0x4a COMMA
5614 + DW_OP_lit27 = 0x4b COMMA
5615 + DW_OP_lit28 = 0x4c COMMA
5616 + DW_OP_lit29 = 0x4d COMMA
5617 + DW_OP_lit30 = 0x4e COMMA
5618 + DW_OP_lit31 = 0x4f COMMA
5619 + DW_OP_reg0 = 0x50 COMMA
5620 + DW_OP_reg1 = 0x51 COMMA
5621 + DW_OP_reg2 = 0x52 COMMA
5622 + DW_OP_reg3 = 0x53 COMMA
5623 + DW_OP_reg4 = 0x54 COMMA
5624 + DW_OP_reg5 = 0x55 COMMA
5625 + DW_OP_reg6 = 0x56 COMMA
5626 + DW_OP_reg7 = 0x57 COMMA
5627 + DW_OP_reg8 = 0x58 COMMA
5628 + DW_OP_reg9 = 0x59 COMMA
5629 + DW_OP_reg10 = 0x5a COMMA
5630 + DW_OP_reg11 = 0x5b COMMA
5631 + DW_OP_reg12 = 0x5c COMMA
5632 + DW_OP_reg13 = 0x5d COMMA
5633 + DW_OP_reg14 = 0x5e COMMA
5634 + DW_OP_reg15 = 0x5f COMMA
5635 + DW_OP_reg16 = 0x60 COMMA
5636 + DW_OP_reg17 = 0x61 COMMA
5637 + DW_OP_reg18 = 0x62 COMMA
5638 + DW_OP_reg19 = 0x63 COMMA
5639 + DW_OP_reg20 = 0x64 COMMA
5640 + DW_OP_reg21 = 0x65 COMMA
5641 + DW_OP_reg22 = 0x66 COMMA
5642 + DW_OP_reg23 = 0x67 COMMA
5643 + DW_OP_reg24 = 0x68 COMMA
5644 + DW_OP_reg25 = 0x69 COMMA
5645 + DW_OP_reg26 = 0x6a COMMA
5646 + DW_OP_reg27 = 0x6b COMMA
5647 + DW_OP_reg28 = 0x6c COMMA
5648 + DW_OP_reg29 = 0x6d COMMA
5649 + DW_OP_reg30 = 0x6e COMMA
5650 + DW_OP_reg31 = 0x6f COMMA
5651 + DW_OP_breg0 = 0x70 COMMA
5652 + DW_OP_breg1 = 0x71 COMMA
5653 + DW_OP_breg2 = 0x72 COMMA
5654 + DW_OP_breg3 = 0x73 COMMA
5655 + DW_OP_breg4 = 0x74 COMMA
5656 + DW_OP_breg5 = 0x75 COMMA
5657 + DW_OP_breg6 = 0x76 COMMA
5658 + DW_OP_breg7 = 0x77 COMMA
5659 + DW_OP_breg8 = 0x78 COMMA
5660 + DW_OP_breg9 = 0x79 COMMA
5661 + DW_OP_breg10 = 0x7a COMMA
5662 + DW_OP_breg11 = 0x7b COMMA
5663 + DW_OP_breg12 = 0x7c COMMA
5664 + DW_OP_breg13 = 0x7d COMMA
5665 + DW_OP_breg14 = 0x7e COMMA
5666 + DW_OP_breg15 = 0x7f COMMA
5667 + DW_OP_breg16 = 0x80 COMMA
5668 + DW_OP_breg17 = 0x81 COMMA
5669 + DW_OP_breg18 = 0x82 COMMA
5670 + DW_OP_breg19 = 0x83 COMMA
5671 + DW_OP_breg20 = 0x84 COMMA
5672 + DW_OP_breg21 = 0x85 COMMA
5673 + DW_OP_breg22 = 0x86 COMMA
5674 + DW_OP_breg23 = 0x87 COMMA
5675 + DW_OP_breg24 = 0x88 COMMA
5676 + DW_OP_breg25 = 0x89 COMMA
5677 + DW_OP_breg26 = 0x8a COMMA
5678 + DW_OP_breg27 = 0x8b COMMA
5679 + DW_OP_breg28 = 0x8c COMMA
5680 + DW_OP_breg29 = 0x8d COMMA
5681 + DW_OP_breg30 = 0x8e COMMA
5682 + DW_OP_breg31 = 0x8f COMMA
5683 + DW_OP_regx = 0x90 COMMA
5684 + DW_OP_fbreg = 0x91 COMMA
5685 + DW_OP_bregx = 0x92 COMMA
5686 + DW_OP_piece = 0x93 COMMA
5687 + DW_OP_deref_size = 0x94 COMMA
5688 + DW_OP_xderef_size = 0x95 COMMA
5689 + DW_OP_nop = 0x96 COMMA
5690 + /* DWARF 3 extensions. */
5691 + DW_OP_push_object_address = 0x97 COMMA
5692 + DW_OP_call2 = 0x98 COMMA
5693 + DW_OP_call4 = 0x99 COMMA
5694 + DW_OP_call_ref = 0x9a COMMA
5695 + /* GNU extensions. */
5696 + DW_OP_GNU_push_tls_address = 0xe0
5699 +#define DW_OP_lo_user 0xe0 /* Implementation-defined range start. */
5700 +#define DW_OP_hi_user 0xff /* Implementation-defined range end. */
5702 +/* Type encodings. */
5705 + DW_ATE_void = 0x0 COMMA
5706 + DW_ATE_address = 0x1 COMMA
5707 + DW_ATE_boolean = 0x2 COMMA
5708 + DW_ATE_complex_float = 0x3 COMMA
5709 + DW_ATE_float = 0x4 COMMA
5710 + DW_ATE_signed = 0x5 COMMA
5711 + DW_ATE_signed_char = 0x6 COMMA
5712 + DW_ATE_unsigned = 0x7 COMMA
5713 + DW_ATE_unsigned_char = 0x8 COMMA
5715 + DW_ATE_imaginary_float = 0x9
5718 +#define DW_ATE_lo_user 0x80
5719 +#define DW_ATE_hi_user 0xff
5721 +/* Array ordering names and codes. */
5722 +ENUM(dwarf_array_dim_ordering)
5724 + DW_ORD_row_major = 0 COMMA
5725 + DW_ORD_col_major = 1
5728 +/* Access attribute. */
5729 +ENUM(dwarf_access_attribute)
5731 + DW_ACCESS_public = 1 COMMA
5732 + DW_ACCESS_protected = 2 COMMA
5733 + DW_ACCESS_private = 3
5737 +ENUM(dwarf_visibility_attribute)
5739 + DW_VIS_local = 1 COMMA
5740 + DW_VIS_exported = 2 COMMA
5741 + DW_VIS_qualified = 3
5745 +ENUM(dwarf_virtuality_attribute)
5747 + DW_VIRTUALITY_none = 0 COMMA
5748 + DW_VIRTUALITY_virtual = 1 COMMA
5749 + DW_VIRTUALITY_pure_virtual = 2
5752 +/* Case sensitivity. */
5753 +ENUM(dwarf_id_case)
5755 + DW_ID_case_sensitive = 0 COMMA
5756 + DW_ID_up_case = 1 COMMA
5757 + DW_ID_down_case = 2 COMMA
5758 + DW_ID_case_insensitive = 3
5761 +/* Calling convention. */
5762 +ENUM(dwarf_calling_convention)
5764 + DW_CC_normal = 0x1 COMMA
5765 + DW_CC_program = 0x2 COMMA
5766 + DW_CC_nocall = 0x3
5769 +#define DW_CC_lo_user 0x40
5770 +#define DW_CC_hi_user 0xff
5772 +/* Inline attribute. */
5773 +ENUM(dwarf_inline_attribute)
5775 + DW_INL_not_inlined = 0 COMMA
5776 + DW_INL_inlined = 1 COMMA
5777 + DW_INL_declared_not_inlined = 2 COMMA
5778 + DW_INL_declared_inlined = 3
5781 +/* Discriminant lists. */
5782 +ENUM(dwarf_discrim_list)
5784 + DW_DSC_label = 0 COMMA
5788 +/* Line number opcodes. */
5789 +ENUM(dwarf_line_number_ops)
5791 + DW_LNS_extended_op = 0 COMMA
5792 + DW_LNS_copy = 1 COMMA
5793 + DW_LNS_advance_pc = 2 COMMA
5794 + DW_LNS_advance_line = 3 COMMA
5795 + DW_LNS_set_file = 4 COMMA
5796 + DW_LNS_set_column = 5 COMMA
5797 + DW_LNS_negate_stmt = 6 COMMA
5798 + DW_LNS_set_basic_block = 7 COMMA
5799 + DW_LNS_const_add_pc = 8 COMMA
5800 + DW_LNS_fixed_advance_pc = 9 COMMA
5802 + DW_LNS_set_prologue_end = 10 COMMA
5803 + DW_LNS_set_epilogue_begin = 11 COMMA
5804 + DW_LNS_set_isa = 12
5807 +/* Line number extended opcodes. */
5808 +ENUM(dwarf_line_number_x_ops)
5810 + DW_LNE_end_sequence = 1 COMMA
5811 + DW_LNE_set_address = 2 COMMA
5812 + DW_LNE_define_file = 3
5815 +/* Call frame information. */
5816 +ENUM(dwarf_call_frame_info)
5818 + DW_CFA_advance_loc = 0x40 COMMA
5819 + DW_CFA_offset = 0x80 COMMA
5820 + DW_CFA_restore = 0xc0 COMMA
5821 + DW_CFA_nop = 0x00 COMMA
5822 + DW_CFA_set_loc = 0x01 COMMA
5823 + DW_CFA_advance_loc1 = 0x02 COMMA
5824 + DW_CFA_advance_loc2 = 0x03 COMMA
5825 + DW_CFA_advance_loc4 = 0x04 COMMA
5826 + DW_CFA_offset_extended = 0x05 COMMA
5827 + DW_CFA_restore_extended = 0x06 COMMA
5828 + DW_CFA_undefined = 0x07 COMMA
5829 + DW_CFA_same_value = 0x08 COMMA
5830 + DW_CFA_register = 0x09 COMMA
5831 + DW_CFA_remember_state = 0x0a COMMA
5832 + DW_CFA_restore_state = 0x0b COMMA
5833 + DW_CFA_def_cfa = 0x0c COMMA
5834 + DW_CFA_def_cfa_register = 0x0d COMMA
5835 + DW_CFA_def_cfa_offset = 0x0e COMMA
5838 + DW_CFA_def_cfa_expression = 0x0f COMMA
5839 + DW_CFA_expression = 0x10 COMMA
5840 + DW_CFA_offset_extended_sf = 0x11 COMMA
5841 + DW_CFA_def_cfa_sf = 0x12 COMMA
5842 + DW_CFA_def_cfa_offset_sf = 0x13 COMMA
5844 + /* SGI/MIPS specific. */
5845 + DW_CFA_MIPS_advance_loc8 = 0x1d COMMA
5847 + /* GNU extensions. */
5848 + DW_CFA_GNU_window_save = 0x2d COMMA
5849 + DW_CFA_GNU_args_size = 0x2e COMMA
5850 + DW_CFA_GNU_negative_offset_extended = 0x2f
5853 +#define DW_CIE_ID 0xffffffff
5854 +#define DW_CIE_VERSION 1
5856 +#define DW_CFA_extended 0
5857 +#define DW_CFA_lo_user 0x1c
5858 +#define DW_CFA_hi_user 0x3f
5860 +#define DW_CHILDREN_no 0x00
5861 +#define DW_CHILDREN_yes 0x01
5863 +#define DW_ADDR_none 0
5865 +/* Source language names and codes. */
5866 +ENUM(dwarf_source_language)
5868 + DW_LANG_C89 = 0x0001 COMMA
5869 + DW_LANG_C = 0x0002 COMMA
5870 + DW_LANG_Ada83 = 0x0003 COMMA
5871 + DW_LANG_C_plus_plus = 0x0004 COMMA
5872 + DW_LANG_Cobol74 = 0x0005 COMMA
5873 + DW_LANG_Cobol85 = 0x0006 COMMA
5874 + DW_LANG_Fortran77 = 0x0007 COMMA
5875 + DW_LANG_Fortran90 = 0x0008 COMMA
5876 + DW_LANG_Pascal83 = 0x0009 COMMA
5877 + DW_LANG_Modula2 = 0x000a COMMA
5878 + DW_LANG_Java = 0x000b COMMA
5880 + DW_LANG_C99 = 0x000c COMMA
5881 + DW_LANG_Ada95 = 0x000d COMMA
5882 + DW_LANG_Fortran95 = 0x000e COMMA
5884 + DW_LANG_Mips_Assembler = 0x8001 COMMA
5886 + DW_LANG_Upc = 0x8765
5889 +#define DW_LANG_lo_user 0x8000 /* Implementation-defined range start. */
5890 +#define DW_LANG_hi_user 0xffff /* Implementation-defined range start. */
5892 +/* Names and codes for macro information. */
5893 +ENUM(dwarf_macinfo_record_type)
5895 + DW_MACINFO_define = 1 COMMA
5896 + DW_MACINFO_undef = 2 COMMA
5897 + DW_MACINFO_start_file = 3 COMMA
5898 + DW_MACINFO_end_file = 4 COMMA
5899 + DW_MACINFO_vendor_ext = 255
5902 +/* @@@ For use with GNU frame unwind information. */
5904 +#define DW_EH_PE_absptr 0x00
5905 +#define DW_EH_PE_omit 0xff
5907 +#define DW_EH_PE_uleb128 0x01
5908 +#define DW_EH_PE_udata2 0x02
5909 +#define DW_EH_PE_udata4 0x03
5910 +#define DW_EH_PE_udata8 0x04
5911 +#define DW_EH_PE_sleb128 0x09
5912 +#define DW_EH_PE_sdata2 0x0A
5913 +#define DW_EH_PE_sdata4 0x0B
5914 +#define DW_EH_PE_sdata8 0x0C
5915 +#define DW_EH_PE_signed 0x08
5917 +#define DW_EH_PE_pcrel 0x10
5918 +#define DW_EH_PE_textrel 0x20
5919 +#define DW_EH_PE_datarel 0x30
5920 +#define DW_EH_PE_funcrel 0x40
5921 +#define DW_EH_PE_aligned 0x50
5923 +#define DW_EH_PE_indirect 0x80
5925 +#endif /* _ELF_DWARF2_H */
5926 diff -puN /dev/null include/linux/dwarf2-lang.h
5927 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
5928 +++ 25-akpm/include/linux/dwarf2-lang.h 2004-10-21 14:54:15.337591824 -0700
5930 +#ifndef DWARF2_LANG
5931 +#define DWARF2_LANG
5932 +#include <linux/dwarf2.h>
5935 + * This is free software; you can redistribute it and/or modify it under
5936 + * the terms of the GNU General Public License as published by the Free
5937 + * Software Foundation; either version 2, or (at your option) any later
5941 + * This file defines macros that allow generation of DWARF debug records
5942 + * for asm files. This file is platform independent. Register numbers
5943 + * (which are about the only thing that is platform dependent) are to be
5944 + * supplied by a platform defined file.
5946 +#define DWARF_preamble() .section .debug_frame,"",@progbits
5948 + * This macro starts a debug frame section. The debug_frame describes
5949 + * where to find the registers that the enclosing function saved on
5952 + * ORD is use by the label generator and should be the same as what is
5953 + * passed to CFI_postamble.
5955 + * pc, pc register gdb ordinal.
5957 + * code_align this is the factor used to define locations or regions
5958 + * where the given definitions apply. If you use labels to define these
5959 + * this should be 1.
5961 + * data_align this is the factor used to define register offsets. If
5962 + * you use struct offset, this should be the size of the register in
5963 + * bytes or the negative of that. This is how it is used: you will
5964 + * define a register as the reference register, say the stack pointer,
5965 + * then you will say where a register is located relative to this
5966 + * reference registers value, say 40 for register 3 (the gdb register
5967 + * number). The <40> will be multiplied by <data_align> to define the
5968 + * byte offset of the given register (3, in this example). So if your
5969 + * <40> is the byte offset and the reference register points at the
5970 + * begining, you would want 1 for the data_offset. If <40> was the 40th
5971 + * 4-byte element in that structure you would want 4. And if your
5972 + * reference register points at the end of the structure you would want
5973 + * a negative data_align value(and you would have to do other math as
5977 +#define CFI_preamble(ORD, pc, code_align, data_align) \
5978 +.section .debug_frame,"",@progbits ; \
5979 +frame/**/_/**/ORD: \
5980 + .long end/**/_/**/ORD-start/**/_/**/ORD; \
5981 +start/**/_/**/ORD: \
5982 + .long DW_CIE_ID; \
5983 + .byte DW_CIE_VERSION; \
5985 + .uleb128 code_align; \
5986 + .sleb128 data_align; \
5990 + * After the above macro and prior to the CFI_postamble, you need to
5991 + * define the initial state. This starts with defining the reference
5992 + * register and, usually the pc. Here are some helper macros:
5995 +#define CFA_define_reference(reg, offset) \
5996 + .byte DW_CFA_def_cfa; \
5998 + .uleb128 (offset);
6000 +#define CFA_define_offset(reg, offset) \
6001 + .byte (DW_CFA_offset + reg); \
6002 + .uleb128 (offset);
6004 +#define CFI_postamble(ORD) \
6008 + * So now your code pushs stuff on the stack, you need a new location
6009 + * and the rules for what to do. This starts a running description of
6010 + * the call frame. You need to describe what changes with respect to
6011 + * the call registers as the location of the pc moves through the code.
6012 + * The following builds an FDE (fram descriptor entry?). Like the
6013 + * above, it has a preamble and a postamble. It also is tied to the CFI
6015 + * The first entry after the preamble must be the location in the code
6016 + * that the call frame is being described for.
6018 +#define FDE_preamble(ORD, fde_no, initial_address, length) \
6019 + .long FDE_end/**/_/**/fde_no-FDE_start/**/_/**/fde_no; \
6020 +FDE_start/**/_/**/fde_no: \
6021 + .long frame/**/_/**/ORD; \
6022 + .long initial_address; \
6025 +#define FDE_postamble(fde_no) \
6027 +FDE_end/**/_/**/fde_no:
6029 + * That done, you can now add registers, subtract registers, move the
6030 + * reference and even change the reference. You can also define a new
6031 + * area of code the info applies to. For discontinuous bits you should
6032 + * start a new FDE. You may have as many as you like.
6036 + * To advance the address by <bytes>
6039 +#define FDE_advance(bytes) \
6040 + .byte DW_CFA_advance_loc4 \
6046 + * With the above you can define all the register locations. But
6047 + * suppose the reference register moves... Takes the new offset NOT an
6048 + * increment. This is how esp is tracked if it is not saved.
6051 +#define CFA_define_cfa_offset(offset) \
6052 + .byte $DW_CFA_def_cfa_offset; \
6053 + .uleb128 (offset);
6055 + * Or suppose you want to use a different reference register...
6057 +#define CFA_define_cfa_register(reg) \
6058 + .byte DW_CFA_def_cfa_register; \
6062 diff -puN include/linux/serial_core.h~kgdb-ga include/linux/serial_core.h
6063 --- 25/include/linux/serial_core.h~kgdb-ga 2004-10-21 14:54:15.282600184 -0700
6064 +++ 25-akpm/include/linux/serial_core.h 2004-10-21 14:54:15.338591672 -0700
6065 @@ -172,7 +172,9 @@ struct uart_port {
6066 unsigned char x_char; /* xon/xoff char */
6067 unsigned char regshift; /* reg offset shift */
6068 unsigned char iotype; /* io access style */
6071 + int kgdb; /* in use by kgdb */
6073 #define UPIO_PORT (0)
6074 #define UPIO_HUB6 (1)
6075 #define UPIO_MEM (2)
6076 diff -puN include/linux/spinlock.h~kgdb-ga include/linux/spinlock.h
6077 --- 25/include/linux/spinlock.h~kgdb-ga 2004-10-21 14:54:15.284599880 -0700
6078 +++ 25-akpm/include/linux/spinlock.h 2004-10-21 14:54:15.338591672 -0700
6081 #include <asm/processor.h> /* for cpu relax */
6082 #include <asm/system.h>
6084 +#include <asm/current.h>
6085 +#define SET_WHO(x, him) (x)->who = him;
6087 +#define SET_WHO(x, him)
6091 * Must define these before including other files, inline functions need them
6092 @@ -88,6 +94,9 @@ typedef struct {
6097 + struct task_struct *who;
6100 #define SPIN_LOCK_UNLOCKED (spinlock_t) { SPINLOCK_MAGIC, 0, 10, __FILE__ , NULL, 0}
6102 @@ -99,6 +108,7 @@ typedef struct {
6103 (x)->module = __FILE__; \
6104 (x)->owner = NULL; \
6106 + SET_WHO(x, NULL) \
6109 #define CHECK_LOCK(x) \
6110 @@ -121,6 +131,7 @@ typedef struct {
6112 (x)->owner = __FILE__; \
6113 (x)->oline = __LINE__; \
6114 + SET_WHO(x, current) \
6117 /* without debugging, spin_is_locked on UP always says
6118 @@ -151,6 +162,7 @@ typedef struct {
6120 (x)->owner = __FILE__; \
6121 (x)->oline = __LINE__; \
6122 + SET_WHO(x, current) \
6126 diff -puN kernel/pid.c~kgdb-ga kernel/pid.c
6127 --- 25/kernel/pid.c~kgdb-ga 2004-10-21 14:54:15.285599728 -0700
6128 +++ 25-akpm/kernel/pid.c 2004-10-21 14:54:15.339591520 -0700
6129 @@ -252,6 +252,9 @@ void switch_exec_pids(task_t *leader, ta
6130 * machine. From a minimum of 16 slots up to 4096 slots at one gigabyte or
6134 +int kgdb_pid_init_done; /* so we don't call prior to... */
6136 void __init pidhash_init(void)
6138 int i, j, pidhash_size;
6139 @@ -273,6 +276,9 @@ void __init pidhash_init(void)
6140 for (j = 0; j < pidhash_size; j++)
6141 INIT_HLIST_HEAD(&pid_hash[i][j]);
6144 + kgdb_pid_init_done++;
6148 void __init pidmap_init(void)
6149 diff -puN kernel/sched.c~kgdb-ga kernel/sched.c
6150 --- 25/kernel/sched.c~kgdb-ga 2004-10-21 14:54:15.287599424 -0700
6151 +++ 25-akpm/kernel/sched.c 2004-10-21 14:54:15.342591064 -0700
6152 @@ -2931,6 +2931,13 @@ out_unlock:
6154 EXPORT_SYMBOL(set_user_nice);
6157 +struct task_struct *kgdb_get_idle(int this_cpu)
6159 + return cpu_rq(this_cpu)->idle;
6163 #ifdef __ARCH_WANT_SYS_NICE
6166 diff -puN MAINTAINERS~kgdb-ga MAINTAINERS
6167 --- 25/MAINTAINERS~kgdb-ga 2004-10-21 14:54:15.288599272 -0700
6168 +++ 25-akpm/MAINTAINERS 2004-10-21 14:54:15.344590760 -0700
6169 @@ -1242,6 +1242,12 @@ W: http://sf.net/projects/kernel-janitor
6170 W: http://developer.osdl.org/rddunlap/kj-patches/
6173 +KGDB FOR I386 PLATFORM
6175 +M: george@mvista.com
6176 +L: linux-net@vger.kernel.org
6181 M: neilb@cse.unsw.edu.au
6182 diff -puN arch/i386/Kconfig.debug~kgdb-ga arch/i386/Kconfig.debug
6183 --- 25/arch/i386/Kconfig.debug~kgdb-ga 2004-10-21 14:54:15.290598968 -0700
6184 +++ 25-akpm/arch/i386/Kconfig.debug 2004-10-21 14:54:15.344590760 -0700
6185 @@ -65,4 +65,6 @@ config X86_MPPARSE
6186 depends on X86_LOCAL_APIC && !X86_VISWS
6189 +source "arch/i386/Kconfig.kgdb"
6192 diff -puN /dev/null arch/i386/Kconfig.kgdb
6193 --- /dev/null 2003-09-15 06:40:47.000000000 -0700
6194 +++ 25-akpm/arch/i386/Kconfig.kgdb 2004-10-21 14:54:15.345590608 -0700
6197 + bool "Include kgdb kernel debugger"
6198 + depends on DEBUG_KERNEL
6200 + If you say Y here, the system will be compiled with the debug
6201 + option (-g) and a debugging stub will be included in the
6202 + kernel. This stub communicates with gdb on another (host)
6203 + computer via a serial port. The host computer should have
6204 + access to the kernel binary file (vmlinux) and a serial port
6205 + that is connected to the target machine. Gdb can be made to
6206 + configure the serial port or you can use stty and setserial to
6207 + do this. See the 'target' command in gdb. This option also
6208 + configures in the ability to request a breakpoint early in the
6209 + boot process. To request the breakpoint just include 'kgdb'
6210 + as a boot option when booting the target machine. The system
6211 + will then break as soon as it looks at the boot options. This
6212 + option also installs a breakpoint in panic and sends any
6213 + kernel faults to the debugger. For more information see the
6214 + Documentation/i386/kgdb/kgdb.txt file.
6218 + prompt "Debug serial port BAUD"
6219 + default KGDB_115200BAUD
6221 + Gdb and the kernel stub need to agree on the baud rate to be
6222 + used. Some systems (x86 family at this writing) allow this to
6225 +config KGDB_9600BAUD
6228 +config KGDB_19200BAUD
6231 +config KGDB_38400BAUD
6234 +config KGDB_57600BAUD
6237 +config KGDB_115200BAUD
6242 + hex "hex I/O port address of the debug serial port"
6246 + Some systems (x86 family at this writing) allow the port
6247 + address to be configured. The number entered is assumed to be
6248 + hex, don't put 0x in front of it. The standard address are:
6249 + COM1 3f8 , irq 4 and COM2 2f8 irq 3. Setserial /dev/ttySx
6250 + will tell you what you have. It is good to test the serial
6251 + connection with a live system before trying to debug.
6254 + int "IRQ of the debug serial port"
6258 + This is the irq for the debug port. If everything is working
6259 + correctly and the kernel has interrupts on a control C to the
6260 + port should cause a break into the kernel debug stub.
6268 + bool "Add any additional compile options"
6272 + Saying yes here turns on the ability to enter additional
6276 +config KGDB_OPTIONS
6277 + depends on KGDB_MORE
6278 + string "Additional compile arguments"
6281 + This option allows you enter additional compile options for
6282 + the whole kernel compile. Each platform will have a default
6283 + that seems right for it. For example on PPC "-ggdb -O1", and
6284 + for i386 "-O1". Note that by configuring KGDB "-g" is already
6285 + turned on. In addition, on i386 platforms
6286 + "-fomit-frame-pointer" is deleted from the standard compile
6289 +config NO_KGDB_CPUS
6290 + int "Number of CPUs"
6291 + depends on KGDB && SMP
6295 + This option sets the number of cpus for kgdb ONLY. It is used
6296 + to prune some internal structures so they look "nice" when
6297 + displayed with gdb. This is to overcome possibly larger
6298 + numbers that may have been entered above. Enter the real
6299 + number to get nice clean kgdb_info displays.
6302 + bool "Enable kgdb time stamp macros?"
6306 + Kgdb event macros allow you to instrument your code with calls
6307 + to the kgdb event recording function. The event log may be
6308 + examined with gdb at a break point. Turning on this
6309 + capability also allows you to choose how many events to
6310 + keep. Kgdb always keeps the lastest events.
6313 + depends on KGDB_TS
6314 + prompt "Max number of time stamps to save?"
6315 + default KGDB_TS_128
6329 +config KGDB_TS_1024
6334 +config STACK_OVERFLOW_TEST
6335 + bool "Turn on kernel stack overflow testing?"
6339 + This option enables code in the front line interrupt handlers
6340 + to check for kernel stack overflow on interrupts and system
6341 + calls. This is part of the kgdb code on x86 systems.
6343 +config KGDB_CONSOLE
6344 + bool "Enable serial console thru kgdb port"
6348 + This option enables the command line "console=kgdb" option.
6349 + When the system is booted with this option in the command line
6350 + all kernel printk output is sent to gdb (as well as to other
6351 + consoles). For this to work gdb must be connected. For this
6352 + reason, this command line option will generate a breakpoint if
6353 + gdb has not yet connected. After the gdb continue command is
6354 + given all pent up console output will be printed by gdb on the
6355 + host machine. Neither this option, nor KGDB require the
6356 + serial driver to be configured.
6359 + bool "Turn on SysRq 'G' command to do a break?"
6363 + This option includes an option in the SysRq code that allows
6364 + you to enter SysRq G which generates a breakpoint to the KGDB
6365 + stub. This will work if the keyboard is alive and can
6366 + interrupt the system. Because of constraints on when the
6367 + serial port interrupt can be enabled, this code may allow you
6368 + to interrupt the system before the serial port control C is
6369 + available. Just say yes here.