aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime-gdb.py
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2018-03-13 11:56:20 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2018-03-15 00:18:19 +0000
commitef400ed20afd033827abdc82d3e5afd272bf4629 (patch)
treedcadfa5613d90260fb05e85b3cbc103a3d434b32 /src/runtime/runtime-gdb.py
parenteb3c44b2c44ee99c7e24b181ce6abbb7d63df946 (diff)
downloadgo-ef400ed20afd033827abdc82d3e5afd272bf4629.tar.gz
go-ef400ed20afd033827abdc82d3e5afd272bf4629.zip
runtime: refactor gdb PC parsing
Change-Id: I91607edaf9c256e6723eb3d6e18c8210eb86b704 Reviewed-on: https://go-review.googlesource.com/100464 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/runtime-gdb.py')
-rw-r--r--src/runtime/runtime-gdb.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/runtime/runtime-gdb.py b/src/runtime/runtime-gdb.py
index 64e37903eb..e705435def 100644
--- a/src/runtime/runtime-gdb.py
+++ b/src/runtime/runtime-gdb.py
@@ -230,6 +230,27 @@ def makematcher(klass):
goobjfile.pretty_printers.extend([makematcher(var) for var in vars().values() if hasattr(var, 'pattern')])
+
+#
+# Utilities
+#
+
+def pc_to_int(pc):
+ # python2 will not cast pc (type void*) to an int cleanly
+ # instead python2 and python3 work with the hex string representation
+ # of the void pointer which we can parse back into an int.
+ # int(pc) will not work.
+ try:
+ # python3 / newer versions of gdb
+ pc = int(pc)
+ except gdb.error:
+ # str(pc) can return things like
+ # "0x429d6c <runtime.gopark+284>", so
+ # chop at first space.
+ pc = int(str(pc).split(None, 1)[0], 16)
+ return pc
+
+
#
# For reference, this is what we're trying to do:
# eface: p *(*(struct 'runtime.rtype'*)'main.e'->type_->data)->string
@@ -424,18 +445,7 @@ class GoroutinesCmd(gdb.Command):
if ptr['m']:
s = '*'
pc = ptr['sched']['pc'].cast(vp)
- # python2 will not cast pc (type void*) to an int cleanly
- # instead python2 and python3 work with the hex string representation
- # of the void pointer which we can parse back into an int.
- # int(pc) will not work.
- try:
- #python3 / newer versions of gdb
- pc = int(pc)
- except gdb.error:
- # str(pc) can return things like
- # "0x429d6c <runtime.gopark+284>", so
- # chop at first space.
- pc = int(str(pc).split(None, 1)[0], 16)
+ pc = pc_to_int(pc)
blk = gdb.block_for_pc(pc)
status = int(ptr['atomicstatus'])
st = sts.get(status, "unknown(%d)" % status)
@@ -514,11 +524,7 @@ class GoroutineCmd(gdb.Command):
if not pc:
print("No such goroutine: ", goid)
return
- try:
- #python3 / newer versions of gdb
- pc = int(pc)
- except gdb.error:
- pc = int(str(pc).split(None, 1)[0], 16)
+ pc = pc_to_int(pc)
save_frame = gdb.selected_frame()
gdb.parse_and_eval('$save_sp = $sp')
gdb.parse_and_eval('$save_pc = $pc')