If you're using VS Code to develop the TEN framework, there is a launch.json file in the TEN framework source tree that provides default debug targets.
For Users of the TEN Framework
If you're using VS Code to develop your own application based on the TEN framework, you can add configurations to your .vscode/launch.json file so that you can debug your application with breakpoints and variable inspection whichever programming language (C++/Golang/Python) you are using.
Debugging in C++ Applications
If the application is written in C++, it means the extensions can be written in C++ or Python.
Debugging C++ code with lldb or gdb
You can use the following configurations to debug C++ code:
Debugging C++ code with lldb
{"name":"app (C++) (lldb, launch)","type":"lldb","request":"launch",// "launch" or "attach""program":"${workspaceFolder}/bin/worker",// The executable path"cwd":"${workspaceFolder}/","env": {"LD_LIBRARY_PATH":"${workspaceFolder}/ten_packages/system/xxx/lib",// linux"DYLD_LIBRARY_PATH":"${workspaceFolder}/ten_packages/system/xxx/lib"// macOS }}
Debugging C++ code with gdb
{"name":"app (C++) (gdb, launch)","type":"cppdbg","request":"launch",// "launch" or "attach""program":"${workspaceFolder}/bin/worker",// The executable path"cwd":"${workspaceFolder}/","MIMode":"gdb","environment": [ {// linux"name":"LD_LIBRARY_PATH","value":"${workspaceFolder}/ten_packages/system/xxx/lib" }, {// macOS"name":"DYLD_LIBRARY_PATH","value":"${workspaceFolder}/ten_packages/system/xxx/lib" } ]}
Debugging Python code with debugpy
You can use debugpy to debug Python code. However, since the program is not started directly through the Python interpreter, the Python code is executed by the embedded Python interpreter. Therefore, you can only attach a debugger to a running process.
First, you need to install debugpy in the Python environment:
pipinstalldebugpy
Then, you need to start the application with environment variable TEN_ENABLE_PYTHON_DEBUG and TEN_PYTHON_DEBUG_PORT set. For example:
If the environment variable TEN_ENABLE_PYTHON_DEBUG is set to true, then the application will block until the debugger is attached. If the environment variable TEN_PYTHON_DEBUG_PORT is set, then the debugger server will listen on the specified port for incoming connections.
Then, you can attach the debugger to the running process. Here is an example of the configuration:
{"name":"app (Go) (gdb, launch)","type":"cppdbg","request":"launch",// "launch" or "attach""program":"${workspaceFolder}/bin/worker",// The executable path"cwd":"${workspaceFolder}/","MIMode":"gdb","environment": [ {// linux"name":"LD_LIBRARY_PATH","value":"${workspaceFolder}/ten_packages/system/xxx/lib" }, {// macOS"name":"DYLD_LIBRARY_PATH","value":"${workspaceFolder}/ten_packages/system/xxx/lib" } ]}
Debugging Python code with debugpy
Refer to the section above for debugging Python code with debugpy. Start the application with environment variable TEN_ENABLE_PYTHON_DEBUG and TEN_PYTHON_DEBUG_PORT set.
If you want to debug C++ and Python code at the same time, you can use the compound configuration Mixed Go/Python/C++ (lldb). With this configuration, you can perform breakpoint debugging for C++, Go and Python code simultaneously. However, the variable inspection is only supported for C++ and Python but not for Go code.
If you want to debug Go and Python code at the same time, you can use the compound configuration Mixed Go/Python. With this configuration, you can perform breakpoint debugging for Go and Python code simultaneously and inspect variables for both Go and Python code.
Debugging in Python applications
If the application is written in Python, it means the extensions can be written in Python or C++.
Debugging C++ code with lldb or gdb
You can use the following configurations to debug C++ code:
{"name":"app (Python) (cpp, launch)","type":"cppdbg",//"request":"launch",// "launch" or "attach""program":"/usr/bin/python3",// The Python interpreter path"args": ["main.py" ],"cwd":"${workspaceFolder}/","environment": [ {"name":"PYTHONPATH", "value": "${workspaceFolder}/ten_packages/system/ten_runtime_python/lib:${workspaceFolder}/ten_packages/system/ten_runtime_python/interface"
}, {"name":"TEN_APP_BASE_DIR","value":"${workspaceFolder}/" }, ],"MIMode":"gdb",// "gdb" or "lldb"}
Debugging Python code with debugpy
Refer to the section above for debugging Python code with debugpy. You can use the following configurations to debug Python code:
If you want to start debugging C++ and Python code at the same time, you can launch the application with the configuration app (Python) (debugpy, launch) and attach the debugger to the running process with the following configuration:
{"name":"app (Python) (cpp, attach)","type":"cppdbg","request":"attach",// "launch" or "attach""program":"${workspaceFolder}/bin/worker",// The executable path"cwd":"${workspaceFolder}/","MIMode":"gdb","environment": [ {"name":"LD_LIBRARY_PATH","value":"${workspaceFolder}/ten_packages/system/xxx/lib" }, {"name":"DYLD_LIBRARY_PATH","value":"${workspaceFolder}/ten_packages/system/xxx/lib" } ]}