KWin/Debugging: Difference between revisions

From KDE Community Wiki
(Add kwin diagnosis dbus info and QT_LOGGING_RULES info)
(Major overhaul)
Line 1: Line 1:
= Debug & log KWin (or any process) via gdb =
{{Construction}}
While interacting with gdb, the debugged process is stopped - that's of course nasty if the debugged process is what paints what you see. Therefore it's inevitable to debug KWin from a side-channel, eg. '''another VT''' or '''via ssh''' - depending on what's available on your system.


'''NOTICE''' that debugging from a ssh login is generally preferable, since it doesn't impact the framebuffer/scanout buffer state.
= Getting diagnosis information for bug reports =


== gdb says "ptrace: Operation not permitted." ==
If you want to fetch relevant information to report a bug with KWin, the following command will provide a general list of data which should help the KWin developers diagnose your problem.
This is a security feature in "newer" linux kernels - you must explicitly allow gdb to attach to a non-inferior process:


{{Input|1=<nowiki>echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope</nowiki>}}
{{Input|1=<nowiki>
qdbus org.kde.KWin /KWin supportInformation
</nowiki>}}
 
Depending on your distro (e.g. openSUSE), by default the command might be named a bit differently:
 
{{Input|1=<nowiki>
qdbus-qt5 org.kde.KWin /KWin supportInformation
</nowiki>}}
 
= Report issues via DrKonqi =
 
Generally speaking, Plasmashell handles all widgets (including the menu), KWin handles windows and compositing (such as window decorations and desktop effects), and KGlobalAccel5 handles keyboard shortcuts.
 
In a situation where the Plasmashell and KGlobalAccel5 processes are still running but KWin has crashed, you will probably see a sad face in your notification tray, that's DrKonqi, the KDE Crash Handler, getting sad that you experienced a crash. Click its icon and you should be able to follow through with the crash reporting process in a straightforward manner.
 
In a situation where KGlobalAccel5 is still running but both Plasmashell and KWin are running, you can still invoke any keyboard shortcut to run a program that allows you to run a command, such as KRunner, Konsole or Yakuake. With that, you can restart the plasmashell process with:
 
{{Input|1=<nowiki>
plasmashell --replace
</nowiki>}}
 
Or if you have manually enabled the new systemd initialization:
 
{{Input|1=<nowiki>
systemctl --user restart plasma-plasmashell
</nowiki>}}
 
And you might get a DrKonqi icon on your panel mentioning the KWin crash.
 
In case you were unable to create a backtrace using the KDE Crash Handler, proceed to the section [[KWin/Debugging#Debug KWin with GDB]].
 
== Install debug symbols ==
 
TODO
 
= Debug KWin with GDB =
 
== TL;DR for bug reporters ==
 
For ease of reference, users wanting to report a KWin crash can just copy-paste the following two commands, wait for the crash to happen and ignore the rest of this page. You'll get a file named kwin.gdb in your home folder (or wherever folder you run this command).
 
{{Input|1=<nowiki>
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
gdb -pid $(pidof kwin_x11) -batch -ex "set logging file kwin.gdb" -ex "set logging on" -ex "continue" -ex "thread apply all backtrace" -ex "quit"
</nowiki>}}
 
If you want to know what these commands do (recommended), keep reading.
 
== General information ==
 
While interacting with GDB, the debugged process is stopped - that's of course nasty if the debugged process is what paints what you see. Therefore it's inevitable to debug KWin from a side-channel, eg. '''another VT''' or '''via SSH''' - depending on what's available on your system.
 
'''NOTICE''' that debugging from an SSH login is generally preferable, since it doesn't impact the framebuffer/scanout buffer state.
 
== GDB says "ptrace: Operation not permitted." ==
 
This is probably the first thing you'll need to circumvent. By default, you're not allowed to attach GDB to KWin.
 
This is a security feature in "newer" Linux kernels, you'll need to explicitly allow GDB to attach to a non-inferior process:
 
{{Input|1=<nowiki>
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
</nowiki>}}


== Do I have to write down the debug output by hand ???? ==
== Do I have to write down the debug output by hand ???? ==
Line 14: Line 75:


You just copy the gdb output into a file.
You just copy the gdb output into a file.
{{Input|1=<nowiki>gdb --pid `pidof kwin_x11` 2>&1 | tee kwin.gdb</nowiki>}}
{{Input|1=<nowiki>
gdb --pid `pidof kwin_x11` 2>&1 | tee kwin.gdb
</nowiki>}}
 
Alternatively, you can use the lengthier method made available by GDB.
 
{{Input|1=<nowiki>
gdb --pid `pidof kwin_x11`
set logging file kwin.gdb
set logging on
</nowiki>}}
 
== I don't know nothing about GDB, how do I obtain a stacktrace? ==
 
A stacktrace (or backtrace) is a set of data containing information of the state the program was when it crashed. It is the primary means for the KWin developers to find out what happened on your machine.
 
Nowadays it's common for programs to take advantage of multiple threads to run more efficiently and make better use of the CPU cores available on your machine. Different threads might run different parts of a program, and each thread can render a different stacktrace.


== I don't know nothing about gdb, how do I obtain a stacktrace? ==
So after attaching GDB to the application process, you'll see the GDB shell. It's where you'll run instructions so GDB can fetch the information you want.
After attaching to the process, you likely want to cause a certain condition (halt or crash) - in that case you first need to
{{Input|1=<nowiki>continue</nowiki>}}
the process.


If kwin does not crash, but you want to inspect the stack at some other time, you firt need to interrupt the process, press
Immediately after attaching GDB, it will stop the process, but you'll likely want to cause a certain condition (halt or crash) while KWin is running - in that case you first need to
{{Input|1=<nowiki>
continue
</nowiki>}}
the process before it can be crashed.
 
If KWin does not crash, but you want to inspect the stack at some other time, you'll first need to interrupt the process by pressing
{{Input|1='''Ctrl+C'''}}
{{Input|1='''Ctrl+C'''}}


To dump a stacktrace, issue
To dump a stacktrace, issue
{{Input|1=<nowiki>bt</nowiki>}}
{{Input|1=<nowiki>
bt
</nowiki>}}
 
With this command you will get the stacktrace for the main thread where KWin crashed.


then hit the
Then, hit the
{{Input|1='''Enter'''}}
{{Input|1='''Enter'''}}
key until you reach the end of the stack.
key until you reach the end of the stack.
Line 39: Line 123:
</nowiki>}}
</nowiki>}}


Finally, to leave gdb
Alternatively, to dump a stacktrace the same way DrKonqi does (i.e. showing all available threads), use
thread 2
 
{{Input|1=<nowiki>
thread apply all backtrace
</nowiki>}}
 
This is probably the best method if you want to provide some awesome stacktraces for the KWin devs!
 
Finally, to leave GDB:
 
{{Input|1=<nowiki>
{{Input|1=<nowiki>
detach
detach
quit</nowiki>}}
quit
</nowiki>}}
 
== Automating the creation of backtraces ==
 
GDB provides an easy way to automate debugging: the <code>-batch</code> flag. After enabling it, you should be able to run commands sequentially with <code>-ex</code> or <code>--eval-command</code>. A more detailed explanation of the procedure can be seen in [[Plasma/Debugging]].


= Getting diagnosis information =
{{Input|1=<nowiki>
gdb -pid $(pidof kwin_x11) -batch -ex "set logging file kwin.gdb" -ex "set logging on" -ex "continue" -ex "thread apply all backtrace" -ex "quit"
</nowiki>}}


The following command retrieves internal diagnosis from a running KWin instance :
= Debug KWin with Valgrind =
{{Input|1=<nowiki>qdbus org.kde.KWin /KWin supportInformation</nowiki>}}
 
TODO
 
= Automatically fetch core dumps with coredumpctl =
 
TODO edit /etc/systemd/coredump.conf
 
However, kwin_wayland crashes might be a bit trickier to debug. Because KWin plays the traditional role of what is known as Display Server (in X11 lingo) in a Wayland session, whenever it crashes, you get thrown off to the login screen. Therefore, it's advisable to use a different TTY or SSH and attach GDB directly instead of using coredumpctl (as systemd-coredump might not be able to fetch the stacktrace and it might get truncated).


= Getting debug log output =
= Getting debug log output =


The environment variable QT_LOGGING_RULES can be used to turn on full debug output from kwin :
The environment variable QT_LOGGING_RULES can be used to turn on full debug output from KWin:
{{Input|1=<nowiki>export QT_LOGGING_RULES="kwin_*.debug=true"</nowiki>}}
{{Input|1=<nowiki>
export QT_LOGGING_RULES="kwin_*.debug=true"
</nowiki>}}


The logs in X are at {{Input|1=<nowiki>~/.xsession-errors</nowiki>}}
The logs in X are at {{Input|1=<nowiki>~/.xsession-errors</nowiki>}}
The logs in Wayland are in {{Input|1=<nowiki>~/.local/share/sddm/wayland-session.log</nowiki>}}
The logs in Wayland are in {{Input|1=<nowiki>~/.local/share/sddm/wayland-session.log</nowiki>}}
TODO KDE_DEBUG=1 to disable DrKonqi

Revision as of 07:40, 16 November 2020

 
Under Construction
This is a new page, currently under construction!


Getting diagnosis information for bug reports

If you want to fetch relevant information to report a bug with KWin, the following command will provide a general list of data which should help the KWin developers diagnose your problem.

qdbus org.kde.KWin /KWin supportInformation

Depending on your distro (e.g. openSUSE), by default the command might be named a bit differently:

qdbus-qt5 org.kde.KWin /KWin supportInformation

Report issues via DrKonqi

Generally speaking, Plasmashell handles all widgets (including the menu), KWin handles windows and compositing (such as window decorations and desktop effects), and KGlobalAccel5 handles keyboard shortcuts.

In a situation where the Plasmashell and KGlobalAccel5 processes are still running but KWin has crashed, you will probably see a sad face in your notification tray, that's DrKonqi, the KDE Crash Handler, getting sad that you experienced a crash. Click its icon and you should be able to follow through with the crash reporting process in a straightforward manner.

In a situation where KGlobalAccel5 is still running but both Plasmashell and KWin are running, you can still invoke any keyboard shortcut to run a program that allows you to run a command, such as KRunner, Konsole or Yakuake. With that, you can restart the plasmashell process with:

plasmashell --replace

Or if you have manually enabled the new systemd initialization:

systemctl --user restart plasma-plasmashell

And you might get a DrKonqi icon on your panel mentioning the KWin crash.

In case you were unable to create a backtrace using the KDE Crash Handler, proceed to the section KWin/Debugging#Debug KWin with GDB.

Install debug symbols

TODO

Debug KWin with GDB

TL;DR for bug reporters

For ease of reference, users wanting to report a KWin crash can just copy-paste the following two commands, wait for the crash to happen and ignore the rest of this page. You'll get a file named kwin.gdb in your home folder (or wherever folder you run this command).

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
gdb -pid $(pidof kwin_x11) -batch -ex "set logging file kwin.gdb" -ex "set logging on" -ex "continue" -ex "thread apply all backtrace" -ex "quit"

If you want to know what these commands do (recommended), keep reading.

General information

While interacting with GDB, the debugged process is stopped - that's of course nasty if the debugged process is what paints what you see. Therefore it's inevitable to debug KWin from a side-channel, eg. another VT or via SSH - depending on what's available on your system.

NOTICE that debugging from an SSH login is generally preferable, since it doesn't impact the framebuffer/scanout buffer state.

GDB says "ptrace: Operation not permitted."

This is probably the first thing you'll need to circumvent. By default, you're not allowed to attach GDB to KWin.

This is a security feature in "newer" Linux kernels, you'll need to explicitly allow GDB to attach to a non-inferior process:

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

Do I have to write down the debug output by hand ????

No ;-)

You just copy the gdb output into a file.

gdb --pid `pidof kwin_x11` 2>&1 | tee kwin.gdb

Alternatively, you can use the lengthier method made available by GDB.

gdb --pid `pidof kwin_x11`
set logging file kwin.gdb
set logging on

I don't know nothing about GDB, how do I obtain a stacktrace?

A stacktrace (or backtrace) is a set of data containing information of the state the program was when it crashed. It is the primary means for the KWin developers to find out what happened on your machine.

Nowadays it's common for programs to take advantage of multiple threads to run more efficiently and make better use of the CPU cores available on your machine. Different threads might run different parts of a program, and each thread can render a different stacktrace.

So after attaching GDB to the application process, you'll see the GDB shell. It's where you'll run instructions so GDB can fetch the information you want.

Immediately after attaching GDB, it will stop the process, but you'll likely want to cause a certain condition (halt or crash) while KWin is running - in that case you first need to

continue

the process before it can be crashed.

If KWin does not crash, but you want to inspect the stack at some other time, you'll first need to interrupt the process by pressing

Ctrl+C

To dump a stacktrace, issue

bt

With this command you will get the stacktrace for the main thread where KWin crashed.

Then, hit the

Enter

key until you reach the end of the stack.

Sometimes, you may want to see what's in another thread

thread 2
bt
thread 3
bt

Alternatively, to dump a stacktrace the same way DrKonqi does (i.e. showing all available threads), use

thread apply all backtrace

This is probably the best method if you want to provide some awesome stacktraces for the KWin devs!

Finally, to leave GDB:

detach
quit

Automating the creation of backtraces

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. A more detailed explanation of the procedure can be seen in Plasma/Debugging.

gdb -pid $(pidof kwin_x11) -batch -ex "set logging file kwin.gdb" -ex "set logging on" -ex "continue" -ex "thread apply all backtrace" -ex "quit"

Debug KWin with Valgrind

TODO

Automatically fetch core dumps with coredumpctl

TODO edit /etc/systemd/coredump.conf

However, kwin_wayland crashes might be a bit trickier to debug. Because KWin plays the traditional role of what is known as Display Server (in X11 lingo) in a Wayland session, whenever it crashes, you get thrown off to the login screen. Therefore, it's advisable to use a different TTY or SSH and attach GDB directly instead of using coredumpctl (as systemd-coredump might not be able to fetch the stacktrace and it might get truncated).

Getting debug log output

The environment variable QT_LOGGING_RULES can be used to turn on full debug output from KWin:

export QT_LOGGING_RULES="kwin_*.debug=true"

The logs in X are at

~/.xsession-errors

The logs in Wayland are in

~/.local/share/sddm/wayland-session.log

TODO KDE_DEBUG=1 to disable DrKonqi