1

I am new to Visual Studio Code. I am trying to debug a simple C++ code. I edited my launch.json to be able to debug the app like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch", 
            "type": "cppdbg",  
            "request": "launch",      
            "program": "${workspaceFolder}/Calculator",   
            "args": [],   
            "stopAtEntry": false,  
            "cwd": "${workspaceFolder}",  
            "environment": [],  
            "externalConsole": true,  
            "MIMode": "lldb"            
        }        
    ]
}

When I start debugging, the terminal is opened in the correct folder but the program is not executed. So the Visual Code does not stop in the breakpoints I want to check in the program.

In my task.json I have the following code:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Echo vars",
            "command": "echo",
            "args": [
                "${env:USERNAME}",
                "workspaceFolder = ${workspaceFolder}"
            ],
            "type": "shell",
            "problemMatcher": []
        },
        {
            "label": "build",
            "type": "shell",
            "command": "g++ -g Calculator.cpp -o Calculator",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": "$gcc"
        }
    ]
}

Can anybody help me on this?

Thanks in advance

2
  • 1
    have you built your code with debug symbols? Commented Mar 19, 2020 at 19:43
  • Hi Alan, thanks for answering. I am afraid I do not know what you mean with "debug symbols". Can you explain me that in more detail please? Commented Mar 19, 2020 at 19:51

1 Answer 1

1

As mentioned in the comments: if your Calculator.cpp is not compiled with debug symbols ie. g++ called without -g flag, you will not be able to debug it.

Hence, add to your launch.json a prelaunchTask entry which will make sure your build task which is compiling your source with debug symbols is always executed prior to launching the debugger.

"environment": [],  
"externalConsole": true,  
"MIMode": "lldb",      
"preLaunchTask": "build"

edit your launch.json to add debugger log output to your project:

"logging": { "engineLogging": true, "trace": false, "traceResponse": false } 
Sign up to request clarification or add additional context in comments.

22 Comments

I added all that. Besides in my task.json I have the following sentence: "command": "g++ -g Calculator.cpp -o Calculator", so I guess I am compiling with debug symbols as you suggested. I followed different tutorial and I do not know what is wrong with may Mac. I guess I will try to reinstall VSCode again
do you see in VSC that the command g++ -g Calculator.cpp -o Calculator is executed before your program is launched?
Hi pero_hero. Thanks for answering. Yes, the command is being executed before my program is launched. Actually, to be sure of that I deleted the executable file after pressing the Start Debugging button. And the command is perfectly executed. Calculator executable file is correctly created.
In the debug console i always get this message: "Warning: Debuggee TargetArchitecture not detected, assuming x86_64."
I have this warning message as well and it is working. can you try to add a logging output of the debugger to your project, as shown in the updated answer and add the first part of it to the OP? I would also set stopAtEntry to true.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.