Debugging
VS Code Debugging
For NYRA Framework Developers
If you’re developing the NYRA framework itself using VS Code, you’ll find a launch.json file in the source tree that provides default debug targets.
For NYRA Framework Users
If you’re creating your own application on top of NYRA, you can add configurations to your local .vscode/launch.json so you can:
Set breakpoints
Inspect variables
Debug various programming languages (C++, Go, Python)
Debugging in C++ Applications
If your main application is in C++, your extensions can be in C++ or Python.
Debugging C++ Code with lldb or gdb
lldb Example
{
"name": "app (C++) (lldb, launch)",
"type": "lldb",
"request": "launch", // "launch" or "attach"
"program": "${workspaceFolder}/bin/worker", // The compiled executable
"cwd": "${workspaceFolder}/",
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/nyra_packages/system/xxx/lib", // Linux
"DYLD_LIBRARY_PATH": "${workspaceFolder}/nyra_packages/system/xxx/lib" // macOS
}
}gdb Example
{
"name": "app (C++) (gdb, launch)",
"type": "cppdbg",
"request": "launch", // "launch" or "attach"
"program": "${workspaceFolder}/bin/worker", // The compiled executable
"cwd": "${workspaceFolder}/",
"MIMode": "gdb",
"environment": [
{
"name": "LD_LIBRARY_PATH", // Linux
"value": "${workspaceFolder}/nyra_packages/system/xxx/lib"
},
{
"name": "DYLD_LIBRARY_PATH", // macOS
"value": "${workspaceFolder}/nyra_packages/system/xxx/lib"
}
]
}Debugging Python Code with debugpy (in a C++ App)
debugpy (in a C++ App)Because Python code runs inside an embedded interpreter, you can only attach a Python debugger to a running process.
Install
debugpy:bashCopier le codepip install debugpySet Environment Variables and Launch:
bashCopier le codeNYRA_ENABLE_PYTHON_DEBUG=true NYRA_PYTHON_DEBUG_PORT=5678 ./bin/workerNYRA_ENABLE_PYTHON_DEBUG=truemakes the application wait for a Python debugger to attach.NYRA_PYTHON_DEBUG_PORT=5678is where the debugger server listens.
Attach the Debugger:
{ "name": "app (C++) (debugpy, attach)", "type": "debugpy", "request": "attach", "connect": { "host": "localhost", "port": 5678 }, "justMyCode": false }
Debugging C++ and Python Simultaneously
To launch both C++ (via lldb or gdb) and Python (via debugpy) in a single click, do the following:
Add a Delay Task in
tasks.json:{ "label": "delay 3 seconds", "type": "shell", "command": "sleep 3", "windows": { "command": "ping 127.0.0.1 -n 3 > nul" }, "group": "none" }Launch Configurations in
launch.json:"configurations": [ { "name": "app (C++) (lldb, launch with debugpy)", "type": "lldb", "request": "launch", "program": "${workspaceFolder}/bin/worker", "cwd": "${workspaceFolder}/", "env": { "LD_LIBRARY_PATH": "${workspaceFolder}/nyra_packages/system/xxx/lib", "DYLD_LIBRARY_PATH": "${workspaceFolder}/nyra_packages/system/xxx/lib", "NYRA_ENABLE_PYTHON_DEBUG": "true", "NYRA_PYTHON_DEBUG_PORT": "5678" } }, { "name": "app (C++) (debugpy, attach with delay)", "type": "debugpy", "request": "attach", "connect": { "host": "localhost", "port": 5678 }, "justMyCode": false, "preLaunchTask": "delay 3 seconds" } ], "compounds": [ { "name": "app (C++) (lldb) and app (C++) (debugpy)", "configurations": [ "app (C++) (lldb, launch with debugpy)", "app (C++) (debugpy, attach with delay)" ] } ]
Now you can pick the compound configuration to debug both C++ and Python code at once.
Debugging in Go Applications
If your main application is Go, you can still have extensions in Go, C++, or Python.
Debugging Go Code with Delve
{
"name": "app (golang) (go, launch)",
"type": "go",
"request": "launch",
"mode": "exec",
"cwd": "${workspaceFolder}/",
"program": "${workspaceFolder}/bin/worker",
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/nyra_packages/system/xxx/lib", // Linux
"DYLD_LIBRARY_PATH": "${workspaceFolder}/nyra_packages/system/xxx/lib", // macOS
"NYRA_APP_BASE_DIR": "${workspaceFolder}"
}
}Debugging C++ Code in a Go App
lldb Example
{
"name": "app (Go) (lldb, launch)",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/bin/worker",
"cwd": "${workspaceFolder}/",
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/nyra_packages/system/xxx/lib", // Linux
"DYLD_LIBRARY_PATH": "${workspaceFolder}/nyra_packages/system/xxx/lib" // macOS
},
"initCommands": [
"process handle SIGURG --stop false --pass true"
]
}gdb Example
{
"name": "app (Go) (gdb, launch)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/worker",
"cwd": "${workspaceFolder}/",
"MIMode": "gdb",
"environment": [
{
// Linux
"name": "LD_LIBRARY_PATH",
"value": "${workspaceFolder}/nyra_packages/system/xxx/lib"
},
{
// macOS
"name": "DYLD_LIBRARY_PATH",
"value": "${workspaceFolder}/nyra_packages/system/xxx/lib"
}
]
}Debugging Python Code in a Go App
Use the same procedure as for C++ apps with Python embedded:
NYRA_ENABLE_PYTHON_DEBUG=true NYRA_PYTHON_DEBUG_PORT=5678 ./bin/workerThen attach a Python debugger with:
{
"name": "app (Go) (debugpy, attach)",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"justMyCode": false
}Debugging C++, Go, and Python Together
Add a Delay Task (for the Python debugger).
Launch Configurations in
launch.json:"configurations": [ { "name": "app (golang) (debugpy, remote attach with delay)", "type": "debugpy", "request": "attach", "connect": { "host": "localhost", "port": 5678 }, "preLaunchTask": "delay 3 seconds", "justMyCode": false }, { "name": "app (golang) (go, launch with debugpy)", "type": "go", "request": "launch", "mode": "exec", "cwd": "${workspaceFolder}/", "program": "${workspaceFolder}/bin/worker", "env": { "NYRA_APP_BASE_DIR": "${workspaceFolder}", "NYRA_ENABLE_PYTHON_DEBUG": "true", "NYRA_PYTHON_DEBUG_PORT": "5678" } }, { "name": "app (golang) (lldb, launch with debugpy)", "type": "lldb", "request": "launch", "program": "${workspaceFolder}/bin/worker", "cwd": "${workspaceFolder}/", "env": { "NYRA_ENABLE_PYTHON_DEBUG": "true", "NYRA_PYTHON_DEBUG_PORT": "5678" }, "initCommands": [ "process handle SIGURG --stop false --pass true" ] } ], "compounds": [ { "name": "Mixed Go/Python", "configurations": [ "app (golang) (go, launch with debugpy)", "app (golang) (debugpy, remote attach with delay)" ] }, { "name": "Mixed Go/Python/C++ (lldb)", "configurations": [ "app (golang) (lldb, launch with debugpy)", "app (golang) (debugpy, remote attach with delay)" ] } ]
Mixed Go/Python: Debug both Go and Python in one click.
Mixed Go/Python/C++ (lldb): Add C++ debugging to the mix.
Debugging in Python Applications
If your main application is Python, you can still have C++ extensions.
Debugging C++ Code with lldb/gdb in a Python App
Example launch.json snippet:
{
"name": "app (Python) (cpp, launch)",
"type": "cppdbg",
"request": "launch",
"program": "/usr/bin/python3", // The Python interpreter
"args": [
"main.py"
],
"cwd": "${workspaceFolder}/",
"environment": [
{
"name": "PYTHONPATH",
"value": "${workspaceFolder}/nyra_packages/system/nyra_runtime_python/lib:${workspaceFolder}/nyra_packages/system/nyra_runtime_python/interface"
},
{
"name": "NYRA_APP_BASE_DIR",
"value": "${workspaceFolder}/"
}
],
"MIMode": "gdb" // or "lldb"
}Debugging Python Code with debugpy in a Python App
debugpy in a Python App{
"name": "app (Python) (debugpy, launch)",
"type": "debugpy",
"python": "/usr/bin/python3",
"request": "launch",
"program": "${workspaceFolder}/main.py",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/",
"env": {
"PYTHONPATH": "${workspaceFolder}/nyra_packages/system/nyra_runtime_python/lib:${workspaceFolder}/nyra_packages/system/nyra_runtime_python/interface",
"NYRA_APP_BASE_DIR": "${workspaceFolder}/",
"NYRA_ENABLE_PYTHON_DEBUG": "true"
}
}Debugging C++ and Python Together in a Python App
Launch the Python code with
debugpy.Attach a C++ debugger to the running native process:
{
"name": "app (Python) (cpp, attach)",
"type": "cppdbg",
"request": "attach",
"program": "${workspaceFolder}/bin/worker", // Or the correct native process name
"cwd": "${workspaceFolder}/",
"MIMode": "gdb",
"environment": [
{
"name": "LD_LIBRARY_PATH",
"value": "${workspaceFolder}/nyra_packages/system/xxx/lib"
},
{
"name": "DYLD_LIBRARY_PATH",
"value": "${workspaceFolder}/nyra_packages/system/xxx/lib"
}
]
}You can break into both Python and C++ code while the Python interpreter is embedded in a native process.
Last updated