runtime: fix GDB "info goroutines" for Go 1.5

"info goroutines" is failing because it hasn't kept up with changes in
the 1.5 runtime.  This fixes three issues preventing "info goroutines"
from working.  allg is no longer a linked list, so switch to using the
allgs slice.  The g struct's 'status' field is now called
'atomicstatus', so rename uses of 'status'.  Finally, this was trying
to parse str(pc) as an int, but str(pc) can return symbolic
information after the raw hex value; fix this by stripping everything
after the first space.

This also adds a test for "info goroutines" to runtime-gdb_test, which
was previously quite skeletal.

Change-Id: I8ad83ee8640891cdd88ecd28dad31ed9b5833b7a
Reviewed-on: https://go-review.googlesource.com/4935
Reviewed-by: Minux Ma <minux@golang.org>
diff --git a/src/runtime/runtime-gdb.py b/src/runtime/runtime-gdb.py
index cee025e..33fcc76 100644
--- a/src/runtime/runtime-gdb.py
+++ b/src/runtime/runtime-gdb.py
@@ -28,6 +28,31 @@
 goobjfile.pretty_printers = []
 
 #
+#  Value wrappers
+#
+
+class SliceValue:
+	"Wrapper for slice values."
+
+	def __init__(self, val):
+		self.val = val
+
+	@property
+	def len(self):
+		return int(self.val['len'])
+
+	@property
+	def cap(self):
+		return int(self.val['cap'])
+
+	def __getitem__(self, i):
+		if i < 0 or i >= self.len:
+			raise IndexError(i)
+		ptr = self.val["array"]
+		return (ptr + i).dereference()
+
+
+#
 #  Pretty Printers
 #
 
@@ -355,8 +380,8 @@
 	def invoke(self, _arg, _from_tty):
 		# args = gdb.string_to_argv(arg)
 		vp = gdb.lookup_type('void').pointer()
-		for ptr in linked_list(gdb.parse_and_eval("'runtime.allg'"), 'alllink'):
-			if ptr['status'] == 6:  # 'gdead'
+		for ptr in SliceValue(gdb.parse_and_eval("'runtime.allgs'")):
+			if ptr['atomicstatus'] == 6:  # 'gdead'
 				continue
 			s = ' '
 			if ptr['m']:
@@ -370,9 +395,12 @@
 				#python3 / newer versions of gdb
 				pc = int(pc)
 			except gdb.error:
-				pc = int(str(pc), 16)
+				# str(pc) can return things like
+				# "0x429d6c <runtime.gopark+284>", so
+				# chop at first space.
+				pc = int(str(pc).split(None, 1)[0], 16)
 			blk = gdb.block_for_pc(pc)
-			print(s, ptr['goid'], "{0:8s}".format(sts[int(ptr['status'])]), blk.function)
+			print(s, ptr['goid'], "{0:8s}".format(sts[int(ptr['atomicstatus'])]), blk.function)
 
 
 def find_goroutine(goid):
@@ -386,8 +414,8 @@
 	@return tuple (gdb.Value, gdb.Value)
 	"""
 	vp = gdb.lookup_type('void').pointer()
-	for ptr in linked_list(gdb.parse_and_eval("'runtime.allg'"), 'alllink'):
-		if ptr['status'] == 6:  # 'gdead'
+	for ptr in SliceValue(gdb.parse_and_eval("'runtime.allgs'")):
+		if ptr['atomicstatus'] == 6:  # 'gdead'
 			continue
 		if ptr['goid'] == goid:
 			return (ptr['sched'][x].cast(vp) for x in ('pc', 'sp'))