runtime: remove hardcoded runtime consts from gdb script
Instead evaluate and read the runtime internal constants
defined in runtime2.go
R=go1.11
Change-Id: If2f4b87e5b3f62f0c0ff1e86a90db8e37a78abb6
Reviewed-on: https://go-review.googlesource.com/87877
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Austin Clements <austin@google.com>
diff --git a/src/runtime/runtime-gdb.py b/src/runtime/runtime-gdb.py
index dd1f79b..3e8e1aa 100644
--- a/src/runtime/runtime-gdb.py
+++ b/src/runtime/runtime-gdb.py
@@ -27,6 +27,48 @@
goobjfile = gdb.current_objfile() or gdb.objfiles()[0]
goobjfile.pretty_printers = []
+# G state (runtime2.go)
+
+def read_runtime_const(varname, default):
+ try:
+ return int(gdb.parse_and_eval(varname))
+ except Exception:
+ return int(default)
+
+
+G_IDLE = read_runtime_const("'runtime._Gidle'", 0)
+G_RUNNABLE = read_runtime_const("'runtime._Grunnable'", 1)
+G_RUNNING = read_runtime_const("'runtime._Grunning'", 2)
+G_SYSCALL = read_runtime_const("'runtime._Gsyscall'", 3)
+G_WAITING = read_runtime_const("'runtime._Gwaiting'", 4)
+G_MORIBUND_UNUSED = read_runtime_const("'runtime._Gmoribund_unused'", 5)
+G_DEAD = read_runtime_const("'runtime._Gdead'", 6)
+G_ENQUEUE_UNUSED = read_runtime_const("'runtime._Genqueue_unused'", 7)
+G_COPYSTACK = read_runtime_const("'runtime._Gcopystack'", 8)
+G_SCAN = read_runtime_const("'runtime._Gscan'", 0x1000)
+G_SCANRUNNABLE = G_SCAN+G_RUNNABLE
+G_SCANRUNNING = G_SCAN+G_RUNNING
+G_SCANSYSCALL = G_SCAN+G_SYSCALL
+G_SCANWAITING = G_SCAN+G_WAITING
+
+sts = {
+ G_IDLE: 'idle',
+ G_RUNNABLE: 'runnable',
+ G_RUNNING: 'running',
+ G_SYSCALL: 'syscall',
+ G_WAITING: 'waiting',
+ G_MORIBUND_UNUSED: 'moribund',
+ G_DEAD: 'dead',
+ G_ENQUEUE_UNUSED: 'enqueue',
+ G_COPYSTACK: 'copystack',
+ G_SCAN: 'scan',
+ G_SCANRUNNABLE: 'runnable+s',
+ G_SCANRUNNING: 'running+s',
+ G_SCANSYSCALL: 'syscall+s',
+ G_SCANWAITING: 'waiting+s',
+}
+
+
#
# Value wrappers
#
@@ -360,9 +402,6 @@
# Commands
#
-sts = ('idle', 'runnable', 'running', 'syscall', 'waiting', 'moribund', 'dead', 'recovery')
-
-
def linked_list(ptr, linkfield):
while ptr:
yield ptr
@@ -379,7 +418,7 @@
# args = gdb.string_to_argv(arg)
vp = gdb.lookup_type('void').pointer()
for ptr in SliceValue(gdb.parse_and_eval("'runtime.allgs'")):
- if ptr['atomicstatus'] == 6: # 'gdead'
+ if ptr['atomicstatus'] == G_DEAD:
continue
s = ' '
if ptr['m']:
@@ -398,7 +437,9 @@
# 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['atomicstatus'])]), blk.function)
+ status = int(ptr['atomicstatus'])
+ st = sts.get(status, "unknown(%d)" % status)
+ print(s, ptr['goid'], "{0:8s}".format(st), blk.function)
def find_goroutine(goid):
@@ -413,7 +454,7 @@
"""
vp = gdb.lookup_type('void').pointer()
for ptr in SliceValue(gdb.parse_and_eval("'runtime.allgs'")):
- if ptr['atomicstatus'] == 6: # 'gdead'
+ if ptr['atomicstatus'] == G_DEAD:
continue
if ptr['goid'] == goid:
break