我创建了一个 launch.json 文件来为我的调试器进行设置,但我放入手表中的任何变量都不可用。
编译调试器没有报告任何错误,出于什么原因,我认为我为调试器编写了正确的路径和选项,但由于缺乏知识,我非常不确定,我决定将文件和我的主文件放在放在这里让大家看看,launch.json 文件是否真的有不一致的地方。
launch.json:
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "A:\\Dokumente\\BHT\\WiSe2324\\AuD\\ueb03\\main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "A:\\Dokumente\\BHT\\WiSe2324\\AuD\\ueb03",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "A:\\Programme\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
main.c:
#include <stdio.h>
#include <stdlib.h>
#include "datastructure.h"
#include "tools.h"
#include "menu.h"
#include "calendar.h"
int main(){
char *menuTitle[] = {"Termin erstellen", "Termin bearbeiten", "Termin entfernen", "Termin suchen", "Termine sortieren", "Terminne auflisten", "Programm beenden"};
int menuChoice = 0;
sAppointment Calendar[MAXAPPOINTMENTS];
do{
menuChoice = getMenu("ULTIMATIVE TERMINERSTELLUNGSSOFTWARE V0.3", menuTitle, 7);
switch(menuChoice){
case 1:
createAppointment();
break;
case 2:
editAppointment();
break;
case 3:
deleteAppointment();
break;
case 4:
searchAppointment();
break;
case 5:
sortCalendar();
break;
case 6:
listCalendar();
break;
case 7:
printf("Programm wird beendet");
break;
case 2147483647:
Dog();
waitForEnter("\n\n\n");
}
}while(menuChoice != 7);
free(Calendar);
return 0;
}
我首先简单地写了变量名称,然后用它的类型完整地写了它,还尝试了其他变量。 如果我设置了断点,它们也不起作用。我认为程序应该在到达断点后停止。 正如 launch.json 文件所示,我还为调试会话设置了第二个终端来操作其中的值。
发生这种情况很可能是因为您的程序未使用调试符号/信息进行编译。
-g
标志。-g1
、-g2
和-g3
,-g3
拥有最多的调试信息。这是一个例子:
gcc main.c -O0 -g3 -o main.exe
如果你使用CMake,你可以这样设置:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g3")