📄 core-lite.patch
字号:
+ * cause a fault. When this happens, we trap it, restore state to+ * this call, and let ourself know that something bad has happened.+ */+extern asmlinkage int kgdb_fault_setjmp(unsigned long *curr_context);++/**+ * kgdb_fault_longjmp - Restore state when we have faulted.+ * @curr_context: The previously stored state.+ *+ * When something bad does happen, this function is called to+ * restore the known good state, and set the return value to 1, so+ * we know something bad happened.+ */+extern asmlinkage void kgdb_fault_longjmp(unsigned long *curr_context);++/* Optional functions. */+extern int kgdb_arch_init(void);+extern void kgdb_disable_hw_debug(struct pt_regs *regs);+extern void kgdb_post_master_code(struct pt_regs *regs, int e_vector,+ int err_code);+extern void kgdb_roundup_cpus(unsigned long flags);+extern int kgdb_set_hw_break(unsigned long addr);+extern int kgdb_remove_hw_break(unsigned long addr);+extern void kgdb_remove_all_hw_break(void);+extern void kgdb_correct_hw_break(void);+extern void kgdb_shadowinfo(struct pt_regs *regs, char *buffer,+ unsigned threadid);+extern struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs,+ int threadid);+extern struct pt_regs *kgdb_shadow_regs(struct pt_regs *regs, int threadid);+extern int kgdb_validate_break_address(unsigned long addr);+extern int kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr);+extern int kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle);++/**+ * struct kgdb_arch - Desribe architecture specific values.+ * @gdb_bpt_instr: The instruction to trigger a breakpoint.+ * @flags: Flags for the breakpoint, currently just %KGDB_HW_BREAKPOINT.+ * @shadowth: A value of %1 indicates we shadow information on processes.+ * @set_breakpoint: Allow an architecture to specify how to set a software+ * breakpoint.+ * @remove_breakpoint: Allow an architecture to specify how to remove a+ * software breakpoint.+ * @set_hw_breakpoint: Allow an architecture to specify how to set a hardware+ * breakpoint.+ * @remove_hw_breakpoint: Allow an architecture to specify how to remove a+ * hardware breakpoint.+ *+ * The @shadowth flag is an option to shadow information not retrievable by+ * gdb otherwise. This is deprecated in favor of a binutils which supports+ * CFI macros.+ */+struct kgdb_arch {+ unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];+ unsigned long flags;+ unsigned shadowth;+ int (*set_breakpoint) (unsigned long, char *);+ int (*remove_breakpoint)(unsigned long, char *);+ int (*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);+ int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);+};++/* Thread reference */+typedef unsigned char threadref[8];++/**+ * struct kgdb_io - Desribe the interface for an I/O driver to talk with KGDB.+ * @read_char: Pointer to a function that will return one char.+ * @write_char: Pointer to a function that will write one char.+ * @flush: Pointer to a function that will flush any pending writes.+ * @init: Pointer to a function that will initialize the device.+ * @late_init: Pointer to a function that will do any setup that has+ * other dependencies.+ * @pre_exception: Pointer to a function that will do any prep work for+ * the I/O driver.+ * @post_exception: Pointer to a function that will do any cleanup work+ * for the I/O driver.+ *+ * The @init and @late_init function pointers allow for an I/O driver+ * such as a serial driver to fully initialize the port with @init and+ * be called very early, yet safely call request_irq() later in the boot+ * sequence.+ *+ * @init is allowed to return a non-0 return value to indicate failure.+ * If this is called early on, then KGDB will try again when it would call+ * @late_init. If it has failed later in boot as well, the user will be+ * notified.+ */+struct kgdb_io {+ int (*read_char) (void);+ void (*write_char) (u8);+ void (*flush) (void);+ int (*init) (void);+ void (*late_init) (void);+ void (*pre_exception) (void);+ void (*post_exception) (void);+};++extern struct kgdb_io kgdb_io_ops;+extern struct kgdb_arch arch_kgdb_ops;+extern int kgdb_initialized;++extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);+extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);++extern void __init kgdb8250_add_port(int i, struct uart_port *serial_req);+extern void __init kgdb8250_add_platform_port(int i, struct plat_serial8250_port *serial_req);++extern int kgdb_hex2long(char **ptr, long *long_val);+extern char *kgdb_mem2hex(char *mem, char *buf, int count);+extern char *kgdb_hex2mem(char *buf, char *mem, int count);+extern int kgdb_get_mem(char *addr, unsigned char *buf, int count);+extern int kgdb_set_mem(char *addr, unsigned char *buf, int count);++int kgdb_isremovedbreak(unsigned long addr);+int kgdb_skipexception(int exception, struct pt_regs *regs);++extern int kgdb_handle_exception(int ex_vector, int signo, int err_code,+ struct pt_regs *regs);+extern void kgdb_nmihook(int cpu, void *regs);+extern int debugger_step;+extern atomic_t debugger_active;+#else+/* Stubs for when KGDB is not set. */+static const atomic_t debugger_active = ATOMIC_INIT(0);+#endif /* CONFIG_KGDB */+#endif /* _KGDB_H_ */+#endif /* __KERNEL__ */Index: linux-2.6.15.5/kernel/Makefile===================================================================--- linux-2.6.15.5.orig/kernel/Makefile+++ linux-2.6.15.5/kernel/Makefile@@ -26,6 +26,7 @@ obj-$(CONFIG_STOP_MACHINE) += stop_machi obj-$(CONFIG_AUDIT) += audit.o obj-$(CONFIG_AUDITSYSCALL) += auditsc.o obj-$(CONFIG_KPROBES) += kprobes.o+obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_SYSFS) += ksysfs.o obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o obj-$(CONFIG_GENERIC_HARDIRQS) += irq/Index: linux-2.6.15.5/kernel/kgdb.c===================================================================--- /dev/null+++ linux-2.6.15.5/kernel/kgdb.c@@ -0,0 +1,1959 @@+/*+ * kernel/kgdb.c+ *+ * Maintainer: Tom Rini <trini@kernel.crashing.org>+ *+ * Copyright (C) 2000-2001 VERITAS Software Corporation.+ * Copyright (C) 2002-2004 Timesys Corporation+ * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com>+ * Copyright (C) 2004 Pavel Machek <pavel@suse.cz>+ * Copyright (C) 2004-2005 Tom Rini <trini@kernel.crashing.org>+ * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd.+ * Copyright (C) 2005 Wind River Systems, Inc.+ *+ * Contributors at various stages not listed above:+ * Jason Wessel ( jason.wessel@windriver.com )+ * George Anzinger <george@mvista.com>+ * Anurekh Saxena (anurekh.saxena@timesys.com)+ * Lake Stevens Instrument Division (Glenn Engel)+ * Jim Kingdon, Cygnus Support.+ *+ * Original KGDB stub: David Grothe <dave@gcom.com>,+ * Tigran Aivazian <tigran@sco.com>+ *+ * This file is licensed under the terms of the GNU General Public License+ * version 2. This program is licensed "as is" without any warranty of any+ * kind, whether express or implied.+ */++#include <linux/string.h>+#include <linux/kernel.h>+#include <linux/interrupt.h>+#include <linux/sched.h>+#include <linux/smp.h>+#include <linux/spinlock.h>+#include <linux/delay.h>+#include <linux/mm.h>+#include <linux/threads.h>+#include <linux/reboot.h>+#include <asm/system.h>+#include <asm/ptrace.h>+#include <asm/uaccess.h>+#include <linux/kgdb.h>+#include <asm/atomic.h>+#include <linux/notifier.h>+#include <linux/module.h>+#include <asm/cacheflush.h>+#include <linux/init.h>+#include <linux/sysrq.h>+#include <linux/console.h>+#include <asm/byteorder.h>++extern int pid_max;+extern int pidhash_init_done;++/* How many times to count all of the waiting CPUs */+#define ROUNDUP_WAIT 640000 /* Arbitrary, increase if needed. */+#define BUF_THREAD_ID_SIZE 16++/*+ * kgdb_initialized with a value of 1 indicates that kgdb is setup and is+ * all ready to serve breakpoints and other kernel exceptions. A value of+ * -1 indicates that we have tried to initialize early, and need to try+ * again later.+ */+int kgdb_initialized;+/* Is a host GDB connected to us? */+int kgdb_connected;+/* Could we be about to try and access a bad memory location? If so we+ * also need to flag this has happend. */+int kgdb_may_fault;+/* All the KGDB handlers are installed */+int kgdb_from_module_registered = 0;++/* We provide a kgdb_io_ops structure that may be overriden. */+struct kgdb_io __attribute__ ((weak)) kgdb_io_ops;++static struct kgdb_io kgdb_io_ops_prev[MAX_KGDB_IO_HANDLERS];+static int kgdb_io_handler_cnt = 0;++/* Export the following symbols for use with kernel modules */+EXPORT_SYMBOL(kgdb_io_ops);+EXPORT_SYMBOL(kgdb_tasklet_breakpoint);+EXPORT_SYMBOL(kgdb_connected);+EXPORT_SYMBOL(kgdb_register_io_module);+EXPORT_SYMBOL(kgdb_unregister_io_module);+EXPORT_SYMBOL(debugger_active);++/*+ * Holds information about breakpoints in a kernel. These breakpoints are+ * added and removed by gdb.+ */+struct kgdb_bkpt kgdb_break[MAX_BREAKPOINTS];++struct kgdb_arch *kgdb_ops = &arch_kgdb_ops;++static const char hexchars[] = "0123456789abcdef";++static spinlock_t slavecpulocks[NR_CPUS];+static atomic_t procindebug[NR_CPUS];+atomic_t kgdb_setting_breakpoint;+EXPORT_SYMBOL(kgdb_setting_breakpoint);+struct task_struct *kgdb_usethread, *kgdb_contthread;++int debugger_step;+atomic_t debugger_active;++/* Our I/O buffers. */+static char remcom_in_buffer[BUFMAX];+static char remcom_out_buffer[BUFMAX];+/* Storage for the registers, in GDB format. */+static unsigned long gdb_regs[(NUMREGBYTES + sizeof(unsigned long) - 1) /+ sizeof(unsigned long)];+/* Storage of registers for handling a fault. */+unsigned long kgdb_fault_jmp_regs[NUMCRITREGBYTES / sizeof(unsigned long)]+ JMP_REGS_ALIGNMENT;+static int kgdb_notify_reboot(struct notifier_block *this,+ unsigned long code ,void *x);+struct debuggerinfo_struct {+ void *debuggerinfo;+ struct task_struct *task;+} kgdb_info[NR_CPUS];++/* to keep track of the CPU which is doing the single stepping*/+atomic_t cpu_doing_single_step = ATOMIC_INIT(-1);++/* reboot notifier block */+static struct notifier_block kgdb_reboot_notifier = {+ .notifier_call = kgdb_notify_reboot,+ .next = NULL,+ .priority = INT_MAX,+};++/**+ * kgdb_arch_init - Perform any architecture specific initalization.+ *+ * RETURN:+ * The return value is ignored.+ *+ * This function will handle the initalization of any architecture+ * specific hooks.+ */+int __attribute__ ((weak))+ kgdb_arch_init(void)+{+ return 0;+}++/**+ * kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.+ * @regs: Current &struct pt_regs.+ *+ * This function will be called if the particular architecture must+ * disable hardware debugging while it is processing gdb packets or+ * handling exception.+ */+void __attribute__ ((weak))+ kgdb_disable_hw_debug(struct pt_regs *regs)+{+}++/*+ * Skip an int3 exception when it occurs after a breakpoint has been+ * removed. Backtrack eip by 1 since the int3 would have caused it to+ * increment by 1.+ */+int __attribute__ ((weak))+ kgdb_skipexception(int exception, struct pt_regs *regs)+{+ return 0;+}++/**+ * kgdb_set_hw_break - Set a hardware breakpoint at @addr.+ * @addr: The address to set a hardware breakpoint at.+ */+int __attribute__ ((weak))+ kgdb_set_hw_break(unsigned long addr)+{+ return 0;+}++/**+ * kgdb_remove_hw_break - Remove a hardware breakpoint at @addr.+ * @addr: The address to remove a hardware breakpoint from.+ */+int __attribute__ ((weak))+ kgdb_remove_hw_break(unsigned long addr)+{+ return 0;+}++/**+ * kgdb_remove_all_hw_break - Clear all hardware breakpoints.+ */+void __attribute__ ((weak))+ kgdb_remove_all_hw_break(void)+{+}++/**+ * kgdb_correct_hw_break - Correct hardware breakpoints.+ *+ * A hook to allow for changes to the hardware breakpoint, called+ * after a single step (s) or continue (c) packet, and once we're about+ * to let the kernel continue running.+ *+ * This is used to set the hardware breakpoint registers for all the+ * slave cpus on an SMP configuration. This must be called after any+ * changes are made to the hardware breakpoints (such as by a single+ * step (s) or continue (c) packet. This is only required on+ * architectures that support SMP and every processor has its own set+ * of breakpoint registers.+ */+void __attribute__ ((weak))+ kgdb_correct_hw_break(void)+{+}++/**+ * kgdb_post_master_code - Save error vector/code numbers.+ * @regs: Original pt_regs.+ * @e_vector: Original error vector.+ * @err_code: Original error code.+ *+ * This is needed on architectures which support SMP and KGDB.+ * This function is called after all the slave cpus have been put+ * to a know spin state and the master CPU has control over KGDB.+ */++void __attribute__ ((weak))+ kgdb_post_master_code(struct pt_regs *regs, int e_vector, int err_code)+{+}++/**+ * kgdb_roundup_cpus - Get other CPUs into a holding pattern+ * @flags: Current IRQ state+ *+ * On SMP systems, we need to get the attention of the other CPUs+ * and get them be in a known state. This should do what is needed+ * to get the other CPUs to call kgdb_wait(). Note that on some arches,+ * the NMI approach is not used for rounding up all the CPUs. For example,+ * in case of MIPS, smp_call_function() is used to roundup CPUs. In+ * this case, we have to make sure that interrupts are enabled before+ * calling smp_call_function(). The argument to this function is+ * the flags that will be used when restoring the interrupts. There is+ * local_irq_save() call before kgdb_roundup_cpus().+ */+void __attribute__ ((weak))+ kgdb_roundup_cpus(unsigned long flags)+{+}++/**+ * kgdb_shadowinfo - Get shadowed information on @threadid.+ * @regs: The &struct pt_regs of the current process.+ * @buffer: A buffer of %BUFMAX size.+ * @threadid: The thread id of the shadowed process to get information on.+ */+void __attribute__ ((weak))+ kgdb_shadowinfo(struct pt_regs *regs, char *buffer, unsigned threadid)+{+}++/**+ * kgdb_get_shadow_thread - Get the shadowed &task_struct of @threadid.+ * @regs: The &struct pt_regs of the current thread.+ * @threadid: The thread id of the shadowed process to get information on.+ *+ * RETURN:+ * This returns a pointer to the &struct task_struct of the shadowed+ * thread, @threadid.+ */+struct task_struct __attribute__ ((weak))+ * kgdb_get_shadow_thread(struct pt_regs *regs, int threadid)+{+ return NULL;+}++/**+ * kgdb_shadow_regs - Return the shadowed registers of @threadid.+ * @regs: The &struct pt_regs of the current thread.+ * @threadid: The thread id we want the &struct pt_regs for.+ *+ * RETURN:+ * The a pointer to the &struct pt_regs of the shadowed thread @threadid.+ */+struct pt_regs __attribute__ ((weak))+ * kgdb_shadow_regs(struct pt_regs *regs, int threadid)+{+ return NULL;+}++int __attribute__ ((weak))+ kgdb_validate_break_address(unsigned long addr)+{+ int error = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -