Я пытаюсь отладить программу C
с VS Code, который загружает методы через заголовочные файлы и использует Makefile для компиляции. Я хочу поместить точки останова в другие файлы C
, чтобы проверить, правильно ли работают мои методы.
speller.c
#include "dictionary.h"
int main(int argc, char *argv[])
{
bool loaded = load(dictionary);
}
dictionary.c
bool load(const char *dictionary)
{
// BREAKPOINT!
}
Makefile
speller:
gcc -g -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o speller.o speller.c
gcc -g -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o dictionary.o dictionary.c
gcc -g -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -o speller speller.o dictionary.o
Вот мой собственный bash-скрипт, который я сделал, чтобы я мог быстро получить самые новые файлы .out
и скомпилированный код, и мне не нужно было повторять все шаги вручную.
Это было сделано исполняемым, чтобы я мог использовать его в моем tasks.json
позже.
delete-make-run.sh
#!/bin/bash
rm -f \*.o && rm -f $1 && make && ./$1 $2 $3
launch.json
{
"name": "gcc build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/speller",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc delete make run",
"miDebuggerPath": "/usr/bin/gdb"
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc delete make run",
"command": "delete-make-run",
"args": [
"speller",
"texts/aca.txt"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
Запуск моей программы работает следующим образом:
$ delete-make-run speller texts/aca.txt
Когда я ставлю точку останова в speller.c , она работает, но как отладить методы в файле .h
?