ITADN

Crash command: log: add -d, -m, and -c

#581Openosandov 创建于 2025-12-11
O
osandovcommented
https://crash-utility.github.io/help_pages/log.html These three options add extra per-message information: `-d` adds the context dictionary as additional lines under each message: ``` crash> log -d ... [ 0.509530] acpi PNP0A08:00: _OSC: OS supports [ExtendedConfig ASPM ClockPM Segments MSI EDR HPX-Type3] SUBSYSTEM=acpi DEVICE=+acpi:PNP0A08:00 ``` `-m` adds the message level in angle brackets: ``` crash> log -m ... [ 0.000000] <5>Linux version 6.17.9-300.fc43.x86_64 (mockbuild@928180b471f54176bbf3623ccb67b438) (gcc (GCC) 15.2.1 20251111 (Red Hat 15.2.1-4), GNU ld version 2.45.1-1.fc43) #1 SMP PREEMPT_DYNAMIC Mon Nov 24 23:31:27 UTC 2025 [ 0.000000] <6>Command line: BOOT_IMAGE=(hd0,gpt2)/vmlinuz-6.17.9-300.fc43.x86_64 root=UUID=92c549ff-686c-47fe-a121-847f4e8a41e7 ro rootflags=subvol=root rd.luks.uuid=luks-462382a8-ecaa-49a7-bf0f-10ce2a0a1ce7 rhgb quiet ``` `-c` adds the calling thread ID in square brackets: ``` crash> log -c ... [33532.992567] [ T18349] r8152-cfgselector 2-3.1.2: USB disconnect, device number 4 ``` or the calling CPU number, depending on which is available: ``` [33532.992745] [ C1] r8152 2-3.1.2:1.0 enp0s13f0u3u1u2: Stop submitting intr, status -108 ``` Note that they can be combined: ``` crash> log -cdm ... [ 0.509530] [ T1] <6>acpi PNP0A08:00: _OSC: OS supports [ExtendedConfig ASPM ClockPM Segments MSI EDR HPX-Type 3] SUBSYSTEM=acpi DEVICE=+acpi:PNP0A08:00 ``` Our [`get_printk_records()`](https://drgn.readthedocs.io/en/latest/helpers.html#drgn.helpers.linux.printk.get_printk_records) helper already returns this information as [`PrintkRecord.context`](https://drgn.readthedocs.io/en/latest/helpers.html#drgn.helpers.linux.printk.PrintkRecord.context), [`PrintkRecord.level`](https://drgn.readthedocs.io/en/latest/helpers.html#drgn.helpers.linux.printk.PrintkRecord.level), and [`PrintkRecord.caller_tid`](https://drgn.readthedocs.io/en/latest/helpers.html#drgn.helpers.linux.printk.PrintkRecord.caller_tid)/[`PrintkRecord.caller_cpu`](https://drgn.readthedocs.io/en/latest/helpers.html#drgn.helpers.linux.printk.PrintkRecord.caller_cpu). So, this issue has two steps: 1. Add parameters to [`get_dmesg()`](https://drgn.readthedocs.io/en/latest/helpers.html#drgn.helpers.linux.printk.get_dmesg)/[`print_dmesg()`](https://drgn.readthedocs.io/en/latest/helpers.html#drgn.helpers.linux.printk.print_dmesg) that enable adding this information. Something like: ```python3 def get_dmesg( prog: Program, *, timestamps: Union[bool, Literal["human"]] = True, level: bool = False, caller: bool = False, context: bool = False, ) -> bytes: """ ... :param level: Whether to include the log level of each message. :param caller: Whether to include the thread ID or CPU number that logged each message. :param context: Whether to include the context dictionary of each message. """ ``` Crash's format is fine, so we can just copy that. 2. Add the corresponding options to `_crash_cmd_log()`.
2 条评论