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>
Richard Henderson committed
Aug 8, 2026 at 10:49 UTC
a854350af144692f0efc6cd8f1a6254898e89866
1 file changed
+7
-1
disas/capstone.c
+7
-1
@@ -107,8 +107,9 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn,
107
{
108
fprintf_function print = info->fprintf_func;
109
FILE *stream = info->stream;
110
+ int unit = MIN(info->cap_insn_unit, n - i);
111
111
- switch (info->cap_insn_unit) {
112
+ switch (unit) {
113
case 4:
114
if (info->endian == BFD_ENDIAN_BIG) {
115
for (; i < n; i += 4) {
@@ -140,6 +141,11 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn,
141
}
142
break;
143
}
144
+
145
+ if (unit < info->cap_insn_unit) {
146
+ int width = (info->cap_insn_unit - unit) * 2;
147
+ print(stream, "%*s", width, "");
148
+ }
149
}
150
151
static void cap_dump_insn(disassemble_info *info, cs_insn *insn)