From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WXHGKcl0cGpoKQIAWB0awg (envelope-from ) for ; Mon, 03 Aug 2026 07:00:25 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=jt4J/+wc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A02181E09E; Mon, 03 Aug 2026 07:00:25 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 86A831E099 for ; Mon, 03 Aug 2026 07:00:24 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95FB94BA23F1 for ; Mon, 3 Aug 2026 11:00:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95FB94BA23F1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=jt4J/+wc Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id DB8B44B99F74 for ; Mon, 3 Aug 2026 10:59:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB8B44B99F74 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DB8B44B99F74 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785754798; cv=none; b=x7QpuJkb7uz5rlKKDexrjqJFNd4PLnMM2iADP2VL0wkqyQAKy37RbMhdyQ8OTlHYMWuJkbNkxirvXwa6Ecm1ji7ct/tN+p7z0hJMAR9DA6YrRdJgyZia+bZZKgnUGCH5lCp2pnftkqQ24OV7BLz/5ShPMhjXSzBLBy+3ocdMzZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785754798; c=relaxed/simple; bh=HyF/71dbU+5UMpSEAYMCutTVVPxufYUqvAvixZFjtQA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jFgx/aYDzw5rgWvha7GZW5JnZzbT2sbZW5UCJFLy0SSkvDSXVewWekU0HRrmR+adK8qgpgDtLjYJ2fNWi1zSExyKV0wUjuXOwaW77KY4v3j9OY/7aJo5yG5Bmk0L/amsY7fdPFZVT9LLxhz0GnL9pSlwYKumEOUc3DLSREbnr9k= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=jt4J/+wc DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB8B44B99F74 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2caea3f742bso32423795ad.0 for ; Mon, 03 Aug 2026 03:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785754797; x=1786359597; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=tvbGjObNTyMkCbwcRv4WT/V/LiG/Gf/lsKaWfGSnYpI=; b=jt4J/+wcXhSK6dw132+zr1U6R8VTKysKoRwVHcSCV7orhF12Y/nqOiUy3ELuYwogem xN5rB/o0NBxsM9yCgz0G4odyZNe0/sSQNr1nChUIPIdJAJBeP028+ekdbHu1kpoVwmhO kM9z/IVmFunvcGIKUdLTiKGcIypU8wozz1BYaHiI7D/4Caw7PcCMls85fbt2WOwlJhHD SZN9ryzzO7+hQQAtGW2vY98jH/uXibaLRQ0/Jz8Ya9sGaczyg7eclJ3u2S5fcp3XNUxE Kqo1bGZIxCaU+D/vUe+n87m0RiWvy4147UGzMPxb8mowjKoUusUQzxIA8VYedCCuNOMs nPnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785754797; x=1786359597; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tvbGjObNTyMkCbwcRv4WT/V/LiG/Gf/lsKaWfGSnYpI=; b=Vn2SPOXOm8og0Qqi5tmfUSXE8TNg9/YLSJ5mhCIqQeKFZkouvj2RzBAcuKLlwG9eKv 0WN8+BIY+AlYR4P9IPcZHrhyFzQ/knAZ6zTSCPfOWmcZY4JICfaqQkE+YT/wVZjJ1nXR 2neqpLINflg60ZXk0pvl9ptcupvNovQ+PXlNtFM8WUiGgR3Wo2bfYJ2h/Se/GaH7wO1v zyZhU+9W2xBS4aQWuZiGj4/c7tBqvqQtYud4QfOGE0QZDwe1+aoEPDR9QLL2VDB8FKGj mNET+vM1H+3Jm6rmEZ2Emm1jFvptEJ35KdpSnyaPqBEcT7Hl4CpWDyffovarfmWs+H+B BtnA== X-Gm-Message-State: AOJu0YxgBt3IMEV6oaBLBJ2AwuKRn/YNlIF49zIn/Y+qzTLQrhGzB5Kw hUl8APZ4IOMf6S6Jub30K7+krkhk4wvMZWw2wwltwMe4sHhi/3vVMI0b X-Gm-Gg: AR+sD10g8tznoR4qp6mUNldI5vgnlaqrghbwqTLDWcufamQgsCxqCm21Jx/z7lxk4UC QoKXu3GPBjrraQoNa/ltKlL3g6ZqcYbYRzmJB3g/DCanY90gJBEImlVTR3pZq0NBoy2dT3/99Yh 53p+VHvP2GfXx87DDPqbc/+049iJM8fjGmThAaAIk9X26v0RbpnkHWnUCdfxnUG2mwSVAM4F0qi /A9DA1fqPmSBitQIYZDyIMUMVr3QvRO/4EdXuM6x2iFkqsO0q4n6HlpR05iMnYGK8J7dJQMC22+ 5T+c9OnZoPxzKo7bpkCCbhwcc8/oluTr8+3tE+XgLJ1U5M2BUdenqQk4HW+3zJITBnITZ9LZ15Y ChLB0reDZZ/xHpt2yFCGNq3bI/a0CZ8dfEam71cTT2EGdrZIn9e3s1m9CownRhJ3Ig435N4B46f erpAl9wbQY3L/ZaZ/lDAVU8+ExjxhZoSAKHWmcVXFEw2ytXMYXozoHog8VqvrdRdIlM57oWczHF 42o3RriWGldu7+wsk0ulvVLuQ== X-Received: by 2002:a17:903:4b4c:b0:2ce:6d4a:5b8a with SMTP id d9443c01a7336-2d05242c4a2mr93578505ad.38.1785754796819; Mon, 03 Aug 2026 03:59:56 -0700 (PDT) Received: from dhcp-9-123-6-89.bl1-in.ibm.com ([129.41.58.1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d04b0ea870sm35993245ad.48.2026.08.03.03.59.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 03 Aug 2026 03:59:56 -0700 (PDT) From: Aditya Vidyadhar Kamath To: ulrich.weigand@de.ibm.com, simon.marchi@polymtl.ca, tom@tromey.com Cc: gdb-patches@sourceware.org, Aditya.Kamath1@ibm.com, sangamesh.swamy@in.ibm.com, PRAJWAL.B.MEHENDARKAR@ibm.com Subject: [PATCH v2 1/2] Add TLS variable debug support for AIX [ 64-bit XCOFF files only] Date: Mon, 3 Aug 2026 16:29:44 +0530 Message-ID: <20260803105943.75052-2-akamath996@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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~public-inbox=simark.ca@sourceware.org From: Aditya Kamath This is a patch that adds TLS debug support for variables in AIX for 64 bit XCOFF binaries only. Currently in AIX, if we debug a TLS variable we get, (gdb) print tls_counter Cannot find thread-local variables on this target This patch uses thread pointer in R13 plus adds the offset to get the TLS variable address. Also adds the AIX specific gdbarch () methods. After this patch we get, gdb/gdb thread-local GNU gdb (GDB) 18.0.50.20260728-git Copyright (C) 2026 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "powerpc64-ibm-aix7.2.0.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: . +------------------------------------------------------------------------------+ | Find the GDB manual online at: | | http://www.gnu.org/software/gdb/documentation/. | | For help, type "help". | | Type "apropos word" to search for commands related to "word". | +------------------------------------------------------------------------------+ Reading symbols from thread-local... (gdb) b 16 Breakpoint 1 at 0x10000894: file thread-local.c, line 16. (gdb) r Starting program: /home/aditya/binutils-gdb/thread-local [New Thread 258 (tid 118292825) (id 2)] [Switching to thread 2 (Thread 258 (tid 118292825))] Thread 2 hit Breakpoint 1, thread_function (arg=0x1) at thread-local.c:16 16 sleep(1); (gdb) p tls_counter $1 = 100 (gdb) q --- gdb/rs6000-aix-tdep.c | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c index d823fea5645..aa68654ff41 100644 --- a/gdb/rs6000-aix-tdep.c +++ b/gdb/rs6000-aix-tdep.c @@ -39,6 +39,7 @@ #include "gdbsupport/xml-utils.h" #include "trad-frame.h" #include "frame-unwind.h" +#include "inferior.h" /* If the kernel has to deliver a signal, it pushes a sigcontext structure on the stack and then calls the signal handler, passing @@ -1355,6 +1356,73 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, offset, len, 0); } +/* For AIX, use the rs6000_aix_fetch_tls_load_module_address gdbarch method. + + Thread-local variables accessed via a simple TP-relative offset (the Local + Exec and Initial Exec TLS models) are only valid for the main executable and + for shared libraries that were pulled in at program startup. Variables + belonging to a library loaded later via dlopen() have their storage + allocated dynamically; their addresses must be resolved through the DTV + (Dynamic Thread Vector) and cannot be computed with a plain TP offset. + + Until full DTV-based lookup is implemented, reject any objfile that is a + shared library (OBJF_SHARED) which has been dlopen'd and only + allow the main executable (OBJF_MAINLINE). Returning 0 here causes + rs6000_aix_get_thread_local_address() to be called with lm_addr == 0, + which it treats as nothing for now. */ + +static CORE_ADDR +rs6000_aix_fetch_tls_load_module_address (struct objfile *objfile) +{ + /* TLS variables from shared libraries cannot be directly fetched + via the thread pointer if they were loaded by dlopen(). */ + if (objfile->flags & OBJF_SHARED) + throw_error (TLS_GENERIC_ERROR, + _("TLS lookup via thread pointer is not supported for " + "shared library \"%s\"; full DTV-based lookup is not " + "yet implemented for AIX"), + objfile_name (objfile)); + + return 0; +} + +/* Use the AIX get_thread_local_address gdbarch function. + + On 64-bit AIX the thread pointer is in R13. For the Local Exec TLS model + (used by the main executable) the XCOFF symbol value is a signed + TP-relative offset, so the per-thread address is: + + address = thread_pointer + (int64_t) offset + + This only works correctly when the variable's storage is allocated + statically relative to the thread pointer, which is guaranteed for the + main executable. */ + +static CORE_ADDR +rs6000_aix_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid, + CORE_ADDR lm_addr, CORE_ADDR offset) +{ + ppc_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + /* 64-bit AIX: the thread pointer is in R13. */ + if (tdep->wordsize != 8) + throw_error (TLS_GENERIC_ERROR, + _("TLS lookup not yet supported for 32-bit AIX")); + + int tp_regnum = PPC_R0_REGNUM + 13; + + regcache *regcache + = get_thread_arch_regcache (current_inferior (), ptid, gdbarch); + target_fetch_registers (regcache, tp_regnum); + + ULONGEST tp; + if (regcache->cooked_read (tp_regnum, &tp) != REG_VALID) + throw_error (TLS_GENERIC_ERROR, + _("Unable to fetch thread pointer for TLS lookup")); + + return tp + (CORE_ADDR)(int64_t) offset; +} + static void rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -1411,6 +1479,14 @@ rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset); set_gdbarch_make_solib_ops (gdbarch, make_aix_solib_ops); + + + /* TLS support for AIX. */ + set_gdbarch_fetch_tls_load_module_address + (gdbarch, rs6000_aix_fetch_tls_load_module_address); + set_gdbarch_get_thread_local_address + (gdbarch, rs6000_aix_get_thread_local_address); + frame_unwind_append_unwinder (gdbarch, &aix_sighandle_frame_unwind); } -- 2.51.2