From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ce7TBL9QaGpKSTEAWB0awg (envelope-from ) for ; Tue, 28 Jul 2026 02:48:31 -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=Uuu2zZs8; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 104C41E09E; Tue, 28 Jul 2026 02:48:31 -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 [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 0967A1E099 for ; Tue, 28 Jul 2026 02:48:29 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80EFB4BB3B93 for ; Tue, 28 Jul 2026 06:48:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80EFB4BB3B93 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=Uuu2zZs8 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 6E6324BB24E7 for ; Tue, 28 Jul 2026 06:48:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E6324BB24E7 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 6E6324BB24E7 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785221282; cv=none; b=xK4+2jVRoy0Pta6LQ6rzXbXyGJKA7Wy6z1vAUDf45yeRQbVLgYGvlqq/BXoitCTSI5NBP+KFqDDfWVmmpRU9Yxo1hs/v19R0jhgl/p6ZgErAqGOa6xCMWn0UC0hV6qL8Dt9wINZbh31jYHJGk2LujG/Dv9+zEIyuRiMTgexK8p8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785221282; c=relaxed/simple; bh=oH42Lp+eCmsoS+wRry/J6hjLGu3E8NkRmOSKtiQJAL0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IxNK1YzkGOv/ii89guB2GzKrz8S5i6Z+cvrPEnBZq21KtnWvFlb0plUxx4PqKNT5iNDsjEdJuwD/ooHoLjTNhhkEIqlgzzoV70TQ8Rnbp9UNgi7MSilbkGchUexFpaWVinrKJbOMN6eDkP2ub8rZkLsMaHykuwGTizh5vik9JVU= 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=Uuu2zZs8 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E6324BB24E7 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2ce87c7e3bbso40474865ad.1 for ; Mon, 27 Jul 2026 23:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785221281; x=1785826081; 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=6mfZyexTd/u8zf3K6jocR1wK2Xbkub2mW9mdAvT3CcY=; b=Uuu2zZs8LXv9bvYhtKmD3bSkyrJXWlnJyUktTMQbbTSENzcsQPXgr2EnXAK1YzFkeY FxTKlr9dFMENRCQHmq+RjY0t4TMwTb3ge57URK6cUFlyHGSwxrTN1DpdtqveeUSuyn6c WXWMHc2t4a9OymQKXkfHF1bUXNzLRy/igV3eRY/tc4g2cwPUBabSSjKMZ3nj6FhoP943 i6VUgBSLa+iBv9Th9esCtXWGayto6NSGQc2Q4wYbSQlRdvSRhfEHIR+FINi7Df5wJjOA 22teXYb4z/fYO63TDTHI0E9Nhz3nXJlapLFaHpk3saA+z55/3gm+pYJIoeKmL5rRb6QV WtrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785221281; x=1785826081; 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=6mfZyexTd/u8zf3K6jocR1wK2Xbkub2mW9mdAvT3CcY=; b=nWBmsW0S+Hc//3noffQIhm41hOX2zcjKx0m3dBzAPYJnibXSq3+78G/u9Yo2/OBmwL 36a9VVe9X4v2CS0kFV6+z2OHT/NfwZYo8BPOtOzALa5rYDq3iPToqSsdSmy8Lk3iXBoL AXS8DtBgk4mbbXXRpNrK5Sl77opNyM006gwOaSyv6wie/We0jY3fjQtOJ5lFlJrZou1Z l4fcufq50RycHDuLt1PC1JEQJZcY14Otq3Bdp0Fu04DfhEASPV7nus0As1hCDTa1NjXo wjM6PJRdGqL+WHirivlM0mpyThEdLswHoTY7BKsmgaY7y87i2AvDTXxiZxS9h0CBfug7 DB5w== X-Gm-Message-State: AOJu0YykCv4d+1ANns09OifgMOcD2PU13KTCxbnOge2e4ASmw6GsvXF9 AXGL1Ojc5CV7cfZJZiIDNt4ELJqsWy1huG/q0dxWdMixEuqMkqPVwr9T X-Gm-Gg: AR+sD1355szECg2V8GS2CHUo0ZYs8Ubh3BytDUlt5f3U1l78bDtblGozlJINOwWia3b Zu9eswKXsn99mGKb4nlDUGson4aubTYRSzKvDaJdR5Enzo3i1JD5gPPPzlw7IPDR2/N3wjhoZMf lZhzlU4HIRB4x5FpisrxJP5WRl5OS+mk9BCjpq/p2NNNqhk7AJQwJ47D1ERbjMCXcDwlrf3c/15 LvNBgCVeZJwK9/9vZTPosbWAyA20d4VA6HR0IUxxbNVME8yLi6sSPhdTadiST4Bp7TZReH2R8hf qDGJaUru3Q9vh/PJ0FfRDGErbBdP08yprHGRRPx5QuMVUX1GNjDPUCpW87xjs4cXKGwokkVpn8F aOBwCyDI3XpGzQrobiKDUPJT7N2f9dD3z+CDZUDbwr+IBp2T89XDHDF/BdLUkOp9M4XK4DWxxxT osm3AKTNfb2TNzDgVvCiY+pb7DVmo9d3DTBrXTBY0= X-Received: by 2002:a05:6a20:3d07:b0:3c3:8ce8:203 with SMTP id adf61e73a8af0-3c8ba5f4ed0mr1530568637.50.1785221281177; Mon, 27 Jul 2026 23:48:01 -0700 (PDT) Received: from dhcp-9-123-6-89.bl1-in.ibm.com ([129.41.58.1]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13d6ba579c3sm32326259c88.8.2026.07.27.23.47.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 27 Jul 2026 23:48:00 -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 v6] Fix crash in AIX when current working directory is NULL Date: Tue, 28 Jul 2026 12:17:01 +0530 Message-ID: <20260728064700.6533-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 issue is seen in other targets as well. In AIX if we do not have read permission in a current directory we get, gdb ~/gdb_tests/simple_test gdb: warning: error finding working directory: A parameter must be a directory. GNU gdb (GDB) 18.0.50.20260619-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/simple_test... terminate called after throwing an instance of 'std::logic_error' what(): basic_string: construction from null is not valid Fatal signal: IOT/Abort trap ----- Backtrace ----- 0x100943f1b gdb_internal_backtrace_1 //home/binutils-gdb/gdb/bt-utils.c:122 0x100944027 _Z22gdb_internal_backtracev //home/binutils-gdb/gdb/bt-utils.c:173 0x10060faa7 handle_fatal_signal //home/binutils-gdb/gdb/event-top.c:1008 0x4fdf ??? --------------------- A fatal error internal to GDB has been detected, further debugging is not possible. GDB will now terminate. This is a bug, please report it. For instructions, see: . ============================= The reason for the same above is that in AIX, the variable current_directory in dwarf2/read.c can be NULL if getcwd () fails during GDB initialisation. When this happens the dwarf2_per_bfd construction initialisation list captured_cwd to NULL resulting in this segmentation fault shown above. There are two reasons this happened: 1: The current working directory got deleted in another terminal. 2: Insufficient permission to read the current directory or its parent/predicissor directory. This patch is a fix to the same. Afer this fix we get GDB loaded correctly. gdb ~/gdb_tests/simple_test gdb: warning: error finding working directory: A parameter must be a directory. GNU gdb (GDB) 18.0.50.20260619-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/simple_test... (gdb) q Also adding a test case for the same. The reason I could not do it in a simple exp file is AIX is protecting the currrent working directory when I try to delete. It says The requested resource is busy. So I had to write a C code the fork () and child will delete the current working directory which mimics directory deletion in another terminal. Then from here exec gdb with a binary having dwarf symbols to reproduce the crash. --- gdb/dwarf2/read.c | 9 ++- gdb/dwarf2/read.h | 7 +- gdb/testsuite/gdb.base/getcwd-fail-helper.c | 84 +++++++++++++++++++++ gdb/testsuite/gdb.base/getcwd-fail.c | 20 +++++ gdb/testsuite/gdb.base/getcwd-fail.exp | 75 ++++++++++++++++++ 5 files changed, 191 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.base/getcwd-fail-helper.c create mode 100644 gdb/testsuite/gdb.base/getcwd-fail.c create mode 100644 gdb/testsuite/gdb.base/getcwd-fail.exp diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 38c498b1901..fb22cbbf82a 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -859,7 +859,9 @@ dwarf2_per_bfd::dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names, bool can_copy_) : obfd (obfd), can_copy (can_copy_), - captured_cwd (current_directory), + captured_cwd (current_directory != nullptr + ? std::optional (current_directory) + : std::nullopt), captured_debug_dir (debug_file_directory) { if (names == NULL) @@ -6735,7 +6737,10 @@ try_open_dwop_file (dwarf2_per_bfd *per_bfd, const char *file_name, int is_dwp, gdb::unique_xmalloc_ptr absolute_name; desc = openp (search_path, flags, file_name, O_RDONLY | O_BINARY, - &absolute_name, per_bfd->captured_cwd.c_str ()); + &absolute_name, + (per_bfd->captured_cwd.has_value () + ? per_bfd->captured_cwd->c_str () + : nullptr)); if (desc < 0) return NULL; diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 15dd2abf3a1..a7c1861a64d 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -757,8 +757,11 @@ struct dwarf2_per_bfd abstract_to_concrete; /* Current directory, captured at the moment that object this was - created. */ - std::string captured_cwd; + created. If nullopt, the working directory was unavailable + which means getcwd failed either due to directory deletion or + permission issues. So paths should be treated as absolute. */ + std::optional captured_cwd; + /* Captured copy of debug_file_directory. */ std::string captured_debug_dir; }; diff --git a/gdb/testsuite/gdb.base/getcwd-fail-helper.c b/gdb/testsuite/gdb.base/getcwd-fail-helper.c new file mode 100644 index 00000000000..63ffff07a31 --- /dev/null +++ b/gdb/testsuite/gdb.base/getcwd-fail-helper.c @@ -0,0 +1,84 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Helper to reproduce getcwd failure by deleting cwd via child process. */ +#include +#include +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + const char *temp_dir = argv[1]; + const char *gdb_path = argv[2]; + + /* Create and change to temp directory. */ + if (mkdir (temp_dir, 0755) != 0) + { + perror ("mkdir failed"); + return 1; + } + + if (chdir (temp_dir) != 0) + { + perror ("chdir failed"); + return 1; + } + + /* child deletes directory, parent execs GDB. */ + pid_t pid = fork (); + if (pid < 0) + { + perror ("fork failed"); + return 1; + } + + if (pid == 0) + { + /* cd to / and delete the temp directory. */ + if (chdir ("/") != 0) + exit (1); + + if (rmdir (temp_dir) != 0) + exit (1); + + exit (0); + } + + /* wait for child to delete directory. */ + int status; + waitpid (pid, &status, 0); + + if (!WIFEXITED (status) || WEXITSTATUS (status) != 0) + { + fprintf (stderr, "Failed to delete directory\n"); + return 1; + } + + /* Exec GDB. */ + char **gdb_args = malloc ((argc - 1) * sizeof (char *)); + gdb_args[0] = (char *) gdb_path; + for (int i = 3; i < argc; i++) + gdb_args[i - 2] = argv[i]; + gdb_args[argc - 2] = NULL; + + execv (gdb_path, gdb_args); + perror ("execv failed"); + return 1; +} diff --git a/gdb/testsuite/gdb.base/getcwd-fail.c b/gdb/testsuite/gdb.base/getcwd-fail.c new file mode 100644 index 00000000000..5fecf0bbd93 --- /dev/null +++ b/gdb/testsuite/gdb.base/getcwd-fail.c @@ -0,0 +1,20 @@ + /* Copyright 2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main (void) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/getcwd-fail.exp b/gdb/testsuite/gdb.base/getcwd-fail.exp new file mode 100644 index 00000000000..3861ea7026e --- /dev/null +++ b/gdb/testsuite/gdb.base/getcwd-fail.exp @@ -0,0 +1,75 @@ +# Copyright 2026 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test GDB when current working directory has been deleted. +# Reproduces crash: getcwd() returns NULL. + +require isnative +require {!is_remote target} +require {is_any_target "*-*-linux*" "*-*-aix*"} +require allow_fork_tests + +standard_testfile .c + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug}]} { + return -1 +} + +# Compile helper program +set helper_src "${srcdir}/${subdir}/getcwd-fail-helper.c" +set helper_bin [standard_output_file "getcwd-fail-helper"] + +# Debug needs to be there so we can trigger getcwd the dwarf2/read.c code. +if {[gdb_compile $helper_src $helper_bin executable {debug}] != ""} { + untested "failed to compile helper" + return -1 +} + +set temp_dir [standard_output_file "temp_getcwd_test"] +set gdb_path [transform $GDB] + +# The test code creates temp dir, child deletes it, parent execs GDB +set test "gdb in deleted cwd" +set spawn_id [remote_spawn host "$helper_bin $temp_dir $gdb_path -nw -nx -q $binfile"] + +set crashed 0 + +remote_expect host 30 { + -re "terminate called.*logic_error.*basic_string.*construction from null" { + set crashed 1 + exp_continue + } + -re "Fatal signal.*IOT/Abort" { + set crashed 1 + exp_continue + } + -re "$gdb_prompt $" { + if {$crashed} { + fail "$test - crashed" + } else { + pass "$test" + } + } + eof { + if {$crashed} { + fail "$test - crashed with std::logic_error" + } else { + pass "$test" + } + } + timeout { + fail "$test - timeout" + } +} -- 2.51.2