用C++调试Linux开发的Makefile项目

bla*_*pup 5 linux makefile remote-debugging visual-studio-2015

我可以用 C++ 调试 Linux Development 的 Console Application 项目,但不能调试 Makefile 项目。断点未命中。

我的系统如下

  • 10号窗之家
  • Visual Studio 社区 2015 更新 3
  • 用于 Linux 开发的 Visual C++ 1.0.7
  • VirtualBox 5.1.30 r118389 (Qt5.6.2) - CentOS 7 1708

新项目 -> Visual C++ -> 跨平台 -> Linux -> 控制台应用程序(Linux) 我可以创建项目并且运行良好。

但是,我无法调试 makefile 项目。

我试过如下

  1. 创建项目
    New project -> Visual C++ -> Cross Platform -> Linux -> Makefile Project(Linux) 名称:Project1
    位置:D:\WorkSpace\TEST_LINUX\
    解决方案名称:Project1

  2. 添加源
    点击右边的“我的项目(项目1(Linux))”->添加->新项目...->C++文件(.cpp)
    名称:main.cpp
    D:\WorkSpace\TEST_LINUX\Project1\Project1

  3. 创建空的 Makefile
    d:\WorkSpace\TEST_LINUX\Project1\Project1\Makefile

  4. 添加 Makefile
    右击“my Project(Project1 (Linux))” -> Add -> Existing Item...
    文件名:Makefile

  5. 编辑 main.cpp 和 Makefile

    主程序

    #include <stdio.h>
    
    int main()
    {
        printf("Hello world 1\n");
        printf("Hello world 2\n");
        printf("Hello world 3\n");
        printf("Hello world 4\n");
        printf("Hello world 5\n");
    
        return 0;
    }
    
    Run Code Online (Sandbox Code Playgroud)

    生成文件

    all:
        gcc -o Project1 main.cpp
    
    clean:
        rm -rf Project1
    
    Run Code Online (Sandbox Code Playgroud)
  6. 配置属性右击“my Project(Project1 (Linux))”-> Properties
    Edit Configuration Properties -> General -> Remote Build Root Directory
    ~/projects->/home/mike/projects

    编辑配置属性 -> 远程构建 -> 构建命令行
    ->cd $(RemoteRootDir)/$(ProjectName); make all
    编辑配置属性 -> 远程构建 -> 重建所有命令行
    ->cd $(RemoteRootDir)/$(ProjectName); make clean all
    编辑配置属性 -> 远程构建 -> 清理命令行
    ->cd $(RemoteRootDir)/$(ProjectName); make clean
    编辑配置属性 -> 远程构建-> 输出
    ->$(RemoteRootDir)/$(ProjectName)/Project1

  7. 断点
    将光标放在一行上("printf("Hello world 2\n");" and "printf("Hello world 5\n");") 然后按 F9

  8. 调试
    点击“远程GDB调试器”

  9. 输出窗口
    看到最后一行,这个程序运行良好,但调试不起作用。

    输出 -> 显示来自:调试的输出

    =thread-group-added,id="i1"
    GNU gdb (GDB) 7.9
    Copyright (C) 2015 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "--host=i686-pc-mingw32 --target=x86_64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word".
    Loaded 'shared libraries loaded at this time.'. Cannot find or open the symbol file.
    Stopped due to shared library event:
      Inferior loaded /lib64/libc.so.6
        /lib64/ld-linux-x86-64.so.2
    Loaded '/lib64/libc.so.6'. Cannot find or open the symbol file.
    Loaded '/lib64/ld-linux-x86-64.so.2'. Cannot find or open the symbol file.
    [Inferior 1 (process 8809) exited normally]
    The program '' has exited with code 0 (0x0).
    
    Run Code Online (Sandbox Code Playgroud)
  10. 修改main.cpp

    #include <stdio.h>
    
    int main()
    {
        printf("Hello world 1\n");
        getchar();
        printf("Hello world 2\n");
        getchar();
        printf("Hello world 3\n");
        getchar();
        printf("Hello world 4\n");
        getchar();
        printf("Hello world 5\n");
    
        return 0;
    }
    
    Run Code Online (Sandbox Code Playgroud)
  11. 重试调试
    点击“Remote GDB Debugger”

    出现 Linux 控制台窗口。

    Process /home/mike/projects/Project1/Project1 created; pid = 9353
    Listening on port 4444
    Remote debugging from host 127.0.0.1
    Hello world 1
    
    Run Code Online (Sandbox Code Playgroud)

    在 Linux 控制台窗口中按 [Enter]

    Process /home/mike/projects/Project1/Project1 created; pid = 10152
    Listening on port 4444
    Remote debugging from host 127.0.0.1
    Hello world 1
    
    
    
    Hello world 2
    Hello world 3
    
    Run Code Online (Sandbox Code Playgroud)

    在 Linux 控制台窗口中按 [Enter]

    Process /home/mike/projects/Project1/Project1 created; pid = 10152
    Listening on port 4444
    Remote debugging from host 127.0.0.1
    Hello world 1
    
    
    
    Hello world 2
    Hello world 3
    
    
    
    Hello world 4
    Hello world 5
    
    Child exited with status 0
    GDBserver exiting
    
    Run Code Online (Sandbox Code Playgroud)

奇怪的东西

  1. 虽然我按了两次 [Enter],但调试完成了。
    在 putty 中运行程序并按 [Enter] 四次,程序完成。

  2. 断点是一个白点。
    在单击“Remote GDB Debugger”之前,断点显示为一个红点。
    但是点击["Remote GDB Debugger"]后,断点显示为一个白点。
    白点提示为“当前不会命中断点。包含此断点的模块尚未加载或无法获取断点地址。”

  3. 每次,这个项目都过时了。
    每当我单击“远程 GDB 调试器”时,都会出现对话框。

    Microsoft Visual Studio
    This project is out of date
    Would you like to build it?
    
    Run Code Online (Sandbox Code Playgroud)

    我绝不会修改我的来源。它并没有过时。

我该怎么做才能在 Makefile Project (Linux) 和 Consol Application (Linux) 中进行调试?

提前感谢您的赞赏。

我邮寄到 vccplinux-support@microsoft.com 但被邮寄回来 550 5.4.1 [vccplinux-support@microsoft.com]: Recipient address rejected: Access denied [BL2NAM06FT015.Eop-nam06.prod.protection.outlook.com]