Ubuntu 上使用 arm-linux-insight (GDB 圖形前端) 連接開發板 gdbserver 時,GUI 無法直接設定 target remote。本文提供主控台指令模式與配置檔持久化兩種解決方案。
arm-linux-gnueabihf-gdb、insightgdbserver :1000 ./app192.168.1.105(gdb) target remote 192.168.1.105:1000
Remote debugging using 192.168.1.105:1000
0x00008000 in _start ()
(gdb) continue
Continuing.
gdbserver 已啟動程式,使用 continue 而非 run(gdb) break 8 # 第 8 行設定斷點
(gdb) continue # 運行至斷點
# 圖形介面自動切換至原始碼視窗
Insight 啟動時自動讀取 ~/.gdbtkinit (Tcl/Tk 腳本),預設包含連線參數:
# ~/.gdbtkinit 範例
set auto_connect 1
set remote_host 192.168.1.105
set remote_port 1000
set remote_program "./app"
# 連線指令自動化
proc auto_connect {} {
global auto_connect remote_host remote_port
if {$auto_connect} {
gdb_cmd "target remote $remote_host:$remote_port"
}
}
auto_connect
修改此檔案即可預設連線目標,避免每次手動輸入。
#!/bin/bash
# start_insight.sh
TARGET_IP=192.168.1.105
TARGET_PORT=1000
EXEC_PATH=/path/to/app
# 確保 gdbserver 運行在目標機
ssh root@$TARGET_IP "gdbserver :$TARGET_PORT $EXEC_PATH &"
# 啟動 Insight 並自動連線
arm-linux-insight -ex "target remote $TARGET_IP:$TARGET_PORT" $EXEC_PATH
| 現象 | 原因與對策 |
|---|---|
| Connection refused | gdbserver 未啟動、埠口錯誤、防火牆阻擋 |
| No symbol table | 編譯未加 -g、strip 過的二進制檔 |
| 架構不匹配 | Host GDB 與 Target 架構不符 (arm vs aarch64) |
| 原始碼路徑不符 | set substitute-path /build/src /local/src 映射路徑 |
launch.json,支援 OpenOCD/J-Link/GDB Server掌握 target remote 手動連線與 .gdbtkinit 持久化配置,即可在 Insight 中高效進行 ARM 嵌入式遠端除錯。