Tutorial: Debugging (kdenlive KF5 On Arch Linux)

Hey guys,

I've been using kdenlive the KDE Non-LInear Video Editor for editing videos for my uni's alumni club for a while and quite like this programme. With KDE Plasma 5, the new desktop and toolkit version on the horizon, the kdenlive developers are porting their programme to a new base.

After very interesting sessions helping the kdenlive developers with their port to KDE frameworks 5 I thought I'd share my experiences with you here.

I have no technical background so this was a very interesting adventure for me and I hope I can help any non-programmer here to help our coding friends with bug squashing.

I'm running Antergos / Arch Linux so I'll explain how to do it on this Distro but everyone is welcome and encouraged to share a tutorial for their Distro of choice here.

 

1. Getting everything in place for debugging

To get started you basically need gdb and yaourt the GNU DeBugger. Install them either via the GUI of your choice or by using the sudo pacman -S gdb yaourt in console.

2. Edit /etc/makepkg.conf for maximum performance and to not strip out the debugging symbols

Arch uses the AUR (Arch User Repository) as their equivalent to PPAs (Private Package Archives) on Ubuntu. The main difference is, that the packages are compiled locally and not on a remote server so you can/should/must tune the build environment yourself. This is done by editing the options in the makepkg.conf text file. 

To do that open /etc/makepkg.conf in your favourite text editor with root (admin) privileges and edit the following lines:

#-- Make Flags: change this for DistCC/SMP systems
MAKEFLAGS="-j6"

Tells the compiler how many threads it should be using. I'm on an AMD X6 so I tell it to use all 6 threads. This speeds up the build process extremely.

The second important step is to tell makepkg to leave the debugging symbols in so you can get a backtrace of the bug in the first place. Arch builds it's packages without debugging symbols by default so you have to compile every software you want to debug manually. This is not a huge problem in this case as we're using the development branch of kdenlive so there are no stable builds anyway.

OPTIONS=(docs !libtool !staticlibs emptydirs zipman purge !upx !debug)

#-- File integrity checks to use. Valid: md5, sha1, sha256, sha384, sha512
INTEGRITY_CHECK=(md5)
#-- Options to be used when stripping binaries. See `man strip' for details.</strong><br /><strong>#STRIP_BINARIES="--strip-all"</strong><br /><strong>#-- Options to be used when stripping shared libraries. See`man strip' for details.
#STRIP_SHARED="--strip-unneeded"
#-- Options to be used when stripping static libraries. See `man strip' for details.
#STRIP_STATIC="--strip-debug"
#-- Manual (man and info) directories to compress (if zipman is specified)
MAN_DIRS=({usr{,/local}{,/share},opt/*}/{man,info})
#-- Doc directories to remove (if !docs is specified)
DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc})
#-- Files to be removed from all packages (if purge is specified)
PURGE_TARGETS=(usr/{,share}/info/dir .packlist *.pod)

Delete the "strip" from OPTIONS=() and uncomment (place #) in front of lines that refer to "strip" or copy my stuff from above.

 (Every "#" should be in it's own line the formatting in the forum is not ideal for this)

 

3. Getting the latest code

MLT - The Media Lovin Toolkit kdenlive is based on

  1. Open a terminal and type yaourt mlt-qt5-git 
  2. If it asks you to edit the Packagebuild say yes and open it with the text editor of your choice say kate.
  3. Replace the lines  --enable-glp \  and   --enable-glp3 \ with  --enable-gpl \ and --enable-gpl3 \  Otherwise it won't work properly
  4. Save and exit. Don't edit packagebuild anymore, don't edit install, continue with package creation
  5. When it ask you install it by entering your password.

 

 Kdenlive

  1. Open a terminal and type yaourt kdenlive-frameworks-git
  2. If it asks you to edit the Packagebuild say yes and open it with the text editor of your choice say kate.
  3. Replace the line -DCMAKE_BUILD_TYPE=Release with -DCMAKE_BUILD_TYPE=Debug
  4. Save and exit. Don't edit packagebuild anymore, don't edit install, continue with package creation 
  5. When it ask you install it by entering your password.


4. Actually debug something

If you encounter a crash it's best if you're able to enclude a so called backtrace so the developer can tell where exactly the hiccup occured.

To do that

  1. Open a terminal and launch gdb by typing
  2. gdb kdenlive
  3. If your system language is not English (like in my case) use LANG=C gdb kdenlive to get an English output.
  4. If you did everything right up to Step 3 gsb should say "Reading symbols from kdenlive...done."
  5. If it doesn't you have to check steps 1-3 again and look for mistakes.
  6. Enter (gdb) set logging file kdenlive-trace.log
  7. Enter (gdb) set logging on
  8. Now the debug output is saved to kdenlive-trace.log in the directory you're currently in.
  9. Enter (gdb) runto actually start the programme
  10. When kdenlive crashes there should be a message like "Program received signal SIGABRT, Aborted.
    0x00007ffff18e5a97 in raise () from /usr/lib/libc.so.6" or "Program received signal SIGSEGV, Segmentation fault.
    0x00007fffedbc1824 in pthread_mutex_lock () from /usr/lib/libpthread.so.0"
  11. DON'T CLOSE THE WINDOW OR KILL THE APP NOW
  12. Go back to your terminal running gdb and
  13. Enter (gdb) thread apply all bt full to start the backtrace
  14. Hit return as many times as requested until your back at the (gdb) promt
  15. Now enter quit and you've successfully created your first backtrace.
  16. File a bug report against the programme using the projects bugtracker in this case https://bugs.kde.org/
  17. Upload the backtrace as part of your report and await instructions from the developers.
  18. If they ask you to test if the latest code fixed your problem repeat step 3 for kdenlive and report back to them.

Here are two examples: 

KF5 - Segfault when changing project preferences after project creation

https://bugs.kde.org/show_bug.cgi?id=343639

KF5 port crashes on import of a slideshow clip

https://bugs.kde.org/show_bug.cgi?id=343326

 

I hope this helps new users and also helps the kdenlive guys get more bugs reported. The awesome thing about opensource is that I don't have to wait for a release for months. Jean-Baptiste Mardelle kdenlive's lead developer had a fix out for one of my issues in as fast as 17 minutes.

 

Cheers!