public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Ari Hannula <ari.hannula@intel.com>
To: gdb-patches@sourceware.org
Cc: "ravitheja.addepally" <ravitheja.addepally@intel.com>,
	Ari Hannula <ari.hannula@intel.com>
Subject: [PATCH 2/5] [func_call] New tests for a btrace crash.
Date: Thu, 10 Feb 2022 14:52:40 +0100	[thread overview]
Message-ID: <20220210135243.3127629-3-ari.hannula@intel.com> (raw)
In-Reply-To: <20220210135243.3127629-1-ari.hannula@intel.com>

From: "ravitheja.addepally" <ravitheja.addepally@intel.com>

During remote debugging when stoppin in the start-routine of a pthread,
GDB crashes when attempting to display function-call-history.

gdb/testsuite/ChangeLog:
2015-04-27  ravitheja.addepally  <ravitheja.addepally@intel.com>

	* gdb.btrace/server-multithreaded-function-call-history.c: New file.
	* gdb.btrace/server-multithreaded-function-call-history.exp: New file.

Signed-off-by: ravitheja.addepally <ravitheja.addepally@intel.com>
Signed-off-by: Ari Hannula <ari.hannula@intel.com>
---
 ...rver-multithreaded-function-call-history.c | 70 +++++++++++++++++++
 ...er-multithreaded-function-call-history.exp | 61 ++++++++++++++++
 2 files changed, 131 insertions(+)
 create mode 100644 gdb/testsuite/gdb.btrace/server-multithreaded-function-call-history.c
 create mode 100644 gdb/testsuite/gdb.btrace/server-multithreaded-function-call-history.exp

diff --git a/gdb/testsuite/gdb.btrace/server-multithreaded-function-call-history.c b/gdb/testsuite/gdb.btrace/server-multithreaded-function-call-history.c
new file mode 100644
index 0000000000..4dbe4c1fe8
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/server-multithreaded-function-call-history.c
@@ -0,0 +1,70 @@
+/* Manythreads test program.
+   Copyright 2004-2022 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/>.
+
+   Copied from gdb.threads/manythreads.c  */
+
+#include <pthread.h>
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+#include <limits.h>
+
+void *
+thread_function (void *arg)
+{
+  int x = * (int *) arg;
+
+#ifdef DEBUG
+  printf ("Thread <%d> executing\n", x);
+#endif /* DEBUG */
+
+  return NULL;
+}
+
+int 
+main (int argc, char **argv)
+{
+  pthread_attr_t attr;
+  pthread_t threads[256];
+  int args[256];
+  int i, j;
+
+  pthread_attr_init (&attr);
+
+#ifdef PTHREAD_STACK_MIN
+  pthread_attr_setstacksize (&attr, 2*PTHREAD_STACK_MIN);
+#endif
+
+  /* Create a ton of quick-executing threads, then wait for them to
+     complete.  */
+  for (i = 0; i < 1000; ++i) 
+    {
+      for (j = 0; j < 256; ++j)
+	{
+	  args[j] = i * 1000 + j;
+	  pthread_create (&threads[j], &attr, thread_function, &args[j]);
+	}
+
+      for (j = 0; j < 256; ++j)
+	  pthread_join (threads[j], NULL);
+    }
+
+  pthread_attr_destroy (&attr);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.btrace/server-multithreaded-function-call-history.exp b/gdb/testsuite/gdb.btrace/server-multithreaded-function-call-history.exp
new file mode 100644
index 0000000000..3af51c4228
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/server-multithreaded-function-call-history.exp
@@ -0,0 +1,61 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2005-2022 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/>.
+
+load_lib gdbserver-support.exp
+
+standard_testfile
+
+if { [skip_gdbserver_tests] } {
+    return 0
+}
+
+if { [skip_btrace_tests] } {
+    return -1
+}
+
+set opts { debug }
+if [info exists DEBUG] {
+    lappend opts "additional_flags=-DDEBUG"
+}
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } {
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_load $binfile
+
+# Make sure we're disconnected, in case we're testing with an
+# extended-remote board, therefore already connected.
+gdb_test "disconnect" ".*"
+
+gdbserver_run ""
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_breakpoint main
+gdb_test "continue" "Breakpoint.* main .*" "continue to main"
+
+gdb_test_no_output "record btrace"
+
+gdb_breakpoint thread_function
+gdb_test "continue" "Breakpoint.* thread_function .*" "continue to thread_function one"
+
+# test passes if this does not crash
+gdb_test "record function-call-history" ".*"
+
+gdb_test "continue" "Breakpoint.* thread_function .*" "continue to thread_function two"
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  parent reply	other threads:[~2022-02-10 13:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10 13:52 [PATCH 0/5] Functions call history patches Ari Hannula
2022-02-10 13:52 ` [PATCH 1/5] [func_call] Add possible spelling of linker error message Ari Hannula
2022-03-17 17:58   ` Metzger, Markus T
2022-03-17 18:45     ` Keith Seitz
2022-02-10 13:52 ` Ari Hannula [this message]
2022-03-17 17:58   ` [PATCH 2/5] [func_call] New tests for a btrace crash Metzger, Markus T
2022-02-10 13:52 ` [PATCH 3/5] [func_call] Fix MI output for function call history Ari Hannula
2022-03-17 17:58   ` Metzger, Markus T
2022-02-10 13:52 ` [PATCH 4/5] [func_call] Add function-call-history-length command to MI Ari Hannula
2022-03-17 17:59   ` Metzger, Markus T
2022-02-10 13:52 ` [PATCH 5/5] [func_call] Add function-call-history " Ari Hannula

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=20220210135243.3127629-3-ari.hannula@intel.com \
    --to=ari.hannula@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=ravitheja.addepally@intel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).