使用 GDB 进行远程调试
在 GDB 服务器支持的目标机上调试时,本地 GDB 进程会与远程机器上运行的 GDB 服务器进行对话,后者控制着要调试的进程。
GDB 服务器进程通过传递端口号和可执行文件在远程机器上启动:
gdbserver :1234 <executable>
然后它通常会做出响应:
Process bin/qtcreator created; pid = 5159 Listening on port 1234
在运行Qt Creator 的本地机器上:
- 转到Debug >Start Debugging >Attach to Running Debug Server 。
- 在Kit 中,选择用于构建项目的构建和运行工具包。
- 在Server port 中,输入远程机器的名称和要使用的端口号。
- 在Local executable 中,指定本地计算机上应用程序可执行文件的路径。
- 在Command line arguments 中,指定要传递给可执行文件的命令行参数。
- 在Working directory 中,指定工作目录。默认为构建结果的目录。
- 为控制台应用程序选择Run in terminal 。
- 选择Break at "main" 可在主函数处停止调试器。
- 选择Use target extended-remote to connect 可在
target extended-remote mode
中创建连接。在此模式下,当调试程序退出或您从程序中脱离时,调试器仍与目标相连。您可以重新运行应用程序,附加到正在运行的应用程序,或使用目标机专用的监控命令。例如,除非使用--once
选项调用,否则 GDB 不会退出,但可以使用monitor exit
命令使其退出。 - 在Override SysRoot 中,指定要使用的
sysroot
的路径,而不是默认的sysroot
。 - 在Init commands 中,输入与目标建立连接后立即执行的命令。
- 在Reset commands 中,输入重置与目标的连接时要执行的命令。
- 在Debug information 中,指定存储调试信息的位置。不能使用空路径。
- 在Override server channel 中,指定要使用的通信通道,如串行线路或自定义端口。
- 在Recent 中,选择要使用的最新配置。
- 选择OK 开始调试。
默认情况下,无响应的 GDB 进程会在 40 秒后终止。要增加GDB timeout 中的超时时间,请访问首选项>Debugger >GDB 。
有关在 GDB 中以target extended-remote
模式连接的更多信息,请参阅《使用 GDB 调试:连接到远程目标》。
使用 SSH 端口转发
要在无法暴露 GDB 服务器端口的远程目标上进行调试,请使用 SSH 隧道将远程端口映射到本地端口。Qt Creator 会自动检测本地和远程端口。
打开 SSH 端口转发:
- 转到首选项>Devices 。
- 在Device 中,选择Remote Linux Device 。
- 选择Use SSH port forwarding for debugging 。
- 选择OK 。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.