RE: [PATCH v5 03/15] gdb, gdbserver: support dlmopen()

Metzger, Markus T via Gdb-patches
2022-06-27T12:56:42Z

Thanks for your review, Kevin,

>> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
>> index 6222f79a7a0..1f2abcf16ef 100644
>[...]
>> @@ -1697,17 +1872,34 @@ solist_update_incremental (struct svr4_info *info,
>CORE_ADDR lm)
>> if (!svr4_current_sos_via_xfer_libraries (&library_list, annex))
>> return 0;
>>
>> - tail->next = library_list.head;
>> + /* We expect gdbserver to provide updates for the namespace that
>> + contains LM, which whould be this namespace... */
>> + so_list *sos = nullptr;
>> + if (library_list.solib_lists.find (debug_base)
>> + != library_list.solib_lists.end ())
>> + std::swap (sos, library_list.solib_lists[debug_base]);
>> + if (sos == nullptr)
>> + {
>> + /* ...or for the special zero namespace for earlier versions... */
>> + if (library_list.solib_lists.find (0)
>> + != library_list.solib_lists.end ())
>> + std::swap (sos, library_list.solib_lists[0]);
>[...]
>
>I was puzzled for a while by the uses of std:swap() in the above
>snippets of code. I checked the rest of the GDB sources and found
>that (at least in GDB) this is not a common idiom. I'd appreciate
>it if you could add a few lines of explanation for at least one
>of them.

Do those comments help?

diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 1f2abcf16ef..b231888b001 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1346,6 +1346,10 @@ svr4_current_sos_direct (struct svr4_info *info)
&& (library_list.solib_lists[0] == nullptr))
library_list.solib_lists.erase (0);

+ /* Replace the (empty) solib_lists in INFO with the one generated
+ from the target. We don't want to copy it on assignment and then
+ delete the original afterwards, so let's just swap the
+ internals. */
std::swap (info->solib_lists, library_list.solib_lists);
return;
}
@@ -1872,7 +1876,11 @@ solist_update_incremental (svr4_info *info, CORE_ADDR debug_base,
if (!svr4_current_sos_via_xfer_libraries (&library_list, annex))
return 0;

- /* We expect gdbserver to provide updates for the namespace that
+ /* Get the so list from the target. We replace the list in the
+ target response so we can easily check that the response only
+ covers one namespace.
+
+ We expect gdbserver to provide updates for the namespace that
contains LM, which whould be this namespace... */
so_list *sos = nullptr;
if (library_list.solib_lists.find (debug_base)

>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index 6aef39e5e02..98715fdc87e 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -2451,6 +2451,102 @@ proc skip_shlib_tests {} {
>> return 1
>> }
>>
>> +# Return 1 if we should skip dlmopen tests, 0 if we should not.
>> +
>> +proc skip_dlmopen_tests {} {
>> + global srcdir subdir gdb_prompt inferior_exited_re
>> +
[...]
>> + verbose "$me: returning $skip_dlmopen_tests" 2
>> + return $skip_dlmopen_tests
>> +}
>> +
>> # Return 1 if we should skip tui related tests.
>
>I'm wondering if this can be a gdb_caching_proc? At the moment, there's
>probably not much point since I think it's only used by the new test.
>But if we end up with more tests which use it, it might be worthwhile.

Makes sense.

thanks,
markus.