# 10.8.调试 port

有时，程序在运行时会出现问题，导致 Port 失败。为了帮助调试 Ports，FreeBSD 提供了一些工具。这些工具的功能是有限的，因为调试 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
