From: Keith Seitz <keiths@redhat.com>
To: Aditya Vidyadhar Kamath <akamath996@gmail.com>
Cc: gdb-patches@sourceware.org, Aditya.Kamath1@ibm.com
Subject: Re: [PATCH] Fix crash in AIX when current working directory is NULL
Date: Tue, 23 Jun 2026 10:10:48 -0700 [thread overview]
Message-ID: <3ae0f8af-b88a-4f51-bce8-19be9b404fa0@redhat.com> (raw)
In-Reply-To: <20260622091114.18783-2-akamath996@gmail.com>
Hi,
On 6/22/26 2:11 AM, Aditya Vidyadhar Kamath wrote:
> From: Aditya Kamath <Aditya.Kamath1@ibm.com>
>
> In AIX if we cannot read in the current directory we get,
>
Thank you for the patch. I can confirm that this is independent of
architecture/OS. On x86_64 Fedora 43, we can also demonstrate the issue:
term1$ pwd
/home/keiths/tmp
term1$ mkdir gone && cd gone
term2$ rm -rf ~/tmp/gone
term1$ gdb -nx -q ~/tmp/simple
/home/keiths/gdb: ⚠️ warning: error finding working directory: No such
file or directory
Reading symbols from /home/keiths/tmp/simple...
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string: construction from null is not valid
We've seen a number of similar issues throughout the years. Is it
possible to write a test for this?
> 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.
I apologize for being pedantic, but this is more accurately described as
a (abort due to a) std::logic_error.
> 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.
Typo "predicissor". Did you mean "predecessor?"
>
> This patch is a fix to the same.
>
> Afer this fix we get GDB loaded correctly.
Typo "After"
> 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 <http://gnu.org/licenses/gpl.html>
> 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:
> <https://www.gnu.org/software/gdb/bugs/>.
>
> +------------------------------------------------------------------------------+
> | 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
> ---
> gdb/dwarf2/read.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index 84b1480dbcb..7962acc784d 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -859,7 +859,7 @@ 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 == NULL ? "" : current_directory),
Please use "nullptr" instead.
> captured_debug_dir (debug_file_directory)
> {
> if (names == NULL)
While this fix does catch this one specific place, I wonder if this bug
lurks elsewhere. For example, in main.c, when getcwd() is called and
returns NULL, gdb warns the user and leaves current_directory as NULL.
Changing that so that current_directory isn't NULL also fixes this
problem and could prevent(?) other similar problems. Of course, that
kind of change could introduce some sort of API semantic inconsistencies
with current_directory which likely would require more (invasive)
changes.
In any case, I am just asking. Your patch is simple and minimally
invasive. Nonetheless, if it is possible, I would really like a
test for this.
Keith
next prev parent reply other threads:[~2026-06-23 17:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 9:11 Aditya Vidyadhar Kamath
2026-06-23 17:10 ` Keith Seitz [this message]
2026-06-24 11:50 ` Aditya Kamath
2026-06-26 14:56 ` Tom Tromey
2026-06-29 12:35 ` Aditya Kamath
2026-06-26 16:15 ` Ulrich Weigand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3ae0f8af-b88a-4f51-bce8-19be9b404fa0@redhat.com \
--to=keiths@redhat.com \
--cc=Aditya.Kamath1@ibm.com \
--cc=akamath996@gmail.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox