I run TVHeadend on a Pi 4 running Ubuntu Server 22.04.1 arm 64-bit.
I want to use an IDE to edit, debug and compile TVHeadend source code on the Pi 4. But Ubuntu Server has no desktop environment.
Here is a solution where I run the IDE (Visual Studio Code) on a separate machine (Laptop) for remote development of TVHeadend source code on the Pi 4.
Target Audience is beginners/hobbyists with an interest in coding.
Instructions
Re-requisites
• A Pi 4 running Ubuntu Server 22.04.1 arm 64-bit.
• A second machine running Visual Studio Code (VSC)
Set up TVHeadend build environment on Pi 4
• Here is a tutorial on how to build TVHeadend on a Pi 4 using the TVHeadend Autobuild script
https://tvheadend.org/d/8188-tvheadend-build-and-install-on-pi-4-running-ubuntu-22-04-1-arm64
• If this is successful then you should have the TVHeadend sources in somewhere like: /home/ubuntu/buildir/tvheadend
• In ../buildir/tvheadend will also be the Makefile, configure script, the .config.mk file etc... needed to build TVHeadend.
• Successfully built TVHeadend binary will appear in ../buildir/tvheadend/build.linux
Install Visual Studio Code on another machine
• In my case I installed visual-studio-code-bin from “Add/Remove Software” in Manjaro but it could be installed on other Linux Distros, Windows or Mac.
• I installed these plugins: Remote-SSH plugin, C/C++ Extension Pack, C/C++ Themes, Remote Explorer, Remote - SSH: Editing Configuration Files, C/C++, CMake, CMake Tools, Makefile Tools
Configure Visual Studio Code to SSH to the Pi 4
• I followed these instructions
https://www.digitalocean.com/community/tutorials/how-to-use-visual-studio-code-for-remote-development-via-the-remote-ssh-plugin
• The link explains how to Configure the Remote-SSH Plugin to connect to the Pi 4 so you can navigate to the TVHeadend source code directory that is on the Pi 4 but from within VSC.
Tell VSC what compiler to use
• I confirmed the location of the binary of the cc compiler I am using on Ubuntu
ubuntu@ubuntu:~/buildir/tvheadend$ which cc
/usr/bin/cc
• Connect to the Pi from VSC using the SSH-Plugin.
• From VSC type... CTRL + Left SHIFT + P then type in “C/C++: Edit configurations (UI)”
• I filled in the details below...
• When you save this a file is created:
../buildir/tvheadend/.vscode/c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/cc",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-gcc-arm64",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
Tell VSC to build TVHeadend
• Click on the "Explorer" icon in the VSC left menu and in the “src” dir I clicked on “main.c”
• Type CTRL + Shift + P then type “Build” in to the search box then select Makefile: Build the current Target makefile.buildTarget
• This immediately starts building tvheadend.
Simplify the build process with VSC Tasks
• Visual Studio Code Tasks
https://code.visualstudio.com/docs/editor/tasks
• A "Task" simplifies the build process in VSC so for instance you can build tvheadend by selecting... File Menu > Terminal > Run Build Task (or Ctrl+Shift+B)
• After the above step when VSC builds TVHeadend it should automatically create a tasks.json file in...
• ../buildir/tvheadend/.vscode/tasks.json
• This is the contents of my tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "make",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
• The “isDefault”: true means that you can now get VSC to build tvheadend by selecting... File Menu > Terminal > Run Build Task (or Ctrl+Shift+B)
• "command": "make" basically means that this process causes VSC to execute the make command!
• To create a new task from scratch type: [Ctrl + Shift + p] then type “tasks” > select “Tasks: Configure Tasks” > Create Tasks.json file from template > Others
A compound task
• Visual Studio Code Compound Tasks
https://code.visualstudio.com/docs/editor/tasks#_compound-tasks
• This is not essential but basically a compound tasks automates execution of several steps that may need to occur prior to building TVHeadend for instance:
make distclean
./configure
make -j$(nproc)
• This is the tasks.json file to execute the above three steps one after another...
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run Make distclean command",
"type": "shell",
"command": "make distclean",
"problemMatcher": [],
"group": "build"
},
{
"label": "Run Config script",
"type": "shell",
"command": "./configure",
"args": [
"--enable-hdhomerun_client",
"--disable-hdhomerun_static",
"--disable-dvbscan",
"--enable-libav",
"--disable-ffmpeg_static",
"--enable-libx264",
"--disable-libx264_static",
"--enable-libx265",
"--disable-libx265_static",
"--enable-libvpx",
"--disable-libvpx_static",
"--enable-libtheora",
"--disable-libtheora_static",
"--enable-libvorbis",
"--disable-libvorbis_static",
"--enable-libfdkaac",
"--disable-libfdkaac_static",
"--enable-libopus",
"--disable-libopus_static",
"--enable-vaapi",
"--enable-omx",
"--enable-dvbcsa",
"--enable-dvben50221",
"--enable-libsystemd_daemon",
"--enable-pcre2",
"--enable-pngquant",
"--python=/usr/bin/python3"
],
"problemMatcher": [],
"group": "build"
},
{
"label": "Run Make command",
"type": "shell",
"command": "make",
"args": [
"-j$(nproc)"
],
"problemMatcher": [],
"group": "build"
},
{
"label": "Build TVH",
"dependsOrder": "sequence",
"dependsOn": [
"Run Make distclean command",
"Run Config script",
"Run Make command"
],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
• To make this Task the Default Build Task...
• File Menu > Terminal > Configure Default Build Task > Then choose the task with the label: “Build TVH”.
• To run this task... Ctrl + Shift + P > tasks: Run Task > Select the task label: “Build TVH”.
• Or simply Ctrl +Shift + B
Debugging TVHeadend from Visual Studio Code
• Remote Debugging with gdb in Visual Studio Code
https://code.visualstudio.com/docs/editor/debugging
• Install gdb in Ubuntu, check if it is installed already, if not then install it...
which gdb
sudo apt update
sudo apt install gdb
• In VSC click the Debugger icon on the left most menu (fourth one down, looks a bit like a Play icon) OR by typing Ctrl + Shift + D.
• I got to a window where I clicked on “Create a launch.json file".
• Here I chose: node.js debugger. That created the file: launch.json in
../buildir/tvheadend/.vscode/launch.json
{
// 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": [
{
// for Linux
"name": "(gdb) Launch TVH",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/build.linux/tvheadend",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/build.linux",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "Build TVH",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
• A key point is that it must have the line: "preLaunchTask": "Build TVH",
• This makes it refer back to the Task you use to build TVHeadend using the correct label of that task: “Build TVH”.
• To test the remote debugging...
• Go to main.c in the “src” dir of tvheadend in VSC, find a line of code anywhere in the "main" method and make a breakpoint by clicking on a faint RED DOT to the left of the line number.
• Click on the Run Menu > Start Debugging in VSC.
• After recompiling the code (the preLaunchTask in launch.json refers back to the name of the build task in tasks.json), Tvheadend is launched and execution stops at that breakpoint.
• Now you can do things like variable inspection.
In Conclusion
• Many thanks to @Adrian Smith for this idea and explanations!
• I hope this helps someone and saves them time.
• Comments, feedback or corrections very welcome.
Useful Links
• Remote Development with Visual Studio Code
https://code.visualstudio.com/docs/remote/remote-overview
• More on Remote Development with Visual Studio Code
https://www.digitalocean.com/community/tutorials/how-to-use-visual-studio-code-for-remote-development-via-the-remote-ssh-plugin
• Compile and test tvheadend from an IDE?
https://tvheadend.org/d/8160-need-help-compile-and-test-tvheadend-from-an-ide