diff options
| author | Alexandre Chartre <alexandre.chartre@oracle.com> | 2025-11-21 10:53:17 +0100 |
|---|---|---|
| committer | Peter Zijlstra <peterz@infradead.org> | 2025-11-21 15:30:08 +0100 |
| commit | 0bb080ba6469a573bc85122153d931334d10a173 (patch) | |
| tree | a5c158ee68e7bf24b55999c9ec58e1b9935f8606 /tools/objtool/check.c | |
| parent | d4e13c21497d0cde73694163908f89d7168c1243 (diff) | |
objtool: Disassemble instruction on warning or backtrace
When an instruction warning (WARN_INSN) or backtrace (BT_INSN) is issued,
disassemble the instruction to provide more context.
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://patch.msgid.link/20251121095340.464045-8-alexandre.chartre@oracle.com
Diffstat (limited to 'tools/objtool/check.c')
| -rw-r--r-- | tools/objtool/check.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 0999717abc9c..4da1f07b3538 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4792,11 +4792,34 @@ static void free_insns(struct objtool_file *file) free(chunk->addr); } +static struct disas_context *objtool_disas_ctx; + +const char *objtool_disas_insn(struct instruction *insn) +{ + struct disas_context *dctx = objtool_disas_ctx; + + if (!dctx) + return ""; + + disas_insn(dctx, insn); + return disas_result(dctx); +} + int check(struct objtool_file *file) { - struct disas_context *disas_ctx; + struct disas_context *disas_ctx = NULL; int ret = 0, warnings = 0; + /* + * If the verbose or backtrace option is used then we need a + * disassembly context to disassemble instruction or function + * on warning or backtrace. + */ + if (opts.verbose || opts.backtrace) { + disas_ctx = disas_context_create(file); + objtool_disas_ctx = disas_ctx; + } + arch_initial_func_cfi_state(&initial_func_cfi); init_cfi_state(&init_cfi); init_cfi_state(&func_cfi); @@ -4936,11 +4959,12 @@ out: if (opts.verbose) { if (opts.werror && warnings) WARN("%d warning(s) upgraded to errors", warnings); - disas_ctx = disas_context_create(file); - if (disas_ctx) { - disas_warned_funcs(disas_ctx); - disas_context_destroy(disas_ctx); - } + disas_warned_funcs(disas_ctx); + } + + if (disas_ctx) { + disas_context_destroy(disas_ctx); + objtool_disas_ctx = NULL; } free_insns(file); |