public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp
@ 2021-11-15 11:21 Tom de Vries
  2021-11-15 11:21 ` [PATCH 2/2] [gdb] Don't use gdb_stdlog for inferior-events Tom de Vries
  2021-11-15 16:39 ` [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp Simon Marchi
  0 siblings, 2 replies; 7+ messages in thread
From: Tom de Vries @ 2021-11-15 11:21 UTC (permalink / raw)
  To: gdb-patches

Test-case gdb.base/foll-vfork.exp has inferior output that is not needed, but
which makes the regexp matching more difficult (see commit 1f28b70def1
"[gdb/testsuite] Fix regexp in gdb.base/foll-vfork.exp").

Disable the inferior output using '#if DEBUG'.

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.base/foll-vfork-exit.c | 14 ++++++++++++--
 gdb/testsuite/gdb.base/foll-vfork.c      |  9 ++++++++-
 gdb/testsuite/gdb.base/foll-vfork.exp    | 17 +++++++++++------
 gdb/testsuite/gdb.base/vforked-prog.c    |  7 ++++++-
 4 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/gdb/testsuite/gdb.base/foll-vfork-exit.c b/gdb/testsuite/gdb.base/foll-vfork-exit.c
index 6c263cdc057..15e272afe82 100644
--- a/gdb/testsuite/gdb.base/foll-vfork-exit.c
+++ b/gdb/testsuite/gdb.base/foll-vfork-exit.c
@@ -29,12 +29,22 @@ main ()
   pid = vfork (); /* VFORK */
   if (pid == 0)
     {
-      printf ("I'm the child!\n");
+      const char *s = "I'm the child!";
+#if DEBUG
+      printf ("%s\n", s);
+#else
+    const char *volatile v = s;
+#endif
       _exit (0);
     }
   else
     {
-      printf ("I'm the proud parent of child #%d!\n", pid);
+      const char *s = "I'm the proud parent of child";
+#if DEBUG
+      printf ("%s #%d!\n", s, pid);
+#else
+    const char *volatile v = s;
+#endif
     }
 
   return 0;
diff --git a/gdb/testsuite/gdb.base/foll-vfork.c b/gdb/testsuite/gdb.base/foll-vfork.c
index 2f6661d1a0b..b7e332e146b 100644
--- a/gdb/testsuite/gdb.base/foll-vfork.c
+++ b/gdb/testsuite/gdb.base/foll-vfork.c
@@ -40,12 +40,19 @@ main (int argc, char ** argv)
     memcpy (prog + len - 10, "vforked-prog", 12);
     prog[len + 2] = 0;
 
+#if DEBUG
     printf ("I'm the child!\n");
+#endif
     execlp (prog, prog, (char *) 0);
     perror ("exec failed");
     _exit (1);
   }
   else {
-    printf ("I'm the proud parent of child #%d!\n", pid);
+    const char *s = "I'm the proud parent of child";
+#if DEBUG
+    printf ("%s #%d!\n", s, pid);
+#else
+    const char *volatile v = s;
+#endif
   }
 }
diff --git a/gdb/testsuite/gdb.base/foll-vfork.exp b/gdb/testsuite/gdb.base/foll-vfork.exp
index a781a5c2087..fc710167f7d 100644
--- a/gdb/testsuite/gdb.base/foll-vfork.exp
+++ b/gdb/testsuite/gdb.base/foll-vfork.exp
@@ -32,9 +32,14 @@ if [gdb_debug_enabled] {
     return 0
 }
 
+# Set DEBUG to 0 or 1 in sources.
+set debug 0
+
 standard_testfile
 
-set compile_options debug
+set compile_options {}
+lappend compile_options debug
+lappend compile_options additional_flags=-DDEBUG=$debug
 
 if {[build_executable $testfile.exp $testfile $srcfile $compile_options] == -1} {
     untested "failed to compile main testcase"
@@ -126,7 +131,7 @@ proc vfork_parent_follow_to_bp {} {
 
    gdb_test_no_output "set follow-fork parent"
 
-   set bp_location [gdb_get_line_number "printf (\"I'm the proud parent of child"]
+   set bp_location [gdb_get_line_number "I'm the proud parent of child"]
    gdb_test "break ${srcfile}:${bp_location}" ".*" "break, vfork to bp"
 
    set test "continue to bp"
@@ -176,7 +181,7 @@ proc vfork_and_exec_child_follow_to_main_bp {} {
 
    gdb_test_no_output "set follow-fork child"
 
-   set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
+   set linenum [gdb_get_line_number "Hello from vforked-prog" ${srcfile2}]
 
    set test "continue to bp"
    gdb_test_multiple "continue" $test {
@@ -278,7 +283,7 @@ proc tcatch_vfork_then_child_follow_exec {} {
    continue_to_vfork
 
    set linenum1 [gdb_get_line_number "pid = vfork ();"]
-   set linenum2 [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
+   set linenum2 [gdb_get_line_number "Hello from vforked-prog" ${srcfile2}]
 
    set test "finish"
    gdb_test_multiple "finish" $test {
@@ -356,7 +361,7 @@ proc vfork_relations_in_info_inferiors { variant } {
    if { $variant == "exec" } {
        global srcfile2
 
-       set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
+       set linenum [gdb_get_line_number "Hello from vforked-prog" ${srcfile2}]
        set test "continue to bp"
        gdb_test_multiple "continue" $test {
 	   -re ".*xecuting new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " {
@@ -487,7 +492,7 @@ set testfile "foll-vfork-exit"
 set srcfile ${testfile}.c
 set binfile [standard_output_file ${testfile}]
 
-if {[build_executable $testfile.exp $testfile $srcfile] == -1} {
+if {[build_executable $testfile.exp $testfile $srcfile $compile_options] == -1} {
     untested "failed to build $testfile"
     return
 }
diff --git a/gdb/testsuite/gdb.base/vforked-prog.c b/gdb/testsuite/gdb.base/vforked-prog.c
index 936c6e6032d..999efa8ce0d 100644
--- a/gdb/testsuite/gdb.base/vforked-prog.c
+++ b/gdb/testsuite/gdb.base/vforked-prog.c
@@ -19,6 +19,11 @@
 
 int main (void)
 {
-  printf("Hello from vforked-prog...\n");
+  const char *s = "Hello from vforked-prog";
+#if DEBUG
+  printf ("%s...\n", s);
+#else
+  const char *volatile v = s;
+#endif
   return 0;
 }

base-commit: e6c46d077240565fac4d70066719a8bbe2c212d1
-- 
2.26.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] [gdb] Don't use gdb_stdlog for inferior-events
  2021-11-15 11:21 [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp Tom de Vries
@ 2021-11-15 11:21 ` Tom de Vries
  2021-11-15 16:42   ` Simon Marchi
  2021-11-15 16:39 ` [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp Simon Marchi
  1 sibling, 1 reply; 7+ messages in thread
From: Tom de Vries @ 2021-11-15 11:21 UTC (permalink / raw)
  To: gdb-patches

The test-case gdb.base/foll-vfork.exp contains:
...
if [gdb_debug_enabled] {
    untested "debug is enabled"
    return 0
}
...

To understand what it does, I disabled this bit and ran with GDB_DEBUG=infrun,
like so:
...
$ cd $build/gdb/testsuite
$ make check GDB_DEBUG=infrun RUNTESTFLAGS=gdb.base/foll-vfork.exp
...
and ran into:
...
(gdb) PASS: gdb.base/foll-vfork.exp: exec: \
  vfork parent follow, through step: set follow-fork parent
next^M
33        if (pid == 0) {^M
(gdb) FAIL: gdb.base/foll-vfork.exp: exec: \
  vfork parent follow, through step: step
...

The problem is that the test-case expects:
...
(gdb) PASS: gdb.base/foll-vfork.exp: exec: \
  vfork parent follow, through step: set follow-fork parent
next^M
[Detaching after vfork from child process 28169]^M
33        if (pid == 0) {^M
(gdb) PASS: gdb.base/foll-vfork.exp: exec: \
  vfork parent follow, through step: step
...
but the "Detaching" line has been redirected to
$outputs/gdb.base/foll-vfork/gdb.debug.

I looked at the documentation of "set logging debugredirect [on|off]":
...
  By default, GDB debug output will go to both the terminal and the logfile.
  Set debugredirect if you want debug output to go only to the log file.
...
and my interpretation of it was that "debug output" did not match the
"messages" description of inferior-events:
...
The set print inferior-events command allows you to enable or disable printing
of messages when GDB notices that new inferiors have started or that inferiors
have exited or have been detached.
...

Fix the discrepancy by not redirecting inferior-events for debugredirect.
[ Alternatively, we could update the documentation to clarify that debug
output also implies inferior-events messsages. ]

Update the gdb.base/foll-vfork.exp test-case to not require
gdb_debug_enabled == 0.

Tested on x86_64-linux.

Tested test-case gdb.base/foll-vfork.exp with and without GDB_DEBUG=infrun.
---
 gdb/infrun.c                          | 33 ++++++++++++---------------
 gdb/testsuite/gdb.base/foll-vfork.exp |  7 ------
 2 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 95c8bfb2e7d..64e535a3477 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -455,10 +455,9 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
 	      ptid_t process_ptid = ptid_t (child_ptid.pid ());
 
 	      target_terminal::ours_for_output ();
-	      fprintf_filtered (gdb_stdlog,
-				_("[Detaching after %s from child %s]\n"),
-				has_vforked ? "vfork" : "fork",
-				target_pid_to_str (process_ptid).c_str ());
+	      printf_filtered (_("[Detaching after %s from child %s]\n"),
+			       has_vforked ? "vfork" : "fork",
+			       target_pid_to_str (process_ptid).c_str ());
 	    }
 	}
       else
@@ -522,11 +521,10 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
 	  std::string child_pid = target_pid_to_str (child_ptid);
 
 	  target_terminal::ours_for_output ();
-	  fprintf_filtered (gdb_stdlog,
-			    _("[Attaching after %s %s to child %s]\n"),
-			    parent_pid.c_str (),
-			    has_vforked ? "vfork" : "fork",
-			    child_pid.c_str ());
+	  printf_filtered (_("[Attaching after %s %s to child %s]\n"),
+			   parent_pid.c_str (),
+			   has_vforked ? "vfork" : "fork",
+			   child_pid.c_str ());
 	}
 
       /* Add the new inferior first, so that the target_detach below
@@ -634,10 +632,9 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
 	      ptid_t process_ptid = ptid_t (parent_ptid.pid ());
 
 	      target_terminal::ours_for_output ();
-	      fprintf_filtered (gdb_stdlog,
-				_("[Detaching after fork from "
-				  "parent %s]\n"),
-				target_pid_to_str (process_ptid).c_str ());
+	      printf_filtered (_("[Detaching after fork from "
+				 "parent %s]\n"),
+			       target_pid_to_str (process_ptid).c_str ());
 	    }
 
 	  target_detach (parent_inf, 0);
@@ -957,15 +954,13 @@ handle_vfork_child_exec_or_exit (int exec)
 
 	      if (exec)
 		{
-		  fprintf_filtered (gdb_stdlog,
-				    _("[Detaching vfork parent %s "
-				      "after child exec]\n"), pidstr.c_str ());
+		  printf_filtered (_("[Detaching vfork parent %s "
+				     "after child exec]\n"), pidstr.c_str ());
 		}
 	      else
 		{
-		  fprintf_filtered (gdb_stdlog,
-				    _("[Detaching vfork parent %s "
-				      "after child exit]\n"), pidstr.c_str ());
+		  printf_filtered (_("[Detaching vfork parent %s "
+				     "after child exit]\n"), pidstr.c_str ());
 		}
 	    }
 
diff --git a/gdb/testsuite/gdb.base/foll-vfork.exp b/gdb/testsuite/gdb.base/foll-vfork.exp
index fc710167f7d..8904a344411 100644
--- a/gdb/testsuite/gdb.base/foll-vfork.exp
+++ b/gdb/testsuite/gdb.base/foll-vfork.exp
@@ -25,13 +25,6 @@ if {![istarget "*-linux*"]} then {
     continue
 }
 
-# Test relies on checking follow-fork output. Do not run if gdb debug is
-# enabled as it will be redirected to the log.
-if [gdb_debug_enabled] {
-    untested "debug is enabled"
-    return 0
-}
-
 # Set DEBUG to 0 or 1 in sources.
 set debug 0
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp
  2021-11-15 11:21 [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp Tom de Vries
  2021-11-15 11:21 ` [PATCH 2/2] [gdb] Don't use gdb_stdlog for inferior-events Tom de Vries
@ 2021-11-15 16:39 ` Simon Marchi
  2021-11-15 22:11   ` Tom de Vries
  1 sibling, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2021-11-15 16:39 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 2021-11-15 6:21 a.m., Tom de Vries via Gdb-patches wrote:
> Test-case gdb.base/foll-vfork.exp has inferior output that is not needed, but
> which makes the regexp matching more difficult (see commit 1f28b70def1
> "[gdb/testsuite] Fix regexp in gdb.base/foll-vfork.exp").
>
> Disable the inferior output using '#if DEBUG'.
>
> Tested on x86_64-linux.
> ---
>  gdb/testsuite/gdb.base/foll-vfork-exit.c | 14 ++++++++++++--
>  gdb/testsuite/gdb.base/foll-vfork.c      |  9 ++++++++-
>  gdb/testsuite/gdb.base/foll-vfork.exp    | 17 +++++++++++------
>  gdb/testsuite/gdb.base/vforked-prog.c    |  7 ++++++-
>  4 files changed, 37 insertions(+), 10 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.base/foll-vfork-exit.c b/gdb/testsuite/gdb.base/foll-vfork-exit.c
> index 6c263cdc057..15e272afe82 100644
> --- a/gdb/testsuite/gdb.base/foll-vfork-exit.c
> +++ b/gdb/testsuite/gdb.base/foll-vfork-exit.c
> @@ -29,12 +29,22 @@ main ()
>    pid = vfork (); /* VFORK */
>    if (pid == 0)
>      {
> -      printf ("I'm the child!\n");
> +      const char *s = "I'm the child!";
> +#if DEBUG
> +      printf ("%s\n", s);
> +#else
> +    const char *volatile v = s;
> +#endif

In my original comment, I meant that we could have simply deleted the
printfs, instead of deleting the regexp $ anchor, as done in
1f28b70def1.  I don't think these printfs provide any value to debug the
test case at all.

Since 1f28b70def1 is already merged, the printfs can just stay as-is
(since the regexp accepts them).  Or we can remove them and put back the
anchor.  I slightly prefer the latter, because it makes the test case
check slightly more restrictive (if there is some spurious output after
the prompt, the test will fail).  But it won't make a big difference in
the grand scheme of things.

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] [gdb] Don't use gdb_stdlog for inferior-events
  2021-11-15 11:21 ` [PATCH 2/2] [gdb] Don't use gdb_stdlog for inferior-events Tom de Vries
@ 2021-11-15 16:42   ` Simon Marchi
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2021-11-15 16:42 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 2021-11-15 6:21 a.m., Tom de Vries via Gdb-patches wrote:
> The test-case gdb.base/foll-vfork.exp contains:
> ...
> if [gdb_debug_enabled] {
>     untested "debug is enabled"
>     return 0
> }
> ...
>
> To understand what it does, I disabled this bit and ran with GDB_DEBUG=infrun,
> like so:
> ...
> $ cd $build/gdb/testsuite
> $ make check GDB_DEBUG=infrun RUNTESTFLAGS=gdb.base/foll-vfork.exp

Interesting, I didn't know about that.

> ...
> and ran into:
> ...
> (gdb) PASS: gdb.base/foll-vfork.exp: exec: \
>   vfork parent follow, through step: set follow-fork parent
> next^M
> 33        if (pid == 0) {^M
> (gdb) FAIL: gdb.base/foll-vfork.exp: exec: \
>   vfork parent follow, through step: step
> ...
>
> The problem is that the test-case expects:
> ...
> (gdb) PASS: gdb.base/foll-vfork.exp: exec: \
>   vfork parent follow, through step: set follow-fork parent
> next^M
> [Detaching after vfork from child process 28169]^M
> 33        if (pid == 0) {^M
> (gdb) PASS: gdb.base/foll-vfork.exp: exec: \
>   vfork parent follow, through step: step
> ...
> but the "Detaching" line has been redirected to
> $outputs/gdb.base/foll-vfork/gdb.debug.
>
> I looked at the documentation of "set logging debugredirect [on|off]":
> ...
>   By default, GDB debug output will go to both the terminal and the logfile.
>   Set debugredirect if you want debug output to go only to the log file.
> ...
> and my interpretation of it was that "debug output" did not match the
> "messages" description of inferior-events:
> ...
> The set print inferior-events command allows you to enable or disable printing
> of messages when GDB notices that new inferiors have started or that inferiors
> have exited or have been detached.
> ...
>
> Fix the discrepancy by not redirecting inferior-events for debugredirect.
> [ Alternatively, we could update the documentation to clarify that debug
> output also implies inferior-events messsages. ]
>
> Update the gdb.base/foll-vfork.exp test-case to not require
> gdb_debug_enabled == 0.
>
> Tested on x86_64-linux.
>
> Tested test-case gdb.base/foll-vfork.exp with and without GDB_DEBUG=infrun.

I think the patch is doing the right thing, LGTM.

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp
  2021-11-15 16:39 ` [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp Simon Marchi
@ 2021-11-15 22:11   ` Tom de Vries
  2021-11-16 15:01     ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Tom de Vries @ 2021-11-15 22:11 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1915 bytes --]

On 11/15/21 5:39 PM, Simon Marchi wrote:
> On 2021-11-15 6:21 a.m., Tom de Vries via Gdb-patches wrote:
>> Test-case gdb.base/foll-vfork.exp has inferior output that is not needed, but
>> which makes the regexp matching more difficult (see commit 1f28b70def1
>> "[gdb/testsuite] Fix regexp in gdb.base/foll-vfork.exp").
>>
>> Disable the inferior output using '#if DEBUG'.
>>
>> Tested on x86_64-linux.
>> ---
>>  gdb/testsuite/gdb.base/foll-vfork-exit.c | 14 ++++++++++++--
>>  gdb/testsuite/gdb.base/foll-vfork.c      |  9 ++++++++-
>>  gdb/testsuite/gdb.base/foll-vfork.exp    | 17 +++++++++++------
>>  gdb/testsuite/gdb.base/vforked-prog.c    |  7 ++++++-
>>  4 files changed, 37 insertions(+), 10 deletions(-)
>>
>> diff --git a/gdb/testsuite/gdb.base/foll-vfork-exit.c b/gdb/testsuite/gdb.base/foll-vfork-exit.c
>> index 6c263cdc057..15e272afe82 100644
>> --- a/gdb/testsuite/gdb.base/foll-vfork-exit.c
>> +++ b/gdb/testsuite/gdb.base/foll-vfork-exit.c
>> @@ -29,12 +29,22 @@ main ()
>>    pid = vfork (); /* VFORK */
>>    if (pid == 0)
>>      {
>> -      printf ("I'm the child!\n");
>> +      const char *s = "I'm the child!";
>> +#if DEBUG
>> +      printf ("%s\n", s);
>> +#else
>> +    const char *volatile v = s;
>> +#endif
> 
> In my original comment, I meant that we could have simply deleted the
> printfs, instead of deleting the regexp $ anchor, as done in
> 1f28b70def1.  I don't think these printfs provide any value to debug the
> test case at all.
> 
> Since 1f28b70def1 is already merged, the printfs can just stay as-is
> (since the regexp accepts them).  Or we can remove them and put back the
> anchor.  I slightly prefer the latter, because it makes the test case
> check slightly more restrictive (if there is some spurious output after
> the prompt, the test will fail).  But it won't make a big difference in
> the grand scheme of things.

So, is this what you meant?

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-testsuite-Remove-inferior-output-in-gdb.base-foll-vfork.exp.patch --]
[-- Type: text/x-patch, Size: 4581 bytes --]

[gdb/testsuite] Remove inferior output in gdb.base/foll-vfork.exp

Test-case gdb.base/foll-vfork.exp has inferior output that is not needed, but
which makes the regexp matching more difficult (see commit 1f28b70def1
"[gdb/testsuite] Fix regexp in gdb.base/foll-vfork.exp").

Remove the inferior output, and revert commit 1f28b70def1 to make the matching
more restrictive.

Tested on x86_64-linux.

---
 gdb/testsuite/gdb.base/foll-vfork-exit.c |  4 ++--
 gdb/testsuite/gdb.base/foll-vfork.c      |  3 +--
 gdb/testsuite/gdb.base/foll-vfork.exp    | 14 +++++++-------
 gdb/testsuite/gdb.base/vforked-prog.c    |  2 +-
 4 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/gdb/testsuite/gdb.base/foll-vfork-exit.c b/gdb/testsuite/gdb.base/foll-vfork-exit.c
index 6c263cdc057..a0509d57991 100644
--- a/gdb/testsuite/gdb.base/foll-vfork-exit.c
+++ b/gdb/testsuite/gdb.base/foll-vfork-exit.c
@@ -29,12 +29,12 @@ main ()
   pid = vfork (); /* VFORK */
   if (pid == 0)
     {
-      printf ("I'm the child!\n");
+      const char *volatile s = "I'm the child!";
       _exit (0);
     }
   else
     {
-      printf ("I'm the proud parent of child #%d!\n", pid);
+      const char *volatile s = "I'm the proud parent of child";
     }
 
   return 0;
diff --git a/gdb/testsuite/gdb.base/foll-vfork.c b/gdb/testsuite/gdb.base/foll-vfork.c
index 2f6661d1a0b..2385447dbc4 100644
--- a/gdb/testsuite/gdb.base/foll-vfork.c
+++ b/gdb/testsuite/gdb.base/foll-vfork.c
@@ -40,12 +40,11 @@ main (int argc, char ** argv)
     memcpy (prog + len - 10, "vforked-prog", 12);
     prog[len + 2] = 0;
 
-    printf ("I'm the child!\n");
     execlp (prog, prog, (char *) 0);
     perror ("exec failed");
     _exit (1);
   }
   else {
-    printf ("I'm the proud parent of child #%d!\n", pid);
+    const char *volatile s = "I'm the proud parent of child";
   }
 }
diff --git a/gdb/testsuite/gdb.base/foll-vfork.exp b/gdb/testsuite/gdb.base/foll-vfork.exp
index 5de0795d60a..3a16046d94a 100644
--- a/gdb/testsuite/gdb.base/foll-vfork.exp
+++ b/gdb/testsuite/gdb.base/foll-vfork.exp
@@ -119,7 +119,7 @@ proc vfork_parent_follow_to_bp {} {
 
    gdb_test_no_output "set follow-fork parent"
 
-   set bp_location [gdb_get_line_number "printf (\"I'm the proud parent of child"]
+   set bp_location [gdb_get_line_number "I'm the proud parent of child"]
    gdb_test "break ${srcfile}:${bp_location}" ".*" "break, vfork to bp"
 
    set test "continue to bp"
@@ -169,7 +169,7 @@ proc vfork_and_exec_child_follow_to_main_bp {} {
 
    gdb_test_no_output "set follow-fork child"
 
-   set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
+   set linenum [gdb_get_line_number "Hello from vforked-prog" ${srcfile2}]
 
    set test "continue to bp"
    gdb_test_multiple "continue" $test {
@@ -271,7 +271,7 @@ proc tcatch_vfork_then_child_follow_exec {} {
    continue_to_vfork
 
    set linenum1 [gdb_get_line_number "pid = vfork ();"]
-   set linenum2 [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
+   set linenum2 [gdb_get_line_number "Hello from vforked-prog" ${srcfile2}]
 
    set test "finish"
    gdb_test_multiple "finish" $test {
@@ -349,7 +349,7 @@ proc vfork_relations_in_info_inferiors { variant } {
    if { $variant == "exec" } {
        global srcfile2
 
-       set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
+       set linenum [gdb_get_line_number "Hello from vforked-prog" ${srcfile2}]
        set test "continue to bp"
        gdb_test_multiple "continue" $test {
 	   -re ".*xecuting new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " {
@@ -367,13 +367,13 @@ proc vfork_relations_in_info_inferiors { variant } {
 
    set test "vfork relation no longer appears in info inferiors"
    gdb_test_multiple "info inferiors" $test {
-       -re "is vfork child of inferior 1.*$gdb_prompt " {
+       -re "is vfork child of inferior 1.*$gdb_prompt $" {
 	   fail $test
        }
-       -re "is vfork parent of inferior 2.*$gdb_prompt " {
+       -re "is vfork parent of inferior 2.*$gdb_prompt $" {
 	   fail $test
        }
-       -re "$gdb_prompt " {
+       -re "$gdb_prompt $" {
 	   pass $test
        }
    }
diff --git a/gdb/testsuite/gdb.base/vforked-prog.c b/gdb/testsuite/gdb.base/vforked-prog.c
index 936c6e6032d..6542f1d8583 100644
--- a/gdb/testsuite/gdb.base/vforked-prog.c
+++ b/gdb/testsuite/gdb.base/vforked-prog.c
@@ -19,6 +19,6 @@
 
 int main (void)
 {
-  printf("Hello from vforked-prog...\n");
+  const char *volatile s = "Hello from vforked-prog";
   return 0;
 }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp
  2021-11-15 22:11   ` Tom de Vries
@ 2021-11-16 15:01     ` Simon Marchi
  2021-11-16 15:46       ` Tom de Vries
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2021-11-16 15:01 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 2021-11-15 5:11 p.m., Tom de Vries via Gdb-patches wrote:
> On 11/15/21 5:39 PM, Simon Marchi wrote:
>> On 2021-11-15 6:21 a.m., Tom de Vries via Gdb-patches wrote:
>>> Test-case gdb.base/foll-vfork.exp has inferior output that is not needed, but
>>> which makes the regexp matching more difficult (see commit 1f28b70def1
>>> "[gdb/testsuite] Fix regexp in gdb.base/foll-vfork.exp").
>>>
>>> Disable the inferior output using '#if DEBUG'.
>>>
>>> Tested on x86_64-linux.
>>> ---
>>>  gdb/testsuite/gdb.base/foll-vfork-exit.c | 14 ++++++++++++--
>>>  gdb/testsuite/gdb.base/foll-vfork.c      |  9 ++++++++-
>>>  gdb/testsuite/gdb.base/foll-vfork.exp    | 17 +++++++++++------
>>>  gdb/testsuite/gdb.base/vforked-prog.c    |  7 ++++++-
>>>  4 files changed, 37 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/gdb/testsuite/gdb.base/foll-vfork-exit.c b/gdb/testsuite/gdb.base/foll-vfork-exit.c
>>> index 6c263cdc057..15e272afe82 100644
>>> --- a/gdb/testsuite/gdb.base/foll-vfork-exit.c
>>> +++ b/gdb/testsuite/gdb.base/foll-vfork-exit.c
>>> @@ -29,12 +29,22 @@ main ()
>>>    pid = vfork (); /* VFORK */
>>>    if (pid == 0)
>>>      {
>>> -      printf ("I'm the child!\n");
>>> +      const char *s = "I'm the child!";
>>> +#if DEBUG
>>> +      printf ("%s\n", s);
>>> +#else
>>> +    const char *volatile v = s;
>>> +#endif
>>
>> In my original comment, I meant that we could have simply deleted the
>> printfs, instead of deleting the regexp $ anchor, as done in
>> 1f28b70def1.  I don't think these printfs provide any value to debug the
>> test case at all.
>>
>> Since 1f28b70def1 is already merged, the printfs can just stay as-is
>> (since the regexp accepts them).  Or we can remove them and put back the
>> anchor.  I slightly prefer the latter, because it makes the test case
>> check slightly more restrictive (if there is some spurious output after
>> the prompt, the test will fail).  But it won't make a big difference in
>> the grand scheme of things.
>
> So, is this what you meant?

Yeah, pretty much.  Could the -re entries use -wrap?

You still assign the strings to volatile variables to make the
gdb_get_line_number calls work, I suppose?

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp
  2021-11-16 15:01     ` Simon Marchi
@ 2021-11-16 15:46       ` Tom de Vries
  0 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2021-11-16 15:46 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 11/16/21 4:01 PM, Simon Marchi wrote:
> On 2021-11-15 5:11 p.m., Tom de Vries via Gdb-patches wrote:
>> On 11/15/21 5:39 PM, Simon Marchi wrote:
>>> On 2021-11-15 6:21 a.m., Tom de Vries via Gdb-patches wrote:
>>>> Test-case gdb.base/foll-vfork.exp has inferior output that is not needed, but
>>>> which makes the regexp matching more difficult (see commit 1f28b70def1
>>>> "[gdb/testsuite] Fix regexp in gdb.base/foll-vfork.exp").
>>>>
>>>> Disable the inferior output using '#if DEBUG'.
>>>>
>>>> Tested on x86_64-linux.
>>>> ---
>>>>  gdb/testsuite/gdb.base/foll-vfork-exit.c | 14 ++++++++++++--
>>>>  gdb/testsuite/gdb.base/foll-vfork.c      |  9 ++++++++-
>>>>  gdb/testsuite/gdb.base/foll-vfork.exp    | 17 +++++++++++------
>>>>  gdb/testsuite/gdb.base/vforked-prog.c    |  7 ++++++-
>>>>  4 files changed, 37 insertions(+), 10 deletions(-)
>>>>
>>>> diff --git a/gdb/testsuite/gdb.base/foll-vfork-exit.c b/gdb/testsuite/gdb.base/foll-vfork-exit.c
>>>> index 6c263cdc057..15e272afe82 100644
>>>> --- a/gdb/testsuite/gdb.base/foll-vfork-exit.c
>>>> +++ b/gdb/testsuite/gdb.base/foll-vfork-exit.c
>>>> @@ -29,12 +29,22 @@ main ()
>>>>    pid = vfork (); /* VFORK */
>>>>    if (pid == 0)
>>>>      {
>>>> -      printf ("I'm the child!\n");
>>>> +      const char *s = "I'm the child!";
>>>> +#if DEBUG
>>>> +      printf ("%s\n", s);
>>>> +#else
>>>> +    const char *volatile v = s;
>>>> +#endif
>>>
>>> In my original comment, I meant that we could have simply deleted the
>>> printfs, instead of deleting the regexp $ anchor, as done in
>>> 1f28b70def1.  I don't think these printfs provide any value to debug the
>>> test case at all.
>>>
>>> Since 1f28b70def1 is already merged, the printfs can just stay as-is
>>> (since the regexp accepts them).  Or we can remove them and put back the
>>> anchor.  I slightly prefer the latter, because it makes the test case
>>> check slightly more restrictive (if there is some spurious output after
>>> the prompt, the test will fail).  But it won't make a big difference in
>>> the grand scheme of things.
>>
>> So, is this what you meant?
> 
> Yeah, pretty much.  Could the -re entries use -wrap?
> 

Sure.

> You still assign the strings to volatile variables to make the
> gdb_get_line_number calls work, I suppose?
> 

Indeed.

I'll commit this variant, updated to use -wrap.

Thanks,
- Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-11-16 15:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 11:21 [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp Tom de Vries
2021-11-15 11:21 ` [PATCH 2/2] [gdb] Don't use gdb_stdlog for inferior-events Tom de Vries
2021-11-15 16:42   ` Simon Marchi
2021-11-15 16:39 ` [PATCH 1/2] [gdb/testsuite] Disable inferior output in gdb.base/foll-vfork.exp Simon Marchi
2021-11-15 22:11   ` Tom de Vries
2021-11-16 15:01     ` Simon Marchi
2021-11-16 15:46       ` Tom de Vries

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).