Skip to content

joshring/c3-debugging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 

Repository files navigation

c3-debugging

C3 debugging in vscode on Windows, Linux and Mac

Important

Set File->Preferences->Settings, set "debug.allowBreakpointsEverywhere" This will allow you to set breakpoints graphically

Click here if you prefer to set breakpoints manually

Manually add the breakpoints at the bottom of the debug window (see bottom left of screenshot), unfortunately I have not figured out how to do so via the side of the editor window

Manually adding breakpoints supports:

  • File and Line based breakpoints: file_name.c3:line_number for example: main.c3:5
  • Package and function based breakpoints: package_name.function_name for example my_library.example_fn
Alt Text

Linux with GDB

Linux with GDB and C++ dev tools

Download VSCode extension for debugging support

VSCode extension used: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

Add the following directories and files

Add file: .vscode/launch.json

File content:

{
    // 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 with C++ devtools",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/your_project_exe_name",
            "args": [],
            "cwd": "${workspaceFolder}/build",
            "environment": [],
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb",
            "setupCommands": [
                {
                    "text": "-enable-pretty-printing",
                }
            ],
            "preLaunchTask": "c3cbuild",
            "stopAtEntry": true,
        }
    ]
}

Add file .vscode/tasks.json

File content:

{
    "version": "2.0.0",
    "type":"shell",
    "tasks": [
        {
            "type": "shell",
            "command": "c3c",
            "args": ["build"],
            "label": "c3cbuild",
            "presentation": {
                "echo": true,
		"reveal": "never",
		"focus": false,
		"panel": "dedicated",
		"showReuseMessage": false,
		"clear": false,
		"revealProblems": "onProblem",
		"close": true
            },
            "problemMatcher": {
                "owner": "c3c",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+)\\s+(Warning|Error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

Linux and possibly MacOS with LLVM using DAP

Download VSCode extension for debugging support

VSCode extension used: https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap

Add the following directories and files

Add file: .vscode/launch.json

File content:

{
    // 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": [
        // On ubuntu: sudo apt-get install llvm llvm-18 llvm-18-dev lldb lldb-18 llvm-18-tools
        // add to your path /usr/lib/llvm-18/bin/lldb-dap
        // I added this to my .bashrc file
        // export PATH="/usr/lib/llvm-18/bin:$PATH"
        //
        // On Mac I believe llvm tools are already installed
        {
            "name": "lldb dap Debug",
            "type": "lldb-dap",
            "request": "launch",
            "program": "${workspaceFolder}/build/your_project_exe_name",
            // "args": [ "one", "two", "three" ],
            // "env": {
            //    "FOO": "1"
            //    "BAR": ""
            // }
            "preLaunchTask": "c3cbuild",
            "stopOnEntry": true
        }
    ]
}

Add file .vscode/tasks.json

File content:

{
    "version": "2.0.0",
    "type":"shell",
    "tasks": [
        {
            "type": "shell",
            "command": "c3c",
            "args": ["build"],
            "label": "c3cbuild",
            "presentation": {
                "echo": true,
		"reveal": "never",
		"focus": false,
		"panel": "dedicated",
		"showReuseMessage": false,
		"clear": false,
		"revealProblems": "onProblem",
		"close": true
            },
            "problemMatcher": {
                "owner": "c3c",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+)\\s+(Warning|Error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

Debugging on NVIM

Debugging with VSCode on Windows

Important

Set File->Preferences->Settings, set "debug.allowBreakpointsEverywhere" This will allow you to set breakpoints graphically

Add the following directories and files

Add file: .vscode/launch.json

File content:

{
    // 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": "MSVC debugger for C3",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\build\\project_name_here_to_replace.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "preLaunchTask": "c3cbuild",
        }
    ]
}

Add file .vscode/tasks.json

File content:

{
    "version": "2.0.0",
    "type":"shell",
    "tasks": [
        {
            "type": "shell",
            "command": "c3c",
            "args": ["build"],
            "label": "c3cbuild",
            "presentation": {
                "echo": true,
		"reveal": "never",
		"focus": false,
		"panel": "dedicated",
		"showReuseMessage": false,
		"clear": false,
		"revealProblems": "onProblem",
		"close": true
            },
            "problemMatcher": {
                "owner": "c3c",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+)\\s+(Warning|Error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

Clion debugging with C3 with LLVM-dap

  • Create a new Run/Debug configuration based on Debug Adapter Protocol, make the command point to your lldb-dap exe, in my case it's just from my local mingw installation
  • Under mappings specify the language and file types (you need the c3intellij plugin installed for this, I think).
  • Under Configuration, specify the working dir and path to the exe, and provide the full DAP parameters to pass on in the form of JSON. You're supposed to be able to use variables here instead of hardcoding the paths, but I couldn't quite get it working so this is good enough for me right now.,

That should be it, I think. It respects my in-editor breakpoints and I can see my locals. image_lat

About

C3 debugging in vscode on Linux and Mac

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors