runtime: fix gdb support for channels.

R=rsc
CC=golang-dev
https://golang.org/cl/4418043
diff --git a/src/pkg/runtime/chan.c b/src/pkg/runtime/chan.c
index 2fab9e2..f2bdad2 100644
--- a/src/pkg/runtime/chan.c
+++ b/src/pkg/runtime/chan.c
@@ -9,7 +9,6 @@
 
 static	int32	debug	= 0;
 
-typedef	struct	Link	Link;
 typedef	struct	WaitQ	WaitQ;
 typedef	struct	SudoG	SudoG;
 typedef	struct	Select	Select;
@@ -51,12 +50,6 @@
 // chanbuf(c, i) is pointer to the i'th slot in the buffer.
 #define chanbuf(c, i) ((byte*)((c)+1)+(uintptr)(c)->elemsize*(i))
 
-struct	Link
-{
-	Link*	link;			// asynch queue circular linked list
-	byte	elem[8];		// asynch queue data element (+ more)
-};
-
 enum
 {
 	// Scase.kind
diff --git a/src/pkg/runtime/runtime-gdb.py b/src/pkg/runtime/runtime-gdb.py
index 08772a4..3f767fb 100644
--- a/src/pkg/runtime/runtime-gdb.py
+++ b/src/pkg/runtime/runtime-gdb.py
@@ -122,10 +122,13 @@
 		return str(self.val.type)
 
 	def children(self):
-		ptr = self.val['recvdataq']
-		for idx in range(self.val["qcount"]):
-			yield ('[%d]' % idx, ptr['elem'])
-			ptr = ptr['link']
+		# see chan.c chanbuf()
+		et = [x.type for x in self.val['free'].type.target().fields() if x.name == 'elem'][0]
+                ptr = (self.val.address + 1).cast(et.pointer())
+                for i in range(self.val["qcount"]):
+			j = (self.val["recvx"] + i) % self.val["dataqsiz"]
+			yield ('[%d]' % i, (ptr + j).dereference())
+
 
 #
 #  Register all the *Printer classes above.