From patchwork Thu Feb 20 01:51:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Austin Lund X-Patchwork-Id: 1516 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id E39EC1726CCD0 for ; Thu, 20 Feb 2020 01:52:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.3 (2019-12-06) on apollo.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_ADSP_CUSTOM_MED=0.001, DKIM_INVALID=1,DKIM_SIGNED=0.1,FREEMAIL_FROM=0.5,MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,T_DMARC_POLICY_NONE=0.01, T_DMARC_SIMPLE_DKIM=0.01 autolearn=ham autolearn_force=no version=3.4.3 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Thu, 20 Feb 2020 01:52:03 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 86EE0193039A65; Thu, 20 Feb 2020 01:52:02 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id 171DA193039A5E; Thu, 20 Feb 2020 01:52:02 +0000 (UTC) Authentication-Results: orion.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D3U+1Wyf Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id F1E7129D11; Thu, 20 Feb 2020 01:52:01 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D3U+1Wyf Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id E40B829D07 for ; Thu, 20 Feb 2020 01:51:58 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by luna.archlinux.org (Postfix) with ESMTPS for ; Thu, 20 Feb 2020 01:51:58 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id D0191193039A4D for ; Thu, 20 Feb 2020 01:51:54 +0000 (UTC) Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS for ; Thu, 20 Feb 2020 01:51:54 +0000 (UTC) Received: by mail-pg1-x544.google.com with SMTP id j4so1094164pgi.1 for ; Wed, 19 Feb 2020 17:51:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3jIPgIyKztK5xEBkmIpJgjw0jRfiXeTOmVHZ4X8XO8I=; b=D3U+1Wyfty/ybMaTi0vFwLuh9yDTYdgXjhydGUSYUGR/85KCWFik0bvp74LRTgczfM AuNXRWB6k1BAowExoyKYUzbjvNTEjTixlgWZYsD8Zd7HJKQKxbLojBNr3skkWrauAI4Z FJNgoOppKJcyTQ0hXdcDL3KfFSJfZFGdlhjDcobec9buVBcxiABZsyrNjOT4C4JwnNUg SN2x6+28gA7TccGQb6Z/Xmngx/btZ1pMx7rQqFvBdDPE9c6R5kLevLfAoWNEzVAIIXOY fK7E2odvgc984BKNH+I9YvTVWP4thxcNuZnjc8A2ZRVAgMrauXP4SdErIwgLqhl3J9q5 MOfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3jIPgIyKztK5xEBkmIpJgjw0jRfiXeTOmVHZ4X8XO8I=; b=QfsHJbMhWxVljGp2o0sXeb5cLgOTvRTJ+bDxisNcrkJzuIfcarTtNMJ0/SWYu4IzvC Dc5aMSjxF53hKK1YjCL1y6QZCPjVYxIu7VGLfNXuhPCfuvzQB6UnEIl/sI2QLfaO/Kry M9k9jJLADuwVcMKonYefkIJS4asEouYRJEyLw5N7ZeybtKUF4HdShhBLKMbgN/6eN5G1 Jy0WPv6fJHU7v2JGuP0jU2mY6uUpHj4KsxILsKPzqqytQHjeaDRtLKf5jUa+CiO3XhG7 hj1vz6A8ae8aHPCCUR1LMdqAaWM2bTlBX6m+hgFX0fSBVE+7MYY/nnixcasS2wvHsola OXYw== X-Gm-Message-State: APjAAAXfDRQDReJhtrBqcAgea2kIJNzhgkqv+NwNW9fdWmNt0+N2iQKF VkwRD8Hi4R60zESm6lhq/HsFwxc7JZY= X-Google-Smtp-Source: APXvYqwvSEgBPqA9WIMSNp/X8B9DHs20xNaubPK1zKkjKu/aLmtaFdegdNSSAEBcG0XQKb+ZI/GE3w== X-Received: by 2002:a63:3dc1:: with SMTP id k184mr30953877pga.103.1582163512724; Wed, 19 Feb 2020 17:51:52 -0800 (PST) Received: from sarek.staff.eduroam.uq.edu.au ([130.102.13.10]) by smtp.gmail.com with ESMTPSA id s18sm960499pgn.34.2020.02.19.17.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 17:51:51 -0800 (PST) From: Austin Lund To: pacman-dev@archlinux.org Date: Thu, 20 Feb 2020 11:51:43 +1000 Message-Id: <20200220015143.2249601-1-austin.lund@gmail.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Subject: [pacman-dev] [PATCH] makepkg: Include more source files in debug packages. X-BeenThere: pacman-dev@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Discussion list for pacman development Errors-To: pacman-dev-bounces@archlinux.org Sender: "pacman-dev" Currently only the file pointed to by the DW_AT_name is included as a source file in debug packages. This means many files that are useful for debugging are not included. For example, no header files are included but yet these may by referenced in the .debug_line section. This sed script converts into shell variables the debug dump information from readelf about compilation units, directory tables and file tables. This can be used to get the full path of all the source files from within the package being compiled that are referenced in the debugging information. Also, placeholder symbols (e.g. ) and paths outside the current source (e.g. linked libraries) will be more consistently ignored from inclusion in the debug packages. Signed-off-by: Austin Lund --- scripts/libmakepkg/tidy/strip.sh.in | 46 +++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 2b6f732d..2598d606 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -35,9 +35,51 @@ build_id() { LANG=C readelf -n "$1" | sed -n '/Build ID/ { s/.*: //p; q; }' } +_source_files_sedscript='1 { a \ +declare -A COMPDIR +} +/^Contents of the .debug_info section:$/,/^[^[:space:]]/ { +/^ <0>.*\(DW_TAG_compile_unit\)$/,/^ {0,3}[^[:space:]]/{ + /^ <0>.*\(DW_TAG_compile_unit\)$/{h;d} + /^ {0,3}[^[:space:]]/{ + x + s/(.*)/\n&\n/ + s/.*DW_AT_comp_dir[^\n]*: ([^\n]*)\n.*/'\''\1'\''&/ + s/.*DW_AT_stmt_list[^\n]*: ([^\n]*)\n.*/COMPDIR\[\1\]=&/ + P;d + } + H + d +} +} +/^Raw dump of debug contents of section .debug_line:$/,/^[^[:space:]]/ { +/^ Offset:/,/^ Line Number Statements:$/ { + /^ Offset:/ { + a \ +unset DIRTABLE\ +unset FILETABLE + + s/.*(0x[[:xdigit:]]+)$/OFFSET=\1/; p; d } + /^ The Directory Table/,/^$/ { + /^ [[:digit:]]+\t[^/.]/ { + s/^ ([[:digit:]]+)\t(.*)/DIRTABLE[\1]=\$\{COMPDIR\[\$OFFSET]\}\/\2/ + p; d + } + d + } + /^ The File Name Table/,/^$/ { + /^ [[:digit:]]+\t[1-9]/ { + s/^ [[:digit:]]+\t([[:digit:]]+)\t.*\t(.*)$/\[\[ -v DIRTABLE\[\1\] \]\] \&\& echo \$\{DIRTABLE\[\1\]\}\/\2/ + p; d + } + d + } +} +}' + source_files() { LANG=C readelf "$1" --debug-dump | \ - awk '/DW_AT_name +:/{name=$8}/DW_AT_comp_dir +:/{{if (name == "") next}{if (name !~ /^[<\/]/) {printf "%s/", $8}}{print name}}' + sed -n -E -e "${_source_files_sedscript}" | /bin/bash } strip_file() { @@ -60,7 +102,7 @@ strip_file() { while IFS= read -r t; do f=${t/${dbgsrcdir}/"$srcdir"} mkdir -p "${dbgsrc/"$dbgsrcdir"/}${t%/*}" - cp -- "$f" "${dbgsrc/"$dbgsrcdir"/}$t" + cp -n -- "$f" "${dbgsrc/"$dbgsrcdir"/}$t" done < <(source_files "$binary") # copy debug symbols to debug directory