Unifying the Lunaix's Physical Memory Model (#28)
[lunaix-os.git] / lunaix-os / scripts / gdb / lunadbg / structs / signal.py
1 from gdb import Type, Value, lookup_type
2 from . import KernelStruct
3 from ..pp import MyPrettyPrinter
4
5 class SignalContext(KernelStruct):
6     __SIGNUM = 16
7     def __init__(self, gdb_inferior: Value) -> None:
8         super().__init__(gdb_inferior, SignalContext)
9
10     @staticmethod
11     def get_type() -> Type:
12         return lookup_type("struct sigctx").pointer()
13
14     def print_abstract(self, pp : MyPrettyPrinter, *args):
15         sigactive = self._kstruct["sig_active"]
16         sigpending = SignalHelper.get_sig_bitmap(self._kstruct["sig_pending"])
17
18         pp.print(f"sig: handling={sigactive}, pending=[{sigpending}]")
19     
20     def print_simple(self, pp : MyPrettyPrinter, *args):
21         pp.print_field(self._kstruct, "sig_active")
22         pp.print_field(self._kstruct, "sig_pending", cast=SignalHelper.get_sig_bitmap)
23         pp.print_field(self._kstruct, "sig_mask", cast=SignalHelper.get_sig_bitmap)
24
25         order = []
26         active = int(self._kstruct['sig_active'])
27         sig_order = self._kstruct["sig_order"]
28         while active != 0:
29             order.append(str(active))
30             active = int(sig_order[active])
31
32         pp.print("nestings:", ' -> '.join(reversed(order)))
33     
34     def print_detailed(self, pp, *args):
35         self.print_simple(pp)
36     
37
38
39 class SignalHelper:
40
41     @staticmethod
42     def get_sig_bitmap(sigbmp):
43         if sigbmp == 0:
44             return '<None>'
45         v = []
46         i = 0
47         while sigbmp != 0:
48             if sigbmp & 1 != 0:
49                 v.append(str(i))
50             sigbmp = sigbmp >> 1
51             i+=1
52         return ",".join(v)