5-malloc.md (#25)
[lunaix-os.git] / lunaix-os / scripts / gdb / lunadbg / sched_dump.py
1 import gdb
2 from .utils import pid_argument, llist_foreach
3 from .pp import MyPrettyPrinter
4 from .structs.pcb import ProcInfo
5 from .structs.scheduler import Scheduler
6 from .commands import LunadbgCommand
7        
8 class ProcessDump(LunadbgCommand):
9     """Dump the state of Lunaix PCB"""
10     def __init__(self) -> None:
11         super().__init__("proc")
12
13     def invoke(self, argument: str, from_tty: bool) -> None:
14         pp = MyPrettyPrinter()
15         ProcInfo.process_at(argument).print_detailed(pp)
16
17
18 class SchedulerDump(LunadbgCommand):
19     """Dump the state of Lunaix process table"""
20     def __init__(self) -> None:
21         super().__init__("sched")
22         self._parser.add_argument("print_type")
23         self._parser.add_argument("-l", "--long-list", 
24                                   required=False, default=False, action='store_true')
25
26     def invoke(self, argument: str, from_tty: bool) -> None:
27         args = self._parse_args(argument)
28         if args is None:
29             return
30         
31         sched_context = gdb.parse_and_eval("&sched_ctx")
32         sched = Scheduler(sched_context)
33
34         sched.print_detailed(MyPrettyPrinter(), args.print_type, args.long_list)