Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp667073lqt; Mon, 18 Mar 2024 22:53:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUx2OQ1hqdBpGtsewwH2UHsem/2PdOvD0osktm9VFOqAGiYXfxqR2EOPfT+01+8ordRExvMzj13Swe0r748eAdYtR/e9AZjh7evnTuhPg== X-Google-Smtp-Source: AGHT+IHQjkIuuuSTO6105Ax8wffVHAIk68+aFio3HanVk2jwG6B28GUEurNvWI57ybVWlF3U77Jz X-Received: by 2002:a05:6a21:328e:b0:1a3:5213:d02c with SMTP id yt14-20020a056a21328e00b001a35213d02cmr2381222pzb.31.1710827597497; Mon, 18 Mar 2024 22:53:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710827597; cv=pass; d=google.com; s=arc-20160816; b=i4gVVeahtY+Mq5Tf6q8RgqLT5qwDWe1BoESc1r6TLdda6PJV6RN2gb9hg8HeSN+Wls llYCdIM9qXCdX68snFYL0Sf2+xtaxm9SxviqEb1YappbxLu0HROv1pT9/BPkAa254/R2 70T7BBgsDEsxiSwXc9/adoNXAp7QBRxHLVowxAQVz6cbzHeX66KgEm7gGVhDQVEjoo9s UdKo4WPeo2GywP1NLmFcCbpIsQsH7QVCEZ9ZKZO9GwdYnrv+SkqsYdKjaIKP7gmZobAo IFeTdgI00ObisS7oHHc04V9ViCmdHeDhY7xxa+K51l6daEkvtM07tLXemSRNAvXS46f3 4CCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=yecB0Cw5UHZsNP1HKTviR/b7d/KrnUMEnv9J0hYYdZ0=; fh=44lErbL5kvNUjSV6UDWgBEjJyOJpjjMpxi6K+HFi+Bc=; b=xhD7cEN+1zHOcU1mnFoJpBWtZ0IlQvFv/QwwQZTvWyvTNDThuw2bcVHBbQhEWEjbDe 5cVPIc0FmT0uYUoLHzlRe4H1/MtHUuV8rVVBS7Zut6zyRNbVED5ulhrcat2UgwFmsn7R WW/eTm1nrSbu9YtoSOIMQbW8K9MK4NeTJSRBxGPlPuiStyPbGhMJMMiYHmEhV/o4Fonb wMFMtyfOi6wYFxNWX7uIuQV4O5jts8KGYJG+6dFWzp07ch1aE98CtgQfd8ryKEwHh1eg 0/StnaWg7qrtUGniJYpqDqokrMwEBzQp+zlJxpChE8uc5BEemqXwsAJkDYBN/wG0R+H8 QF2w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="UsrZ/AVi"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107034-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a2-20020a630b42000000b005dcae4c1ff4si9453562pgl.172.2024.03.18.22.53.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 22:53:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="UsrZ/AVi"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107034-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4774AB21B0F for ; Tue, 19 Mar 2024 05:53:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E00CF7E580; Tue, 19 Mar 2024 05:51:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UsrZ/AVi" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF1477D41B; Tue, 19 Mar 2024 05:51:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710827482; cv=none; b=uEaTcrrNUbWmeoXqpCCzv0lZLltqu+R9VeCkAzZz0lx8p6FtAfhzVXUUEzPT5nxkjWgQ6pjKbm6Cba9UzjHoN/cvtRxzE21ygkwAOImwtK4HkvHhKEd0m0LtUlWP5o4o0tKFrwCE0szvxb9e7fZf1b12JNTLQ/nc7K0TBALUQWo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710827482; c=relaxed/simple; bh=ek6tyO55YdT1JBe57BgyHQSsS0HIXVRzIrOiaUCJ7Rs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l6RCy11FB4Wpz1YdpqIycmzcjPijznvu4398PaA1Vs086H1/qUZLg9THGVQ7pXxABul8SlzL4+Z2nrcG5FbWKa4+/Jd3NhWqHkZt9E1QubZUiovrWGrHIxDv9K00EqQZO3WjNRQn4tGGnWu4sYqdSHCTEzX7F8uwfysaAca1hqw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UsrZ/AVi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8FE4C43601; Tue, 19 Mar 2024 05:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710827482; bh=ek6tyO55YdT1JBe57BgyHQSsS0HIXVRzIrOiaUCJ7Rs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UsrZ/AViHFVoq9A7uDh/gzfcOtJNEFoQ/bRR4QNJdM3Hq4LKCIeZMsNB5PgvHjVUi nm2bKuZNZpVNxSu1hKRvpHWWGJ/TA2tzePiF+6H2iQVXTstyOk9UQ5xiFjcfwpHIZ0 ddtJLwJESmqjAS8gGPM9XQykf9qnHXSZkXDo5UhDM++xXqwDaD4YNf4XjCFqovmCqI OQHlpP4da9MdH/S8EwVikZoWMyJ1MKVtjMqcZ62TDguZ9cklX7JRw8X7wVbdNHWt+F gzSt2Cerft2hEMBOQOzgXK0JhzLbnHjz9lvlcAjNRc8sLaWcm5zPePj4RVfpF0+MLU WqUMQMDZf27Ug== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH 08/23] perf annotate-data: Add debug messages Date: Mon, 18 Mar 2024 22:51:00 -0700 Message-ID: <20240319055115.4063940-9-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog In-Reply-To: <20240319055115.4063940-1-namhyung@kernel.org> References: <20240319055115.4063940-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a new debug option "type-profile" to enable the detailed info during the type analysis especially for instruction tracking. You can use this before the command name like 'report' or 'annotate'. $ perf --debug type-profile annotate --data-type Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 74 +++++++++++++++++++++++++++++---- tools/perf/util/debug.c | 3 ++ tools/perf/util/debug.h | 1 + 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index ff81d164aa57..f482ccfdaa91 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -23,6 +23,29 @@ #include "symbol.h" #include "symbol_conf.h" +#define pr_debug_dtp(fmt, ...) \ +do { \ + if (debug_type_profile) \ + pr_info(fmt, ##__VA_ARGS__); \ + else \ + pr_debug3(fmt, ##__VA_ARGS__); \ +} while (0) + +static void pr_debug_type_name(Dwarf_Die *die) +{ + struct strbuf sb; + char *str; + + if (!debug_type_profile && verbose < 3) + return; + + strbuf_init(&sb, 32); + die_get_typename_from_type(die, &sb); + str = strbuf_detach(&sb, NULL); + pr_info(" type=%s (die:%lx)\n", str, (long)dwarf_dieoffset(die)); + free(str); +} + /* * Compare type name and size to maintain them in a tree. * I'm not sure if DWARF would have information of a single type in many @@ -201,7 +224,7 @@ static int check_variable(Dwarf_Die *var_die, Dwarf_Die *type_die, int offset, /* Get the type of the variable */ if (die_get_real_type(var_die, type_die) == NULL) { - pr_debug("variable has no type\n"); + pr_debug_dtp("variable has no type\n"); ann_data_stat.no_typeinfo++; return -1; } @@ -215,7 +238,7 @@ static int check_variable(Dwarf_Die *var_die, Dwarf_Die *type_die, int offset, if ((dwarf_tag(type_die) != DW_TAG_pointer_type && dwarf_tag(type_die) != DW_TAG_array_type) || die_get_real_type(type_die, type_die) == NULL) { - pr_debug("no pointer or no type\n"); + pr_debug_dtp("no pointer or no type\n"); ann_data_stat.no_typeinfo++; return -1; } @@ -223,14 +246,15 @@ static int check_variable(Dwarf_Die *var_die, Dwarf_Die *type_die, int offset, /* Get the size of the actual type */ if (dwarf_aggregate_size(type_die, &size) < 0) { - pr_debug("type size is unknown\n"); + pr_debug_dtp("type size is unknown\n"); ann_data_stat.invalid_size++; return -1; } /* Minimal sanity check */ if ((unsigned)offset >= size) { - pr_debug("offset: %d is bigger than size: %" PRIu64 "\n", offset, size); + pr_debug_dtp("offset: %d is bigger than size: %"PRIu64"\n", + offset, size); ann_data_stat.bad_offset++; return -1; } @@ -251,6 +275,19 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die) int fb_offset = 0; bool is_fbreg = false; u64 pc; + char buf[64]; + + if (dloc->op->multi_regs) + snprintf(buf, sizeof(buf), " or reg%d", dloc->op->reg2); + else if (dloc->op->reg1 == DWARF_REG_PC) + snprintf(buf, sizeof(buf), " (PC)"); + else + buf[0] = '\0'; + + pr_debug_dtp("-----------------------------------------------------------\n"); + pr_debug_dtp("%s [%"PRIx64"] for reg%d%s offset=%#x in %s\n", + __func__, dloc->ip - dloc->ms->sym->start, + dloc->op->reg1, buf, dloc->op->offset, dloc->ms->sym->name); /* * IP is a relative instruction address from the start of the map, as @@ -261,7 +298,7 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die) /* Get a compile_unit for this address */ if (!find_cu_die(dloc->di, pc, &cu_die)) { - pr_debug("cannot find CU for address %" PRIx64 "\n", pc); + pr_debug_dtp("cannot find CU for address %"PRIx64"\n", pc); ann_data_stat.no_cuinfo++; return -1; } @@ -269,12 +306,17 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die) reg = loc->reg1; offset = loc->offset; + pr_debug_dtp("CU die offset: %#lx\n", (long)dwarf_dieoffset(&cu_die)); + if (reg == DWARF_REG_PC) { if (die_find_variable_by_addr(&cu_die, dloc->var_addr, &var_die, &offset)) { ret = check_variable(&var_die, type_die, offset, /*is_pointer=*/false); dloc->type_offset = offset; + + pr_debug_dtp("found PC-rel by addr=%#"PRIx64" offset=%#x\n", + dloc->var_addr, offset); goto out; } @@ -310,6 +352,9 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die) default: break; } + + pr_debug_dtp("frame base: cfa=%d fbreg=%d\n", + dloc->fb_cfa, fbreg); } } @@ -334,6 +379,19 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die) /* Found a variable, see if it's correct */ ret = check_variable(&var_die, type_die, offset, reg != DWARF_REG_PC && !is_fbreg); + if (ret == 0) { + pr_debug_dtp("found \"%s\" in scope=%d/%d (die: %#lx) ", + dwarf_diename(&var_die), i+1, nr_scopes, + (long)dwarf_dieoffset(&scopes[i])); + if (reg == DWARF_REG_PC) + pr_debug_dtp("%#x(PC) offset=%#x", loc->offset, offset); + else if (reg == DWARF_REG_FB || is_fbreg) + pr_debug_dtp("%#x(reg%d) stack fb_offset=%#x offset=%#x", + loc->offset, reg, fb_offset, offset); + else + pr_debug_dtp("%#x(reg%d)", loc->offset, reg); + pr_debug_type_name(type_die); + } dloc->type_offset = offset; goto out; } @@ -343,8 +401,10 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die) goto retry; } - if (ret < 0) + if (ret < 0) { + pr_debug_dtp("no variable found\n"); ann_data_stat.no_var++; + } out: free(scopes); @@ -373,7 +433,7 @@ struct annotated_data_type *find_data_type(struct data_loc_info *dloc) dloc->di = debuginfo__new(dso->long_name); if (dloc->di == NULL) { - pr_debug("cannot get the debug info\n"); + pr_debug_dtp("cannot get the debug info\n"); return NULL; } diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index c39ee0fcb8cf..d633d15329fa 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -41,6 +41,7 @@ static int redirect_to_stderr; int debug_data_convert; static FILE *_debug_file; bool debug_display_time; +int debug_type_profile; FILE *debug_file(void) { @@ -231,6 +232,7 @@ static struct sublevel_option debug_opts[] = { { .name = "data-convert", .value_ptr = &debug_data_convert }, { .name = "perf-event-open", .value_ptr = &debug_peo_args }, { .name = "kmaps", .value_ptr = &debug_kmaps }, + { .name = "type-profile", .value_ptr = &debug_type_profile }, { .name = NULL, } }; @@ -270,6 +272,7 @@ int perf_quiet_option(void) redirect_to_stderr = 0; debug_peo_args = 0; debug_kmaps = 0; + debug_type_profile = 0; return 0; } diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 35a7a5ae762e..a4026d1fd6a3 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h @@ -14,6 +14,7 @@ extern int debug_peo_args; extern bool quiet, dump_trace; extern int debug_ordered_events; extern int debug_data_convert; +extern int debug_type_profile; #ifndef pr_fmt #define pr_fmt(fmt) fmt -- 2.44.0.291.gc1ea87d7ee-goog