VSCode通过Makefile

时间:2019-06-07 20:45:59

标签: c++ visual-studio-code gdb gnu-make

我使用以下Makefile来构建应用程序和对其进行单元测试:

GDB=gdb
DEBUG ?= 1
ifeq ($(DEBUG), 1)
    CCFLAGS =-DDEBUG
    RUNPATH =${GDB}
else
    CCFLAGS=-DNDEBUG
    RUNPATH=""
endif

CPP=g++ ${CCFLAGS}
TESTGEN=cxxtestgen
CFLAGS_DBG="-enable-pretty-printing"
TEST_BUILD_PATH="./build/tests"
BUILD_PATH="./build"
TESTS_SRC_PATH="./tests"
SRC_PATH=""

# NORMAL TARGETS
# To Be filled

# RUN TESTS

test_command_parser_gen:
    ${TESTGEN} --error-printer -o ${TESTS_SRC_PATH}/CommandParser/runner.cpp  ./tests/CommandParser/testCommandParser.h

test_command_parser_build: test_command_parser_gen
    ${CPP} -o ${TEST_BUILD_PATH}/commandParser ${TESTS_SRC_PATH}/CommandParser/runner.cpp ./src/tools/command_parser.cpp

test_command_parser_run: test_command_parser_build
    ${RUNPATH} ./build/tests/commandParser

我希望能够使用make命令通过调试器对其进行调试。如您所见,我可以通过命令make test_command_parser_run DEBUG=1

将单元测试构建为Debig模式。

但是考虑到以下vscode调试配置,

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cpp Build debug test",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "cpp build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

如何通过make命令启动调试器?

0 个答案:

没有答案