⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x86_64-lite.patch

📁 Linux-2.6.18内核调试工具补丁程序KGDB。
💻 PATCH
📖 第 1 页 / 共 2 页
字号:
+	gdb_x86_64vector = e_vector;+	gdb_x86_64errcode = err_code;+}++void kgdb_roundup_cpus(unsigned long flags)+{+	send_IPI_allbutself(APIC_DM_NMI);+}++int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,+			       char *remcomInBuffer, char *remcomOutBuffer,+			       struct pt_regs *linux_regs)+{+	unsigned long addr, length;+	unsigned long breakno, breaktype;+	char *ptr;+	int newPC;+	unsigned long dr6;++	switch (remcomInBuffer[0]) {+	case 'c':+	case 's':+		/* try to read optional parameter, pc unchanged if no parm */+		ptr = &remcomInBuffer[1];+		if (kgdb_hex2long(&ptr, &addr))+			linux_regs->rip = addr;+		newPC = linux_regs->rip;++		/* clear the trace bit */+		linux_regs->eflags &= ~TF_MASK;++		atomic_set(&cpu_doing_single_step, -1);+		/* set the trace bit if we're stepping */+		if (remcomInBuffer[0] == 's') {+			linux_regs->eflags |= TF_MASK;+			debugger_step = 1;+			if (kgdb_contthread)+				atomic_set(&cpu_doing_single_step,+					   smp_processor_id());++		}++		asm volatile ("movq %%db6, %0\n":"=r" (dr6));+		if (!(dr6 & 0x4000)) {+			for (breakno = 0; breakno < 4; ++breakno) {+				if (dr6 & (1 << breakno)) {+					if (breakinfo[breakno].type == 0) {+						/* Set restore flag */+						linux_regs->eflags |=+						    X86_EFLAGS_RF;+						break;+					}+				}+			}+		}+		kgdb_correct_hw_break();+		asm volatile ("movq %0, %%db6\n"::"r" (0UL));++		return (0);++	case 'Y':+		ptr = &remcomInBuffer[1];+		kgdb_hex2long(&ptr, &breakno);+		ptr++;+		kgdb_hex2long(&ptr, &breaktype);+		ptr++;+		kgdb_hex2long(&ptr, &length);+		ptr++;+		kgdb_hex2long(&ptr, &addr);+		if (set_hw_break(breakno & 0x3, breaktype & 0x3,+				 length & 0x3, addr) == 0)+			strcpy(remcomOutBuffer, "OK");+		else+			strcpy(remcomOutBuffer, "ERROR");+		break;++		/* Remove hardware breakpoint */+	case 'y':+		ptr = &remcomInBuffer[1];+		kgdb_hex2long(&ptr, &breakno);+		if (remove_hw_break(breakno & 0x3) == 0)+			strcpy(remcomOutBuffer, "OK");+		else+			strcpy(remcomOutBuffer, "ERROR");+		break;++	}			/* switch */+	return -1;+}++static struct pt_regs *in_interrupt_stack(unsigned long rsp, int cpu)+{+	struct pt_regs *regs;+	unsigned long end = (unsigned long)cpu_pda(cpu)->irqstackptr;+	if (rsp <= end && rsp >= end - IRQSTACKSIZE + 8) {+		regs = *(((struct pt_regs **)end) - 1);+		return regs;+	}+	return NULL;+}++static struct pt_regs *in_exception_stack(unsigned long rsp, int cpu)+{+	int i;+	struct tss_struct *init_tss = &__get_cpu_var(init_tss);+	for (i = 0; i < N_EXCEPTION_STACKS; i++)+		if (rsp >= init_tss[cpu].ist[i] &&+		    rsp <= init_tss[cpu].ist[i] + EXCEPTION_STKSZ) {+			struct pt_regs *r =+			    (void *)init_tss[cpu].ist[i] + EXCEPTION_STKSZ;+			return r - 1;+		}+	return NULL;+}++void kgdb_shadowinfo(struct pt_regs *regs, char *buffer, unsigned threadid)+{+	static char intr_desc[] = "Stack at interrupt entrypoint";+	static char exc_desc[] = "Stack at exception entrypoint";+	struct pt_regs *stregs;+	int cpu = hard_smp_processor_id();++	if ((stregs = in_interrupt_stack(regs->rsp, cpu)))+		kgdb_mem2hex(intr_desc, buffer, strlen(intr_desc));+	else if ((stregs = in_exception_stack(regs->rsp, cpu)))+		kgdb_mem2hex(exc_desc, buffer, strlen(exc_desc));+}++struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs, int threadid)+{+	struct pt_regs *stregs;+	int cpu = hard_smp_processor_id();++	if ((stregs = in_interrupt_stack(regs->rsp, cpu)))+		return current;+	else if ((stregs = in_exception_stack(regs->rsp, cpu)))+		return current;++	return NULL;+}++struct pt_regs *kgdb_shadow_regs(struct pt_regs *regs, int threadid)+{+	struct pt_regs *stregs;+	int cpu = hard_smp_processor_id();++	if ((stregs = in_interrupt_stack(regs->rsp, cpu)))+		return stregs;+	else if ((stregs = in_exception_stack(regs->rsp, cpu)))+		return stregs;++	return NULL;+}++/* Register KGDB with the die_chain so that we hook into all of the right+ * spots. */+static int kgdb_notify(struct notifier_block *self, unsigned long cmd,+		       void *ptr)+{+	struct die_args *args = ptr;+	struct pt_regs *regs = args->regs;++	if (cmd == DIE_PAGE_FAULT_NO_CONTEXT && atomic_read(&debugger_active)+			&& kgdb_may_fault) {+		kgdb_fault_longjmp(kgdb_fault_jmp_regs);+		return NOTIFY_STOP;+	/* CPU roundup? */+	} else if (atomic_read(&debugger_active) && cmd == DIE_NMI_IPI) {+		kgdb_nmihook(smp_processor_id(), regs);+		return NOTIFY_STOP;+		/* See if KGDB is interested. */+	} else if (cmd == DIE_PAGE_FAULT || user_mode(regs) ||+		   cmd == DIE_NMI_IPI || (cmd == DIE_DEBUG &&+					  atomic_read(&debugger_active)))+		/* Userpace events, normal watchdog event, or spurious+		 * debug exception.  Ignore. */+		return NOTIFY_DONE;++	kgdb_handle_exception(args->trapnr, args->signr, args->err, regs);++	return NOTIFY_STOP;+}++static struct notifier_block kgdb_notifier = {+	.notifier_call = kgdb_notify,+	.priority = 0x7fffffff,	/* we need to notified first */+};++int kgdb_arch_init(void)+{+	notifier_chain_register(&die_chain, &kgdb_notifier);+	return 0;+}+/*+ * 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 kgdb_skipexception(int exception, struct pt_regs *regs)+{+	if (exception == 3 && kgdb_isremovedbreak(regs->rip - 1)) {+		regs->rip -= 1;+		return 1;+	}+	return 0;+}++struct kgdb_arch arch_kgdb_ops = {+	.gdb_bpt_instr = {0xcc},+	.flags = KGDB_HW_BREAKPOINT,+	.shadowth = 1,+};Index: linux-2.6.15-rc6-x86_64/arch/x86_64/kernel/Makefile===================================================================--- linux-2.6.15-rc6-x86_64.orig/arch/x86_64/kernel/Makefile	2005-12-21 10:09:55.000000000 +0530+++ linux-2.6.15-rc6-x86_64/arch/x86_64/kernel/Makefile	2005-12-26 14:01:58.321765336 +0530@@ -29,6 +29,7 @@ obj-$(CONFIG_GART_IOMMU)	+= pci-gart.o aperture.o obj-$(CONFIG_DUMMY_IOMMU)	+= pci-nommu.o pci-dma.o obj-$(CONFIG_KPROBES)		+= kprobes.o+obj-$(CONFIG_KGDB)		+= kgdb.o kgdb-jmp.o obj-$(CONFIG_X86_PM_TIMER)	+= pmtimer.o  obj-$(CONFIG_MODULES)		+= module.oIndex: linux-2.6.15-rc6-x86_64/lib/Kconfig.debug===================================================================--- linux-2.6.15-rc6-x86_64.orig/lib/Kconfig.debug	2005-12-26 14:01:53.913435504 +0530+++ linux-2.6.15-rc6-x86_64/lib/Kconfig.debug	2005-12-26 14:01:58.334763360 +0530@@ -209,7 +209,7 @@ config KGDB 	bool "KGDB: kernel debugging with remote gdb" 	select WANT_EXTRA_DEBUG_INFORMATION-	depends on DEBUG_KERNEL && (X86 || MIPS || IA64 || PPC)+	depends on DEBUG_KERNEL && (X86 || MIPS || IA64 || X86_64 || PPC) 	help 	  If you say Y here, it will be possible to remotely debug the 	  kernel using gdb. It is strongly suggested that you enableIndex: linux-2.6.15-rc6-x86_64/kernel/kgdb.c===================================================================--- linux-2.6.15-rc6-x86_64.orig/kernel/kgdb.c	2005-12-26 13:59:37.552165568 +0530+++ linux-2.6.15-rc6-x86_64/kernel/kgdb.c	2005-12-26 14:01:58.335763208 +0530@@ -1718,7 +1718,8 @@  */ static void kgdb_tasklet_bpt(unsigned long ing) {-	breakpoint();+	if(CHECK_EXCEPTION_STACK())+		breakpoint(); }  DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);@@ -1729,6 +1730,17 @@  */ static void __init kgdb_early_entry(void) {+	/*+	 * Don't try and do anything until the architecture is able to+	 * setup the exception stack.  In this case, it is up to the+	 * architecture to hook in and look at us when they are ready.+	 */+	if(!CHECK_EXCEPTION_STACK()) {+		kgdb_initialized = -1;+		tasklet_schedule(&kgdb_tasklet_breakpoint);+		return;+	}+ 	/* Let the architecture do any setup that it needs to. */ 	kgdb_arch_init(); Index: linux-2.6.15-rc6-x86_64/include/asm-x86_64/kgdb.h===================================================================--- linux-2.6.15-rc6-x86_64.orig/include/asm-x86_64/kgdb.h	2005-12-26 12:14:53.973528792 +0530+++ linux-2.6.15-rc6-x86_64/include/asm-x86_64/kgdb.h	2005-12-26 14:01:58.321765336 +0530@@ -0,0 +1,50 @@+#ifdef __KERNEL__+#ifndef _ASM_KGDB_H_+#define _ASM_KGDB_H_++/*+ * Copyright (C) 2001-2004 Amit S. Kale+ */++/*+ *  Note that this register image is in a different order than+ *  the register image that Linux produces at interrupt time.+ *+ *  Linux's register image is defined by struct pt_regs in ptrace.h.+ *  Just why GDB uses a different order is a historical mystery.+ */+#define _RAX	0+#define _RDX	1+#define _RCX	2+#define _RBX	3+#define _RSI	4+#define _RDI	5+#define _RBP	6+#define _RSP	7+#define _R8	8+#define _R9	9+#define _R10	10+#define _R11	11+#define _R12	12+#define _R13	13+#define _R14	14+#define _R15	15+#define _PC	16+#define _PS	17++/* Number of bytes of registers.  */+#define NUMREGBYTES		((_PS+1)*8)+#define NUMCRITREGBYTES		(8 * 8)		/* 8 registers. */++#ifndef __ASSEMBLY__+/* BUFMAX defines the maximum number of characters in inbound/outbound+ * buffers at least NUMREGBYTES*2 are needed for register packets, and+ * a longer buffer is needed to list all threads. */+#define BUFMAX			1024+#define BREAKPOINT()		asm("   int $3");+#define CHECK_EXCEPTION_STACK() ((&__get_cpu_var(init_tss))[0].ist[0])+#define BREAK_INSTR_SIZE	1+#define CACHE_FLUSH_IS_SAFE	1+#endif				/* !__ASSEMBLY__ */+#endif				/* _ASM_KGDB_H_ */+#endif				/* __KERNEL__ */Index: linux-2.6.15-rc6-x86_64/include/asm-x86_64/system.h===================================================================--- linux-2.6.15-rc6-x86_64.orig/include/asm-x86_64/system.h	2005-10-28 05:32:08.000000000 +0530+++ linux-2.6.15-rc6-x86_64/include/asm-x86_64/system.h	2005-12-26 14:01:58.333763512 +0530@@ -27,7 +27,9 @@ 	,"rcx","rbx","rdx","r8","r9","r10","r11","r12","r13","r14","r15"  #define switch_to(prev,next,last) \-	asm volatile(SAVE_CONTEXT						    \+       asm volatile(".globl __switch_to_begin\n\t"				    \+		     "__switch_to_begin:\n\t"					  \+		     SAVE_CONTEXT						  \ 		     "movq %%rsp,%P[threadrsp](%[prev])\n\t" /* save RSP */	  \ 		     "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */	  \ 		     "call __switch_to\n\t"					  \@@ -39,6 +41,8 @@ 		     "movq %%rax,%%rdi\n\t" 					  \ 		     "jc   ret_from_fork\n\t"					  \ 		     RESTORE_CONTEXT						    \+		     ".globl __switch_to_end\n\t"				  \+		     "__switch_to_end:\n\t"					  \ 		     : "=a" (last)					  	  \ 		     : [next] "S" (next), [prev] "D" (prev),			  \ 		       [threadrsp] "i" (offsetof(struct task_struct, thread.rsp)), \Index: linux-2.6.15-rc6-x86_64/include/linux/kgdb.h===================================================================--- linux-2.6.15-rc6-x86_64.orig/include/linux/kgdb.h	2005-12-26 13:59:37.472177728 +0530+++ linux-2.6.15-rc6-x86_64/include/linux/kgdb.h	2005-12-26 14:01:58.334763360 +0530@@ -24,6 +24,10 @@ #include <linux/linkage.h> #include <linux/init.h> +#ifndef CHECK_EXCEPTION_STACK+#define CHECK_EXCEPTION_STACK()	1+#endif+ struct tasklet_struct; struct pt_regs; struct task_struct;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -