Skip to contentSkip to conversation

kgdb-lite for 2.6.3

PATCH In review Pavel Machek 4 participants 7 messages Feb 22, 2004 – Feb 23, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 kgdb-lite for 2.6.3

Hi!

Here's kgdb-lite for 2.6.3: core-lite + i386-lite + 8250. Should be both functional, and suitable for merging (maybe even to -vanilla?)

Pavel

include/linux/debugger.h +70 -0
Index: linux-2.6.3-kgdb/include/linux/debugger.h
===================================================================
@@ -0,0 +1,70 @@
+#ifndef _DEBUGGER_H_
+#define _DEBUGGER_H_
+
+/*
+ * Copyright (C) 2003-2004 Amit S. Kale
+ *
+ * Definition switchout for debuggers
+ */
+
+/*
+ * KGDB
+ */
+#ifdef CONFIG_KGDB
+
+typedef int gdb_debug_hook(int exVector, int signo, int err_code,
+                            struct pt_regs *regs);
+extern gdb_debug_hook  *linux_debug_hook;
+#define	CHK_DEBUGGER(trapnr,signr,error_code,regs,after)			\
+    {									\
+	if (linux_debug_hook != (gdb_debug_hook *) NULL && !user_mode(regs)) \
+	{								\
+		(*linux_debug_hook)(trapnr, signr, error_code, regs) ;	\
+		after;							\
+	}								\
+    }
+
+void kgdb_nmihook(int cpu, void *regs);
+static inline void debugger_nmihook(int cpu, void *regs)
+{
+	kgdb_nmihook(cpu, regs);
+}
+
+void kgdb_entry(void);
+static inline void debugger_entry(void)
+{
+	kgdb_entry();
+}
+
+extern int debugger_step;
+extern atomic_t debugger_active;
+
+/*
+ * No debugger in the kernel
+ */
+#else
+
+#define	CHK_DEBUGGER(trapnr,signr,error_code,regs,after)	\
+{									\
+	if (0)								\
+		after;							\
+}
+
+static inline void debugger_nmihook(int cpu, void *regs)
+{
+	/* Do nothing */
+}
+
+static inline void debugger_entry(void)
+{
+	/* Do nothing */
+}
+
+#define debugger_step 0
+static const atomic_t debugger_active = { 0 };
+#define debugger_memerr_expected 0
+
+#endif
+
+
+#endif /* _DEBUGGER_H_ */
include/linux/kgdb.h +113 -0

113 lines not on this page · raw message

init/main.c +2 -0
Index: linux-2.6.3-kgdb/init/main.c
===================================================================
@@ -39,6 +39,7 @@
 #include <linux/writeback.h>
 #include <linux/cpu.h>
 #include <linux/efi.h>
+#include <linux/debugger.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -580,6 +581,7 @@
 	do_pre_smp_initcalls();
 
 	smp_init();
+	debugger_entry();
 	do_basic_setup();
 
 	prepare_namespace();
kernel/kgdbstub.c +1267 -0

1,267 lines not on this page · raw message

kernel/Makefile +1 -0
Index: linux-2.6.3-kgdb/kernel/Makefile
===================================================================
@@ -19,6 +19,7 @@
 obj-$(CONFIG_COMPAT) += compat.o
 obj-$(CONFIG_IKCONFIG) += configs.o
 obj-$(CONFIG_IKCONFIG_PROC) += configs.o
+obj-$(CONFIG_KGDB) += kgdbstub.o
 
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/sched.c +3 -0
Index: linux-2.6.3-kgdb/kernel/sched.c
===================================================================
@@ -37,6 +37,7 @@
 #include <linux/rcupdate.h>
 #include <linux/cpu.h>
 #include <linux/percpu.h>
+#include <linux/debugger.h>
 
 #ifdef CONFIG_NUMA
 #define cpu_to_node_mask(cpu) node_to_cpumask(cpu_to_node(cpu))
@@ -2961,6 +2962,8 @@
 #if defined(in_atomic)
 	static unsigned long prev_jiffy;	/* ratelimiting */
 
+	if (atomic_read(&debugger_active))
+		return;
 	if ((in_atomic() || irqs_disabled()) && system_running) {
 		if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
 			return;
Makefile +2 -0
Index: linux-2.6.3-kgdb/Makefile
===================================================================
@@ -440,6 +440,8 @@
 
 ifndef CONFIG_FRAME_POINTER
 CFLAGS		+= -fomit-frame-pointer
+else
+CFLAGS		+= -fno-omit-frame-pointer
 endif
 
 ifdef CONFIG_DEBUG_INFO
arch/i386/Kconfig +14 -0
Index: linux-2.6.3-kgdb-lite/arch/i386/Kconfig
===================================================================
@@ -1253,6 +1253,20 @@
 	  If you say Y here, various routines which may sleep will become very
 	  noisy if they are called with a spinlock held.	
 
+config KGDB
+	bool "KGDB: kernel debugging with remote gdb"
+	depends on DEBUG_KERNEL
+	select DEBUG_INFO
+	select FRAME_POINTER
+	help
+	  If you say Y here, it will be possible to remotely debug the
+	  kernel using gdb. This enlarges your kernel image disk size by
+	  several megabytes and requires a machine with more than 128 MB
+	  RAM to avoid excessive linking time. 
+	  Documentation of kernel debugger available at
+	  http://kgdb.sourceforge.net
+	  This is only useful for kernel hackers. If unsure, say N.
+
 config FRAME_POINTER
 	bool "Compile the kernel with frame pointers"
 	help
arch/i386/kernel/i386-stub.c +373 -0

373 lines not on this page · raw message

arch/i386/kernel/Makefile +1 -0
Index: linux-2.6.3-kgdb-lite/arch/i386/kernel/Makefile
===================================================================
@@ -31,6 +31,7 @@
 obj-$(CONFIG_ACPI_SRAT) 	+= srat.o
 obj-$(CONFIG_HPET_TIMER) 	+= time_hpet.o
 obj-$(CONFIG_EFI) 		+= efi.o efi_stub.o
+obj-$(CONFIG_KGDB)		+= i386-stub.o
 
 EXTRA_AFLAGS   := -traditional
 
arch/i386/kernel/nmi.c +13 -1
Index: linux-2.6.3-kgdb-lite/arch/i386/kernel/nmi.c
===================================================================
@@ -25,6 +25,7 @@
 #include <linux/module.h>
 #include <linux/nmi.h>
 #include <linux/sysdev.h>
+#include <linux/debugger.h>
 
 #include <asm/smp.h>
 #include <asm/mtrr.h>
@@ -420,14 +421,25 @@
 	int sum, cpu = smp_processor_id();
 
 	sum = irq_stat[cpu].apic_timer_irqs;
+	if (atomic_read(&debugger_active)) {
 
-	if (last_irq_sums[cpu] == sum) {
+		/*
+		 * The machine is in debugger, hold this cpu if already
+		 * not held.
+		 */
+		debugger_nmihook(cpu, regs);
+		alert_counter[cpu] = 0;
+
+	} else if (last_irq_sums[cpu] == sum) {
 		/*
 		 * Ayiee, looks like this CPU is stuck ...
 		 * wait a few IRQs (5 seconds) before doing the oops ...
 		 */
 		alert_counter[cpu]++;
 		if (alert_counter[cpu] == 5*nmi_hz) {
+
+			CHK_DEBUGGER(2,SIGSEGV,0,regs,)
+
 			spin_lock(&nmi_print_lock);
 			/*
 			 * We are in trouble anyway, lets at least try
arch/i386/kernel/signal.c +2 -1
Index: linux-2.6.3-kgdb-lite/arch/i386/kernel/signal.c
===================================================================
@@ -580,7 +580,8 @@
 		 * have been cleared if the watchpoint triggered
 		 * inside the kernel.
 		 */
-		__asm__("movl %0,%%db7"	: : "r" (current->thread.debugreg[7]));
+		if (current->thread.debugreg[7])
+			__asm__("movl %0,%%db7"	: : "r" (current->thread.debugreg[7]));
 
 		/* Whee!  Actually deliver the signal.  */
 		handle_signal(signr, &info, oldset, regs);
arch/i386/kernel/traps.c +15 -6
Index: linux-2.6.3-kgdb-lite/arch/i386/kernel/traps.c
===================================================================
@@ -51,6 +51,7 @@
 
 #include <linux/irq.h>
 #include <linux/module.h>
+#include <linux/debugger.h>
 
 #include "mach_traps.h"
 
@@ -256,6 +257,7 @@
 {
 	static int die_counter;
 
+	CHK_DEBUGGER(1,SIGTRAP,err,regs,)
 	console_verbose();
 	spin_lock_irq(&die_lock);
 	bust_spinlocks(1);
@@ -330,6 +332,7 @@
 #define DO_ERROR(trapnr, signr, str, name) \
 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
 { \
+	CHK_DEBUGGER(trapnr,signr,error_code,regs,)\
 	do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \
 }
 
@@ -347,7 +350,10 @@
 #define DO_VM86_ERROR(trapnr, signr, str, name) \
 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
 { \
+	CHK_DEBUGGER(trapnr,signr,error_code,regs,goto skip_trap)\
 	do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \
+skip_trap: \
+	return; \
 }
 
 #define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
@@ -547,7 +553,7 @@
 	tsk->thread.debugreg[6] = condition;
 
 	/* Mask out spurious TF errors due to lazy TF clearing */
-	if (condition & DR_STEP) {
+	if (condition & DR_STEP && !debugger_step) {
 		/*
 		 * The TF error should be masked out only if the current
 		 * process is not traced and if the TRAP flag has been set
@@ -570,11 +576,13 @@
 	info.si_errno = 0;
 	info.si_code = TRAP_BRKPT;
 	
-	/* If this is a kernel mode trap, save the user PC on entry to 
-	 * the kernel, that's what the debugger can make sense of.
-	 */
-	info.si_addr = ((regs->xcs & 3) == 0) ? (void *)tsk->thread.eip : 
-	                                        (void *)regs->eip;
+
+	/* If this is a kernel mode trap, we need to reset db7 to allow us
+	 * to continue sanely */
+	if ((regs->xcs & 3) == 0)
+		goto clear_dr7;
+
+	info.si_addr = (void *)regs->eip;
 	force_sig_info(SIGTRAP, &info, tsk);
 
 	/* Disable additional traps. They'll be re-enabled when
@@ -584,6 +592,7 @@
 	__asm__("movl %0,%%db7"
 		: /* no output */
 		: "r" (0));
+	CHK_DEBUGGER(1,SIGTRAP,error_code,regs,)
 	return;
 
 debug_vm86:
arch/i386/mm/fault.c +9 -0
Index: linux-2.6.3-kgdb-lite/arch/i386/mm/fault.c
===================================================================
@@ -2,6 +2,11 @@
  *  linux/arch/i386/mm/fault.c
  *
  *  Copyright (C) 1995  Linus Torvalds
+ *
+ *  Change History
+ *
+ *	Tigran Aivazian <[email protected]>	Remote debugging support.
+ *
  */
 
 #include <linux/signal.h>
@@ -21,6 +26,7 @@
 #include <linux/vt_kern.h>		/* For unblank_screen() */
 #include <linux/highmem.h>
 #include <linux/module.h>
+#include <linux/debugger.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -399,6 +405,8 @@
  	if (is_prefetch(regs, address))
  		return;
 
+	CHK_DEBUGGER(14, SIGSEGV,error_code, regs,)
+
 /*
  * Oops. The kernel tried to access some bad page. We'll have to
  * terminate things with extreme prejudice.
@@ -406,6 +414,7 @@
 
 	bust_spinlocks(1);
 
+
 	if (address < PAGE_SIZE)
 		printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
 	else
include/asm-i386/kgdb.h +49 -0

49 lines not on this page · raw message

include/asm-i386/processor.h +2 -0
Index: linux-2.6.3-kgdb-lite/include/asm-i386/processor.h
===================================================================
@@ -425,6 +425,8 @@
 	unsigned int		saved_fs, saved_gs;
 /* IO permissions */
 	unsigned long	*io_bitmap_ptr;
+	void *		debuggerinfo;
+
 };
 
 #define INIT_THREAD  {							\
drivers/serial/8250.c +39 -0
Index: linux-2.6.3-kgdb/drivers/serial/8250.c
===================================================================
@@ -1198,12 +1198,17 @@
 	spin_unlock_irqrestore(&up->port.lock, flags);
 }
 
+static int released_irq = -1;
+
 static int serial8250_startup(struct uart_port *port)
 {
 	struct uart_8250_port *up = (struct uart_8250_port *)port;
 	unsigned long flags;
 	int retval;
 
+	if (up->port.irq == released_irq)
+		return -EBUSY;
+
 	up->capabilities = uart_config[up->port.type].flags;
 
 	if (up->port.type == PORT_16C950) {
@@ -1869,6 +1874,10 @@
 	for (i = 0; i < UART_NR; i++) {
 		struct uart_8250_port *up = &serial8250_ports[i];
 
+		if (up->port.irq == released_irq) {
+			continue;
+		}
+
 		up->port.line = i;
 		up->port.ops = &serial8250_pops;
 		init_timer(&up->timer);
@@ -2138,6 +2147,36 @@
 	uart_resume_port(&serial8250_reg, &serial8250_ports[line].port);
 }
 
+/*
+ * Find all the ports using the given irq and shut them down.
+ * Result should be that the irq will be released.
+ * At most one irq can be released this way.
+ * Once an irq is released, any attempts to initialize a port with that irq
+ * will fail with EBUSY.
+ */
+
+int serial8250_release_irq(int irq)
+{
+        struct uart_8250_port *up;
+	int ttyS;
+
+	if (released_irq != -1) {
+		return -EBUSY;
+	}
+	released_irq = irq;
+	for (ttyS = 0; ttyS < UART_NR; ttyS++){
+		up =  &serial8250_ports[ttyS];
+		if (up->port.irq == irq && (irq_lists + irq)->head) {
+#ifdef CONFIG_DEBUG_SPINLOCK   /* ugly business... */
+			if(up->port.lock.magic != SPINLOCK_MAGIC)
+				spin_lock_init(&up->port.lock);
+#endif
+			serial8250_shutdown(&up->port);
+		}
+        }
+	return 0;
+}
+
 static int __init serial8250_init(void)
 {
 	int ret, i;
drivers/serial/Kconfig +7 -0
Index: linux-2.6.3-kgdb/drivers/serial/Kconfig
===================================================================
@@ -6,6 +6,13 @@
 
 menu "Serial drivers"
 
+config KGDB_8250
+	bool "KGDB: On generic serial port (8250)"
+	depends on KGDB
+	help
+	  Uses generic serial port (8250) for kgdb. This is independent of the
+	  option 9250/16550 and compatible serial port.
+
 #
 # The new 8250/16550 serial drivers
 config SERIAL_8250
drivers/serial/kgdb_8250.c +396 -0

396 lines not on this page · raw message

drivers/serial/Makefile +2 -0
Index: linux-2.6.3-kgdb/drivers/serial/Makefile
===================================================================
@@ -32,3 +32,5 @@
 obj-$(CONFIG_V850E_UART) += v850e_uart.o
 obj-$(CONFIG_SERIAL98) += serial98.o
 obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o
+
+obj-$(CONFIG_KGDB_8250) += kgdb_8250.o
drivers/serial/serial_core.c +5 -1
Index: linux-2.6.3-kgdb/drivers/serial/serial_core.c
===================================================================
@@ -917,7 +917,11 @@
 static void uart_break_ctl(struct tty_struct *tty, int break_state)
 {
 	struct uart_state *state = tty->driver_data;
-	struct uart_port *port = state->port;
+	struct uart_port *port;
+
+	if (!state)
+		return;
+	port = state->port;
 
 	BUG_ON(!kernel_locked());
 
Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#1 lore raw

Just some random comments after browsing the code.

Sam

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+int kgdb_hexToLong(char **ptr, long *longValue);

A patch has been posted by Tom Rini to convert this to the linux naming: kgdb_hex2long(...).

+static const char hexchars[] = "0123456789abcdef";
Grepping after 0123456789 in the src tree gives a lot of hits. Maybe we should pull in some functionality from klibc, and place it in lib/ at some point in time.

+
+static char remcomInBuffer[BUFMAX]; +static char remcomOutBuffer[BUFMAX];
This does not follow usual Linux naming convention. Something like: remcom_in_buf, remcom_out_buf?

kernel/kgdbstub.c line 216

Quoted 11 lines
kernel/kgdbstub.c +11 -0
+static void getpacket(char *buffer)
+{
+	unsigned char checksum;
+	unsigned char xmitcsum;
+	int i;
+	int count;
+	char ch;
+
+	do {
+	/* wait around for the start character, ignore all other characters */
+		while ((ch = (kgdb_serial->read_char() & 0x7f)) != '$');

Placing ';' on a seperate line would be good for the readability.

kernel/kgdbstub.c line 653

Quoted 13 lines
kernel/kgdbstub.c +13 -0
+int kgdb_handle_exception(int exVector, int signo, int err_code, 
+                     struct pt_regs *linux_regs)
+{
+	unsigned long length, addr;
+	char *ptr;
+	unsigned long flags;
+	unsigned long gdb_regs[NUMREGBYTES / sizeof (unsigned long)];
+	int i;
+	long threadid;
+	threadref thref;
+	struct task_struct *thread = NULL;
+	unsigned procid;
+	static char tmpstr[256];

Too? large varriable on the stack.

#2 lore raw
Quoted 10 lines · Sam Ravnborg

Just some random comments after browsing the code.

Sam

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+int kgdb_hexToLong(char **ptr, long *longValue);

A patch has been posted by Tom Rini to convert this to the linux naming: kgdb_hex2long(...).

Quoted 4 lines

+static const char hexchars[] = "0123456789abcdef";
Grepping after 0123456789 in the src tree gives a lot of hits. Maybe we should pull in some functionality from klibc, and place it in lib/ at some point in time.

It is already there, in lib/vsprintf.c: simple_strtoul() and simple_strtol().

--bart

#3 lore raw
In reply to Sam Ravnborg

Hi!

Quoted 8 lines

Just some random comments after browsing the code.

Sam

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+int kgdb_hexToLong(char **ptr, long *longValue);

A patch has been posted by Tom Rini to convert this to the linux naming: kgdb_hex2long(...).

Yep, and I did the patch originially ;-).

Quoted 10 lines

+static const char hexchars[] = "0123456789abcdef";
Grepping after 0123456789 in the src tree gives a lot of hits. Maybe we should pull in some functionality from klibc, and place it in lib/ at some point in time.

kernel/kgdbstub.c +3 -0
+
+static char remcomInBuffer[BUFMAX];
+static char remcomOutBuffer[BUFMAX];

This does not follow usual Linux naming convention. Something like: remcom_in_buf, remcom_out_buf?

Yes, and getpacket should also become get_packet...

Quoted 14 lines

kernel/kgdbstub.c line 216

Quoted 11 lines
kernel/kgdbstub.c +11 -0
+static void getpacket(char *buffer)
+{
+	unsigned char checksum;
+	unsigned char xmitcsum;
+	int i;
+	int count;
+	char ch;
+
+	do {
+	/* wait around for the start character, ignore all other characters */
+		while ((ch = (kgdb_serial->read_char() & 0x7f)) != '$');

Placing ';' on a seperate line would be good for the readability.

Quoted 15 lines

kernel/kgdbstub.c line 653

Quoted 13 lines
kernel/kgdbstub.c +13 -0
+int kgdb_handle_exception(int exVector, int signo, int err_code, 
+                     struct pt_regs *linux_regs)
+{
+	unsigned long length, addr;
+	char *ptr;
+	unsigned long flags;
+	unsigned long gdb_regs[NUMREGBYTES / sizeof (unsigned long)];
+	int i;
+	long threadid;
+	threadref thref;
+	struct task_struct *thread = NULL;
+	unsigned procid;
+	static char tmpstr[256];

Too? large varriable on the stack.

Whi one?

tmpstr is static....
Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#4 lore raw
Quoted 7 lines
Quoted 3 lines

kernel/kgdbstub.c line 653

Quoted 1 line
kernel/kgdbstub.c +1 -0
+	static char tmpstr[256];

Too? large varriable on the stack.

Whi one?

tmpstr is static....

Yup tmpstr, missed the static.

Sam

#5 lore raw
In reply to Sam Ravnborg

Hi!

Quoted 4 lines

+static const char hexchars[] = "0123456789abcdef";
Grepping after 0123456789 in the src tree gives a lot of hits. Maybe we should pull in some functionality from klibc, and place it in lib/ at some point in time.

This one will have to wait, I fixed the others in the internal tree.

Here's the diff
Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
arch/i386/kernel/i386-stub.c +17 -17
@@ -283,7 +283,7 @@
 }
 
 int kgdb_arch_handle_exception(int exceptionVector, int signo,
-		int err_code, char *remcomInBuffer, char *remcomOutBuffer,
+		int err_code, char *remcom_in_buffer, char *remcom_out_buffer,
 		struct pt_regs *linux_regs)
 {
 	long addr, length;
@@ -292,19 +292,19 @@
 	int newPC;
 	int dr6;
 	
-	switch (remcomInBuffer[0]) {
+	switch (remcom_in_buffer[0]) {
 	case 'c':
 	case 's':
 		if (kgdb_contthread && kgdb_contthread != current) {
-			strcpy(remcomOutBuffer, "E00");
+			strcpy(remcom_out_buffer, "E00");
 			break;
 		}
 
 		kgdb_contthread = NULL;
 
 		/* try to read optional parameter, pc unchanged if no parm */
-		ptr = &remcomInBuffer[1];
-		if (kgdb_hexToLong(&ptr, &addr)) {
+		ptr = &remcom_in_buffer[1];
+		if (kgdb_hex2long(&ptr, &addr)) {
 			linux_regs->eip = addr;
 		} 
 		newPC = linux_regs->eip;
@@ -313,7 +313,7 @@
 		linux_regs->eflags &= 0xfffffeff;
 
 		/* set the trace bit if we're stepping */
-		if (remcomInBuffer[0] == 's') {
+		if (remcom_in_buffer[0] == 's') {
 			linux_regs->eflags |= 0x100;
 			debugger_step = 1;
 		}
@@ -336,30 +336,30 @@
 		return (0);
 
 	case 'Y':
-		ptr = &remcomInBuffer[1];
-		kgdb_hexToLong(&ptr, &breakno);
+		ptr = &remcom_in_buffer[1];
+		kgdb_hex2long(&ptr, &breakno);
 		ptr++;
-		kgdb_hexToLong(&ptr, &breaktype);
+		kgdb_hex2long(&ptr, &breaktype);
 		ptr++;
-		kgdb_hexToLong(&ptr, &length);
+		kgdb_hex2long(&ptr, &length);
 		ptr++;
-		kgdb_hexToLong(&ptr, &addr);
+		kgdb_hex2long(&ptr, &addr);
 		if (set_hw_break(breakno & 0x3, breaktype & 0x3, 
 				 length & 0x3, addr) == 0) {
-			strcpy(remcomOutBuffer, "OK");
+			strcpy(remcom_out_buffer, "OK");
 		} else {
-			strcpy(remcomOutBuffer, "ERROR");
+			strcpy(remcom_out_buffer, "ERROR");
 		}
 		break;
 
 		/* Remove hardware breakpoint */
 	case 'y':
-		ptr = &remcomInBuffer[1];
-		kgdb_hexToLong(&ptr, &breakno);
+		ptr = &remcom_in_buffer[1];
+		kgdb_hex2long(&ptr, &breakno);
 		if (remove_hw_break(breakno & 0x3) == 0) {
-			strcpy(remcomOutBuffer, "OK");
+			strcpy(remcom_out_buffer, "OK");
 		} else {
-			strcpy(remcomOutBuffer, "ERROR");
+			strcpy(remcom_out_buffer, "ERROR");
 		}
 		break;
 
arch/ppc/kernel/ppc-stub.c +5 -5
@@ -223,13 +223,13 @@
  * This function does PoerPC specific procesing for interfacing to gdb.
  */
 int kgdb_arch_handle_exception (int vector, int signo, int err_code,
-		char *remcomInBuffer, char *remcomOutBuffer,
+		char *remcom_in_buffer, char *remcom_out_buffer,
 		struct pt_regs *linux_regs)
 {
 	char *ptr;
 	unsigned long addr;
 	
-	switch (remcomInBuffer[0])
+	switch (remcom_in_buffer[0])
 		{
 		/*
 		 * sAA..AA   Step one instruction from AA..AA 
@@ -239,7 +239,7 @@
 		case 'c':
 			if (kgdb_contthread && kgdb_contthread != current)
 			{
-				strcpy(remcomOutBuffer, "E00");
+				strcpy(remcom_out_buffer, "E00");
 				break;
 			}
 
@@ -247,11 +247,11 @@
 
 			/* handle the optional parameter */
 			ptr = &remcomInBuffer[1];
-			if (kgdb_hexToLong (&ptr, &addr))
+			if (kgdb_hex2long (&ptr, &addr))
 				linux_regs->nip = addr;
 
 			/* set the trace bit if we're stepping */
-			if (remcomInBuffer[0] == 's')
+			if (remcom_in_buffer[0] == 's')
 			{
 #if defined (CONFIG_4xx)
 				linux_regs->msr |= MSR_DE;
arch/x86_64/kernel/x86_64-stub.c +17 -17
@@ -297,7 +297,7 @@
 }
 
 int kgdb_arch_handle_exception(int exceptionVector, int signo, int err_code,
-                                 char *remcomInBuffer, char *remcomOutBuffer,
+                                 char *remcom_in_buffer, char *remcom_out_buffer,
                                  struct pt_regs *linux_regs)
 {
 	unsigned long addr, length;
@@ -306,19 +306,19 @@
 	int newPC;
 	unsigned long dr6;
 	
-	switch (remcomInBuffer[0]) {
+	switch (remcom_in_buffer[0]) {
 	case 'c':
 	case 's':
 		if (kgdb_contthread && kgdb_contthread != current) {
-			strcpy(remcomOutBuffer, "E00");
+			strcpy(remcom_out_buffer, "E00");
 			break;
 		}
 
 		kgdb_contthread = NULL;
 
 		/* try to read optional parameter, pc unchanged if no parm */
-		ptr = &remcomInBuffer[1];
-		if (kgdb_hexToLong(&ptr, &addr)) {
+		ptr = &remcom_in_buffer[1];
+		if (kgdb_hex2long(&ptr, &addr)) {
 			linux_regs->rip = addr;
 		} 
 		newPC = linux_regs->rip;
@@ -327,7 +327,7 @@
 		linux_regs->eflags &= 0xfffffeff;
 
 		/* set the trace bit if we're stepping */
-		if (remcomInBuffer[0] == 's') {
+		if (remcom_in_buffer[0] == 's') {
 			linux_regs->eflags |= 0x100;
 			debugger_step = 1;
 		}
@@ -350,30 +350,30 @@
 		return (0);
 
 	case 'Y':
-		ptr = &remcomInBuffer[1];
-		kgdb_hexToLong(&ptr, &breakno);
+		ptr = &remcom_in_buffer[1];
+		kgdb_hex2long(&ptr, &breakno);
 		ptr++;
-		kgdb_hexToLong(&ptr, &breaktype);
+		kgdb_hex2long(&ptr, &breaktype);
 		ptr++;
-		kgdb_hexToLong(&ptr, &length);
+		kgdb_hex2long(&ptr, &length);
 		ptr++;
-		kgdb_hexToLong(&ptr, &addr);
+		kgdb_hex2long(&ptr, &addr);
 		if (set_hw_break(breakno & 0x3, breaktype & 0x3, 
 				 length & 0x3, addr) == 0) {
-			strcpy(remcomOutBuffer, "OK");
+			strcpy(remcom_out_buffer, "OK");
 		} else {
-			strcpy(remcomOutBuffer, "ERROR");
+			strcpy(remcom_out_buffer, "ERROR");
 		}
 		break;
 
 		/* Remove hardware breakpoint */
 	case 'y':
-		ptr = &remcomInBuffer[1];
-		kgdb_hexToLong(&ptr, &breakno);
+		ptr = &remcom_in_buffer[1];
+		kgdb_hex2long(&ptr, &breakno);
 		if (remove_hw_break(breakno & 0x3) == 0) {
-			strcpy(remcomOutBuffer, "OK");
+			strcpy(remcom_out_buffer, "OK");
 		} else {
-			strcpy(remcomOutBuffer, "ERROR");
+			strcpy(remcom_out_buffer, "ERROR");
 		}
 		break;
 
include/linux/kgdb.h +1 -1
@@ -105,7 +105,7 @@
 
 extern void kgdb8250_add_port(int i, struct uart_port *serial_req);
 
-int kgdb_hexToLong(char **ptr, long *longValue);
+int kgdb_hex2long(char **ptr, long *longValue);
 char *kgdb_mem2hex(char *mem, char *buf, int count);
 char *kgdb_hex2mem(char *buf, char *mem, int count);
 int kgdb_get_mem (char *addr, unsigned char *buf, int count);
kernel/kgdbstub.c +82 -81

410 lines not on this page · raw message

#6 lore raw
Quoted 8 lines · Pavel Machek

Hi!

Quoted 4 lines

+static const char hexchars[] = "0123456789abcdef"; Grepping after 0123456789 in the src tree gives a lot of hits. Maybe we should pull in some functionality from klibc, and place it in lib/ at some point in time.

This one will have to wait, I fixed the others in the internal tree.

Looks good.
Please checkin unless someone shouts.

Signature · 3 lines
Amit Kale
EmSysSoft (http://www.emsyssoft.com)
KGDB: Linux Kernel Source Level Debugger (http://kgdb.sourceforge.net)