public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [vxworks 07/14] "multi-tasks-mode" support.
Date: Sun, 25 Apr 2010 15:56:00 -0000	[thread overview]
Message-ID: <1272210447-13895-8-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1272210447-13895-1-git-send-email-brobecker@adacore.com>

VxWorks systems do not provide a concept of a process, but some users
would really like to be able to debug all the tasks running in their
"program", and only those.  The multi-tasks mode is an answer to that
request, based on the fact that Ada programs maintain a list of known
Ada tasks inside the runtime.  The debugger can access it to compute
the current list of Ada tasks, and from there determine the list of
VxWorks threads running as part of the user's application.

Given the fact that this feature relies on a property of the GNAT runtime,
it only works for Ada applications.

Resuming/stopping the relevant threads is done by calls to specialized
routines in the GNAT runtime.  This was necessary to avoid loads of
race conditions that we kept facing when doing this with WTX requests
to each and every affected thread.  The runtime routines have nice
properties that allow us to avoid the problem entirely.

2010-04-24  Joel Brobecker  <brobecker@adacore.com>

        * remote-wtx-tasks.h, remote-wtx-tasks.c: New files.
---
 gdb/remote-wtx-tasks.c |  201 ++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/remote-wtx-tasks.h |   53 +++++++++++++
 2 files changed, 254 insertions(+), 0 deletions(-)
 create mode 100644 gdb/remote-wtx-tasks.c
 create mode 100644 gdb/remote-wtx-tasks.h

diff --git a/gdb/remote-wtx-tasks.c b/gdb/remote-wtx-tasks.c
new file mode 100644
index 0000000..b69c107
--- /dev/null
+++ b/gdb/remote-wtx-tasks.c
@@ -0,0 +1,201 @@
+/* Ada multi-task functionnalities for VxWorks targets.
+
+   Copyright 2005, 2010 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/>.  */
+
+/* Some symbol names embedded in the inferior when it uses tasks.  */
+
+#include "defs.h"
+#include "remote-wtxapi.h"
+#include "remote-wtx-bp.h"
+#include "remote-wtx-tasks.h"
+#include "gdbcmd.h"
+#include "target.h"
+
+#define ADA_STOP_ALL_TASKS ("system__tasking__debug__stop_all_tasks")
+#define ADA_STOP_ALL_TASKS_HANDLER ("system__tasking__debug__stop_all_tasks_handler")
+#define ADA_CONTINUE_ALL_TASKS  ("system__tasking__debug__continue_all_tasks")
+
+/* Breakpoint scope/action operations for the Ada multitask mode :
+   Ada application scope/Ada application action.  */
+
+static int multi_task_mode = 0;
+
+/* The user must not be allowed to change the value of the multitask
+   mode while debugging.  Unfortunately, the set/show mechanism does
+   not allow us to add this type of guard directly.  So what we do is
+   we let the "set multi-tasks-mode" command update the intermediate
+   variable below, and then let a hook called at each update propagate
+   the new value to MULTI_TASK_MODE if allowed, or report an error
+   if not.  */
+static int multi_task_mode_setshow_var = 0;
+
+/* Some variables used to cache the address of functions provided by the
+   inferior to suspend/resume all ada tasks.  */
+
+static CORE_ADDR continue_all_tasks_fun_addr  = 0;
+static CORE_ADDR stop_all_tasks_handler_fun_addr = 0;
+static CORE_ADDR stop_all_tasks_fun_addr = 0;
+
+/* Return non-zero if the user has selected the multi-tasks mode.  */
+
+int
+multi_task_mode_is_on (void)
+{
+  return multi_task_mode;
+}
+
+/* Initialize the breakpoint datas for the multi-tasks mode.  */
+
+void
+open_multi_task_mode (void)
+{
+  set_break_command_action (action_call);
+  set_break_command_call_rtn (stop_all_tasks_handler_fun_addr);
+}
+
+/* Initialize the breakpoint datas for the single-tasks mode.  */
+
+void
+close_multi_task_mode (void)
+{
+  set_break_command_action (action_task);
+  set_break_command_call_rtn (0);
+}
+
+/* Hook called after the "set multi-tasks-mode" command has been
+   executed.  This function verifies that the debugger is not already
+   debugging a process, or else cancels the user request with an
+   error message.  Otherwise, the request is processed by setting
+   MULTI_TASK_MODE to the new value.  */
+
+static void
+set_multi_tasks_mode_cmd (char *args, int from_tty,
+                          struct cmd_list_element *c)
+{
+  /* If we are already debugging a process, reset MULTI_TASK_MODE_SETSHOW_VAR
+     and report an error.  */
+  if (target_has_execution)
+    {
+      multi_task_mode_setshow_var = multi_task_mode;
+      error (_("\
+The multi-tasks mode cannot be changed while debugging a process"));
+    }
+
+  multi_task_mode = multi_task_mode_setshow_var;
+}
+
+void
+_initialize_remote_wtx_tasks (void)
+{
+  add_setshow_boolean_cmd ("multi-tasks-mode", no_class,
+                           &multi_task_mode_setshow_var,"\
+Set whether gdb is debugging the whole Ada kernel application on VxWorks.", "\
+Show whether gdb is debugging the whole Ada kernel application on VxWorks.", "\
+If set, on VxWorks, gdb debugs the whole Ada kernel application.",
+			   set_multi_tasks_mode_cmd, NULL,
+			   &setlist, &showlist);
+}
+
+/* Set the multi-tasks mode user setting to off (zero).  */
+
+void
+turn_multi_task_mode_off (void)
+{
+  multi_task_mode = 0;
+  multi_task_mode_setshow_var = 0;
+}
+
+/* Close the multi-tasking support.  */
+
+void
+stop_multi_task_mode (void)
+{
+  stop_all_tasks_fun_addr = 0;
+  continue_all_tasks_fun_addr = 0;
+  stop_all_tasks_handler_fun_addr = 0;
+
+  set_break_command_action (action_task);
+  set_break_command_call_rtn (0);
+}
+
+/* Set up the multi-tasks mode.
+
+   Automatically deactivate the multi-tasks mode if the inferior
+   is found to not use Ada tasks.  */
+
+void
+start_multi_task_mode (void)
+{
+  set_break_command_action (action_call);
+
+  remote_wtxapi_get_symbol_address (ADA_STOP_ALL_TASKS,
+                                    &stop_all_tasks_fun_addr);
+  remote_wtxapi_get_symbol_address (ADA_CONTINUE_ALL_TASKS,
+                                    &continue_all_tasks_fun_addr);
+
+  if (stop_all_tasks_fun_addr == 0 || continue_all_tasks_fun_addr == 0)
+    {
+      warning (_("Your application does not use Ada tasking.\n\
+multi-tasks-mode turned off."));
+      turn_multi_task_mode_off ();
+      stop_multi_task_mode ();
+      return;
+    }
+
+  /* Search for ADA_STOP_ALL_TASKS_HANDLER and install it if we can
+     find it.  */
+  remote_wtxapi_get_symbol_address (ADA_STOP_ALL_TASKS_HANDLER,
+        			    &stop_all_tasks_handler_fun_addr);
+  if (stop_all_tasks_handler_fun_addr != 0)
+    set_break_command_call_rtn (stop_all_tasks_handler_fun_addr);
+}
+
+/* Resume all Ada tasks in our inferior.  */
+
+int
+continue_all_ada_tasks ()
+{
+  long *ignored_retval;
+
+  if (continue_all_tasks_fun_addr != 0)
+    return wtxapi_direct_call (continue_all_tasks_fun_addr, &ignored_retval,
+                               0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+  
+  return 0;
+}
+
+/* Stop all Ada tasks in our inferior.  After this operation, the Ada tasks
+   can be either suspended, and stopped, depending of the vxWorks version;
+   this information is returned in STATUS.  */
+
+int
+stop_all_ada_tasks (enum wtx_task_status *status)
+{
+  long *ignored_retval;
+
+  if (stop_all_tasks_fun_addr != 0)
+    {
+      *status = WTX_TASK_STATUS_STOPPED;
+      return wtxapi_direct_call (stop_all_tasks_fun_addr, &ignored_retval,
+                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+    }
+
+  *status = WTX_TASK_STATUS_RUNNING;
+  return 0;
+}
+
diff --git a/gdb/remote-wtx-tasks.h b/gdb/remote-wtx-tasks.h
new file mode 100644
index 0000000..d7b6129
--- /dev/null
+++ b/gdb/remote-wtx-tasks.h
@@ -0,0 +1,53 @@
+/* Ada multi-task functionnalities for VxWorks targets.
+
+   Copyright 2005, 2010 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/>.  */
+
+/*  FIXME: brobecke/2007-10-19: We're introducing a new API which should
+    be simpler to use.
+
+    In order to avoid colliding with the deprecated interface, we will
+    temporarily break the naming scheme and not prepend our function
+    names with "wtx_tasks_" for now.  The plan is to rename all the
+    deprecated routines using the "deprecated_" prefix, followed by
+    renaming these new functions.  To be done later.  */
+
+/* Task status; used to know which routine to use when resuming the
+   inferior.  Note that STOPPED and SUSPENDED are actually the same
+   status on VxWorks 5.  */
+
+enum wtx_task_status
+  {
+    WTX_TASK_STATUS_CREATED,
+    WTX_TASK_STATUS_RUNNING,
+    WTX_TASK_STATUS_STOPPED,
+    WTX_TASK_STATUS_SUSPENDED,
+    WTX_TASK_STATUS_UNKNOWN
+  };
+
+int multi_task_mode_is_on (void);
+
+void turn_multi_task_mode_off (void);
+
+void start_multi_task_mode (void);
+
+void stop_multi_task_mode (void);
+
+int continue_all_ada_tasks (void);
+
+int stop_all_ada_tasks (enum wtx_task_status *status);
+
-- 
1.6.3.3

  parent reply	other threads:[~2010-04-25 15:56 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-25 15:47 Adding support for VxWorks target Joel Brobecker
2010-04-25 15:47 ` [vxworks 01/14] Some ada-lang/ada-tasks routines needed by the " Joel Brobecker
2010-04-25 15:48 ` [vxworks 10/14] Add new "wtx" target Joel Brobecker
2010-04-25 15:48 ` [vxworks 03/14] New module remote-wtx-utils Joel Brobecker
2010-04-26 18:55   ` Tom Tromey
2010-04-27 16:27     ` Joel Brobecker
2010-04-25 15:48 ` [vxworks 14/14] Configury and Makefile updates for VxWorks Joel Brobecker
2010-04-25 15:48 ` [vxworks 02/14] New command_post observer Joel Brobecker
2010-04-26 18:51   ` Tom Tromey
2010-04-27 14:22     ` Joel Brobecker
2010-04-27 17:16       ` Tom Tromey
2010-04-25 15:48 ` [vxworks 13/14] Add tdep files for x86 and powerpc Joel Brobecker
2010-04-25 20:45   ` Mark Kettenis
2010-04-26 16:41     ` Joel Brobecker
2010-04-25 15:48 ` [vxworks 11/14] WTX-TCL support module Joel Brobecker
2010-04-25 15:48 ` [vxworks 08/14] Partition support Joel Brobecker
2010-04-25 15:48 ` [vxworks 09/14] remote-wtx-hw / register fetch/store support Joel Brobecker
2010-04-25 15:56 ` [vxworks 06/14] VxWorks breakpoint-handling module Joel Brobecker
2010-04-25 15:56 ` [vxworks 05/14] Add options to control Vxworks related settings Joel Brobecker
2010-05-04 15:25   ` Joel Brobecker
2010-04-25 15:56 ` Joel Brobecker [this message]
2010-04-25 15:56 ` [vxworks 12/14] Add support for VxWorks 6 Joel Brobecker
2010-04-25 16:01 ` [vxworks 04/14] remote-wtxapi: The WTX API abstraction layer Joel Brobecker
2010-05-04 14:58 ` Adding support for VxWorks target Joel Brobecker
2010-05-04 15:43   ` Stan Shebs
2010-05-04 18:30     ` one big unit or several smaller units? (was: "Re: Adding support for VxWorks target") Joel Brobecker
2010-11-25  0:53 ` Adding support for VxWorks target Joel Brobecker

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=1272210447-13895-8-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.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).