Discussion:
Generating gdb debug logs for devs
Add Reply
Pekka Järvinen via arch-general
2017-02-01 23:53:28 UTC
Reply
Permalink
Raw Message
Hi,

I have segfaulting lxrandr and I was referred to
https://wiki.archlinux.org/index.php/Debug_-_Getting_Traces after filing
bug report.
I've installed ABS, modified PKGBUILD and made my own /etc/makepkg-dev.conf

makepkg -sf --config /etc/makepkg-dev.conf generates the executable.

Still gdb gives very little info after running
cd lxrandr/pkg/lxrandr/usr/bin
gdb -ex "set logging file debug.log" -ex "set logging overwrite on" -ex
"thread apply all bt full" -ex "set logging on" -ex "run" -ex "backtrace"
-ex "frame 0" -ex "kill" -ex "quit" ./lxrandr

I'm guessing because I need to add debugging to libraries which lxrandr is
using too.

In the wiki there's
--- snip ---
Note: It is insufficient to simply install the newly compiled debug
package, because the debugger will check that the file containing the debug
symbols is from the same build as the associated library and executable.
You must install both of the recompiled packages. In Arch, the debug
symbols files are installed under /usr/lib/debug. See the GDB documentation
for more information about debug packages.
--- snip ---

But as a non c/c++ dev this doesn't say anything. What do I need to
install/run and where?

So could the wiki page be enhanced by adding concrete example(s)?

Original bug report: https://bugs.archlinux.org/task/51480
--
Pekka Järvinen
Martin Kühne via arch-general
2017-02-02 00:05:31 UTC
Reply
Permalink
Raw Message
So uh for all this to take effect you have to do the updates on the
PKGBUILD options=(!strip debug) most notably I guess... not sure what
makepkg.conf adjustments you made, but I'm pretty sure the main
lifting is up to these two options being set.

Is it possible that you would share the makepkg.conf you were using as
well as the PKGBUILD you were doing the build with?

cheers!
mar77i
Pekka Järvinen via arch-general
2017-02-02 00:16:54 UTC
Reply
Permalink
Raw Message
Hi,

Here's the configs:

lxrandr:
% cat PKGBUILD
# $Id: PKGBUILD 162929 2016-02-21 01:19:49Z bgyorgy $
# Maintainer: Sergej Pupykin <pupykin.s+***@gmail.com>
# Contributor: Geoffroy Carrier <***@koon.fr>

options=(debug !strip)
pkgbase=lxrandr
pkgname=(lxrandr lxrandr-gtk3)
pkgver=0.3.1
pkgrel=1
pkgdesc="Monitor configuration tool (part of LXDE)"
arch=('i686' 'x86_64')
license=('GPL2')
url="http://lxde.org/"
depends=('gtk2' 'gtk3' 'xorg-xrandr')
makedepends=('intltool')
source=("http://downloads.sourceforge.net/lxde/$pkgbase-$pkgver.tar.xz")
md5sums=('b327938f18a4baac85c4707f927d606e')

build() {
export CFLAGS="$CFLAGS -O0 -fbuiltin -g"
export CXXFLAGS="$CXXFLAGS -O0 -fbuiltin -g"
# GTK+ 2 version
[ -d gtk2 ] || cp -r $pkgbase-$pkgver gtk2
cd gtk2
./configure --sysconfdir=/etc --prefix=/usr
make

cd "$srcdir"
# GTK+ 3 version
[ -d gtk3 ] || cp -r $pkgbase-$pkgver gtk3
cd gtk3
./configure --sysconfdir=/etc --prefix=/usr --enable-gtk3
make
}

package_lxrandr() {
groups=('lxde')
depends=('gtk2' 'xorg-xrandr')

cd gtk2
make DESTDIR="$pkgdir" install
}

package_lxrandr-gtk3() {
groups=('lxde-gtk3')
pkgdesc+=' (GTK+ 3 version)'
depends=('gtk3' 'xorg-xrandr')
conflicts=('lxrandr')

cd gtk3
make DESTDIR="$pkgdir" install
}

-----------------
% cat /etc/makepkg-debug.conf | grep -v ^#

DLAGENTS=('ftp::/usr/bin/curl -fC - --ftp-pasv --retry 3 --retry-delay 3 -o
%o %u'
'http::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
'https::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
'rsync::/usr/bin/rsync --no-motd -z %u %o'
'scp::/usr/bin/scp -C %u %o')


VCSCLIENTS=('bzr::bzr'
'git::git'
'hg::mercurial'
'svn::subversion')

CARCH="x86_64"
CHOST="x86_64-pc-linux-gnu"

CPPFLAGS="-D_FORTIFY_SOURCE=2"
CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong"
CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong"
LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro"
DEBUG_CFLAGS="-g -fvar-tracking-assignments"
DEBUG_CXXFLAGS="-g -fvar-tracking-assignments"

BUILDENV=(!distcc color !ccache check !sign)

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

INTEGRITY_CHECK=(md5)
STRIP_BINARIES="--strip-all"
STRIP_SHARED="--strip-unneeded"
STRIP_STATIC="--strip-debug"
MAN_DIRS=({usr{,/local}{,/share},opt/*}/{man,info})
DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc})
PURGE_TARGETS=(usr/{,share}/info/dir .packlist *.pod)


COMPRESSGZ=(gzip -c -f -n)
COMPRESSBZ2=(bzip2 -c -f)
COMPRESSXZ=(xz -c -z -)
COMPRESSLRZ=(lrzip -q)
COMPRESSLZO=(lzop -q)
COMPRESSZ=(compress -c -f)

PKGEXT='.pkg.tar.xz'
SRCEXT='.src.tar.gz'



2017-02-02 2:05 GMT+02:00 Martin Kühne via arch-general <
Post by Martin Kühne via arch-general
So uh for all this to take effect you have to do the updates on the
PKGBUILD options=(!strip debug) most notably I guess... not sure what
makepkg.conf adjustments you made, but I'm pretty sure the main
lifting is up to these two options being set.
Is it possible that you would share the makepkg.conf you were using as
well as the PKGBUILD you were doing the build with?
cheers!
mar77i
--
Pekka Järvinen
Christoph Gysin via arch-general
2017-02-02 10:50:14 UTC
Reply
Permalink
Raw Message
Post by Pekka Järvinen via arch-general
I've installed ABS, modified PKGBUILD and made my own /etc/makepkg-dev.conf
No need to change both makepkg.conf and the PKGBUILD. Either will do.
Post by Pekka Järvinen via arch-general
makepkg -sf --config /etc/makepkg-dev.conf generates the executable.
This will only build the package. Make sure to install it, or use
'makepkg -sfi' to install it automatically.
Post by Pekka Järvinen via arch-general
Still gdb gives very little info after running
cd lxrandr/pkg/lxrandr/usr/bin
gdb -ex "set logging file debug.log" -ex "set logging overwrite on" -ex
"thread apply all bt full" -ex "set logging on" -ex "run" -ex "backtrace"
-ex "frame 0" -ex "kill" -ex "quit" ./lxrandr
I'm guessing because I need to add debugging to libraries which lxrandr is
using too.
You should see symbols for the stackframes in lxrandr, but stackframes
inside libraries might not resolve until you also build debug versions
for them.
Post by Pekka Järvinen via arch-general
In the wiki there's
--- snip ---
Note: It is insufficient to simply install the newly compiled debug
package, because the debugger will check that the file containing the debug
symbols is from the same build as the associated library and executable.
You must install both of the recompiled packages. In Arch, the debug
symbols files are installed under /usr/lib/debug. See the GDB documentation
for more information about debug packages.
--- snip ---
This is referring to using split debug packages. When using
option=(debug) without !split, makepkg will create a separate package
with debug symbols. If using this approach, you must install both,
simply installing the symbols won't work because they have to match
the binary they were built for.
Post by Pekka Järvinen via arch-general
But as a non c/c++ dev this doesn't say anything. What do I need to
install/run and where?
You most likely need to install debug symbols for the libraries used
when lxrandr crashes.

Chris
Pekka Järvinen via arch-general
2017-02-02 13:54:15 UTC
Reply
Permalink
Raw Message
Hi,

This will only build the package. Make sure to install it, or use
Post by Christoph Gysin via arch-general
'makepkg -sfi' to install it automatically.
% makepkg -sfi
...
loading packages...
warning: lxrandr-0.3.1-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...
error: unresolvable package conflicts detected
error: failed to prepare transaction (conflicting dependencies)
:: lxrandr-gtk3 and lxrandr are in conflict
==> WARNING: Failed to install built package(s).

Ok, let's try with pacman:

% sudo pacman -U lxrandr-0.3.1-1-x86_64.pkg.tar.xz
loading packages...
warning: lxrandr-0.3.1-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Packages (1) lxrandr-0.3.1-1

Total Installed Size: 0.22 MiB
Net Upgrade Size: 0.01 MiB

:: Proceed with installation? [Y/n]
(1/1) checking keys in keyring

[####################################################################] 100%
(1/1) checking package integrity

[####################################################################] 100%
(1/1) loading package files

[####################################################################] 100%
(1/1) checking for file conflicts

[####################################################################] 100%
(1/1) checking available disk space

[####################################################################] 100%
:: Processing package changes...
(1/1) reinstalling lxrandr

[####################################################################] 100%
:: Running post-transaction hooks...
(1/2) Arming ConditionNeedsUpdate...
(2/2) Updating the desktop file MIME type cache...

% lxrandr
zsh: segmentation fault (core dumped) lxrandr

Still crashing as expected.

% gdb lxrandr
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from lxrandr...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/lxrandr
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00000000004035d4 in main ()
(gdb)

But still no proper info..
Post by Christoph Gysin via arch-general
You most likely need to install debug symbols for the libraries used
when lxrandr crashes.
So how/where I can find out what I need to install?
--
Pekka Järvinen
Neven Sajko via arch-general
2017-02-02 19:32:24 UTC
Reply
Permalink
Raw Message
A few notes:

You can use, eg., the file command to check if executables are stripped.
(with something like "file /bin/executable")
But gdb already tells you that no debugging symbols were found for the
executable.

Thus, you either need install an lxrandr package with debugging
symbols (with -g and unstripped),
or (if you splitted out the debugging symbols during the build)
install lxrandr together with its split debugging symbols.
Neven Sajko via arch-general
2017-02-02 19:34:46 UTC
Reply
Permalink
Raw Message
BTW, maybe arandr would suffice as a replacement for lxrandr?
Neven Sajko via arch-general
2017-02-02 19:43:40 UTC
Reply
Permalink
Raw Message
After glimpsing through your makepkg and PKGBUILD:

Are you sure you are using makepkg-debug.conf instead of makepkg.conf
as the config?

Since you are a beginner, maybe it would have been better to first
just compile lxrandr manually, instead of with makepkg.
Pekka Järvinen via arch-general
2017-02-03 00:37:53 UTC
Reply
Permalink
Raw Message
Hi,

2017-02-02 21:43 GMT+02:00 Neven Sajko via arch-general <
Post by Neven Sajko via arch-general
Since you are a beginner, maybe it would have been better to first
just compile lxrandr manually, instead of with makepkg.
This finally provided results!

main (argc=<optimized out>, argv=<optimized out>) at lxrandr.c:783
783 fixed = LVDS ? LVDS : monitors->data;

I would suggest mentioning this manual compiling to the wiki page
https://wiki.archlinux.org/index.php/Debug_-_Getting_Traces so that others
don't need to use hours/days figuring out this again.

And yes, I used the makepkg-debug.conf without getting debug info.
--
Pekka Järvinen
Ralf Mardorf
2017-02-03 01:08:51 UTC
Reply
Permalink
Raw Message
Post by Pekka Järvinen via arch-general
I would suggest mentioning this manual compiling to the wiki page
Hi,

IMO using a PKGBUILD from ABS and changing options by the PKGBUILD or a
config is the easiest way to go. Compiling without building a package
could lead to issues. Could the package be removed or does it require
to at least build a dummy package, to resolve dependencies? Or, if a
user keeps a package, will installing without a package overwrite the
files provided by the package, or will it become a mess of manually
installed files and files installed by the package? The best approach
seems to be, to rebuild the package with the required options and then
to replace the installed package by the new package. FWIW everybody
could edit the Wiki ;).

Regards,
Ralf
Christoph Gysin via arch-general
2017-02-03 14:50:18 UTC
Reply
Permalink
Raw Message
On Fri, Feb 3, 2017 at 2:37 AM, Pekka Järvinen via arch-general
Post by Pekka Järvinen via arch-general
This finally provided results!
main (argc=<optimized out>, argv=<optimized out>) at lxrandr.c:783
783 fixed = LVDS ? LVDS : monitors->data;
At this point, lxrandr has crashed and you are left at the gdb prompt.
Type "bt" to create a backtrace showing all functions and line numbers
of the current call stack. In your example, lxrandr is crashing in
main(), so there is only one stack frame.

Also, it might help the developers to print the values of relevant
variables. In the above example, it looks like LVDS evaluates to
false, and monitors is NULL, causing the segfault. You can confirm
this by printing those variables at the prompt, and include it in your
bug report:

(gdb) p LVDS
...
(gdb) p monitors
...
Post by Pekka Järvinen via arch-general
I would suggest mentioning this manual compiling to the wiki page
https://wiki.archlinux.org/index.php/Debug_-_Getting_Traces so that others
don't need to use hours/days figuring out this again.
Manual compiling is not the recommended way.

Chris
--
echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" ***@fr33z3
Christoph Gysin via arch-general
2017-02-03 14:31:06 UTC
Reply
Permalink
Raw Message
On Thu, Feb 2, 2017 at 3:54 PM, Pekka Järvinen via arch-general
Post by Pekka Järvinen via arch-general
% makepkg -sfi
...
error: unresolvable package conflicts detected
error: failed to prepare transaction (conflicting dependencies)
:: lxrandr-gtk3 and lxrandr are in conflict
Ah, in this case -i won't work because the PKGBUILD builds two
conflicting versions, and -i tries to install them all.
Post by Pekka Järvinen via arch-general
% sudo pacman -U lxrandr-0.3.1-1-x86_64.pkg.tar.xz
...
Packages (1) lxrandr-0.3.1-1
Total Installed Size: 0.22 MiB
Net Upgrade Size: 0.01 MiB
This seems too small to contain the debug symbols. Something went
wrong during your build. Try to clean the build dir and try again,
using the upstream PKGBUILD and simply adding:

options+=(debug)

Building it should result in packages lxrandr-0.3.1-1 and
lxrandr-debug-0.3.1-1. Installing both should get you proper
backtraces.
Post by Pekka Järvinen via arch-general
% gdb lxrandr
...
Reading symbols from lxrandr...(no debugging symbols found)...done.
This indicates that you have no debug symbols for lxrandr.

Chris
--
echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" ***@fr33z3
Loading...