From patchwork Sat Oct 12 02:32:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 98772 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 189CB385AC3F for ; Sat, 12 Oct 2024 02:43:37 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 97D463858C2B for ; Sat, 12 Oct 2024 02:43:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97D463858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 97D463858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728700988; cv=none; b=SgZz4x+eEb+qTqj7+oC+Rzfa19cvkNdlKXRwibiDkY2SdFSZWFayx0yTF51xQCT+Tg8te/1+Z+AwmdvE9GQqZPSVtIrGJfzryJuwKCsfWw+CnmbkB9f+XrVwEIiyIBEOpTN4oqGh8C6xxc6/dwtDiuZuHIOzmic9CUcvt1kx/gY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728700988; c=relaxed/simple; bh=Tl6MOeGMkfxlNWl06MkA4v24pYKJ0XhjXFpIcIBpI9A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ue5dc8XTzkQOSh/Ah18kdiY63cZgUPm1UxvApFEVZa4k7KoLf988OSIADargf9E4r8I0CGlsH+HHx21oqUk82QEGbO+qRNaRuGFvGW18fnTTHrwwZfbAYqPnwXWk/p1zgDMvhYbRUfW2591WZ3LkuFfaUFpX+QZ862BC0bNxR74= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728700985; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9QP3imvLapmnpdzHYQhZbenIeCxzs81N3tWhHWmdeFI=; b=Fm0lbdnFlwFedDSIfUzi4FG97t8y5eueR/mV+6dHTHTxWcKJT9teyUlhe9/Zv3aN1B9COT aAChlilQH5PcAtLLEFn9Kjgq4TlMxdQpTNsJjoYTTCiz2yVVNtxjkpMguR/UOvQhYA81U2 TD5f0ox3KPjY5SA+7ugvsqSaUHnrIJo= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-292-bL05oBhFP_Wwo3Dim_fmFQ-1; Fri, 11 Oct 2024 22:43:04 -0400 X-MC-Unique: bL05oBhFP_Wwo3Dim_fmFQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2F91619560A3 for ; Sat, 12 Oct 2024 02:43:03 +0000 (UTC) Received: from f41-1.lan (unknown [10.22.64.14]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 57AB219560AE; Sat, 12 Oct 2024 02:43:02 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH v2 01/11] Don't attempt to find TLS address when target has no registers Date: Fri, 11 Oct 2024 19:32:42 -0700 Message-ID: <20241012024220.101084-2-kevinb@redhat.com> In-Reply-To: <20241012024220.101084-1-kevinb@redhat.com> References: <20241012024220.101084-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This commit fixes two bugs, one of which is Bug 25807 - that one is fixed by the change in findvar.c. I found it while testing on aarch64; it turned a KFAIL for gdb.threads/tls.exp: print a_thread_local into a FAIL due to a GDB internal error. In addition to the existing test just noted, I've also added a test to the new test case gdb.base/tls-nothreads.exp. It'll be tested, using different scenarios, up to 8 times: PASS: gdb.base/tls-nothreads.exp: default: force_internal_tls=false: after exit: print tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: default: force_internal_tls=true: after exit: print tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: static: force_internal_tls=false: after exit: print tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: static: force_internal_tls=true: after exit: print tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: pthreads: force_internal_tls=false: after exit: print tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: pthreads: force_internal_tls=true: after exit: print tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: pthreads-static: force_internal_tls=false: after exit: print tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: pthreads-static: force_internal_tls=true: after exit: print tls_tbss_1 There is a related problem that's fixed by the minsyms.c change. It can be observed when debugging a program without debugging symbols when the program is not executing. I've written a new test for this, but it's included in the new test case gdb.base/tls-nothreads.exp, found later in this series. Depending on the target, it'll be run up to 8 times for different targets. E.g., on aarch64, I'm seeing these PASSes, all of which test this change: PASS: gdb.base/tls-nothreads.exp: default: force_internal_tls=false: stripped: after exit: print (int) tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: default: force_internal_tls=true: stripped: after exit: print (int) tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: static: force_internal_tls=false: stripped: after exit: print (int) tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: static: force_internal_tls=true: stripped: after exit: print (int) tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: pthreads: force_internal_tls=false: stripped: after exit: print (int) tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: pthreads: force_internal_tls=true: stripped: after exit: print (int) tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: pthreads-static: force_internal_tls=false: stripped: after exit: print (int) tls_tbss_1 PASS: gdb.base/tls-nothreads.exp: pthreads-static: force_internal_tls=true: stripped: after exit: print (int) tls_tbss_1 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25807 --- gdb/findvar.c | 7 ++++++- gdb/minsyms.c | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gdb/findvar.c b/gdb/findvar.c index f7760aa61ca..a530e679c8a 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -485,7 +485,12 @@ language_defn::read_var_value (struct symbol *var, /* Determine address of TLS variable. */ if (obj_section && (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) - addr = target_translate_tls_address (obj_section->objfile, addr); + { + if (!target_has_registers ()) + error (_("Cannot read `%s' without registers"), + var->print_name ()); + addr = target_translate_tls_address (obj_section->objfile, addr); + } } break; diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 33eb9072e5f..a904bd96045 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -1684,7 +1684,13 @@ find_minsym_type_and_address (minimal_symbol *msymbol, { /* Skip translation if caller does not need the address. */ if (address_p != NULL) - *address_p = target_translate_tls_address (objfile, addr); + { + if (!target_has_registers ()) + error (_( + "Cannot determine address of TLS symbol `%s' without registers"), + bound_msym.minsym->print_name ()); + *address_p = target_translate_tls_address (objfile, addr); + } return builtin_type (objfile)->nodebug_tls_symbol; }