From owner-freebsd-hackers Tue Nov 5 14:56: 7 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3104C37B404 for ; Tue, 5 Nov 2002 14:56:05 -0800 (PST) Received: from rootlabs.com (root.org [67.118.192.226]) by mx1.FreeBSD.org (Postfix) with SMTP id 1D80643E3B for ; Tue, 5 Nov 2002 14:56:04 -0800 (PST) (envelope-from nate@rootlabs.com) Received: (qmail 12196 invoked by uid 1000); 5 Nov 2002 22:56:03 -0000 Date: Tue, 5 Nov 2002 14:56:03 -0800 (PST) From: Nate Lawson To: Archie Cobbs Cc: current@FreeBSD.ORG, hackers@FreeBSD.ORG Subject: Re: GDB auto enter/detach patch In-Reply-To: <200211052101.gA5L1t3Y039774@arch20m.dellroad.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, 5 Nov 2002, Archie Cobbs wrote: > Nate Lawson writes: > > I've put together a patch that enables a kernel on the target machine to > > detect a GDB packet and automatically enter GDB mode. When the debugger > > detaches, it also continues execution. This speeds up debugging, > > especially when the target is in a remote location. The patch plus more > > explanation is at: > > > > http://www.root.org/~nate/freebsd/ > > Neat. A couple of comments: > > 1. I think a better abstraction of the GDB packet protocol would > be something like this: > > struct gdb_parse { > int state; /* opaque state value */ > u_int len; /* current packet length */ > u_int maxlen; /* maximum packet length */ > u_char data[0]; /* packet data */ > }; > > extern void gdb_parse_init(struct gdb_parse *p); > extern int gdb_parse_byte(struct gdb_parse *p); > > That is, if you're doing the state machine, why not go ahead > and decode the packet data as well? The first version of the patch collected the data in a small static buffer with the idea that I'd send the command to the gdb stub once it was assembled. However, gdb on attach retries multiple times with different commands before giving up so I just discard the first complete gdb frame and let the retries hit gdb once I call breakpoint() > 2. You need to handle the escape mechanism for packets containing > "raw" data.: '$', '#', and '~' are escaped with '~' characters > in case the the 'X' command is used. Escapes should be added but I haven't done that yet because all the commands currently used to attach to the stub don't need them. > 3. I think GDB_AUTO_DETACH should be mandatory, i.e., the current > state of affairs is a bug IMHO. I've always wondered why that wasn't the case. I'd also like to catch the $k command (kill) which is sent on typing "quit" into gdb while still attached and do something useful. Should that also restart the kernel like an explicit "detach"? > 4. Does FreeBSD use the 'O' command to send ordinary serial port output > when GDB mode is active? Haven't looked but this would be nice to > have if it's not already there. No, it uses gdb remote chat which prefixes commands with |||| > 5. Receipt of a '$' character should always reset the state, no? > (modulo the '~' escape mechanism mentioned above). Yeah, I should add this. Basically the state machine is a little lax at the moment and it's possible (although unlikely) that data transferred over the serial port could trigger a breakpoint(). It matches $ + up to 12 chars + # + [0-F] + [0-F] If you're worried about this, just use the sysctl to turn off debug.gdb_auto_enter while transferring binary data over the gdb port. Even when I implement stricter protocol matching, relying on inband signalling is inherently unreliable. If you need to debug a serial port driver, you can use a 2nd serial port. -Nate To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message