部署、运行和调试 Linux 项目Deploy, run, and debug your Linux project

一旦创建了 Linux 项目并且使用 Linux 连接管理器连接到该项目,就可以运行并调试该项目。Once you have created a Linux project and you have connected to the project using the Linux Connection Manager, you can run and debug the project. 在远程目标上编译、执行和调试代码。You compile, execute, and debug the code on the remote target.

与 Linux 项目交互并对其进行调试方法有若干种。There are several ways to interact with and debug your Linux project.

  • 使用 Visual Studio 传统功能(例如断点、监视窗口和悬停在变量上)进行调试。Debug using traditional Visual Studio features, such as breakpoints, watch windows, and hovering over a variable. 使用这些方法,可以像平常调试其他项目类型那样进行调试。Using these methods, you may debug as you normally would for other project types.
  • 从特殊 Linux 控制台窗口中的目标计算机查看输出。View output from the target computer in a special Linux Console window. 还可以使用控制台将输入发送到目标计算机。You can also use the console to send input to the target computer.

调试 Linux 项目Debug your Linux project

  1. 在“调试”属性页中选择调试模式。Select debugging mode in the Debugging property page.

    GDB 用于调试在 Linux 上运行的应用程序。GDB is used to debug applications running on Linux. 但是,能以两种不同的模式运行,可从项目“调试”属性页中的“调试模式”选项中进行选择:However, this can run in two different modes, which can be selected from the Debugging Mode option in the project's Debugging property page:

    GDB 选项

    • 在“gdbserver”模式中,GDB 在本地运行,连接到在远程系统上运行的 gdbserver。In gdbserver mode, GDB is run locally which connects to gdbserver running on the remote system. 请注意,这是 Linux 控制台窗口唯一支持的模式。Note that this is the only mode which the Linux Console window supports.

    • 在“gdb”模式中,Visual Studio 调试器驱动远程系统上的 GDB,如果 GDB 的本地版本与目标计算机上安装的版本不兼容,则远程系统上的 GDB 更易兼容。In gdb mode, the Visual Studio debugger drives GDB on the remote system, which is more compatible if the local version of GDB is not compatible with the version installed on the target computer. |

      备注

      如果不能在 gdbserver 调试模式中命中断点,请尝试 gdb 模式。If you are unable to hit breakpoints in gdbserver debugging mode, try gdb mode. 必须先将 gdb 安装在远程目标上。gdb must first be installed on the remote target.

  2. 使用 Visual Studio 中的标准“调试”工作栏,选择远程目标。Select the remote target using the standard Debug toolbar in Visual Studio.

    远程目标可用时,将看见它按名称或 IP 地址列出。When the remote target is available, you will see it listed by either name or IP address.

    远程目标

    如果还未连接到远程目标,将会看见使用 Linux 连接管理器连接到远程目标的说明。If you have not yet connected to the remote target, you will see an instruction to use Linux Connection Manager to connect to the remote target.

    远程体系结构

  3. 在已知将执行的某些代码的左滚动条槽中单击,设置断点。Set a breakpoint by clicking in the left gutter of some code that you know will execute.

    设置断点的代码行上出现一个红点。A red dot appears on the line of code where you set the breakpoint.

  4. 按 F5(或者“调试”>“开始调试”)开始调试。Press F5 (or Debug > Start Debugging) to start debugging.

    开始调试时,应用程序先在远程目标上编译,再启动。When you start debugging, the application is compiled on the remote target before it starts. 任何编译错误都将显示在“错误列表”窗口中。Any compilation errors will appear in the Error List window.

    如果没有错误,则应用将启动并且调试程序将在断点处暂停。If there are no errors, the app will start and the debugger will pause at the breakpoint.

    命中断点

    现在,可以通过按命令键(如 F10 或 F11),与处于当前状态的应用程序交互、查看变量以及逐行执行代码。Now, you can interact with the application in it's current state, view variables, and step through code by pressing command keys such as F10 or F11.

  5. 如果需要使用 Linux 控制台与应用进行交互,请选择“调试”>“Linux 控制台”。If you want to use the Linux Console to interact with your app, select Debug > Linux Console.

    Linux 控制台菜单

    此控制台将显示来自目标计算机的全部控制台输出并接收输入,然后将其发送到目标计算机。This console will display any console output from the target computer as well as take input and send it to the target computer.

    Linux 控制台窗口

配置其他调试选项Configure other debugging options

  • 可以使用项目“调试”属性页中的“程序参数”项将命令行参数传递给可执行文件。Command line arguments can be passed to the executable using the Program Arguments item in the project's Debugging property page.

    程序参数

  • 可使用“其他调试程序命令”条目将特定调试程序选项传递到 GDB。Specific debugger options can be passed to GDB using the Additional Debugger Commands entry. 例如,你可能需要忽略 SIGILL(非法指令)信号。For example, you might want to ignore SIGILL (illegal instruction) signals. 那么,可以使用“句柄”命令来实现此目的,方法是:You could use the handle command to achieve this. 将以下命令添加到如上图中所示的“其他调试程序命令”条目:by adding the following to the Additional Debugger Commands entry as shown above:

    handle SIGILL nostop noprint

请参阅See also

C++ 调试属性 (Linux C++)C++ Debugging Properties (Linux C++).