Skip to content

Commit bae4146

Browse files
committed
stack state WIP
1 parent fbc215c commit bae4146

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

sdb/commands/linux/stacks.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import drgn
2424
from drgn.helpers.linux.list import list_for_each_entry
2525
from drgn.helpers.linux.pid import for_each_task
26+
from drgn.helpers.linux.sched import task_state_to_char
2627

2728
import sdb
2829

@@ -203,22 +204,12 @@ def _init_parser(cls, name: str) -> argparse.ArgumentParser:
203204
"t": 0x08,
204205
"X": 0x10,
205206
"Z": 0x20,
207+
"I": 0x402,
206208
}
207209

208210
@staticmethod
209211
def task_struct_get_state(task: drgn.Object) -> str:
210-
task_struct_type = task.type_.type
211-
state = 0
212-
if task_struct_type.has_member('__state'):
213-
state = task.member_('__state').value_()
214-
else:
215-
# For kernels older than v5.14
216-
state = task.state.value_()
217-
if state == 0x402:
218-
return "IDLE"
219-
220-
exit_state = task.exit_state.value_()
221-
return KernelStacks.TASK_STATES[(state | exit_state) & 0x7f]
212+
return task_state_to_char(task)
222213

223214
@staticmethod
224215
def resolve_state(tstate: str) -> str:
@@ -381,7 +372,7 @@ def print_stacks(self, objs: Iterable[drgn.Object]) -> None:
381372
self.print_header()
382373
for stack_key, tasks in KernelStacks.aggregate_stacks(objs):
383374
stacktrace_info = ""
384-
task_state = stack_key[0]
375+
task_state = KernelStacks.resolve_state(stack_key[0])
385376

386377
if self.args.all:
387378
for task in tasks:

sdb/commands/linux/threads.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,20 @@ class KernelThreads(sdb.Locator, sdb.PrettyPrinter):
7878
load_on = [sdb.Kernel()]
7979

8080
FIELDS: Dict[str, Callable[[drgn.Object], Union[str, int]]] = {
81-
"task": lambda obj: hex(obj.value_()),
82-
"state": lambda obj: str(KernelStacks.task_struct_get_state(obj)),
83-
"pid": lambda obj: int(obj.pid),
84-
"prio": lambda obj: int(obj.prio),
85-
"comm": lambda obj: str(obj.comm.string_().decode("utf-8")),
86-
"cmdline": _cmdline,
81+
"task":
82+
lambda obj: hex(obj.value_()),
83+
"state":
84+
lambda obj: str(
85+
KernelStacks.resolve_state(
86+
KernelStacks.task_struct_get_state(obj))),
87+
"pid":
88+
lambda obj: int(obj.pid),
89+
"prio":
90+
lambda obj: int(obj.prio),
91+
"comm":
92+
lambda obj: str(obj.comm.string_().decode("utf-8")),
93+
"cmdline":
94+
_cmdline,
8795
}
8896

8997
def pretty_print(self, objs: Iterable[drgn.Object]) -> None:

0 commit comments

Comments
 (0)