diff options
Diffstat (limited to 'python/weenix/debug_userland.py')
-rw-r--r-- | python/weenix/debug_userland.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/python/weenix/debug_userland.py b/python/weenix/debug_userland.py new file mode 100644 index 0000000..07e8cc3 --- /dev/null +++ b/python/weenix/debug_userland.py @@ -0,0 +1,25 @@ +from elftools.elf.elffile import ELFFile +from os import path + +class DebugUserland(gdb.Command): + def __init__(self): + super(DebugUserland, self).__init__("debug-userland", gdb.COMMAND_USER) + + def invoke(self, arg, from_tty): + directory = 'user/usr/bin/' + filename = directory + arg + '.exec' + if not path.exists(filename): + filename = 'user/bin/' + arg + '.exec' + if arg == 'init': + filename = 'user/sbin/init.exec' + elf = ELFFile(open(filename, 'rb')) + text_section = elf.get_section_by_name('.text') + entry = text_section.header.sh_addr + gdb.execute(f"add-symbol-file {filename} {entry}") + + symtab = elf.get_section_by_name('.symtab') + main = symtab.get_symbol_by_name('main')[0] + main_addr = main.entry.st_value + gdb.execute(f"break *{main_addr}") + +DebugUserland() |