From patchwork Mon Mar 23 04:34:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Vidyadhar Kamath X-Patchwork-Id: 132172 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 665F24B9700A for ; Mon, 23 Mar 2026 04:35:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 665F24B9700A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UkeHq03e X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 655C14B9DB74 for ; Mon, 23 Mar 2026 04:35:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 655C14B9DB74 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 655C14B9DB74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774240506; cv=none; b=gperFr/92bkE7JYfUy2GdRg6FnPW3A93xFjPlA4dus83fgOaRd/1oox8Qi9TWPfOT7H9rQ6eoKqc6jmgzGjltTyctAcs11FRM+8+2/j+iOENzO863q+hVAgaLtli6XbBdkRR1cdGPeP36iRVTT/+kwSjJXmH/XahOkZJ+FADWBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774240506; c=relaxed/simple; bh=8IJvwk7QUrwHfVao9vyih47hsvXSPgUC48lAOzEoK6I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DLx+4gZgrffk5wTh8MHhxk0HMNGVyVYJZnoLwpdNQ8qUOhMOZc/nudiyfqSHh2T+4WxE4n9BRIyffDhnMV8gn4ynXFwqxbSugPDnfD0oh8B/CoYd6EG6WDEUmwub63EcUWMSVhbxDHH6zJFu9De+LyXQ8VcMuxXti2nCV5gWVLs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 655C14B9DB74 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-c742d7c8acfso1568891a12.1 for ; Sun, 22 Mar 2026 21:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774240505; x=1774845305; 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; bh=SN8/0hLOFDLVSuRpW1Xx8RpQKfXawYpim369eRPSf38=; b=UkeHq03eij9MpBQtQP7U9BYp0OKdB3WO9tjlvwb7n1wGEidvDcw4IR4v1iPtJ5eIV+ OYYZJ6qm+8Fxpi3TTaHtmJuKqBwzU7dD82JLPnBmFXWxf/LAfv5PHzPityE7nDENu/hg 4/24cCTiMie0Rk2yLY5yr9dHkqWUMbqd6Wltv022cMhBBftQqFgZ6cyLNCQKCoMKFPEb y+e2s+/PqtW3agKJTyW2jDc/iaflk3sBmxB9EPzSNGCb621iMSrGyVGak5Qbg8TuFKc+ C5rC1MKWEXRw21xul0HN2zkRN52Q+9KxzMZ57ODPnDgEtu8z6raFZ1y5AVjWGqeYzMff SRnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774240505; x=1774845305; 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; bh=SN8/0hLOFDLVSuRpW1Xx8RpQKfXawYpim369eRPSf38=; b=UpqlcuKPCg05JVBoTllxwUTwRbv48nymfG7IXLE/UWyXaGntljmnKDhR/wgqeC9Jp5 98hAKhNH69J5LCtB/ZFQn6GCNpiiB5FVwZYqV6OSYWqqEbqTGJriNCuPLip9iyWv139A aPhInbof8LbNnYZ5bYGYzCChvJoC+LhnIVHGUgUVSYm8BRGsSDM7fqcT9ZFPLxW9feOa XKU6fFtHyN2HfM3GD/7pvn1197Nv4hCZmSGIdterWimAcnmDHuaiFOAOYN6bzh3j/eBJ 8YUHGr1DmWhikEhRjDzkJlcf/E2iQz1hj4uxLfWKyBFW2keeLb+UBvvqPJ2y0hZKRuJk KTFA== X-Gm-Message-State: AOJu0Yy+VALLEGhasLrQwQrG2A2vIuK/H81ILCpLflLNay76+xRHOkgN xBDUYPJVjDi+QA9yqk1M2VFO4EaARag6A7LioT4Ap8Q2o4SJo+YclPyv X-Gm-Gg: ATEYQzwOm0pWZY1VOVVd+/GfsQND81oMBtA6pyaTtPUJ62HxWsu+2TNcpseh7WqXQB0 rjyCZKQBYqJMbpiHuDEPIoM9VNRloTKe9gMW3mDo23RktZ8/95k4fFLc+YxY22mMc2oOQflUx2h DK7U/Hbp0WxTIlJypLu/9p+wx1fMAeXJbCf6lMPZABPL7WeKn7RFb91QyqQ2xJAO17bhCFE3mrI aRUKWTf6Evv5LpMKr5GmKCcI0pwvJ7TKL6wn6smhhhNS6bT3eOOxqYAZeEU/uuzLephnvU74S4u UqbVRXU6oQRWAPI+zumNv0k8YltbL2pyPu6a9Ziz2ypjy7uEZJNt6BPP3pd4VJePIdtmmpTKz7S FH6FXkE71a8kHRvg9j1FqU4jmqqZCFJEfq/yyNs1kOI+2I0unfG16BkUyIPVaDc8BnMXQ+kwNsU /3NNq3k5zyUXti8HUdgDK6X65aZYg5sjXoc7nREFoMu2HC+Q== X-Received: by 2002:a05:6300:218f:b0:398:7d1d:c862 with SMTP id adf61e73a8af0-39bceb11696mr10228874637.28.1774240505205; Sun, 22 Mar 2026 21:35:05 -0700 (PDT) Received: from localhost.localdomain ([122.171.16.28]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82b040da3easm7673557b3a.41.2026.03.22.21.35.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 22 Mar 2026 21:35:04 -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, Aditya Vidyadhar Kamath Subject: [PATCH v3] Add support for recording minimal symbols in AIX for non DWARF compiled library function record. Date: Mon, 23 Mar 2026 10:04:46 +0530 Message-ID: <20260323043445.21520-2-akamath996@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GB_FREEMAIL_NUM, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 From: Aditya Vidyadhar Kamath Commit 1dfd89c739 (gdb: Remove stabs support from XCOFF inferiors) removed STABS handling from xcoffread.c. While removing full symtab and compunit_symtab construction is appropriate when DWARF is available, the change also removed recording of minimal symbols, which still provide value for XCOFF binaries that lack DWARF. On AIX, system libraries such as libc and libpthread are built with STABS debug information up to AIX 7.3 TL4. As a result, current GDB master is unable to record even minimal symbols for these libraries, leading to missing function names (e.g. printf) in common debugging scenarios. Consider the example below, # cat ~/gdb_tests/main.c #include #include "libx.h" int main() { printf ("lib_func() = %d \n", lib_func()); return 0; } # cat ~/gdb_tests/libx.c int g_in_lib = 777; int lib_func() { return g_in_lib + 1; } # cat ~/gdb_tests/libx.h int lib_func(); We build libx and then link it to main. When we compile this in GDB in AIX today in master branch we get, Reading symbols from //gdb_tests/main... (gdb) b main Breakpoint 1 at 0x10000530: file //gdb_tests/main.c, line 5. (gdb) r Starting program: /gdb_tests/main Breakpoint 1, main () at //gdb_tests/main.c:5 5 printf ("lib_func() = %d \n", lib_func()); (gdb) call printf() No symbol "printf" in current context. (gdb) The issue is Without minimal symbols: - Functions from system libraries are not visible in backtraces. - Calls such as call printf() fail with no symbol in current context. - This affects not only stepping, but also basic usability of backtraces on AIX systems without DWARF-enabled system libraries. - Even when full debug information is unavailable, minimal symbols are still sufficient to: - Identify function entry/exit points. - Display meaningful backtraces involving system libraries. This patch restores recording of minimal symbols in xcoffread.c, while keeping the removal of: - STABS-based symtabs - compunit_symtabs The below function (read_xcoff_minimal_symbols) ensures that: - record_minimal_symbol() is still invoked where appropriate. - No attempt is made to rebuild full debug information from STABS. - DWARF remains the sole source for full debugging information when available. This keeps the original intent of the STABS removal intact, while restoring essential functionality for non-DWARF XCOFF binaries. After applying the patch we get, GNU gdb (GDB) 18.0.50.20260316-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 //gdb_tests/main... (gdb) b main Breakpoint 1 at 0x10000530: file //gdb_tests/main.c, line 5. (gdb) n The program is not being run. (gdb) r Starting program: /gdb_tests/main Breakpoint 1, main () at //gdb_tests/main.c:5 5 printf ("lib_func() = %d \n", lib_func()); (gdb) call (int)printf ("lib_func() = %d \n", lib_func()) lib_func() = 778 $1 = 18 (gdb) --- gdb/xcoffread.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index b3d9bb97b62..f8021ef7793 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -28,6 +28,7 @@ #include "xcoffread.h" #include "symtab.h" +#include "minsyms.h" #include "gdbtypes.h" #include "symfile.h" #include "objfiles.h" @@ -232,6 +233,87 @@ xcoff_get_toc_offset (objfile *objfile) return 0; } +/* This function is used to read minimal sysmbols from the XCOFF STABS + symbol table. This function needs to be called when a library (like + libc) in AIX is compiled using xlc whose debug format is STABS. + When STABS debug information is not available, then in the backtrace + or other GDB features the STABS compiled functions like (printf) + will not be seen. Though we no longer support STABS debug, this + function records minimal symbol or information needed to show + such functions in backtrace. */ + +static void +read_xcoff_minimal_symbols (objfile *objfile) +{ + bfd *abfd = objfile->obfd.get (); + + gdb::array_view symbol_table + = gdb_bfd_canonicalize_symtab (abfd, false); + /* Get the number of symbols we need. */ + int number_of_symbols = symbol_table.size(); + + /* Return on error. */ + if (number_of_symbols < 0) + return; + + minimal_symbol_reader reader (objfile); + for (int i = 0; i < number_of_symbols; i++) + { + asymbol *sym = symbol_table[i]; + flagword sym_flags = sym->flags; + CORE_ADDR sym_value = bfd_asymbol_value (sym); + asection *sym_section = bfd_asymbol_section (sym); + enum minimal_symbol_type ms_type = mst_unknown; + const char *sym_name = bfd_asymbol_name (sym); + + /* Skip undefined sections if any. */ + if (sym_section == bfd_und_section_ptr) + continue; + + /* Skip undefined, special symbols and debugging symbols. */ + if (sym_flags & (BSF_DEBUGGING | BSF_SECTION_SYM)) + continue; + + /* We need to pass ms_type when we record. So find the symbol type. */ + + /* If this is an object file. */ + if (sym_flags & BSF_OBJECT) + { + /* Code section. */ + if (sym_section && (bfd_section_flags (sym_section) & SEC_CODE)) + ms_type = mst_text; + /* Data section. */ + else if (sym_section && (bfd_section_flags (sym_section) & SEC_DATA)) + ms_type = mst_data; + /* BSS section. */ + else if (sym_section && (bfd_section_flags (sym_section) & SEC_ALLOC)) + ms_type = mst_bss; + else + ms_type = mst_unknown; + } + /* Check for symbols marked as functions explicitly. */ + else if (sym_flags & BSF_FUNCTION) + ms_type = mst_text; + /* Section Based Guess. Code or Data or BSS. */ + else if (sym_section) + { + if (bfd_section_flags (sym_section) & SEC_CODE) + ms_type = mst_text; + else if (bfd_section_flags (sym_section) & SEC_DATA) + ms_type = mst_data; + else if (bfd_section_flags (sym_section) & SEC_ALLOC) + ms_type = mst_bss; + } + + /* Add the symbol if it's global or weak */ + if ((sym_flags & (BSF_GLOBAL | BSF_WEAK)) && sym_name && *sym_name) + reader.record_with_info (sym_name, unrelocated_addr (sym_value), ms_type, + gdb_bfd_section_index (abfd, sym_section)); + } + + reader.install (); +} + /* Read the XCOFF symbol table. The only thing we are interested in is the TOC offset value. */ @@ -240,6 +322,11 @@ xcoff_symfile_read (objfile *objfile, symfile_add_flags symfile_flags) { xcoff_find_toc_offset (objfile); + /* Read minimal symbols from the STABS symbol table of an XCOFF binary + This makes sure we see functions from libc given libraries link to + it and libc in AIX may not be DWARF compiled. . */ + read_xcoff_minimal_symbols (objfile); + /* DWARF2 sections. */ dwarf2_initialize_objfile (objfile, &dwarf2_xcoff_names); }