Added set_levels_of_recursion to pretty printers
Added help function to wesnoth_gdb for the pretty printers. Usage from within gdb: python wesnoth_gdb.help()
This commit is contained in:
parent
64e01de038
commit
09268be31e
2 changed files with 115 additions and 23 deletions
|
@ -10,25 +10,33 @@ python import os
|
|||
python sys.path.append(os.path.abspath('utils/gdb/'))
|
||||
python import wesnoth_gdb
|
||||
|
||||
#Get help with
|
||||
python print wesnoth_gdb.__doc__
|
||||
|
||||
#Set expanded printing on
|
||||
set print pretty on
|
||||
|
||||
#Hide static members
|
||||
set print static-members off
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
Notes
|
||||
You can interactively reload it in gdb with
|
||||
python reload(wesnoth_gdb)
|
||||
"""
|
||||
__doc__="""
|
||||
python reload(wesnoth_gdb) #Interactively reload wesnoth_gdb
|
||||
python wesnoth.gdb.help() #Help message
|
||||
python print wesnoth_gdb.__doc__ #Help message
|
||||
|
||||
python print wesnoth_gdb.set_levels_of_recursion( number ) #Sets the levels of recursion (default 1)
|
||||
python print wesnoth_gdb.get_levels_of_recursion( ) #Gets the levels of recursion (default 1)
|
||||
|
||||
"""
|
||||
|
||||
import sys, gdb
|
||||
|
||||
|
||||
def help():
|
||||
print __doc__
|
||||
|
||||
#Force a reload, which is handy if you are interactively editting
|
||||
if 'register_wesnoth_pretty_printers' in sys.modules:
|
||||
reload (register_wesnoth_pretty_printers)
|
||||
|
@ -40,8 +48,18 @@ if 'wesnoth_pretty_printers' in sys.modules:
|
|||
else:
|
||||
import wesnoth_pretty_printers
|
||||
|
||||
|
||||
pretty_printers_dict = {}
|
||||
pretty_printers_dict = wesnoth_pretty_printers.add_printers(pretty_printers_dict)
|
||||
register_wesnoth_pretty_printers.register(pretty_printers_dict)
|
||||
|
||||
|
||||
#options
|
||||
|
||||
#get/set the default
|
||||
def get_levels_of_recursion():
|
||||
return wesnoth_pretty_printers.RecursionManager.get_level()
|
||||
def set_levels_of_recursion(num):
|
||||
wesnoth_pretty_printers.RecursionManager.set_level(num)
|
||||
return wesnoth_pretty_printers.RecursionManager.get_level()
|
||||
|
||||
|
|
|
@ -7,6 +7,44 @@ import itertools
|
|||
|
||||
from wesnoth_type_tools import strip_type
|
||||
|
||||
|
||||
class RecursionManager(object):
|
||||
"""Keeps track of the levels of recrusion and whether expansion should happen or not """
|
||||
default=1
|
||||
curr=0
|
||||
|
||||
# @classmethod
|
||||
# def __init__(cls, val):
|
||||
# cls.default = val
|
||||
# cls.curr=0;
|
||||
|
||||
@classmethod
|
||||
def get_level(cls):
|
||||
return cls.default
|
||||
|
||||
@classmethod
|
||||
def set_level(cls, val):
|
||||
if val >= 0 :
|
||||
cls.curr=0;
|
||||
cls.default = val
|
||||
return cls.default
|
||||
|
||||
@classmethod
|
||||
def should_display(cls) :
|
||||
return cls.curr <= cls.default
|
||||
|
||||
@classmethod
|
||||
def inc(cls):
|
||||
cls.curr = cls.curr + 1
|
||||
return cls.should_display()
|
||||
|
||||
@classmethod
|
||||
def dec(cls):
|
||||
if cls.curr > 0 :
|
||||
cls.curr = cls.curr - 1
|
||||
return cls.should_display()
|
||||
|
||||
|
||||
#Printer for n_interned::t_interned
|
||||
class T_InternedPrinter(object) :
|
||||
"""Print a t_interned_token<T>"""
|
||||
|
@ -72,15 +110,16 @@ class AttributeValuePrinter(object) :
|
|||
def __init__(self, val) :
|
||||
self.val = val
|
||||
|
||||
def to_string(self) :
|
||||
# Get the type.
|
||||
type = self.val.type
|
||||
|
||||
# Get the type name.
|
||||
type = strip_type(self.val)
|
||||
# Get the type.
|
||||
self.type = strip_type(self.val)
|
||||
|
||||
attr = self.val.cast(type)
|
||||
attr_type = attr['type_']
|
||||
self.attr = self.val.cast(self.type)
|
||||
self.attr_type = self.attr['type_']
|
||||
|
||||
def to_string(self) :
|
||||
# return "attribute_value"
|
||||
attr=self.attr
|
||||
attr_type = self.attr_type
|
||||
|
||||
if attr_type == 0:
|
||||
return ""
|
||||
|
@ -96,7 +135,24 @@ class AttributeValuePrinter(object) :
|
|||
return 't_string ' + ('%s' % attr['t_string_value_'])
|
||||
|
||||
return "attribute pretty printer found an unknown type"
|
||||
|
||||
|
||||
# def children(self):
|
||||
# attr=self.attr
|
||||
# attr_type = self.attr_type
|
||||
# if attr_type == 0:
|
||||
# raise StopIteration
|
||||
# elif attr_type == 1 :
|
||||
# yield 'bool', attr['bool_value_']
|
||||
# elif attr_type == 2 :
|
||||
# yield 'int' , attr['int_value_']
|
||||
# elif attr_type == 3 :
|
||||
# yield 'double' , attr['double_value_']
|
||||
# elif attr_type == 4 :
|
||||
# yield 'token' ,attr['token_value_']
|
||||
# else :
|
||||
# yield 't_string' , attr['t_string_value_']
|
||||
# raise StopIteration
|
||||
|
||||
def display_hint(self) :
|
||||
#one of 'string' 'array' 'map'
|
||||
return 'string'
|
||||
|
@ -125,7 +181,7 @@ class BoostUnorderedMapPrinter(object) :
|
|||
return self
|
||||
|
||||
def next(self):
|
||||
if self.buckets == 0 :
|
||||
if self.buckets == 0 or not RecursionManager.should_display() :
|
||||
raise StopIteration
|
||||
while not self.node:
|
||||
self.current_bucket = self.current_bucket + 1
|
||||
|
@ -141,8 +197,15 @@ class BoostUnorderedMapPrinter(object) :
|
|||
def __init__(self, val):
|
||||
self.val = val
|
||||
self.buckets = val['table_']['buckets_']
|
||||
self.descended = False;
|
||||
|
||||
def __del__(self) :
|
||||
if self.descended :
|
||||
RecursionManager.dec()
|
||||
|
||||
def children(self):
|
||||
self.descended = True;
|
||||
RecursionManager.inc()
|
||||
return self._iterator(self.val)
|
||||
|
||||
def to_string(self):
|
||||
|
@ -174,7 +237,8 @@ class BoostUnorderedMapIteratorPrinter(object):
|
|||
|
||||
def display_hint(self):
|
||||
return 'string'
|
||||
|
||||
|
||||
|
||||
|
||||
class ConfigPrinter(object) :
|
||||
"""Print a config"""
|
||||
|
@ -183,18 +247,28 @@ class ConfigPrinter(object) :
|
|||
|
||||
def to_string(self) :
|
||||
return "config"
|
||||
|
||||
def children(self) :
|
||||
#yield "invalid", self.val['invalid']
|
||||
yield "values", self.val['values']
|
||||
yield "children", self.val['children']
|
||||
yield "ordered_children", self.val['ordered_children']
|
||||
if RecursionManager.should_display() :
|
||||
#yield "invalid", self.val['invalid']
|
||||
yield "values", self.val['values']
|
||||
yield "children", self.val['children']
|
||||
RecursionManager.inc()
|
||||
yield "ordered_children", self.val['ordered_children']
|
||||
RecursionManager.dec()
|
||||
|
||||
else :
|
||||
pass
|
||||
# yield "values" , '...' #('%s' % self.val['values'].type)
|
||||
# yield "children" , '...' #('%s' % self.val['children'].type)
|
||||
# yield "ordered_children" , '...' #"std::vector<config::child_pos>"
|
||||
|
||||
|
||||
def display_hint(self) :
|
||||
#one of 'string' 'array' 'map'
|
||||
return 'string'
|
||||
|
||||
|
||||
|
||||
# register the pretty-printers
|
||||
def add_printers(pretty_printers_dict) :
|
||||
pretty_printers_dict[re.compile ('^n_interned::t_interned_token.*$')] = T_InternedPrinter
|
||||
|
|
Loading…
Add table
Reference in a new issue