diff --git a/macros.debug b/macros.debug index 6a8432eb7a..d273c0876d 100644 --- a/macros.debug +++ b/macros.debug @@ -2,6 +2,7 @@ %_enable_debug_packages 1 %_include_minidebuginfo 1 +%_include_gdb_index 1 # Expanded at end of %install scriptlet diff --git a/macros.in b/macros.in index c79cfccf1f..205a1f3c62 100644 --- a/macros.in +++ b/macros.in @@ -178,7 +178,7 @@ # the script. See the script for details. # %__debug_install_post \ - %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_include_minidebuginfo:-m} %{?_unique_build_ids:--ver-rel "%{version}-%{release}"} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\ + %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_include_minidebuginfo:-m} %{?_include_gdb_index:-i} %{?_unique_build_ids:--ver-rel "%{version}-%{release}"} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\ %{nil} # Template for debug information sub-package. @@ -453,6 +453,12 @@ package or when debugging this package.\ # #%_include_minidebuginfo 1 +# +# Include a .gdb_index section in the .debug files. +# Requires _enable_debug_packages and gdb-add-index installed. +# +#%_include_gdb_index 1 + # # Defines how and if build_id links are generated for ELF files. # The following settings are supported: diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh index 97837157f7..ef0ca923f3 100644 --- a/scripts/find-debuginfo.sh +++ b/scripts/find-debuginfo.sh @@ -2,7 +2,7 @@ #find-debuginfo.sh - automagically generate debug info and file list #for inclusion in an rpm spec file. # -# Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m] +# Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m] [-i] # [-o debugfiles.list] # [--run-dwz] [--dwz-low-mem-die-limit N] # [--dwz-max-die-limit N] @@ -14,6 +14,8 @@ # The --strict-build-id flag says to exit with failure status if # any ELF binary processed fails to contain a build-id note. # The -r flag says to use eu-strip --reloc-debug-sections. +# The -m flag says to include a .gnu_debugdata section in the main binary. +# The -i flag says to include a .gdb_index section in the .debug file. # # A single -o switch before any -l or -p switches simply renames # the primary output file from debugfiles.list to something else. @@ -48,6 +50,9 @@ strip_r=false # with -m arg, add minimal debuginfo to binary. include_minidebug=false +# with -i arg, add GDB index to .debug file. +include_gdb_index=false + # Barf on missing build IDs. strict=false @@ -88,6 +93,9 @@ while [ $# -gt 0 ]; do -m) include_minidebug=true ;; + -i) + include_gdb_index=true + ;; -o) if [ -z "${lists[$nout]}" -a -z "${ptns[$nout]}" ]; then out=$2 @@ -266,7 +274,15 @@ while read nlinks inum f; do $strict && exit 2 fi - [ type gdb-add-index >/dev/null 2>&1 && gdb-add-index "$f" > /dev/null 2>&1 + # Add .gdb_index if requested. + if $include_gdb_index; then + if type gdb-add-index >/dev/null 2>&1; then + gdb-add-index "$f" + else + echo >&2 "*** ERROR: GDB index requested, but no gdb-add-index installed" + exit 2 + fi + fi # A binary already copied into /usr/lib/debug doesn't get stripped, # just has its file names collected and adjusted. @@ -292,7 +308,7 @@ while read nlinks inum f; do done || exit # Invoke the DWARF Compressor utility. -if $run_dwz && type dwz >/dev/null 2>&1 \ +if $run_dwz \ && [ -d "${RPM_BUILD_ROOT}/usr/lib/debug" ]; then dwz_files="`cd "${RPM_BUILD_ROOT}/usr/lib/debug"; find -type f -name \*.debug`" if [ -n "${dwz_files}" ]; then @@ -310,7 +326,12 @@ if $run_dwz && type dwz >/dev/null 2>&1 \ && dwz_opts="${dwz_opts} -l ${dwz_low_mem_die_limit}" [ -n "${dwz_max_die_limit}" ] \ && dwz_opts="${dwz_opts} -L ${dwz_max_die_limit}" - ( cd "${RPM_BUILD_ROOT}/usr/lib/debug" && dwz $dwz_opts $dwz_files ) + if type dwz >/dev/null 2>&1; then + ( cd "${RPM_BUILD_ROOT}/usr/lib/debug" && dwz $dwz_opts $dwz_files ) + else + echo >&2 "*** ERROR: DWARF compression requested, but no dwz installed" + exit 2 + fi # Remove .dwz directory if empty rmdir "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz" 2>/dev/null if [ -f "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz/${dwz_multifile_name}" ]; then diff --git a/tests/rpmbuild.at b/tests/rpmbuild.at index 1dd57e9249..97ab7cdae0 100644 --- a/tests/rpmbuild.at +++ b/tests/rpmbuild.at @@ -532,3 +532,64 @@ usr/local/bin/hello2 ], [ignore]) AT_CLEANUP + +# ------------------------------ +# Check that a GDB index is included when requested. +AT_SETUP([rpmbuild debuginfo gdb index included]) +AT_KEYWORDS([build] [debuginfo] [gdb]) +AT_CHECK([ +rm -rf ${TOPDIR} +AS_MKDIR_P(${TOPDIR}/SOURCES) + +# Build a package that has some debuginfo +cp "${abs_srcdir}"/data/SOURCES/hello-1.0.tar.gz "${abs_srcdir}"/data/SOURCES/hello-1.0-modernize.patch ${TOPDIR}/SOURCES + +run rpmbuild --quiet \ + --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \ + --rcfile=${abs_top_builddir}/rpmrc \ + --define "_include_gdb_index 1" \ + -ba "${abs_srcdir}"/data/SPECS/hello2.spec + +# Unpack the debuginfo rpms so we can check the .debug files. +rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello2-debuginfo-1.0-1.*.rpm \ + | cpio -diu --quiet + +# Check that gdb-add-index has ran and a .gdb_index section has been added +readelf -S ./usr/lib/debug/usr/local/bin/hello2*.debug \ + | grep gdb_index | cut -c8-17 +], +[0], +[.gdb_index +], +[ignore]) +AT_CLEANUP + +# ------------------------------ +# Check that a GDB index is NOT included when not requested. +AT_SETUP([rpmbuild debuginfo no gdb index included]) +AT_KEYWORDS([build] [debuginfo] [gdb]) +AT_CHECK([ +rm -rf ${TOPDIR} +AS_MKDIR_P(${TOPDIR}/SOURCES) + +# Build a package that has some debuginfo +cp "${abs_srcdir}"/data/SOURCES/hello-1.0.tar.gz "${abs_srcdir}"/data/SOURCES/hello-1.0-modernize.patch ${TOPDIR}/SOURCES + +run rpmbuild --quiet \ + --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \ + --rcfile=${abs_top_builddir}/rpmrc \ + --undefine "_include_gdb_index" \ + -ba "${abs_srcdir}"/data/SPECS/hello2.spec + +# Unpack the debuginfo rpms so we can check the .debug files. +rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello2-debuginfo-1.0-1.*.rpm \ + | cpio -diu --quiet + +# Check that gdb-add-index has not ran and no .gdb_index section has been added +readelf -S ./usr/lib/debug/usr/local/bin/hello2*.debug \ + | grep gdb_index | cut -c8-17 +], +[0], +[], +[ignore]) +AT_CLEANUP