[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#971088: marked as done (xserver-xorg-core: Backtraces print wrong instruction pointers)



Your message dated Wed, 3 Mar 2021 15:43:04 +0100
with message-id <2e200fcc-af32-6825-9166-57750241a201@mailbox.org>
and subject line Re: Bug#971088: xserver-xorg-core: Backtraces print wrong instruction pointers
has caused the Debian Bug report #971088,
regarding xserver-xorg-core: Backtraces print wrong instruction pointers
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
971088: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=971088
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Package: xserver-xorg-core
Version: 2:1.20.8-2
Severity: wishlist


Dear Maintainer,
in the past I was trying to make sense of some backtraces written
by Xorg, but failed, e.g. in #969739.

I did now some debugging and found that in function xorg_backtrace
the function begin retrieved by unw_get_proc_info in "pip.start_ip"
cannot always be used for calculations with "off".

This is because this "off" offset is calculated in unw_get_proc_name
from the nearest symbol, which does not necessarily match pip.start_ip.

Attached patch separately retrieves the instruction pointer by unw_get_reg
and uses that value for the output. A short in gdb wrote with this patch
applied the same addresses as the bt command.

What do you think?

Kind regards,
Bernhard


-- Package-specific info:
/etc/X11/X does not exist.
/etc/X11/X is not a symlink.
/etc/X11/X is not executable.


-- System Information:
Debian Release: bullseye/sid
  APT prefers testing-debug
  APT policy: (500, 'testing-debug'), (500, 'proposed-updates-debug'), (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 5.8.0-2-amd64 (SMP w/4 CPU threads)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages xserver-xorg-core depends on:
ii  keyboard-configuration  1.196
ii  libaudit1               1:2.8.5-3+b1
ii  libbsd0                 0.10.0-1
ii  libc6                   2.31-3
ii  libdbus-1-3             1.12.20-1
ii  libdrm2                 2.4.102-1
ii  libegl1                 1.3.2-1
ii  libepoxy0               1.5.4-1
ii  libgbm1                 20.1.8-1
ii  libgcrypt20             1.8.6-2
ii  libgl1                  1.3.2-1
ii  libpciaccess0           0.16-1
ii  libpixman-1-0           0.36.0-1
ii  libselinux1             3.1-2
ii  libsystemd0             246.6-1
ii  libudev1                246.6-1
ii  libunwind8              1.3.2-2
ii  libxau6                 1:1.0.8-1+b2
ii  libxdmcp6               1:1.1.2-3
ii  libxfont2               1:2.0.3-1
ii  libxshmfence1           1.3-1
ii  udev                    246.6-1
ii  xserver-common          2:1.20.8-2

Versions of packages xserver-xorg-core recommends:
ii  libgl1-mesa-dri  20.1.8-1
ii  libpam-systemd   246.6-1
>From 2c1cd5ebf5e9281c2e02b9fcaf4430b314a44909 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bernhard=20=C3=9Cbelacker?= <bernhardu@mailbox.org>
Date: Sun, 27 Sep 2020 18:03:48 +0200
Subject: Do not mix the function begin address from unw_get_proc_info and the
 offset from unw_get_proc_name.

---
 os/backtrace.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/os/backtrace.c b/os/backtrace.c
index 619bf14..2aad0e3 100644
--- a/os/backtrace.c
+++ b/os/backtrace.c
@@ -45,6 +45,7 @@ xorg_backtrace(void)
 {
     unw_cursor_t cursor;
     unw_context_t context;
+    unw_word_t ip;
     unw_word_t off;
     unw_proc_info_t pip;
     int ret, i = 0;
@@ -88,7 +89,9 @@ xorg_backtrace(void)
             procname[1] = 0;
         }
 
-        if (dladdr((void *)(uintptr_t)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname &&
+        if (unw_get_reg (&cursor, UNW_REG_IP, &ip) < 0)
+          ip = pip.start_ip + off;
+        if (dladdr((void *)(uintptr_t)(ip), &dlinfo) && dlinfo.dli_fname &&
                 *dlinfo.dli_fname)
             filename = dlinfo.dli_fname;
         else
@@ -96,7 +99,7 @@ xorg_backtrace(void)
 
         ErrorFSigSafe("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname,
             ret == -UNW_ENOMEM ? "..." : "", (int)off,
-            (void *)(uintptr_t)(pip.start_ip + off));
+            (void *)(uintptr_t)(ip));
 
         ret = unw_step(&cursor);
         if (ret < 0)
-- 
2.28.0

# Bullseye/testing amd64 qemu VM 2020-09-25

apt update
apt dist-upgrade





apt install ccache cmake make g++-multilib gdb pkg-config coreutils python3-pexpect manpages-dev git ninja-build capnproto libcapnp-dev

git clone https://github.com/mozilla/rr.git
mkdir obj && cd obj

cmake ../rr

make -j$(nproc)





apt install systemd-coredump psmisc mc fakeroot gdb xserver-xorg xterm openbox xserver-xorg-core-dbgsym libdbus-1-3-dbgsym libunwind8-dbgsym
apt build-dep xserver-xorg-core

echo 1 > /proc/sys/kernel/perf_event_paranoid


mkdir /home/benutzer/source/xserver-xorg-core/orig -p
cd    /home/benutzer/source/xserver-xorg-core/orig
apt source xserver-xorg-core
cd xorg-server-1.20.8
mkdir x/x/x/x/x/x/x/x -p
cd

mkdir /home/benutzer/source/libunwind8/orig -p
cd    /home/benutzer/source/libunwind8/orig
apt source libunwind8
cd











# apt install pstack
wget https://snapshot.debian.org/archive/debian/20170317T095121Z/pool/main/p/pstack/pstack_1.3.1-1%2Bb1_amd64.deb
dpkg -i pstack_1.3.1-1+b1_amd64.deb

root@debian:~# pstack 37009

37009: mc -e ./os/backtrace.c
(No symbols found)
crawl: Input/output error
Error tracing through process 37009
0x7f2b9826e926: ????root@debian:~# 

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=950168










/home/benutzer/obj/bin/rr gdb -q --args /usr/lib/xorg/Xorg

set width 0
set pagination off
b *dbus_error_is_set+7
run
display/i $pc
bt
print/x $rdi
set $rdi=0
detach
q


/home/benutzer/obj/bin/rr ps /root/.local/share/rr/gdb-7


/home/benutzer/obj/bin/rr replay --onfork=35233 --goto=3535 /root/.local/share/rr/gdb-7

set width 0
set pagination off
directory /home/benutzer/source/xserver-xorg-core/orig/xorg-server-1.20.8/x/x/x/x






root@debian:~# /home/benutzer/obj/bin/rr gdb -q --args /usr/lib/xorg/Xorg
rr: Saving execution to trace directory `/root/.local/share/rr/gdb-7'.
Reading symbols from /usr/lib/xorg/Xorg...
Reading symbols from /usr/lib/debug/.build-id/26/aa85549ea06b65d38b154de1bdd27e209ec5d3.debug...
(gdb) set width 0
(gdb) set pagination off
(gdb) b *dbus_error_is_set+7
Breakpoint 1 at 0x3e7a7
(gdb) run
Starting program: /usr/lib/xorg/Xorg 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

X.Org X Server 1.20.8
X Protocol Version 11, Revision 0
Build Operating System: Linux 4.19.0-8-amd64 x86_64 Debian
Current Operating System: Linux debian 5.8.0-2-amd64 #1 SMP Debian 5.8.10-1 (2020-09-19) x86_64
Kernel command line: BOOT_IMAGE=/boot/vmlinuz-5.8.0-2-amd64 root=UUID=c9e90f0f-a043-45af-bda9-4a7fb7b42490 ro quiet
Build Date: 31 March 2020  10:14:40AM
xorg-server 2:1.20.8-2 (https://www.debian.org/support) 
Current version of pixman: 0.36.0
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Sat Sep 26 10:47:23 2020
(==) Using system config directory "/usr/share/X11/xorg.conf.d"

Breakpoint 1, 0x00007ffff7f77b37 in dbus_error_is_set (error=error@entry=0x7fffffffe9d0) at ../../../dbus/dbus-errors.c:334
334     ../../../dbus/dbus-errors.c: Datei oder Verzeichnis nicht gefunden.
(gdb) display/i $pc
1: x/i $pc
=> 0x7ffff7f77b37 <dbus_error_is_set+7>:        cmpq   $0x0,(%rdi)
(gdb) bt
#0  0x00007ffff7f77b37 in dbus_error_is_set (error=error@entry=0x7fffffffe9d0) at ../../../dbus/dbus-errors.c:334
#1  0x00007ffff7f7059c in internal_bus_get (type=DBUS_BUS_SYSTEM, private=0, error=0x7fffffffe9d0) at ../../../dbus/dbus-bus.c:426
#2  0x0000555555609f8e in connect_to_bus () at ../../../../config/dbus-core.c:136
#3  0x000055555560a394 in dbus_core_init () at ../../../../config/dbus-core.c:228
#4  0x00005555555ef504 in InitOutput (pScreenInfo=pScreenInfo@entry=0x5555557c2740 <screenInfo>, argc=argc@entry=1, argv=argv@entry=0x7fffffffec08) at ../../../../../../hw/xfree86/common/xf86Init.c:384
#5  0x00005555555b26f4 in dix_main (argc=1, argv=0x7fffffffec08, envp=<optimized out>) at ../../../../dix/main.c:193
#6  0x00007ffff70cbcca in __libc_start_main (main=0x55555559c700 <main>, argc=1, argv=0x7fffffffec08, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffebf8) at ../csu/libc-start.c:308
#7  0x000055555559c73a in _start ()
(gdb) print/x $rdi
$1 = 0x7fffffffe9d0
(gdb) set $rdi=0
(gdb) detach
Detaching from program: /usr/lib/xorg/Xorg, process 35233
[Inferior 1 (process 35233) detached]
(gdb) (EE) 
(EE) Backtrace:
(EE) 0: /usr/lib/xorg/Xorg (OsLookupColor+0x138) [0x55555570be88]
(EE) 1: /lib/x86_64-linux-gnu/libpthread.so.0 (funlockfile+0x50) [0x7ffff727e18f]
(EE) 2: /lib/x86_64-linux-gnu/libdbus-1.so.3 (dbus_error_is_set+0x7) [0x7ffff7f77b37]
(EE) 3: /lib/x86_64-linux-gnu/libdbus-1.so.3 (dbus_bus_register+0x28c) [0x7ffff7f707ec]
(EE) 4: /usr/lib/xorg/Xorg (config_fini+0x1fe) [0x55555560a15e]
(EE) 5: /usr/lib/xorg/Xorg (config_fini+0x604) [0x55555560a964]
(EE) 6: /usr/lib/xorg/Xorg (InitOutput+0x6e4) [0x5555555ef504]
(EE) 7: /usr/lib/xorg/Xorg (InitFonts+0x1d4) [0x5555555b2734]
(EE) 8: /lib/x86_64-linux-gnu/libc.so.6 (__libc_start_main+0xea) [0x7ffff70cbcca]
(EE) 9: /usr/lib/xorg/Xorg (_start+0x2a) [0x55555559c73a]
(EE) 
(EE) Segmentation fault at address 0x0
(EE) 
Fatal server error:
(EE) Caught signal 11 (Segmentation fault). Server aborting
(EE) 
(EE) 
Please consult the The X.Org Foundation support 
         at http://wiki.x.org
 for help. 
(EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
(EE) 
(EE) Server terminated with error (1). Closing log file.
q






root@debian:~# /home/benutzer/obj/bin/rr ps /root/.local/share/rr/gdb-7
PID     PPID    EXIT    CMD
35230   --      0       gdb -q --args /usr/lib/xorg/Xorg
35231   35230   0       iconv -l
35233   35230   -6      /bin/bash -c exec /usr/lib/xorg/Xorg 
35234   35230   -9      (forked without exec)
35235   35234   -9      (forked without exec)
35236   35230   -9      (forked without exec)






/home/benutzer/obj/bin/rr replay --onfork=35233 --goto=10739 /root/.local/share/rr/gdb-7

set width 0
set pagination off
set backtrace past-main
directory /home/benutzer/source/xserver-xorg-core/orig/xorg-server-1.20.8/x/x/x/x
directory /home/benutzer/source/xserver-xorg-core/orig/xorg-server-1.20.8/x/x/x/x/x/x
directory /home/benutzer/source/xserver-xorg-core/orig/xorg-server-1.20.8/x/x/x/x/x/x/x
directory /home/benutzer/source/libunwind8/orig/libunwind-1.3.2/src
directory /home/benutzer/source/libunwind8/orig/libunwind-1.3.2/src/x86_64
display/i $pc
b xorg_backtrace
cont

display/x pip.start_ip





(rr) bt
#0  _Ux86_64_getcontext () at x86_64/getcontext.S:43
#1  0x0000555555707efd in xorg_backtrace ()
#2  0x000055555570bd78 in ?? ()
#3  <signal handler called>
#4  0x00007ffff7f77b37 in dbus_error_is_set () from /lib/x86_64-linux-gnu/libdbus-1.so.3
#5  0x00007ffff7f7059c in ?? () from /lib/x86_64-linux-gnu/libdbus-1.so.3
#6  0x0000555555609f8e in ?? ()
#7  0x000055555560a394 in ?? ()
#8  0x00005555555ef504 in InitOutput ()
#9  0x00005555555b26f4 in ?? ()
#10 0x00007ffff70cbcca in __libc_start_main (main=0x55555559c700, argc=1, argv=0x7fffffffec08, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffebf8) at ../csu/libc-start.c:308
#11 0x000055555559c73a in _start ()

(EE) Backtrace:
(EE) 0: /usr/lib/xorg/Xorg (OsLookupColor+0x138) [0x55555570be88]
(EE) 1: /lib/x86_64-linux-gnu/libpthread.so.0 (funlockfile+0x50) [0x7ffff727e18f]
(EE) 2: /lib/x86_64-linux-gnu/libdbus-1.so.3 (dbus_error_is_set+0x7) [0x7ffff7f77b37]
(EE) 3: /lib/x86_64-linux-gnu/libdbus-1.so.3 (dbus_bus_register+0x28c) [0x7ffff7f707ec]
(EE) 4: /usr/lib/xorg/Xorg (config_fini+0x1fe) [0x55555560a15e]
(EE) 5: /usr/lib/xorg/Xorg (config_fini+0x604) [0x55555560a964]
(EE) 6: /usr/lib/xorg/Xorg (InitOutput+0x6e4) [0x5555555ef504]
(EE) 7: /usr/lib/xorg/Xorg (InitFonts+0x1d4) [0x5555555b2734]
(EE) 8: /lib/x86_64-linux-gnu/libc.so.6 (__libc_start_main+0xea) [0x7ffff70cbcca]
(EE) 9: /usr/lib/xorg/Xorg (_start+0x2a) [0x55555559c73a]

(rr) bt
#0  0x00007ffff7dd223a in _Ux86_64_getcontext () at x86_64/getcontext.S:43
#1  0x0000555555707efd in xorg_backtrace () at ../../../../os/backtrace.c:56
#2  0x000055555570bd78 in OsSigHandler (unused=<optimized out>, sip=0x7fffffffe4b0, signo=11) at ../../../../os/osinit.c:135
#3  0x000055555570bd78 in OsSigHandler (signo=11, sip=0x7fffffffe4b0, unused=<optimized out>) at ../../../../os/osinit.c:110
#4  <signal handler called>
#5  0x00007ffff7f77b37 in dbus_error_is_set (error=0x0, error@entry=0x7fffffffe9d0) at ../../../dbus/dbus-errors.c:334
#6  0x00007ffff7f7059c in internal_bus_get (type=DBUS_BUS_SYSTEM, private=0, error=0x7fffffffe9d0) at ../../../dbus/dbus-bus.c:426
#7  0x0000555555609f8e in connect_to_bus () at ../../../../config/dbus-core.c:136
#8  0x000055555560a394 in dbus_core_init () at ../../../../config/dbus-core.c:228
#9  0x00005555555ef504 in InitOutput (pScreenInfo=pScreenInfo@entry=0x5555557c2740 <screenInfo>, argc=argc@entry=1, argv=argv@entry=0x7fffffffec08) at ../../../../../../hw/xfree86/common/xf86Init.c:384
#10 0x00005555555b26f4 in dix_main (argc=1, argv=0x7fffffffec08, envp=<optimized out>) at ../../../../dix/main.c:193
#11 0x00007ffff70cbcca in __libc_start_main (main=0x55555559c700 <main>, argc=1, argv=0x7fffffffec08, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffebf8) at ../csu/libc-start.c:308
#12 0x000055555559c73a in _start ()

















(rr) reverse-finish
Run back to call of #0  _Uelf64_lookup_symbol (ip=ip@entry=93824994033015, ei=ei@entry=0x7fffffffc8c0, load_offset=load_offset@entry=93824992231424, buf=buf@entry=0x7fffffffe210 "OsLookupColor", buf_len=buf_len@entry=256, min_dist=min_dist@entry=0x7fffffffc7e8, as=0x7ffff7ddf3c0 <local_addr_space>) at elfxx.c:139

Breakpoint 4, _Uelf64_lookup_symbol (ip=ip@entry=93824994033015, ei=ei@entry=0x7fffffffc8c0, load_offset=load_offset@entry=93824992231424, buf=buf@entry=0x7fffffffe210 "OsLookupColor", buf_len=buf_len@entry=256, min_dist=min_dist@entry=0x7fffffffc7e8, as=0x7ffff7ddf3c0 <local_addr_space>) at elfxx.c:143
143                           buf[buf_len - 1] = '\0';
1: x/i $pc
=> 0x7ffff7dd65ab <_Uelf64_lookup_symbol+347>:  mov    0x18(%rsp),%r8
8: (char*)(strtab + sym->st_name) = 0x7ffff678f6d7 "OsLookupColor"
9: /x *min_dist = 0x137
10: /x val = <optimized out>
(rr) bt
#0  _Uelf64_lookup_symbol (ip=ip@entry=93824994033015, ei=ei@entry=0x7fffffffc8c0, load_offset=load_offset@entry=93824992231424, buf=buf@entry=0x7fffffffe210 "OsLookupColor", buf_len=buf_len@entry=256, min_dist=min_dist@entry=0x7fffffffc7e8, as=0x7ffff7ddf3c0 <local_addr_space>) at elfxx.c:143
#1  0x00007ffff7dd67bc in _Uelf64_get_proc_name_in_image (as=as@entry=0x7ffff7ddf3c0 <local_addr_space>, ei=ei@entry=0x7fffffffc8c0, segbase=<optimized out>, mapoff=<optimized out>, ip=ip@entry=93824994033015, buf=buf@entry=0x7fffffffe210 "OsLookupColor", buf_len=256, offp=0x7fffffffd9c8) at elfxx.c:282
#2  0x00007ffff7dd6dee in _Uelf64_get_proc_name (as=0x7ffff7ddf3c0 <local_addr_space>, pid=<optimized out>, ip=93824994033015, buf=0x7fffffffe210 "OsLookupColor", buf_len=256, offp=0x7fffffffd9c8) at elfxx.c:325
#3  0x00007ffff7dcf60c in get_proc_name (arg=0x7fffffffde10, offp=0x7fffffffd9c8, buf_len=256, buf=0x7fffffffe210 "OsLookupColor", ip=93824994033015, as=0x7ffff7ddf3c0 <local_addr_space>) at mi/Gget_proc_name.c:93
#4  _ULx86_64_get_proc_name (cursor=cursor@entry=0x7fffffffde10, buf=buf@entry=0x7fffffffe210 "OsLookupColor", buf_len=buf_len@entry=256, offp=offp@entry=0x7fffffffd9c8) at mi/Gget_proc_name.c:111
#5  0x000055555570803b in xorg_backtrace () at ../../../../os/backtrace.c:82
#6  0x000055555570bd78 in OsSigHandler (unused=<optimized out>, sip=0x7fffffffe4b0, signo=11) at ../../../../os/osinit.c:135
#7  OsSigHandler (signo=11, sip=0x7fffffffe4b0, unused=<optimized out>) at ../../../../os/osinit.c:110
#8  <signal handler called>
#9  0x00007ffff7f77b37 in dbus_error_is_set (error=0x0, error@entry=0x7fffffffe9d0) at ../../../dbus/dbus-errors.c:334
#10 0x00007ffff7f7059c in internal_bus_get (type=DBUS_BUS_SYSTEM, private=0, error=0x7fffffffe9d0) at ../../../dbus/dbus-bus.c:426
#11 0x0000555555609f8e in connect_to_bus () at ../../../../config/dbus-core.c:136
#12 0x000055555560a394 in dbus_core_init () at ../../../../config/dbus-core.c:228
#13 0x00005555555ef504 in InitOutput (pScreenInfo=pScreenInfo@entry=0x5555557c2740 <screenInfo>, argc=argc@entry=1, argv=argv@entry=0x7fffffffec08) at ../../../../../../hw/xfree86/common/xf86Init.c:384
#14 0x00005555555b26f4 in dix_main (argc=1, argv=0x7fffffffec08, envp=<optimized out>) at ../../../../dix/main.c:193
#15 0x00007ffff70cbcca in __libc_start_main (main=0x55555559c700 <main>, argc=1, argv=0x7fffffffec08, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffebf8) at ../csu/libc-start.c:308
#16 0x000055555559c73a in _start () at ../../../../../../hw/xfree86/dri2/dri2ext.c:659

8: (char*)(strtab + sym->st_name) = 0x7ffff678f6d7 "OsLookupColor"
9: /x *min_dist = 0x137
10: /x val = 0x55555570bc40
11: /x ip = 0x55555570bd77

(rr) list elfxx.c:143
138
139                       if ((Elf_W (Addr)) (ip - val) < *min_dist)
140                         {
141                           *min_dist = (Elf_W (Addr)) (ip - val);
142                           strncpy (buf, strtab + sym->st_name, buf_len);
143                           buf[buf_len - 1] = '\0';
144                           ret = (strlen (strtab + sym->st_name) >= buf_len
145                                  ? -UNW_ENOMEM : 0);
146                         }
147                     }

(rr) disassemble OsLookupColor,OsLookupColor+0x137+20
Dump of assembler code from 0x55555570bc40 to 0x55555570bd8b:
   0x000055555570bc40 <OsLookupColor+0>:        push   %r15
   0x000055555570bc42 <OsLookupColor+2>:        mov    $0xd6b,%edi
   0x000055555570bc47 <OsLookupColor+7>:        push   %r14
   0x000055555570bc49 <OsLookupColor+9>:        mov    $0x30d,%r14d
   0x000055555570bc4f <OsLookupColor+15>:       push   %r13
   0x000055555570bc51 <OsLookupColor+17>:       mov    %rsi,%r13
   0x000055555570bc54 <OsLookupColor+20>:       push   %r12
   0x000055555570bc56 <OsLookupColor+22>:       mov    %edx,%r12d
   0x000055555570bc59 <OsLookupColor+25>:       push   %rbp
   0x000055555570bc5a <OsLookupColor+26>:       xor    %ebp,%ebp
   0x000055555570bc5c <OsLookupColor+28>:       push   %rbx
   0x000055555570bc5d <OsLookupColor+29>:       mov    $0x30d,%ebx
   0x000055555570bc62 <OsLookupColor+34>:       sub    $0x28,%rsp
   0x000055555570bc66 <OsLookupColor+38>:       mov    %rcx,0x8(%rsp)
   0x000055555570bc6b <OsLookupColor+43>:       mov    %r8,0x10(%rsp)
   0x000055555570bc70 <OsLookupColor+48>:       mov    %r9,0x18(%rsp)
   0x000055555570bc75 <OsLookupColor+53>:       jmp    0x55555570bcb1 <OsLookupColor+113>
   0x000055555570bc77 <OsLookupColor+55>:       nopw   0x0(%rax,%rax,1)
   0x000055555570bc80 <OsLookupColor+64>:       mov    %r15,%rdi
   0x000055555570bc83 <OsLookupColor+67>:       callq  0x5555555919d0 <strlen@plt>
   0x000055555570bc88 <OsLookupColor+72>:       cmp    %r12,%rax
   0x000055555570bc8b <OsLookupColor+75>:       je     0x55555570bcf0 <OsLookupColor+176>
   0x000055555570bc8d <OsLookupColor+77>:       lea    -0x1(%rbx),%r14d
   0x000055555570bc91 <OsLookupColor+81>:       cmp    %r14d,%ebp
   0x000055555570bc94 <OsLookupColor+84>:       jg     0x55555570bcda <OsLookupColor+154>
   0x000055555570bc96 <OsLookupColor+86>:       lea    0x0(%rbp,%r14,1),%ebx
   0x000055555570bc9b <OsLookupColor+91>:       lea    0x397be(%rip),%rcx        # 0x555555745460 <BuiltinColors>
   0x000055555570bca2 <OsLookupColor+98>:       mov    %ebx,%eax
   0x000055555570bca4 <OsLookupColor+100>:      sar    %eax
   0x000055555570bca6 <OsLookupColor+102>:      cltq   
   0x000055555570bca8 <OsLookupColor+104>:      lea    (%rax,%rax,2),%rax
   0x000055555570bcac <OsLookupColor+108>:      movzwl 0x4(%rcx,%rax,2),%edi
   0x000055555570bcb1 <OsLookupColor+113>:      lea    0x3aa08(%rip),%rax        # 0x5555557466c0 <BuiltinColorNames>
   0x000055555570bcb8 <OsLookupColor+120>:      mov    %r12,%rdx
   0x000055555570bcbb <OsLookupColor+123>:      mov    %r13,%rsi
   0x000055555570bcbe <OsLookupColor+126>:      sar    %ebx
   0x000055555570bcc0 <OsLookupColor+128>:      lea    (%rax,%rdi,1),%r15
   0x000055555570bcc4 <OsLookupColor+132>:      mov    %r15,%rdi
   0x000055555570bcc7 <OsLookupColor+135>:      callq  0x5555555922a0 <strncasecmp@plt>
   0x000055555570bccc <OsLookupColor+140>:      test   %eax,%eax
   0x000055555570bcce <OsLookupColor+142>:      je     0x55555570bc80 <OsLookupColor+64>
   0x000055555570bcd0 <OsLookupColor+144>:      jns    0x55555570bc8d <OsLookupColor+77>
   0x000055555570bcd2 <OsLookupColor+146>:      lea    0x1(%rbx),%ebp
   0x000055555570bcd5 <OsLookupColor+149>:      cmp    %r14d,%ebp
   0x000055555570bcd8 <OsLookupColor+152>:      jle    0x55555570bc96 <OsLookupColor+86>
   0x000055555570bcda <OsLookupColor+154>:      add    $0x28,%rsp
   0x000055555570bcde <OsLookupColor+158>:      xor    %eax,%eax
   0x000055555570bce0 <OsLookupColor+160>:      pop    %rbx
   0x000055555570bce1 <OsLookupColor+161>:      pop    %rbp
   0x000055555570bce2 <OsLookupColor+162>:      pop    %r12
   0x000055555570bce4 <OsLookupColor+164>:      pop    %r13
   0x000055555570bce6 <OsLookupColor+166>:      pop    %r14
   0x000055555570bce8 <OsLookupColor+168>:      pop    %r15
   0x000055555570bcea <OsLookupColor+170>:      retq   
   0x000055555570bceb <OsLookupColor+171>:      nopl   0x0(%rax,%rax,1)
   0x000055555570bcf0 <OsLookupColor+176>:      movslq %ebx,%rbx
   0x000055555570bcf3 <OsLookupColor+179>:      lea    0x39766(%rip),%rax        # 0x555555745460 <BuiltinColors>
   0x000055555570bcfa <OsLookupColor+186>:      mov    0x8(%rsp),%rsi
   0x000055555570bcff <OsLookupColor+191>:      lea    (%rbx,%rbx,2),%rdx
   0x000055555570bd03 <OsLookupColor+195>:      lea    (%rax,%rdx,2),%rax
   0x000055555570bd07 <OsLookupColor+199>:      movzbl (%rax),%ecx
   0x000055555570bd0a <OsLookupColor+202>:      mov    %ecx,%edx
   0x000055555570bd0c <OsLookupColor+204>:      shl    $0x8,%edx
   0x000055555570bd0f <OsLookupColor+207>:      add    %ecx,%edx
   0x000055555570bd11 <OsLookupColor+209>:      movzbl 0x1(%rax),%ecx
   0x000055555570bd15 <OsLookupColor+213>:      mov    %dx,(%rsi)
   0x000055555570bd18 <OsLookupColor+216>:      mov    0x10(%rsp),%rsi
   0x000055555570bd1d <OsLookupColor+221>:      mov    %ecx,%edx
   0x000055555570bd1f <OsLookupColor+223>:      shl    $0x8,%edx
   0x000055555570bd22 <OsLookupColor+226>:      add    %ecx,%edx
   0x000055555570bd24 <OsLookupColor+228>:      mov    %dx,(%rsi)
   0x000055555570bd27 <OsLookupColor+231>:      movzbl 0x2(%rax),%edx
   0x000055555570bd2b <OsLookupColor+235>:      mov    0x18(%rsp),%rsi
   0x000055555570bd30 <OsLookupColor+240>:      mov    %edx,%eax
   0x000055555570bd32 <OsLookupColor+242>:      shl    $0x8,%eax
   0x000055555570bd35 <OsLookupColor+245>:      add    %edx,%eax
   0x000055555570bd37 <OsLookupColor+247>:      mov    %ax,(%rsi)
   0x000055555570bd3a <OsLookupColor+250>:      add    $0x28,%rsp
   0x000055555570bd3e <OsLookupColor+254>:      mov    $0x1,%eax
   0x000055555570bd43 <OsLookupColor+259>:      pop    %rbx
   0x000055555570bd44 <OsLookupColor+260>:      pop    %rbp
   0x000055555570bd45 <OsLookupColor+261>:      pop    %r12
   0x000055555570bd47 <OsLookupColor+263>:      pop    %r13
   0x000055555570bd49 <OsLookupColor+265>:      pop    %r14
   0x000055555570bd4b <OsLookupColor+267>:      pop    %r15
   0x000055555570bd4d <OsLookupColor+269>:      retq   
   0x000055555570bd4e:  xchg   %ax,%ax
   0x000055555570bd50 <OsSigHandler+0>: mov    0xab979(%rip),%rax        # 0x5555557b76d0 <OsSigWrapper>
   0x000055555570bd57 <OsSigHandler+7>: push   %r13
   0x000055555570bd59 <OsSigHandler+9>: push   %r12
   0x000055555570bd5b <OsSigHandler+11>:        mov    %edi,%r12d
   0x000055555570bd5e <OsSigHandler+14>:        push   %rbx
   0x000055555570bd5f <OsSigHandler+15>:        mov    %rsi,%rbx
   0x000055555570bd62 <OsSigHandler+18>:        test   %rax,%rax
   0x000055555570bd65 <OsSigHandler+21>:        je     0x55555570bd73 <OsSigHandler+35>
   0x000055555570bd67 <OsSigHandler+23>:        callq  *%rax
   0x000055555570bd69 <OsSigHandler+25>:        test   %eax,%eax
   0x000055555570bd6b <OsSigHandler+27>:        jne    0x55555570bd73 <OsSigHandler+35>
   0x000055555570bd6d <OsSigHandler+29>:        pop    %rbx
   0x000055555570bd6e <OsSigHandler+30>:        pop    %r12
   0x000055555570bd70 <OsSigHandler+32>:        pop    %r13
   0x000055555570bd72 <OsSigHandler+34>:        retq   
   0x000055555570bd73 <OsSigHandler+35>:        callq  0x555555707ec0 <xorg_backtrace>
   0x000055555570bd78 <OsSigHandler+40>:        cmpl   $0x0,0x8(%rbx)
   0x000055555570bd7c <OsSigHandler+44>:        je     0x55555570bde5 <OsSigHandler+149>
   0x000055555570bd7e <OsSigHandler+46>:        cmp    $0xb,%r12d
   0x000055555570bd82 <OsSigHandler+50>:        ja     0x55555570bdb6 <OsSigHandler+102>
   0x000055555570bd84 <OsSigHandler+52>:        mov    $0x1,%eax
   0x000055555570bd89 <OsSigHandler+57>:        mov    %r12d,%ecx
End of assembler dump.



--> unw_get_proc_name finds the nearest symbol "OsLookupColor" at 0x55555570bc40
    and uses that address for min_dist calculation
.







(rr) bt
#0  xorg_backtrace () at ../../../../os/backtrace.c:97
#1  0x000055555570bd78 in OsSigHandler (unused=<optimized out>, sip=0x7fffffffe4b0, signo=11) at ../../../../os/osinit.c:135
#2  OsSigHandler (signo=11, sip=0x7fffffffe4b0, unused=<optimized out>) at ../../../../os/osinit.c:110
#3  <signal handler called>
#4  0x00007ffff7f77b37 in dbus_error_is_set (error=0x0, error@entry=0x7fffffffe9d0) at ../../../dbus/dbus-errors.c:334
#5  0x00007ffff7f7059c in internal_bus_get (type=DBUS_BUS_SYSTEM, private=0, error=0x7fffffffe9d0) at ../../../dbus/dbus-bus.c:426
#6  0x0000555555609f8e in connect_to_bus () at ../../../../config/dbus-core.c:136
#7  0x000055555560a394 in dbus_core_init () at ../../../../config/dbus-core.c:228
#8  0x00005555555ef504 in InitOutput (pScreenInfo=pScreenInfo@entry=0x5555557c2740 <screenInfo>, argc=argc@entry=1, argv=argv@entry=0x7fffffffec08) at ../../../../../../hw/xfree86/common/xf86Init.c:384
#9  0x00005555555b26f4 in dix_main (argc=1, argv=0x7fffffffec08, envp=<optimized out>) at ../../../../dix/main.c:193
#10 0x00007ffff70cbcca in __libc_start_main (main=0x55555559c700 <main>, argc=1, argv=0x7fffffffec08, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffebf8) at ../csu/libc-start.c:308
#11 0x000055555559c73a in _start () at ../../../../../../hw/xfree86/dri2/dri2ext.c:659

(rr) list backtrace.c:97
file: "../../../../os/backtrace.c", line number: 97, symbol: "???"
92                      *dlinfo.dli_fname)
93                  filename = dlinfo.dli_fname;
94              else
95                  filename = "?";
96
97              ErrorFSigSafe("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname,
98                  ret == -UNW_ENOMEM ? "..." : "", (int)off,
99                  (void *)(uintptr_t)(pip.start_ip + off));
100
101             ret = unw_step(&cursor);

(rr) print/x pip.start_ip
$56 = 0x55555570bd50
(rr) print/x off
$57 = 0x138
(rr) print/x pip.start_ip + off
$58 = 0x55555570be88

(rr) disassemble 0x55555570be88-0x30,0x55555570be88+16
Dump of assembler code from 0x55555570be58 to 0x55555570be98:
   0x000055555570be58 <OsInit+72>:      and    $0x14,%al
   0x000055555570be5a <OsInit+74>:      add    (%rax),%eax
   0x000055555570be5c <OsInit+76>:      add    %al,(%rax)
   0x000055555570be5e <OsInit+78>:      mov    %rax,0x18(%rsp)
   0x000055555570be63 <OsInit+83>:      mov    $0x3,%ebx
   0x000055555570be68 <OsInit+88>:      lea    0x40(%rsp),%r13
   0x000055555570be6d <OsInit+93>:      movabs $0x600000007,%rax
   0x000055555570be77 <OsInit+103>:     mov    %rax,0x20(%rsp)
   0x000055555570be7c <OsInit+108>:     mov    $0xb,%r12d
   0x000055555570be82 <OsInit+114>:     movabs $0x180000001f,%rax
   0x000055555570be8c <OsInit+124>:     lea    0xe0(%rsp),%r14
   0x000055555570be94 <OsInit+132>:     mov    %rax,0x28(%rsp)
End of assembler dump.


--> But in xorg_backtrace that offset is used and added to the function start provided in pip.start_ip,
    which is the correct start for OsSigHandler.
    Therefore the value printed in [] is wrong.






https://wiki.debian.org/UsingQuilt

quilt push -a 
quilt new 08_backtrace.diff
quilt add os/backtrace.c

# edit

quilt refresh
quilt header -e

dpkg-buildpackage









With a package installed with the patch:

root@debian:~# gdb -q --args /usr/lib/xorg/Xorg
Reading symbols from /usr/lib/xorg/Xorg...
Reading symbols from /usr/lib/debug/.build-id/41/5c140ca4d894df5e39193499076eed502b26e9.debug...
(gdb) set width 0
(gdb) set pagination off
(gdb) b *dbus_error_is_set+7
Breakpoint 1 at 0x3e7d7
(gdb) run
Starting program: /usr/lib/xorg/Xorg 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

X.Org X Server 1.20.8
X Protocol Version 11, Revision 0
Build Operating System: Linux 5.8.0-2-amd64 x86_64 Debian
Current Operating System: Linux debian 5.8.0-2-amd64 #1 SMP Debian 5.8.10-1 (2020-09-19) x86_64
Kernel command line: BOOT_IMAGE=/boot/vmlinuz-5.8.0-2-amd64 root=UUID=c9e90f0f-a043-45af-bda9-4a7fb7b42490 ro quiet
Build Date: 31 March 2020  10:14:40AM
xorg-server 2:1.20.8-2 (https://www.debian.org/support) 
Current version of pixman: 0.36.0
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Sun Sep 27 18:15:31 2020
(==) Using system config directory "/usr/share/X11/xorg.conf.d"

Breakpoint 1, 0x00007ffff7f85b37 in dbus_error_is_set (error=error@entry=0x7fffffffead0) at ../../../dbus/dbus-errors.c:334
334     ../../../dbus/dbus-errors.c: Datei oder Verzeichnis nicht gefunden.
(gdb) display/i $pc
1: x/i $pc
=> 0x7ffff7f85b37 <dbus_error_is_set+7>:        cmpq   $0x0,(%rdi)
(gdb) bt
#0  0x00007ffff7f85b37 in dbus_error_is_set (error=error@entry=0x7fffffffead0) at ../../../dbus/dbus-errors.c:334
#1  0x00007ffff7f7e59c in internal_bus_get (type=DBUS_BUS_SYSTEM, private=0, error=0x7fffffffead0) at ../../../dbus/dbus-bus.c:426
#2  0x000055555560c64e in connect_to_bus () at ../../../../config/dbus-core.c:136
#3  0x000055555560ca45 in dbus_core_init () at ../../../../config/dbus-core.c:228
#4  0x00005555555f158f in InitOutput (pScreenInfo=pScreenInfo@entry=0x5555557b40a0 <screenInfo>, argc=argc@entry=1, argv=argv@entry=0x7fffffffed08) at ../../../../../../hw/xfree86/common/xf86Init.c:384
#5  0x00005555555b335c in dix_main (argc=1, argv=0x7fffffffed08, envp=<optimized out>) at ../../../../dix/main.c:193
#6  0x00007ffff70d9cca in __libc_start_main (main=0x55555559cca0 <main>, argc=1, argv=0x7fffffffed08, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffecf8) at ../csu/libc-start.c:308
#7  0x000055555559ccda in _start ()
(gdb) print/x $rdi
$1 = 0x7fffffffead0
(gdb) set $rdi=0
(gdb) b xorg_backtrace
Breakpoint 2 at 0x55555570eb80: file ../../../../os/backtrace.c, line 45.
(gdb) cont
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7f85b37 in dbus_error_is_set (error=0x0, error@entry=0x7fffffffead0) at ../../../dbus/dbus-errors.c:334
334     in ../../../dbus/dbus-errors.c
1: x/i $pc
=> 0x7ffff7f85b37 <dbus_error_is_set+7>:        cmpq   $0x0,(%rdi)
(gdb) cont
Continuing.

Breakpoint 2, xorg_backtrace () at ../../../../os/backtrace.c:45
45      ../../../../os/backtrace.c: Datei oder Verzeichnis nicht gefunden.
1: x/i $pc
=> 0x55555570eb80 <xorg_backtrace>:     push   %r15
(gdb) next
56      in ../../../../os/backtrace.c
1: x/i $pc
=> 0x55555570eba4 <xorg_backtrace+36>:  lea    0x80(%rsp),%r13
(gdb) 
57      in ../../../../os/backtrace.c
1: x/i $pc
=> 0x55555570ebb5 <xorg_backtrace+53>:  mov    %r13,%rdi
(gdb) 
58      in ../../../../os/backtrace.c
1: x/i $pc
=> 0x55555570ebbd <xorg_backtrace+61>:  test   %eax,%eax
(gdb) 
64      in ../../../../os/backtrace.c
1: x/i $pc
=> 0x55555570ebc5 <xorg_backtrace+69>:  lea    0x450(%rsp),%rbp
(gdb) 
65      in ../../../../os/backtrace.c
1: x/i $pc
=> 0x55555570ebdb <xorg_backtrace+91>:  test   %eax,%eax
(gdb) 
71      in ../../../../os/backtrace.c
1: x/i $pc
=> 0x55555570ebe3 <xorg_backtrace+99>:  lea    0x3a752(%rip),%rdi        # 0x55555574933c
(gdb) 
(EE) 
72      in ../../../../os/backtrace.c
1: x/i $pc
=> 0x55555570ebf6 <xorg_backtrace+118>: lea    0x3d1eb(%rip),%rdi        # 0x55555574bde8
(gdb) 
(EE) Backtrace:
73      in ../../../../os/backtrace.c
1: x/i $pc
=> 0x55555570ec09 <xorg_backtrace+137>: mov    %rbp,%rdi
(gdb) bt
#0  xorg_backtrace () at ../../../../os/backtrace.c:73
#1  0x0000555555712a15 in OsSigHandler (unused=<optimized out>, sip=0x7fffffffe5b0, signo=11) at ../../../../os/osinit.c:135
#2  OsSigHandler (signo=11, sip=0x7fffffffe5b0, unused=<optimized out>) at ../../../../os/osinit.c:110
#3  <signal handler called>
#4  0x00007ffff7f85b37 in dbus_error_is_set (error=0x0, error@entry=0x7fffffffead0) at ../../../dbus/dbus-errors.c:334
#5  0x00007ffff7f7e59c in internal_bus_get (type=DBUS_BUS_SYSTEM, private=0, error=0x7fffffffead0) at ../../../dbus/dbus-bus.c:426
#6  0x000055555560c64e in connect_to_bus () at ../../../../config/dbus-core.c:136
#7  0x000055555560ca45 in dbus_core_init () at ../../../../config/dbus-core.c:228
#8  0x00005555555f158f in InitOutput (pScreenInfo=pScreenInfo@entry=0x5555557b40a0 <screenInfo>, argc=argc@entry=1, argv=argv@entry=0x7fffffffed08) at ../../../../../../hw/xfree86/common/xf86Init.c:384
#9  0x00005555555b335c in dix_main (argc=1, argv=0x7fffffffed08, envp=<optimized out>) at ../../../../dix/main.c:193
#10 0x00007ffff70d9cca in __libc_start_main (main=0x55555559cca0 <main>, argc=1, argv=0x7fffffffed08, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffecf8) at ../csu/libc-start.c:308
#11 0x000055555559ccda in _start ()
(gdb) finish
Run till exit from #0  xorg_backtrace () at ../../../../os/backtrace.c:73
(EE) 0: /usr/lib/xorg/Xorg (OsLookupColor+0x135) [0x555555712a15]
(EE) 1: /lib/x86_64-linux-gnu/libpthread.so.0 (funlockfile+0x50) [0x7ffff728e140]
(EE) 2: /lib/x86_64-linux-gnu/libdbus-1.so.3 (dbus_error_is_set+0x7) [0x7ffff7f85b37]
(EE) 3: /lib/x86_64-linux-gnu/libdbus-1.so.3 (dbus_bus_register+0x28c) [0x7ffff7f7e59c]
(EE) 4: /usr/lib/xorg/Xorg (config_fini+0x25e) [0x55555560c64e]
(EE) 5: /usr/lib/xorg/Xorg (config_fini+0x655) [0x55555560ca45]
(EE) 6: /usr/lib/xorg/Xorg (InitOutput+0x6df) [0x5555555f158f]
(EE) 7: /usr/lib/xorg/Xorg (InitFonts+0x1cc) [0x5555555b335c]
(EE) 8: /lib/x86_64-linux-gnu/libc.so.6 (__libc_start_main+0xea) [0x7ffff70d9cca]
(EE) 9: /usr/lib/xorg/Xorg (_start+0x2a) [0x55555559ccda]
(EE) 

--> Addresses in backtraces are the same.

--- End Message ---
--- Begin Message ---
Version: 2:1.20.10-1

--- End Message ---

Reply to: