[PATCH v3 28/28] objtool: Print single line for alternatives with one instruction

Alexandre Chartre posted 28 patches 2 months, 4 weeks ago
There is a newer version of this series
[PATCH v3 28/28] objtool: Print single line for alternatives with one instruction
Posted by Alexandre Chartre 2 months, 4 weeks ago
When disassembling, if an instruction has alternatives which are all
made of a single instruction then print the original instruction and
alternative instructions on a single line with no header. Alternatives
are described in a comment on the same line, after the different
instructions.

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

diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c
index 20d64b58182ce..2fc5821acbc3f 100644
--- a/tools/objtool/disas.c
+++ b/tools/objtool/disas.c
@@ -1012,6 +1012,24 @@ static void *disas_alt(struct disas_context *dctx,
 	}
 	alt_count = i;
 
+	/*
+	 * Print default and non-default alternatives.
+	 *
+	 * If all alternatives have a single instruction then print all
+	 * alternatives on a single line. Otherwise, print alternatives
+	 * side-by-side with an header and a line for each instruction
+	 * of the different alternatives.
+	 */
+
+	if (insn_count == 1) {
+		disas_print(stdout, orig_insn->sec, orig_insn->offset, 0, NULL);
+		printf("%s", alts[0].insn[0].str);
+		for (i = 1; i < alt_count; i++)
+			printf(" | %s  (%s)", alts[i].insn[0].str, alts[i].name);
+		printf("   # <alternative.%x>\n", alt_id);
+		return orig_insn;
+	}
+
 	/*
 	 * Print an header with the name of each alternative.
 	 */
-- 
2.43.5