diff --git a/toolchain/gdbinit b/toolchain/gdbinit index d7bece1..3dfdf83 100644 --- a/toolchain/gdbinit +++ b/toolchain/gdbinit @@ -8,15 +8,50 @@ monitor quit quit end -define reg -monitor info registers -end - define reset monitor system_reset end +define mmap +monitor info mem +end + python import os gdb.execute('file ' + os.environ['BUILDROOT'] + '/sysroot/kernel') -end \ No newline at end of file +end + +python + +import re + +class Reg(gdb.Command): + + def __init__(self): + super(Reg, self).__init__("reg", gdb.COMMAND_USER) + + def invoke(self, arg, from_tty): + regs = gdb.execute('monitor info registers', False, True) + + if not arg: + print(regs) + return + + if arg.upper() in ['CS', 'DS', 'ES', 'FS', 'GS', 'SS']: + for l in regs.splitlines(): + if l.startswith(arg.upper()): + print(l) + elif arg.upper() in ['EFL', 'RFL']: + for l in regs.splitlines(): + if arg.upper() in l: + print(' '.join(l.split()[1:])) + else: + regex = f"\\b{arg.upper()}\\s?=[a-zA-Z0-9]*\\b" + matches = re.findall(regex, regs) + if matches: + print(matches[0]) + else: + print(f"Register {arg.upper()} unknown") + +Reg() +end