public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/testsuite: fix intermittent failure in gdb.mi/mi-cmd-user-context.exp
@ 2022-04-03 19:06 Simon Marchi
  2022-04-04  9:03 ` Andrew Burgess
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Marchi @ 2022-04-03 19:06 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany, Simon Marchi

I got failures like this once on a CI:

    frame^M
    &"frame\n"^M
    ~"#0  child_sub_function () at /home/jenkins/workspace/binutils-gdb_master_build/arch/amd64/target_board/unix/src/binutils-gdb/gdb/testsuite/gdb.mi/user-selected-context-sync.c:33\n"^M
    ~"33\t    dummy = !dummy; /* thread loop line */\n"^M
    ^done^M
    (gdb) ^M
    FAIL: gdb.mi/mi-cmd-user-context.exp: frame 1 (unexpected output)

The problem is that the test expects the following regexp:

  ".*#0  0x.*"

And that typically works, when the output of the frame command looks
like:

  #0  0x00005555555551bb in child_sub_function () at ...

My theory is the following.  Whether or not the hexadecimal address is
printed (roughly) depends on whether the current PC is at the beginning
of a line.  So depending on where thread 2 was when GDB stopped it
(after thread 1 hit its breakpoint), we can get either output.

Strangely, I couldn't reproduce the failure by running the test in a
loop for a while.  Given that the loop in child_sub_function compiles to
just 6 instructions here, it should happen relatively often that GDB
ptrace stops the thread when it's on one of the instructions that
wouldn't print the hex.  That remains a mystery.

I'm still confident enough that this is the reason, so adjust the
regexps to not expect an hexadecimal prefix (0x) but a function name
instead (either child_sub_function or child_function).  That one is
always printed, and is also a good check that we are in the frame we
expect.

Note that for test "frame 5", we are showing a pthread frame (on my
system), so the function name is internal to pthread, not something we
can rely on.  In that case, it's almost certain that we are not at the
beginning of a line, or that we don't have debug info, so I think it's
fine to expect the hex prefix.

And for test "frame 6", it's ok to _not_ expect a hex prefix (what the
test currently does), since we are showing thread 1, which has hit a
breakpoint placed at the beginning of a line.

Change-Id: I919673bbf9927158beb0e8b7e9e980b8d65eca90
---
 gdb/testsuite/gdb.mi/mi-cmd-user-context.exp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/gdb.mi/mi-cmd-user-context.exp b/gdb/testsuite/gdb.mi/mi-cmd-user-context.exp
index d7417d5ea7c..592e7b600da 100644
--- a/gdb/testsuite/gdb.mi/mi-cmd-user-context.exp
+++ b/gdb/testsuite/gdb.mi/mi-cmd-user-context.exp
@@ -79,7 +79,7 @@ mi_gdb_test "thread" \
 
 # Check we're in frame 0.
 mi_gdb_test "frame" \
-    ".*#0  0x.*" \
+    ".*#0  .*child_sub_function .*" \
     "frame 1"
 
 # Ask about a different frame in the current thread, the current frame
@@ -93,7 +93,7 @@ mi_gdb_test "thread" \
     "info thread 6"
 
 mi_gdb_test "frame" \
-    ".*#0  0x.*" \
+    ".*#0  .*child_sub_function.*" \
     "frame 2"
 
 
@@ -108,7 +108,7 @@ mi_gdb_test "thread" \
     "info thread 7"
 
 mi_gdb_test "frame" \
-    ".*#0  0x.*" \
+    ".*#0  .*child_sub_function.*" \
     "frame 3"
 
 # Select a different frame in the current thread.  Despite the use of
@@ -123,7 +123,7 @@ mi_gdb_test "thread" \
     "info thread 8"
 
 mi_gdb_test "frame" \
-    ".*#1  0x.*" \
+    ".*#1  .*child_function.*" \
     "frame 4"
 
 # Similar to the previous test, but this time the --frame option is
-- 
2.35.1


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

end of thread, other threads:[~2022-04-04 16:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 19:06 [PATCH] gdb/testsuite: fix intermittent failure in gdb.mi/mi-cmd-user-context.exp Simon Marchi
2022-04-04  9:03 ` Andrew Burgess
2022-04-04 14:21   ` Tom de Vries
2022-04-04 16:11     ` Simon Marchi

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