pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Building with debugging symbols



Andreas Gustafsson schrieb:
Hi all,

Is there a standard way to build a single package or even all of
pkgsrc with debugging symbols?

I once patched pkgsrc to install most of the source code in $PREFIX. It only worked when building from source, but it was fun anyway.

The idea was to record every C and C++ file that was compiled and to copy these files to $PREFIX, so that they can be used for source debugging.

If you want to play with it, here is the diff against pkgsrc as of 2009-06-19.

Roland
Index: compiler/gcc.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/compiler/gcc.mk,v
retrieving revision 1.97
diff -u -p -r1.97 gcc.mk
--- compiler/gcc.mk     30 May 2009 18:16:26 -0000      1.97
+++ compiler/gcc.mk     18 Mar 2010 21:32:09 -0000
@@ -8,6 +8,22 @@
 #      When set to "yes", the native gcc is used, no matter which
 #      compiler version a package requires.
 #
+# GCC_PREPEND_CFLAGS
+#      These flags are prepended to the final gcc and g++ command line,
+#      both when compiling and when linking files.
+#
+# GCC_APPEND_CFLAGS
+#      These flags are appended to the final gcc and g++ command line,
+#      both when compiling and when linking files.
+#
+# GCC_PREPEND_LDFLAGS
+#      These flags are prepended to the final gcc and g++ command line,
+#      but only when linking.
+#
+# GCC_APPEND_LDFLAGS
+#      These flags are appended to the final gcc and g++ command line,
+#      but only when linking.
+#
 # Package-settable variables:
 #
 # GCC_REQD
@@ -49,7 +65,7 @@ _DEF_VARS.gcc=        \
        _GCC_PKGBASE _GCC_PKGSRCDIR _GCC_PKG_SATISFIES_DEP \
        _GCC_PREFIX _GCC_REQD _GCC_STRICTEST_REQD _GCC_SUBPREFIX \
        _GCC_TEST_DEPENDS _GCC_USE_F2C _GCC_VARS _GCC_VERSION \
-       _GCC_VERSION_STRING \
+       _GCC_VERSION_STRING _GCC_VERSION_STRING_CMD \
        _IGNORE_GCC _IGNORE_GCC3CXX _IGNORE_GCC3F77 _IGNORE_GCC3OBJC \
        _IS_BUILTIN_GCC \
        _LANGUAGES.gcc \
@@ -100,8 +116,9 @@ MAKEFLAGS+= _CC=${_CC:Q}
 .endif
 
 .if !defined(_GCC_VERSION)
-_GCC_VERSION_STRING!=  \
+_GCC_VERSION_STRING_CMD:=      \
        ( ${SETENV} ${ALL_ENV} ${_CC} -v 2>&1 | ${GREP} 'gcc version' ) 
2>/dev/null || ${ECHO} 0
+_GCC_VERSION_STRING!=${_GCC_VERSION_STRING_CMD}
 .  if !empty(_GCC_VERSION_STRING:Megcs*)
 _GCC_VERSION=  2.8.1           # egcs is considered to be gcc-2.8.1.
 .  elif !empty(_GCC_VERSION_STRING:Mgcc*)
@@ -491,7 +508,16 @@ ${_GCC_${_var_}}:
 .    else
        ${RUN}                                  \
        (${ECHO} '#!${TOOLS_SHELL}';                                    \
-        ${ECHO} 'exec ${_GCCBINDIR}/${.TARGET:T} "$$@"';               \
+        ${ECHO} bin=${_GCCBINDIR}/${.TARGET:T}; \
+        ${ECHO} prepend_cflags=${GCC_PREPEND_CFLAGS:Q:Q}; \
+        ${ECHO} append_cflags=${GCC_APPEND_CFLAGS:Q:Q}; \
+        ${ECHO} prepend_ldflags=${GCC_PREPEND_LDFLAGS:Q:Q}; \
+        ${ECHO} append_ldflags=${GCC_APPEND_LDFLAGS:Q:Q}; \
+        ${ECHO}; \
+        ${ECHO} 'compiling=no; for arg do if [ "x$$arg" = "x-c" ]; then 
compiling=yes; fi; done'; \
+        ${ECHO}; \
+        ${ECHO} '[ $$compiling = no ] || eval "exec \$$bin $$prepend_cflags 
\"\$$@\" $$append_cflags"'; \
+        ${ECHO} 'eval "exec \$$bin $$prepend_cflags $$prepend_ldflags \"\$$@\" 
$$append_cflags $$append_ldflags"'; \
        ) > ${.TARGET}
        ${RUN}${CHMOD} +x ${.TARGET}
 .    endif
Index: wrapper/arg-source
===================================================================
RCS file: /cvsroot/pkgsrc/mk/wrapper/arg-source,v
retrieving revision 1.15
diff -u -p -r1.15 arg-source
--- wrapper/arg-source  19 Sep 2007 13:08:19 -0000      1.15
+++ wrapper/arg-source  18 Mar 2010 21:32:10 -0000
@@ -46,8 +46,12 @@
 # the queue.
 
 # Push arguments from the command line into the argument buffer.
+prev_arg=""
+saved_arg=""
 while $test $# -gt 0; do
        arg="$1"; shift
+       prev_arg=$saved_arg
+       saved_arg=$arg
        case $arg in
        ##############################################################
        # Merge "-I /dir" into a single "-I/dir".  Same for -L, -R.
@@ -162,10 +166,55 @@ while $test $# -gt 0; do
                append_queue argbuf "$arg"
                $debug_log $wrapperlog "    (arg-source) push: $arg"
                ;;
-       ##############################################################
-       # For everything else, just queue it up.
-       ##############################################################
+
+
+       --mode=execute)
+               install_debuginfo=no
+               append_queue argbuf "$arg"
+               $debug_log $wrapperlog "    (arg-source) push: $arg"
+               ;;
+
        *)
+               if [ $install_debuginfo = yes ] && [ -f "$arg" ] && [ 
"x$prev_arg" != "x-o" ]; then
+                       wrkdir=${debuginfo_filelist%/*}
+
+                       case $arg in
+                       *conftest.* | *.o | *.lo | *.Tpo |\
+                       *.a | *.la | *.so | *.so.[0-9]* |\
+                       *.sh |\
+                       *.def | *.sym |\
+                       */.wrapper/bin/*)
+                               # These file types are ignored, since they
+                               # are not needed for debugging.
+                               ;;
+
+                       *.c |\
+                       *.C | *.cc | *.cxx | *.cpp |\
+                       *.s | *.S | *.asm)
+                               case $arg in
+                               /*)     ;;
+                               *)      arg=`pwd`/$arg ;;
+                               esac
+               
+                               case $arg in
+                               $wrkdir/*)      arg=${arg#$wrkdir/};;
+                               $debuginfo_dir/src/*)   
arg=${arg#$debuginfo_dir/src/};;
+                               *)      echo "ERROR: [scan] cannot compile 
files outside WRKDIR: $arg" 1>&2
+                                       exit 1 ;;
+                               esac
+
+                               echo "$arg" >> $debuginfo_filelist
+                               arg="$debuginfo_dir/src/$arg"
+                               ;;
+
+                       *)
+                               ls -l "$arg" 1>&2
+                               echo "ERROR: [arg-source] Unknown file type: 
$arg" 1>&2
+                               exit 1
+                               ;;
+                       esac
+               fi
+
                append_queue argbuf "$arg"
                $debug_log $wrapperlog "    (arg-source) push: $arg"
                ;;
Index: wrapper/bsd.wrapper.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/wrapper/bsd.wrapper.mk,v
retrieving revision 1.83
diff -u -p -r1.83 bsd.wrapper.mk
--- wrapper/bsd.wrapper.mk      30 May 2009 19:18:01 -0000      1.83
+++ wrapper/bsd.wrapper.mk      18 Mar 2010 21:32:10 -0000
@@ -420,6 +420,9 @@ _WRAP_SUBST_SED.${_wrappee_}=                               
                \
        -e "s|@_WRAP_TYPE@|${_WRAP_TYPE.${_wrappee_}}|g" \
        -e "s|@WRAPPER_DEBUG@|${_WRAPPER_DEBUG}|g"                      \
        -e "s|@WRAPPER_UPDATE_CACHE@|${WRAPPER_UPDATE_CACHE}|g"         \
+       -e "s|@INSTALL_DEBUGINFO@|${INSTALL_DEBUGINFO:Dyes:Uno}|g"      \
+       -e "s|@_DEBUGINFO_FILELIST@|${_DEBUGINFO_FILELIST}|g"           \
+       -e "s|@_DEBUGINFO_DIR@|${_DEBUGINFO_DIR}|g"                     \
        ${_WRAP_SUBST_SED}
 
 _WRAP_COOKIE.${_wrappee_}=     ${WRAPPER_DIR}/.wrapper_${_wrappee_}_done
@@ -726,7 +729,7 @@ ${_COOKIE.wrapper}: real-wrapper
 .endif
 
 .PHONY: real-wrapper
-real-wrapper: wrapper-message wrapper-vars pre-wrapper do-wrapper post-wrapper 
wrapper-cookie error-check
+real-wrapper: wrapper-message wrapper-vars pre-wrapper do-wrapper post-wrapper 
_wrapper-debuginfo-symlink wrapper-cookie error-check
 
 .PHONY: wrapper-message
 wrapper-message:
@@ -749,6 +752,12 @@ post-wrapper:
        @${DO_NADA}
 .endif
 
+_wrapper-debuginfo-symlink: ${INSTALL_DEBUGINFO:Dsu-target}
+# su-_wrapper-debuginfo-symlink is defined in debuginfo.mk.
+.if !empty(INSTALL_DEBUGINFO:Uno:M[Yy][Ee][Ss])
+.  include "debuginfo.mk"
+.endif
+
 .PHONY: wrapper-cookie
 wrapper-cookie:
        ${RUN} [ ! -f ${_COOKIE.wrapper} ]
Index: wrapper/wrapper-defs.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/wrapper/wrapper-defs.mk,v
retrieving revision 1.3
diff -u -p -r1.3 wrapper-defs.mk
--- wrapper/wrapper-defs.mk     6 May 2009 10:28:01 -0000       1.3
+++ wrapper/wrapper-defs.mk     18 Mar 2010 21:32:10 -0000
@@ -44,4 +44,8 @@ WRAPPER_SRCDIR=               ${.CURDIR}/../../mk/wra
 WRAPPER_BIN_SH?=       ${SH}
 WRAPPER_SHELL?=                ${WRAPPER_BIN_SH}
 
+#if !bootstrapping
+#USE_TOOLS+=           ${INSTALL_DEBUGINFO:Dpax}
+#endif
+
 .endif # WRAPPER_DEFS_MK
Index: wrapper/wrapper.sh
===================================================================
RCS file: /cvsroot/pkgsrc/mk/wrapper/wrapper.sh,v
retrieving revision 1.21
diff -u -p -r1.21 wrapper.sh
--- wrapper/wrapper.sh  30 May 2009 19:18:01 -0000      1.21
+++ wrapper/wrapper.sh  18 Mar 2010 21:32:10 -0000
@@ -36,7 +36,7 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
-#set -eu
+set -eu
 
 # The list of include files for the wrapper.
 empty_file="@_WRAP_EMPTY_FILE@"
@@ -62,6 +62,9 @@ wrapper_type="@_WRAP_TYPE@"   # one of AS,
 wrapperlog="${WRAPPER_LOG-@_WRAP_LOG@}"
 skip_transform="${WRAPPER_SKIP_TRANSFORM-@_WRAP_SKIP_TRANSFORM@}"
 debug="${WRAPPER_DEBUG-@WRAPPER_DEBUG@}"
+install_debuginfo="@INSTALL_DEBUGINFO@"
+debuginfo_filelist="@_DEBUGINFO_FILELIST@"
+debuginfo_dir="@_DEBUGINFO_DIR@"
 
 # Tools that can be used by the wrapper.
 # XXX: Why is this necessary? Isn't the wrapper only called with

--- wrapper/debuginfo.mk
+++ wrapper/debuginfo.mk
@@ -0,0 +1,59 @@
+# $NetBSD$
+#
+# This file installs the debug information for packages, so that they
+# can be debugged using their source code.
+#
+# === User-settable variables ===
+#
+# INSTALL_DEBUGINFO
+#      "yes" to install the debugging information, undefined otherwise.
+#
+#      Default: undefined
+
+_DEBUGINFO_DIR=                ${PREFIX}/share/debuginfo/${PKGNAME}
+_DEBUGINFO_FILELIST=   ${WRKDIR}/.debuginfo-filelist
+
+# called from bsd.wrapper.mk.
+su-_wrapper-debuginfo-symlink: .PHONY
+       @${STEP_MSG} "Creating symlinks for debuginfo generation"
+       ${RUN} ${RM} -rf ${_DEBUGINFO_DIR}
+       ${RUN} ${MKDIR} ${_DEBUGINFO_DIR}
+       ${RUN} ${LN} -s ${BUILDLINK_DIR}/include ${_DEBUGINFO_DIR}/include
+       ${RUN} ${LN} -s ${WRKDIR} ${_DEBUGINFO_DIR}/src
+
+unprivileged-install-hook: _sanitize-debuginfo-filelist
+_sanitize-debuginfo-filelist: .PHONY
+       @${STEP_MSG} "Sanitizing debuginfo file list"
+       ${RUN} >> ${_DEBUGINFO_FILELIST}
+       ${RUN} ${AWK} -F/ '{\
+               ignore = 0; fname="";\
+               for (i = NF; i >= 1; i--) {\
+                       if ($$i == ".") {\
+                       } else if ($$i == "..") {\
+                               ignore++;\
+                       } else if (ignore > 0) {\
+                               ignore--;\
+                       } else {\
+                               fname = $$i "/" fname;\
+                       }\
+               }\
+               if (ignore == 0) print substr(fname, 1, length(fname) - 1);\
+       }' < ${_DEBUGINFO_FILELIST} > ${_DEBUGINFO_FILELIST}.tmp1
+       ${RUN} cd ${WRKDIR}; \
+       while read fname; do \
+               if test -f "$$fname"; then \
+                       echo "$$fname"; \
+               else \
+                       ${WARNING_MSG} "[debuginfo.mk] compiled file $$fname 
does not exist anymore."; \
+               fi; \
+       done < ${_DEBUGINFO_FILELIST}.tmp1 > ${_DEBUGINFO_FILELIST}.tmp2
+       ${RUN} ${SORT} -u < ${_DEBUGINFO_FILELIST}.tmp2 > 
${_DEBUGINFO_FILELIST}.tmp3
+       ${RUN} ${MV} -f ${_DEBUGINFO_FILELIST}.tmp3 ${_DEBUGINFO_FILELIST}
+       ${RUN} ${RM} -f ${_DEBUGINFO_FILELIST}.tmp?
+
+privileged-install-hook: _install-debuginfo
+_install-debuginfo: .PHONY
+       @${STEP_MSG} "Installing debuginfo"
+       ${RUN} ${RM} -rf ${_DEBUGINFO_DIR}
+       ${RUN} set -e; cd ${BUILDLINK_DIR}; ${PAX} -wr include ${_DEBUGINFO_DIR}
+       ${RUN} set -e; cd ${WRKDIR}; ${PAX} -wr ${_DEBUGINFO_DIR}/src < 
${_DEBUGINFO_FILELIST}
# Example /usr/pkg/etc/mk.conf file produced by bootstrap-pkgsrc
# Do 21. Aug 12:39:16 CEST 2008

.ifdef BSD_PKG_MK       # begin pkgsrc settings


UNPRIVILEGED=           yes
PKG_DBDIR=              /usr/pkg/var/db/pkg
LOCALBASE=              /usr/pkg
VARBASE=                /usr/pkg/var
PKG_TOOLS_BIN=          /usr/pkg/sbin
PKGMANDIR=              man

TOOLS_PLATFORM.pax?=            /usr/pkg/bin/${NBPAX_PROGRAM_PREFIX}pax
TOOLS_PLATFORM.tar?=            /usr/pkg/bin/${NBPAX_PROGRAM_PREFIX}tar
TOOLS_PLATFORM.sh?=             /bin/bash

PKG_DEVELOPER=          yes
INSTALL_UNSTRIPPED=     yes
CHECK_STRIPPED=         yes
WRKOBJDIR=              /tmp/${USER}/pkgsrc
PACKAGES=               /home/pkgsrc/packages
DISTDIR=                /home/scratch/distfiles

LOCALBASE_LOCKTYPE=     sleep
WRKDIR_LOCKTYPE=        once

CREATE_WRKDIR_SYMLINK=  yes
CFLAGS+=                -Os -ggdb -W -Wall
LDFLAGS+=               -ggdb
PREFER_PKGSRC=          yes
X11_TYPE=               modular
DEPENDS_TARGET=         package
INSTALL_DEBUGINFO=      yes

ACCEPTABLE_LICENSES+=   velena-license

# TODO: das muss man noch feiner spezifizieren koennen.
# am besten mit einem externen Wrapper, der die Argumente
# neu anordnet.
GCC_PREPEND_CFLAGS=     -fdiagnostics-show-option
.if !defined(NO_STRICT)
GCC_APPEND_CFLAGS=      -Wall -W -Wno-error -ggdb -Werror=int-to-pointer-cast 
-Werror-implicit-function-declaration -Wno-unused-parameter
.endif
GCC_PREPEND_LDFLAGS=    -L${BUILDLINK_DIR}/lib -Wl,-R${LOCALBASE}/lib 
-L/usr/lib64 -Wl,-R/usr/lib64
GCC_APPEND_LDFLAGS=     # none

.if ${PKGPATH} == "pkgtools/pkglint"
CHECK_FILES=            no
.endif

.endif                  # end pkgsrc settings


Home | Main Index | Thread Index | Old Index