From patchwork Fri Nov 22 22:14:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36138 Received: (qmail 98771 invoked by alias); 22 Nov 2019 22:14:44 -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 98762 invoked by uid 89); 22 Nov 2019 22:14:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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.1 spammy=resume, sk:interpr, 2201, our 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; Fri, 22 Nov 2019 22:14:42 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 6CB42116841; Fri, 22 Nov 2019 17:14:40 -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 AqMRfn1huCAQ; Fri, 22 Nov 2019 17:14:40 -0500 (EST) Received: from murgatroyd.Home (97-118-104-188.hlrn.qwest.net [97.118.104.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 2A7AE11683B; Fri, 22 Nov 2019 17:14:40 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI] Avoid crash in print_ada_task_info Date: Fri, 22 Nov 2019 15:14:38 -0700 Message-Id: <20191122221438.25273-1-tromey@adacore.com> MIME-Version: 1.0 In MI mode, print_ada_task_info can crash in find_thread_ptid when trying to print an Ada task that is no longer alive. This patch avoids the problem by checking for this case. Because this is Ada-specific, and because Joel approved it internally, I am checking it in. gdb/ChangeLog 2019-11-22 Tom Tromey * ada-tasks.c (ada_task_is_alive): Make parameter const. (print_ada_task_info): Don't try to fetch thread id if task is not alive. gdb/gdbserver/ChangeLog 2019-11-22 Tom Tromey * gdb.ada/tasks.exp: Add -ada-task-info regression test. * gdb.ada/tasks/foo.adb: Add another stopping location. Change-Id: If25eae6507eebb7537eb8adbcbaa1fc1eec88f5c --- gdb/ChangeLog | 6 ++++++ gdb/ada-tasks.c | 13 ++++++++----- gdb/gdbserver/ChangeLog | 5 +++++ gdb/testsuite/gdb.ada/tasks.exp | 8 +++++++- gdb/testsuite/gdb.ada/tasks/foo.adb | 3 +++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index 110a710a5ff..67aa0c79889 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -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); } @@ -1127,14 +1127,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 (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. */ diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp index 46a53fe76c4..021e902f7b0 100644 --- a/gdb/testsuite/gdb.ada/tasks.exp +++ b/gdb/testsuite/gdb.ada/tasks.exp @@ -82,4 +82,10 @@ gdb_test "info tasks" \ # Now, resume the execution and make sure that GDB does not stop when # task 4 hits the breakpoint. Continuing thus results in our program # running to completion. -gdb_continue_to_end "" continue 1 +set bp_location [gdb_get_line_number "STOP_HERE_2" ${testdir}/foo.adb] +gdb_breakpoint foo.adb:$bp_location +gdb_continue_to_breakpoint second ".*foo.adb:$bp_location.*null; -- STOP_HERE_2" + +# A regression test for a crash caused by trying to find the thread +# for a terminated task. +gdb_test "interpreter-exec mi \"-ada-task-info\"" ".*" diff --git a/gdb/testsuite/gdb.ada/tasks/foo.adb b/gdb/testsuite/gdb.ada/tasks/foo.adb index f95fed4f4ca..9fc43b07c94 100644 --- a/gdb/testsuite/gdb.ada/tasks/foo.adb +++ b/gdb/testsuite/gdb.ada/tasks/foo.adb @@ -65,4 +65,7 @@ begin for J in Task_List'Range loop Task_List (J).Finalize; end loop; + + null; -- STOP_HERE_2 + end Foo;