From 79d403654266c747703359e4b4e7f3931fb53f99 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 22 Nov 2022 12:45:56 +0000 Subject: [PATCH] gdb: relax requirement for the map_failed stap probe to be present From glibc 2.35 and later, the "map_failed" stap probe is no longer included in glibc. The removal of the probe looks like an accident, but it was caused by a glibc commit which meant that the "map_failed" probe could no longer be reached; the compiler then helpfully optimised out the probe. In GDB, in solib-svr4.c, we have a list of probes that we look for related to the shared library loading detection. If any of these probes are missing then GDB will fall back to the non-probe based mechanism for detecting shared library loading. The "map_failed" probe is include in the list of required probes. This means that on glibc 2.35 (or later) systems, GDB is going to always fall back to the non-probes based mechanism for detecting shared library loading. I raised a glibc bug to discuss this issue: https://sourceware.org/bugzilla/show_bug.cgi?id=29818 But, whatever the ultimate decision from the glibc team, given there are version of glibc in the wild without the "map_failed" probe, we probably should update GDB to handle this situation. The "map_failed" probe is already a little strange, very early versions of glibc didn't include this probe, so, in some cases, if this probe is missing GDB is happy to ignore it. This is fine, the action associated with this probe inside GDB is DO_NOTHING, this means the probe isn't actually required in order for GDB to correctly detect the loading of shared libraries. In this commit I propose changing the rules so that any probe whose action is DO_NOTHING, is optional. There is one possible downside to this change, and that concerns 'set stop-on-solib-events on'. If a probe is removed from glibc, but the old style breakpoint based mechanism is still in place within glibc for that same event, then GDB will stop when using the old style non-probe based mechanism, but not when using the probes based mechanism. For the map_failed case this is not a problem, both the map_failed probe, and the call to the old style breakpoint location were optimised out, and so neither event (probes based, or breakpoint based) will trigger. This would only become an issue if glibc removed a probe, but left the breakpoint in place (this would almost certainly be a bug in glibc). For now, I'm proposing that we just don't worry about this. Because some probes have actions that are not DO_NOTHING, then we know the user will always seem _some_ stops when a shared library is loaded/unloaded, and (I'm guessing), in most cases, that's all they care about. I figure when someone complains then we can figure out what the right solution is then. With this commit in place, then, when using a glibc 2.35 or later system, GDB will once again use the stap probes for shared library detection. Reviewed-By: Lancelot SIX --- gdb/solib-svr4.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 6acaf87960b..0fe6c239c66 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -2205,15 +2205,34 @@ svr4_find_and_create_probe_breakpoints (svr4_info *info, probes[i] = find_probes_in_objfile (os->objfile, "rtld", name); - /* The "map_failed" probe did not exist in early - versions of the probes code in which the probes' - names were prefixed with "rtld_". */ - if (with_prefix && streq (name, "rtld_map_failed")) - continue; - /* Ensure at least one probe for the current name was found. */ if (probes[i].empty ()) - return false; + { + /* The "map_failed" probe did not exist in early versions of the + probes code in which the probes' names were prefixed with + "rtld_". + + Additionally, the "map_failed" probe was accidentally removed + from glibc 2.35 and 2.36, when changes in glibc meant the + probe could no longer be reached, and the compiler optimized + the probe away. In this case the probe name doesn't have the + "rtld_" prefix. + + To handle this, and give GDB as much flexibility as possible, + we make the rule that, if a probe isn't required for the + correct operation of GDB (i.e. its action is DO_NOTHING), then + we will still use the probes interface, even if that probe is + missing. + + The only (possible) downside of this is that, if the user has + 'set stop-on-solib-events on' in effect, then they might get + fewer events using the probes interface than with the classic + non-probes interface. */ + if (probe_info[i].action == DO_NOTHING) + continue; + else + return false; + } /* Ensure probe arguments can be evaluated. */ for (probe *p : probes[i]) -- 2.30.2