Skip to content

Commit 43e7a79

Browse files
committed
Implement Thread API for the live kernel
This commit implements the API outlined in #92 for the case where the current target is the live Linux kernel. In order to facilitate this, several of the already existing linux kernel helpers which were written in Python have been rewritten in C in order to make them accessible from libdrgn. Signed-off-by: Kevin Svetlitski <[email protected]>
1 parent 4a32bc9 commit 43e7a79

File tree

17 files changed

+964
-22
lines changed

17 files changed

+964
-22
lines changed

_drgn.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,10 @@ class Thread:
765765
prstatus: bytes
766766
""" The contents of the PRSTATUS note associated with this thread in the core dump. """
767767
object: Object
768-
""" Presently undefined. """
768+
"""
769+
If debugging the kernel, the ``struct task_struct *`` object for this thread.
770+
Otherwise, not defined.
771+
"""
769772
def stack_trace(self) -> StackTrace:
770773
"""
771774
A convenience function for retrieving the stack trace associated with a given thread.

drgn/helpers/linux/idr.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313

1414
from typing import Iterator, Tuple
1515

16-
from _drgn import _linux_helper_idr_find as idr_find
16+
from _drgn import (
17+
_linux_helper_idr_find as idr_find,
18+
_linux_helper_my_idr_for_each as my_idr_for_each,
19+
)
1720
from drgn import Object
1821
from drgn.helpers.linux.radixtree import radix_tree_for_each
1922

2023
__all__ = (
2124
"idr_find",
2225
"idr_for_each",
26+
"my_idr_for_each",
2327
)
2428

2529

drgn/helpers/linux/pid.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
_linux_helper_find_pid as find_pid,
1616
_linux_helper_find_task as find_task,
1717
_linux_helper_pid_task as pid_task,
18+
_linux_helper_my_for_each_task as my_for_each_task,
19+
_linux_helper_my_for_each_pid as my_for_each_pid,
1820
)
1921
from drgn import Object, Program, cast, container_of
2022
from drgn.helpers.linux.idr import idr_for_each
@@ -26,6 +28,8 @@
2628
"for_each_pid",
2729
"for_each_task",
2830
"pid_task",
31+
"my_for_each_task",
32+
"my_for_each_pid",
2933
)
3034

3135

drgn/helpers/linux/radixtree.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
from typing import Iterator, Tuple
1313

14-
from _drgn import _linux_helper_radix_tree_lookup as radix_tree_lookup
14+
from _drgn import (
15+
_linux_helper_radix_tree_lookup as radix_tree_lookup,
16+
_linux_helper_my_radix_tree_for_each as my_radix_tree_for_each,
17+
)
1518
from drgn import Object, cast
1619

17-
__all__ = (
18-
"radix_tree_for_each",
19-
"radix_tree_lookup",
20-
)
20+
__all__ = ("radix_tree_for_each", "radix_tree_lookup", "my_radix_tree_for_each")
2121

2222
_RADIX_TREE_ENTRY_MASK = 3
2323

libdrgn/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ libdrgnimpl_la_SOURCES = $(ARCH_DEFS:.defs=.c) \
4242
hash_table.c \
4343
hash_table.h \
4444
helpers.h \
45+
iterators.h \
46+
iterators.c \
4547
language.c \
4648
language.h \
4749
language_c.c \

0 commit comments

Comments
 (0)