Extend help to all commands

Also print 1 line summary or full output if called directly on command

Signed-off-by: Andrew Worsley <amworsley@gmail.com>
This commit is contained in:
Andrew Worsley 2021-06-22 18:13:09 +10:00 committed by Hector Martin
parent 8ec541ba46
commit eab52cc855
2 changed files with 35 additions and 12 deletions

View file

@ -185,6 +185,8 @@ class ProxyUtils(Reloadable):
self.iface.writemem(adt_base, self.adt_data)
def disassemble_at(self, start, size, pc=None):
'''Start, len, [pc] - disassemble len bytes of memory from start
optional pc address will mark that line with a '*' '''
code = struct.unpack(f"<{size // 4}I", self.iface.readmem(start, size))
c = ARMAsm(".inst " + ",".join(str(i) for i in code), start)

View file

@ -49,14 +49,29 @@ class ExitConsole(SystemExit):
pass
cmd_list = {}
def help_cmd():
def help_cmd(arg=None):
if arg:
if not callable(arg):
print("Unknown command: %s" % repr(arg))
return
cmd = arg.__name__
if cmd not in cmd_list:
print("Undocumented command %s" % cmd)
return
hinfo = cmd_list[cmd]
print("%-10s : %s" % (cmd, hinfo))
return
print("List of Commands:")
for cmd in cmd_list.keys():
hinfo = cmd_list[cmd]
if not hinfo:
print("%s ?" % cmd)
else:
print("%-10s : %s" % (cmd, hinfo))
msg = hinfo.strip().split('\n', 1)[0]
if len(cmd) <= 10:
print("%-10s : %s" % (cmd, msg))
else:
print("%s:\n %s" % (cmd, msg))
#locals is a dictionary for constructing the
# InteractiveConsole with. It adds in the callables
# in proxy utils iface and sysreg into locals
@ -97,19 +112,25 @@ def run_shell(locals, msg=None, exitmsg=None):
if callable(member) and not isinstance(member, property):
cmd = getattr(obj, attr)
locals[attr] = cmd
desc = locals[attr].__doc__
if not desc:
desc = repr(locals[attr])
desc = re.sub("<bound method ", "", desc)
desc = re.sub(" object at 0x[0-9a-fA-F]*>>", "", desc)
desc = re.sub('<', '', desc)
b = re.split(' ', desc)
if len(b) == 3:
desc = ".".join([b[2], re.split('\.', b[0])[-1]])
cmd_list[attr] = desc
for attr in dir(sysreg):
locals[attr] = getattr(sysreg, attr)
for obj_name in locals.keys():
obj = locals.get(obj_name)
if obj is None:
continue
if callable(obj) and not isinstance(obj, property):
desc = locals[obj_name].__doc__
if not desc:
desc = repr(locals[obj_name])
desc = re.sub("<bound method ", "", desc)
desc = re.sub(" object at 0x[0-9a-fA-F]*>>", "", desc)
desc = re.sub('<', '', desc)
b = re.split(' ', desc)
if len(b) == 3:
desc = ".".join([b[2], re.split('\.', b[0])[-1]])
cmd_list[obj_name] = desc
locals['help'] = help_cmd
try: