在Windows VSC中调试基于Makefile的开源项目

/ 0评 / 1

在Linux中如何调试,很多人都知道,但是Windows中就不一定了,我拿OpenOCD这个开源项目来举例.

项目地址:https://github.com/openocd-org/openocd

首先下载MSYS2,一路Next就可以了.

下载地址:https://www.msys2.org/

安装后得到以下几个不同的套件.

简单说明一下.

可以在这个目录里修改他们各自的Repo,毕竟在默认Repo在国外比较慢.

里面内置了大多数Repo,需要哪个取消注释哪个就行.

现在安装一些开发环境用的工具.

pacman -S libtool autoconf automake texinfo pkg-config make autogen git unzip bzip2 base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-libusb mingw-w64-x86_64-libusb-compat-git mingw-w64-x86_64-hidapi mingw-w64-x86_64-libftdi mingw-w64-x86_64-arm-none-eabi-gcc mingw-w64-x86_64-capstone

之后切换到F盘进行第一次构建尝试.

cd /f
git clone https://github.com/openocd-org/openocd
git submodule update --init --recursive
cd openocd/
./bootstrap
./configure --enable-internal-jimtcl
make

编译目标在src/openocd.exe中.

在VSC中打开,新建用于调试的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/src/openocd.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode" : "gdb",
            "miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
        }
    ]
}

在main函数打一个断点.

在这个时候,大概可以认为是OK了,但是通常这个编译的调试信息是很少的,所以一般还可以配置.

CFLAGS="-O0 -g3" ./configure

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注