Debug applications
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.
Debug use cases
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.
Application development
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.
C++ applications
When you write your application in C++, you can write extensions in either C++ or Python.
Debug C++ code with lldb or gdb
Use the following configurations to debug C++ code:
-
With lldb:
-
With gdb:
Debug Python code with debugpy
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
andTEN_PYTHON_DEBUG_PORT
environment variables before starting the application:When you set
TEN_ENABLE_PYTHON_DEBUG
totrue
, the application blocks until a debugger is attached. When you setTEN_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:
Debug C++ and Python code simultaneously
To debug C++ and Python code simultaneously with one click in VS Code:
-
Define a delay task before attaching the debugger:
-
Add the following configurations to the
launch.json
file: -
Start debugging by selecting the compound configuration
app (C++) (lldb, launch) and app (C++) (debugpy, attach)
.
Go applications
When you write your application in Go, you can write extensions in either Go or Python.
Debug Go code with delve
Use the following configuration to debug your Go extensions:
Debug C++ extensions with lldb or gdb
Use the following configurations to debug C++ extensions in your Go application:
-
With lldb:
-
With gdb:
Debug Python code with debugpy
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:
Attach the debugger to the running process using the following configuration:
Debug multiple languages simultaneously
To debug C++, Go, and Python code simultaneously with one click in VS Code:
-
Define a delay task before attaching the debugger:
-
Add the following configurations to the
launch.json
file:
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.
Python applications
When you write your application in Python, you can write extensions in either Python or C++.
Debug C++ extensions with lldb or gdb
Use the following configuration to debug C++ extensions in your Python application:
Debug Python code with debugpy
Use the following configuration to debug Python code directly:
Debug C++ and Python code simultaneously
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: