Commit Graph

25 Commits

Author SHA1 Message Date
Omar Sandoval
cf0b75420c contrib/vmmap.py: use new for_each_vma() helper
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-10-30 13:09:21 -07:00
Imran Khan
754b7be807 contrib: add script to dump irq stats.
Sample output:

python3 -m drgn -s vmlinux -c vmcore contrib/irq.py

List of IRQs
irq: 0 name: timer (struct irq_desc *)0xffff9b42fd00d400  (struct irqaction *)0xffffffff88425240
irq: 1 name: i8042 (struct irq_desc *)0xffff9b42fd00d600  (struct irqaction *)0xffff9b42fcb13c00
irq: 4 name: ttyS0 (struct irq_desc *)0xffff9b42fd00dc00  (struct irqaction *)0xffff9b42fcb2bc00
irq: 8 name: rtc0 (struct irq_desc *)0xffff9b42fd00e400  (struct irqaction *)0xffff9b42fcb59380
irq: 9 name: acpi (struct irq_desc *)0xffff9b42fd00e600  (struct irqaction *)0xffff9b42fcafca80
irq: 11 name: eth0 (struct irq_desc *)0xffff9b42fd00ea00  (struct irqaction *)0xffff9b42fc878d80
irq: 12 name: i8042 (struct irq_desc *)0xffff9b42fd00ec00  (struct irqaction *)0xffff9b42fcb13900
irq: 14 name: ata_piix (struct irq_desc *)0xffff9b42fd00f000  (struct irqaction *)0xffff9b42fc690800
irq: 15 name: ata_piix (struct irq_desc *)0xffff9b42fd00f200  (struct irqaction *)0xffff9b42fc690780

IRQ affinities
irq: 0 name: timer affinity: 0-7
irq: 1 name: i8042 affinity: 0-7
irq: 4 name: ttyS0 affinity: 0-7
irq: 8 name: rtc0 affinity: 0-7
irq: 9 name: acpi affinity: 0-7
irq: 11 name: eth0 affinity: 0-7
irq: 12 name: i8042 affinity: 0-7
irq: 14 name: ata_piix affinity: 0-7
irq: 15 name: ata_piix affinity: 0-7

IRQ stats
irq: 0 name: timer (struct irq_desc *)0xffff9b42fd00d400
    CPU: 0  	 count: 162
    Total: 162
irq: 1 name: i8042 (struct irq_desc *)0xffff9b42fd00d600
    CPU: 0  	 count: 10
    Total: 10
irq: 4 name: ttyS0 (struct irq_desc *)0xffff9b42fd00dc00
    CPU: 0  	 count: 220
    Total: 220
irq: 8 name: rtc0 (struct irq_desc *)0xffff9b42fd00e400
    CPU: 0  	 count: 1
    Total: 1
    Total: 0
irq: 11 name: eth0 (struct irq_desc *)0xffff9b42fd00ea00
    CPU: 0  	 count: 85
    Total: 85
irq: 12 name: i8042 (struct irq_desc *)0xffff9b42fd00ec00
    CPU: 0  	 count: 125
    Total: 125
irq: 14 name: ata_piix (struct irq_desc *)0xffff9b42fd00f000
    CPU: 0  	 count: 496
    Total: 496
irq: 15 name: ata_piix (struct irq_desc *)0xffff9b42fd00f200
    CPU: 0  	 count: 11
    Total: 11

cpuwise IRQ stats
IRQ stats for cpu: 0
    irq: 0 name: timer (struct irq_desc *)0xffff9b42fd00d400 count: 162
    irq: 1 name: i8042 (struct irq_desc *)0xffff9b42fd00d600 count: 10
    irq: 4 name: ttyS0 (struct irq_desc *)0xffff9b42fd00dc00 count: 220
    irq: 8 name: rtc0 (struct irq_desc *)0xffff9b42fd00e400 count: 1
    irq: 11 name: eth0 (struct irq_desc *)0xffff9b42fd00ea00 count: 85
    irq: 12 name: i8042 (struct irq_desc *)0xffff9b42fd00ec00 count: 125
    irq: 14 name: ata_piix (struct irq_desc *)0xffff9b42fd00f000 count: 496
    irq: 15 name: ata_piix (struct irq_desc *)0xffff9b42fd00f200 count: 11
Total: 1110

IRQ stats for cpu: 1
Total: 0

IRQ stats for cpu: 2
Total: 0

IRQ stats for cpu: 3
Total: 0

IRQ stats for cpu: 4
Total: 0

IRQ stats for cpu: 5
Total: 0

IRQ stats for cpu: 6
Total: 0

IRQ stats for cpu: 7
Total: 0

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
2023-10-25 09:28:29 -07:00
Omar Sandoval
54f5fa044f contrib/find_struct_file.py: also look in binfmt_misc
This is a surprising place where file references can be hiding that I've
run into before. There are some beginnings of an lsof-like script here.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-10-16 10:45:45 -07:00
Omar Sandoval
185a5bf66d contrib: add stack_trace_call_fault.py
It's difficult to automatically detect calling an invalid, non-NULL
pointer when getting a stack trace. This manually recreates what we do
for calls to NULL since commit 412ce956b0 ("libdrgn: x86_64: unwind
call when pc is 0"). This was used to debug the issue fixed by "net:
tcp: fix crashes trying to free half-baked MTU probes" [1].

1: https://lore.kernel.org/all/20231010173651.3990234-1-kuba@kernel.org/T/

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-10-13 16:48:21 -07:00
Omar Sandoval
bbaf608af0 contrib: add find_struct_file.py
I used this to find some missing sockets that weren't showing up in lsof
or ss.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-10-13 16:39:17 -07:00
Stephen Brennan
535563b6a7 contrib: ptdrgn: Improve Object completion
Completion of drgn Objects *is* already possible in ptpython, but
unfortunately the list of completions is alphabetical (except for
underscored attributes, which are last). This means that default Object
fields like "absent_" and "type_" are not distinguished from the Object
member fields.

Resolve this by detecting when the first completion is "absent_" and
then moving all the non-default completions to the beginning of the
list. The result is that Object members are enumerated first, followed
by the default Object fields.

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2023-09-06 21:57:39 -07:00
Stephen Brennan
aa851c84fc contrib: Add ptdrgn.py script to run interactively via ptpython
ptpython is a really excellent REPL library which provides great
multiline history and editing support, as well as syntax highlighting,
and a nice code completion UI.

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2023-09-06 21:57:39 -07:00
Piyush Sachdeva
79b30e9a8d script/ps: enhanced ps script
Enhanced the `ps.py` script and made it more modular to support the
following options:
	[-a | --active] thread on each CPU
	[-c | --childs] processes info
	[--cpus] Ready/running proccesses for the given cpu
	[-d | --detailed] information (in addition to standard)
	[--hierarchy] of all parent processes
	[-k | --kthread] information on the given kernel threads
	[-u | --uthread] information on the given user-space threads
	[-t | --threads] information on the given threads

These options make the scipt more versatile and useful.

Signed-off-by: Jay Patel <jaypatel@linux.ibm.com>
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Signed-off-by: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Piyush Sachdeva <piyushs@linux.ibm.com>
2023-08-29 09:46:45 -07:00
Omar Sandoval
9ad47a97eb contrib: add script to dump platform drivers
For a discussion on the linux-debuggers mailing list:
https://lore.kernel.org/linux-debuggers/87v8fiw0fm.fsf@oracle.com/T/#t

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-20 11:11:23 -07:00
Johannes Thumshirn
e4b7749463 contrib: add btrfs block group dumper
Add a script to dump all btrfs block groups and decode relevant members to
contrib.

Example output for a given filesystem:
BG at 536870912
        flags: BTRFS_BLOCK_GROUP_DATA (0x1)
        length: 134217728
        used: 0
        pinned: 0
        reserved: 0
        runtime_flags: BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE|BLOCK_GROUP_FLAG_SEQUENTIAL_ZONE (0x120)
        zone_unsuable: 0

BG at 671088640
        flags: BTRFS_BLOCK_GROUP_SYSTEM|BTRFS_BLOCK_GROUP_DUP (0x22)
        length: 134217728
        used: 16384
        pinned: 0
        reserved: 0
        runtime_flags: BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE|BLOCK_GROUP_FLAG_SEQUENTIAL_ZONE (0x120)
        zone_unsuable: 16384

BG at 805306368
        flags: BTRFS_BLOCK_GROUP_METADATA|BTRFS_BLOCK_GROUP_DUP (0x24)
        length: 134217728
        used: 131072
        pinned: 0
        reserved: 0
        runtime_flags: BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE|BLOCK_GROUP_FLAG_SEQUENTIAL_ZONE (0x120)
        zone_unsuable: 147456

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
2023-06-14 16:36:13 -07:00
Boris Burkov
c0694d6ce2 Add btrfs helpers to contrib
btrfs_tree.py is a pile of helpers Omar gave me once that I have
cherished ever since. It mostly deals with walking and parsing btrees.

btrfs_tree_mod_log.py is a script I wrote to do a tree mod log search
and rewind while debugging a btrfs issue.

Signed-off-by: Boris Burkov <boris@bur.io>
2023-06-09 09:38:26 -07:00
Martin Liska
1133b2fd31 Fix output for of lsmod.py
Unify it with what lsmod(8) does.

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-02-27 14:22:14 -08:00
Martin Liska
983ec87a77 contrib: add vmmap.py script
Mimics `cat /proc/$pid/maps` and the script output is:

Start        End          Flgs   Offset Dev   Inode            File path
55dee5284000-55dee53f3000 r-xp 00000000 fd:02 10515            /usr/lib/systemd/systemd
55dee53f3000-55dee5441000 r--p 0016f000 fd:02 10515            /usr/lib/systemd/systemd
55dee5441000-55dee5442000 rw-p 001bd000 fd:02 10515            /usr/lib/systemd/systemd
55dee5f4c000-55dee615d000 rw-p 00000000 00:00 0
7f5fc801c000-7f5fc8024000 r-xp 00000000 fd:02 1181379          /usr/lib64/libffi.so.7.1.0
7f5fc8024000-7f5fc8224000 ---p 00008000 fd:02 1181379          /usr/lib64/libffi.so.7.1.0
7f5fc8224000-7f5fc8225000 r--p 00008000 fd:02 1181379          /usr/lib64/libffi.so.7.1.0
...

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-02-25 02:08:46 -08:00
Martin Liska
35f9de75b3 contrib: add memory statistics to ps.py
New output of the command is:

PID     PPID    CPU  ST    VMS     RSS  MEM%  COMM
1       0       0    S   10.4M    6.5M   0.4 init
2       0       0    S       0       0   0.0 [kthreadd]
...
263     1       4    S    2.4G  163.5M   9.5 python3
264     1       5    S    2.4G  163.5M   9.5 python3
265     1       6    S    2.4G  163.5M   9.5 python3
266     1       10   S    2.4G  163.5M   9.5 python3
267     1       12   S    2.4G  163.5M   9.5 python3
268     1       13   S    2.4G  163.5M   9.5 python3
269     1       14   S    2.4G  163.5M   9.5 python3
270     1       15   S    2.4G  163.5M   9.5 python3
271     1       16   S    2.4G  163.5M   9.5 python3
...

Supports also older kernel releases like 4.4.

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-02-25 02:07:57 -08:00
Martin Liska
e6228245a0 Fix TCP listing contrib script
Since Linux kernel commit 8dbd76e79a16 ("tcp/dccp: fix possible race
__inet_lookup_established()") (in v5.5), it's actually hlist_nulls_head
what is used for items of inet_hashinfo::listening_hash. This commit was
also backported to stable kernels, so with the change it works for all
releases starting with v4.9. The version 4.4 is not supported right now
(nulls head list is probably not known at the time).

Fixes: #268

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-02-24 13:15:00 -08:00
Martin Liska
adc8c430bb add kernel_sys.py to contrib
This script mimics crash>sys and provides the following output:

CPUS             16
DATE             Fri Jan 27 20:26:24 2023
UPTIME           1 day, 7:29:37
LOAD AVERAGE     0.00, 0.00, 0.00
TASKS            317
NODENAME         tw
RELEASE          6.1.7-1-default
VERSION          #1 SMP PREEMPT_DYNAMIC Wed Jan 18 11:12:34 UTC 2023 (872045c)
MACHINE          x86_64
MEMORY           12.67 GiB

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-02-24 12:22:00 -08:00
Omar Sandoval
5276af94fd contrib: add kcore_list.py
I used this to look at RAM regions on different architectures.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-21 14:26:54 -08:00
Omar Sandoval
cf3c4e736e contrib: vmstat.py: move implementation comment out of docstring
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-03 11:44:04 -08:00
Martin Liska
d5c3be72c3 add vmstat.py script to contrib
The script mimics what crash> kmem -V does, the script
reports the following:

Event                                           Count
VM_ZONE_STAT:
NR_FREE_PAGES                                  512147
NR_ZONE_LRU_BASE                               234271
NR_ZONE_INACTIVE_ANON                          234271
NR_ZONE_ACTIVE_ANON                               196
NR_ZONE_INACTIVE_FILE                           97200
NR_ZONE_ACTIVE_FILE                            110611
NR_ZONE_UNEVICTABLE                              1000
NR_ZONE_WRITE_PENDING                              84
NR_MLOCK                                            0
NR_BOUNCE                                           0
NR_ZSPAGES                                          0
NR_FREE_CMA_PAGES                                   0

VM_NODE_STAT:
NR_LRU_BASE                                    234322
NR_INACTIVE_ANON                               234322
NR_ACTIVE_ANON                                    196
NR_INACTIVE_FILE                                97200
...

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-02-03 11:37:19 -08:00
Martin Liska
7b0cdcf4a5 port contrib/tcp_sock.py to v5.19+
Since Linux kernel commit cae3873c5b3a ("net: inet: Retire port only
listening_hash") (in v5.19), listening_hash is removed and we need
to iterate lhash2 table.

The script reports now:
LISTEN                                           [::]:22                                         [::]:0      /system.slice/sshd.service
LISTEN                                        0.0.0.0:22                                      0.0.0.0:0      /system.slice/sshd.service
LISTEN                                          [::1]:631                                        [::]:0      /system.slice/cups.service
LISTEN                                      127.0.0.1:25                                      0.0.0.0:0      /system.slice/postfix.service
LISTEN                                          [::1]:25                                         [::]:0      /system.slice/postfix.service
LISTEN                                      127.0.0.1:631                                     0.0.0.0:0      /system.slice/cups.service
ESTABLISHED                            192.168.122.99:22                                192.168.122.1:45906  /system.slice/sshd.service
ESTABLISHED                            192.168.122.99:22                                192.168.122.1:48066  /system.slice/sshd.service
ESTABLISHED                            192.168.122.99:22                                192.168.122.1:41128  /system.slice/sshd.service

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-27 10:24:11 -08:00
Martin Liska
b86417c8a2 add mount.py contrib script
Provides crash-like output:

Mount            Type         Devname      Dirname
ffff8fed001d8500 rootfs       rootfs       /
ffff8fed06a197c0 proc         proc         /proc
ffff8fed06a192c0 sysfs        sysfs        /sys
ffff8fed06a18c80 devtmpfs     devtmpfs     /dev
ffff8fed06a18b40 securityfs   securityfs   /sys/kernel/security
ffff8fed06a19cc0 tmpfs        tmpfs        /dev/shm
ffff8fed06a18500 devpts       devpts       /dev/pts
ffff8fed06a18dc0 tmpfs        tmpfs        /run
...

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-27 09:56:57 -08:00
Martin Liska
724d15563d enhance ps
New output:

PID     PPID    CPU  ST COMM
1       0       4    S  systemd
2       0       13   S  [kthreadd]
3       2       0    I  [rcu_gp]
4       2       0    I  [rcu_par_gp]
5       2       0    I  [slub_flushwq]
6       2       0    I  [netns]
8       2       0    I  [kworker/0:0H]
10      2       0    I  [mm_percpu_wq]
11      2       0    I  [rcu_tasks_kthre]
...

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-01-27 08:19:50 -08:00
Martin Liska
c710ea7713 fs_inodes: catch proper exception for None path
When inode_path returns None and it's passed to fsdecode,
I get TypeError exception:

```
  File "/usr/lib64/python3.10/os.py", line 823, in fsdecode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not NoneType
```

Thus catch both exception types.

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-26 08:43:16 -08:00
Omar Sandoval
cefe76bc3e contrib: make lsmod.py handle CONFIG_MODULE_UNLOAD=n
This is a nice example for Type.has_member().

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-22 10:25:13 -08:00
Omar Sandoval
a0a54edc1f Create contrib directory
It's come up several times that it'd be nice to have somewhere to dump
drgn scripts that people write while debugging without requiring them to
be cleaned up and scrutinized in code review. Serapheim Dimitropoulos
noted that several projects have a "contrib" directory for this purpose.
See [1]. Let's create one, document it, exclude it from pre-commit, and
move our (mostly unmaintained) examples there.

1: https://drewdevault.com/2020/06/06/Add-a-contrib-directory.html

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-16 13:17:50 -08:00