From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2fVuE9Y6vWlvaDEAWB0awg (envelope-from ) for ; Fri, 20 Mar 2026 08:17:26 -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=20230601 header.b=YU54Sulz; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 49A2A1E0BC; Fri, 20 Mar 2026 08:17:26 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 79ED01E04F for ; Fri, 20 Mar 2026 08:17:25 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 98E824B9DB68 for ; Fri, 20 Mar 2026 12:17:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98E824B9DB68 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=YU54Sulz Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 0E54A4BB3BE3 for ; Fri, 20 Mar 2026 12:16:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E54A4BB3BE3 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 0E54A4BB3BE3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774009013; cv=none; b=cWTPXxcjUMqk30OhPVDIz2QDIamo/Xi8JdYFk5C+8tsWeYUzOwQBoMPdA8UrDA/9sZPxDdgGOBW0JJcgiUK+sH+ublD+Xm5SEgYMgcuiKiFGzBdHVS8MAUgW9pa4jiHjiE00AtXH681y39TBgT6j5S64UjGl6jYsIwNdXjo0I0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774009013; c=relaxed/simple; bh=tT0hQKUrDBuT37pt9VX5oh1uqM0NnCvoNVSrDpdH9og=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K82HbUjAj33to6ahOWGo32a7OJw0Y0VGdxTGiPrRtspktslxlVKuDCbw4ptomvcgeWbALnSlvVKg/bXdep0Ph2iaQCP8ICBgBWqyM0SJm69kgN1Zd72m/QcLWBFbx9ImBK6B6Ucy+6uyTXacxF0iWZAksu2fI4eP6x1Ta78d6nM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E54A4BB3BE3 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-82748257f5fso2055507b3a.1 for ; Fri, 20 Mar 2026 05:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774009012; x=1774613812; 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=6ZEYL3ET3LuwpaE8oS7FJNx863T8VoUOQennpI2zoCE=; b=YU54SulzUv1jMX6DTuulUCfkyjYPJ962QD4GGJ5iocktI3ynxegM7Ch0daUkTG0xr/ mEzDLTA8b4DM47ODTGryjvpmcH/nCEtG2TRli3UUg+CbKT4Vj4RGQHyB/qA+ebNYIOp5 2ilXkGX/3sit0kbLz2PXveBbUaiZzqMrcTE/YIzcG6s4ElZX2HE0Dx9gUkJbUn/Xo7pj S7kqqgtv48Sc9jbWzNBCrEzPC0BfIiPNdzMU0BJAw14uFnNpwVeiA16dzYjxSIeHuVyI Px4Ae9tVh8Tf15WJomjDzH1d2DAJROdtrxEoJgQoE4fxT44HCXhsQzllF1LBmK0c4QSL Fp+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774009012; x=1774613812; 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=6ZEYL3ET3LuwpaE8oS7FJNx863T8VoUOQennpI2zoCE=; b=qEk9Yir5MqIjrLyCyqPwMyVXeRMdPpT7YhVgeWRne4TNOy4N6vII1Ii7DrdjUPt/Fr 9wVF931YEgkwRrcT6cHVUN3bsFv38hcLv3bRw7Pcj1rlMFdWDEnUY7GsUkjbC8Y3Gtjn mUz1vjhzPePP41JwKl256m7/aLqaZIKmawNg2BZDMVh2l1NOjz6dWNAK+7SRJ7ftxQBe VT5DCt2aMZZec09LJ5gMLaPZfHEBie6Gnc4tGNtKO8hO1MZAVff5TCTVd6HNtSvih2ZN Eofpmgmtaze3XnAyYg0OC0tuVnBPyd3IWdf2GHRhnUsxZM3/nhihDvElS/0qeEV/qK8g mwjg== X-Gm-Message-State: AOJu0YwoA1AJLDh7JhVQ7gpLMUZ0UbTmjNFeuXlnINfu1HDghaPuX7XH MaSZg5vTp3ew8uSCZa3txNgbHKyWyxI3gD1nZqQiHCfvRBIYj6Xfrr5K X-Gm-Gg: ATEYQzyu1geUzGJpHTCopEA19QqC1xFxM/QAZxTxcETU5U3oGuVKBow7NpD1x0TzYYc 7VODMoJXKtNNmXL0gmy/MIrncf3/x5V2qcps+vvUquyLLj9N0Zdr0dODgjux51sKXN1FpIVjreA sGzf6200XeQ4lq7mn2Xn7KFUww9YUAm8Rts3tvcu68NfKTHpAeNHF5kiqR6NSpqsouFT01HTzWu xvhSirnpvmUYROAGt1iiV487snWcqqnyUAKTq01ObgC6qCGd5pek/jGcneJR2R9ZFP+qgwtzggn 5c31yXGKKNC895QUYyxfrICHXhtxgvmuBHpBdMaiWqNb71ZN9YDsWHTMvxtHt+uaeWREfTlB17V yMcJhkePY29Xv/5axAFmUH8zReucyvxAlhEizfyCT4LSgZksSbJJvFnaYu4PfcNpZy49irctJjQ hXCqQuhd80s7pqym+Hzg5UwBbOcIdSMnoEb4IkY29ZS1Dj/Q== X-Received: by 2002:a05:6a21:6d88:b0:398:7667:b2fb with SMTP id adf61e73a8af0-39bcf249a99mr2396537637.19.1774009011358; Fri, 20 Mar 2026 05:16:51 -0700 (PDT) Received: from localhost.localdomain ([122.171.16.15]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82b040db2fbsm2074701b3a.48.2026.03.20.05.16.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 20 Mar 2026 05:16:50 -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 v2] Add support for recording minimal symbols in AIX for non DWARF compiled library function record. Date: Fri, 20 Mar 2026 17:46:38 +0530 Message-ID: <20260320121637.91452-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 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, int g_in_lib = 777; int lib_func() { return g_in_lib + 1; } int lib_func(); int main() { printf ("lib_func() = %d \n", lib_func()); return 0; } 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 | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index aec959e1375..d02c9294be6 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,91 @@ 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 (); + long do_we_need_storage = bfd_get_symtab_upper_bound (abfd); + + if (do_we_need_storage <= 0) + return; + + gdb::unique_xmalloc_ptr sym_table + ((asymbol **) xmalloc (do_we_need_storage)); + /* Get the number of symbols we need. */ + int number_of_symbols = bfd_canonicalize_symtab (abfd, sym_table.get()); + + /* 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 = sym_table.get ()[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 +326,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); } -- 2.41.0