]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
s390: Change s390_disasm and tweak specification exception message
authorFlorian Krohm <flo2030@eich-krohm.de>
Thu, 5 Feb 2026 17:39:49 +0000 (17:39 +0000)
committerFlorian Krohm <flo2030@eich-krohm.de>
Thu, 5 Feb 2026 17:39:49 +0000 (17:39 +0000)
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.

VEX/priv/guest_s390_toIR.c
VEX/priv/host_s390_defs.c
VEX/priv/objdump/s390-dis.c
VEX/priv/s390_disasm.h

index 219388eb6bf34c41f63655c2510c1c9d046a8a32..7950269e6dce1725580dc6d9517875766eb9fd7f 100644 (file)
@@ -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");
    }
 
index d0b7de83849be49cbfa44eb5fd718980f80a0b18..71cb6c8977357c78351852609824123cfd88124d 100644 (file)
@@ -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;
 }
index eeae533b0a114ac8fa5b603761f74832fcdfae29..0343b211a2a61c9d4a8977eeac9cfa80a24b4d65 100644 (file)
@@ -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;
 }
index eec3dbca1777cf83775da3ea0eaaa302441a7665..2606b2eecad0aa9a07015c961d34038609c4f4d1 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "libvex_basictypes.h"
 
-void s390_disasm(const UChar *);
+HChar *s390_disasm(const UChar *, Int);
 
 /*---------------------------------------------------------------*/
 /*--- end                                       s390_disasm.h ---*/