daily update
[deliverable/binutils-gdb.git] / gdb / ada-tasks.c
index 5176d75ccda1670e3ecf5c944d0d368a8c48db86..f57f44ff96e9aad1c2cdea4dcd38099429f2a7ba 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (C) 1992, 1993, 1994, 1997, 1998, 1999, 2000, 2003, 2004, 2005,
-   2007, 2008, 2009 Free Software Foundation, Inc.
+   2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -49,7 +49,9 @@ enum task_states
   Timer_Server_Sleep,
   AST_Server_Sleep,
   Asynchronous_Hold,
-  Interrupt_Server_Blocked_On_Event_Flag
+  Interrupt_Server_Blocked_On_Event_Flag,
+  Activating,
+  Acceptor_Delay_Sleep
 };
 
 /* A short description corresponding to each possible task state.  */
@@ -58,7 +60,7 @@ static const char *task_states[] = {
   N_("Runnable"),
   N_("Terminated"),
   N_("Child Activation Wait"),
-  N_("Accept Statement"),
+  N_("Accept or Select Term"),
   N_("Waiting on entry call"),
   N_("Async Select Wait"),
   N_("Delay Sleep"),
@@ -69,7 +71,9 @@ static const char *task_states[] = {
   "",
   "",
   N_("Asynchronous Hold"),
-  ""
+  "",
+  N_("Activating"),
+  N_("Selective Wait")
 };
 
 /* A longer description corresponding to each possible task state.  */
@@ -78,7 +82,7 @@ static const char *long_task_states[] = {
   N_("Runnable"),
   N_("Terminated"),
   N_("Waiting for child activation"),
-  N_("Blocked in accept statement"),
+  N_("Blocked in accept or select with terminate"),
   N_("Waiting on entry call"),
   N_("Asynchronous Selective Wait"),
   N_("Delay Sleep"),
@@ -89,7 +93,9 @@ static const char *long_task_states[] = {
   "",
   "",
   N_("Asynchronous Hold"),
-  ""
+  "",
+  N_("Activating"),
+  N_("Blocked in selective wait statement")
 };
 
 /* The index of certain important fields in the Ada Task Control Block
@@ -192,45 +198,18 @@ get_task_number_from_id (CORE_ADDR task_id)
 int
 valid_task_id (int task_num)
 {
+  ada_build_task_list (0);
   return (task_num > 0
           && task_num <= VEC_length (ada_task_info_s, task_list));
 }
 
-/* Return the task info associated to the Environment Task.
-   This function assumes that the inferior does in fact use tasking.  */
-
-struct ada_task_info *
-ada_get_environment_task (void)
-{
-  ada_build_task_list (0);
-  gdb_assert (VEC_length (ada_task_info_s, task_list) > 0);
-
-  /* We use a little bit of insider knowledge to determine which task
-     is the Environment Task:  We know that this task is created first,
-     and thus should always be task #1, which is at index 0 of the
-     TASK_LIST.  */
-  return (VEC_index (ada_task_info_s, task_list, 0));
-}
-
-/* Call the ITERATOR function once for each Ada task that hasn't been
-   terminated yet.  */
+/* Return non-zero iff the task STATE corresponds to a non-terminated
+   task state.  */
 
-void
-iterate_over_live_ada_tasks (ada_task_list_iterator_ftype *iterator)
+static int
+ada_task_is_alive (struct ada_task_info *task_info)
 {
-  int i, nb_tasks;
-  struct ada_task_info *task;
-
-  ada_build_task_list (0);
-  nb_tasks = VEC_length (ada_task_info_s, task_list);
-
-  for (i = 0; i < nb_tasks; i++)
-    {
-      task = VEC_index (ada_task_info_s, task_list, i);
-      if (!ada_task_is_alive (task))
-        continue;
-      iterator (task);
-    }
+  return (task_info->state != Terminated);
 }
 
 /* Extract the contents of the value as a string whose length is LENGTH,
@@ -293,7 +272,7 @@ read_fat_string_value (char *dest, struct value *val, int max_len)
 
   /* Extract LEN characters from the fat string.  */
   array_val = value_ind (value_field (val, array_fieldno));
-  read_memory (VALUE_ADDRESS (array_val), dest, len);
+  read_memory (value_address (array_val), dest, len);
 
   /* Add the NUL character to close the string.  */
   dest[len] = '\0';
@@ -314,7 +293,6 @@ get_known_tasks_addr (void)
 
   if (ada_tasks_check_symbol_table)
     {
-      struct symbol *sym;
       struct minimal_symbol *msym;
 
       msym = lookup_minimal_symbol (KNOWN_TASKS_NAME, NULL, NULL);
@@ -570,7 +548,8 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
         ada_coerce_to_simple_array_ptr (value_field (tcb_value,
                                                      fieldno.entry_calls));
       entry_calls_value_element =
-        value_subscript (entry_calls_value, atc_nesting_level_value);
+        value_subscript (entry_calls_value,
+                        value_as_long (atc_nesting_level_value));
       called_task_fieldno =
         ada_get_field_index (value_type (entry_calls_value_element),
                              "called_task", 0);
@@ -631,7 +610,7 @@ static int
 read_known_tasks_array (void)
 {
   const int target_ptr_byte =
-    gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
+    gdbarch_ptr_bit (target_gdbarch) / TARGET_CHAR_BIT;
   const CORE_ADDR known_tasks_addr = get_known_tasks_addr ();
   const int known_tasks_size = target_ptr_byte * MAX_NUMBER_OF_KNOWN_TASKS;
   gdb_byte *known_tasks = alloca (known_tasks_size);
@@ -654,7 +633,7 @@ read_known_tasks_array (void)
   for (i = 0; i < MAX_NUMBER_OF_KNOWN_TASKS; i++)
     {
       struct type *data_ptr_type =
-        builtin_type (current_gdbarch)->builtin_data_ptr;
+        builtin_type (target_gdbarch)->builtin_data_ptr;
       CORE_ADDR task_id =
         extract_typed_address (known_tasks + i * target_ptr_byte,
                               data_ptr_type);
@@ -693,15 +672,6 @@ ada_build_task_list (int warn_if_null)
   return 1;
 }
 
-/* Return non-zero iff the task STATE corresponds to a non-terminated
-   task state.  */
-
-int
-ada_task_is_alive (struct ada_task_info *task_info)
-{
-  return (task_info->state != Terminated);
-}
-
 /* Print a one-line description of the task whose number is TASKNO.
    The formatting should fit the "info tasks" array.  */
 
@@ -742,9 +712,6 @@ short_task_info (int taskno)
   else if (task_info->state == Entry_Caller_Sleep && task_info->called_task)
     printf_filtered (_(" Waiting on RV with %-3d"),
                      get_task_number_from_id (task_info->called_task));
-  else if (task_info->state == Runnable && active_task_p)
-    /* Replace "Runnable" by "Running" since this is the active task.  */
-    printf_filtered (" %-22s", _("Running"));
   else
     printf_filtered (" %-22s", _(task_states[task_info->state]));
 
@@ -785,7 +752,8 @@ info_task (char *taskno_str, int from_tty)
   task_info = VEC_index (ada_task_info_s, task_list, taskno - 1);
 
   /* Print the Ada task ID.  */
-  printf_filtered (_("Ada Task: %s\n"), paddr_nz (task_info->task_id));
+  printf_filtered (_("Ada Task: %s\n"),
+                  paddress (target_gdbarch, task_info->task_id));
 
   /* Print the name of the task.  */
   if (task_info->name[0] != '\0')
@@ -899,6 +867,28 @@ task_command_1 (char *taskno_str, int from_tty)
   if (!ada_task_is_alive (task_info))
     error (_("Cannot switch to task %d: Task is no longer running"), taskno);
    
+  /* On some platforms, the thread list is not updated until the user
+     performs a thread-related operation (by using the "info threads"
+     command, for instance).  So this thread list may not be up to date
+     when the user attempts this task switch.  Since we cannot switch
+     to the thread associated to our task if GDB does not know about
+     that thread, we need to make sure that any new threads gets added
+     to the thread list.  */
+  target_find_new_threads ();
+
+  /* Verify that the ptid of the task we want to switch to is valid
+     (in other words, a ptid that GDB knows about).  Otherwise, we will
+     cause an assertion failure later on, when we try to determine
+     the ptid associated thread_info data.  We should normally never
+     encounter such an error, but the wrong ptid can actually easily be
+     computed if target_get_ada_task_ptid has not been implemented for
+     our target (yet).  Rather than cause an assertion error in that case,
+     it's nicer for the user to just refuse to perform the task switch.  */
+  if (!find_thread_ptid (task_info->ptid))
+    error (_("Unable to compute thread ID for task %d.\n"
+             "Cannot switch to this task."),
+           taskno);
+
   switch_to_thread (task_info->ptid);
   ada_find_printable_frame (get_selected_frame (NULL));
   printf_filtered (_("[Switching to task %d]\n"), taskno);
@@ -942,7 +932,7 @@ Task switching not supported when debugging from core files\n\
 
 /* Indicate that the task list may have changed, so invalidate the cache.  */
 
-void
+static void
 ada_task_list_changed (void)
 {
   stale_task_list_p = 1;  
@@ -951,7 +941,7 @@ ada_task_list_changed (void)
 /* The 'normal_stop' observer notification callback.  */
 
 static void
-ada_normal_stop_observer (struct bpstats *unused_args)
+ada_normal_stop_observer (struct bpstats *unused_args, int unused_args2)
 {
   /* The inferior has been resumed, and just stopped. This means that
      our task_list needs to be recomputed before it can be used again.  */
@@ -960,7 +950,7 @@ ada_normal_stop_observer (struct bpstats *unused_args)
 
 /* A routine to be called when the objfiles have changed.  */
 
-void
+static void
 ada_new_objfile_observer (struct objfile *objfile)
 {
   /* Invalidate all cached data that were extracted from an objfile.  */
@@ -973,6 +963,9 @@ ada_new_objfile_observer (struct objfile *objfile)
   ada_tasks_check_symbol_table = 1;
 }
 
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_tasks;
+
 void
 _initialize_tasks (void)
 {
This page took 0.028026 seconds and 4 git commands to generate.