### [Peilin Ye's blog](https://hackmd.io/@ypl/Sk8YAobw9) # 在 System76 Gazelle (gaze18) 上用 drgn 看 Linux 内核 System76 团队维护一个官方的 Linux 内核仓库([GitHub 链接](https://github.com/pop-os/linux)),基于 Ubuntu 的,但是没有提供 debug(`-dbg`)包,所以有些内核 debug 工具用不成,比如 drgn:[Getting Debugging Symbols — drgn 0.0.23+unknown documentation](https://drgn.readthedocs.io/en/latest/getting_debugging_symbols.html) GitHub 上也有人提了 [issue](https://github.com/pop-os/linux/issues/192),快一年了也没人理,目前只能自己 build 了。好在流程很简单,我 checkout 了 [commit d567a383cdc8 ("Tell thelio-io-2 about suspend status")](https://github.com/pop-os/linux/commit/d567a383cdc8686afc378a00b4cc35293fd3bc4d),执行了 `./rebuild.sh`(按它说的装 build 依赖,缺什么装什么就行;我新装的系统,只预先装了个 pahole)和 `./reinstall.sh`,然后重启了一下,就换上新内核了: ```shell ypl@pop-os:~$ uname -r 6.4.6-76060406-generic ``` `./rebuild.sh` 花了半个多小时,唉……不过终于可以用 drgn 了!试试,在 `./debian/build/build-generic/` 里执行 `sudo drgn --no-default-symbols -s ./vmlinux`: ```python3 drgn 0.0.23 (using Python 3.10.12, elfutils 0.189, with libkdumpfile) For help, type help(drgn). >>> import drgn >>> from drgn import NULL, Object, cast, container_of, execscript, offsetof, reinterpret, sizeof >>> from drgn.helpers.common import * >>> from drgn.helpers.linux import * >>> prog["nr_cpu_ids"] (unsigned int)20 ``` 成了!呃,不过只有 vmlinux 的 debug 信息,没有内核 `.ko` 模块的: ```python3 >>> prog["fq_codel_enqueue"] Traceback (most recent call last): File "/usr/lib/python3.10/code.py", line 90, in runcode exec(code, self.locals) File "<console>", line 1, in <module> KeyError: 'fq_codel_enqueue' ``` 我犯懒了,用了个土办法: ```python3 >>> from pathlib import Path >>> prog.load_debug_info(list(Path.cwd().rglob('*.ko'))) ``` 然后报了一堆 `Too many open files`,哈哈哈,服了,`.ko` 太多了。我 `ulimit -n` 只有 1024,改大点就好了: ```python3 >>> prog["fq_codel_enqueue"] (int (struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free))0xffffffffc102a7e0 ```