Fix "enumeration values not handled in switch" error in testsuite
[deliverable/binutils-gdb.git] / gdb / ada-tasks.c
index 110a710a5ffd023a15071fce596143b138204a3f..1288e1608f57f7377d49b86b5ced72a91a41cef7 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -347,7 +347,7 @@ valid_task_id (int task_num)
    task state.  */
 
 static int
-ada_task_is_alive (struct ada_task_info *task_info)
+ada_task_is_alive (const struct ada_task_info *task_info)
 {
   return (task_info->state != Terminated);
 }
@@ -431,9 +431,9 @@ read_fat_string_value (char *dest, struct value *val, int max_len)
       bounds_fieldno = ada_get_field_index (type, "P_BOUNDS", 0);
 
       bounds_type = TYPE_FIELD_TYPE (type, bounds_fieldno);
-      if (TYPE_CODE (bounds_type) == TYPE_CODE_PTR)
+      if (bounds_type->code () == TYPE_CODE_PTR)
         bounds_type = TYPE_TARGET_TYPE (bounds_type);
-      if (TYPE_CODE (bounds_type) != TYPE_CODE_STRUCT)
+      if (bounds_type->code () != TYPE_CODE_STRUCT)
         error (_("Unknown task name format. Aborting"));
       upper_bound_fieldno = ada_get_field_index (bounds_type, "UB0", 0);
 
@@ -679,7 +679,8 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
                  task_name = p + 2;
 
              /* Copy the task name.  */
-             strncpy (task_info->name, task_name, sizeof (task_info->name));
+             strncpy (task_info->name, task_name,
+                      sizeof (task_info->name) - 1);
              task_info->name[sizeof (task_info->name) - 1] = 0;
            }
          else
@@ -889,10 +890,10 @@ ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
          struct type *eltype = NULL;
          struct type *idxtype = NULL;
 
-         if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+         if (type->code () == TYPE_CODE_ARRAY)
            eltype = check_typedef (TYPE_TARGET_TYPE (type));
          if (eltype != NULL
-             && TYPE_CODE (eltype) == TYPE_CODE_PTR)
+             && eltype->code () == TYPE_CODE_PTR)
            idxtype = check_typedef (TYPE_INDEX_TYPE (type));
          if (idxtype != NULL
              && !TYPE_LOW_BOUND_UNDEFINED (idxtype)
@@ -932,7 +933,7 @@ ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
          /* Validate.  */
          struct type *type = check_typedef (SYMBOL_TYPE (sym));
 
-         if (TYPE_CODE (type) == TYPE_CODE_PTR)
+         if (type->code () == TYPE_CODE_PTR)
            {
              data->known_tasks_element = type;
              return;
@@ -1127,14 +1128,17 @@ print_ada_task_info (struct ui_out *uiout,
       /* Print the associated Thread ID.  */
       if (uiout->is_mi_like_p ())
         {
-         thread_info *thread = find_thread_ptid (task_info->ptid);
+         thread_info *thread = (ada_task_is_alive (task_info)
+                                ? find_thread_ptid (inf, task_info->ptid)
+                                : nullptr);
 
          if (thread != NULL)
            uiout->field_signed ("thread-id", thread->global_num);
          else
-           /* This should never happen unless there is a bug somewhere,
-              but be resilient when that happens.  */
-           uiout->field_skip ("thread-id");
+           {
+             /* This can happen if the thread is no longer alive.  */
+             uiout->field_skip ("thread-id");
+           }
        }
 
       /* Print the ID of the parent task.  */
@@ -1340,7 +1344,7 @@ task_command_1 (const char *taskno_str, int from_tty, struct inferior *inf)
      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.  */
-  thread_info *tp = find_thread_ptid (task_info->ptid);
+  thread_info *tp = find_thread_ptid (inf, task_info->ptid);
   if (tp == NULL)
     error (_("Unable to compute thread ID for task %s.\n"
              "Cannot switch to this task."),
@@ -1429,9 +1433,7 @@ ada_tasks_new_objfile_observer (struct objfile *objfile)
     {
       /* All objfiles are being cleared, so we should clear all
         our caches for all program spaces.  */
-      struct program_space *pspace;
-
-      for (pspace = program_spaces; pspace != NULL; pspace = pspace->next)
+      for (struct program_space *pspace : program_spaces)
         ada_tasks_invalidate_pspace_data (pspace);
     }
   else
@@ -1452,8 +1454,9 @@ ada_tasks_new_objfile_observer (struct objfile *objfile)
       ada_tasks_invalidate_inferior_data (inf);
 }
 
+void _initialize_tasks ();
 void
-_initialize_tasks (void)
+_initialize_tasks ()
 {
   /* Attach various observers.  */
   gdb::observers::normal_stop.attach (ada_tasks_normal_stop_observer);
This page took 0.034002 seconds and 4 git commands to generate.