开发和调试 zxdb

运行测试

如需运行 zxdb 前端测试(这些测试仅在主机开发计算机上运行),请使用以下命令:

fx test zxdb_tests

要运行 debug_agent 测试(这些测试仅在目标 Fuchsia 系统上运行),请运行以下命令:

fx test debug_agent_unit_tests
fx test debug_agent_integration_tests

如需运行端到端测试(测试 zxdb 前端与 debug_agent 的集成),请运行以下命令:

fx test --e2e zxdb_e2e_tests

构建新版本后,重新加载 debug_agent.cm

由于 debug_agent_launcher 是一个长时间运行的进程,因此在第一次调用 ffx debug connect 后,系统不会尝试更新 debug_agent 软件包。要强制系统卸载 debug_agent.cm,请使用

ffx component stop /core/debug_agent

在 debug_agent 中启用调试日志记录

--select core/debug_agent#DEBUG 添加到 fx log 将启用 debug_agent 的调试日志记录,例如

fx log --select core/debug_agent#DEBUG --tag debug_agent --hide_metadata --pretty

在 zxdb 中启用调试日志记录

如需在 zxdb 中启用调试日志记录,请使用

ffx debug connect -- --debug-mode

在其他调试程序中启动 zxdb

可以请求 ffx debug 在另一个调试程序(例如 lldb)中启动 zxdb。

ffx debug connect --debugger lldb

此命令将调出 lldb shell,您可以使用“run”来启动 zxdb。

命令中的“lldb”可以替换为“gdb”。不过,使用 gdb 可能会带来一些问题,包括

  • 较低版本的 gdb 可能不支持所有 DWARF 5 标准,并且可能会缺少某些信息,例如源文件列表。
  • 按 Ctrl-C 组合键不会从 zxdb 返回到 gdb。解决方法是在另一个窗口中使用 pkill -INT zxdb 来停止 zxdb。

在另一个 debug_agent 中调试 debug_agent

您还可以将 debug_agent 附加到另一个 debug_agent。调试程序团队经常执行此操作。

// Run the debugger that will attach to the "to-be-debugged" debug_agent.
$ ffx debug connect

// Within zxdb.
[zxdb] attach debug_agent
Waiting for process matching "debug_agent".
Type "filter" to see the current filters.
Attached Process 1 state=Running koid=345223 name=debug_agent.cm
Attached Process 2 state=Running koid=345403 name=/pkg/bin/debug_agent
// The first debug_agent will capture the launcher and itself. Detach to avoid any deadlock.
[zxdb] pr 1 detach
[zxdb] pr 2 detach
// Create a breakpoint on $main
[zxdb] break $main

// Launch another debugger in another window
$ ffx debug connect

// * Within the first zxdb:
Attached Process 1 state=Running koid=12345 name=/pkg/bin/debug_agent
Breakpoint 1 now matching 1 addrs for $main
🛑 process 1 on bp 1 main(int, const char**) • main.cc:101
    99
   100 int main(int argc, const char* argv[]) {
 ▶ 101   debug_agent::CommandLineOptions options;
   102   cmdline::Status status = ParseCommandLine(argc, argv, &options);
   103   if (status.has_error()) {

// Now you have two running instances of the debugger!