The TEN framework supports debugging applications built with multiple programming languages, including C++, Go, and Python. This guide shows you how to configure VS Code to debug your TEN applications effectively, whether you are working with single-language or mixed-language projects.
There are two main use cases when debugging TEN applications. You can use VS Code's debugging capabilities with language-specific debuggers and custom launch configurations for both:
Framework development
When contributing to or modifying the TEN framework itself, use the launch.json file available in the framework's source tree. This file provides default debug targets to help you get started quickly.
Application development
When building your own applications using the TEN framework, add custom configurations to your .vscode/launch.json file. This enables you to set breakpoints and inspect variables, regardless of the programming language you use: C++, Go, or Python.
Both use cases provide breakpoint debugging, variable inspection, and step-through execution capabilities.
When developing your own application based on the TEN framework using VS Code, add custom configurations to your .vscode/launch.json file. This enables you to set breakpoints and inspect variables, regardless of the programming language you use: C++, Go, or Python.
When you write your application in C++, you can write extensions in either C++ or Python.
Use the following configurations to debug C++ code:
-
With lldb:
_11 "name": "app (C++) (lldb, launch)",
_11 "request": "launch", // "launch" or "attach"
_11 "program": "${workspaceFolder}/bin/worker", // The executable path
_11 "cwd": "${workspaceFolder}/",
_11 "LD_LIBRARY_PATH": "${workspaceFolder}/ten_packages/system/xxx/lib", // linux
_11 "DYLD_LIBRARY_PATH": "${workspaceFolder}/ten_packages/system/xxx/lib" // macOS
-
With gdb:
_20 "name": "app (C++) (gdb, launch)",
_20 "request": "launch", // "launch" or "attach"
_20 "program": "${workspaceFolder}/bin/worker", // The executable path
_20 "cwd": "${workspaceFolder}/",
_20 "name": "LD_LIBRARY_PATH",
_20 "value": "${workspaceFolder}/ten_packages/system/xxx/lib"
_20 "name": "DYLD_LIBRARY_PATH",
_20 "value": "${workspaceFolder}/ten_packages/system/xxx/lib"
Use debugpy to debug Python code in TEN applications. Since TEN applications run Python code inside an embedded interpreter rather than starting with the Python interpreter directly, you must attach the debugger to the running process instead of launching it directly.
-
Install debugpy in the Python environment:
-
Set the TEN_ENABLE_PYTHON_DEBUG and TEN_PYTHON_DEBUG_PORT environment variables before starting the application:
_1TEN_ENABLE_PYTHON_DEBUG=true TEN_PYTHON_DEBUG_PORT=5678 ./bin/worker
When you set TEN_ENABLE_PYTHON_DEBUG to true, the application blocks until a debugger is attached. When you set TEN_PYTHON_DEBUG_PORT, the debugger server listens on the specified port for incoming connections.
-
After starting the application, attach the debugger to the running process using the following configuration:
_10 "name": "app (C++) (debugpy, attach)",
To debug C++ and Python code simultaneously with one click in VS Code:
-
Define a delay task before attaching the debugger:
_9 "label": "delay 3 seconds",
_9 "command": "ping 127.0.0.1 -n 3 > nul"
-
Add the following configurations to the launch.json file:
_35 "name": "app (C++) (lldb, launch with debugpy)",
_35 "request": "launch", // "launch" or "attach"
_35 "program": "${workspaceFolder}/bin/worker", // The executable path
_35 "cwd": "${workspaceFolder}/",
_35 "LD_LIBRARY_PATH": "${workspaceFolder}/ten_packages/system/xxx/lib", // linux
_35 "DYLD_LIBRARY_PATH": "${workspaceFolder}/ten_packages/system/xxx/lib", // macOS
_35 "TEN_ENABLE_PYTHON_DEBUG": "true",
_35 "TEN_PYTHON_DEBUG_PORT": "5678"
_35 "name": "app (C++) (debugpy, attach with delay)",
_35 "preLaunchTask": "delay 3 seconds"
_35 "name": "app (C++) (lldb, launch) and app (C++) (debugpy, attach)",
_35 "app (C++) (lldb, launch with debugpy)",
_35 "app (C++) (debugpy, attach with delay)"
-
Start debugging by selecting the compound configuration app (C++) (lldb, launch) and app (C++) (debugpy, attach).
When you write your application in Go, you can write extensions in either Go or Python.
Use the following configuration to debug your Go extensions:
_13 "name": "app (golang) (go, launch)",
_13 "cwd": "${workspaceFolder}/",
_13 "program": "${workspaceFolder}/bin/worker", // The executable path
_13 "LD_LIBRARY_PATH": "${workspaceFolder}/ten_packages/system/xxx/lib", // linux
_13 "DYLD_LIBRARY_PATH": "${workspaceFolder}/ten_packages/system/xxx/lib", // macOS
_13 "TEN_APP_BASE_DIR": "${workspaceFolder}"
Use the following configurations to debug C++ extensions in your Go application:
-
With lldb:
_12 "name": "app (Go) (lldb, launch)",
_12 "request": "launch", // "launch" or "attach"
_12 "program": "${workspaceFolder}/bin/worker", // The executable path
_12 "cwd": "${workspaceFolder}/",
_12 "LD_LIBRARY_PATH": "${workspaceFolder}/ten_packages/system/xxx/lib", // linux
_12 "DYLD_LIBRARY_PATH": "${workspaceFolder}/ten_packages/system/xxx/lib" // macOS
_12 "initCommands": ["process handle SIGURG --stop false --pass true"]
-
With gdb:
_20 "name": "app (Go) (gdb, launch)",
_20 "request": "launch", // "launch" or "attach"
_20 "program": "${workspaceFolder}/bin/worker", // The executable path
_20 "cwd": "${workspaceFolder}/",
_20 "name": "LD_LIBRARY_PATH",
_20 "value": "${workspaceFolder}/ten_packages/system/xxx/lib"
_20 "name": "DYLD_LIBRARY_PATH",
_20 "value": "${workspaceFolder}/ten_packages/system/xxx/lib"
For Python debugging setup, refer to the C++ applications section. Set the environment variables TEN_ENABLE_PYTHON_DEBUG and TEN_PYTHON_DEBUG_PORT before starting the application:
_1TEN_ENABLE_PYTHON_DEBUG=true TEN_PYTHON_DEBUG_PORT=5678 ./bin/worker
Attach the debugger to the running process using the following configuration:
_10 "name": "app (Go) (debugpy, attach)",
To debug C++, Go, and Python code simultaneously with one click in VS Code:
-
Define a delay task before attaching the debugger:
_9 "label": "delay 3 seconds",
_9 "command": "ping 127.0.0.1 -n 3 > nul"
-
Add the following configurations to the launch.json file:
_56 "name": "app (golang) (debugpy, remote attach with delay)",
_56 "preLaunchTask": "delay 3 seconds",
_56 "name": "app (golang) (go, launch with debugpy)",
_56 "cwd": "${workspaceFolder}/",
_56 "program": "${workspaceFolder}/bin/worker",
_56 "TEN_APP_BASE_DIR": "${workspaceFolder}",
_56 "TEN_ENABLE_PYTHON_DEBUG": "true",
_56 "TEN_PYTHON_DEBUG_PORT": "5678"
_56 "name": "app (golang) (lldb, launch with debugpy)",
_56 "program": "${workspaceFolder}/bin/worker",
_56 "cwd": "${workspaceFolder}/",
_56 "TEN_ENABLE_PYTHON_DEBUG": "true",
_56 "TEN_PYTHON_DEBUG_PORT": "5678"
_56 "process handle SIGURG --stop false --pass true"
_56 "name": "Mixed Go/Python",
_56 "app (golang) (go, launch with debugpy)",
_56 "app (golang) (debugpy, remote attach with delay)"
_56 "name": "Mixed Go/Python/C++ (lldb)",
_56 "app (golang) (lldb, launch with debugpy)",
_56 "app (golang) (debugpy, remote attach with delay)"
Use compound configurations:
- For C++ and Python debugging: Use
Mixed Go/Python/C++ (lldb). This supports breakpoint debugging for all three languages, but variable inspection only works for C++ and Python.
- For Go and Python debugging: Use
Mixed Go/Python. This supports both breakpoint debugging and variable inspection for Go and Python.
When you write your application in Python, you can write extensions in either Python or C++.
Use the following configuration to debug C++ extensions in your Python application:
_19 "name": "app (Python) (cpp, launch)",
_19 "request": "launch", // "launch" or "attach"
_19 "program": "/usr/bin/python3", // The Python interpreter path
_19 "cwd": "${workspaceFolder}/",
_19 "name": "PYTHONPATH",
_19 "value": "${workspaceFolder}/ten_packages/system/ten_runtime_python/lib:${workspaceFolder}/ten_packages/system/ten_runtime_python/interface"
_19 "name": "TEN_APP_BASE_DIR",
_19 "value": "${workspaceFolder}/"
_19 "MIMode": "gdb" // "gdb" or "lldb"
Use the following configuration to debug Python code directly:
_14 "name": "app (Python) (debugpy, launch)",
_14 "python": "/usr/bin/python3",
_14 "program": "${workspaceFolder}/main.py",
_14 "console": "integratedTerminal",
_14 "cwd": "${workspaceFolder}/",
_14 "PYTHONPATH": "${workspaceFolder}/ten_packages/system/ten_runtime_python/lib:${workspaceFolder}/ten_packages/system/ten_runtime_python/interface",
_14 "TEN_APP_BASE_DIR": "${workspaceFolder}/",
_14 "TEN_ENABLE_PYTHON_DEBUG": "true"
To debug both C++ and Python code simultaneously:
-
Launch the application with the app (Python) (debugpy, launch) configuration
-
Attach the C++ debugger to the running process using the following configuration:
_18 "name": "app (Python) (cpp, attach)",
_18 "request": "attach", // "launch" or "attach"
_18 "program": "${workspaceFolder}/bin/worker", // The executable path
_18 "cwd": "${workspaceFolder}/",
_18 "name": "LD_LIBRARY_PATH",
_18 "value": "${workspaceFolder}/ten_packages/system/xxx/lib"
_18 "name": "DYLD_LIBRARY_PATH",
_18 "value": "${workspaceFolder}/ten_packages/system/xxx/lib"