【VS code】Remote编译及Debug配置

EXTENSIONS安装

用到的扩展工具包括C++,CMake tools,remote-SSH等;

配置文件

需要在代码路径下创建.vscode文件夹,放以下文件

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/include/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}

cmake-variants.json

{
    "buildType": {
      "default": "debug",
      "description": "The build type.",
      "choices": {
        "debug": {
          "short": "Debug",
          "long": "Disable optimizations - include debug information.",
          "buildType": "Debug",
          "settings":{
            "Poco_ROOT_DIR":"../poco/build/android-arm64-31-Debug/install",
            "OPENSSL_ROOT_DIR":"../openssl/build/android-arm64-31-Debug/install",
            "SQLITE3_ROOT_DIR":"../sqlite/build/android-arm64-31-Release/install",
            "GTEST_ROOT_DIR":"../googletest/build/android-arm64-31-Debug/install",
            "CMAKE_FIND_ROOT_PATH":["../poco/build/android-arm64-31-Debug/install",
            "../openssl/build/android-arm64-31-Debug/install",
            "../sqlite/build/android-arm64-31-Release/install",
            "../googletest/build/android-arm64-31-Debug/install"]
          }
        },
        "release": {
          "short": "Release",
          "long": "Optimize for speed - exclude debug information.",
          "buildType": "Release",
          "settings": {
            "CMAKE_CXX_FLAGS_RELEASE":"-Wall -Os",
            "Poco_ROOT_DIR":"../poco/build/android-arm64-31-Release/install",
            "OPENSSL_ROOT_DIR":"../openssl/build/android-arm64-31-Release/install",
            "SQLITE3_ROOT_DIR":"../sqlite/build/android-arm64-31-Release/install",
            "GTEST_ROOT_DIR":"../googletest/build/android-arm64-31-Release/install",
            "CMAKE_FIND_ROOT_PATH":["../poco/build/android-arm64-31-Release/install",
            "../openssl/build/android-arm64-31-Release/install",
            "../sqlite/build/android-arm64-31-Release/install",
            "../googletest/build/android-arm64-31-Release/install"]
          }
        }
      }
    },
    "buildTarget": {
      "default": "x64",
      "description": "abi for 64 bit target build",
      "choices": {
        "local": {
          "short": "local",
          "long": "abi for linux x64 bit",
          "env": {
            "target":"local"
          },
          "settings": {
            "CMAKE_SYSTEM_NAME": "Linux",
            "CMAKE_INSTALL_PREFIX": "/usr/local",
            "CMAKE_CXX_COMPILER":"/usr/bin/g++",
            "CMAKE_C_COMPILER":"/usr/bin/gcc"
          }
        },
        "vs8": {
          "short": "vs8",
          "long": "vs8 plantform",
          "env": {
            "target":"vs8"
          },
          "settings": {
            "CMAKE_TOOLCHAIN_FILE": "../android-ndk-r25c/build/cmake/android.toolchain.cmake",
            "CMAKE_INSTALL_PREFIX":"install",
            "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM":"NEVER",
            "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY":"ONLY",
            "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE":"ONLY",
            "PLANTFORM":"Alios"
          }
        },
        "alios_x64": {
          "short": "alios_x64",
          "long": "alios_x64 plantform",
          "env": {
            "target":"x64"
          },
          "settings": {
            "CMAKE_SYSTEM_NAME": "Linux",
            "CMAKE_TOOLCHAIN_FILE": "../android-ndk-r25c/build/cmake/android.toolchain.cmake",
            "PLANTFORM":"Alios",
            "Project_Tests":"On"
          }
        },
        "android-arm64-31": {
          "short": "android-arm64-31",
          "long": "android arm64-v8a API-31 bit target build",
          "env": {
            "target":"android-arm64-31"
          },
          "settings": {
            "CMAKE_INSTALL_PREFIX": "install",
            "CMAKE_TOOLCHAIN_FILE": "../android-ndk-r25c/build/cmake/android.toolchain.cmake",
            "CMAKE_SYSTEM_NAME": "Android",
            "CMAKE_ANDROID_ARCH_ABI": "arm64-v8a",
            "BUILD_SHARED_LIBS":1,
            "LOCAL_LIBS":"--lfoo",
            "LOCAL_SHARED_LIBRARIES" : "log-lib",
            "ANDROID_ABI": "arm64-v8a",
            "ANDROID_NDK": "../android-ndk-r25c",
            "ANDROID_PLATFORM": "android-31",
            "CMAKE_SYSTEM_VERSION": 31,
            "ANDROID_STL":"c++_static",
            "APP_STL":"c++_static",
            "Project_Tests":"ON",
            "PLANTFORM":"Android"
          }
        },
        "android-x86_64-31": {
          "short": "android-x86_64-31",
          "long": "android x86_64 API-31 bit target build",
          "env": {
            "target":"android-x86_64-31"
          },
          "settings": {
            "CMAKE_INSTALL_PREFIX": "install",
            "CMAKE_TOOLCHAIN_FILE": "../android-ndk-r25c/build/cmake/android.toolchain.cmake",
            "CMAKE_SYSTEM_NAME": "Android",
            "CMAKE_ANDROID_ARCH_ABI": "x86_64",
            "BUILD_SHARED_LIBS":1,
            "LOCAL_LIBS":"--lfoo",
            "LOCAL_SHARED_LIBRARIES" : "log-lib",
            "ANDROID_ABI": "x86_64",
            "ANDROID_NDK": "../android-ndk-r25c",
            "ANDROID_PLATFORM": "android-31",
            "CMAKE_SYSTEM_VERSION": 31,
            "ANDROID": "ON",
            "ANDROID_STL":"c++_static",
            "Project_Tests":"OFF"
          }
        }
      }
    }
  }

settings.json

{
    "makefile.extensionOutputFolder": "./.vscode",
    "cmake.sourceDirectory": "../mosi-viwi/viwi_car_service_org",
    "cmake.buildDirectory": "${workspaceFolder}/build/${env.target}-${buildType}",
    "files.exclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/CVS": true,
        "**/.DS_Store": true,
        "**/Thumbs.db": true,
        "**/build*":true,
        "example":true
    },
    "files.associations": {
        "array": "cpp",
        "atomic": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "chrono": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "condition_variable": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "ctime": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "list": "cpp",
        "unordered_map": "cpp",
        "unordered_set": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "fstream": "cpp",
        "functional": "cpp",
        "future": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "iostream": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "memory": "cpp",
        "mutex": "cpp",
        "new": "cpp",
        "optional": "cpp",
        "ostream": "cpp",
        "ratio": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "thread": "cpp",
        "type_traits": "cpp",
        "tuple": "cpp",
        "typeinfo": "cpp",
        "utility": "cpp",
        "__config": "cpp",
        "cstdarg": "cpp",
        "cstring": "cpp",
        "algorithm": "cpp",
        "iomanip": "cpp",
        "numeric": "cpp",
        "cinttypes": "cpp",
        "__bit_reference": "cpp",
        "__debug": "cpp",
        "__errc": "cpp",
        "__functional_base": "cpp",
        "__hash_table": "cpp",
        "__locale": "cpp",
        "__mutex_base": "cpp",
        "__node_handle": "cpp",
        "__nullptr": "cpp",
        "__split_buffer": "cpp",
        "__string": "cpp",
        "__threading_support": "cpp",
        "__tree": "cpp",
        "__tuple": "cpp",
        "bit": "cpp",
        "bitset": "cpp",
        "cstddef": "cpp",
        "ios": "cpp",
        "iterator": "cpp",
        "locale": "cpp",
        "map": "cpp",
        "set": "cpp",
        "string": "cpp",
        "csignal": "cpp"
    }
}

demo.code-workspace

{
	"folders": [
		{
			"name":"CommonAPI_Java",
			"path": ".."
		},
		{
			"name":"CommonAPI_C++",
			"path": "../demo/src/main/cpp"
		}
	],
	"settings": {
		"java.configuration.updateBuildConfiguration": "automatic",
		"java.debug.settings.onBuildFailureProceed": true,
		"java.configuration.maven.globalSettings": "",
		"files.associations": {
			"iostream": "cpp",
			"e01helloworld.hpp": "c",
			"e01helloworldproxy.hpp": "c",
			"e01helloworldproxybase.hpp": "c",
			"e01helloworldstubdefault.hpp": "c",
			"helloworld.h": "c",
			"array": "cpp",
			"atomic": "cpp",
			"*.tcc": "cpp",
			"cctype": "cpp",
			"chrono": "cpp",
			"clocale": "cpp",
			"cmath": "cpp",
			"condition_variable": "cpp",
			"cstdarg": "cpp",
			"cstddef": "cpp",
			"cstdint": "cpp",
			"cstdio": "cpp",
			"cstdlib": "cpp",
			"cstring": "cpp",
			"ctime": "cpp",
			"cwchar": "cpp",
			"cwctype": "cpp",
			"deque": "cpp",
			"list": "cpp",
			"unordered_map": "cpp",
			"unordered_set": "cpp",
			"vector": "cpp",
			"exception": "cpp",
			"algorithm": "cpp",
			"functional": "cpp",
			"optional": "cpp",
			"ratio": "cpp",
			"string_view": "cpp",
			"system_error": "cpp",
			"tuple": "cpp",
			"type_traits": "cpp",
			"fstream": "cpp",
			"future": "cpp",
			"initializer_list": "cpp",
			"iomanip": "cpp",
			"iosfwd": "cpp",
			"istream": "cpp",
			"limits": "cpp",
			"memory": "cpp",
			"mutex": "cpp",
			"new": "cpp",
			"ostream": "cpp",
			"numeric": "cpp",
			"sstream": "cpp",
			"stdexcept": "cpp",
			"streambuf": "cpp",
			"thread": "cpp",
			"cinttypes": "cpp",
			"utility": "cpp",
			"typeinfo": "cpp",
			"iterator": "cpp",
			"map": "cpp",
			"memory_resource": "cpp",
			"random": "cpp",
			"set": "cpp",
			"string": "cpp",
			"base1.h": "c",
			"derived.h": "c",
			"e01helloworldproxy.h": "c",
			"e01helloworldproxybase.h": "c",
			"types.hpp": "c",
			"version.hpp": "c",
			"callinfo.hpp": "c",
			"export.hpp": "c",
			"commonapi.hpp": "c",
			"address.hpp": "c",
			"proxy.hpp": "c",
			"runtime.hpp": "c",
			"attribute.hpp": "c",
			"codecvt": "cpp",
			"any": "cpp",
			"locale": "cpp"
		}
	}
}

配置文件中,对应的project路径需要手动配置;其中,前三个文件是必须的,用于配置与执行Cmake的,最后一个.code-workspace是用于创建workspace的,可放在其它自建目录下,方便打开对应的工程的;

<think>好的,我现在需要帮助用户解决VS Code中Python调试停止的问题,也就是“debug stopped”的情况。根据用户提供的引用内容,我需要结合之前的回答和引用中的信息来找出可能的原因和解决方案。 首先,用户提到之前的问题是关于“Python: Select Interpreter”无法使用,现在转向调试停止的问题。虽然这两个问题不同,但可能有共同点,比如Python扩展的问题或者环境配置错误。 引用[1]中提到,VSCode的Python调试失效可能是因为Python扩展自动更新导致的问题,解决方法是将扩展回退到旧版本。这可能是一个常见原因,特别是如果用户最近更新了扩展后突然出现问题。需要建议用户检查扩展版本,并指导如何回退。 引用[2]涉及Anaconda虚拟环境的问题,解决方案是修改settings.json中的python.terminal.activateEnvironment为false。这提示虚拟环境激活可能导致调试问题,用户可能在调试时遇到了环境激活失败,从而终止了调试会话。需要检查用户的设置是否存在类似配置问题。 引用[3]是关于Ubuntu编译工具版本过高导致的问题,但用户当前的问题可能更多与VS Code配置相关,不过系统环境的问题也不能完全排除,尤其是如果用户在使用特定环境或内核模块时。 接下来,结合之前的回答步骤,可能需要考虑以下方面: 1. **Python扩展版本问题**:自动更新可能导致兼容性问题,回退到稳定版本。 2. **虚拟环境配置错误**:Anaconda环境未正确激活或设置冲突,需调整相关配置。 3. **调试配置错误**:launch.json文件可能有误,需要检查或重新生成。 4. **路径或解释器设置错误**:Python解释器路径不正确,导致调试器无法启动。 5. **扩展冲突或损坏**:其他扩展干扰或Python扩展本身损坏,需重新安装。 6. **系统或依赖项问题**:特定系统环境下工具链版本过高,需调整或屏蔽错误。 需要逐一分析这些可能的原因,并提供对应的解决步骤。同时,确保引用之前提到的解决方案,如修改settings.json中的设置,回退扩展版本,检查虚拟环境等。 还要注意用户可能没有提到的其他潜在因素,例如权限问题、文件路径包含特殊字符、防病毒软件干扰等。但根据现有信息,先集中在已知的引用和常见问题上。 最后,确保回答结构清晰,步骤详细,用户能够逐步操作解决问题,并引用相关的引用内容作为支持。</think>--- ### **VS Code中Python调试停止(Debug Stopped)的常见原因及解决方案** --- #### **1. Python扩展版本兼容性问题** - **现象**:更新Python扩展后突然无法调试,但代码仍可运行。 - **原因**:新版扩展可能存在兼容性Bug(如调试器依赖项冲突)。 - **解决方案**: 1. 打开VS Code,进入扩展市场(`Ctrl+Shift+X`),搜索 **Python** 扩展。 2. 点击扩展右侧的 **齿轮图标** → **Install Another Version**,选择旧版本(如 `2023.10.1`)[^1]。 3. 重启VS Code并尝试重新调试。 > **注**:若手动安装旧版本,需从[VS Code更新日志](https://code.visualstudio.com/updates/v1_66)下载`.vsix`文件,通过 **Install from VSIX** 完成回退[^1]。 --- #### **2. 虚拟环境激活冲突** - **现象**:调试时终端报错 `Conda环境无法激活` 或 `ModuleNotFoundError`。 - **原因**:VS Code默认激活虚拟环境,可能与调试器产生冲突[^2]。 - **解决方案**: 1. 按 `Ctrl+Shift+P` 输入 **Preferences: Open User Settings (JSON)**,打开 `settings.json`。 2. 添加或修改以下配置: ```json "python.terminal.activateEnvironment": false ``` 3. 保存文件并重启VS Code。 --- #### **3. 调试配置(launch.json)错误** - **现象**:调试会话启动后立即终止,无错误提示。 - **原因**:`launch.json` 中参数配置错误(如路径、环境变量)。 - **解决方案**: 1. 删除项目根目录下的 `.vscode/launch.json` 文件。 2. 重新生成配置: - 点击左侧 **Run and Debug** 图标(`Ctrl+Shift+D`)。 - 点击 **create a launch.json file**,选择 **Python File**。 3. 检查默认配置是否符合需求(如 `"program": "${file}"`)。 --- #### **4. Python解释器路径未正确指定** - **现象**:调试时提示 `Python路径无效` 或 `调试器无法连接到进程`。 - **原因**:解释器路径未指向有效Python环境(如虚拟环境、系统环境)。 - **解决方案**: 1. 按 `Ctrl+Shift+P` 输入 **Python: Select Interpreter**,选择正确的解释器(如 `myenv/bin/python`)。 2. 若路径未列出,手动输入路径: - Windows示例:`C:\Python310\python.exe` - macOS/Linux示例:`/usr/local/bin/python3` --- #### **5. 扩展冲突或损坏** - **现象**:调试器启动后崩溃,日志中提示扩展错误。 - **解决方案**: 1. 卸载Python扩展: - 进入扩展面板 → 点击 **卸载**。 2. 删除残留配置: - 清空 `settings.json` 中所有 `python.*` 相关配置。 3. 重新安装Python扩展并重启VS Code。 --- #### **6. 系统工具链兼容性问题(Linux/Mac特有)** - **现象**:调试时内核报错或编译工具链冲突(如Ubuntu 22.04)。 - **解决方案**: 1. **临时方案**:在调试配置中添加环境变量屏蔽错误: ```json "env": { "DISABLE_INTERNAL_DEBUGGER_WORKAROUND": "1" } ``` 2. **长期方案**:更新Python调试器依赖(如 `debugpy`): ```bash pip install --upgrade debugpy ``` --- ### **代码示例:验证调试器连接** ```python # test_debug.py import debugpy # 手动启动调试器监听 debugpy.listen(5678) print("等待调试器连接...") debugpy.wait_for_client() print("调试器已连接!") ``` - 运行此文件后,在VS Code中附加调试器(`Attach to Remote Debugger`)。 --- ### **相关问题** 1. **如何查看VS Code调试日志以定位问题?** - 打开 **输出面板**(`Ctrl+Shift+U`)→ 选择 **Python** 或 **Debug Console** 日志[^1]。 2. **调试时断点不生效如何解决?** - 检查文件路径是否与调试配置中的 `cwd` 一致,或尝试禁用优化器(`python -O`)。 3. **VS Code调试器提示“无法连接到目标进程”怎么办?** - 确认防火墙未阻止调试端口(默认 `5678`),或更换调试协议为 `legacy`[^3]。 --- 通过以上步骤,可覆盖90%的调试停止问题。若仍无法解决,建议提供 **调试日志** 或 **错误截图** 进一步分析[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值