Skip to content

Commit

Permalink
DLPX-87560 sdb: dmesg broken for 5.15 kernels (#340)
Browse files Browse the repository at this point in the history
This patch replaces our hand-written implementation of dmesg
which doesn't work for most vanilla kernel versions after 5.10
with the drgn helper which stays up to date more often.

In order for this to work I had to change the type of our
dmesg command from a Locator+PrettyPrinter to a standard
command. This is not a big deal as the only reason we would
ever walk and filter dmesg would be to filter the kernel logs
by level. I've added this as an argument to the command.

= Github Issue Tracker Automation

Closes #336
  • Loading branch information
sdimitro authored Aug 22, 2023
1 parent 7e9225c commit 3a1fadc
Show file tree
Hide file tree
Showing 10 changed files with 1,938 additions and 3,806 deletions.
73 changes: 47 additions & 26 deletions sdb/commands/linux/dmesg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,64 @@

# pylint: disable=missing-docstring

import argparse
from typing import Iterable

import drgn
from drgn.helpers.linux.printk import get_printk_records
import sdb

# pylint: disable=line-too-long

class DMesg(sdb.Locator, sdb.PrettyPrinter):

names = ["dmesg"]
load_on = [sdb.Kernel()]

input_type = "struct printk_log *"
output_type = "struct printk_log *"
class DMesg(sdb.Command):
"""
DESCRIPTION
def no_input(self) -> Iterable[drgn.Object]:
log_idx = sdb.get_object("log_first_idx")
log_seq = sdb.get_object("clear_seq")
log_end = sdb.get_object("log_next_seq")
log_buf = sdb.get_object("log_buf")
Get contents from kernel log buffer formatted like dmesg(1).
while log_seq < log_end:
entry = drgn.cast('struct printk_log *', log_buf + log_idx)
EXAMPLES
yield entry
sdb> dmesg ! tail
[ 30.544756] AVX2 version of gcm_enc/dec engaged.
[ 30.545019] AES CTR mode by8 optimization enabled
[ 38.855043] Rounding down aligned max_sectors from 4294967295 to 4294967288
[ 38.863427] db_root: cannot open: /etc/target
[ 39.822443] aufs 5.15.5-20211129
[ 40.344495] NFSD: Using UMH upcall client tracking operations.
[ 40.344501] NFSD: starting 20-second grace period (net f0000000)
[ 40.978893] EXT4-fs (zd0): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
[ 176.825888] bpfilter: Loaded bpfilter_umh pid 4662
[ 176.826272] Started bpfilter
if entry.len == 0:
log_idx = 0
else:
log_idx += entry.len
log_seq += 1
sdb> dmesg -l 3
[ 38.863427] db_root: cannot open: /etc/target
"""

def pretty_print(self, objs: Iterable[drgn.Object]) -> None:
for obj in objs:
secs = int(obj.ts_nsec.value_() / 1000000000)
usecs = int((obj.ts_nsec.value_() % 1000000000) / 1000)
names = ["dmesg"]
# input_type = None
load_on = [sdb.Kernel()]

message = drgn.cast("char *", obj) + obj.type_.type.size
text = message.string_().decode('utf-8', 'ignore')
@classmethod
def _init_parser(cls, name: str) -> argparse.ArgumentParser:
parser = super()._init_parser(name)
#
# #define KERN_EMERG KERN_SOH "0" /* system is unusable */
# #define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
# #define KERN_CRIT KERN_SOH "2" /* critical conditions */
# #define KERN_ERR KERN_SOH "3" /* error conditions */
# #define KERN_WARNING KERN_SOH "4" /* warning conditions */
# #define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
# #define KERN_INFO KERN_SOH "6" /* informational */
# #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
#
parser.add_argument('--level', '-l', nargs="?", type=int, default=7)
return parser

print(f"[{secs:5d}.{usecs:06d}]: {text}")
def _call(self, objs: Iterable[drgn.Object]) -> None:
for record in get_printk_records(sdb.get_prog()):
if self.args.level >= record.level:
secs = record.timestamp // 1000000000
sub_secs = record.timestamp % 1000000000 // 1000
msg = record.text.decode('utf-8')
print(f"[{secs: 5d}.{sub_secs:06d}] {msg}")
2,532 changes: 1,265 additions & 1,267 deletions tests/integration/data/regression_output/dump.201912060006/linux/dmesg

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[ 3.685278] piix4_smbus 0000:00:07.3: SMBus Host Controller not enabled!
[ 4.346112] sd 2:0:0:0: [sda] Assuming drive cache: write through
[ 4.356113] sd 2:0:1:0: [sdb] Assuming drive cache: write through
[ 4.363435] sd 2:0:2:0: [sdc] Assuming drive cache: write through
[ 4.366085] sd 2:0:3:0: [sdd] Assuming drive cache: write through
[ 48.368009] db_root: cannot open: /etc/target
[ 305.340853] Kernel panic - not syncing: sysrq triggered crash
@#$ EXIT CODE $#@
0

This file was deleted.

Loading

0 comments on commit 3a1fadc

Please sign in to comment.