diff --git a/Makefile.inc1 b/Makefile.inc1 index dd2ebe4..f922f19 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -221,3 +221,7 @@ profiles: select-profile: @${BUILD_TOOLS}/select-profile.py ${name} + +debug: + @${BUILD_TOOLS}/build-debug.py + diff --git a/build/config/env.pyd b/build/config/env.pyd index cf66ecd..549c745 100644 --- a/build/config/env.pyd +++ b/build/config/env.pyd @@ -115,6 +115,10 @@ IX_INTERNAL_PATH_PREFIX = "/builds/${PRODUCT}" if PRODUCT == "FreeNAS": DOWNLOAD_HOST = "download.freenas.org" +# Debug info location +DEBUG_ROOT = "${OBJDIR}/debug" +DEBUG_WORLD = "${DEBUG_ROOT}/world" + # Calculate make jobs number, PXZ acceleration and so on HW_NCPU = sh("sysctl -n hw.ncpu") HW_PHYSMEM = sh("sysctl -n hw.physmem") diff --git a/build/tools/build-sdk.py b/build/tools/build-debug.py similarity index 52% rename from build/tools/build-sdk.py rename to build/tools/build-debug.py index a355da1..9f05d9e 100755 --- a/build/tools/build-sdk.py +++ b/build/tools/build-debug.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python2.7 #+ # Copyright 2015 iXsystems, Inc. # All rights reserved @@ -26,6 +26,51 @@ # ##################################################################### +import os +import errno +from utils import sh, e, info + + +def is_elf(filename): + if os.path.islink(filename): + return False + + with open(filename, 'rb') as f: + header = f.read(4) + return header == b'\x7fELF' + + +def main(): + sh('rm -rf ${DEBUG_WORLD}') + sh('mkdir -p ${DEBUG_WORLD}') + + info('Saving debug information in ${{DEBUG_WORLD}}') + + for root, dirs, files in os.walk(e('${WORLD_DESTDIR}/')): + for name in files: + filename = os.path.join(root, name) + relpath = os.path.relpath(filename, e('${WORLD_DESTDIR}')) + destpath = os.path.join(e('${DEBUG_WORLD}'), relpath) + if not is_elf(filename): + continue + + try: + os.makedirs(os.path.dirname(destpath)) + except OSError as err: + if err.errno != errno.EEXIST: + raise + + # We need to remove any flags on protected files and restore + # them after stripping + flags = os.stat(filename).st_flags + os.chflags(filename, 0) + + sh('objcopy --only-keep-debug ${filename} ${destpath}.debug') + sh('strip ${filename}', nofail=True) + + os.chflags(filename, flags) + + if __name__ == '__main__': - pass + main()