public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Natalia Saiapova <natalia.saiapova@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 6/6] gdb/testsuite: add tests for inferior calls in breakpoint conditions.
Date: Fri,  9 Oct 2020 13:27:18 +0200	[thread overview]
Message-ID: <20201009112719.629-7-natalia.saiapova@intel.com> (raw)
In-Reply-To: <20201009112719.629-1-natalia.saiapova@intel.com>

Test three scenarios for breakpoints whose condition includes a function
call:
* only one thread matches the condition;
* both threads match the condition;
* no thread matches the condition.

gdb/testsuite/ChangeLog:
2020-08-26  Natalia Saiapova  <natalia.saiapova@intel.com>

	* gdb.threads/infcall-bp-cond.c: New test.
	* gdb.threads/infcall-bp-cond.exp: New file.

Signed-off-by: Natalia Saiapova <natalia.saiapova@intel.com>
---
 gdb/testsuite/gdb.threads/infcall-bp-cond.c   | 58 +++++++++++++++
 gdb/testsuite/gdb.threads/infcall-bp-cond.exp | 73 +++++++++++++++++++
 2 files changed, 131 insertions(+)
 create mode 100644 gdb/testsuite/gdb.threads/infcall-bp-cond.c
 create mode 100644 gdb/testsuite/gdb.threads/infcall-bp-cond.exp

diff --git a/gdb/testsuite/gdb.threads/infcall-bp-cond.c b/gdb/testsuite/gdb.threads/infcall-bp-cond.c
new file mode 100644
index 00000000000..dda2d3bb0e0
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/infcall-bp-cond.c
@@ -0,0 +1,58 @@
+/* Copyright 2020 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <pthread.h>
+
+#define NUM_THREADS 2
+
+int
+is_one (int tid)
+{
+  return tid == 1;
+}
+
+int
+return_true ()
+{
+  return 1;
+}
+
+int
+return_false ()
+{
+  return 0;
+}
+
+void *
+doSmt (void *arg)
+{
+  int a = 42; /* breakpoint-here  */
+}
+
+int main(int argc, char *argv[])
+{
+  pthread_t threads[NUM_THREADS];
+  int args[NUM_THREADS];
+
+  for (int i = 0; i < NUM_THREADS; i++)
+    {
+      args[i] = i;
+      pthread_create (&threads[i], NULL, doSmt, &args[i]);
+    }
+
+  pthread_exit(NULL);
+}
diff --git a/gdb/testsuite/gdb.threads/infcall-bp-cond.exp b/gdb/testsuite/gdb.threads/infcall-bp-cond.exp
new file mode 100644
index 00000000000..c5abe2646f0
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/infcall-bp-cond.exp
@@ -0,0 +1,73 @@
+# Copyright 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Tests inferior calls executed from a breakpoint condition in
+# a multi-threaded program.
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \
+	  {debug pthreads}] } {
+    return
+}
+
+set bp_line [gdb_get_line_number "breakpoint-here"]
+
+proc run_condition_test {message n_expected_hits condition} {
+    with_test_prefix $message {
+	global binfile gdb_prompt srcfile bp_line
+
+	clean_restart ${binfile}
+
+	if {![runto_main]} {
+	    fail "run to main"
+	    return
+	}
+
+	gdb_test "set \$n_cond_eval = 0"
+	gdb_breakpoint "$srcfile:$bp_line if (++\$n_cond_eval) $condition"
+
+	set n_hit_condition 0
+	set should_continue true
+	set iteration 0
+
+	while {$should_continue} {
+	    incr iteration
+	    with_test_prefix "continue iteration $iteration" {
+		gdb_test_multiple "continue" "continue" {
+		    -re "$srcfile:$bp_line.*$gdb_prompt" {
+			incr n_hit_condition
+		    }
+		    -re "$gdb_prompt" {
+			set should_continue false
+		    }
+		}
+	    }
+	}
+
+	set test_condition "expected number of hits"
+	if {$n_hit_condition == $n_expected_hits} {
+	    pass $test_condition
+	} else {
+	    fail $test_condition
+	}
+
+	gdb_test "print \$n_cond_eval" "= 2" "condition was evaluated twice"
+    }
+}
+
+run_condition_test "exactly one thread is hit" 1 "&& is_one (*(int*)arg)"
+run_condition_test "exactly two threads are hit" 2 "|| return_true ()"
+run_condition_test "no thread is hit" 0 "&& return_false ()"
-- 
2.17.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  parent reply	other threads:[~2020-10-09 11:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200831123519.16232-1-natalia.saiapova () intel ! com>
2020-10-09 11:27 ` [PATCH v2 0/6] Fix inferior calls from breakpoint condition Natalia Saiapova
2020-10-09 11:27   ` [PATCH v2 1/6] gdb: add in_cond_eval field to thread_control_state struct Natalia Saiapova
2021-03-02 10:43     ` Andrew Burgess
2020-10-09 11:27   ` [PATCH v2 2/6] gdb/infrun: in condition evaluation resume only current thread Natalia Saiapova
2021-03-02 11:15     ` Andrew Burgess
2020-10-09 11:27   ` [PATCH v2 3/6] gdb/infcall: in condition evaluation register target back after infcall Natalia Saiapova
2020-10-19  0:53     ` Kevin Buettner
2021-03-02 11:26     ` Andrew Burgess
2020-10-09 11:27   ` [PATCH v2 4/6] gdb/infrun: in condition evaluation wait only for the current inferior Natalia Saiapova
2020-10-19  1:44     ` Kevin Buettner
2020-10-26 12:11       ` Saiapova, Natalia
2021-03-02 12:17         ` Andrew Burgess
2020-10-09 11:27   ` [PATCH v2 5/6] gdb/infrun: in condition evaluation do not stop all threads Natalia Saiapova
2020-10-09 11:27   ` Natalia Saiapova [this message]
2020-10-12  0:49   ` [PATCH v2 0/6] Fix inferior calls from breakpoint condition Kevin Buettner

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=20201009112719.629-7-natalia.saiapova@intel.com \
    --to=natalia.saiapova@intel.com \
    --cc=gdb-patches@sourceware.org \
    /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).