Bug 27957 - Add check-readmore
Summary: Add check-readmore
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: testsuite (show other bugs)
Version: HEAD
: P2 enhancement
Target Milestone: 12.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-05 12:30 UTC by Tom de Vries
Modified: 2021-10-09 16:54 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2021-06-05 12:30:18 UTC
I ran into this FAIL:
...
    FAIL: gdb.base/info-types-c.exp: info types (state == 1)
...

It was not 100% reproducible, due to gdb printing speed and matching order.

And it was not one of the cases caught by check-read1, instead, check-read1 made it pass reliably.

Which made me wonder, can we make the opposite: make something similar to read1, but instead of forcing read to return 1 byte at the a time, try to make read more patient and try to read a bit more.

I gave it a try:
...
$ git diff
diff --git a/gdb/testsuite/lib/read1.c b/gdb/testsuite/lib/read1.c
index 7dabdd4ca0c..960db7933dc 100644
--- a/gdb/testsuite/lib/read1.c
+++ b/gdb/testsuite/lib/read1.c
@@ -29,6 +29,7 @@ ssize_t
 read (int fd, void *buf, size_t count)
 {
   static ssize_t (*read2) (int fd, void *buf, size_t count) = NULL;
+  ssize_t res, res2;
   if (read2 == NULL)
     {
       /* Use setenv (v, "", 1) rather than unsetenv (v) to work around
@@ -38,7 +39,18 @@ read (int fd, void *buf, size_t count)
       setenv ("LD_PRELOAD", "", 1);
       read2 = dlsym (RTLD_NEXT, "read");
     }
-  if (count > 1 && isatty (fd) >= 1)
-    count = 1;
-  return read2 (fd, buf, count);
+  res = read2 (fd, buf, count);
+  if (isatty (fd) == 0)
+    return res;
+
+  if (res == count || res == -1)
+    return res;
+
+  sleep (1);
+
+  res2 = read2 (fd, (char *)buf + res, count - res);
+  if (res2 == -1)
+    res2 = 0;
+
+  return res + res2;
 }
...
Comment 1 Tom de Vries 2021-06-08 07:25:20 UTC
Posted RFC: https://sourceware.org/pipermail/gdb-patches/2021-June/179675.html