> 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/porters-handbook/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://book.bsdcn.org/porters-handbook/di-10-zhang-ce-shi-port/10.8.tiao-shi-port.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
