X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/92f6e64a6da763c45ff9f4ab5eafcab3d8766dcb..b60166b327a9108b07e3069fa6568a451529ffd9:/lunaix-os/scripts/gdb/lunadbg/utils.py diff --git a/lunaix-os/scripts/gdb/lunadbg/utils.py b/lunaix-os/scripts/gdb/lunadbg/utils.py index 43d947a..3e5682d 100644 --- a/lunaix-os/scripts/gdb/lunadbg/utils.py +++ b/lunaix-os/scripts/gdb/lunadbg/utils.py @@ -4,13 +4,39 @@ def pid_argument(argument): if not argument: return "__current" else: - return f"sched_ctx._procs[({argument})]" + return f"sched_ctx.procs[({argument})]" -def llist_foreach(head, container_type, cb): +def llist_foreach(head: gdb.Value, container_type: gdb.Type, field, cb, inclusive=True): c = head i = 0 - while (c["next"] != head): - el = c["next"].cast(container_type) + offset = gdb.Value(0).cast(container_type)[field].address + offset_p = int(offset) + + if not inclusive: + c = c["next"] + if c == head: + return 0 + + while (True): + current = gdb.Value(int(c) - offset_p) + el = current.cast(container_type) cb(i, el) c = c["next"] - i+=1 \ No newline at end of file + i+=1 + if c == head: + break + return i + +def get_dnode_name(dnode): + return dnode['name']['value'].string() + +def get_dnode_path(dnode): + components = [] + current = dnode + while (current != 0 and current != current['parent']): + components.append(get_dnode_name(current)) + current = current['parent'] + if len(components) == 0: + components.append('') + components.append('') + return '/'.join(reversed(components)) \ No newline at end of file