B-C
view release on metacpan or search on metacpan
.gdb/dashboard view on Meta::CPAN
@staticmethod
def set_custom_prompt(dashboard):
def custom_prompt(_):
# render thread status indicator
if dashboard.is_running():
pid = dashboard.inferior_pid()
status = R.prompt_running.format(pid=pid)
else:
status = R.prompt_not_running
# build prompt
prompt = R.prompt.format(status=status)
prompt = gdb.prompt.substitute_prompt(prompt)
return prompt + ' ' # force trailing space
gdb.prompt_hook = custom_prompt
@staticmethod
def parse_inits(python):
for root, dirs, files in os.walk(os.path.expanduser('~/.gdbinit.d/')):
dirs.sort()
for init in sorted(files):
path = os.path.join(root, init)
_, ext = os.path.splitext(path)
# either load Python files or GDB
if python ^ (ext != '.py'):
gdb.execute('source ' + path)
@staticmethod
def get_modules():
# scan the scope for modules
modules = []
for name in globals():
obj = globals()[name]
try:
if issubclass(obj, Dashboard.Module):
modules.append(obj)
except TypeError:
continue
# sort modules alphabetically
modules.sort(key=lambda x: x.__name__)
return modules
@staticmethod
def create_command(name, invoke, doc, is_prefix, complete=None):
Class = type('', (gdb.Command,), {'invoke': invoke, '__doc__': doc})
Class(name, gdb.COMMAND_USER, complete or gdb.COMPLETE_NONE, is_prefix)
@staticmethod
def err(string):
print(ansi(string, R.style_error))
@staticmethod
def complete(word, candidates):
matching = []
for candidate in candidates:
if candidate.startswith(word):
matching.append(candidate)
return matching
@staticmethod
def parse_arg(arg):
# encode unicode GDB command arguments as utf8 in Python 2.7
if type(arg) is not str:
arg = arg.encode('utf8')
return arg
# Module descriptor ------------------------------------------------------------
class ModuleInfo:
def __init__(self, dashboard, module):
self.name = module.__name__.lower() # from class to module name
self.enabled = True
self.instance = module()
self.doc = self.instance.__doc__ or '(no documentation)'
self.prefix = 'dashboard {}'.format(self.name)
# add GDB commands
self.add_main_command(dashboard)
self.add_style_command(dashboard)
self.add_subcommands(dashboard)
def add_main_command(self, dashboard):
module = self
def invoke(self, arg, from_tty, info=self):
arg = Dashboard.parse_arg(arg)
if arg == '':
info.enabled ^= True
if dashboard.is_running():
dashboard.redisplay()
else:
status = 'enabled' if info.enabled else 'disabled'
print('{} module {}'.format(module.name, status))
else:
Dashboard.err('Wrong argument "{}"'.format(arg))
doc_brief = 'Configure the {} module.'.format(self.name)
doc_extended = 'Toggle the module visibility.'
doc = '{}\n{}\n\n{}'.format(doc_brief, doc_extended, self.doc)
Dashboard.create_command(self.prefix, invoke, doc, True)
def add_style_command(self, dashboard):
if 'attributes' in dir(self.instance):
Dashboard.StyleCommand(dashboard, self.prefix, self.instance,
self.instance.attributes())
def add_subcommands(self, dashboard):
if 'commands' in dir(self.instance):
for name, command in self.instance.commands().items():
self.add_subcommand(dashboard, name, command)
def add_subcommand(self, dashboard, name, command):
action = command['action']
doc = command['doc']
complete = command.get('complete')
def invoke(self, arg, from_tty, info=self):
arg = Dashboard.parse_arg(arg)
if info.enabled:
try:
action(arg)
except Exception as e:
Dashboard.err(e)
return
# don't catch redisplay errors
( run in 0.442 second using v1.01-cache-2.11-cpan-39bf76dae61 )