Subject: bug#58826: 29.0.50; gud-gdb can't find core file if executable is in a different directory

From: Eli Zaretskii <[email-masked]>
Date: Fri, 18 Nov 2022 10:23:04 +0200

> From: Richard Stallman <[email-masked]>
> Cc: [email-masked], [email-masked],
> 	[email-masked]
> Date: Fri, 18 Nov 2022 00:05:47 -0500
> 
> There are supposed to be GDB options it can specify on startup to get
> the right behavior from GDB.  Is there some such option that is
> missing from GDB?

No.  GDB behaves correctly and as expected.  The issue is with GUD,
specifically how GUD sets the default-directory of the buffer through
which the user interacts with GDB.

Here's the doc string which describes this subtlety:

  (defun gud-gdb (command-line)
    "Run gdb passing it COMMAND-LINE as arguments.
  If COMMAND-LINE names a program FILE to debug, gdb will run in
  a buffer named *gud-FILE*, and the directory containing FILE
  becomes the initial working directory and source-file directory
  for your debugger.  If you don't want `default-directory' to
  change to the directory of FILE, specify FILE without leading
  directories, in which case FILE should reside either in the
  directory of the buffer from which this command is invoked, or
  it can be found by searching PATH.

The above means that the default-directory of the *gud-FILE* buffer
will be different depending on whether at gud-gdb's prompt you type
the GDB command with the program to debug in its absolute file-name
form:

   gdb ... /foo/bar/baz ...

or you type

   gdb ... baz ...

and let GDB find 'baz' by searching PATH.