[PATCH v2 28/47] gdb: load solibs if the target does not have the notion of an exec file

Tankut Baris Aktemur
2024-12-13T16:27:53Z

In the 'post_create_inferior' function, the code block that calls the
solib ops' post-create-inferior hook function is guarded by a
null-check on exec_bfd. This prevents loading solibs of an inferior
if it does not have an exec_bfd. However, such a scenario could be
possible with relatively newer targets, such as GPUs, where an
executable does not exist but the GPU kernels are treated as
libraries.

Add a check for this case.
---
gdb/infcmd.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 27473123c1a0b2702b81d0b28c41931b4e39dd52..78e7bbb0de048f5973d5803731a6f01cf30047c3 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -260,7 +260,15 @@ post_create_inferior (int from_tty)
throw;
}

- if (current_program_space->exec_bfd ())
+ /* Some targets (e.g. GPUs) may still have solibs although they do
+ not have the notion of an exec file. */
+ const char *exec_file
+ = target_pid_to_exec_file (current_inferior ()->pid);
+ bool target_may_have_solibs
+ = (exec_file != nullptr && *exec_file == '\0');
+
+ if (current_program_space->exec_bfd () != nullptr
+ || target_may_have_solibs)
{
const unsigned solib_add_generation
= current_program_space->solib_add_generation;