> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man1/kdump.1.md).

# kdump.1

`kdump` — 显示内核跟踪数据

## 名称

`kdump`

## 概要

`kdump [-dEnlHRSsTA] [-f trfile] [-m maxdata] [-p pid] [-t trstr]`

## 描述

`kdump` 命令以易读格式显示由 [ktrace(1)](/man/man1/ktrace.1.md) 生成的内核跟踪文件。默认显示当前目录下的 `ktrace.out` 文件。

选项如下：

**`-A`** 显示被跟踪进程的 ABI。

**`-c`** 在每个跟踪条目中显示 CPU 编号。

**`-d`** 以十进制显示所有数字。

**`-E`** 显示经过的时间戳（从跟踪开始的时间）。

**`-f`** `trfile` 显示指定文件而非 `ktrace.out`。

**`-H`** 在每个跟踪记录中列出线程的线程 ID（tid）（如果可用）。如果没有可用的线程 ID，则打印 0。

**`-l`** 循环读取跟踪文件，到达文件末尾后等待更多数据。

**`-m`** `maxdata` 解码 I/O 时最多显示 `maxdata` 字节。

**`-n`** 抑制临时翻译。通常 `kdump` 会尝试将许多系统调用解码为更易读的格式。例如，ioctl(2) 值会被替换为宏名，`errno` 值会被替换为 strerror(3) 字符串。抑制此功能会产生更一致的输出格式，便于进一步处理。

**`-p`** `pid` 仅显示与进程或线程 `pid` 对应的跟踪事件。当同一个跟踪文件中记录了多个进程或线程时，这可能很有用。

**`-R`** 显示相对时间戳（距离前一条目的时间）。

**`-r`** 解码 STRU 记录时，以符号形式而非数字形式显示结构成员，如 UID、GID、日期等。

**`-S`** 显示系统调用号。

**`-s`** 抑制 I/O 数据的显示。

**`-T`** 为每个条目显示绝对时间戳（自纪元起的秒数）。

**`-t`** `trstr` 参见 [ktrace(1)](/man/man1/ktrace.1.md) 的 `-t` 选项。

`kdump` 的输出格式是面向行的，包含多个字段。下面的示例展示了由以下命令生成的 kdump 片段：

```sh
?> ktrace echo "ktrace"
?> kdump
 85045 echo     CALL  writev(0x1,0x804b030,0x2)
 85045 echo     GIO   fd 1 wrote 7 bytes
       "ktrace
       "
 85045 echo     RET   writev 7
```

第一个字段是被跟踪进程的 PID。第二个字段是被跟踪程序的名称。第三个字段是内核代表进程执行的操作。如果正在打印线程 ID，则在 PID 字段和程序名字段之间会添加一个额外的线程 ID 列。

在上面的第一行中，内核代表进程执行 writev(2) 系统调用，所以这是一个 `CALL` 操作。第四个字段显示了执行的系统调用及其参数。writev(2) 系统调用接受一个文件描述符（这里是 1，即标准输出），然后是一个指向要写入的 iovector 的指针，以及要写入的 iovector 数量。在第二行中，我们看到操作是 `GIO`（一般 I/O），文件描述符 1 写入了七个字节。接下来是写入的七个字节，即字符串 “ktrace” 加上回车符和换行符。最后一行是 `RET` 操作，显示从内核返回、从哪个系统调用返回，以及进程接收到的返回值。writev(2) 系统调用写入了七个字节，所以返回值为 7。

可能的操作包括：

| **名称** | **操作**       | **第四字段**          |
| ------ | ------------ | ----------------- |
| `CALL` | 进入系统调用       | 系统调用名和参数          |
| `RET`  | 从系统调用返回      | 系统调用名和返回值         |
| `NAMI` | 文件名查找        | 文件路径              |
| `GIO`  | 一般 I/O       | fd、读/写、字节数        |
| `PSIG` | 信号           | 信号名、处理程序、掩码、代码    |
| `CSW`  | 上下文切换        | 停止/恢复 用户/内核 wmesg |
| `USER` | 来自用户进程的数据    | 数据                |
| `STRU` | 各种系统调用       | 结构                |
| `SCTL` | sysctl(3) 请求 | MIB 名             |
| `PFLT` | 进入缺页         | 缺页地址和类型           |
| `PRET` | 从缺页返回        | 缺页结果              |

## 参见

[ktrace(1)](/man/man1/ktrace.1.md)

## 历史

`kdump` 命令首次出现于 4.4BSD。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man1/kdump.1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
