Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1447751

[PATCH 1/2] perf symbols: use .gnu_debuglink as gdb does

From Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Newsgroups linux.kernel
Subject [PATCH 1/2] perf symbols: use .gnu_debuglink as gdb does
Date 2016-07-21 11:50 +0200
Message-ID <rXiMa-5GH-15@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


As documented in the comment gdb looks for debug files not only relative
to the binary's directory, but also in .debug and /usr/lib/debug/.
Let perf do the same thing.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 tools/perf/util/dso.c | 49 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 774f6ec884d5..51d39f37cabd 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -45,21 +45,50 @@ int dso__read_binary_type_filename(const struct dso *dso,
 
 	switch (type) {
 	case DSO_BINARY_TYPE__DEBUGLINK: {
-		char *debuglink;
+		/* gdb interprets the content of the debuglink section as
+		 * path relative to
+		 *  - the binary's directory
+		 *  - .debug/ in the binary's directory
+		 *  - /usr/lib/debug
+		 *  and uses the first one that exists.
+		 */
+		char debuglink[512];
+		char *pathbase;
 
 		len = __symbol__join_symfs(filename, size, dso->long_name);
-		debuglink = filename + len;
-		while (debuglink != filename && *debuglink != '/')
-			debuglink--;
-		if (*debuglink == '/')
-			debuglink++;
+		if (!is_regular_file(filename)) {
+			ret = -1;
+			break;
+		}
 
-		ret = -1;
-		if (!is_regular_file(filename))
+		ret = filename__read_debuglink(filename,
+					       debuglink, sizeof(debuglink));
+		if (ret < 0)
+			break;
+
+		pathbase = filename + len;
+		while (pathbase != filename && *pathbase != '/')
+			pathbase--;
+		if (*pathbase == '/')
+			pathbase++;
+
+		snprintf(pathbase, size - (pathbase - filename),
+			 "%s", debuglink);
+		if (is_regular_file(filename))
+			break;
+
+		snprintf(pathbase, size - (pathbase - filename),
+			 ".debug/%s", debuglink);
+		if (is_regular_file(filename))
+			break;
+
+		len = __symbol__join_symfs(filename, size, "/usr/lib/debug");
+		snprintf(filename + len, size - len, "%s", debuglink);
+
+		if (is_regular_file(filename))
 			break;
 
-		ret = filename__read_debuglink(filename, debuglink,
-					       size - (debuglink - filename));
+		ret = -1;
 		}
 		break;
 	case DSO_BINARY_TYPE__BUILD_ID_CACHE:
-- 
2.8.1

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] perf symbols: use .gnu_debuglink as gdb does Uwe Kleine-König   <u.kleine-koenig@pengutronix.de> - 2016-07-21 11:50 +0200
  [PATCH 2/2] perf probe: Add option --symfs Uwe Kleine-König   <u.kleine-koenig@pengutronix.de> - 2016-07-21 11:50 +0200

csiph-web