From patchwork Fri Jul 26 01:50:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 33804 Received: (qmail 119876 invoked by alias); 26 Jul 2019 01:50:23 -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 119839 invoked by uid 89); 26 Jul 2019 01:50:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=revise, libthread_db, HContent-Transfer-Encoding:8bit X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 Jul 2019 01:50:21 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 892A7307D84D for ; Fri, 26 Jul 2019 01:50:20 +0000 (UTC) Received: from f30-1.lan (ovpn-118-27.phx2.redhat.com [10.3.118.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61BFA1001B0C; Fri, 26 Jul 2019 01:50:20 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH] Fix gdb.python/py-thrhandle.exp failures for -m32 multilib Date: Thu, 25 Jul 2019 18:50:13 -0700 Message-Id: <20190726015013.3970-1-kevinb@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes This patch fixes the following failures when testing with "target_board unix/-m32" using a x86_64-pc-linux-gnu native GDB. FAIL: gdb.python/py-thrhandle.exp: print thread for bogus handle thrs[3] FAIL: gdb.python/py-thrhandle.exp: print thread for bogus handle thrs[4] FAIL: gdb.python/py-thrhandle.exp: print thread id for thrs[0] FAIL: gdb.python/py-thrhandle.exp: print thread id for thrs[1] FAIL: gdb.python/py-thrhandle.exp: print thread id for thrs[2] FAIL: gdb.python/py-thrhandle.exp: thread 0: fetch thread handle from thread FAIL: gdb.python/py-thrhandle.exp: thread 0: verify that handles are the same FAIL: gdb.python/py-thrhandle.exp: thread 1: fetch thread handle from thread FAIL: gdb.python/py-thrhandle.exp: thread 1: verify that handles are the same FAIL: gdb.python/py-thrhandle.exp: thread 2: fetch thread handle from thread FAIL: gdb.python/py-thrhandle.exp: thread 2: verify that handles are the same I've written it so that it might work for other 64-bit host / 32-bit target combos too. gdb/ChangeLog: * linux-thread-db.c (thread_db_target::thread_handle_to_thread_info): Add case for debugging 32-bit target on 64-bit host. Revise comment. --- gdb/linux-thread-db.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 950be9ca5a..1d32e9195c 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1672,16 +1672,21 @@ thread_db_target::thread_handle_to_thread_info (const gdb_byte *thread_handle, { thread_t handle_tid; - /* Thread handle sizes must match in order to proceed. We don't use an - assert here because the resulting internal error will cause GDB to - exit. This isn't necessarily an internal error due to the possibility - of garbage being passed as the thread handle via the python interface. */ - if (handle_len != sizeof (handle_tid)) + /* When debugging a 32-bit target from a 64-bit host, handle_len + will be 4 and sizeof (handle_tid) will be 8. This requires + a different cast than the more straightforward case where + the sizes are the same. + + Use "--target_board unix/-m32" from a native x86_64 linux build + to test the 32/64-bit case. */ + if (handle_len == 4 && sizeof (handle_tid) == 8) + handle_tid = (thread_t) * (const uint32_t *) thread_handle; + else if (handle_len == sizeof (handle_tid)) + handle_tid = * (const thread_t *) thread_handle; + else error (_("Thread handle size mismatch: %d vs %zu (from libthread_db)"), handle_len, sizeof (handle_tid)); - handle_tid = * (const thread_t *) thread_handle; - for (thread_info *tp : inf->non_exited_threads ()) { thread_db_thread_info *priv = get_thread_db_thread_info (tp);