Skip to content

Commit

Permalink
scripts/gdb: add iteration function for rbtree
Browse files Browse the repository at this point in the history
Add inorder iteration function for rbtree usage.

This is a preparation patch for the next patch to fix the gdb mounts
issue.

Link: https://lkml.kernel.org/r/20240723064902.124154-3-kuan-ying.lee@canonical.com
Fixes: 2eea9ce ("mounts: keep list of mounts in an rbtree")
Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Kieran Bingham <kbingham@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
kylee0215 authored and akpm00 committed Jul 25, 2024
1 parent 0b99969 commit 8d033da
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/gdb/linux/rbtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
rb_root_type = utils.CachedType("struct rb_root")
rb_node_type = utils.CachedType("struct rb_node")

def rb_inorder_for_each(root):
def inorder(node):
if node:
yield from inorder(node['rb_left'])
yield node
yield from inorder(node['rb_right'])

yield from inorder(root['rb_node'])

def rb_inorder_for_each_entry(root, gdbtype, member):
for node in rb_inorder_for_each(root):
yield utils.container_of(node, gdbtype, member)

def rb_first(root):
if root.type == rb_root_type.get_type():
Expand Down

0 comments on commit 8d033da

Please sign in to comment.