Search code examples
cvisual-studio-codedebugginggdb

Visual Studio Code gdb Debugger doesn't register any expressions


Update: Question solved. Thanks for the help. I had to set the flags for the debug symbols in my makefile, which looks like this:

cc = gcc -Wall -pedantic
prg = main.exe
obj = main.o datetime.o tools.o calendar.o menu.o
CFLAGS += -O0 -g3

$(prg): $(obj)
    @$(cc) -O0 -g3 -o $@ $^

main.o: main.c menu.h calendar.h
    @$(cc) -O0 -g3 -c $<

tools.o: tools.c
    @$(cc) -O0 -g3 -c $<

datetime.o: datetime.c
    @$(cc) -O0 -g3 -c $<

calendar.o: calendar.c tools.h
    @$(cc) -O0 -g3 -c $<

menu.o: menu.c tools.h
    @$(cc) -O0 -g3 -c $<

run:
    @./$(prg)

all: $(prg) run

I made a launch.json File to do the settings for my debugger but any variable I put in the watch, is not available.

Compiling the debugger did not report any errors, for what reason I think I wrote the right paths and options for the debugger but as I am very unsure because of the lack of knowledge, I decided to put the file and the main file of my folder here to let everybode see, if the launch.json file actually has any inconsistensies.

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;
}

I first simply wrote the variable name and then fully wrote it with it's type and also tried other variables. The breakpoint also doesn't work if I set them. I think the program should stop after reaching the breakpoint. I also had as the launch.json file shows, set a second terminal for the debug session to manipulate the values in it.


Solution

  • This is happening most likely because your program is not compiled with debug symbols / information.

    • To compile with debug information, use the -g flag with GCC.
    • -g1, -g2, and -g3 can also be used, -g3 would have the most amount of debug information.

    Here's an example:

    gcc main.c -O0 -g3 -o main.exe
    

    If you're using CMake, you can set it like this:

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g3")