[PATCH v2 27/47] gdb: revise the pid_to_exec_file target op

Tankut Baris Aktemur
2024-12-13T16:26:02Z

Some targets, such as Intel GT, do not have the notion of an exec
file. These targets may leave the pid_to_exec_file target op
unimplemented, but from GDB's point of view, this means the exec file
could not be determined, and GDB issues a warning.

Extend the meaning of the pid_to_exec_file target op, so that if the
exec file path is empty, it means that the target does not have exec
files at all. This way, GDB can omit checking the exec file while
also not issuing the warning.
---
gdb/exec.c | 6 ++++++
gdb/target.h | 3 +++
2 files changed, 9 insertions(+)

diff --git a/gdb/exec.c b/gdb/exec.c
index 82d9266b7e3669dabfe29c5362498d60be9fa6c5..e495982ca2085d6e23a13b1662f0d4e1779b5e74 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -331,6 +331,12 @@ exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty)
return;
}

+ if (*exec_file_target == '\0')
+ {
+ /* The target does not have the notion of an exec file. */
+ return;
+ }
+
gdb::unique_xmalloc_ptr<char> exec_file_host
= exec_file_find (exec_file_target, NULL);

diff --git a/gdb/target.h b/gdb/target.h
index 630944cde3a78a2fa8f2ed32282f995b66dc274a..683d786b55861193dde7f78b8225d7b20f2c0944 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2004,6 +2004,9 @@ extern gdb::array_view<const gdb_byte> target_thread_info_to_thread_handle

If the executable file cannot be determined, NULL is returned.

+ If the target does not have the notion of executable files,
+ empty string is returned.
+
Else, a pointer to a character string containing the pathname
is returned. This string should be copied into a buffer by
the client if the string will not be immediately used, or if