]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: ginsn: do not emit an unnecessary trailing comma in textual dump
authorIndu Bhagat <indu.bhagat@oracle.com>
Thu, 1 Aug 2024 18:34:08 +0000 (11:34 -0700)
committerIndu Bhagat <indu.bhagat@oracle.com>
Thu, 1 Aug 2024 18:34:08 +0000 (11:34 -0700)
For ginsns with less than 2 source operands or no destination operands,
the current textual dump contains a superfluous comma, like the relevant
testcases show.

Adjust the code a bit to not emit the lone trailing comma.  Also, adjust
the aarch64 and x86_64 testcases.

gas/
        * ginsn.c (ginsn_src_print): Do not use a trailing comma when
printing the src of ginsn.
        (ginsn_print): Check the strlen and prefix a comma before the
src string.

gas/testsuite/
* gas/scfi/aarch64/ginsn-cofi-1.l: Adjust the expected textual
dump of the ginsn.
* gas/scfi/x86_64/ginsn-cofi-1.l: Likewise.

gas/ginsn.c
gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l
gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l

index 20e83c5d51e23883cbde9b7c27be3c0a6ab2edc1..08c8e5ac3f8f88db888d3318ee5751b6dc9745f9 100644 (file)
@@ -477,14 +477,14 @@ ginsn_src_print (struct ginsn_src *src)
   switch (src->type)
     {
     case GINSN_SRC_REG:
-      snprintf (src_str, len, "%%r%d", ginsn_get_src_reg (src));
+      snprintf (src_str, len, "%%r%d", ginsn_get_src_reg (src));
       break;
     case GINSN_SRC_IMM:
-      snprintf (src_str, len, "%lld",
+      snprintf (src_str, len, "%lld",
                (long long int) ginsn_get_src_imm (src));
       break;
     case GINSN_SRC_INDIRECT:
-      snprintf (src_str, len, "[%%r%d+%lld]", ginsn_get_src_reg (src),
+      snprintf (src_str, len, "[%%r%d+%lld]", ginsn_get_src_reg (src),
                (long long int) ginsn_get_src_disp (src));
       break;
     default:
@@ -578,16 +578,22 @@ ginsn_print (ginsnS *ginsn)
   /* src 2.  */
   src = ginsn_get_src2 (ginsn);
   src_buf = ginsn_src_print (src);
-  str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
-                       "%s", src_buf);
+  if (strlen (src_buf))
+    {
+      str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
+                           ", %s", src_buf);
+    }
   free (src_buf);
   gas_assert (str_size >= 0 && str_size < GINSN_LISTING_LEN);
 
   /* dst.  */
   dst = ginsn_get_dst (ginsn);
   char *dst_buf = ginsn_dst_print (dst);
-  str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
-                       "%s", dst_buf);
+  if (strlen (dst_buf))
+    {
+      str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
+                           ", %s", dst_buf);
+    }
   free (dst_buf);
 
 end:
index d05e19d059d3fa8e3ec7679e0b5a6f74968503bd..168547cf938ea5b0aad84b8f997a1e8997fce90a 100644 (file)
@@ -19,7 +19,7 @@ AARCH64 GAS  .*
   11 \?\?\?\? 02000014                 b       .L3
   11                   ginsn: JMP 
   12 \?\?\?\? 20021FD6                 br      x17
-  12                   ginsn: JMP %r17
+  12                   ginsn: JMP %r17
   13                   .L3:
   13                   ginsn: SYM .L3
   14 \?\?\?\? 60003FD6                 blr     x3
index 3261b76a5fdb4b29fd3e0f9f927e8db0b1996cae..fdb2dcb5c22bd2f2ee8faffdb3f6eff80002904a 100644 (file)
@@ -18,7 +18,7 @@ GAS LISTING .*
   11 \?\?\?\? E200                     loop    foo
   11                   ginsn: JCC 
   12 \?\?\?\? 3EFFE0                   notrack jmp     \*%rax
-  12                   ginsn: JMP %r0
+  12                   ginsn: JMP %r0
   13 \?\?\?\? 41FFD0                   call    \*%r8
   13                   ginsn: CALL
   14 \?\?\?\? FF14C500                 call    \*cost_arr\(,%rax,8\)
@@ -33,15 +33,15 @@ GAS LISTING .*
   17 \?\?\?\? 67E316                   jecxz   .L179
   17                   ginsn: JCC 
   18 \?\?\?\? 41FFE0                   jmp     \*%r8
-  18                   ginsn: JMP %r8
+  18                   ginsn: JMP %r8
   19 \?\?\?\? FF6730                   jmp     \*48\(%rdi\)
-  19                   ginsn: JMP %r5
+  19                   ginsn: JMP %r5
   20 \?\?\?\? FF24C500                 jmp     \*cost_arr\(,%rax,8\)
   20      000000
-  20                   ginsn: JMP %r0
+  20                   ginsn: JMP %r0
   21 \?\?\?\? FF242500                 jmp     \*symbol\+1
   21      000000
-  21                   ginsn: JMP %r4
+  21                   ginsn: JMP %r4
   22 \?\?\?\? 7000                     jo      .L179
   22                   ginsn: JCC 
   23                   .L179: