public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: gdb-patches@sourceware.org, Simon Marchi <simon.marchi@polymtl.ca>
Subject: [COMMITTED PATCH] gdb: testsuite: make string[] type as char in gdb.base/charset.c
Date: Thu, 13 Jan 2022 11:29:01 +0800	[thread overview]
Message-ID: <20220113032901.69707-1-yangtiezhu@loongson.cn> (raw)

This reverts the commit ff656e2e1cb1 ("gdb: testsuite: fix failed
testcases in gdb.base/charset.exp").

The original test code has no problem. On an architecture where
char is signed, then both 'A' and ebcdic_us_string[7] will yield
-63, which makes the equality true. On an architecture where char
is unsigned, then both 'A' and ebcdic_us_string[7] will yield 193,
which also makes the equality true.

The test cases only failed on LoongArch. The default type of char
is signed char on LoongArch, like x86-64. But when use gdb print
command on LoongArch, the default type of char is unsigned char,
this is wrong, I will look into it later, sorry for that.

On LoongArch:

  $ cat test_char.c
  #include <stdio.h>

  int main()
  {
          char c1 = 193;
          unsigned char c2 = 193;

          printf("%d\n", c1);
          printf("%d\n", c1 == c2);

          return 0;
  }
  $ gcc test_char.c -o test_char
  $ ./test_char
  -63
  0

  (gdb) set target-charset EBCDIC-US
  (gdb) print 'A'
  $1 = 193 'A'
  (gdb) print /c 'A'
  $2 = 193 'A'
  (gdb) print /u 'A'
  $3 = 193
  (gdb) print /d 'A'
  $4 = -63
  (gdb) print /x 'A'
  $5 = 0xc1

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 gdb/testsuite/gdb.base/charset.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gdb/testsuite/gdb.base/charset.c b/gdb/testsuite/gdb.base/charset.c
index dd66252c5e4..30c3fb42892 100644
--- a/gdb/testsuite/gdb.base/charset.c
+++ b/gdb/testsuite/gdb.base/charset.c
@@ -44,10 +44,10 @@
 
 #define NUM_CHARS (71)
 
-unsigned char ascii_string[NUM_CHARS];
-unsigned char iso_8859_1_string[NUM_CHARS];
-unsigned char ebcdic_us_string[NUM_CHARS];
-unsigned char ibm1047_string[NUM_CHARS];
+char ascii_string[NUM_CHARS];
+char iso_8859_1_string[NUM_CHARS];
+char ebcdic_us_string[NUM_CHARS];
+char ibm1047_string[NUM_CHARS];
 
 #ifndef __cplusplus
 
@@ -86,7 +86,7 @@ long long_array[3];
    explicit casts or warnings.  */
 
 void
-init_string (unsigned char string[],
+init_string (char string[],
 	     unsigned char x,
 	     unsigned char alert,
 	     unsigned char backspace,
@@ -115,7 +115,7 @@ init_string (unsigned char string[],
 
 
 void
-fill_run (unsigned char string[], int start, int len, int first)
+fill_run (char string[], int start, int len, int first)
 {
   int i;
 
-- 
2.27.0


                 reply	other threads:[~2022-01-13  3:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220113032901.69707-1-yangtiezhu@loongson.cn \
    --to=yangtiezhu@loongson.cn \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).