Skip to content
Advertisement

How can I set up launch.json in Visual Code to debbug C

I’m newbie about Visual Code. I’d like to use Debbuging function with Visual Code. But There is a probelm to do it. It may happen by wrong launch.json setting(In my opnion)

I’m using mac os newest version.

I refered to some pages to do it myself.

https://code.visualstudio.com/docs/languages/cpp

https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md

https://code.visualstudio.com/docs/python/debugging

However I saw same error. It said “launch: program ‘${/Users/bpk/Documents/Study/C/Study}/study’ does not exist”

This is my launch.json file below

    {
    "version": "0.2.0",
    "configurations": [

{
    "name": "Python3",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "pythonPath": "${config:python.pythonPath}",
    "program": "${/Users/bpk/Documents/Study/Python3/study.py}",
    "cwd": "${/Users/bpk/Documents/Study/Python3}",
    "env": {},
    "envFile": "${/Users/bpk/Documents/Study/Python3}/.env",
    "debugOptions": [
        "RedirectOutput"
    ]
},
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${/Users/bpk/Documents/Study/C/Study}/study",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${/Users/bpk/Documents/Study/C/Study}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        { 
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${/Users/bpk/Documents/Study/C/Study}/study",
            "processId": "${command:pickProcess}",
            "MIMode": "gdb"
        }
    ],
    "compounds": []
}

=cmd-param-changed,param="pagination",value="off"
[New Thread 0x1803 of process 16326]
[New Thread 0x1a03 of process 16326]
[New Thread 0x2703 of process 16326]
ERROR: Unable to start debugging. Unexpected GDB output from command        "-exec-run". Warning:
Cannot insert breakpoint -1.
Cannot access memory at address 0xf782
The program '/Users/jaekwangkim/Documents/Workspace/Project/C/PE_File_Assembler/a.out' has exited with code 42 (0x0000002a).

Upper message is debug console log from visual code

Thanks to read my first question!

Advertisement

Answer

I think you are mixing up variables and strings ${...} indicates a variable used within visual code. Directory paths don’t need the encompassing ${}.

Your Python3 configuration should look like this:

{
    "name": "Python3",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "pythonPath": "${config:python.pythonPath}",
    "program": "/Users/bpk/Documents/Study/Python3/study.py",
    "cwd": "/Users/bpk/Documents/Study/Python3",
    "env": {},
    "envFile": "/Users/bpk/Documents/Study/Python3/.env",
    "debugOptions": [
        "RedirectOutput"
    ]
},

Changes to your C debug configuration are much the same as Python and should look like this:

 {
     "name": "(gdb) Launch",
     "type": "cppdbg",
     "request": "launch",
     "program": "/Users/bpk/Documents/Study/C/Study/study",
     "args": [],
     "stopAtEntry": false,
     "cwd": "/Users/bpk/Documents/Study/C/Study",
     "environment": [],
     "externalConsole": false,
     "MIMode": "gdb",
     "setupCommands": [
         {
             "description": "Enable pretty-printing for gdb",
             "text": "-enable-pretty-printing",
             "ignoreFailures": true
         }
     ]
 },
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement