Skip to contentSkip to conversation

Send a fuller T packet

RFC In review Tom Rini 4 participants 8 messages Mar 2, 2004 – Mar 4, 2004

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

RFC 1/1 Send a fuller T packet

Hello. Since a 'T' packet is allowed to send back information on an arbitrary number of registers, and on PPC32 we've always been including information on the stack pointer and program counter, I was wondering what people thought of the following patch:

include/asm-x86_64/kgdb.h +4 -0
diff -u linux-2.6.3/include/asm-x86_64/kgdb.h linux-2.6.3/include/asm-x86_64/kgdb.h
@@ -48,6 +48,10 @@
 /* Number of bytes of registers.  */
 #define NUMREGBYTES (_LASTREG*8)
 
+#define PC_REGNUM	_PC	/* Program Counter */
+#define SP_REGNUM	_RSP	/* Stack Pointer */
+#define PTRACE_PC	rip	/* Program Counter, in ptrace regs. */
+
 #define BREAKPOINT() asm("   int $3");
 #define BREAK_INSTR_SIZE       1
 
include/asm-i386/kgdb.h +4 -0
diff -u linux-2.6.3/include/asm-i386/kgdb.h linux-2.6.3/include/asm-i386/kgdb.h
@@ -43,6 +43,10 @@
 	_GS			/* 15 */
 };
 
+#define PC_REGNUM	_PC	/* Program Counter */
+#define SP_REGNUM	_ESP	/* Stack Pointer */
+#define PTRACE_PC	eip	/* Program Counter, in ptrace regs. */
+
 #define BREAKPOINT() asm("   int $3");
 #define BREAK_INSTR_SIZE       1
 
kernel/kgdb.c +34 -5
diff -u linux-2.6.3/kernel/kgdb.c linux-2.6.3/kernel/kgdb.c
@@ -695,12 +695,24 @@
 	/* Master processor is completely in the debugger */
 	kgdb_post_master_code(linux_regs, exVector, err_code);
 
+	/* If kgdb is connected, then an exception has occured, and
+	 * we need to pass something back to GDB. */
 	if (kgdb_connected) {
-		/* reply to host that an exception has occurred */
 		ptr = remcom_out_buffer;
 		*ptr++ = 'T';
 		*ptr++ = hexchars[(signo >> 4) % 16];
 		*ptr++ = hexchars[signo % 16];
+		*ptr++ = hexchars[(PC_REGNUM >> 4) % 16];
+		*ptr++ = hexchars[PC_REGNUM % 16];
+		*ptr++ = ':';
+		ptr = kgdb_mem2hex((char *)&linux_regs->PTRACE_PC, ptr, 4);
+		*ptr++ = ';';
+		*ptr++ = hexchars[SP_REGNUM >> 4];
+		*ptr++ = hexchars[SP_REGNUM & 0xf];
+		*ptr++ = ':';
+		ptr = kgdb_mem2hex(((char *)linux_regs) + SP_REGNUM * 4, ptr,
+				4);
+		*ptr++ = ';';
 		ptr += strlen(strcpy(ptr, "thread:"));
 		int_to_threadref(&thref, shadow_pid(current->pid));
 		ptr = pack_threadid(ptr, &thref);
@@ -728,11 +740,28 @@
 			 * we clear out our breakpoints now incase
 			 * GDB is reconnecting. */
 			remove_all_break();
-			remcom_out_buffer[0] = 'S';
-			remcom_out_buffer[1] = hexchars[signo >> 4];
-			remcom_out_buffer[2] = hexchars[signo % 16];
+			/* reply to host that an exception has occurred */
+			ptr = remcom_out_buffer;
+			*ptr++ = 'T';
+			*ptr++ = hexchars[(signo >> 4) % 16];
+			*ptr++ = hexchars[signo % 16];
+			*ptr++ = hexchars[(PC_REGNUM >> 4) % 16];
+			*ptr++ = hexchars[PC_REGNUM % 16];
+			*ptr++ = ':';
+			ptr = kgdb_mem2hex((char *)&linux_regs->PTRACE_PC, ptr,
+					4);
+			*ptr++ = ';';
+			*ptr++ = hexchars[SP_REGNUM >> 4];
+			*ptr++ = hexchars[SP_REGNUM & 0xf];
+			*ptr++ = ':';
+			ptr = kgdb_mem2hex(((char *)linux_regs) + SP_REGNUM * 4,
+					ptr, 4);
+			*ptr++ = ';';
+			ptr += strlen(strcpy(ptr, "thread:"));
+			int_to_threadref(&thref, shadow_pid(current->pid));
+			ptr = pack_threadid(ptr, &thref);
+			*ptr++ = ';';
 			break;
-
 		case 'g':	/* return the value of the CPU registers */
 			thread = kgdb_usethread;
 

Is this too much extra stuff to bother with, since that information can be gotten elsewhere?

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#1 lore raw
Quoted 9 lines · Tom Rini

Hello. Since a 'T' packet is allowed to send back information on an arbitrary number of registers, and on PPC32 we've always been including information on the stack pointer and program counter, I was wondering what people thought of the following patch:

diff -u linux-2.6.3/include/asm-x86_64/kgdb.h linux-2.6.3/include/asm-x86_64/kgdb.h

include/asm-x86_64/kgdb.h line 53

Quoted 6 lines
include/asm-x86_64/kgdb.h +3 -0
@@ -48,6 +48,10 @@
 /* Number of bytes of registers.  */
 #define NUMREGBYTES (_LASTREG*8)
 
+#define PC_REGNUM	_PC	/* Program Counter */
+#define SP_REGNUM	_RSP	/* Stack Pointer */
+#define PTRACE_PC	rip	/* Program Counter, in ptrace regs. */

I would really like to keep this stuff out of kgdb.h since it may be included by the user to pick up the BREAKPOINT() (which, by the way we should standardize as I note that here it has () while not on the current x86).

Isn't there a kgdb_local.h which is used only by kdgd and friends? We really do want to keep the name space as clean as possible to prevent possible conflicts.

Quoted 84 lines
include/asm-x86_64/kgdb.h +1 -0
+
 #define BREAKPOINT() asm("   int $3");
 #define BREAK_INSTR_SIZE       1
 

diff -u linux-2.6.3/include/asm-i386/kgdb.h linux-2.6.3/include/asm-i386/kgdb.h

include/asm-i386/kgdb.h +4 -0
@@ -43,6 +43,10 @@
 	_GS			/* 15 */
 };
 
+#define PC_REGNUM	_PC	/* Program Counter */
+#define SP_REGNUM	_ESP	/* Stack Pointer */
+#define PTRACE_PC	eip	/* Program Counter, in ptrace regs. */
+
 #define BREAKPOINT() asm("   int $3");
 #define BREAK_INSTR_SIZE       1
 

diff -u linux-2.6.3/kernel/kgdb.c linux-2.6.3/kernel/kgdb.c

kernel/kgdb.c +34 -5
@@ -695,12 +695,24 @@
 	/* Master processor is completely in the debugger */
 	kgdb_post_master_code(linux_regs, exVector, err_code);
 
+	/* If kgdb is connected, then an exception has occured, and
+	 * we need to pass something back to GDB. */
 	if (kgdb_connected) {
-		/* reply to host that an exception has occurred */
 		ptr = remcom_out_buffer;
 		*ptr++ = 'T';
 		*ptr++ = hexchars[(signo >> 4) % 16];
 		*ptr++ = hexchars[signo % 16];
+		*ptr++ = hexchars[(PC_REGNUM >> 4) % 16];
+		*ptr++ = hexchars[PC_REGNUM % 16];
+		*ptr++ = ':';
+		ptr = kgdb_mem2hex((char *)&linux_regs->PTRACE_PC, ptr, 4);
+		*ptr++ = ';';
+		*ptr++ = hexchars[SP_REGNUM >> 4];
+		*ptr++ = hexchars[SP_REGNUM & 0xf];
+		*ptr++ = ':';
+		ptr = kgdb_mem2hex(((char *)linux_regs) + SP_REGNUM * 4, ptr,
+				4);
+		*ptr++ = ';';
 		ptr += strlen(strcpy(ptr, "thread:"));
 		int_to_threadref(&thref, shadow_pid(current->pid));
 		ptr = pack_threadid(ptr, &thref);
@@ -728,11 +740,28 @@
 			 * we clear out our breakpoints now incase
 			 * GDB is reconnecting. */
 			remove_all_break();
-			remcom_out_buffer[0] = 'S';
-			remcom_out_buffer[1] = hexchars[signo >> 4];
-			remcom_out_buffer[2] = hexchars[signo % 16];
+			/* reply to host that an exception has occurred */
+			ptr = remcom_out_buffer;
+			*ptr++ = 'T';
+			*ptr++ = hexchars[(signo >> 4) % 16];
+			*ptr++ = hexchars[signo % 16];
+			*ptr++ = hexchars[(PC_REGNUM >> 4) % 16];
+			*ptr++ = hexchars[PC_REGNUM % 16];
+			*ptr++ = ':';
+			ptr = kgdb_mem2hex((char *)&linux_regs->PTRACE_PC, ptr,
+					4);
+			*ptr++ = ';';
+			*ptr++ = hexchars[SP_REGNUM >> 4];
+			*ptr++ = hexchars[SP_REGNUM & 0xf];
+			*ptr++ = ':';
+			ptr = kgdb_mem2hex(((char *)linux_regs) + SP_REGNUM * 4,
+					ptr, 4);
+			*ptr++ = ';';
+			ptr += strlen(strcpy(ptr, "thread:"));
+			int_to_threadref(&thref, shadow_pid(current->pid));
+			ptr = pack_threadid(ptr, &thref);
+			*ptr++ = ';';
 			break;
-
 		case 'g':	/* return the value of the CPU registers */
 			thread = kgdb_usethread;
 

Is this too much extra stuff to bother with, since that information can be gotten elsewhere?

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
author
#2 lore raw
Quoted 16 lines · George Anzinger
Quoted 15 lines · Tom Rini

Hello. Since a 'T' packet is allowed to send back information on an arbitrary number of registers, and on PPC32 we've always been including information on the stack pointer and program counter, I was wondering what people thought of the following patch:

diff -u linux-2.6.3/include/asm-x86_64/kgdb.h
linux-2.6.3/include/asm-x86_64/kgdb.h
--- linux-2.6.3/include/asm-x86_64/kgdb.h 2004-02-27
11:30:37.445782703 -0700
+++ linux-2.6.3/include/asm-x86_64/kgdb.h 2004-03-02
14:42:47.854532793 -0700

include/asm-x86_64/kgdb.h +0 -0
@@ -48,6 +48,10 @@
 /* Number of bytes of registers.  */
 #define NUMREGBYTES (_LASTREG*8)
 
Quoted 8 lines

include/asm-x86_64/kgdb.h line 53

Quoted 3 lines
include/asm-x86_64/kgdb.h +3 -0
+#define PC_REGNUM	_PC	/* Program Counter */
+#define SP_REGNUM	_RSP	/* Stack Pointer */
+#define PTRACE_PC	rip	/* Program Counter, in ptrace regs. */

I would really like to keep this stuff out of kgdb.h since it may be included by the user to pick up the BREAKPOINT() (which, by the way we should standardize as I note that here it has () while not on the current x86).

It's BREAKPOINT() everywhere:

$ grep BREAKPOINT include/asm-*/kgdb.h
include/asm-i386/kgdb.h:#define BREAKPOINT() asm("   int $3");
include/asm-ppc/kgdb.h:#define BREAKPOINT()             asm(".long 0x7d821008") /* twge r2, r2 */
include/asm-x86_64/kgdb.h:#define BREAKPOINT() asm("   int $3");
Quoted 3 lines

Isn't there a kgdb_local.h which is used only by kdgd and friends? We really do want to keep the name space as clean as possible to prevent possible conflicts.

The simple answer is you don't call BREAKPOINT() in your code anywhere. You call breakpoint() or kgdb_schedule_breakpoint().
The split here is different in that <linux/kgdb.h> should be standalone (it's not, _yet_).

But this is all an aside to my question. :)

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#3 lore raw
Quoted 19 lines · Tom Rini
Quoted 16 lines · George Anzinger
Quoted 14 lines · Tom Rini

Hello. Since a 'T' packet is allowed to send back information on an arbitrary number of registers, and on PPC32 we've always been including information on the stack pointer and program counter, I was wondering what people thought of the following patch:

diff -u linux-2.6.3/include/asm-x86_64/kgdb.h linux-2.6.3/include/asm-x86_64/kgdb.h
--- linux-2.6.3/include/asm-x86_64/kgdb.h 2004-02-27
11:30:37.445782703 -0700
+++ linux-2.6.3/include/asm-x86_64/kgdb.h 2004-03-02
14:42:47.854532793 -0700

include/asm-x86_64/kgdb.h +0 -0
@@ -48,6 +48,10 @@
 /* Number of bytes of registers.  */
 #define NUMREGBYTES (_LASTREG*8)
 
Quoted 8 lines
Quoted 5 lines

include/asm-x86_64/kgdb.h line 53

Quoted 3 lines
include/asm-x86_64/kgdb.h +3 -0
+#define PC_REGNUM	_PC	/* Program Counter */
+#define SP_REGNUM	_RSP	/* Stack Pointer */
+#define PTRACE_PC	rip	/* Program Counter, in ptrace regs. */

I would really like to keep this stuff out of kgdb.h since it may be included by the user to pick up the BREAKPOINT() (which, by the way we should standardize as I note that here it has () while not on the current x86).

It's BREAKPOINT() everywhere:

Yeah, something you changed? Oh well, I will just have to learn to put the "()" in :)

Quoted 11 lines
$ grep BREAKPOINT include/asm-*/kgdb.h
include/asm-i386/kgdb.h:#define BREAKPOINT() asm("   int $3");
include/asm-ppc/kgdb.h:#define BREAKPOINT()             asm(".long 0x7d821008") /* twge r2, r2 */
include/asm-x86_64/kgdb.h:#define BREAKPOINT() asm("   int $3");
Quoted 1 line

Isn't there a kgdb_local.h which is used only by kdgd and friends? We really do want to keep the name space as clean as possible to prevent possible conflicts.

The simple answer is you don't call BREAKPOINT() in your code anywhere. You call breakpoint() or kgdb_schedule_breakpoint().

Uh, why? Last I knew that was a real function. Most of the time I just want a simple breakpoint. I surly don't want the register dumps and such that a function call causes, not to mention that it may do something else that is not friendly.

Quoted 2 lines

The split here is different in that <linux/kgdb.h> should be standalone (it's not, _yet_).

Yeah, but it will most likely include asm/kgdb.h....

Quoted 2 lines

But this is all an aside to my question. :)

Right, my answer on that is if it reduces the line traffic yes, if not, no. Because then it is just bloat.

Quoted 1 line
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
#4 lore raw

Hi,

Polution of kgdb.h is definitely bad.

I tried this code from Tom's bitkeeper tree some time back. It was incorrect in two aspects hence I took only the minimal 'T' packet.
1. It assumes 32 bit pc and sp.
2. sp is not equal to ((char *)linux_regs) + SP_REGNUM * 4 on powerpc.

A full 'T' packet is still a good idea because it saves a 'g' packet in following cases:
1. gdb internal breakpoints, like module_event.
2. conditional breakpoints.
3. tracepoints.

In general we can report an arbitrary number of registers in a 'T' packet. Reporting registers other than PC and SP is effectively making 'T' packet into a 'g' packet.

Architecture dependent code is the right place to compose the PC and SP part of a 'T' packet. Given a pt_regs pointer, an architecture dependent function can compose PC number, PC value, SP number and SP value, all of which are arch dependent. How about architecture dependent function:
int make_pcsp_packet(struct pt_regs *, char *buffer)

-Amit

Quoted 59 lines · George Anzinger
Quoted 26 lines · Tom Rini
Quoted 16 lines · George Anzinger
Quoted 15 lines · Tom Rini

Hello. Since a 'T' packet is allowed to send back information on an arbitrary number of registers, and on PPC32 we've always been including information on the stack pointer and program counter, I was wondering what people thought of the following patch:

diff -u linux-2.6.3/include/asm-x86_64/kgdb.h
linux-2.6.3/include/asm-x86_64/kgdb.h
--- linux-2.6.3/include/asm-x86_64/kgdb.h 2004-02-27
11:30:37.445782703 -0700
+++ linux-2.6.3/include/asm-x86_64/kgdb.h 2004-03-02
14:42:47.854532793 -0700

include/asm-x86_64/kgdb.h +0 -0
@@ -48,6 +48,10 @@
 /* Number of bytes of registers.  */
 #define NUMREGBYTES (_LASTREG*8)
 
Quoted 8 lines

include/asm-x86_64/kgdb.h line 53

Quoted 3 lines
include/asm-x86_64/kgdb.h +3 -0
+#define PC_REGNUM	_PC	/* Program Counter */
+#define SP_REGNUM	_RSP	/* Stack Pointer */
+#define PTRACE_PC	rip	/* Program Counter, in ptrace regs. */

I would really like to keep this stuff out of kgdb.h since it may be included by the user to pick up the BREAKPOINT() (which, by the way we should standardize as I note that here it has () while not on the current x86).

Quoted 1 line

It's BREAKPOINT() everywhere:

Yeah, something you changed? Oh well, I will just have to learn to put the "()" in :)

Quoted 6 lines
$ grep BREAKPOINT include/asm-*/kgdb.h
include/asm-i386/kgdb.h:#define BREAKPOINT() asm("   int $3");
include/asm-ppc/kgdb.h:#define BREAKPOINT()             asm(".long
0x7d821008") /* twge r2, r2 */ include/asm-x86_64/kgdb.h:#define
BREAKPOINT() asm("   int $3");
Quoted 6 lines
Quoted 3 lines

Isn't there a kgdb_local.h which is used only by kdgd and friends? We really do want to keep the name space as clean as possible to prevent possible conflicts.

The simple answer is you don't call BREAKPOINT() in your code anywhere. You call breakpoint() or kgdb_schedule_breakpoint().

Uh, why? Last I knew that was a real function. Most of the time I just want a simple breakpoint. I surly don't want the register dumps and such that a function call causes, not to mention that it may do something else that is not friendly.

Quoted 2 lines

The split here is different in that <linux/kgdb.h> should be standalone (it's not, _yet_).

Yeah, but it will most likely include asm/kgdb.h....

Quoted 1 line

But this is all an aside to my question. :)

Right, my answer on that is if it reduces the line traffic yes, if not, no. Because then it is just bloat.

#5 lore raw
In reply to Tom Rini

Hi!

Quoted 10 lines
Quoted 4 lines

I would really like to keep this stuff out of kgdb.h since it may be included by the user to pick up the BREAKPOINT() (which, by the way we should standardize as I note that here it has () while not on the current x86).

It's BREAKPOINT() everywhere:

$ grep BREAKPOINT include/asm-*/kgdb.h
include/asm-i386/kgdb.h:#define BREAKPOINT() asm("   int $3");
include/asm-ppc/kgdb.h:#define BREAKPOINT()             asm(".long 0x7d821008") /* twge r2, r2 */
include/asm-x86_64/kgdb.h:#define BREAKPOINT() asm("   int $3");

Notice how it ends with ';' on everything but ppc. Perhaps it needs do { } while (0) wrapping?
Pavel

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

Hi!

Quoted 5 lines
Quoted 4 lines

I would really like to keep this stuff out of kgdb.h since it may be included by the user to pick up the BREAKPOINT() (which, by the way we should standardize as I note that here it has () while not on the current x86).

Quoted 8 lines
Quoted 5 lines

It's BREAKPOINT() everywhere:

$ grep BREAKPOINT include/asm-*/kgdb.h
include/asm-i386/kgdb.h:#define BREAKPOINT() asm("   int $3");
include/asm-ppc/kgdb.h:#define BREAKPOINT()             asm(".long 0x7d821008") /* twge r2, r2 */
include/asm-x86_64/kgdb.h:#define BREAKPOINT() asm("   int $3");

Notice how it ends with ';' on everything but ppc. Perhaps it needs do { } while (0) wrapping?

... not that PPC works right now :) But yes, you're right.

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#7 lore raw
Quoted 14 lines · Tom Rini
Quoted 12 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 1 line

I would really like to keep this stuff out of kgdb.h since it may be included by the user to pick up the BREAKPOINT() (which, by the way we should standardize as I note that here it has () while not on the current x86).

It's BREAKPOINT() everywhere:

$ grep BREAKPOINT include/asm-*/kgdb.h
include/asm-i386/kgdb.h:#define BREAKPOINT() asm("   int $3");
include/asm-ppc/kgdb.h:#define BREAKPOINT()             asm(".long 0x7d821008") /* twge r2, r2 */
include/asm-x86_64/kgdb.h:#define BREAKPOINT() asm("   int $3");
Quoted 6 lines
Quoted 2 lines

Notice how it ends with ';' on everything but ppc. Perhaps it needs do { } while (0) wrapping?

... not that PPC works right now :) But yes, you're right.

I agree, lets force the ";".

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