From f0787c57d8914877f7d52165e78b1c5b417b3fdc Mon Sep 17 00:00:00 2001 From: Franciszek Zdobylak Date: Sat, 22 May 2021 21:13:33 +0200 Subject: [PATCH] Add printing vm_map to kdump --- sys/debug/README.md | 4 ++-- sys/debug/proc.py | 3 +++ sys/debug/virtmem.py | 21 ++++++++++++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/sys/debug/README.md b/sys/debug/README.md index 544bdb85f5..41395fe45a 100644 --- a/sys/debug/README.md +++ b/sys/debug/README.md @@ -16,8 +16,8 @@ you can use following custom commands: * `free_pages` - list of free pages per segment with virtual and physical addresses, -* `segments` - list all memory segments, incl. start, end addresses and - number of pages (currently just one), +* `vm_map` - list memory map of process of given pid (when number is given as argument) + or of current process (when no argument is given) * `klog` - all log messages currently saved in the kernel, * `threads` - all existing threads, * `tlb` - Translation Lookaside Buffer with addresses and flags marking if page diff --git a/sys/debug/proc.py b/sys/debug/proc.py index 96f11bedb3..da47d49a2f 100644 --- a/sys/debug/proc.py +++ b/sys/debug/proc.py @@ -43,6 +43,9 @@ def __repr__(self): def address(self): return self._obj.address + def vm_map(self): + return self._obj['p_uspace'] + class Kprocess(SimpleCommand): """List all processes.""" diff --git a/sys/debug/virtmem.py b/sys/debug/virtmem.py index b78f9bf2f3..987272d83d 100644 --- a/sys/debug/virtmem.py +++ b/sys/debug/virtmem.py @@ -4,6 +4,7 @@ from .cmd import UserCommand from .cpu import TLBLo from .utils import TextTable, global_var, cast +from .proc import Process PM_NQUEUES = 16 @@ -81,13 +82,19 @@ def __init__(self): def __call__(self, args): args = args.strip() - if args not in ['user', 'kernel']: - print('Choose either "user" or "kernel" vm_map!') - return - vm_map = gdb.parse_and_eval('vm_map_%s()' % args) - if vm_map == 0: - print('No active %s vm_map!' % args) - return + if len(args) == 0: + vm_map = gdb.parse_and_eval('vm_map_user()') + if vm_map == 0: + print('No active user vm_map!') + return + else: + pid = int(args) + proc = Process.from_pid(pid) + if proc is None: + print(f'No process of pid {pid}!') + return + vm_map = proc.vm_map() + entries = vm_map['entries'] table = TextTable(types='itttttt', align='rrrrrrr') table.header(['segment', 'start', 'end', 'prot', 'flags', 'object',