Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp6996981pxu; Thu, 24 Dec 2020 21:30:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1yYHfsUXgXIuav/PL2Ic2iDZ27iNa8xyc4As5NApjSB1z7TixL1lg+IehDS+kumVKtW3+ X-Received: by 2002:a17:906:3094:: with SMTP id 20mr29916062ejv.218.1608874231322; Thu, 24 Dec 2020 21:30:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608874231; cv=none; d=google.com; s=arc-20160816; b=lbGf56qkMxwqFl08moiNTtQRaa+NPi1K//IF3/sQRXiqJoo/nthrIO2Qzqn8JH/DCP N4epYjqh5z45m1smmDAFc1TmyimYD9PWlhphhzHv4Awhk5woL3VmVz6wT5BJjDVIGc3M 5veFP+YCWBkeXLkPPff0DmKHV5SYp0MR5iwktssqQ8lq2+HKC3AhmPC5GGsw9FwHAFLU G2Mfpdk6uV47mhILoK0DJXjhNkCctApHan5/0PI3YWMcFxRAYZSkIJ3fxkyvwASl5Uf9 CZSKxtzn6ecxyiXNrQFtjBQmMWrNeqT5mZovpJAJ6MkSh8kuI39SS4NClRjC+IbjgqqZ OtSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=HfQeMTR9dHIFoLebfafxegiW3US03+p5EYWEz17ILko=; b=IMR0e3yXE1O9tTnp40tCa6sPkA+feLsheeadi2GIc2nN/UF/gzE0MpaM2zQweQcdbK dCYXW8AmvxgQ9Oz6AbWCZ4j+yGZxv2mcJqk/j5HWFf2nLHUkhT6WHOmhFngTvu5nfaU0 dqZ7bUuZrY3y93Clgui9+imns0IXhtM8lHYQqCNzd+Pp3flo3NFUXC6N13FxioJi3F5O fzO2xwvflSStykjo5InCurkXMM+fmTNt4mIyZRy0H+v1Xc13vmJkdOIvMfQBQKmRaXG1 p8T+EVogZztvqc3OURUWCNUMkVbDL1BvZvQ9/oLyicrtwIAC3kX2hazTjrL9xHjadPHr HarQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HvswmbMD; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si18144719edv.445.2020.12.24.21.29.55; Thu, 24 Dec 2020 21:30:31 -0800 (PST) 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=@linaro.org header.s=google header.b=HvswmbMD; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726184AbgLYF2v (ORCPT + 99 others); Fri, 25 Dec 2020 00:28:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725853AbgLYF2v (ORCPT ); Fri, 25 Dec 2020 00:28:51 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D12A3C0613C1 for ; Thu, 24 Dec 2020 21:28:10 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id m5so2135932pjv.5 for ; Thu, 24 Dec 2020 21:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HfQeMTR9dHIFoLebfafxegiW3US03+p5EYWEz17ILko=; b=HvswmbMDL5uxqB0KAbPcLNnn+5vuDGciqdkPp8cLLiFowOTsnt2IpO66ZQq3/eFtND 9RAVODop0575vtynRDfV8yk0g2eoRiSMLPj7ACMw9U86P6k45SkXO955Wb9FyxMwrGjm Qn6Z5WJWYHuzASpFJfIae3mF3TpQAbrYn1Uls/Dqd8LZh1JF4MRI0PuGZXpx+sLnhBN/ n6vF2LUWpKWeTQAyXzAdaRYFymypMBc62kUu2uC6P1O+w4L56GkLs5452qAg6Ieji8dO nZYNdetwUmuFNUpdE6q8tWL9ShTWWI+6Ossq+vMHxbSJgjXV/nW3GoElhbUKFamCpF4N dfZQ== 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; bh=HfQeMTR9dHIFoLebfafxegiW3US03+p5EYWEz17ILko=; b=Txl3dToxDFTVaz1j26SYTj83kij4lA+xICYKCuZk+vpggvKikwLgCDSQhNdv91l4Lp FET4NQp9OqPq317v7DrlMenyvg7Mb2ipzUCSJCWyB9rBx6rR6KceqWLEkqtu5KCv51EP 26j/US5MOtF/GlWsR4H3Iu8vSYwrWxKAMp93PkjtGlBo2GcAJUmIZ9Tsb7a/DzbvgGB4 LRjmfUkR5UaXFO4meCUcU9bBCMjlC/RJnXj50t49yJJpjaOHKfGkuL5UfXCTgpUG84FL L7WOK6oh0m7YNYbYLPZVVY5Tk58OQhUnOQ0YU7fr1jWQKR3s4CCCycxr+BiUGZROxj8h ybNQ== X-Gm-Message-State: AOAM533F992CeYopKs0U+hJp86YB146A+KZj92TzXgGSWBVSyHEp08vI 8EXOfxWAIuojFPbPgGp6hMtHug== X-Received: by 2002:a17:90b:8d8:: with SMTP id ds24mr7246522pjb.134.1608874090429; Thu, 24 Dec 2020 21:28:10 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id f15sm4156167pju.49.2020.12.24.21.28.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Dec 2020 21:28:09 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , John Garry , Will Deacon , Mathieu Poirier , Masami Hiramatsu , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexandre Truong , Ian Rogers , Thomas Richter , He Zhe , Sumanth Korikkar , Alexis Berlemont , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v2 2/3] perf probe: Fixup Arm64 SDT arguments Date: Fri, 25 Dec 2020 13:27:50 +0800 Message-Id: <20201225052751.24513-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201225052751.24513-1-leo.yan@linaro.org> References: <20201225052751.24513-1-leo.yan@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Arm64 ELF section '.note.stapsdt' uses string format "-4@[sp, NUM]" if the probe is to access data in stack, e.g. below is an example for dumping Arm64 ELF file and shows the argument format: Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4] Comparing against other archs' argument format, Arm64's argument introduces an extra space character in the middle of square brackets, due to argv_split() uses space as splitter, the argument is wrongly divided into two items. To support Arm64 SDT, this patch fixes up for this case, if any item contains sub string "[sp", concatenates the two continuous items. And adds the detailed explaination in comment. Signed-off-by: Leo Yan --- tools/perf/util/probe-file.c | 38 ++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index bbecb449ea94..52273542e6ef 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -794,6 +794,8 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, char *ret = NULL; int i, args_count, err; unsigned long long ref_ctr_offset; + char *arg; + int arg_idx = 0; if (strbuf_init(&buf, 32) < 0) return NULL; @@ -818,11 +820,43 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, if (args == NULL) goto error; - for (i = 0; i < args_count; ++i) { - if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) { + for (i = 0; i < args_count; ) { + /* + * FIXUP: Arm64 ELF section '.note.stapsdt' uses string + * format "-4@[sp, NUM]" if a probe is to access data in + * the stack, e.g. below is an example for the SDT + * Arguments: + * + * Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4] + * + * Since the string introduces an extra space character + * in the middle of square brackets, the argument is + * divided into two items. Fixup for this case, if an + * item contains sub string "[sp,", need to concatenate + * the two items. + */ + if (strstr(args[i], "[sp,") && (i+1) < args_count) { + err = asprintf(&arg, "%s %s", args[i], args[i+1]); + i += 2; + } else { + err = asprintf(&arg, "%s", args[i]); + i += 1; + } + + /* Failed to allocate memory */ + if (err < 0) { argv_free(args); goto error; } + + if (synthesize_sdt_probe_arg(&buf, arg_idx, arg) < 0) { + free(arg); + argv_free(args); + goto error; + } + + free(arg); + arg_idx++; } argv_free(args); -- 2.17.1