From c63f340d90800895f007de64b7d2d14624263331 Mon Sep 17 00:00:00 2001 From: nthnluu Date: Sun, 28 Jan 2024 21:20:27 -0500 Subject: Created student weenix repository --- python/weenix/debug_userland.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 python/weenix/debug_userland.py (limited to 'python/weenix/debug_userland.py') 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() -- cgit v1.2.3-70-g09d2