mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Chartre <alexandre.chartre@oracle.com>
To: linux-kernel@vger.kernel.org, mingo@kernel.org,
	jpoimboe@kernel.org, peterz@infradead.org
Cc: alexandre.chartre@oracle.com
Subject: [RFC 12/13] objtool: Improve tracing of alternative instructions
Date: Fri,  6 Jun 2025 17:34:39 +0200	[thread overview]
Message-ID: <20250606153440.865808-13-alexandre.chartre@oracle.com> (raw)
In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com>

When tracing function validation, improve the reporting of
alternative instruction by more clearly showing the different
alternatives beginning and end.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
 tools/objtool/check.c | 59 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 3 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 050d34930372..afcb6c67daa9 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -54,9 +54,61 @@ static int vtrace_depth;
 		}						\
 	} while (0)
 
+#define VTRACE_INFO(insn, fmt, ...)				\
+	do {							\
+		if (vtrace)					\
+			vtrace_info(insn, fmt, ##__VA_ARGS__);	\
+	} while (0)
+
+#define VTRACE_ALT_FMT(fmt) "<alternative.%lx> alt " fmt
+
+#define VTRACE_ALT(insn, fmt, ...)				\
+	VTRACE_INSN(insn, VTRACE_ALT_FMT(fmt),			\
+		    (insn)->offset, ##__VA_ARGS__)
+
+#define VTRACE_ALT_INFO(insn, fmt, ...)				\
+	VTRACE_INFO(insn, VTRACE_ALT_FMT(fmt),			\
+		    (insn)->offset, ##__VA_ARGS__)
+
+#define VTRACE_ALT_INFO_NOADDR(insn, fmt, ...)			\
+	VTRACE_INFO(NULL, VTRACE_ALT_FMT(fmt),			\
+		    (insn)->offset, ##__VA_ARGS__)
+
 #define VTRACE_INSN_OFFSET_SPACE	10
 #define VTRACE_INSN_SPACE		60
 
+/*
+ * Print a message in the instruction flow. If insn is not NULL then
+ * the instruction address is printed in addition of the message,
+ * otherwise only the message is printed. In all cases, the instruction
+ * itself is not printed.
+ */
+static void vtrace_info(struct instruction *insn, const char *format, ...)
+{
+	const char *addr_str;
+	va_list args;
+	int len;
+	int i;
+
+	len = sym_name_max_len + VTRACE_INSN_OFFSET_SPACE;
+	if (insn) {
+		addr_str = offstr(insn->sec, insn->offset);
+		VTRACE_PRINTF("%6lx:  %-*s  ", insn->offset, len, addr_str);
+	} else {
+		len += 11;
+		VTRACE_PRINTF("%-*s", len, "");
+	}
+
+	/* print vertical bars to show the validation flow */
+	for (i = 1; i < vtrace_depth; i++)
+		VTRACE_PRINTF("| ");
+
+	va_start(args, format);
+	vfprintf(stderr, format, args);
+	va_end(args);
+	VTRACE_PRINTF("\n");
+}
+
 /*
  * Print an instruction address (offset and function), the instruction itself
  * and an optional message.
@@ -3692,7 +3744,7 @@ static bool skip_alt_group(struct instruction *insn)
 
 	/* ANNOTATE_IGNORE_ALTERNATIVE */
 	if (insn->alt_group && insn->alt_group->ignore) {
-		VTRACE_INSN(insn, "alt group ignored");
+		VTRACE_ALT(insn, "alt group ignored");
 		return true;
 	}
 
@@ -3905,8 +3957,9 @@ static int validate_insn(struct objtool_file *file, struct symbol *func,
 
 		i = 1;
 		for (alt = insn->alts; alt; alt = alt->next) {
-			VTRACE_INSN(insn, "alternative %d/%d", i, count);
+			VTRACE_ALT_INFO(insn, "%d/%d begin", i, count);
 			ret = validate_branch(file, func, alt->insn, *statep);
+			VTRACE_ALT_INFO_NOADDR(insn, "%d/%d end", i, count);
 			if (ret) {
 				BT_INSN(insn, "(alt)");
 				return ret;
@@ -3914,7 +3967,7 @@ static int validate_insn(struct objtool_file *file, struct symbol *func,
 			i++;
 		}
 
-		VTRACE_INSN(insn, "alternative orig");
+		VTRACE_ALT_INFO(insn, "default");
 	}
 
 	if (skip_alt_group(insn))
-- 
2.43.5


  parent reply	other threads:[~2025-06-06 15:35 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06 15:34 [RFC 00/13] objtool: Function validation tracing Alexandre Chartre
2025-06-06 15:34 ` [RFC 01/13] objtool: Move disassembly functions to a separated file Alexandre Chartre
2025-06-06 15:34 ` [RFC 02/13] objtool: Create disassembly context Alexandre Chartre
2025-06-10 21:12   ` Josh Poimboeuf
2025-06-06 15:34 ` [RFC 03/13] objtool: Disassemble code with libopcodes instead of running objdump Alexandre Chartre
2025-06-10 21:22   ` Josh Poimboeuf
2025-06-11 12:23   ` Peter Zijlstra
2025-06-11 13:35     ` Alexandre Chartre
2025-06-11 19:25       ` Josh Poimboeuf
2025-06-06 15:34 ` [RFC 04/13] objtool: Print symbol during disassembly Alexandre Chartre
2025-06-10 21:55   ` Josh Poimboeuf
2025-06-06 15:34 ` [RFC 05/13] objtool: Store instruction disassembly result Alexandre Chartre
2025-06-10 22:40   ` Josh Poimboeuf
2025-06-06 15:34 ` [RFC 06/13] objtool: Disassemble instruction on warning or backtrace Alexandre Chartre
2025-06-06 15:34 ` [RFC 07/13] objtool: Extract code to validate instruction from the validate branch loop Alexandre Chartre
2025-06-10 23:31   ` Josh Poimboeuf
2025-06-06 15:34 ` [RFC 08/13] objtool: Record symbol name max length Alexandre Chartre
2025-06-06 15:34 ` [RFC 09/13] objtool: Add option to trace function validation Alexandre Chartre
2025-06-11  0:48   ` Josh Poimboeuf
2025-06-06 15:34 ` [RFC 10/13] objtool: Trace instruction state changes during " Alexandre Chartre
2025-06-11  1:23   ` Josh Poimboeuf
2025-06-06 15:34 ` [RFC 11/13] objtool: Improve register reporting " Alexandre Chartre
2025-06-06 15:34 ` Alexandre Chartre [this message]
2025-06-06 15:34 ` [RFC 13/13] objtool: Do not validate IBT for .return_sites and .call_sites Alexandre Chartre
2025-06-06 15:58 ` [RFC 00/13] objtool: Function validation tracing Josh Poimboeuf
2025-06-06 19:29   ` Alexandre Chartre
2025-06-09 18:31 ` Josh Poimboeuf
2025-06-10  7:07   ` Alexandre Chartre
2025-06-10 13:00     ` Alexandre Chartre
2025-06-10 21:05       ` Josh Poimboeuf
2025-06-11  6:00         ` Alexandre Chartre
2025-06-11 14:20           ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250606153440.865808-13-alexandre.chartre@oracle.com \
    --to=alexandre.chartre@oracle.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®