Home > Blockchain >  Set breakpoints in C debugger (vs code)
Set breakpoints in C debugger (vs code)

Time:11-30

The issue I'm having is that when I run "C run/debug active file" the the code executes but doesn't stop at the breakpoints I set. I don't know a lot about how debuggers work but I'm guessing the the debugger isn't listening to the correct process? Or why would this happen?

In all honesty, I've been struggling to get all my dependencies correct and in the process may have broke intended functionality so it could be that I set up the scripts in a way that breaks it's intended use.

tasks.json looks like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C  : g   build active file",
            "command": "g  ",
            "args": [
                "main.cc",
                "-o",
                "main",
                "-std=c  17",
                "-I/usr/local/include/cairomm-1.16",
                "-I/usr/local/lib/cairomm-1.16/include",
                "-I/usr/include/cairo",
                "-I/usr/include/glib-2.0",
                "-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
                "-I/usr/include/pixman-1",
                "-I/usr/include/uuid",
                "-I/usr/include/freetype2",
                "-I/usr/include/libpng16",
                "-I/usr/include/sigc  -3.0",
                "-I/usr/lib/x86_64-linux-gnu/sigc  -3.0/include",
                "-L/usr/local/lib",
                "-lcairomm-1.16",
                "-lcairo",
                "-lsigc-3.0",
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Debugger."
        },
        {
            "type": "cppbuild",
            "label": "C/C  : g  -9 build active file",
            "command": "/usr/bin/g  -9",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-L/usr/local/lib",
                "-lcairomm-1.16",
                "-lcairo",
                "-lsigc-3.0"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ]
}

launch.json looks like this:

{
    "version": "0.0.0",
    "configurations": [
        {
            "name": "gcc - Build and debug active file",
            "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": "C/C  : gcc build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

c_cpp_properties.json looks like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C  : g   build active file",
            "command": "g  ",
            "args": [
                "main.cc",
                "-o",
                "main",
                "-std=c  17",
                "-I/usr/local/include/cairomm-1.16",
                "-I/usr/local/lib/cairomm-1.16/include",
                "-I/usr/include/cairo",
                "-I/usr/include/glib-2.0",
                "-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
                "-I/usr/include/pixman-1",
                "-I/usr/include/uuid",
                "-I/usr/include/freetype2",
                "-I/usr/include/libpng16",
                "-I/usr/include/sigc  -3.0",
                "-I/usr/lib/x86_64-linux-gnu/sigc  -3.0/include",
                "-L/usr/local/lib",
                "-lcairomm-1.16",
                "-lcairo",
                "-lsigc-3.0",
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Debugger."
        },
        {
            "type": "cppbuild",
            "label": "C/C  : g  -9 build active file",
            "command": "/usr/bin/g  -9",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-L/usr/local/lib",
                "-lcairomm-1.16",
                "-lcairo",
                "-lsigc-3.0"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ]
}

I reworked it and went slower this time. I don't have a launch file but

Here's tasks:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C  : g   build active file",
            "command": "/usr/bin/g  ",
            "args": [
                "-fdiagnostics-color=always",
                "-std=c  17",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-I/usr/local/include/cairomm-1.16",
                "-I/usr/local/lib/cairomm-1.16/include",
                "-I/usr/include/cairo",
                "-I/usr/include/glib-2.0",
                "-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
                "-I/usr/include/pixman-1",
                "-I/usr/include/uuid",
                "-I/usr/include/freetype2",
                "-I/usr/include/libpng16",
                "-I/usr/include/sigc  -3.0",
                "-I/usr/lib/x86_64-linux-gnu/sigc  -3.0/include",
                "-L/usr/local/lib",
                "-lcairomm-1.16",
                "-lcairo",
                "-lsigc-3.0",
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

And here's c_cpp_properties

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/lib",
                "/usr/local/lib/cairomm-1.16/include",
                "/usr/local/include/cairomm-1.16",
                "/usr/include/sigc  -3.0",
                "/usr/lib/x86_64-linux-gnu/sigc  -3.0/include",
                "/usr/include/cairo",
                "/usr/include/freetype2"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu  20",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

CodePudding user response:

I think there are a lot of unnecessary code in your tasks.json , try this out I am successfully able to set breakpoints during debugging .

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C  : g  .exe build active file",
            "command": "C:\\MinGW\\bin\\g  .exe",
            "args": [
                "-g",
                "${workspaceFolder}\\*.cpp",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: C:\\MinGW\\bin\\g  .exe"
        }
    ]
}
  • Related