B-C
view release on metacpan or search on metacpan
.gdb/dashboard view on Meta::CPAN
'default': '32'
},
'style_low': {
'default': '1;30'
},
'style_high': {
'default': '1;37'
},
'style_error': {
'default': '31'
}
}
# Common -----------------------------------------------------------------------
def run(command):
return gdb.execute(command, to_string=True)
def ansi(string, style):
if R.ansi:
return '[{}m{}[0m'.format(style, string)
else:
return string
def divider(label='', primary=False, active=True):
width = Dashboard.term_width
if primary:
divider_fill_style = R.divider_fill_style_primary
divider_fill_char = R.divider_fill_char_primary
divider_label_style_on = R.divider_label_style_on_primary
divider_label_style_off = R.divider_label_style_off_primary
else:
divider_fill_style = R.divider_fill_style_secondary
divider_fill_char = R.divider_fill_char_secondary
divider_label_style_on = R.divider_label_style_on_secondary
divider_label_style_off = R.divider_label_style_off_secondary
if label:
if active:
divider_label_style = divider_label_style_on
else:
divider_label_style = divider_label_style_off
skip = R.divider_label_skip
margin = R.divider_label_margin
before = ansi(divider_fill_char * skip, divider_fill_style)
middle = ansi(label, divider_label_style)
after_length = width - len(label) - skip - 2 * margin
after = ansi(divider_fill_char * after_length, divider_fill_style)
if R.divider_label_align_right:
before, after = after, before
return ''.join([before, ' ' * margin, middle, ' ' * margin, after])
else:
return ansi(divider_fill_char * width, divider_fill_style)
def check_gt_zero(x):
return x > 0
def check_ge_zero(x):
return x >= 0
def to_unsigned(value, size=8):
# values from GDB can be used transparently but are not suitable for
# being printed as unsigned integers, so a conversion is needed
return int(value.cast(gdb.Value(0).type)) % (2 ** (size * 8))
def format_address(address):
return '0x{:016x}'.format(address)
# Dashboard --------------------------------------------------------------------
class Dashboard(gdb.Command):
"""Redisplay the dashboard."""
def __init__(self):
gdb.Command.__init__(self, 'dashboard',
gdb.COMMAND_USER, gdb.COMPLETE_NONE, True)
self.enabled = True
# setup subcommands
Dashboard.EnabledCommand(self)
Dashboard.LayoutCommand(self)
# setup style commands
Dashboard.StyleCommand(self, 'dashboard', R, R.attributes())
# setup events
gdb.events.cont.connect(lambda _: self.on_continue())
gdb.events.stop.connect(lambda _: self.on_stop())
gdb.events.exited.connect(lambda _: self.on_exit())
def on_continue(self):
if self.enabled and self.is_running():
os.system('clear')
print(divider('Output/messages', True))
self.pre_display = False
def on_stop(self):
if self.enabled and self.is_running():
self.display()
def on_exit(self):
pass
def load_modules(self, modules):
self.modules = []
for module in modules:
info = Dashboard.ModuleInfo(self, module)
self.modules.append(info)
def redisplay(self):
if self.is_running():
os.system('clear')
self.display()
def inferior_pid(self):
return gdb.selected_inferior().pid
def is_running(self):
return self.inferior_pid() != 0
def display(self):
Dashboard.update_term_width()
# fetch lines
lines = []
for module in self.modules:
.gdb/dashboard view on Meta::CPAN
def invoke(self, arg, from_tty):
arg = Dashboard.parse_arg(arg)
if arg == '':
status = 'enabled' if self.dashboard.enabled else 'disabled'
print('The dashboard is {}'.format(status))
elif arg == 'on':
self.dashboard.enabled = True
self.dashboard.redisplay()
elif arg == 'off':
self.dashboard.enabled = False
else:
msg = 'Wrong argument "{}"; expecting "on" or "off"'
Dashboard.err(msg.format(arg))
def complete(self, text, word):
return Dashboard.complete(word, ['on', 'off'])
class LayoutCommand(gdb.Command):
"""Set or show the dashboard layout.
Accepts a space-separated list of directive. Each directive is in the form
"[!]<module>". Modules in the list are placed in the dashboard in the same order
as they appear and those prefixed by "!" are disabled by default. Omitted
modules are hidden and placed at the bottom in alphabetical order. Without
arguments the current layout is shown; enabled and disabled modules are properly
marked."""
def __init__(self, dashboard):
gdb.Command.__init__(self, 'dashboard -layout', gdb.COMMAND_USER)
self.dashboard = dashboard
def invoke(self, arg, from_tty):
arg = Dashboard.parse_arg(arg)
directives = str(arg).split()
if directives:
self.layout(directives)
if from_tty and not self.dashboard.is_running():
self.show()
else:
self.show()
def show(self):
for module in self.dashboard.modules:
style = R.style_high if module.enabled else R.style_low
print(ansi(module.name, style))
def layout(self, directives):
modules = self.dashboard.modules
# reset visibility
for module in modules:
module.enabled = False
# move and enable the selected modules on top
last = 0
n_enabled = 0
for directive in directives:
# parse next directive
enabled = (directive[0] != '!')
name = directive[not enabled:]
try:
# it may actually start from last, but in this way repeated
# modules can be handler transparently and without error
todo = enumerate(modules[last:], start=last)
index = next(i for i, m in todo if name == m.name)
modules[index].enabled = enabled
modules.insert(last, modules.pop(index))
last += 1
n_enabled += enabled
except StopIteration:
def find_module(x):
return x.name == name
first_part = modules[:last]
if len(filter(find_module, first_part)) == 0:
Dashboard.err('Cannot find module "{}"'.format(name))
else:
Dashboard.err('Module "{}" already set'.format(name))
continue
# redisplay the dashboard
if n_enabled:
self.dashboard.redisplay()
def complete(self, text, word):
all_modules = (m.name for m in self.dashboard.modules)
return Dashboard.complete(word, all_modules)
class StyleCommand(gdb.Command):
"""Access the stylable attributes.
Without arguments print all the stylable attributes. Subcommands are used to set
or print (when the value is omitted) individual attributes."""
def __init__(self, dashboard, prefix, obj, attributes):
self.prefix = prefix + ' -style'
gdb.Command.__init__(self, self.prefix,
gdb.COMMAND_USER, gdb.COMPLETE_NONE, True)
self.dashboard = dashboard
self.obj = obj
self.attributes = attributes
self.add_styles()
def add_styles(self):
this = self
for name, attribute in self.attributes.items():
# fetch fields
attr_name = attribute.get('name', name)
attr_type = attribute.get('type', str)
attr_check = attribute.get('check', lambda _: True)
attr_default = attribute['default']
# set the default value (coerced to the type)
value = attr_type(attr_default)
setattr(self.obj, attr_name, value)
# create the command
def invoke(self, arg, from_tty, name=name, attr_name=attr_name,
attr_type=attr_type, attr_check=attr_check):
new_value = Dashboard.parse_arg(arg)
if new_value == '':
# print the current value
value = getattr(this.obj, attr_name)
print('{} = {!r}'.format(name, value))
else:
try:
# convert and check the new value
parsed = ast.literal_eval(new_value)
( run in 1.908 second using v1.01-cache-2.11-cpan-7fcb06a456a )