Skip to content

Commit fc5a7bb

Browse files
committed
ugly WIP
1 parent 0f5af03 commit fc5a7bb

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

tools/moar-gdb.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
#import blessings
5656
import sys
5757

58+
import pdb
59+
60+
pdb.set_trace()
61+
5862
import traceback # debugging
5963

6064
# These are the flags from MVMString's body.flags
@@ -248,6 +252,27 @@ def to_string(self):
248252
"None"
249253
]
250254

255+
please_just_give_me_the_default_pprinter_gdb_you_piece_of_shit = False
256+
257+
class PPrintFallback(Exception):
258+
def __init__(self, exc):
259+
self.exc = exc
260+
261+
def can_fall_back(method):
262+
def with_fallback(self, *args, **kwargs):
263+
global please_just_give_me_the_default_pprinter_gdb_you_piece_of_shit
264+
try:
265+
result = method(self, *args, **kwargs)
266+
except PPrintFallback as e:
267+
traceback.print_exception(type(e), e.exc, None)
268+
print("please give me the default pprinter, yes yes")
269+
please_just_give_me_the_default_pprinter_gdb_you_piece_of_shit = True
270+
result = self.val.to_string()
271+
please_just_give_me_the_default_pprinter_gdb_you_piece_of_shit = False
272+
return result
273+
return with_fallback
274+
275+
251276
class MVMObjectPPrinter(object):
252277
def __init__(self, val, pointer = False):
253278
print("pretty print for ", hex(val))
@@ -263,19 +288,28 @@ def get_basic_info(self):
263288
self.as_mvmobject = self.val.cast(gdb.lookup_type("MVMObject"))
264289

265290
self._repr = self.as_mvmobject['st']['REPR']
291+
try:
292+
self._repr.dereference()
293+
except gdb.MemoryError as e:
294+
raise PPrintFallback(e)
295+
266296
print(hex(self._repr))
267297

268298
self.reprname = self._repr['name'].string()
269299

270-
self.debugname = self.as_mvmobject['st']['debug_name'].string()
300+
self.debugname = self.as_mvmobject['st']['debug_name']
301+
if self.debugname != 0:
302+
self.debugname = self.debugname.string()
271303

272304
self.inited = True
273305

306+
@can_fall_back
274307
def stringify(self):
275308
print("stringifying an mvmobject")
276309
self.get_basic_info()
277310
return str(self.val.type) + " (" + self.debugname + ") of repr " + self.reprname
278311

312+
@can_fall_back
279313
def to_string(self):
280314
return self.stringify()
281315

@@ -880,9 +914,16 @@ def str_lookup_function(val):
880914

881915
return None
882916

917+
mvm_not_object = [
918+
"MVMThreadContext",
919+
920+
]
921+
883922
def mvmobject_lookup_function(val):
923+
if please_just_give_me_the_default_pprinter_gdb_you_piece_of_shit:
924+
return None
884925
pointer = str(val.type).endswith("*")
885-
if str(val.type).startswith("MVM"):
926+
if str(val.type).startswith("MVM") and not (str(val.type).endswith("Body") or str(val.type).endswith("Body*")):
886927
try:
887928
if pointer:
888929
val.cast(gdb.lookup_type("MVMObject").pointer())

0 commit comments

Comments
 (0)