Commit a854350af1 for qemu.org
commit a854350af144692f0efc6cd8f1a6254898e89866
Author: Richard Henderson <richard.henderson@linaro.org>
Date: Sat Aug 8 10:49:24 2026 -0700
disas/capstone: Allow for cap_insn_unit > length
cap_insn_unit is designed for targets like arm thumb2
and s390x where 4 and 6-byte insns are displayed in
2-byte chunks.
For riscv, we prefer 4-byte insns to display as one
4-byte unit, rather than 2x 2-byte units. So we will
want to set cap_insn_unit to 4, but allow for insns
that are smaller than 4. Emit padding to match.
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
diff --git a/disas/capstone.c b/disas/capstone.c
index fe3efb0d3c..8fb8d0724c 100644
--- a/disas/capstone.c
+++ b/disas/capstone.c
@@ -107,8 +107,9 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn,
{
fprintf_function print = info->fprintf_func;
FILE *stream = info->stream;
+ int unit = MIN(info->cap_insn_unit, n - i);
- switch (info->cap_insn_unit) {
+ switch (unit) {
case 4:
if (info->endian == BFD_ENDIAN_BIG) {
for (; i < n; i += 4) {
@@ -140,6 +141,11 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn,
}
break;
}
+
+ if (unit < info->cap_insn_unit) {
+ int width = (info->cap_insn_unit - unit) * 2;
+ print(stream, "%*s", width, "");
+ }
}
static void cap_dump_insn(disassemble_info *info, cs_insn *insn)