Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 922336 - dev-debug/gdb-14.1: Segmentation fault when running `list .`
Summary: dev-debug/gdb-14.1: Segmentation fault when running `list .`
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2024-01-17 23:35 UTC by Christopher Fore
Modified: 2024-01-24 07:31 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
fixes segfault with no debugsyms (fix-list-segfault.patch,3.49 KB, patch)
2024-01-23 15:54 UTC, Christopher Fore
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Fore 2024-01-17 23:35:12 UTC
Test program:
```
int main() {}
```

Steps to reproduce:
1. emerge -1 =dev-debug/gdb-14.1
2. Compile test program (gcc/clang main.c)
3. gdb ./a.out
4. Set a breakpoint on main, `b main`
5. `run`
6. `list .` and the segfault should occur

Tested with: GCC 14, GCC 13, Clang 17 and all three resulted in a segmentation fault. The test program was compiled with GCC and Clang as well.

```
----- Backtrace -----
0x555f641fb514 _ZL24gdb_internal_backtrace_1v
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/bt-utils.c:122
0x555f641fb514 _Z22gdb_internal_backtracev
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/bt-utils.c:168
0x555f64311d36 _ZL19handle_fatal_signali
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/event-top.c:889
0x555f643125f1 _ZL14handle_sigsegvi
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/event-top.c:962
0x7fb9d226b0cf ???
0x555f644fcb4b _Z18symtab_to_fullnameP6symtab
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/source.c:1239
0x555f644f860f _ZN12source_cache6ensureEP6symtab
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/source-cache.c:199
0x555f644f9127 _ZN12source_cache16get_source_linesEP6symtabiiPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/source-cache.c:364
0x555f644fce85 _ZL23print_source_lines_baseP6symtabii10enum_flagsI23print_source_lines_flagE
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/source.c:1381
0x555f64229494 _ZL16list_around_linePKc15symtab_and_line
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/cli/cli-cmds.c:1222
0x555f64229494 _ZL12list_commandPKci
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/cli/cli-cmds.c:1294
0x555f6423293c _Z8cmd_funcP16cmd_list_elementPKci
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/cli/cli-decode.c:2735
0x555f64572208 _Z15execute_commandPKci
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/top.c:575
0x555f643114dd _Z15command_handlerPKc
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/event-top.c:552
0x555f64311871 _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/event-top.c:788
0x555f64310c99 _ZL23gdb_rl_callback_handlerPc
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/event-top.c:259
0x7fb9d307d72c ???
0x555f6431235d _ZL42gdb_rl_callback_read_char_wrapper_noexceptv
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/event-top.c:195
0x555f643107ea _ZL33gdb_rl_callback_read_char_wrapperPv
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/event-top.c:234
0x555f645aac9c _ZL19stdin_event_handleriPv
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/ui.c:155
0x555f646d86d9 _ZL18gdb_wait_for_eventi
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdbsupport/event-loop.cc:0
0x555f646d8177 _Z16gdb_do_one_eventi
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdbsupport/event-loop.cc:264
0x555f643e7149 _ZL16start_event_loopv
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/main.c:407
0x555f643e7149 _ZL21captured_command_loopv
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/main.c:471
0x555f643e3ead _ZL13captured_mainPv
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/main.c:1324
0x555f643e3ead _Z8gdb_mainP18captured_main_args
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/main.c:1343
0x555f641548e9 main
	/var/tmp/portage/dev-debug/gdb-14.1/work/gdb-14.1/gdb/gdb.c:39
---------------------
A fatal error internal to GDB has been detected, further
debugging is not possible.  GDB will now terminate.

This is a bug, please report it.  For instructions, see:
<https://bugs.gentoo.org/>.

Segmentation fault
```


`bt` from running gdb inside gdb:
```
(gdb) bt
#0  symtab_to_fullname (s=0x0) at source.c:1239
#1  0x0000555555917610 in source_cache::ensure (this=0x555555e635a8 <g_source_cache>, s=0x0)
    at source-cache.c:199
#2  0x0000555555918128 in source_cache::get_source_lines (this=0x0, s=0x0, first_line=1, last_line=10,
    lines=0x7fffffffd1f0) at source-cache.c:364
#3  0x000055555591be86 in print_source_lines_base (s=0x0, line=1, stopline=11, flags=...)
    at source.c:1381
#4  0x0000555555648495 in list_around_line (arg=0x555555e82ea5 ".", cursal=...) at cli/cli-cmds.c:1222
#5  list_command (arg=0x555555e82ea5 ".", from_tty=1) at cli/cli-cmds.c:1294
#6  0x000055555565193d in cmd_func (cmd=0x7cfe9fa5fa97e000, cmd@entry=0x555555f51c80, args=0x0,
    args@entry=0x555555e82ea5 ".", from_tty=0, from_tty@entry=1) at cli/cli-decode.c:2735
#7  0x0000555555991209 in execute_command (p=<optimized out>, p@entry=0x555555e82ea0 "list .",
    from_tty=1) at top.c:575
#8  0x00005555557304de in command_handler (command=0x555555e82ea0 "list .") at event-top.c:552
#9  0x0000555555730872 in command_line_handler (rl=...) at event-top.c:788
#10 0x000055555572fc9a in gdb_rl_callback_handler (rl=0x555555e84f20 "list .") at event-top.c:259
#11 0x00007ffff7f7b72d in rl_callback_read_char () from /usr/lib64/libreadline.so.8
#12 0x000055555573135e in gdb_rl_callback_read_char_wrapper_noexcept () at event-top.c:195
#13 0x000055555572f7eb in gdb_rl_callback_read_char_wrapper (client_data=<optimized out>)
    at event-top.c:234
#14 0x00005555559c9c9d in stdin_event_handler (error=<optimized out>, client_data=0x555555e82bf0)
    at ui.c:155
#15 0x0000555555af76da in gdb_wait_for_event (block=block@entry=1) at event-loop.cc:716
#16 0x0000555555af7178 in gdb_do_one_event (mstimeout=mstimeout@entry=-1) at event-loop.cc:264
#17 0x000055555580614a in start_event_loop () at main.c:407
#18 captured_command_loop () at main.c:471
#19 0x0000555555802eae in captured_main (data=<optimized out>) at main.c:1324
#20 gdb_main (args=0x7fffffffd7e8) at main.c:1343
#21 0x00005555555738ea in main (argc=2, argv=0x7fffffffd928) at gdb.c:39
```


This does not occur in dev-debug/gdb-13.2-r2
Comment 1 Christopher Fore 2024-01-17 23:35:31 UTC
$ emerge --info gdb
Portage 3.0.61 (python 3.12.1-final-0, default/linux/amd64/23.0/desktop, gcc-14, glibc-2.38-r9, 6.6.10-gentoo-dist x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-6.6.10-gentoo-dist-x86_64-AMD_Ryzen_9_5900HX_with_Radeon_Graphics-with-glibc2.38
KiB Mem:    32184756 total,   5950892 free
KiB Swap:    8011772 total,   8011772 free
Timestamp of repository guru: Mon, 15 Jan 2024 16:18:32 +0000
Head commit of repository guru: 48e95ac7fad1d5b23f72e6cae26a96f9f31ac7aa

Head commit of repository librewolf: 2e7225f295e1c6fda913be45be6111ba26149a39

Timestamp of repository riscv: Mon, 15 Jan 2024 16:18:41 +0000
Head commit of repository riscv: 7d51af6a95379ed71ecd880b78cc82e9dfaf79ae

Timestamp of repository steam-overlay: Mon, 15 Jan 2024 16:18:24 +0000
Head commit of repository steam-overlay: e2c585d13cfab05881ff77b0254dcb40ef2a1d8c

Head commit of repository gentoo: eb857ea390272700426d1181599a5e6ae1934550

sh dash 0.5.12
ld GNU ld (Gentoo 2.41 p4) 2.41.0
app-misc/pax-utils:        1.3.7::gentoo
app-shells/bash:           5.2_p26::gentoo
dev-build/autoconf:        2.13-r8::gentoo, 2.72-r1::gentoo
dev-build/automake:        1.16.5-r1::gentoo
dev-build/cmake:           3.27.7::local
dev-build/libtool:         2.4.7-r2::gentoo
dev-build/make:            4.4.1-r1::gentoo
dev-build/meson:           1.3.1::gentoo
dev-java/java-config:      2.3.3-r1::gentoo
dev-lang/perl:             5.38.2-r1::gentoo
dev-lang/python:           3.11.7::gentoo, 3.12.1_p1::gentoo
dev-lang/rust:             1.74.1::gentoo
sys-apps/baselayout:       2.14-r1::gentoo
sys-apps/openrc:           0.53::gentoo
sys-apps/sandbox:          2.38::gentoo
sys-devel/binutils:        2.41-r4::gentoo
sys-devel/binutils-config: 5.5::gentoo
sys-devel/clang:           16.0.6::gentoo, 17.0.6::gentoo
sys-devel/gcc:             13.2.1_p20231216::gentoo, 14.0.1_pre20240114::gentoo
sys-devel/gcc-config:      2.11::gentoo
sys-devel/lld:             16.0.6::gentoo, 17.0.6::gentoo
sys-devel/llvm:            16.0.6::gentoo, 17.0.6::gentoo
sys-kernel/linux-headers:  6.6::gentoo (virtual/os-headers)
sys-libs/glibc:            2.38-r9::gentoo
Repositories:

guru
    location: /var/db/repos/guru
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/guru.git
    masters: gentoo
    volatile: False

librewolf
    location: /var/db/repos/librewolf
    sync-type: git
    sync-uri: https://codeberg.org/librewolf/gentoo.git
    masters: gentoo
    volatile: False

local
    location: /var/db/repos/local
    masters: gentoo
    volatile: False

riscv
    location: /var/db/repos/riscv
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/riscv.git
    masters: gentoo
    volatile: False

steam-overlay
    location: /var/db/repos/steam-overlay
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/steam-overlay.git
    masters: gentoo
    volatile: False

crossdev
    location: /var/db/repos/crossdev
    masters: gentoo
    priority: 10
    volatile: False

gentoo
    location: /var/db/repos/gentoo
    sync-type: git
    sync-uri: https://github.com/gentoo/gentoo
    priority: 1000
    volatile: False

Installed sets: @gcc-testing
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* @FREE @BINARY-REDISTRIBUTABLE"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe -fdiagnostics-color=always"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt /usr/share/maven-bin-3.9/conf"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=native -O2 -pipe -fdiagnostics-color=always"
DISTDIR="/var/cache/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GDK_PIXBUF_MODULE_FILE GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME"
FCFLAGS="-march=native -O2 -pipe -fdiagnostics-color=always"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg buildpkg-live candy config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox pkgdir-index-trusted preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-march=native -O2 -pipe -fdiagnostics-color=always"
GENTOO_MIRRORS="https://mirrors.rit.edu/gentoo/"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs"
LEX="flex"
MAKEOPTS="-j10"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
SHELL="/bin/bash"
USE="X a52 aac acl acpi alsa amd64 bluetooth branding bzip2 cairo cdda cdr crypt cups dbus dri dts dvd dvdr elogind encode exif flac gdbm gif gpm gtk gui iconv icu ipv6 jpeg lcms libnotify libtirpc lzma mad mng mp3 mp4 mpeg multilib ncurses nls ogg opengl pam pango pcre pdf pipewire png policykit ppds pulseaudio qt5 readline screencast sdl seccomp sound spell ssl startup-notification svg test-rust tiff truetype udev udisks unicode upower usb vaapi vdpau vorbis vulkan wayland wifi wxwidgets x264 xattr xcb xft xml xv xvid zlib zstd" ABI_X86="64" ADA_TARGET="gnat_2021" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_anon authn_dbm authn_file authz_dbm authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir env expires ext_filter file_cache filter headers include info log_config logio mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2 aes avx avx2 f16c fma3 pclmul popcnt rdrand sha sse3 sse4_1 sse4_2 sse4a ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 ntrip navcom oceanserver oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 tsip tripmate tnt ublox" INPUT_DEVICES="libinput synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz glk hd44780 lb216 lcdm001 mtxorb text" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php8-1" POSTGRES_TARGETS="postgres15" PYTHON_SINGLE_TARGET="python3_11" PYTHON_TARGETS="python3_11 python3_12 pypy3" RUBY_TARGETS="ruby31" VIDEO_CARDS="amdgpu radeonsi" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipp2p iface geoip fuzzy condition tarpit sysrq proto logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PYTHONPATH, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS

=================================================================
                        Package Settings
=================================================================

dev-debug/gdb-14.1::gentoo was built with the following:
USE="lzma nls python server xml zstd (-cet) -debuginfod -guile -multitarget -sim -source-highlight -test -vanilla -xxhash" ABI_X86="(64)" PYTHON_SINGLE_TARGET="python3_11 -python3_10 -python3_12"
CFLAGS="-march=native -O2 -pipe -fdiagnostics-color=always -ggdb3"
CXXFLAGS="-march=native -O2 -pipe -fdiagnostics-color=always -ggdb3"
FEATURES="fixlafiles userpriv compressdebug pkgdir-index-trusted distlocks sandbox userfetch sfperms binpkg-dostrip qa-unresolved-soname-deps usersync strict buildpkg unmerge-orphans usersandbox network-sandbox candy protect-owned news merge-sync splitdebug config-protect-if-modified ipc-sandbox unknown-features-warn assume-digests preserve-libs buildpkg-live parallel-fetch ebuild-locks unmerge-logs binpkg-logs pid-sandbox binpkg-docompress xattr multilib-strict binpkg-multi-instance"
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-01-18 04:57:32 UTC
Thank you, especially for the straightforward reproducer. Reported at https://sourceware.org/bugzilla/show_bug.cgi?id=31256.
Comment 3 Christopher Fore 2024-01-18 15:02:58 UTC
Thanks! I just tried it on the live ebuild and it has the segfault too.
Comment 4 Christopher Fore 2024-01-18 20:24:45 UTC
Bisected to 3e3a1874fcec34bcf51b4baf4be09aebab561bff

(https://sourceware.org/bugzilla/show_bug.cgi?id=31256#c1)
Comment 5 Christopher Fore 2024-01-23 15:54:09 UTC
Created attachment 882986 [details, diff]
fixes segfault with no debugsyms

Here's the patch from upstream, I tested it on head and 14.1 and both worked.
Comment 6 Larry the Git Cow gentoo-dev 2024-01-24 07:31:58 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a32e214f465b7e90dca9fd6c6439a5bc563daa41

commit a32e214f465b7e90dca9fd6c6439a5bc563daa41
Author:     Christopher Fore <csfore@posteo.net>
AuthorDate: 2024-01-23 16:56:41 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-01-24 07:31:05 +0000

    dev-debug/gdb: Backport patches for 14.1
    
    - fix-list-segfault.patch:
       Fixes segfault encountered when running gdb on an executable without
       debugging symbols
    
    - fix-dll-export-forwarding.patch:
       Fixes virtual memory address (VMA) calculating by making it relative
       to DLL_NAME again.
    
    - fix-print-global-variable-stubs.patch:
       Fixes printing of global variable stubs if no inferior is running by
       adding a missing nullptr check
    
    All tests pass.
    
    Closes: https://bugs.gentoo.org/922336
    Signed-off-by: Christopher Fore <csfore@posteo.net>
    Closes: https://github.com/gentoo/gentoo/pull/34978
    Signed-off-by: Sam James <sam@gentoo.org>

 .../files/gdb-14.1-fix-dll-export-forwarding.patch |  60 ++++
 .../gdb/files/gdb-14.1-fix-list-segfault.patch     | 101 +++++++
 .../gdb-14.1-fix-print-global-variable-stubs.patch | 109 +++++++
 dev-debug/gdb/gdb-14.1-r1.ebuild                   | 317 +++++++++++++++++++++
 4 files changed, 587 insertions(+)