Using GDB in Visual Studio

56 篇文章 1 订阅
54 篇文章 0 订阅

转自https://gpac.wp.mines-telecom.fr/2015/06/11/using-gdb-in-visual-studio/

Dear followers,

One of the target platform for GPAC is Windows. Developing for Windows in a comfortable manner requires Visual Studio, in particular for debugging. Microsoft recently announced great changes that will make Visual Studio users (including the GPAC developers) happy:

 

Setup for local debugging

Install software:

  • Install Visual Studio 2015. Install the “Tools for Visual C++ Mobile Development” in a sub-menu (disabled by default).
  • Install gdb/gdbserver. Use MinGW-w64 binaries and put them in your PATH (you can rely on the excellent MSYS2 for a full development environment).
    /!\ Legacy MinGW and Cygwin gdb binaries are known to fail /!\

Build:

  • Use your usual build system and gcc or clang compiler. Don’t forget to enable debugging!

Debugging:

  • In your command-line, launch:
  • In Visual Studio:
    • Open the “command window” (either press CTRL+ALT+A or click: View menu -> Other Windows -> Command Window)
    • Launch:

      That’s all! Once Debug.GDBLaunch is attached your program will run. Breakpoints are effective. And you can enjoy the Visual Studio debugging experience:

      20150610_msvs_gdb

      Setup for remote debugging

      This is an extension of the gdbserver we used above.  It allows to debug mobile (android/iOS) or any platform (linux, …) executables from a remote

      For specific remote parameters, see:

    使用 Visual Studio Code 编写 C++ 程序,需要安装以下两个组件: 1. Visual Studio Code 编辑器 2. C++ 插件 下面是具体步骤: 1. 安装 Visual Studio Code 编辑器 首先需要下载并安装 Visual Studio Code 编辑器,可以在官网上下载:https://code.visualstudio.com/ 2. 安装 C++ 插件 打开 Visual Studio Code 编辑器,点击左侧的扩展图标(Extensions),在搜索栏中输入 “C++”,选择 Microsoft 的 “C/C++” 插件,点击安装按钮进行安装。 3. 创建 C++ 项目 打开 Visual Studio Code 编辑器,点击左上角的 “File” 菜单,选择 “New Folder” 创建一个文件夹,命名为 “HelloWorld”。 在该文件夹下新建一个文件,命名为 “main.cpp”。 4. 编写 C++ 代码 在 main.cpp 文件中编写以下代码: ```c++ #include <iostream> using namespace std; int main() { cout << "Hello World!" << endl; return 0; } ``` 5. 编译和运行代码 按下 F5 键,选择 “C++ (GDB/LLDB)” 作为调试配置,点击 “Create a launch.json file” 按钮创建一个 launch.json 文件。 在 launch.json 文件中添加以下代码: ```json { "version": "0.2.0", "configurations": [ { "name": "C++ Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/main", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true } ] } ``` 然后按下 F5 键,代码就会被编译并运行,控制台输出 “Hello World!”。
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值