Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: gdb-patches@sourceware.org, Tom Tromey <tom@tromey.com>
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: Re: Building today's snapshot of GDB with MinGW
Date: Thu, 02 Jul 2020 17:12:44 +0300	[thread overview]
Message-ID: <83tuyqvwdf.fsf@gnu.org> (raw)
In-Reply-To: <83a70l20dn.fsf@gnu.org> (message from Eli Zaretskii on Mon, 29 Jun 2020 21:27:32 +0300)

> Date: Mon, 29 Jun 2020 21:27:32 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> 
> 4. Running "maint selftests" produces several warnings and failures:

I took a closer look at the selftest failures unrelated to
architectures.  There are a few:

>   Self test failed: self-test failed at unittests/format_pieces-selftests.c:37
>   Self test failed: self-test failed at utils.c:2971
>   Self test failed: Could not convert character to `UTF-8' character set
>   Self test failed: self-test failed at unittests/scoped_fd-selftests.c:80

The one in utils.c:2971 tests gdb_realpath.  It fails because
gdb_realpath implementation on MS-Windows returns a file name with
backslashes, whereas the test compares the basename of the value
starting with the last slash.  The patch to fix that is attached at
the end of this message.

The UTF-8 conversion problem comes from the Rust tests.  I don't
really understand why would this fail, since this GDB is linked with
libiconv.  Tom, can I get some guidance for how to dig deeper into
this?

The test in scoped_fd-selftests.c fails because it does something
MS-Windows doesn't support:

  ::scoped_fd sfd (gdb_mkostemp_cloexec (filename));
  SELF_CHECK (sfd.get () >= 0);

  unlink (filename);

  gdb_file_up file = sfd.to_file ("rw");
  SELF_CHECK (file != nullptr);

Gnulib's mkostemp opens the file with O_RDRW; according to MS
documentation of fdopen, here:

  https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fdopen-wfdopen?view=vs-2019

fdopen fails if the MODE argument doesn't match the original open mode
of the file descriptor, so we must use "r+", not "rw" (which isn't
supported according to the MS docs).  The second patch below fixes
that failure.

Btw, all the tests in scoped_fd-selftests.c call unlink to delete the
temporary file before closing its descriptor.  Is that necessary for
the tests to work correctly?  On Windows these unlink calls all fail,
and the resulting temporary files are left behind and clutter the
directory.  If possible, I'd like to move them after we close the
file.  Is it okay to submit a patch which will do that on all
platforms?

The format_pieces-selftests.c failure is due to the %lld, %llx, and
similar descriptors that test 'long long' formats.  The reason is
clearly seen in the debugger, for this test:

  static void
  test_format_specifier ()
  {
    /* The format string here ends with a % sequence, to ensure we don't
       see a trailing empty literal piece.  */
    check ("Hello\\t %d%llx%%d%d", /* ARI: %ll */
      {
	format_piece ("Hello\t ", literal_piece, 0),
	format_piece ("%d", int_arg, 0),
	format_piece ("%llx", long_long_arg, 0), /* ARI: %ll */
	format_piece ("%%d", literal_piece, 0),
	format_piece ("%d", int_arg, 0),
      });
  }

Here's the relevant part of the debug session:

  (top-gdb) p pieces.m_pieces
  $2 = {<std::_Vector_base<format_piece, std::allocator<format_piece> >> = {
      _M_impl = {<std::allocator<format_piece>> = {<__gnu_cxx::new_allocator<format_piece>> = {<No data fields>}, <No data fields>}, _M_start = 0x178c5f98,
	_M_finish = 0x178c5fd4,
	_M_end_of_storage = 0x178c5ff8}}, <No data fields>}
  (top-gdb) p pieces.m_pieces._M_impl._M_start
  $3 = (std::_Vector_base<format_piece, std::allocator<format_piece> >::pointer) 0x178c5f98
  (top-gdb) p *pieces.m_pieces._M_impl._M_start
  $4 = {string = 0x178c5ad0 "Hello\t ", argclass = literal_piece,
    n_int_args = 0}
  (top-gdb) p pieces.m_pieces._M_impl._M_start[1]
  $5 = {string = 0x178c5ad8 "%d", argclass = int_arg, n_int_args = 0}
  (top-gdb) p pieces.m_pieces._M_impl._M_start[2]
  $6 = {string = 0x178c5adc "%I64x", argclass = long_long_arg, n_int_args = 0}
  (top-gdb) p pieces.m_pieces._M_impl._M_start[3]
  $7 = {string = 0x178c5ae2 "%%d", argclass = literal_piece, n_int_args = 0}
  (top-gdb) p pieces.m_pieces._M_impl._M_start[4]
  $8 = {string = 0x178c5ae6 "%d", argclass = int_arg, n_int_args = 0}

As you see, we replace "%llx" with "%I64x", and the comparison then
fails.  Would it be okay to fix this by providing a different
expected_pieces when USE_PRINTF_I64 is non-zero?

Here are the two patches I propose; ok to commit (with the
appropriate log messages)?

--- gdb/utils.c~	2020-06-29 04:47:10.000000000 +0300
+++ gdb/utils.c	2020-07-02 16:11:45.476031500 +0300
@@ -2967,8 +2967,20 @@ gdb_realpath_check_trailer (const char *
   size_t len = strlen (result.get ());
   size_t trail_len = strlen (trailer);
 
+#ifndef _WIN32
   SELF_CHECK (len >= trail_len
 	      && strcmp (result.get () + len - trail_len, trailer) == 0);
+#else
+  const char *res_trail = result.get () + len - trail_len;
+  int slash = res_trail[0];
+
+  SELF_CHECK (len >= trail_len
+	      && (strcmp (result.get () + len - trail_len, trailer) == 0
+		  || (strcmp (result.get () + len - trail_len + 1,
+			      trailer + 1) == 0
+		      && IS_DIR_SEPARATOR (slash)
+		      && IS_DIR_SEPARATOR (trailer[0]))));
+#endif
 }
 
 static void
--- gdb/unittests/scoped_fd-selftests.c~	2020-06-29 04:47:10.000000000 +0300
+++ gdb/unittests/scoped_fd-selftests.c	2020-07-02 16:30:55.733738900 +0300
@@ -76,7 +76,7 @@ test_to_file ()
 
   unlink (filename);
   
-  gdb_file_up file = sfd.to_file ("rw");
+  gdb_file_up file = sfd.to_file ("r+");
   SELF_CHECK (file != nullptr);
   SELF_CHECK (sfd.get () == -1);
 }


  parent reply	other threads:[~2020-07-02 14:12 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-29 18:27 Eli Zaretskii
2020-06-29 20:36 ` Christian Biesinger
2020-06-30 14:09   ` Eli Zaretskii
2020-06-30 22:24     ` Simon Marchi
2020-07-01 15:09       ` Eli Zaretskii
2020-07-02 13:50         ` Eli Zaretskii
2020-07-02 14:25           ` Simon Marchi
2020-07-02 14:30             ` Simon Marchi
2020-07-02 17:47               ` Eli Zaretskii
2020-07-02 14:40             ` Pedro Alves
2020-07-02 17:46               ` Eli Zaretskii
2020-07-02 18:21                 ` Pedro Alves
2020-07-02 18:33                   ` Eli Zaretskii
2020-07-02 18:34                     ` Pedro Alves
2020-07-01 15:20       ` Eli Zaretskii
2020-07-01 19:25         ` Christian Biesinger
2020-07-02  2:29           ` Eli Zaretskii
2020-07-02 10:18             ` Hannes Domani
2020-07-02 13:20               ` Eli Zaretskii
2020-07-06 10:39                 ` Hannes Domani
2020-07-06 16:35                   ` Eli Zaretskii
2020-07-01 19:25     ` Joel Brobecker
2020-07-02 13:46       ` Eli Zaretskii
2020-06-30 16:18 ` Eli Zaretskii
2020-06-30 18:21   ` Christian Biesinger
2020-06-30 18:28     ` Eli Zaretskii
2020-07-01 19:29   ` Joel Brobecker
2020-07-02  2:31     ` Eli Zaretskii
2020-07-01 19:30   ` Joel Brobecker
2020-07-02 13:39     ` Eli Zaretskii
2020-07-03 15:25       ` Joel Brobecker
2020-07-27  9:49         ` Tom de Vries
2020-07-27 10:05           ` Tom de Vries
2020-07-27 10:26             ` Tom de Vries
2020-07-27 11:48               ` [committed][gdb/build] Fix typo sys/sockets.h -> sys/socket.h Tom de Vries
2020-07-27 12:51                 ` Joel Brobecker
2020-07-27 14:18               ` Building today's snapshot of GDB with MinGW Eli Zaretskii
2020-07-02 14:12 ` Eli Zaretskii [this message]
2020-07-03 15:08   ` Eli Zaretskii

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=83tuyqvwdf.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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