[PATCH] Add basic find-debuginfo script tests
Martin Cermak
mcermak@redhat.com
Fri Jun 13 09:01:27 GMT 2025
Hi Mark,
On Fri 2025-06-13 00:43 , Mark Wielaard wrote:
> Covers basic find-debuginfo script functionality. Checks .debug files
> are generated by eu-strip, .gnu_debugdata is generated, .gdb_index is
> added by gdb-add-index, dwz multi file is created and all debugsources
> are found.
>
> * tests/Makefile.am (TESTSUITE_AT): Add find-debuginfo.at.
> * tests/testsuite.at: m4_include find-debuginfo.at.
> * tests/find-debuginfo.at: New test file.
>
> Signed-off-by: Mark Wielaard <mark@klomp.org>
> ---
>
> I recently claimed debugedit already had a test like this that would
> catch when some of the tools used by find-debuginfo were broken. Turns
> out I was just imagining things. There was no such test (yet).
>
> So I wrote this. It adds a basic find-debuginfo script test that
> should catch issues if the tools used (eu-strip, gdb-add-index, dwz)
> are really broken.
>
> It is based on the test setup that Frank wrote for the handling of
> static archives (that means this patch will have merge conflicts with
> that one, sorry Frank).
>
> It doesn't test very specific things, but it is a start.
>
> tests/Makefile.am | 3 +-
> tests/find-debuginfo.at | 108 ++++++++++++++++++++++++++++++++++++++++
> tests/testsuite.at | 1 +
> 3 files changed, 111 insertions(+), 1 deletion(-)
> create mode 100644 tests/find-debuginfo.at
>
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index b1d39f4ac1fc..7fab084f31f2 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -32,7 +32,8 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
> # The tests
> TESTSUITE_AT = \
> testsuite.at \
> - debugedit.at
> + debugedit.at \
> + find-debuginfo.at
>
> # Some source files that are needed by the tests
> EXTRA_DIST += data/SOURCES/foo.c \
> diff --git a/tests/find-debuginfo.at b/tests/find-debuginfo.at
> new file mode 100644
> index 000000000000..f968db0f43c4
> --- /dev/null
> +++ b/tests/find-debuginfo.at
> @@ -0,0 +1,108 @@
> +# find-debuginfo.at: Tests for the find-debuginfo script
> +#
> +# Copyright (C) 2025 Red Hat Inc.
> +# Copyright (C) 2025 Mark J. Wielaard <mark@klomp.org>
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, see see <http://www.gnu.org/licenses/>.
> +
> +# Tests for scripts/find-debuginfo.in
> +AT_BANNER([find-debuginfo])
> +
> +# Show which find-debuginfo script we are testing
> +AT_TESTED([find-debuginfo])
> +
> +# Helper to create some test binaries
> +m4_define([FIND_DEBUGINFO_PKG_BUILD_SETUP],[[
> +mkdir subdir_build
> +cp "${abs_srcdir}"/data/SOURCES/foo.c subdir_build
> +cp "${abs_srcdir}"/data/SOURCES/bar.c subdir_build
> +cp "${abs_srcdir}"/data/SOURCES/foobar.h subdir_build
> +cp "${abs_srcdir}"/data/SOURCES/baz.c subdir_build
> +cd subdir_build
> +# Three almost identical binaries
> +# so dwz has something to put into the alt file
> +$CC $CFLAGS -g3 -I. -o foo foo.c bar.c baz.c
> +$CC $CFLAGS -g3 -I. -o bar bar.c baz.c foo.c
> +$CC $CFLAGS -g3 -I. -o baz baz.c foo.c bar.c
> +cd ..
> +]])
> +
> +# Check find-debuginfo --help doesn't crash and burn
> +AT_SETUP([find-debuginfo help])
> +AT_KEYWORDS([find-debuginfo] [help])
> +AT_CHECK([find-debuginfo --help],[0],[ignore],[ignore])
> +AT_CLEANUP
> +
> +# Run find-debuginfo on a small build and check all parts ran
> +AT_SETUP([find-debuginfo run])
> +AT_KEYWORDS([find-debuginfo] [debuginfo] [sourcefiles] [gdb-index] [dwz])
> +FIND_DEBUGINFO_PKG_BUILD_SETUP
> +# Sanity check the binaries have debug sections
> +AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [0], [ignore], [])
> +AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [0], [ignore], [])
> +AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [0], [ignore], [])
> +# We need to set some environment variables for running find-debuginfo
> +# normally set by rpmbuild.
> +#
> +# generate .gnu_debugdata (-m), .gdb_index (-i) and run dwz (--run-dwz)
> +# for binaries in subdir_build.
> +AT_CHECK([env RPM_BUILD_DIR=${PWD} \
> + RPM_BUILD_ROOT=${PWD} \
> + RPM_PACKAGE_NAME=pkg \
> + RPM_PACKAGE_VERSION=ver \
> + RPM_PACKAGE_RELEASE=rel \
> + RPM_ARCH=arch \
> + find-debuginfo -m -i --run-dwz ${PWD}/subdir_build],
> + [0], [stdout], [])
> +# Make sure all three binaries are processed
> +AT_CHECK([grep "Extracting debug info from 3 files" stdout], [0], [ignore], [])
> +AT_CHECK([grep "DWARF-compressing 3 files" stdout], [0], [ignore], [])
> +# debug sections should have been removed
> +AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [1], [ignore], [])
> +AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [1], [ignore], [])
> +AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [1], [ignore], [])
> +# But they now have a .gnu_debugdata section
> +AT_CHECK([$READELF -S subdir_build/foo | grep gnu_debugdata],
> + [0], [ignore], [])
> +AT_CHECK([$READELF -S subdir_build/bar | grep gnu_debugdata],
> + [0], [ignore], [])
> +AT_CHECK([$READELF -S subdir_build/baz | grep gnu_debugdata],
> + [0], [ignore], [])
> +# There are .debug files with those .debug_ sections
> +AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
> + [0], [ignore], [])
> +AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
> + [0], [ignore], [])
> +AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
> + [0], [ignore], [])
> +# The .debug files should also have a .gdb_index sections
> +AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep gdb_index],
> + [0], [ignore], [])
> +AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep gdb_index],
> + [0], [ignore], [])
> +AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep gdb_index],
> + [0], [ignore], [])
> +# There should also be a dwz multi file now
> +AT_CHECK([test -f usr/lib/debug/.dwz/pkg-ver-rel.arch], [0], [], [])
> +# Check all sources are listed in debugsources.list
> +AT_DATA([expout],
> +[subdir_build/
> +subdir_build/bar.c
> +subdir_build/baz.c
> +subdir_build/foo.c
> +subdir_build/foobar.h
> +])
> +AT_CHECK([cat subdir_build/debugsources.list | tr '\0' '\n' | sort -u],
> + [0], [expout], [])
> +AT_CLEANUP
> diff --git a/tests/testsuite.at b/tests/testsuite.at
> index baf7ca2c81c6..d7027f0039d5 100644
> --- a/tests/testsuite.at
> +++ b/tests/testsuite.at
> @@ -10,3 +10,4 @@ AT_INIT
> AT_TESTED([debugedit])
>
> m4_include([debugedit.at])
> +m4_include([find-debuginfo.at])
> --
> 2.49.0
>
This does work for me. The patch applies cleanly on top of
currently latest 1a2cef32e5face9fc943c0b11759c6e8c7e0c765, and
with this patch:
Using gdb-14.2-4.1.el10_0.x86_64 and dwz-0.15-7.el10.x86_64 all
tests are green. After upgrading to gdb-16.3-2.el10.x86_64, the
newly added 37: find-debuginfo run FAILED (find-debuginfo.at:90)
I can also reproduce by gcc hello.c -g -o hello; gdb-add-index
./hello; eu-readelf -S hello | fgrep index; dwz hello; eu-readelf
-S hello | fgrep index. This also shows how the .gdb_index
section is added, but then will vanish after applying dwz in case
gdb-16 was used.
So this does work for me as expected.
Thank you,
Martin
More information about the Debugedit
mailing list