From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754263AbdC1Fz0 (ORCPT ); Tue, 28 Mar 2017 01:55:26 -0400 Received: from terminus.zytor.com ([65.50.211.136]:51983 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754123AbdC1FzY (ORCPT ); Tue, 28 Mar 2017 01:55:24 -0400 Date: Mon, 27 Mar 2017 22:52:13 -0700 From: tip-bot for Jin Yao Message-ID: Cc: kan.liang@intel.com, ak@linux.intel.com, yao.jin@linux.intel.com, hpa@zytor.com, milian.wolff@kdab.com, mingo@kernel.org, jolsa@kernel.org, acme@redhat.com, linux-kernel@vger.kernel.org, tglx@linutronix.de Reply-To: hpa@zytor.com, yao.jin@linux.intel.com, ak@linux.intel.com, kan.liang@intel.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, acme@redhat.com, milian.wolff@kdab.com, mingo@kernel.org, jolsa@kernel.org In-Reply-To: <1490474069-15823-2-git-send-email-yao.jin@linux.intel.com> References: <1490474069-15823-2-git-send-email-yao.jin@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf report: Refactor common code in srcline.c Git-Commit-ID: 5580338d0f207921bc1fef5b668cd564adcc3419 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 5580338d0f207921bc1fef5b668cd564adcc3419 Gitweb: http://git.kernel.org/tip/5580338d0f207921bc1fef5b668cd564adcc3419 Author: Jin Yao AuthorDate: Sun, 26 Mar 2017 04:34:25 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 27 Mar 2017 11:59:23 -0300 perf report: Refactor common code in srcline.c Introduce dso__name() and filename_split() out of existing code because these codes will be used in several places in next patch. For filename_split(), it may also solve a potential memory leak in existing code. In existing addr2line(), sep = strchr(filename, ':'); if (sep) { *sep++ = '\0'; *file = filename; *line_nr = strtoul(sep, NULL, 0); ret = 1; } out: pclose(fp); return ret; If sep is NULL, filename is not freed or returned via file. Signed-off-by: Yao Jin Tested-by: Milian Wolff Cc: Andi Kleen Cc: Jiri Olsa Cc: Kan Liang Link: http://lkml.kernel.org/r/1490474069-15823-2-git-send-email-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/srcline.c | 68 +++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c index b4db3f4..2953c9f 100644 --- a/tools/perf/util/srcline.c +++ b/tools/perf/util/srcline.c @@ -12,6 +12,24 @@ bool srcline_full_filename; +static const char *dso__name(struct dso *dso) +{ + const char *dso_name; + + if (dso->symsrc_filename) + dso_name = dso->symsrc_filename; + else + dso_name = dso->long_name; + + if (dso_name[0] == '[') + return NULL; + + if (!strncmp(dso_name, "/tmp/perf-", 10)) + return NULL; + + return dso_name; +} + #ifdef HAVE_LIBBFD_SUPPORT /* @@ -207,6 +225,27 @@ void dso__free_a2l(struct dso *dso) #else /* HAVE_LIBBFD_SUPPORT */ +static int filename_split(char *filename, unsigned int *line_nr) +{ + char *sep; + + sep = strchr(filename, '\n'); + if (sep) + *sep = '\0'; + + if (!strcmp(filename, "??:0")) + return 0; + + sep = strchr(filename, ':'); + if (sep) { + *sep++ = '\0'; + *line_nr = strtoul(sep, NULL, 0); + return 1; + } + + return 0; +} + static int addr2line(const char *dso_name, u64 addr, char **file, unsigned int *line_nr, struct dso *dso __maybe_unused, @@ -216,7 +255,6 @@ static int addr2line(const char *dso_name, u64 addr, char cmd[PATH_MAX]; char *filename = NULL; size_t len; - char *sep; int ret = 0; scnprintf(cmd, sizeof(cmd), "addr2line -e %s %016"PRIx64, @@ -233,23 +271,14 @@ static int addr2line(const char *dso_name, u64 addr, goto out; } - sep = strchr(filename, '\n'); - if (sep) - *sep = '\0'; - - if (!strcmp(filename, "??:0")) { - pr_debug("no debugging info in %s\n", dso_name); + ret = filename_split(filename, line_nr); + if (ret != 1) { free(filename); goto out; } - sep = strchr(filename, ':'); - if (sep) { - *sep++ = '\0'; - *file = filename; - *line_nr = strtoul(sep, NULL, 0); - ret = 1; - } + *file = filename; + out: pclose(fp); return ret; @@ -278,15 +307,8 @@ char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym, if (!dso->has_srcline) goto out; - if (dso->symsrc_filename) - dso_name = dso->symsrc_filename; - else - dso_name = dso->long_name; - - if (dso_name[0] == '[') - goto out; - - if (!strncmp(dso_name, "/tmp/perf-", 10)) + dso_name = dso__name(dso); + if (dso_name == NULL) goto out; if (!addr2line(dso_name, addr, &file, &line, dso, unwind_inlines))