]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ada-tasks.c::read_atcb: start from a cleared ada_task_info result
authorJoel Brobecker <brobecker@adacore.com>
Wed, 7 Nov 2018 21:03:38 +0000 (16:03 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Wed, 7 Nov 2018 21:28:07 +0000 (16:28 -0500)
The purpose of this patch is not to fix a bug per se, but rather
to robustify this function to make sure it never returns a struct
ada_task_info where some of the fields are left uninitialized.
Reading the current implementation, it attempts to methodically
set them all one by one: but it's not excluded that a future
change might miss something. A memset is cheap and make sure that
this function returns repeatable results.

This in turns allows us to remove some assignments which have become
redundant.

gdb/ChangeLog:

        * ada-tasks.c (read_atcb): Clear task_info before computing
        the value of each of its fields.

gdb/ChangeLog
gdb/ada-tasks.c

index f7d1de52270f0fe0af88a76d894f8cef6b15b230..c94321bebd183333eeabe47935405ac35b806d03 100644 (file)
@@ -1,3 +1,8 @@
+2018-11-07  Joel Brobecker  <brobecker@adacore.com>
+
+       * ada-tasks.c (read_atcb): Clear task_info before computing
+       the value of each of its fields.
+
 2018-11-07  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * dwarf2read.c (dwarf2_init_integer_type): Check for name being
index 566eae599ef82ff05726d68de6a7902f048dd4e0..5b97e93fece2e5a8297e5129f24d9a96f02b6999 100644 (file)
@@ -611,6 +611,10 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
   const struct ada_tasks_pspace_data *pspace_data
     = get_ada_tasks_pspace_data (current_program_space);
 
+  /* Clear the whole structure to start with, so that everything
+     is always initialized the same.  */
+  memset (task_info, 0, sizeof (struct ada_task_info));
+
   if (!pspace_data->initialized_p)
     {
       const char *err_msg = ada_get_tcb_types_info ();
@@ -704,9 +708,6 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
     task_info->parent =
       value_as_address (value_field (common_value,
                                     pspace_data->atcb_fieldno.parent));
-  else
-    task_info->parent = 0;
-  
 
   /* If the ATCB contains some information about entry calls, then
      compute the "called_task" as well.  Otherwise, zero.  */
@@ -732,15 +733,10 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
         value_as_address (value_field (entry_calls_value_element,
                                        called_task_fieldno));
     }
-  else
-    {
-      task_info->called_task = 0;
-    }
 
-  /* If the ATCB cotnains some information about RV callers,
-     then compute the "caller_task".  Otherwise, zero.  */
+  /* If the ATCB cotnains some information about RV callers, then
+     compute the "caller_task".  Otherwise, leave it as zero.  */
 
-  task_info->caller_task = 0;
   if (pspace_data->atcb_fieldno.call >= 0)
     {
       /* Get the ID of the caller task from Common_ATCB.Call.all.Self.