aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndu Bhagat <indu.bhagat@oracle.com>2024-08-01 11:34:08 -0700
committerIndu Bhagat <indu.bhagat@oracle.com>2024-08-01 11:34:08 -0700
commit67f39cdbc9d07ae5f14f988aedc887bb5bbae495 (patch)
treee4f1875abd8bef4764032e83254bd8ed1cb98fee
parentd56083b5047b8e7cc9eda2f867bd2b75724920a1 (diff)
downloadgdb-67f39cdbc9d07ae5f14f988aedc887bb5bbae495.zip
gdb-67f39cdbc9d07ae5f14f988aedc887bb5bbae495.tar.gz
gdb-67f39cdbc9d07ae5f14f988aedc887bb5bbae495.tar.bz2
gas: ginsn: do not emit an unnecessary trailing comma in textual dump
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.
-rw-r--r--gas/ginsn.c20
-rw-r--r--gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l2
-rw-r--r--gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l10
3 files changed, 19 insertions, 13 deletions
diff --git a/gas/ginsn.c b/gas/ginsn.c
index 20e83c5..08c8e5a 100644
--- a/gas/ginsn.c
+++ b/gas/ginsn.c
@@ -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:
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l b/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l
index d05e19d..168547c 100644
--- a/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l
+++ b/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l
@@ -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
diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l b/gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l
index 3261b76..fdb2dcb 100644
--- a/gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l
+++ b/gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l
@@ -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: