執行測試
如何執行 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 殼層,您可以使用「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!