gdb helpers

This commit is contained in:
Thomas Lovén 2022-01-02 22:53:17 +01:00
parent aca48a1ed0
commit 0f28d5ae84

View File

@ -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
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