From: Florian Krohm Date: Thu, 5 Feb 2026 17:39:49 +0000 (+0000) Subject: s390: Change s390_disasm and tweak specification exception message X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f7088d4c53ad80ca157487dc8dda1544377abd4;p=thirdparty%2Fvalgrind.git s390: Change s390_disasm and tweak specification exception message s390_disasm now returns a pointer to the disassembled insn string or NULL. A new parameter controls whether the mnemonic should be padded with blanks to the max. insn length. When reporting a specification exception also write out the disassembled insn. --- diff --git a/VEX/priv/guest_s390_toIR.c b/VEX/priv/guest_s390_toIR.c index 219388eb6..7950269e6 100644 --- a/VEX/priv/guest_s390_toIR.c +++ b/VEX/priv/guest_s390_toIR.c @@ -20800,8 +20800,10 @@ s390_decode_and_irgen(const UChar *bytes, UInt insn_length, DisResult *dres) s390_decode_special_and_irgen(bytes + S390_SPECIAL_OP_PREAMBLE_SIZE); } else { /* Handle normal instructions. */ - if (UNLIKELY(vex_traceflags & VEX_TRACE_FE)) - s390_disasm(bytes); + if (UNLIKELY(vex_traceflags & VEX_TRACE_FE)) { + HChar *str = s390_disasm(bytes, /* padmnm */ 1); + vex_printf("%s\n", str ? str : "disassembly failed"); + } switch (insn_length) { case 2: @@ -20871,6 +20873,11 @@ s390_decode_and_irgen(const UChar *bytes, UInt insn_length, DisResult *dres) vex_printf(" "); vex_printf("%02x%02x", bytes[i], bytes[i + 1]); } + if (status == S390_DECODE_UNIMPLEMENTED_INSN || + status == S390_DECODE_SPECIFICATION_EXCEPTION) { + const HChar *str = s390_disasm(bytes, /* padmnm */ 0); + vex_printf(" %s", str == NULL ? "??????" : str); + } vex_printf("\n"); } diff --git a/VEX/priv/host_s390_defs.c b/VEX/priv/host_s390_defs.c index d0b7de838..71cb6c897 100644 --- a/VEX/priv/host_s390_defs.c +++ b/VEX/priv/host_s390_defs.c @@ -1473,8 +1473,10 @@ s390_insn_map_regs(HRegRemap *m, s390_insn *insn) static __inline__ UChar * emit(UChar *p, const UChar *insn, UInt len) { - if (UNLIKELY(vex_traceflags & VEX_TRACE_ASM)) - s390_disasm(insn); + if (UNLIKELY(vex_traceflags & VEX_TRACE_ASM)) { + HChar *str = s390_disasm(insn, /* padmnm */ 1); + vex_printf("%s\n", str ? str : "disassembly failed"); + } return (UChar *)__builtin_memcpy(p, insn, len) + len; } diff --git a/VEX/priv/objdump/s390-dis.c b/VEX/priv/objdump/s390-dis.c index eeae533b0..0343b211a 100644 --- a/VEX/priv/objdump/s390-dis.c +++ b/VEX/priv/objdump/s390-dis.c @@ -31,17 +31,21 @@ static int opc_index[256]; static int current_arch_mask = 0; static int option_use_insn_len_bits_p = 0; static int option_print_insn_desc = 0; - +static int pad_mnemonic; static const char * padmnm(const char *mnm) { static char buf[S390_MAX_MNEMONIC_LEN + 1]; - if (vex_strlen(mnm) > S390_MAX_MNEMONIC_LEN) - return "failed: buf too small"; + if (pad_mnemonic) { + if (vex_strlen(mnm) > S390_MAX_MNEMONIC_LEN) + return "failed: buf too small"; - vex_sprintf(buf, "%-*s", S390_MAX_MNEMONIC_LEN, mnm); + vex_sprintf(buf, "%-*s", S390_MAX_MNEMONIC_LEN, mnm); + } else { + vex_sprintf(buf, "%s", mnm); + } return buf; } @@ -677,8 +681,10 @@ s390_disasm_init(SFILE *dis, unsigned (*fp)(char *, const char *, va_list)) } -void -s390_disasm(const unsigned char insn[]) +/* Watch out: returned string is allocated in a static buffer and will + be overwritten in the next invocation. */ +HChar * +s390_disasm(const unsigned char insn[], int pad_mnm) { static int initialised = 0; static SFILE disasm; @@ -688,6 +694,7 @@ s390_disasm(const unsigned char insn[]) s390_disasm_init(&disasm, vex_vsprintf); } + pad_mnemonic = pad_mnm; disasm.pos = 0; /* reset */ disasm.buf[0] = '\0'; @@ -697,5 +704,5 @@ s390_disasm(const unsigned char insn[]) the current address: .+offset of .-offset */ int rc = print_insn_s390(/* address */ 0, insn, disasm.info); - vex_printf("%s\n", (rc == 0) ? "disassemly failed" : disasm.buf); + return rc == 0 ? NULL : disasm.buf; } diff --git a/VEX/priv/s390_disasm.h b/VEX/priv/s390_disasm.h index eec3dbca1..2606b2eec 100644 --- a/VEX/priv/s390_disasm.h +++ b/VEX/priv/s390_disasm.h @@ -31,7 +31,7 @@ #include "libvex_basictypes.h" -void s390_disasm(const UChar *); +HChar *s390_disasm(const UChar *, Int); /*---------------------------------------------------------------*/ /*--- end s390_disasm.h ---*/