< Plasma
Revision as of 19:01, 28 September 2020 by Thiagosueto (talk | contribs) (Small fixes and add attach/automate)


Plasmashell debugging

This guide serves as a collection of useful resources for debugging plasmashell. As plasmashell controls essentially all widgets on your desktop, a faulty widget might be hard to spot at first sight. Likewise, any official widget issues should be reported to bugs.kde.org under the plasmashell product.

Check widgets dynamically

This procedure is useful for checking for memory leaks.

  • Open Konsole and press Meta+Right to tile it to the right.
  • Run journalctl /usr/bin/plasmashell and check whether any warnings or errors are present.
  • If there are, run journalctl /usr/bin/plasmashell -f 2> plasmashell.log to check logs in real time and paste it automatically into a log.
  • Open the default process manager based on KSysGuard by pressing Ctrl+Esc, then press Meta+Left to tile it to the left. Write plasmashell to filter it for easier visualization, or just select it. Take note of memory usage.
  • Click each individual widget on the panel and check if any warnings appear on Konsole as well as whether there is any change in memory usage on the process manager. If after closing a widget memory usage comes back to normal, it's fine. If this does not occur, this might indicate a memory leak, so check if it occurs repeatedly.
  • You should now have a file named plasmashell.log on your home folder that you may send to the devs together with your bug report over bugs.kde.org.

Simply opening a widget may not cause an increase in memory. If you want to verify this more thoroughly, click each individual action in that widget, or check each widget individually as shown in the next section.

You may also want to use this after you've determined a way to reproduce a crash in plasmashell caused by a widget. If so, run some debug tool such as gdb, valgrind, or strace.

Check widgets individually

  • Open Konsole
  • If the widget you want to check is system-wide, list all available system widgets with ls /usr/share/plasma/plasmoids/, then locate the widget you want to check.
  • If the widget you want to check was installed by you/is made by a third-party, list all available user widgets with ls .local/share/plasma/plasmoids/, then locate the widget you want to check. Remember that if an issue is found with a third-party widget, it should be reported to the original developer, not to the KDE developers.
  • You can use plasmawindowed (available by default on Plasma) or plasmoidviewer (made available in plasma-sdk) to run a widget individually. plasmawindowed runs the widget separately but as if running natively, plasmoidviewer is more developer-oriented and allows you to set positions and whatnot. For general debugging, plasmawindowed should suffice.
  • Run a debug tool such as gdb like so: gdb plasmawindowed

If any debug symbols are missing, gdb will tell you. Depending on your package manager it might even tell you what command to run in order to fetch the required debug symbols, in which case you should install such packages before continuing. Follow the instructions provided by your distribution for that.

  • Inside gdb, execute the command set logging on before anything else so a file named gdb.txt is created. Optionally, you may want to set logging file filename.txt before it to have a special filename for your log.
  • Then execute run org.kde.plasma.plasmoidname, utilizing the correct widget name you saw in the plasma/plasmoids folder. The widget should now run standalone with a few window controls (minimize, maximize, close) on top.

The run command inside gdb executes the application, and anything coming after run should be its arguments or options. Thus, it works analogously to plasmawindowed org.kde.plasma.plasmoidname, except gdb will log everything or most things you need.

  • Test as much as you want, then close the widget by clicking the close button.
  • Back to gdb, run bt to create the backtrace. If you want to be extra thorough with your backtrace, you might want to run bt full instead for more verbose output.
  • Finish by running quit.
  • You should now have a file named gdb.txt on your home folder that you may send to the devs together with your bug report over bugs.kde.org.

Attach gdb to the plasmashell process

It is possible to attach gdb to a running process, in this case plasmashell. With this, you should have a crash log and backtrace even if your system completely freezes somehow.

To do this, gdb will need to know the PID of the plasmashell process. It is possible to do so manually with ps -aux | grep plasmashell, say, 2000, and then running gdb plasmashell 2000, or perhaps gdb -p 2000, but for efficiency you may just gdb -p $(pidof plasmashell) (This will fetch the PID of plasmashell for you automatically and it should run fine in bash, sh, ksh and zsh, in fish you'd use gdb -p (pidof plasmashell) instead).

After that, it's mostly the same process described above. When gdb is attached to an application, the application is "stopped" temporarily while gdb waits for input. Run set logging file plasmashell.txt, then set logging on, then run continue; this should make plasmashell continue running as usual. Wait for the crash to happen, then return to gdb and type bt to generate a backtrace. Lastly, run quit to exit gdb.

Automate generation of backtraces with batch

gdb provides an easy way to automate debugging: the -batch flag. After enabling it, you should be able to run commands sequentially with -ex or --eval-command. If you don't want to see any output on your terminal, you might want to use -batch-silent instead. Let's see four examples of this:

  • Run application and provide general backtrace: gdb dolphin -batch -ex "set logging file dolphin.txt" -ex "set logging on" -ex "run" -ex "bt" -ex "quit"
  • Attach to application and provide general backtrace: gdb -pid $(pidof plasmashell) -batch -ex "set logging file dolphin.txt" -ex "set logging on" -ex "continue" -ex "bt" -ex "quit"
  • Run application and be extra verbose: gdb dolphin -batch -ex "set logging file dolphin.txt" -ex "set logging on" -ex "run" -ex "bt full" -ex "quit"
  • Attach to application and be extra quiet: gdb --silent -pid $(pidof plasmashell) -batch-silent -ex "set logging file dolphin.txt" -ex "set logging on" -ex "continue" -ex "bt" -ex "quit"

This page was last edited on 27 January 2021, at 22:00. Content is available under Creative Commons License SA 4.0 unless otherwise noted.