Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sys/debug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .sync import CondVar, Mutex
from .thread import Kthread, Thread, CurrentThread
from .events import stop_handler
from .virtmem import VmInfo


def addPrettyPrinters():
Expand All @@ -32,6 +33,7 @@ def addPrettyPrinters():
Kthread()
Ktrace()
Kgmon()
VmInfo()

# Functions
CurrentThread()
Expand Down
53 changes: 52 additions & 1 deletion sys/debug/cpu.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gdb

from .struct import GdbStructMeta
from .utils import TextTable, cast
from .utils import TextTable, cast, cast_ptr, get_arch
from .cmd import UserCommand, CommandDispatcher


Expand Down Expand Up @@ -110,3 +110,54 @@ class Cpu(CommandDispatcher):

def __init__(self):
super().__init__('cpu', [TLB()])


class PageTableMips():
def __init__(self, pmap):
self._pmap = pmap

def print(self):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't plan to add more methods to the class in this PR I suggest you convert it to a function. Right now the class looks like an overkill.

pdp = cast_ptr(self._pmap['pde'], 'pde_t')
table = TextTable(types='ttttt', align='rrrrr')
table.header(['vpn', 'pte0', 'pte1', 'pte2', 'pte3'])
for i in range(1024):
pde = TLBLo(pdp[i])
if not pde.valid:
continue
ptp = cast_ptr(pde.ppn, 'pte_t')
pte = [TLBLo(ptp[j]) for j in range(1024)]
for j in range(0, 1024, 4):
if not any(pte.valid for pte in pte[j:j+4]):
continue
pte4 = [str(pte) if pte.valid else '-' for pte in pte[j:j+4]]
table.add_row([f'{(i << 22) + (j << 12):8x}', pte4[0], pte4[1],
pte4[2], pte4[3]])
print(table)


class PageTableAArch64():
def __init__(self, pmap):
self._pmap = pmap
print("Page table not implemented for AArch64")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise NotImplementedError ?


def print(self):
pass


class PageTableRiscv():
def __init__(self, pmap):
self._pmap = pmap
print("Page table not implemented for RISC-V")

def print(self):
pass


if get_arch() == 'mips':
PageTable = PageTableMips
elif get_arch() == 'aarch64':
PageTable = PageTableAArch64
elif get_arch() == 'riscv':
PageTable = PageTableRiscv
else:
print(f'Arch {get_arch()} not supported')
8 changes: 4 additions & 4 deletions sys/debug/kdump.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .virtmem import VmPhysSeg, VmFreePages, VmMapSeg, PhysMap
from .memory import Vmem, MallocStats, PoolStats
from .cmd import CommandDispatcher

Expand All @@ -7,6 +6,7 @@ class Kdump(CommandDispatcher):
"""Examine kernel data structures."""

def __init__(self):
super().__init__('kdump', [VmPhysSeg(), VmFreePages(), VmMapSeg(),
PhysMap(), Vmem(), MallocStats(),
PoolStats()])
super().__init__('kdump', [Vmem(),
MallocStats(),
PoolStats(),
])
10 changes: 9 additions & 1 deletion sys/debug/proc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import gdb

from .cmd import SimpleCommand, AutoCompleteMixin
from .cmd import SimpleCommand
from .utils import TextTable, global_var
from .struct import GdbStructMeta, TailQueue, enum
from .thread import Thread
from .vm_map import VmMap
from .sync import Mutex


Expand All @@ -12,6 +13,7 @@ class Process(metaclass=GdbStructMeta):
__cast__ = {'p_pid': int,
'p_lock': Mutex,
'p_thread': Thread,
'p_uspace': VmMap,
'p_state': enum}

@staticmethod
Expand All @@ -32,6 +34,12 @@ def list_all(cls):
dead = TailQueue(global_var('zombie_list'), 'p_all')
return map(cls, list(alive) + list(dead))

@classmethod
def find_by_pid(cls, pid):
for p in cls.list_all():
if p.p_pid == pid:
return p

def __repr__(self):
return 'proc{pid=%d}' % self.p_pid

Expand Down
12 changes: 12 additions & 0 deletions sys/debug/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def cast(value, typename):
return value.cast(gdb.lookup_type(typename))


def cast_ptr(value, typename):
return value.cast(gdb.lookup_type(typename).pointer())


def local_var(name):
return gdb.newest_frame().read_var(name)

Expand All @@ -21,6 +25,14 @@ def relpath(path):
return path.rsplit('sys/')[-1]


def get_arch():
for arch in ['mips', 'aarch64', 'riscv']:
if arch in gdb.architecture_names():
return arch
print('Current architecture is not supported')
raise KeyError
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not it be NotImplementedError ?



# calculates address of ret instruction within function body (MIPS specific)
def func_ret_addr(name):
s = gdb.execute('disass thread_create', to_string=True)
Expand Down
Loading