diff --git a/Mk/Features/debuginfo.mk b/Mk/Features/debuginfo.mk new file mode 100644 --- /dev/null +++ b/Mk/Features/debuginfo.mk @@ -0,0 +1,34 @@ +# DEBUGINFO Support +# +# Add WITH_DEBUGINFO=yes into make.conf: +# - If set, the port will be compiled in the release mode but with debugging +# info generated. The debugging info is then extract from binaries and put +# into a separate subpackage called debuginfo. +# - If used in conjunction with WITH_DEBUG the port will be compiled in the +# debug mode. + +.if !defined(_DEBUGINFO_MK_INCLUDED) +_DEBUGINFO_MK_INCLUDED= yes +DEBUGINFO_Include_MAINTAINER= portmgr@FreeBSD.org + +# We need to do everything that Features/debug.mk does, but without setting +# WITH_DEBUG to prevent build systems from building in the complete debug mode. +# instead let them detect WITH_DEBUGINFO and build what meson calls "debugoptimized" +# and CMake calls "RelWithDebInfo". +. if !defined(WITH_DEBUG) +. include "debug.mk" +. endif + +SUBPACKAGES+= debuginfo +DESCR.debuginfo= ${WRKDIR}/descr.debuginfo +DEBUGINFO_EXTRACT_ENV= PREFIX=${PREFIX} LOCALBASE=${LOCALBASE} STAGEDIR=${STAGEDIR} \ + TMPPLIST=${TMPPLIST} PREPEND_SUBPACKAGE_PREFIX=yes + +_FEATURES_stage= 751:debuginfo-extract + +debuginfo-extract: + @${ECHO_CMD} "Debugging symbols for the ${PKGNAME} package" > ${DESCR.debuginfo} + @${ECHO_CMD} "====> Extracting debugging symbols from binaries" + @${SETENV} ${DEBUGINFO_EXTRACT_ENV} ${SH} ${SCRIPTSDIR}/generate-symbols.sh + +.endif diff --git a/Mk/Scripts/generate-symbols.sh b/Mk/Scripts/generate-symbols.sh --- a/Mk/Scripts/generate-symbols.sh +++ b/Mk/Scripts/generate-symbols.sh @@ -6,7 +6,6 @@ # For example: # /var/qmail/bin/qmaild -> /usr/local/lib/debug/var/qmail/bin/qmaild.debug # /usr/local/bin/ssh -> /usr/local/lib/debug/usr/local/bin/ssh.debug -LIB_DIR_PREFIX="${LOCALBASE}/lib/debug" set -o pipefail @@ -14,7 +13,15 @@ echo "====> $*" } -msg "Finding symbols" + +if [ -z "${PREFIX}" -o -z "${LOCALBASE}" -o -z "${STAGEDIR}" -o -z "${TMPPLIST}" ]; then + echo "PREFIX, LOCALBASE, STAGEDIR and TMPPLIST are required in environment." >&2 + exit 1 +fi + +if [ ! -z "${PREPEND_SUBPACKAGE_PREFIX}" ]; then + subpkg_prefix="@@debuginfo@@" +fi # Find all ELF files ELF_FILES=$(mktemp -t elf_files) @@ -25,7 +32,7 @@ > ${ELF_FILES} # Create all of the /usr/local/lib/* dirs -lib_dir="${STAGEDIR}${LIB_DIR_PREFIX}" +lib_dir="${STAGEDIR}${LOCALBASE}/lib/debug" sed -e "s,^${STAGEDIR}/,${lib_dir}/," -e 's,/[^/]*$,,' \ ${ELF_FILES} | sort -u | xargs mkdir -p @@ -40,8 +47,8 @@ # Strip and add a reference to f.debug for finding the symbols. objcopy --strip-debug --strip-unneeded \ --add-gnu-debuglink="${debug_file_name}" "${staged_elf_file}" - msg "Saved symbols for ${staged_elf_file}" - echo "${debug_file_name#${STAGEDIR}}" >&3 + msg "Saved symbols for ${staged_elf_file#${STAGEDIR}}" + echo "${subpkg_prefix}${debug_file_name#${STAGEDIR}}" >&3 done < ${ELF_FILES} 3>> ${TMPPLIST} # Need @dir entries if PREFIX != LOCALBASE diff --git a/Mk/Scripts/qa.sh b/Mk/Scripts/qa.sh --- a/Mk/Scripts/qa.sh +++ b/Mk/Scripts/qa.sh @@ -736,6 +736,8 @@ [ -z "${f}" ] && continue # Ignore symlinks [ -f "${f}" -a ! -L "${f}" ] || continue + # Ignore .debug files + [ "${f}" == "${f%.debug}" ] || continue if ! readelf -d ${f} | grep SONAME > /dev/null; then warn "${f} doesn't have a SONAME." warn "pkg(8) will not register it as being provided by the port." diff --git a/Mk/Uses/cmake.mk b/Mk/Uses/cmake.mk --- a/Mk/Uses/cmake.mk +++ b/Mk/Uses/cmake.mk @@ -70,13 +70,15 @@ . if defined(WITH_DEBUG) CMAKE_BUILD_TYPE?= Debug +. elif defined(WITH_DEBUGINFO) +CMAKE_BUILD_TYPE?= RelWithDebInfo . else CMAKE_BUILD_TYPE?= Release . endif #defined(WITH_DEBUG) PLIST_SUB+= CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:tl}" -. if defined(STRIP) && ${STRIP} != "" && !defined(WITH_DEBUG) +. if defined(STRIP) && ${STRIP} != "" && !defined(WITH_DEBUG) && !defined(WITH_DEBUGINFO) INSTALL_TARGET?= install/strip . endif diff --git a/Mk/Uses/meson.mk b/Mk/Uses/meson.mk --- a/Mk/Uses/meson.mk +++ b/Mk/Uses/meson.mk @@ -53,6 +53,8 @@ # should we have strip separate from WITH_DEBUG? . if defined(WITH_DEBUG) CONFIGURE_ARGS+= --buildtype debug +. elif defined(WITH_DEBUGINFO) +CONFIGURE_ARGS+= --buildtype debugoptimized . else CONFIGURE_ARGS+= --buildtype release \ --optimization plain \ diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk --- a/Mk/bsd.port.mk +++ b/Mk/bsd.port.mk @@ -1016,7 +1016,7 @@ # These need to be absolute since we don't know how deep in the ports # tree we are and thus can't go relative. They can, of course, be overridden # by individual Makefiles or local system make configuration. -_LIST_OF_WITH_FEATURES= bind_now debug lto pie relro sanitize ssp +_LIST_OF_WITH_FEATURES= bind_now debug debuginfo lto pie relro sanitize ssp _DEFAULT_WITH_FEATURES= ssp PORTSDIR?= /usr/ports LOCALBASE?= /usr/local @@ -2654,7 +2654,7 @@ ${v}.${sp}?= ${$v}.${sp} . endfor _PKGMESSAGES.${sp}= ${PKGMESSAGE}.${sp} -. if !exists(${DESCR.${sp}}) +. if !exists(${DESCR.${sp}}) && ${sp} != debuginfo DESCR.${sp}= ${DESCR} DEV_WARNING+= "DESCR.${sp} needs to point to an existing file." . endif @@ -5480,7 +5480,7 @@ 900:add-plist-info 910:add-plist-docs 920:add-plist-examples \ 930:add-plist-data 940:add-plist-post ${POST_PLIST:C/^/990:/} \ ${_OPTIONS_install} ${_USES_install} \ - ${_OPTIONS_stage} ${_USES_stage} + ${_OPTIONS_stage} ${_USES_stage} ${_FEATURES_stage} . if defined(DEVELOPER) _STAGE_SEQ+= 995:stage-qa . else diff --git a/devel/gdb/Makefile b/devel/gdb/Makefile --- a/devel/gdb/Makefile +++ b/devel/gdb/Makefile @@ -1,5 +1,6 @@ PORTNAME= gdb DISTVERSION= 14.1 +PORTREVISION= 1 CATEGORIES= devel MASTER_SITES= GNU @@ -28,6 +29,7 @@ --disable-sim \ --enable-targets=all --enable-64-bit-bfd \ --with-separate-debug-dir=/usr/lib/debug \ + --with-additional-debug-dirs=${LOCALBASE}/lib/debug \ ${ICONV_CONFIGURE_ARG} \ --without-libunwind-ia64 CONFIGURE_OUTSOURCE= yes diff --git a/devel/llvm15/Makefile b/devel/llvm15/Makefile --- a/devel/llvm15/Makefile +++ b/devel/llvm15/Makefile @@ -1,6 +1,6 @@ PORTNAME= llvm DISTVERSION= 15.0.7 -PORTREVISION= 10 +PORTREVISION= 11 CATEGORIES= devel lang MASTER_SITES= https://github.com/llvm/llvm-project/releases/download/llvmorg-${DISTVERSION:S/rc/-rc/}/ \ https://${PRE_}releases.llvm.org/${LLVM_RELEASE}${RCDIR}/ diff --git a/devel/llvm15/files/patch-lldb_source_Symbol_LocateSymbolFile.cpp b/devel/llvm15/files/patch-lldb_source_Symbol_LocateSymbolFile.cpp new file mode 100644 --- /dev/null +++ b/devel/llvm15/files/patch-lldb_source_Symbol_LocateSymbolFile.cpp @@ -0,0 +1,35 @@ +--- lldb/source/Symbol/LocateSymbolFile.cpp.orig 2023-01-12 07:12:30 UTC ++++ lldb/source/Symbol/LocateSymbolFile.cpp +@@ -25,6 +25,10 @@ + + #include "llvm/Support/FileSystem.h" + ++#if defined(__FreeBSD__) ++#include ++#endif ++ + // From MacOSX system header "mach/machine.h" + typedef int cpu_type_t; + typedef int cpu_subtype_t; +@@ -299,6 +303,21 @@ Symbols::LocateExecutableSymbolFile(const ModuleSpec & + FileSpec file_spec("/usr/libdata/debug"); + FileSystem::Instance().Resolve(file_spec); + debug_file_search_paths.AppendIfUnique(file_spec); ++ } ++#elif defined(__FreeBSD__) ++ { ++ int mib[2]; ++ char buf[PATH_MAX]; ++ size_t len = PATH_MAX; ++ ++ mib[0] = CTL_USER; ++ mib[1] = USER_LOCALBASE; ++ if (::sysctl(mib, 2, buf, &len, NULL, 0) == 0) { ++ std::string localbase(buf); ++ FileSpec file_spec(localbase + "/lib/debug"); ++ FileSystem::Instance().Resolve(file_spec); ++ debug_file_search_paths.AppendIfUnique(file_spec); ++ } + } + #else + // Add /usr/lib/debug directory.