fix dependency check logic cause config always disabled
[lunaix-os.git] / lunaix-os / scripts / gdb / lunadbg / utils.py
1 import gdb
2
3 def pid_argument(argument):
4     if not argument:
5         return "__current"
6     else:
7         return f"sched_ctx.procs[({argument})]"
8
9 def llist_foreach(head: gdb.Value, container_type: gdb.Type, field, cb, inclusive=True):
10     c = head
11     i = 0
12     offset = gdb.Value(0).cast(container_type)[field].address
13     offset_p = int(offset)
14
15     if not inclusive:
16         c = c["next"]
17         if c == head:
18             return 0
19
20     while (True):
21         current = gdb.Value(int(c) - offset_p)
22         el = current.cast(container_type)
23         cb(i, el)
24         c = c["next"]
25         i+=1
26         if c == head:
27             break
28     return i
29
30 def get_dnode_name(dnode):
31     return dnode['name']['value'].string()
32
33 def get_dnode_path(dnode):
34     components = []
35     current = dnode
36     while (current != 0 and current != current['parent']):
37         components.append(get_dnode_name(current))
38         current = current['parent']
39     if len(components) == 0:
40         components.append('')
41     components.append('')
42     return '/'.join(reversed(components))