#C++ debugging in VSCode

13 messages · Page 1 of 1 (latest)

limpid abyss
#

I an trying to understand how to enable the gcc debugger in vscode for the c++ track.
While working on the Log Levels example, I was able to solve it and build it locally. "make-C build" generates the binary and passes all the test. Now suppose I want to run this particular example under the gcc debugger, I followed the instructions in https://forum.exercism.org/t/local-testing-in-vsc-on-c-how-to-use-debug-features/7270, creating the launch.json and task.json but i still get an error.

*  Executing task: C/C++: g++ build active file 

Starting build...
/usr/bin/g++ -fdiagnostics-color=always -g /home/alejandrojginerd/exercism/cpp/log-levels/log_levels.cpp -o /home/alejandrojginerd/exercism/cpp/log-levels/log_levels
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status

Build finished with error(s).

 *  The terminal process failed to launch (exit code: -1). 
 *  Terminal will be reused by tasks, press any key to close it. 

it seems it is looking for the main() function witch does not exist but then why was it able to build it in the first place (not under gcc debugger). What am i missing?

signal vessel
#

I tried to setup debugging in VSCode on my Linux partition and succeeded in hitting a breakpoint.

  1. What OS are you using?
  2. Could you provide us with the content of your launch.json file?

As a side note, I did not use make -C build to build. Instead, I followed the instructions found on this page: https://exercism.org/docs/tracks/cpp/tests

Basically, I did this:

mkdir build
cd build
cmake -G "Unix Makefiles" ..
make
Exercism

Learn how to test your C++ exercises on Exercism

limpid abyss
# signal vessel I tried to setup debugging in VSCode on my Linux partition and succeeded in hitt...
  1. I am running Ubuntu 22.04.4 LTS
    // 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": "${workspaceFolder}/build/log-levels",   //<- paste relative path here
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "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
                }
            ]
        }
    ]
} ```
signal vessel
#

Your launch.json file looks similar to mine, but I just noticed you mentioned a tasks.json file. I didn't use that; I created the executable to debug by simply running make. Maybe the issue is in that file? Could you provide its content?

limpid abyss
#
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}```
#

As I have said, making the project and building it is no problem. When I run make -C build it runs and passes all the tests. However, for future excersices i would like to be able to add breakpoints and run the program line-by-line using VScode debbuger.

#

ussually, adding breackpoints to my project is no problem but for excersim projects I have been having some trouble. I supopose iot has to do with the whole make thing as my projects so far never required more than one .cpp and one .hpp

signal vessel
#

I'm not sure you need the tasks.json file. Try renaming it to something else, build using make and run the debugger to see if it works. If it does, you could simply delete the tasks.json file.

limpid abyss
#

deleting the task.json does not solve the issue. VScode automatically regenrates it when i runn the debugger

signal vessel
#

How do you run the debugger? Maybe I'm not using the same command.

limpid abyss
#

I simply click the run and debugg button in the IDE

#

top right corner