Skip to content

Commit 4f1ff11

Browse files
author
Prakash Surya
committed
WIP: Add "cmdline" column to "threads" command
1 parent 76813d8 commit 4f1ff11

File tree

5 files changed

+1269
-1244
lines changed

5 files changed

+1269
-1244
lines changed

sdb/commands/threads.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,40 @@
1616

1717
# pylint: disable=missing-docstring
1818

19+
from textwrap import shorten
1920
from typing import Callable, Dict, Iterable, Union
2021

2122
import drgn
2223
from drgn.helpers.linux.pid import for_each_task
24+
from drgn.helpers.linux.mm import cmdline
2325

2426
import sdb
2527
from sdb.commands.internal.table import Table
2628
from sdb.commands.stacks import Stacks
2729

2830

31+
def _cmdline(obj: drgn.Object) -> str:
32+
try:
33+
s = " ".join(map(lambda s: s.decode("utf-8"), cmdline(obj)))
34+
35+
#
36+
# The command line for a given thread can be obnoxiously long,
37+
# so (by default) we limit it to 50 characters here. This helps
38+
# preserve the readability of the command's output, but comes at
39+
# the cost of not always showing the full command line of a
40+
# thread.
41+
#
42+
return shorten(s, width=50)
43+
except drgn.FaultError:
44+
#
45+
# The command line information is contained in the user address
46+
# space of each thread, rather than in the kernel's address
47+
# space. Thus, often, it may not be possible to retreive the
48+
# thread's command line; e.g. when reading from a core dump.
49+
#
50+
return ""
51+
52+
2953
class Threads(sdb.Locator, sdb.PrettyPrinter):
3054
"""
3155
Locate and print information about threads (task_stuct)
@@ -36,16 +60,16 @@ class Threads(sdb.Locator, sdb.PrettyPrinter):
3660
pid - the pid of the thread's process
3761
prio - the priority of the thread
3862
comm - the thread's command
63+
cmdline - the thread's command line (when available)
3964
4065
EXAMPLE
4166
sdb> threads | filter 'obj.comm == "java"' | threads
42-
task state pid prio comm
43-
------------------ ------------- ---- ---- ----
44-
0xffff95d48b0e8000 INTERRUPTIBLE 4386 120 java
45-
0xffff95d48b0e96c0 INTERRUPTIBLE 4388 120 java
46-
0xffff95d48b0ead80 INTERRUPTIBLE 4387 120 java
47-
0xffff95d48b0edb00 INTERRUPTIBLE 4304 120 java
48-
0xffff95d4af20ad80 INTERRUPTIBLE 4395 120 java
67+
task state pid prio comm cmdline
68+
------------------ ------------- ---- ---- ---- ----------------------------------------
69+
0xffff8c96a7c70000 INTERRUPTIBLE 3029 120 java /usr/bin/java -Ddelphix.debug=true [...]
70+
0xffff8c96a7c71740 INTERRUPTIBLE 3028 120 java /usr/bin/java -Ddelphix.debug=true [...]
71+
0xffff8c96a7c75d00 INTERRUPTIBLE 3024 120 java /usr/bin/java -Ddelphix.debug=true [...]
72+
0xffff8c9715808000 INTERRUPTIBLE 3027 120 java /usr/bin/java -Ddelphix.debug=true [...]
4973
"""
5074

5175
names = ["threads", "thread"]
@@ -58,6 +82,7 @@ class Threads(sdb.Locator, sdb.PrettyPrinter):
5882
"pid": lambda obj: int(obj.pid),
5983
"prio": lambda obj: int(obj.prio),
6084
"comm": lambda obj: str(obj.comm.string_().decode("utf-8")),
85+
"cmdline": lambda obj: _cmdline(obj),
6186
}
6287

6388
def pretty_print(self, objs: Iterable[drgn.Object]) -> None:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
task state pid prio comm
2-
---- ----- --- ---- ----
1+
task state pid prio comm cmdline
2+
---- ----- --- ---- ---- -------

0 commit comments

Comments
 (0)