linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf probe: Add support for DW_OP_call_frame_cfa vars
@ 2020-04-01 16:19 Daniel Shaulov
  2020-04-02 18:49 ` Arnaldo Carvalho de Melo
  2020-04-03  5:43 ` Masami Hiramatsu
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Shaulov @ 2020-04-01 16:19 UTC (permalink / raw)
  Cc: Daniel Shaulov, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Masami Hiramatsu, Thomas Gleixner,
	Greg Kroah-Hartman, Thomas Richter, linux-kernel

Add support for probes on variables with DW_OP_call_frame_cfa
as the dwarf operation in the debug info.

Some compilers (specifically Golang compiler) output
DW_OP_call_frame_cfa instead of DW_OP_fbreg for variables
on the stack. If DW_OP_call_frame_cfa is the only expression
than it is the same as DW_OP_fbreg with an offset of zero.
In the case of the Golang compiler, DW_OP_call_frame_cfa may
be followed by DW_OP_consts, with a number and than DW_OP_plus.
This trio is the same as DW_OP_fbreg with the number from
DW_OP_consts as the offset.

With this change, probing on functions in Golang with variables works.

Signed-off-by: Daniel Shaulov <daniel.shaulov@granulate.io>
---
 tools/perf/util/probe-finder.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index e4cff49384f4..866b17aea263 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -240,11 +240,23 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr,
 	}
 
 	/* If this is based on frame buffer, set the offset */
-	if (op->atom == DW_OP_fbreg) {
+	if (op->atom == DW_OP_fbreg || op->atom == DW_OP_call_frame_cfa) {
 		if (fb_ops == NULL)
 			return -ENOTSUP;
 		ref = true;
-		offs = op->number;
+		if (op->atom == DW_OP_fbreg) {
+			offs = op->number;
+		} else if (nops == 3) {
+			/*
+			 * In the case of DW_OP_call_frame_cfa, we either have
+			 * an offset of 0 or we have two more expressions that
+			 * add a const
+			 */
+			if ((op + 1)->atom != DW_OP_consts ||
+			    (op + 2)->atom != DW_OP_plus)
+				return -ENOTSUP;
+			offs = (op + 1)->number;
+		}
 		op = &fb_ops[0];
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-03 17:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-01 16:19 [PATCH] perf probe: Add support for DW_OP_call_frame_cfa vars Daniel Shaulov
2020-04-02 18:49 ` Arnaldo Carvalho de Melo
2020-04-02 20:25   ` Daniel Shaulov
2020-04-03  5:39     ` Masami Hiramatsu
2020-04-03 13:02     ` Arnaldo Carvalho de Melo
2020-04-03 17:59       ` Daniel Shaulov
2020-04-03  5:43 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).