55
55
#import blessings
56
56
import sys
57
57
58
+ import pdb
59
+
60
+ pdb .set_trace ()
61
+
58
62
import traceback # debugging
59
63
60
64
# These are the flags from MVMString's body.flags
@@ -248,6 +252,27 @@ def to_string(self):
248
252
"None"
249
253
]
250
254
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
+
251
276
class MVMObjectPPrinter (object ):
252
277
def __init__ (self , val , pointer = False ):
253
278
print ("pretty print for " , hex (val ))
@@ -263,19 +288,28 @@ def get_basic_info(self):
263
288
self .as_mvmobject = self .val .cast (gdb .lookup_type ("MVMObject" ))
264
289
265
290
self ._repr = self .as_mvmobject ['st' ]['REPR' ]
291
+ try :
292
+ self ._repr .dereference ()
293
+ except gdb .MemoryError as e :
294
+ raise PPrintFallback (e )
295
+
266
296
print (hex (self ._repr ))
267
297
268
298
self .reprname = self ._repr ['name' ].string ()
269
299
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 ()
271
303
272
304
self .inited = True
273
305
306
+ @can_fall_back
274
307
def stringify (self ):
275
308
print ("stringifying an mvmobject" )
276
309
self .get_basic_info ()
277
310
return str (self .val .type ) + " (" + self .debugname + ") of repr " + self .reprname
278
311
312
+ @can_fall_back
279
313
def to_string (self ):
280
314
return self .stringify ()
281
315
@@ -880,9 +914,16 @@ def str_lookup_function(val):
880
914
881
915
return None
882
916
917
+ mvm_not_object = [
918
+ "MVMThreadContext" ,
919
+
920
+ ]
921
+
883
922
def mvmobject_lookup_function (val ):
923
+ if please_just_give_me_the_default_pprinter_gdb_you_piece_of_shit :
924
+ return None
884
925
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*" )) :
886
927
try :
887
928
if pointer :
888
929
val .cast (gdb .lookup_type ("MVMObject" ).pointer ())
0 commit comments