Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3057306pxj; Mon, 10 May 2021 17:40:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHzKmWxlIkU6PE8RlMqCMLAq8zCwAVWpcaEgMHyhDPPdKauNAEb72pwMiOl7e7EC8PAbSn X-Received: by 2002:a92:6902:: with SMTP id e2mr24562178ilc.172.1620693622689; Mon, 10 May 2021 17:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620693622; cv=none; d=google.com; s=arc-20160816; b=GfI2iJUNiSAlchg95lFH4ZcDlP4bBJCG0zaHqXvSNoCkEPJ2dHMft1dr1e6Agun4rm jpTiGPXeyMwcCcYoALAFxU4sZbvDlQGLgMCq5OPTJr6t1Kvkwwpkmsfz5O9ziAGD/TFY bYQtQjRj5eyw+3SkZeR9YTu7aushsdBnqJt5ZAezdjObNhjI07pZw0W7nbqloBYDaTN3 5D0uFviQeAQ+36HhoZwmwe4yfhJeENKWh8OPFesMoylxI7Z6P6M3nhlBcqic/QmojEek Zi3AYV0tH9AXn6qLp68PMQLtnjgGrIMs7Zi1wA0wDyHk0oazp7SxGuRMtK2IYJYbX6AT Gtwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bXxtCW2oZxmP3x76plR5OR7eL+Iwsnt548Hrnczvi0s=; b=Vy4z/cr3qbTU5/evUSFnul9icNt2pktLsbvgF3AsBJPoprfl0OZ/Rs76HYBJSXqOIj 7peEDrjY5Gj1S6HhcZcwhRp8ek+VmPUjlIaVhHs+KqDZyYbkbHkt5kCWE6HAz9aD34kK M0W4EO8X9g9pkwobLx/fFHKZUSWG/ef9AsCiM79Pk6kny78CMdWeZ4eAf0pIU5LEWlXh w3EihR+uaLKeGDLpY4xDsGgMlNElE6smZyva5NZ/OE+ON7hC4QW3r3Ee0svQbgbtpYf1 BZdm0jYWUZyCNq9+YrGDH2jQVn+9Fvtp0GN0Mg1R9kJLMFa9tajd3G+/Gn0WEOO3LY4f m2eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OMx6HmmP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k64si1384380iof.43.2021.05.10.17.40.10; Mon, 10 May 2021 17:40:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OMx6HmmP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230355AbhEKAkT (ORCPT + 99 others); Mon, 10 May 2021 20:40:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbhEKAkE (ORCPT ); Mon, 10 May 2021 20:40:04 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3EE6C061574 for ; Mon, 10 May 2021 17:38:58 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id z16so14572267pga.1 for ; Mon, 10 May 2021 17:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bXxtCW2oZxmP3x76plR5OR7eL+Iwsnt548Hrnczvi0s=; b=OMx6HmmPZHtprRayuT+9x7LU+gltcNKnmFzFrdIW1Phf6C2VL7KZJx82S8IC4VWC3V WTreD5gyFK0PNtJjddF63kvvR02C0HA/siaZfPVblE6R/zTU1Aju4gpe2vXTIiylng/D 5x+Yq3vRc2z+PO8czcGkAarpMRSlVFH6bGSTQ= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=bXxtCW2oZxmP3x76plR5OR7eL+Iwsnt548Hrnczvi0s=; b=DlwxXioudEkPFk4AkbrdsbxokrgDO5b5uQppahFGldOAzz/QS6nwOKGAR7c4BcZ5LY J06tMJb+48eYQb90IslOYewvxnMaYAecHA+Aih9I5sapOSL5GcRk/l+SHMyUKG9WXDrE eB0A4cpltrARITfpam+0UoeLT/qR0vVykvBPAHgINkFY9wAigtiBdClkXsgz8dmEK90v jY0a0PdA5XysY7hnHh8czGMd/lvdWqWWHefwKSGxHdpFw4sHl/+xroP31L1nXZ+3vQp6 0KRPeowrQ9B7ZT1JMTKf2TitP6pMDD246eArDh/ZWQM+riidw5YgFQdTITctEnr1LRar v/ZQ== X-Gm-Message-State: AOAM530AuDxDL6swgPBO3Ehjz+7pTQ8zZZSWJHZ6+KpmK32DMWfOWLFy d6lUEyX10yZNxsfnPSNj0NA99A== X-Received: by 2002:a63:e4a:: with SMTP id 10mr14331998pgo.67.1620693538187; Mon, 10 May 2021 17:38:58 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:201:6765:417e:19fc:9756]) by smtp.gmail.com with ESMTPSA id d26sm12142539pfq.215.2021.05.10.17.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 17:38:57 -0700 (PDT) From: Stephen Boyd To: Andrew Morton , Petr Mladek Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Alexei Starovoitov , Jessica Yu , Evan Green , Hsin-Yi Wang , Konstantin Khlebnikov , Sasha Levin , Steven Rostedt , Andy Shevchenko , Matthew Wilcox Subject: [PATCH v6 08/13] scripts/decode_stacktrace.sh: Support debuginfod Date: Mon, 10 May 2021 17:38:40 -0700 Message-Id: <20210511003845.2429846-9-swboyd@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210511003845.2429846-1-swboyd@chromium.org> References: <20210511003845.2429846-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that stacktraces contain the build ID information we can update this script to use debuginfod-find to locate the debuginfo for the vmlinux and modules automatically. This can replace the existing code that requires specifying a path to vmlinux or tries to find the vmlinux and modules automatically by using the release number. Work it into the script as a fallback option if the vmlinux isn't specified on the commandline. Cc: Jiri Olsa Cc: Alexei Starovoitov Cc: Jessica Yu Cc: Evan Green Cc: Hsin-Yi Wang Cc: Konstantin Khlebnikov Cc: Sasha Levin Cc: Petr Mladek Cc: Steven Rostedt Cc: Andy Shevchenko Cc: Matthew Wilcox Signed-off-by: Stephen Boyd --- scripts/decode_stacktrace.sh | 81 +++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 11 deletions(-) diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh index 90398347e366..ca21f8bdf5f2 100755 --- a/scripts/decode_stacktrace.sh +++ b/scripts/decode_stacktrace.sh @@ -3,11 +3,10 @@ # (c) 2014, Sasha Levin #set -x -if [[ $# < 1 ]]; then +usage() { echo "Usage:" echo " $0 -r | [base path] [modules path]" - exit 1 -fi +} if [[ $1 == "-r" ]] ; then vmlinux="" @@ -24,6 +23,7 @@ if [[ $1 == "-r" ]] ; then if [[ $vmlinux == "" ]] ; then echo "ERROR! vmlinux image for release $release is not found" >&2 + usage exit 2 fi else @@ -31,12 +31,35 @@ else basepath=${2-auto} modpath=$3 release="" + debuginfod= + + # Can we use debuginfod-find? + if type debuginfod-find >/dev/null 2>&1 ; then + debuginfod=${1-only} + fi + + if [[ $vmlinux == "" && -z $debuginfod ]] ; then + echo "ERROR! vmlinux image must be specified" >&2 + usage + exit 1 + fi fi declare -A cache declare -A modcache find_module() { + if [[ -n $debuginfod ]] ; then + if [[ -n $modbuildid ]] ; then + debuginfod-find debuginfo $modbuildid && return + fi + + # Only using debuginfod so don't try to find vmlinux module path + if [[ $debuginfod == "only" ]] ; then + return + fi + fi + if [[ "$modpath" != "" ]] ; then for fn in $(find "$modpath" -name "${module//_/[-_]}.ko*") ; do if readelf -WS "$fn" | grep -qwF .debug_line ; then @@ -150,6 +173,27 @@ parse_symbol() { symbol="$segment$name ($code)" } +debuginfod_get_vmlinux() { + local vmlinux_buildid=${1##* } + + if [[ $vmlinux != "" ]]; then + return + fi + + if [[ $vmlinux_buildid =~ ^[0-9a-f]+ ]]; then + vmlinux=$(debuginfod-find debuginfo $vmlinux_buildid) + if [[ $? -ne 0 ]] ; then + echo "ERROR! vmlinux image not found via debuginfod-find" >&2 + usage + exit 2 + fi + return + fi + echo "ERROR! Build ID for vmlinux not found. Try passing -r or specifying vmlinux" >&2 + usage + exit 2 +} + decode_code() { local scripts=`dirname "${BASH_SOURCE[0]}"` @@ -157,6 +201,14 @@ decode_code() { } handle_line() { + if [[ $basepath == "auto" && $vmlinux != "" ]] ; then + module="" + symbol="kernel_init+0x0/0x0" + parse_symbol + basepath=${symbol#kernel_init (} + basepath=${basepath%/init/main.c:*)} + fi + local words # Tokenize @@ -182,16 +234,28 @@ handle_line() { fi done + if [[ ${words[$last]} =~ ^[0-9a-f]+\] ]]; then + words[$last-1]="${words[$last-1]} ${words[$last]}" + unset words[$last] + last=$(( $last - 1 )) + fi + if [[ ${words[$last]} =~ \[([^]]+)\] ]]; then module=${words[$last]} module=${module#\[} module=${module%\]} + modbuildid=${module#* } + module=${module% *} + if [[ $modbuildid == $module ]]; then + modbuildid= + fi symbol=${words[$last-1]} unset words[$last-1] else # The symbol is the last element, process it symbol=${words[$last]} module= + modbuildid= fi unset words[$last] @@ -201,14 +265,6 @@ handle_line() { echo "${words[@]}" "$symbol $module" } -if [[ $basepath == "auto" ]] ; then - module="" - symbol="kernel_init+0x0/0x0" - parse_symbol - basepath=${symbol#kernel_init (} - basepath=${basepath%/init/main.c:*)} -fi - while read line; do # Let's see if we have an address in the line if [[ $line =~ \[\<([^]]+)\>\] ]] || @@ -218,6 +274,9 @@ while read line; do # Is it a code line? elif [[ $line == *Code:* ]]; then decode_code "$line" + # Is it a version line? + elif [[ -n $debuginfod && $line =~ PID:\ [0-9]+\ Comm: ]]; then + debuginfod_get_vmlinux "$line" else # Nothing special in this line, show it as is echo "$line" -- https://chromeos.dev