From patchwork Wed Nov 7 21:32:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 30067 Received: (qmail 71982 invoked by alias); 7 Nov 2018 21:32:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 71851 invoked by uid 89); 7 Nov 2018 21:32:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Reading X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Nov 2018 21:32:44 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 76DF8560E1 for ; Wed, 7 Nov 2018 16:32:43 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id moYn8dhQoRhN for ; Wed, 7 Nov 2018 16:32:43 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 66347560E0 for ; Wed, 7 Nov 2018 16:32:43 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4233) id 606FE3517; Wed, 7 Nov 2018 16:32:43 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [FYI/pushed] ada-tasks.c::read_atcb: start from a cleared ada_task_info result Date: Wed, 7 Nov 2018 16:32:36 -0500 Message-Id: <1541626357-41376-2-git-send-email-brobecker@adacore.com> In-Reply-To: <1541626357-41376-1-git-send-email-brobecker@adacore.com> References: <1541626357-41376-1-git-send-email-brobecker@adacore.com> 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 | 5 +++++ gdb/ada-tasks.c | 16 ++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f7d1de5..c94321b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-11-07 Joel Brobecker + + * ada-tasks.c (read_atcb): Clear task_info before computing + the value of each of its fields. + 2018-11-07 Andrew Burgess * dwarf2read.c (dwarf2_init_integer_type): Check for name being diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index 566eae5..5b97e93 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -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.