Skip to contentSkip to conversation

kgdb cleanups

PATCH Pavel Machek 6 participants 21 messages Jan 9, 2004 – Jan 14, 2004

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

Hi!

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Pavel

Documentation/i386/kgdb/kgdb.txt renamed from linux/Documentation/i386/kgdb/kgdb.txt +4 -237
@@ -1,242 +1,9 @@
-Last edit: <20030806.1637.12>
-This file has information specific to the i386 kgdb option.  Other
-platforms with the kgdb option may behave in a similar fashion.
-
-New features:
-============
-20030806.1557.37
-This version was made against the 2.6.0-test2 kernel. We have made the
-following changes:
-
-- The getthread() code in the stub calls find_task_by_pid().  It fails
-  if we are early in the bring up such that the pid arrays have yet to
-  be allocated.  We have added a line to kernel/pid.c to make
-  "kgdb_pid_init_done" true once the arrays are allocated.  This way the
-  getthread() code knows not to call.  This is only used by the thread
-  debugging stuff and threads will not yet exist at this point in the
-  boot.
-
-- For some reason, gdb was not asking for a new thread list when the
-  "info thread" command was given.  We changed to the newer version of
-  the thread info command and gdb now seems to ask when needed.  Result,
-  we now get all threads in the thread list.
-
-- We now respond to the ThreadExtraInfo request from gdb with the thread
-  name from task_struct .comm.  This then appears in the thread list.
-  Thoughts on additional options for this are welcome.  Things such as
-  "has BKL" and "Preempted" come to mind.  I think we could have a flag
-  word that could enable different bits of info here.
-
-- We now honor, sort of, the C and S commands.  These are continue and
-  single set after delivering a signal.  We ignore the signal and do the
-  requested action.  This only happens when we told gdb that a signal
-  was the reason for entry, which is only done on memory faults.  The
-  result is that you can now continue into the Oops.
-
-- We changed the -g to -gdwarf-2.  This seems to be the same as -ggdb,
-  but it is more exact on what language to use.
-
-- We added two dwarf2 include files and a bit of code at the end of
-  entry.S.  This does not yet work, so it is disabled.  Still we want to
-  keep track of the code and "maybe" someone out there can fix it.
-
-- Randy Dunlap sent some fix ups for this file which are now merged.
-
-- Hugh Dickins sent a fix to a bit of code in traps.c that prevents a
-  compiler warning if CONFIG_KGDB is off (now who would do that :).
-
-- Andrew Morton sent a fix for the serial driver which is now merged.
-
-- Andrew also sent a change to the stub around the cpu managment code
-  which is also merged.
-
-- Andrew also sent a patch to make "f" as well as "g" work as SysRq
-  commands to enter kgdb, merged.
-
-- If CONFIG_KGDB and CONFIG_DEBUG_SPINLOCKS are both set we added a
-  "who" field to the spinlock data struct.  This is filled with
-  "current" when ever the spinlock suceeds.  Useful if you want to know
-  who has the lock.
-
-_ And last, but not least, we fixed the "get_cu" macro to properly get
-  the current value of "current".
-
-New features:
-============
-20030505.1827.27
-We are starting to align with the sourceforge version, at least in
-commands.  To this end, the boot command string to start kgdb at
-boot time has been changed from "kgdb" to "gdb".
-
-Andrew Morton sent a couple of patches which are now included as follows:
-1.) We now return a flag to the interrupt handler.
-2.) We no longer use smp_num_cpus (a conflict with the lock meter).
-3.) And from William Lee Irwin III <[email protected]> code to make
-    sure high-mem is set up before we attempt to register our interrupt
-    handler.
-We now include asm/kgdb.h from config.h so you will most likely never
-have to include it.  It also 'NULLS' the kgdb macros you might have in
-your code when CONFIG_KGDB is not defined.  This allows you to just
-turn off CONFIG_KGDB to turn off all the kgdb_ts() calls and such.
-This include is conditioned on the machine being an x86 so as to not
-mess with other archs.
-
-20020801.1129.03
-This is currently the version for the 2.4.18 (and beyond?) kernel.
-
-We have several new "features" beginning with this version:
-
-1.) Kgdb now syncs the "other" CPUs with a cross-CPU NMI.  No more
-    waiting and it will pull that guy out of an IRQ off spin lock :)
-
-2.) We doctored up the code that tells where a task is waiting and
-    included it so that the "info thread" command will show a bit more
-    than "schedule()".  Try it...
-
-3.) Added the ability to call a function from gdb.  All the standard gdb
-    issues apply, i.e. if you hit a breakpoint in the function, you are
-    not allowed to call another (gdb limitation, not kgdb).  To help
-    this capability we added a memory allocation function.  Gdb does not
-    return this memory (it is used for strings that you pass to that function
-    you are calling from gdb) so we fixed up a way to allow you to
-    manually return the memory (see below).
-
-4.) Kgdb time stamps (kgdb_ts()) are enhanced to expand what was the
-    interrupt flag to now also include the preemption count and the
-    "in_interrupt" info.  The flag is now called "with_pif" to indicate
-    the order, preempt_count, in_interrupt, flag.  The preempt_count is
-    shifted left by 4 bits so you can read the count in hex by dropping
-    the low order digit.  In_interrupt is in bit 1, and the flag is in
-    bit 0.
-
-5.) The command: "p kgdb_info" is now expanded and prints something
-    like:
-(gdb) p kgdb_info
-$2 = {used_malloc = 0, called_from = 0xc0107506, entry_tsc = 67468627259,
-  errcode = 0, vector = 3, print_debug_info = 0, hold_on_sstep = 1,
-  cpus_waiting = {{task = 0xc027a000, pid = 32768, hold = 0,
-      regs = 0xc027bf84}, {task = 0x0, pid = 0, hold = 0, regs = 0x0}}}
-
-    Things to note here: a.) used_malloc is the amount of memory that
-    has been malloc'ed to do calls from gdb.  You can reclaim this
-    memory like this: "p kgdb_info.used_malloc=0" Cool, huh?  b.)
-    cpus_waiting is now "sized" by the number of CPUs you enter at
-    configure time in the kgdb configure section.  This is NOT used
-    anywhere else in the system, but it is "nice" here.  c.)  The task's
-    "pid" is now in the structure.  This is the pid you will need to use
-    to decode to the thread id to get gdb to look at that thread.
-    Remember that the "info thread" command prints a list of threads
-    wherein it numbers each thread with its reference number followed
-    by the thread's pid.  Note that the per-CPU idle threads actually
-    have pids of 0 (yes, there is more than one pid 0 in an SMP system).
-    To avoid confusion, kgdb numbers these threads with numbers beyond
-    the MAX_PID.  That is why you see 32768 and above.
-
-6.) A subtle change, we now provide the complete register set for tasks
-    that are active on the other CPUs.  This allows better trace back on
-    those tasks.
-
-    And, let's mention what we could not fix.  Back-trace from all but the
-    thread that we trapped will, most likely, have a bogus entry in it.
-    The problem is that gdb does not recognize the entry code for
-    functions that use "current" near (at all?) the entry.  The compiler
-    is putting the "current" decode as the first two instructions of the
-    function where gdb expects to find %ebp changing code.  Back trace
-    also has trouble with interrupt frames.  I am talking with Daniel
-    Jacobowitz about some way to fix this, but don't hold your breath.
-
-20011220.0050.35
-Major enhancement with this version is the ability to hold one or more
-CPUs in an SMP system while allowing the others to continue.  Also, by
-default only the current CPU is enabled on single-step commands (please
-note that gdb issues single-step commands at times other than when you
-use the si command).
-
-Another change is to collect some useful information in
-a global structure called "kgdb_info".  You should be able to just:
-
-p kgdb_info
-
-although I have seen cases where the first time this is done gdb just
-prints the first member but prints the whole structure if you then enter
-CR (carriage return or enter).  This also works:
-
-p *&kgdb_info
-
-Here is a sample:
-(gdb) p kgdb_info
-$4 = {called_from = 0xc010732c, entry_tsc = 32804123790856, errcode = 0,
-  vector = 3, print_debug_info = 0}
-
-"Called_from" is the return address from the current entry into kgdb.
-Sometimes it is useful to know why you are in kgdb, for example, was
-it an NMI or a real breakpoint?  The simple way to interrogate this
-return address is:
-
-l *0xc010732c
-
-which will print the surrounding few lines of source code.
-
-"Entry_tsc" is the CPU TSC on entry to kgdb (useful to compare to the
-kgdb_ts entries).
-
-"errcode" and "vector" are other entry parameters which may be helpful on
-some traps.
-
-"print_debug_info" is the internal debugging kgdb print enable flag.  Yes,
-you can modify it.
-
-In SMP systems kgdb_info also includes the "cpus_waiting" structure and
-"hold_on_step":
-
-(gdb) p kgdb_info
-$7 = {called_from = 0xc0112739, entry_tsc = 1034936624074, errcode = 0,
-  vector = 2, print_debug_info = 0, hold_on_sstep = 1, cpus_waiting = {{
-      task = 0x0, hold = 0, regs = 0x0}, {task = 0xc71b8000, hold = 0,
-      regs = 0xc71b9f70}, {task = 0x0, hold = 0, regs = 0x0}, {task = 0x0,
-      hold = 0, regs = 0x0}, {task = 0x0, hold = 0, regs = 0x0}, {task = 0x0,
-      hold = 0, regs = 0x0}, {task = 0x0, hold = 0, regs = 0x0}, {task = 0x0,
-      hold = 0, regs = 0x0}}}
-
-"Cpus_waiting" has an entry for each CPU other than the current one that
-has been stopped.  Each entry contains the task_struct address for that
-CPU, the address of the regs for that task and a hold flag.  All these
-have the proper typing so that, for example:
-
-p *kgdb_info.cpus_waiting[1].regs
-
-will print the registers for CPU 1.
-
-"Hold_on_sstep" is a new feature with this version and comes up set or
-true.  What this means is that whenever kgdb is asked to single-step all
-other CPUs are held (i.e. not allowed to execute).  The flag applies to
-all but the current CPU and, again, can be changed:
-
-p kgdb_info.hold_on_sstep=0
-
-restores the old behavior of letting all CPUs run during single-stepping.
-
-Likewise, each CPU has a "hold" flag, which if set, locks that CPU out
-of execution.  Note that this has some risk in cases where the CPUs need
-to communicate with each other.  If kgdb finds no CPU available on exit,
-it will push a message thru gdb and stay in kgdb.  Note that it is legal
-to hold the current CPU as long as at least one CPU can execute.
-
-20010621.1117.09
-This version implements an event queue.  Events are signaled by calling
-a function in the kgdb stub and may be examined from gdb.  See EVENTS
-below for details.  This version also tightens up the interrupt and SMP
-handling to not allow interrupts on the way to kgdb from a breakpoint
-trap.  It is fine to allow these interrupts for user code, but not
-system debugging.
-
 Version
 =======
 
-This version of the kgdb package was developed and tested on
-kernel version 2.4.16.  It will not install on any earlier kernels.
-It is possible that it will continue to work on later versions
-of 2.4 and then versions of 2.5 (I hope).
+This version of the kgdb package was developed and tested on kernel
+version 2.6.0.  It is possible that it will continue to work on later
+versions of 2.6.
 
 
 Debugging Setup
@@ -314,7 +81,7 @@
 set up after any serial drivers, it is possible that this command will
 work when the control-C will not.
 
-Save and exit the Xconfig program.  Then do "make clean" , "make dep"
+Save and exit the Xconfig program.  Then do "make clean"
 and "make bzImage" (or whatever target you want to make).  This gets the
 kernel compiled with the "-g" option set -- necessary for debugging.
 
Documentation/i386/kgdb/kgdbeth.txt renamed from linux/Documentation/i386/kgdb/kgdbeth.txt +4 -4
diff -ur -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x vmlinuz -x TAGS -x bootsect -x '*RCS*' -x conmakehash -x map -x build -x build -x configure -x '*target*' -x '*.flags' -x '*.bak' -x '*.cmd' tmp/linux/Documentation/i386/kgdb/kgdbeth.txt linux/Documentation/i386/kgdb/kgdbeth.txt
@@ -33,8 +33,8 @@
 
   gdbeth=DEVICENUM
   gdbeth_remoteip=HOSTIPADDR
-  gdbeth_remotemac=REMOTEMAC
-  gdbeth_localmac=LOCALMAC
+  gdbeth_remotemac=HOSTMAC
+  gdbeth_localmac=TARGETMAC
 
 kgdbeth=DEVICENUM sets the ethernet device number to listen on for
 debugging packets.  e.g. kgdbeth=0 listens on eth0.
@@ -43,10 +43,10 @@
 Only packets originating from this IP address will be accepted by the
 debugger.  e.g. kgdbeth_remoteip=192.168.2.2
 
-kgdbeth_remotemac=REMOTEMAC sets the ethernet address of the HOST machine.
+kgdbeth_remotemac=HOSTMAC sets the ethernet address of the HOST machine.
 e.g. kgdbeth_remotemac=00:07:70:12:4E:F5
 
-kgdbeth_localmac=LOCALMAC sets the ethernet address of the TARGET machine.
+kgdbeth_localmac=TARGETMAC sets the ethernet address of the TARGET machine.
 e.g. kgdbeth_localmac=00:10:9F:18:21:3C
 
 You can also set the following command-line option on the TARGET kernel:
arch/i386/kernel/entry.S renamed from linux/arch/i386/kernel/entry.S +0 -58

70 lines not on this page · raw message

arch/i386/kernel/kgdb_stub.c renamed from linux/arch/i386/kernel/kgdb_stub.c +23 -799

992 lines not on this page · raw message

drivers/net/kgdb_eth.c renamed from linux/drivers/net/kgdb_eth.c +6 -7
@@ -39,12 +39,12 @@
 
 #define	GDB_BUF_SIZE	512		/* power of 2, please */
 
-static char	kgdb_buf[GDB_BUF_SIZE] ;
-static int	kgdb_buf_in_inx ;
-static atomic_t	kgdb_buf_in_cnt ;
-static int	kgdb_buf_out_inx ;
+static char	kgdb_buf[GDB_BUF_SIZE];
+static int	kgdb_buf_in_inx;
+static atomic_t	kgdb_buf_in_cnt;
+static int	kgdb_buf_out_inx;
 
-extern void	set_debug_traps(void) ;		/* GDB routine */
+extern void	set_debug_traps(void);		/* GDB routine */
 extern void	breakpoint(void);
 
 unsigned int	kgdb_remoteip = 0;
@@ -479,8 +479,7 @@
 put_char_on_queue(int chr)
 {
 	eth_queue[outgoing_queue++] = chr;
-	if(outgoing_queue == ETH_QUEUE_SIZE)
-	{
+	if(outgoing_queue == ETH_QUEUE_SIZE) {
 		eth_flushDebugChar();
 	}
 }
include/asm-i386/kgdb_local.h renamed from linux/include/asm-i386/kgdb_local.h +2 -2
@@ -83,7 +83,7 @@
       tty:   (struct tty_struct *)&state, \
       IER:   SB_IER,       \
       MCR:   SB_MCR}
-extern void putDebugChar(int);
+extern void put_debug_char(int);
 /* RTAI support needs us to really stop/start interrupts */
 
 #define kgdb_sti() __asm__ __volatile__("sti": : :"memory")
@@ -98,5 +98,5 @@
 #ifdef CONFIG_SERIAL
 extern void shutdown_for_kgdb(struct async_struct *info);
 #endif
-#define INIT_KDEBUG putDebugChar("+");
+#define INIT_KDEBUG put_debug_char("+");	/* WTF is this? it expects integer! */
 #endif				/* __KGDB_LOCAL */
include/linux/dwarf2-lang.h renamed from linux/include/linux/dwarf2-lang.h +0 -132

132 lines not on this page · raw message

include/linux/dwarf2.h renamed from linux/include/linux/dwarf2.h +0 -738

738 lines not on this page · raw message

kernel/kgdb.c renamed from linux/kernel/kgdb.c +750 -0

750 lines not on this page · raw message

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

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Could you please work this with the kgdb developers?

Jim Houston <[email protected]>
george anzinger <[email protected]>
"Amit S. Kale" <[email protected]>

Because merging this might stomp all over work which they have in progress.

(But thanks: kgdb does need a cleanup)

#2 lore raw
In reply to Pavel Machek
Quoted 9 lines · Pavel Machek

Hi!

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Pavel

A few comments:

I like the code seperation. Does it follow what Amit is doing? It would be nice if Amit's version and this one could come together around this.

I don't think we want to merge the eth and regular kgdb just yet. I would, however, like to keep eth completly out of the stub. Possibly a new module which just takes care of steering the I/O to the correct place.

I think we might want to try the bad sys call one more time. If it triggers, a kernel fix is in order. I don't see the point of removing it. After all, the disable/enable on preempt really should be paired such that we never leave the kernel with a preempt count.

I have new dwarft stuff. I actually have debug records that allow bt through interrupt code. Working on the spin lock loops. It is fine to drop these at this point as the new ones will replace them anyway.

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#3 lore raw
Quoted 10 lines · George Anzinger
Quoted 9 lines · Pavel Machek

Hi!

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Pavel

Quoted 8 lines

A few comments:

I like the code seperation. Does it follow what Amit is doing? It would be nice if Amit's version and this one could come together around this.

I don't think we want to merge the eth and regular kgdb just yet. I would, however, like to keep eth completly out of the stub. Possibly a new module which just takes care of steering the I/O to the correct place.

I've sent Amit the start of an plug interface for abstracting the communication layer. Should be relatively painless and allow for starting sessions on the interface of your choice.

Signature · 1 line
Matt Mackall : http://www.selenic.com : Linux development and consulting
#4 lore raw
Quoted 16 lines · Matt Mackall
Quoted 14 lines · George Anzinger
Quoted 9 lines · Pavel Machek

Hi!

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Pavel

A few comments:

Quoted 9 lines
Quoted 3 lines

I like the code seperation. Does it follow what Amit is doing? It would be nice if Amit's version and this one could come together around this.

I don't think we want to merge the eth and regular kgdb just yet. I would, however, like to keep eth completly out of the stub. Possibly a new module which just takes care of steering the I/O to the correct place.

I've sent Amit the start of an plug interface for abstracting the communication layer. Should be relatively painless and allow for starting sessions on the interface of your choice.

May I see?

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#5 lore raw
Quoted 25 lines · George Anzinger
Quoted 24 lines · Matt Mackall
Quoted 20 lines · George Anzinger
Quoted 9 lines · Pavel Machek

Hi!

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Pavel

A few comments:

I like the code seperation. Does it follow what Amit is doing? It would be nice if Amit's version and this one could come together around this.

I don't think we want to merge the eth and regular kgdb just yet. I would, however, like to keep eth completly out of the stub. Possibly a new module which just takes care of steering the I/O to the correct place.

Quoted 5 lines
Quoted 4 lines

I've sent Amit the start of an plug interface for abstracting the communication layer. Should be relatively painless and allow for starting sessions on the interface of your choice.

May I see?

Here's the interface plus the eth side of it:

 tiny-mpm/arch/i386/kernel/kgdb_stub.c |   59 +++++++++-------------------------
 tiny-mpm/drivers/net/kgdb_eth.c       |   26 +++++++++-----
 tiny-mpm/include/asm-i386/kgdb.h      |   14 +++++---
 3 files changed, 44 insertions(+), 55 deletions(-)
include/asm-i386/kgdb.h renamed from include/asm-i386/kgdb.h~kgdb-plug +10 -4
diff -puN include/asm-i386/kgdb.h~kgdb-plug include/asm-i386/kgdb.h
@@ -19,13 +19,19 @@ extern void breakpoint(void);
 #define BREAKPOINT   asm("   int $3")
 #endif
 
+struct kgdb_hook {
+	char *sendbuf;
+	int maxsend;
+	int (*getchar)(void);
+	void (*putchar)(int chr);
+	void (*flush)(void);
+	void (*trap)(int enable);
+};
+
+extern void kgdb_attach(struct kgdb_hook *hook);
 extern void kgdb_schedule_breakpoint(void);
 extern void kgdb_process_breakpoint(void);
 
-extern int kgdb_tty_hook(void);
-extern int kgdb_eth_hook(void);
-extern int kgdboe;
-
 /*
  * GDB debug stub (or any debug stub) can point the 'linux_debug_hook'
  * pointer to its routine and it will be entered as the first thing
arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +17 -42

126 lines not on this page · raw message

diff -puN arch/i386/lib/kgdb_serial.c~kgdb-plug arch/i386/lib/kgdb_serial.c

drivers/net/kgdb_eth.c renamed from drivers/net/kgdb_eth.c~kgdb-plug +17 -9
diff -puN drivers/net/kgdb_eth.c~kgdb-plug drivers/net/kgdb_eth.c
@@ -34,8 +34,6 @@ static int in_head, in_tail, out_count;
 static atomic_t in_count;
 int kgdboe = 0; /* Default to tty mode */
 
-extern void set_debug_traps(void);
-extern void breakpoint(void);
 static void rx_hook(struct netpoll *np, int port, char *msg, int len);
 
 static struct netpoll np = {
@@ -47,7 +45,7 @@ static struct netpoll np = {
 	.remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
 };
 
-int eth_getDebugChar(void)
+static int getchar(void)
 {
 	int chr;
 
@@ -60,7 +58,7 @@ int eth_getDebugChar(void)
 	return chr;
 }
 
-void eth_flushDebugChar(void)
+static void flush(void)
 {
 	if(out_count && np.dev) {
 		netpoll_send_udp(&np, out_buf, out_count);
@@ -68,13 +66,24 @@ void eth_flushDebugChar(void)
 	}
 }
 
-void eth_putDebugChar(int chr)
+static void putchar(int chr)
 {
 	out_buf[out_count++] = chr;
 	if(out_count == OUT_BUF_SIZE)
 		eth_flushDebugChar();
 }
 
+#define MAX_SEND 30
+char sendbuf[MAX_SEND];
+static struct kgdb_hook kh = {
+	.sendbuf = sendbuf,
+	.maxsend = MAX_SEND
+	.getchar = getchar,
+	.putchar = putchar,
+	.flush = flush,
+	.trap = netpoll_set_trap
+};
+
 static void rx_hook(struct netpoll *np, int port, char *msg, int len)
 {
 	int i;
@@ -82,8 +91,10 @@ static void rx_hook(struct netpoll *np, 
 	np->remote_port = port;
 
 	/* Is this gdb trying to attach? */
-	if (!netpoll_trap() && len == 8 && !strncmp(msg, "$Hc-1#09", 8))
+	if (!netpoll_trap() && len == 8 && !strncmp(msg, "$Hc-1#09", 8)) {
+		kgdb_attach(kh);
 		kgdb_schedule_breakpoint();
+	}
 
 	for (i = 0; i < len; i++) {
 		if (msg[i] == 3)
@@ -117,12 +128,9 @@ static int init_kgdboe(void)
 	}
 #endif
 
-	set_debug_traps();
-
 	if(!np.remote_ip || netpoll_setup(&np))
 		return 1;
 
-	kgdboe = 1;
 	printk(KERN_INFO "kgdb: debugging over ethernet enabled\n");
 
 	return 0;

_

Signature · 1 line
Matt Mackall : http://www.selenic.com : Linux development and consulting
#6 lore raw

Hi!

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 18 lines
Quoted 9 lines

Hi!

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Pavel

A few comments:

I like the code seperation. Does it follow what Amit is doing? It would be nice if Amit's version and this one could come together around this.

I don't think we want to merge the eth and regular kgdb just yet. I would, however, like to keep eth completly out of the stub. Possibly a new module which just takes care of steering the I/O to the correct place.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

I've sent Amit the start of an plug interface for abstracting the communication layer. Should be relatively painless and allow for starting sessions on the interface of your choice.

May I see?

Here's the interface plus the eth side of it:

Does it work with those patches? (Amid's version does not seem to work over ethernet).
Pavel

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

Hi!

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 10 lines
Quoted 9 lines

Hi!

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Pavel

Quoted 8 lines

A few comments:

I like the code seperation. Does it follow what Amit is doing? It would be nice if Amit's version and this one could come together around this.

I don't think we want to merge the eth and regular kgdb just yet. I would, however, like to keep eth completly out of the stub. Possibly a new module which just takes care of steering the I/O to the correct place.

I've sent Amit the start of an plug interface for abstracting the communication layer. Should be relatively painless and allow for starting sessions on the interface of your choice.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

May I see?

Here's the interface plus the eth side of it:

Does it work with those patches? (Amid's version does not seem to work over ethernet).

The stuff currently in -mm and -tiny works. The "pluggable" bits are proof of concept at this stage and I've been busy working on other things - was hoping someone else would run with them.

Signature · 1 line
Matt Mackall : http://www.selenic.com : Linux development and consulting
#8 lore raw
In reply to Matt Mackall
Quoted 27 lines · Matt Mackall
Quoted 25 lines · George Anzinger
Quoted 23 lines · Matt Mackall
Quoted 18 lines · George Anzinger
Quoted 9 lines · Pavel Machek

Hi!

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Pavel

A few comments:

I like the code seperation. Does it follow what Amit is doing? It would be nice if Amit's version and this one could come together around this.

I don't think we want to merge the eth and regular kgdb just yet. I would, however, like to keep eth completly out of the stub. Possibly a new module which just takes care of steering the I/O to the correct place.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

I've sent Amit the start of an plug interface for abstracting the communication layer. Should be relatively painless and allow for starting sessions on the interface of your choice.

May I see?

A few comments:

First, I would like to keep kgdb.h for the user of kgdb so that it may be included without concern most anywhere. In this light I think it should only contain the breakpoint macro and the timestamp macro stuff, i.e. those things that a user might want to put in his code.

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Other comments below.

Quoted 13 lines

Here's the interface plus the eth side of it:

 tiny-mpm/arch/i386/kernel/kgdb_stub.c |   59 +++++++++-------------------------
 tiny-mpm/drivers/net/kgdb_eth.c       |   26 +++++++++-----
 tiny-mpm/include/asm-i386/kgdb.h      |   14 +++++---
 3 files changed, 44 insertions(+), 55 deletions(-)

diff -puN include/asm-i386/kgdb.h~kgdb-plug include/asm-i386/kgdb.h

include/asm-i386/kgdb.h extern void breakpoint(void); · line 24

Quoted 6 lines
include/asm-i386/kgdb.h renamed from include/asm-i386/kgdb.h~kgdb-plug +3 -0
@@ -19,13 +19,19 @@ extern void breakpoint(void);
 #define BREAKPOINT   asm("   int $3")
 #endif
 
+struct kgdb_hook {
+	char *sendbuf;
+	int maxsend;

I don't see the need of maxsend, or sendbuff, for that matter, as kgdb uses it now (for the eth code) it is redundant, in that the eth putchar also does the same thing as is being done in the kgdb_stub.c code. I think this should be removed from the stub and the limit in the ethcode relied upon.

Quoted 44 lines
include/asm-i386/kgdb.h renamed from include/asm-i386/kgdb.h~kgdb-plug +7 -4
+	int (*getchar)(void);
+	void (*putchar)(int chr);
+	void (*flush)(void);
+	void (*trap)(int enable);
+};
+
+extern void kgdb_attach(struct kgdb_hook *hook);
 extern void kgdb_schedule_breakpoint(void);
 extern void kgdb_process_breakpoint(void);
 
-extern int kgdb_tty_hook(void);
-extern int kgdb_eth_hook(void);
-extern int kgdboe;
-
 /*
  * GDB debug stub (or any debug stub) can point the 'linux_debug_hook'
  * pointer to its routine and it will be entered as the first thing

diff -puN arch/i386/kernel/kgdb_stub.c~kgdb-plug arch/i386/kernel/kgdb_stub.c

arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +1 -11
@@ -130,12 +130,7 @@ typedef void (*Function) (void);	/* poin
 /* Thread reference */
 typedef unsigned char threadref[8];
 
-extern int tty_putDebugChar(int);     /* write a single character      */
-extern int tty_getDebugChar(void);    /* read and return a single char */
-extern void tty_flushDebugChar(void); /* flush pending characters      */
-extern int eth_putDebugChar(int);     /* write a single character      */
-extern int eth_getDebugChar(void);    /* read and return a single char */
-extern void eth_flushDebugChar(void); /* flush pending characters      */
+struct kgdb_hook *kh = 0;
 
 /************************************************************************/
 /* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
@@ -275,39 +270,25 @@ malloc(int size)
 	}
 }
 
-/*
- * I/O dispatch functions...
- * Based upon kgdboe, either call the ethernet
- * handler or the serial one..
- */
 void

arch/i386/kernel/kgdb_stub.c malloc(int size) · line 278

Quoted 10 lines
arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +2 -5
 putDebugChar(int c)
 {
-	if (!kgdboe) {
-		tty_putDebugChar(c);
-	} else {
-		eth_putDebugChar(c);
-	}
+	if (kh)
+		kh->putchar(c);
 }

I was thinking that this might read something like:

         if (xxx[kh].putchar(c))
                xxx[kh].putchar(c);

One might further want to do something like:

         if (!xxx[kh].putchar(c))
                kh = 0;

In otherwords, an array (xxx must, of course, be renamed) of stuct kgdb_hook (which name should also be changed to relate to I/O, kgdb_IO_hook, for example).
Then reserve entry 0 for the rs232 I/O code. An alternate possibility is an
array of pointer to struct kgdb_hook which allows one to define the struct contents as below and to build the array, all at compile/link time. A legal entry MUST define get and put, but why not define them all, using dummy functions for the ones that make no sense in a particular interface.

I also think the functions that kgdb_stub calls should be putDebugChar and friends, not the underlying functions. I.e. move these out of kgdb_stub.c to a new common module. This would make it easy for other archs to use, as they would be using something that looks very much like what they do today. So, in short, kdgd_stub.c needs to know nothing of kh or the structure it references.

I would also like to see the index (kh in my code) in the kgdb_info structure so that the user can examine it. I am not sure if I want to allow him to change it, but I have considered it.

Quoted 47 lines
arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +5 -14
 int
 getDebugChar(void)
 {
-	if (!kgdboe) {
-		return tty_getDebugChar();
-	} else {
-		return eth_getDebugChar();
-	}
+	if (kh)
+		return kh->getchar();
 }
 
 void
 flushDebugChar(void)
 {
-	if (!kgdboe) {
-		tty_flushDebugChar();
-	} else {
-		eth_flushDebugChar();
-	}
+	if (kh)
+		kh->flush();
 }
 
 /*
@@ -490,7 +471,7 @@ putpacket(char *buffer)
 
 	/*  $<packet info>#<checksum>. */
 
-	if (!kgdboe) {
+	if (kh && !kh->sendbuf) {
 		do {
 			if (remote_debug)
 				printk("T:%s\n", buffer);
@@ -516,10 +497,7 @@ putpacket(char *buffer)
 		 * We only transfer MAX_SEND_COUNT size bytes each time
 		 */
 
-#define MAX_SEND_COUNT 30
-
 		int send_count = 0, i = 0;
-		char send_buf[MAX_SEND_COUNT];
 
 		do {
 			if (remote_debug)

arch/i386/kernel/kgdb_stub.c putpacket(char *buffer) · line 513

Quoted 10 lines
arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +3 -3
@@ -529,21 +507,21 @@ putpacket(char *buffer)
 			count = 0;
 			send_count = 0;
 			while ((ch = buffer[count])) {
-				if (send_count >= MAX_SEND_COUNT) {
-					for(i = 0; i < MAX_SEND_COUNT; i++) {
-						putDebugChar(send_buf[i]);
+				if (send_count >= kh->maxsend) {
+					for(i = 0; i < kh->maxsend; i++) {
+						putDebugChar(kh->sendbuf[i]);
 					}

As I observed above, the eth code already does all this. This code is redundant and should be removed.

Quoted 128 lines
arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +6 -9
 					flushDebugChar();
 					send_count = 0;
 				} else {
-					send_buf[send_count] = ch;
+					kh->sendbuf[send_count] = ch;
 					checksum += ch;
 					count ++;
 					send_count++;
 				}
 			}
 			for(i = 0; i < send_count; i++)
-				putDebugChar(send_buf[i]);
+				putDebugChar(kh->sendbuf[i]);
 			putDebugChar('#');
 			putDebugChar(hexchars[checksum >> 4]);
 			putDebugChar(hexchars[checksum % 16]);
@@ -1272,12 +1250,9 @@ kgdb_handle_exception(int exceptionVecto
 		print_regs(&regs);
 		return (0);
 	}
-	/*
-	 * If we're using eth mode, set the 'mode' in the netdevice.
-	 */
 
-	if (kgdboe)
-		netpoll_set_trap(1);
+	if (kh)
+		kh->trap(1);
 
 	kgdb_local_irq_save(flags);
 
@@ -1727,8 +1702,8 @@ kgdb_handle_exception(int exceptionVecto
 				}
 			}
 
-			if (kgdboe)
-				netpoll_set_trap(0);
+			if(kh)
+				kh->trap(0);
 
 			correct_hw_break();
 			asm volatile ("movl %0, %%db6\n"::"r" (0));

diff -puN arch/i386/lib/kgdb_serial.c~kgdb-plug arch/i386/lib/kgdb_serial.c diff -puN drivers/net/kgdb_eth.c~kgdb-plug drivers/net/kgdb_eth.c

drivers/net/kgdb_eth.c renamed from drivers/net/kgdb_eth.c~kgdb-plug +17 -9
@@ -34,8 +34,6 @@ static int in_head, in_tail, out_count;
 static atomic_t in_count;
 int kgdboe = 0; /* Default to tty mode */
 
-extern void set_debug_traps(void);
-extern void breakpoint(void);
 static void rx_hook(struct netpoll *np, int port, char *msg, int len);
 
 static struct netpoll np = {
@@ -47,7 +45,7 @@ static struct netpoll np = {
 	.remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
 };
 
-int eth_getDebugChar(void)
+static int getchar(void)
 {
 	int chr;
 
@@ -60,7 +58,7 @@ int eth_getDebugChar(void)
 	return chr;
 }
 
-void eth_flushDebugChar(void)
+static void flush(void)
 {
 	if(out_count && np.dev) {
 		netpoll_send_udp(&np, out_buf, out_count);
@@ -68,13 +66,24 @@ void eth_flushDebugChar(void)
 	}
 }
 
-void eth_putDebugChar(int chr)
+static void putchar(int chr)
 {
 	out_buf[out_count++] = chr;
 	if(out_count == OUT_BUF_SIZE)
 		eth_flushDebugChar();
 }
 
+#define MAX_SEND 30
+char sendbuf[MAX_SEND];
+static struct kgdb_hook kh = {
+	.sendbuf = sendbuf,
+	.maxsend = MAX_SEND
+	.getchar = getchar,
+	.putchar = putchar,
+	.flush = flush,
+	.trap = netpoll_set_trap
+};
+
 static void rx_hook(struct netpoll *np, int port, char *msg, int len)
 {
 	int i;
@@ -82,8 +91,10 @@ static void rx_hook(struct netpoll *np, 
 	np->remote_port = port;
 
 	/* Is this gdb trying to attach? */
-	if (!netpoll_trap() && len == 8 && !strncmp(msg, "$Hc-1#09", 8))
+	if (!netpoll_trap() && len == 8 && !strncmp(msg, "$Hc-1#09", 8)) {
+		kgdb_attach(kh);
 		kgdb_schedule_breakpoint();
+	}
 
 	for (i = 0; i < len; i++) {
 		if (msg[i] == 3)
@@ -117,12 +128,9 @@ static int init_kgdboe(void)
 	}
 #endif
 
-	set_debug_traps();
-
 	if(!np.remote_ip || netpoll_setup(&np))
 		return 1;
 
-	kgdboe = 1;
 	printk(KERN_INFO "kgdb: debugging over ethernet enabled\n");
 
 	return 0;

_

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#9 lore raw
Quoted 3 lines · George Anzinger

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Agreed, I just haven't touched it since you last mentioned it.

Quoted 8 lines

include/asm-i386/kgdb.h extern void breakpoint(void); · line 24

Quoted 3 lines
include/asm-i386/kgdb.h renamed from include/asm-i386/kgdb.h~kgdb-plug +3 -0
+struct kgdb_hook {
+	char *sendbuf;
+	int maxsend;

I don't see the need of maxsend, or sendbuff, for that matter, as kgdb uses it now (for the eth code) it is redundant, in that the eth putchar also does the same thing as is being done in the kgdb_stub.c code. I think this should be removed from the stub and the limit in the ethcode relied upon.

Fair enough.

Quoted 16 lines
Quoted 11 lines

void
putDebugChar(int c)
{

arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +2 -5
-	if (!kgdboe) {
-		tty_putDebugChar(c);
-	} else {
-		eth_putDebugChar(c);
-	}
+	if (kh)
+		kh->putchar(c);

}

I was thinking that this might read something like:

         if (xxx[kh].putchar(c))
                xxx[kh].putchar(c);
Quoted 7 lines

One might further want to do something like:

         if (!xxx[kh].putchar(c))
                kh = 0;

In otherwords, an array (xxx must, of course, be renamed) of stuct kgdb_hook (which name should also be changed to relate to I/O, kgdb_IO_hook, for example). Then reserve entry 0 for the rs232 I/O code.

Dunno about that. Probably should work more like the console code, whoever registers first wins. Early boot will probably be the exclusive province of serial for a while yet, but designing it in is probably short-sighted.

Quoted 5 lines

An alternate possibility is an array of pointer to struct kgdb_hook which
allows one to define the struct contents as below and to build the array, all at compile/link time. A legal entry MUST define get and put, but why not define them all, using dummy functions for the ones that make no sense in a particular interface.

Throwing all the stubs in a special section could work well too. Then we could add an avail() function so that early boot debugging could discover if each one was available. The serial code could use this to kickstart itself while the eth code could test a local initialized flag and say "not a chance". Which gives us all the architecture to throw in other trivial interfaces (parallel, bus-snoopers, etc.).

Signature · 1 line
Matt Mackall : http://www.selenic.com : Linux development and consulting
#10 lore raw

Hi!

Quoted 5 lines
Quoted 3 lines

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Agreed, I just haven't touched it since you last mentioned it.

I believe we need better name than kgdb_local.h.... Hmm, but I'm not sure what the name should be.
Pavel

Signature · 1 line
When do you have heart between your knees?
#11 lore raw
Quoted 10 lines · Pavel Machek

Hi!

Quoted 3 lines
Quoted 1 line

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Agreed, I just haven't touched it since you last mentioned it.

I believe we need better name than kgdb_local.h.... Hmm, but I'm not sure what the name should be.

Sure. How about kgdb_internal.h ??

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#12 lore raw

Hi!

Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Agreed, I just haven't touched it since you last mentioned it.

I believe we need better name than kgdb_local.h.... Hmm, but I'm not sure what the name should be.

Sure. How about kgdb_internal.h ??

Yes, that looks better. [Somehow I thought even better name has to exists.]

Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#13 lore raw
In reply to Matt Mackall

Regarding pluggable iterfaces -
The version I have lets a user to choose the interface by supplying appropriate command line. (e.g. kgdbwait kgdb8250=... or kgdbwait kgdbeth=...) It supports an arbitrary number of interfaces. The kgdb core itself is independent of an interface. All interfaces are defined by a structure described below. An interface registers itself with kgdb core by assigning this structure to pointer kgdb_serial.

struct kgdb_serial {
	int chunksize;
	int (*read_char)(void);
	void (*write_char)(int);
	void (*flush)(void);
	int (*hook)(void);
	void (*begin_session)(void);
	void (*end_session)(void);
};

Where chunksize is maximum chunksize an interface can handle.

read_char and write_char are derived from getDebugChar and putDebugChar flush flushes written characters. Flush control is given to kgdb core so that it can ensure that #checksum doesn't split.

begin_session and end_session inform an interface about a gdb communication session. (Haven't decided about console packets to gdb yet)

hook is interface initialization. It can return errors. This allows kgdb core to probe the interface for availability at multiple points. Because of this, there can be multiple debugger entry points
1. At very begining of start_kernel -> Only an 8250 interface with early boot enabled can respond to hook call.
2. After smp initialization -> An 8250 interface without an early boot can respond to this.
3. An ethernet interface can itself call debugger_entry to enter debugger after it's brought up from userland.

Other interfaces can come up at (1) or (2)

Quoted 60 lines · Matt Mackall
Quoted 3 lines · George Anzinger

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Agreed, I just haven't touched it since you last mentioned it.

Quoted 9 lines

include/asm-i386/kgdb.h extern void breakpoint(void); · line 24

Quoted 3 lines
include/asm-i386/kgdb.h renamed from include/asm-i386/kgdb.h~kgdb-plug +3 -0
+struct kgdb_hook {
+	char *sendbuf;
+	int maxsend;

I don't see the need of maxsend, or sendbuff, for that matter, as kgdb uses it now (for the eth code) it is redundant, in that the eth putchar also does the same thing as is being done in the kgdb_stub.c code. I think this should be removed from the stub and the limit in the ethcode relied upon.

Fair enough.

Quoted 16 lines
Quoted 11 lines

void
putDebugChar(int c)
{

arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +2 -5
-	if (!kgdboe) {
-		tty_putDebugChar(c);
-	} else {
-		eth_putDebugChar(c);
-	}
+	if (kh)
+		kh->putchar(c);

}

I was thinking that this might read something like:

         if (xxx[kh].putchar(c))
                xxx[kh].putchar(c);
Quoted 7 lines

One might further want to do something like:

         if (!xxx[kh].putchar(c))
                kh = 0;

In otherwords, an array (xxx must, of course, be renamed) of stuct kgdb_hook (which name should also be changed to relate to I/O, kgdb_IO_hook, for example). Then reserve entry 0 for the rs232 I/O code.

Dunno about that. Probably should work more like the console code, whoever registers first wins. Early boot will probably be the exclusive province of serial for a while yet, but designing it in is probably short-sighted.

Quoted 5 lines

An alternate possibility is an array of pointer to struct kgdb_hook
which allows one to define the struct contents as below and to build the array, all at compile/link time. A legal entry MUST define get and put, but why not define them all, using dummy functions for the ones that make no sense in a particular interface.

Throwing all the stubs in a special section could work well too. Then we could add an avail() function so that early boot debugging could discover if each one was available. The serial code could use this to kickstart itself while the eth code could test a local initialized flag and say "not a chance". Which gives us all the architecture to throw in other trivial interfaces (parallel, bus-snoopers, etc.).

Signature · 3 lines
Amit Kale
EmSysSoft (http://www.emsyssoft.com)
KGDB: Linux Kernel Source Level Debugger (http://kgdb.sourceforge.net)
#14 lore raw
Quoted 5 lines · Amit S. Kale

Regarding pluggable iterfaces -
The version I have lets a user to choose the interface by supplying appropriate command line. (e.g. kgdbwait kgdb8250=... or kgdbwait kgdbeth=...) It supports an arbitrary number of interfaces. The kgdb core itself is independent of an interface. All interfaces are defined by a structure described below. An interface registers itself with kgdb core by assigning this structure to pointer kgdb_serial.

struct kgdb_serial {
	int chunksize;

Do we really need this? The only place I saw it used it did not seem to matter where the split occured and there was now endchunck/beginchunck stuff. I would MUCH rather see the interface code take care of this with out mucking up the core code (as the eth code already does). Did I miss something here?

Quoted 8 lines
	int (*read_char)(void);
	void (*write_char)(int);
	void (*flush)(void);
	int (*hook)(void);
	void (*begin_session)(void);
	void (*end_session)(void);
};
Quoted 4 lines

Where chunksize is maximum chunksize an interface can handle.

read_char and write_char are derived from getDebugChar and putDebugChar
flush flushes written characters. Flush control is given to kgdb core so that it can ensure that #checksum doesn't split.

Actually, I think it is needed so that gdb knows that the kgdb stub has exited.
This could, of course, be done with out the flush, but then the write code
would have to recognize an end of record (not hard with the given protocol). I don't think there is any requirement that a checksum not be split. My assumption here is that the logical record is reassembled on the gdb end without concern about how many physical records are involved. Is this not true?

Quoted 2 lines

begin_session and end_session inform an interface about a gdb communication session. (Haven't decided about console packets to gdb yet)

I assume you mean entry to the stub/ exit the stub as a "session". This eliminates the old hook, right?

Quoted 5 lines

hook is interface initialization. It can return errors. This allows kgdb core to probe the interface for availability at multiple points. Because of this, there can be multiple debugger entry points
1. At very begining of start_kernel -> Only an 8250 interface with early boot enabled can respond to hook call.
2. After smp initialization -> An 8250 interface without an early boot can respond to this.
3. An ethernet interface can itself call debugger_entry to enter debugger after it's brought up from userland.

Hm.. Eth is up way before user land, else we could not nfs mount root and all that that implies. I think eth should be "available" when it is initialized. I am not sure I see a reason to support a way to get to kgdb from user land. We have ^C and also the Sys Rq entry. That should be enough.

Also, as mention in a prior email, I don't think it is a good idea to switch interfaces once communication is started, unless commanded to do so, even if the default request is to use an inteface that just came up.

I would suggest the the readyness of an interface be something one can easily determine from gdb (assuming we have established a connection). I suggest putting this in the kgdb_info structure. Possibly a pointer to an array of ??? where each entry is one of the interfaces. Should have an "up" value here (filled in by the hook calls), as well as, say a pointer to more details on the interface. The details might be baud, irq, address, for serial, and the ip address, etc for eth.

-g

Quoted 71 lines

Other interfaces can come up at (1) or (2)

Quoted 64 lines · Matt Mackall
Quoted 3 lines · George Anzinger

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Agreed, I just haven't touched it since you last mentioned it.

Quoted 9 lines

include/asm-i386/kgdb.h extern void breakpoint(void); · line 24

Quoted 3 lines
include/asm-i386/kgdb.h renamed from include/asm-i386/kgdb.h~kgdb-plug +3 -0
+struct kgdb_hook {
+	char *sendbuf;
+	int maxsend;

I don't see the need of maxsend, or sendbuff, for that matter, as kgdb uses it now (for the eth code) it is redundant, in that the eth putchar also does the same thing as is being done in the kgdb_stub.c code. I think this should be removed from the stub and the limit in the ethcode relied upon.

Fair enough.

Quoted 16 lines
Quoted 11 lines

void
putDebugChar(int c)
{

arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +2 -5
-	if (!kgdboe) {
-		tty_putDebugChar(c);
-	} else {
-		eth_putDebugChar(c);
-	}
+	if (kh)
+		kh->putchar(c);

}

I was thinking that this might read something like:

        if (xxx[kh].putchar(c))
               xxx[kh].putchar(c);
Quoted 7 lines

One might further want to do something like:

        if (!xxx[kh].putchar(c))
               kh = 0;

In otherwords, an array (xxx must, of course, be renamed) of stuct kgdb_hook (which name should also be changed to relate to I/O, kgdb_IO_hook, for example). Then reserve entry 0 for the rs232 I/O code.

Dunno about that. Probably should work more like the console code, whoever registers first wins. Early boot will probably be the exclusive province of serial for a while yet, but designing it in is probably short-sighted.

Quoted 5 lines

An alternate possibility is an array of pointer to struct kgdb_hook which allows one to define the struct contents as below and to build the array, all at compile/link time. A legal entry MUST define get and put, but why not define them all, using dummy functions for the ones that make no sense in a particular interface.

Throwing all the stubs in a special section could work well too. Then we could add an avail() function so that early boot debugging could discover if each one was available. The serial code could use this to kickstart itself while the eth code could test a local initialized flag and say "not a chance". Which gives us all the architecture to throw in other trivial interfaces (parallel, bus-snoopers, etc.).

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#15 lore raw
Quoted 9 lines · George Anzinger
Quoted 8 lines · Amit S. Kale

Regarding pluggable iterfaces -
The version I have lets a user to choose the interface by supplying appropriate command line. (e.g. kgdbwait kgdb8250=... or kgdbwait kgdbeth=...) It supports an arbitrary number of interfaces. The kgdb core itself is independent of an interface. All interfaces are defined by a structure described below. An interface registers itself with kgdb core by assigning this structure to pointer kgdb_serial.

Quoted 8 lines
Quoted 2 lines
struct kgdb_serial {
	int chunksize;

Do we really need this? The only place I saw it used it did not seem to matter where the split occured and there was now endchunck/beginchunck stuff. I would MUCH rather see the interface code take care of this with out mucking up the core code (as the eth code already does). Did I miss something here?

Having an interface recognize a kgdb core record isn't a good design. Having kgdb core record know interface limitations isn't good either.

If kgdb calls flush at end of a packet and an interface splits a packet whenever its length goes above its limit, that'll be the right way of doing it.

Quoted 15 lines
Quoted 9 lines
	int (*read_char)(void);
	void (*write_char)(int);
	void (*flush)(void);
	int (*hook)(void);
	void (*begin_session)(void);
	void (*end_session)(void);
};
Quoted 5 lines

Where chunksize is maximum chunksize an interface can handle.

read_char and write_char are derived from getDebugChar and putDebugChar flush flushes written characters. Flush control is given to kgdb core so that it can ensure that #checksum doesn't split.

Quoted 7 lines

Actually, I think it is needed so that gdb knows that the kgdb stub has exited. This could, of course, be done with out the flush, but then the write code would have to recognize an end of record (not hard with the given protocol). I don't think there is any requirement that a checksum not be split. My assumption here is that the logical record is reassembled on the gdb end without concern about how many physical records are involved. Is this not true?

I guess yes. Splitting of #checksum may not matter.

Quoted 6 lines
Quoted 3 lines

begin_session and end_session inform an interface about a gdb communication session. (Haven't decided about console packets to gdb yet)

I assume you mean entry to the stub/ exit the stub as a "session". This eliminates the old hook, right?

Yes. begin_session and end_session mark entry and exit points into handle_exception. They are required to mark ethernet interface in trap mode.

What's old hook?

Quoted 11 lines
Quoted 10 lines

hook is interface initialization. It can return errors. This allows kgdb core to probe the interface for availability at multiple points. Because of this, there can be multiple debugger entry points
1. At very begining of start_kernel -> Only an 8250 interface with early boot enabled can respond to hook call.
2. After smp initialization -> An 8250 interface without an early boot can respond to this.
3. An ethernet interface can itself call debugger_entry to enter debugger after it's brought up from userland.

Quoted 5 lines

Hm.. Eth is up way before user land, else we could not nfs mount root and all that that implies. I think eth should be "available" when it is initialized. I am not sure I see a reason to support a way to get to kgdb from user land. We have ^C and also the Sys Rq entry. That should be enough.

Pardon my poor knowledge of network stack. I still have to work out the details of how and when to start kgdb-ethernet connection.

Now that you mention it, I'll think about it. I can actually bring up an ethernet interface from kgdb eth code itself and associate an ip address with it.

Quoted 4 lines

Also, as mention in a prior email, I don't think it is a good idea to switch interfaces once communication is started, unless commanded to do so, even if the default request is to use an inteface that just came up.

Agreed.

-amit

Quoted 74 lines

I would suggest the the readyness of an interface be something one can easily determine from gdb (assuming we have established a connection). I suggest putting this in the kgdb_info structure. Possibly a pointer to an array of ??? where each entry is one of the interfaces. Should have an "up" value here (filled in by the hook calls), as well as, say a pointer to more details on the interface. The details might be baud, irq, address, for serial, and the ip address, etc for eth.

-g

Quoted 63 lines

Other interfaces can come up at (1) or (2)

Quoted 60 lines · Matt Mackall
Quoted 3 lines · George Anzinger

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Agreed, I just haven't touched it since you last mentioned it.

Quoted 9 lines

include/asm-i386/kgdb.h extern void breakpoint(void); · line 24

Quoted 3 lines
include/asm-i386/kgdb.h renamed from include/asm-i386/kgdb.h~kgdb-plug +3 -0
+struct kgdb_hook {
+	char *sendbuf;
+	int maxsend;

I don't see the need of maxsend, or sendbuff, for that matter, as kgdb uses it now (for the eth code) it is redundant, in that the eth putchar also does the same thing as is being done in the kgdb_stub.c code. I think this should be removed from the stub and the limit in the ethcode relied upon.

Fair enough.

Quoted 16 lines
Quoted 11 lines

void
putDebugChar(int c)
{

arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +2 -5
-	if (!kgdboe) {
-		tty_putDebugChar(c);
-	} else {
-		eth_putDebugChar(c);
-	}
+	if (kh)
+		kh->putchar(c);

}

I was thinking that this might read something like:

        if (xxx[kh].putchar(c))
               xxx[kh].putchar(c);
Quoted 7 lines

One might further want to do something like:

        if (!xxx[kh].putchar(c))
               kh = 0;

In otherwords, an array (xxx must, of course, be renamed) of stuct kgdb_hook (which name should also be changed to relate to I/O, kgdb_IO_hook, for example). Then reserve entry 0 for the rs232 I/O code.

Dunno about that. Probably should work more like the console code, whoever registers first wins. Early boot will probably be the exclusive province of serial for a while yet, but designing it in is probably short-sighted.

Quoted 5 lines

An alternate possibility is an array of pointer to struct kgdb_hook which allows one to define the struct contents as below and to build the array, all at compile/link time. A legal entry MUST define get and put, but why not define them all, using dummy functions for the ones that make no sense in a particular interface.

Throwing all the stubs in a special section could work well too. Then we could add an avail() function so that early boot debugging could discover if each one was available. The serial code could use this to kickstart itself while the eth code could test a local initialized flag and say "not a chance". Which gives us all the architecture to throw in other trivial interfaces (parallel, bus-snoopers, etc.).

Signature · 3 lines
Amit Kale
EmSysSoft (http://www.emsyssoft.com)
KGDB: Linux Kernel Source Level Debugger (http://kgdb.sourceforge.net)
#16 lore raw
Quoted 22 lines · Amit S. Kale
Quoted 10 lines · George Anzinger
Quoted 8 lines · Amit S. Kale

Regarding pluggable iterfaces -
The version I have lets a user to choose the interface by supplying appropriate command line. (e.g. kgdbwait kgdb8250=... or kgdbwait kgdbeth=...) It supports an arbitrary number of interfaces. The kgdb core itself is independent of an interface. All interfaces are defined by a structure described below. An interface registers itself with kgdb core by assigning this structure to pointer kgdb_serial.

Quoted 8 lines
Quoted 2 lines
struct kgdb_serial {
	int chunksize;

Do we really need this? The only place I saw it used it did not seem to matter where the split occured and there was now endchunck/beginchunck stuff. I would MUCH rather see the interface code take care of this with out mucking up the core code (as the eth code already does). Did I miss something here?

Quoted 4 lines

Having an interface recognize a kgdb core record isn't a good design. Having kgdb core record know interface limitations isn't good either.

If kgdb calls flush at end of a packet and an interface splits a packet whenever its length goes above its limit, that'll be the right way of doing it.

I think this is what happens in the current eth code.

Quoted 30 lines
Quoted 15 lines
Quoted 9 lines
	int (*read_char)(void);
	void (*write_char)(int);
	void (*flush)(void);
	int (*hook)(void);
	void (*begin_session)(void);
	void (*end_session)(void);
};
Quoted 5 lines

Where chunksize is maximum chunksize an interface can handle.

read_char and write_char are derived from getDebugChar and putDebugChar flush flushes written characters. Flush control is given to kgdb core so that it can ensure that #checksum doesn't split.

Quoted 7 lines

Actually, I think it is needed so that gdb knows that the kgdb stub has exited. This could, of course, be done with out the flush, but then the write code would have to recognize an end of record (not hard with the given protocol). I don't think there is any requirement that a checksum not be split. My assumption here is that the logical record is reassembled on the gdb end without concern about how many physical records are involved. Is this not true?

I guess yes. Splitting of #checksum may not matter.

Quoted 3 lines
Quoted 2 lines

begin_session and end_session inform an interface about a gdb communication session. (Haven't decided about console packets to gdb yet)

Quoted 7 lines
Quoted 2 lines

I assume you mean entry to the stub/ exit the stub as a "session". This eliminates the old hook, right?

Yes. begin_session and end_session mark entry and exit points into handle_exception. They are required to mark ethernet interface in trap mode.

What's old hook?

I think it was a function in eth that was called to mark the begin and end just as begin_session and end_session do. Might want to consider one function for this, with a parameter.

-g

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#17 lore raw
In reply to Matt Mackall
Quoted 50 lines · Matt Mackall
Quoted 1 line · George Anzinger

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Agreed, I just haven't touched it since you last mentioned it.

Quoted 5 lines

include/asm-i386/kgdb.h extern void breakpoint(void); · line 24

Quoted 3 lines
include/asm-i386/kgdb.h renamed from include/asm-i386/kgdb.h~kgdb-plug +3 -0
+struct kgdb_hook {
+	char *sendbuf;
+	int maxsend;

I don't see the need of maxsend, or sendbuff, for that matter, as kgdb uses it now (for the eth code) it is redundant, in that the eth putchar also does the same thing as is being done in the kgdb_stub.c code. I think this should be removed from the stub and the limit in the ethcode relied upon.

Fair enough.

Quoted 13 lines
Quoted 11 lines

void
putDebugChar(int c)
{

arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +2 -5
-	if (!kgdboe) {
-		tty_putDebugChar(c);
-	} else {
-		eth_putDebugChar(c);
-	}
+	if (kh)
+		kh->putchar(c);

}

I was thinking that this might read something like:

Quoted 8 lines
        if (xxx[kh].putchar(c))
               xxx[kh].putchar(c);

One might further want to do something like:

        if (!xxx[kh].putchar(c))
               kh = 0;

In otherwords, an array (xxx must, of course, be renamed) of stuct kgdb_hook (which name should also be changed to relate to I/O, kgdb_IO_hook, for example). Then reserve entry 0 for the rs232 I/O code.

Dunno about that. Probably should work more like the console code, whoever registers first wins. Early boot will probably be the exclusive province of serial for a while yet, but designing it in is probably short-sighted.

Quoted 1 line

An alternate possibility is an array of pointer to struct kgdb_hook which allows one to define the struct contents as below and to build the array, all at compile/link time. A legal entry MUST define get and put, but why not define them all, using dummy functions for the ones that make no sense in a particular interface.

Quoted 7 lines

Throwing all the stubs in a special section could work well too. Then we could add an avail() function so that early boot debugging could discover if each one was available. The serial code could use this to kickstart itself while the eth code could test a local initialized flag and say "not a chance". Which gives us all the architecture to throw in other trivial interfaces (parallel, bus-snoopers, etc.).

I am thinking of something more like what was done with the x86 timer code. Each timer option sets up a structure with an array of pointers to each option. There it is done at compile time, and the runtime code tries each. There it is done in order, but here we want to do it a bit differently.

Maybe we could have an "available" flag or just assume that the address being !=0 for getdebugchar means it is "available". I think there should be a prefered intface set at config time. Possibly over ride this with the command line. Then have a back up order in case kgdb wants to communicate prior to the prefered one being available.

We would also have a rule that the command line over ride only works if communication has not yet been established. Here, we would also like control from gdb/kgdb so we could switch to a different interface, but under gdb control at this point. Either a maintaince command or setting the "channel" with a memory modify command. We would want this to take effect only after the current command is acknowledged.

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#18 lore raw
Quoted 73 lines · George Anzinger
Quoted 54 lines · Matt Mackall
Quoted 3 lines · George Anzinger

For the internal kgdb stuff I have created kdgb_local.h which I intended to be local to the workings of kgdb and not to contain anything a user would need.

Agreed, I just haven't touched it since you last mentioned it.

Quoted 9 lines

include/asm-i386/kgdb.h extern void breakpoint(void); · line 24

Quoted 3 lines
include/asm-i386/kgdb.h renamed from include/asm-i386/kgdb.h~kgdb-plug +3 -0
+struct kgdb_hook {
+	char *sendbuf;
+	int maxsend;

I don't see the need of maxsend, or sendbuff, for that matter, as kgdb uses it now (for the eth code) it is redundant, in that the eth putchar also does the same thing as is being done in the kgdb_stub.c code. I think this should be removed from the stub and the limit in the ethcode relied upon.

Fair enough.

Quoted 16 lines
Quoted 11 lines

void
putDebugChar(int c)
{

arch/i386/kernel/kgdb_stub.c renamed from arch/i386/kernel/kgdb_stub.c~kgdb-plug +2 -5
-	if (!kgdboe) {
-		tty_putDebugChar(c);
-	} else {
-		eth_putDebugChar(c);
-	}
+	if (kh)
+		kh->putchar(c);

}

I was thinking that this might read something like:

        if (xxx[kh].putchar(c))
               xxx[kh].putchar(c);
Quoted 7 lines

One might further want to do something like:

        if (!xxx[kh].putchar(c))
               kh = 0;

In otherwords, an array (xxx must, of course, be renamed) of stuct kgdb_hook (which name should also be changed to relate to I/O, kgdb_IO_hook, for example). Then reserve entry 0 for the rs232 I/O code.

Dunno about that. Probably should work more like the console code, whoever registers first wins. Early boot will probably be the exclusive province of serial for a while yet, but designing it in is probably short-sighted.

Quoted 5 lines

An alternate possibility is an array of pointer to struct kgdb_hook which allows one to define the struct contents as below and to build the array, all at compile/link time. A legal entry MUST define get and put, but why not define them all, using dummy functions for the ones that make no sense in a particular interface.

Quoted 6 lines

Throwing all the stubs in a special section could work well too. Then we could add an avail() function so that early boot debugging could discover if each one was available. The serial code could use this to kickstart itself while the eth code could test a local initialized flag and say "not a chance". Which gives us all the architecture to throw in other trivial interfaces (parallel, bus-snoopers, etc.).

I am thinking of something more like what was done with the x86 timer code. Each timer option sets up a structure with an array of pointers to each option. There it is done at compile time, and the runtime code tries each. There it is done in order, but here we want to do it a bit differently.

Maybe we could have an "available" flag or just assume that the address being !=0 for getdebugchar means it is "available". I think there should be a prefered intface set at config time. Possibly over ride this with the command line. Then have a back up order in case kgdb wants to communicate prior to the prefered one being available.

Quoted 6 lines

We would also have a rule that the command line over ride only works if communication has not yet been established. Here, we would also like control from gdb/kgdb so we could switch to a different interface, but under gdb control at this point. Either a maintaince command or setting the "channel" with a memory modify command. We would want this to take effect only after the current command is acknowledged.

I have something similar in my patches.
Each interface has kgdb_hook function, which returns failure if an interface isn't ready.

Signature · 3 lines
Amit Kale
EmSysSoft (http://www.emsyssoft.com)
KGDB: Linux Kernel Source Level Debugger (http://kgdb.sourceforge.net)
#19 lore raw
Quoted 34 lines · Amit S. Kale
Quoted 24 lines · George Anzinger
Quoted 7 lines
Quoted 6 lines

An alternate possibility is an array of pointer to struct kgdb_hook which allows one to define the struct contents as below and to build the array, all at compile/link time. A legal entry MUST define get and put, but why not define them all, using dummy functions for the ones that make no sense in a particular interface.

Quoted 6 lines

Throwing all the stubs in a special section could work well too. Then we could add an avail() function so that early boot debugging could discover if each one was available. The serial code could use this to kickstart itself while the eth code could test a local initialized flag and say "not a chance". Which gives us all the architecture to throw in other trivial interfaces (parallel, bus-snoopers, etc.).

I am thinking of something more like what was done with the x86 timer code.
Each timer option sets up a structure with an array of pointers to each
option. There it is done at compile time, and the runtime code tries each. There it is done in order, but here we want to do it a bit differently.

Maybe we could have an "available" flag or just assume that the address being !=0 for getdebugchar means it is "available". I think there should be a prefered intface set at config time. Possibly over ride this with the command line. Then have a back up order in case kgdb wants to communicate prior to the prefered one being available.

Quoted 6 lines

We would also have a rule that the command line over ride only works if communication has not yet been established. Here, we would also like control from gdb/kgdb so we could switch to a different interface, but under gdb control at this point. Either a maintaince command or setting the "channel" with a memory modify command. We would want this to take effect only after the current command is acknowledged.

Quoted 2 lines

I have something similar in my patches.
Each interface has kgdb_hook function, which returns failure if an interface isn't ready.

Keep in mind that an interface may be ready to communicate and still not able to handle the ^C break. The reason is that the ^C requires interrupt support which is not available until rather late in the bring up. In particular, trying to register an interrupt routine prior to the memory subsystem being able to do an alloc causes failure to register the interrupt function, which does cause and error return from request_irq(). The version in the common.patch seems to keep this information but does nothing with it. I think it would be better to try again later and to keep trying until the request is successful. See for example, the kgdb patch in Andrew's mm breakout.

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#20 lore raw
In reply to George Anzinger

Hi!

Quoted 12 lines
Quoted 7 lines

No real code changes, but cleanups all over the place. What about applying?

Ouch and arch-dependend code is moved to kernel/kgdb.c. I'll probably do x86-64 version so that is rather important.

Pavel

A few comments:

I like the code seperation. Does it follow what Amit is doing? It would be nice if Amit's version and this one could come together around

Quoted 1 line

this.

No, it does not follow Amit's work.

...and that's a problem because Amit's work looks way better than this. I guess I need to start again, relative to Amit's patches this time.

Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]