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

From: Stefan Kangas <[email-masked]>
Date: Sat, 12 Nov 2022 20:32:34 -0800

Eli Zaretskii <[email-masked]> writes:

>> > AFAIU, if you run the debugger like this:
>> >
>> >   gdb --fullname python3 core.sfmviz.py.1807941
>> >
>> > then GUD will not change the default-directory to /usr/bin, which I
>> > believe is what you want.  GDB will then locate the Python executable
>> > either in the current default-directory or by searching PATH.
>>
>> OK. It's documented, but it's still not good. What if the executable
>> wasn't in the $PATH?
>
> Is that what happens in your case?
>
> In general, you need in that case to change to the directory of the
> executable, and invoke gud-gdb from there.
>
> IME, the current behavior covers most of the use cases: either you are
> debugging a program you are developing from its source tree, or you
> are debugging an installed program that's on PATH.
>
>> It's also really unintuitive to have an implicit change of directory
>> here, and it would match most people's expectations if it was changed, I
>> think. Do you know why we're doing that?
>
> If you think about that, it's actually quite natural: it makes the
> files you are likely to access from the debug session appear in the
> current directory.

I think Eli is right here.

> In any case, this is a long-standing behavior.

Indeed.  So any change would also need to be careful not to break
backwards-compatibility in relevant cases.

At the same time, users might not expect the change of directory to
depend on whether or not she says "python3" or "/usr/bin/python3".  So
to avoid just wontfixing this outright, here are some alternative ideas:

- Perhaps we could skip changing the directory if the prefix (in the
  above case "/usr/bin") is already in PATH?

- But that won't take care of the case where it is *not* in PATH.  So
  perhaps we should have even more heuristics to also see if it is some
  interpreter (under the assumption that interpreters generally don't
  live together with the source code that is being debugged)?

  IOW, if --fullname is some well-known value like "python3", we don't
  change directory by default.  We would need to consider if such a
  change would break anything for relevant use-cases, of course.

That's the best I could think of, at least.  If that is overcomplicating
things, I guess we will have to close this bug as wontfix, as
unsatisfying as that seems.