I need a way to debug a C program consisting of multi C files with the makefile in vscode, when I debug the program using the wingw32-make command in the tasks.json , the program run directly without stoping at the breakpoints, but when using the gcc command in the tasks.json the breakpoints can be arrived. I am confused. Forgive my ignorance, any response would be greatly appreciated!
below is my code
heada.h
#ifndef PRACTICES_MYFUNC0A_H#define PRACTICES_MYFUNC0A_Henum steerwheel {square, circle};typedef struct { int wheels; enum steerwheel sw;} Car;Car * getCar(int, enum steerwheel);#endif //PRACTICES_MYFUNC0A_H
MainTest.c
#include <stdio.h>#include <malloc.h>#include "funcha.h"int main() { Car *car = getCar(4, square); int i; printf("%d,%d\n",car->wheels, car->sw); scanf("%d",&i); printf("%d\n", i); free(car); getchar();}
MyFunc01.c
#include <stdio.h>#include <malloc.h>#include "funcha.h"Car * getCar(int wheels, enum steerwheel sw) { Car *car = malloc(sizeof(Car)); car->wheels = wheels; car->sw = sw; return car;}
Makefile
MainTest: MainTest.o myFunc01.o funcha.h gcc -o MainTest MainTest.o myFunc01.omyFunc01.o: myFunc01.c funcha.h gcc -c myFunc01.cMainTest.o: MainTest.c funcha.h gcc -c MainTest.c.PHONY: cleanclean: rm MainTest myFunc01.o MainTest.o
and the .vscode foloer's file is below:launch.json
{"version": "0.2.0","configurations": [ {"name": "(gdb) 启动","type": "cppdbg","request": "launch","program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "D:\\work_softwares\\mingw64\\bin\\gdb.exe","setupCommands": [ {"description": "为 gdb 启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true } ],"preLaunchTask": "makerun" } ]}
tasks.json
{"tasks": [ {"type": "shell","label": "makerun", // this manner can arrived at the breakpoints。 why ???????"command": "D:\\work_softwares\\mingw64\\bin\\mingw32-make.exe","args": ["-C","${workspaceFolder}","MainTest" ],"options": {"cwd": "D:\\work_softwares\\mingw64\\bin" },"problemMatcher": [],"group": {"kind": "build","isDefault": true } }, {"type": "shell","label": "notmakerun", // this manner can arrived at the breakpoints。"command": "D:\\work_softwares\\mingw64\\bin\\gcc.exe","args": ["-g","${workspaceFolder}\\*.c","-o","${workspaceFolder}\\MainTest.exe" ],"options": {"cwd": "D:\\work_softwares\\mingw64\\bin" },"problemMatcher": [] } ],"version": "2.0.0"}