> 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/port/di-10-zhang-ce-shi-port/10.8.tiao-shi-port.md).

# 10.8.调试 port

有时，程序在运行时会出现问题，导致 Port 失败。框架提供了一些辅助工具来帮助调试 Ports。这些工具的功能是有限的，因为调试 Port 的方式很大程度上取决于使用的技术。以下变量有助于调试 Ports：

* `WITH_DEBUG`：如果设置此变量，Ports 将会在构建时包含调试符号。
* `WITH_DEBUG_PORTS`：指定要使用 `WITH_DEBUG` 选项构建的 Ports 列表。
* `DEBUG_FLAGS`：用于指定要添加到 `CFLAGS` 的附加标志，默认值为 `-g`。

当 `WITH_DEBUG` 被设置时，无论是全局设置还是针对某些 Ports 设置，生成的二进制文件都不会被剥离调试信息。

这些变量可以在 **make.conf** 或命令行中指定：

```sh
# cd category/port && make -DWITH_DEBUG DEBUG_FLAGSS="-g -O0"
```

> **注意**
>
> 如果使用 [ports-mgmt/poudriere](https://cgit.freebsd.org/ports/tree/ports-mgmt/poudriere/) 构建 Port，调试变量必须在 poudriere 的 **make.conf** 中指定，而不是在 **/etc/make.conf** 中指定。有关详细信息，请参阅 [ports-mgmt/poudriere](https://cgit.freebsd.org/ports/tree/ports-mgmt/poudriere/) 文档。

有关更多调试工具的信息，请参阅 [Developer’s Handbook](https://docs.freebsd.org/en/books/developers-handbook/tools#debugging)。


---

# 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/port/di-10-zhang-ce-shi-port/10.8.tiao-shi-port.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.
