Debugging C++ on SublimeText

143 Views Asked by At

Following https://packagecontrol.io/packages/Debugger to debug python in ST, I noticed .sublime-project gets an additional section

"debugger_configurations":
[
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}"
    },
],

I tried to do something similar for a simple C++ project in ST. Then I saw

"debugger_configurations":
[
    {
        "type": "gdb",
        "request": "launch",
        "name": "Launch Program",
        "target": "./bin/executable",
        "cwd": "${folder}",
        "valuesFormatting": "parseText"
    },
],

I set a breakpoint and hit play, which led to

Could not start debugger process, does the program exist in filesystem?
Error: spawn gdb ENOENT
Debugging ended

I changed "target": "./myexecutable", hit play again and got the same result as before.

Is it possible to debug C++ on ST? I wondering where I'm going wrong.

2nd try, with lldb it adds:

"debugger_configurations":
[
    {
        "type": "lldb",
        "request": "launch",
        "name": "Launch",
        "program": "${folder}/<program>",
        "args": [],
        "cwd": "${folder}"
    },

Hit play and

Console is in 'commands' mode, prefix expressions with '?'. unable to find executable for '/Users/user/project/'

enter image description here

Then changed "program": "${folder}/${file_base_name}",

and got

enter image description here

2

There are 2 best solutions below

0
KcFnMi On

https://github.com/daveleroy/SublimeDebugger/blob/master/examples/cpp/cpp.sublime-project

"debugger_configurations": [
    {
        "name": "C++ (Console)",
        "type": "lldb",
        "request": "launch",
        "program": "${project_path}",
        "cwd": "${project_path}",
        "terminal": "external",
    },
0
Somedude On

That is a bug with the debugger plugin itself. It has been fixed in a recent commit.

The plugin on package control is outdated and has not been updated by the developer in a while, and some of the recent patches are unavailable there. Install the plugin by directly cloning SublimeDebugger's github repository into your packages folder (found inside Sublime Text's data directory) should fix your issue.

If that still does not work, try checking out an older commit using git. The current version might be a bit unstable [citation needed]