aboutsummaryrefslogtreecommitdiff
path: root/python/weenix/debug_userland.py
diff options
context:
space:
mode:
authornthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
committernthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
commitc63f340d90800895f007de64b7d2d14624263331 (patch)
tree2c0849fa597dd6da831c8707b6f2603403778d7b /python/weenix/debug_userland.py
Created student weenix repository
Diffstat (limited to 'python/weenix/debug_userland.py')
-rw-r--r--python/weenix/debug_userland.py25
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()