If you're going to be regularly trying development versions of Tvheadend or need to report a crash or deadlock then you should really read this page!

If you are investigating problems within Tvheadend then its worth being familiar with tools such as gdb and valgrind or clang, although these are not covered here.

However one thing that can be useful in investigating crashes within Tvheadend is to ensure that coredumps are generated, this will allow post analysis in gdb without having to actual run Tvheadend within gdb.

You can enable temporarily by running:

ulimit -c unlimited

To make this permanent put this somewhere in your shell environment setup (.bashrc, .profile, etc...)Firstly I'd recommend that if you're specifically trying to investigate an issue then you should consider running Tvheadend manually, rather than as a service, as documented here.

If you need to investigate some running problem you can always attach (see below) later and if you need to trap crashes, then you can configure your system to generate a core file and then retrospectively analyse this with gdb.

If you're running manually you should enable coredumps in your environment:

If you're running as a daemon then you should use the -D command line option, this will enable coredumps from the daemon. If you start using sysvinit, upstart etc... then you will need to put this in the configuration file, e.g.:

TVH_ARGS="-D"

Finally it's probably worth changing the coredump file format, personally I use the following configuration:

If you're using a system like Ubuntu that uses apport (and cripples the ability to change the core format) just set core_uses_pid=1 instead.

Note: coredumps are (by default) stored in the current working directory, to make it possible for the daemon to write files the current working directory is set to /tmp when using -D, so check there for core files.

To verify that you have everything configured properly you can use the -A option to force a crash on startup. Do this from the command line or add to /etc/default/tvheadend:

If Tvheadend appears to die but the process is still running, then its quite possible that the process is deadlocked (or possibly live locked). The best way to help investigate such a problem is to get a full stack trace from every thread in the system.

First attach gdb to the running process:

gdb tvheadend pid
(gdb) continue

You may need to replace tvheadend with the full path to the binary and you will need to replace pid with the PID of the running process. To find that run:

ps -C tvheadend

Once you have gdb attached grab a stack trace from every thread using the following command:

(gdb) set logging on
(gdb) set pagination off
(gdb) thread apply all bt full

Note: "set logging on" will cause GDB to write its output to a file, by default this will be gdb.txt in the current directory.

It might also be useful to generate a core file for good measure:

(gdb) generate-core-file

This information may give an indication as to why things are locked, often 2 threads are stuck trying to lock a mutex (probably each holds the opposite lock).

If you're going to report a crash (or lockup) then please try to provide the above information, including a debug log (or whatever logging you have), a core file and the tvheadend binary and basic information about the platform (distribution, version and architecture) you're running on.