4
Cyril Brulebois <kibi@debian.org>
10
One should note that X is responsible for VT switching, meaning
11
switching between an X session and console terminals. In other words,
12
`Ctrl+Alt+Fn` is handled by X. If X is stopped, for example because
13
it’s running under `gdb`, one can no longer switch to another
14
VT. That’s why we’re recommending using a second machine to debug
15
X. Nevertheless, here are some instructions to attempt debugging X
16
with a single machine.
21
This is a _post-mortem_ approach. The idea is to run X with the
22
`-core` option. Once it dies, a core file (`/etc/X11/core`) is
23
generated, and can be loaded from `gdb`.
27
1. Getting a core file.
28
2. Loading a core file.
29
3. Displaying/saving a backtrace.
34
You pay the “need a second machine” price, but that buys you
35
interactivity. Just log into the first machine from the second one,
40
1. Attaching/Starting X from gdb.
41
2. Displaying/saving a backtrace.
46
Obviously, `gdb` is needed; `xserver-xorg-core-dbg` contains the
47
debugging symbols for the server itself. Other needed packages can be
48
determined by looking at the backtrace. **FIXME: More info about
59
* Using `gdm3`: The idea is to tweak the daemon’s
60
`LocalXserverCommand` setting, adding the `-core` option. As of
61
`gdm3 2.30`, the defaults can be found in
62
`/usr/share/gdm/gdm.schemas`. Sample `/etc/gdm3/daemon.conf`
67
LocalXserverCommand=/usr/bin/Xorg -br -verbose -audit 0 -novtswitch -core
70
* Using `kdm`: One should look for the `ServerArgsLocal` variable in
71
the `/etc/kde4/kdm/kdmrc` file, and add `-core` there. Example:
74
ServerArgsLocal=-br -nolisten tcp -core
77
* Using `xdm`: It’s sufficient to add `-core` to the command
78
configured through `/etc/X11/xdm/Xservers`, for example:
81
:0 local /usr/bin/X :0 vt7 -nolisten tcp -core
87
That’s trivial, one just needs to pass both the core file and the path
91
# gdb -c /etc/X11/core /usr/bin/Xorg
94
Now `gdb` is ready to display backtraces.
99
The way of starting X doesn’t really matter, as `gdb` makes it
100
possible to attach a running process. If there’s a single X instance
101
running, that will do the job:
104
# gdb attach $(pidof X)
106
(gdb) handle SIGPIPE nostop
110
If there are several instances, one can use `ps aux` to determine the
111
PID of the appropriate instance (2nd column → `$pid`), and then attach
117
(gdb) handle SIGPIPE nostop
124
In case X crashes at start-up, one can start X from `gdb` in the
125
following way. In this example, the only parameter is the display, but
126
more parameters can be added.
131
(gdb) handle SIGPIPE nostop
138
`SIGPIPE` is a signal that can reach the X server quite easily,
139
especially when performing a VT switch, or refreshing large parts of
140
the screen. That’s why we ask `gdb` not to stop when such a signal is
141
caught, thanks to the `handle SIGPIPE nostop` command.
143
How to display a backtrace?
144
~~~~~~~~~~~~~~~~~~~~~~~~~~~
146
Once X is crashed, for example because it received a `SIGSEGV`
147
(segmentation fault, usually because of a NULL pointer dereference),
148
or a `SIGBUS`, one gets back to the `gdb` prompt. One can then request
149
a backtrace (`bt`) or a full backtrace (`bt full`). The latter is what
150
developers are usually interested in, because variable values are also
158
How to save a backtrace?
159
~~~~~~~~~~~~~~~~~~~~~~~~
161
To save a recording of the gdb session to a file (`gdb.txt` by
168
To save in a different file, use this instead:
171
(gdb) set logging file my-file.txt
175
Once logging is enabled, you can request a (full) backtrace using the