From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 971AB3858422; Mon, 28 Nov 2022 17:16:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 971AB3858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669655816; bh=UuxefCCEXv+/6MSC+xjJ1gP53k88Aeh8CaJdUTJ6914=; h=From:To:Subject:Date:From; b=PrFwkv9ujiqaJUzkeaPgfr7LXQjTM2l+UIvsJyPTWDmy04H7ElaV6WMuJ7Gf15eP0 K0IO+bZLlq9spZxzcp5b+0KC3B4X3fxvYTa5JSQgUP0+PsxZwlpI99R4Ntqztd1IFV s08waxdA4x6m+04bRjPJr+VntdiHu+/qu/5/8kpA= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: relax requirement for the map_failed stap probe to be present X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 149700668dca44a0f8e1b0aab1711901935c5bd8 X-Git-Newrev: 79d403654266c747703359e4b4e7f3931fb53f99 Message-Id: <20221128171656.971AB3858422@sourceware.org> Date: Mon, 28 Nov 2022 17:16:56 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D79d403654266= c747703359e4b4e7f3931fb53f99 commit 79d403654266c747703359e4b4e7f3931fb53f99 Author: Andrew Burgess Date: Tue Nov 22 12:45:56 2022 +0000 gdb: relax requirement for the map_failed stap probe to be present =20 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. =20 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. =20 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. =20 I raised a glibc bug to discuss this issue: =20 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29818 =20 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. =20 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. =20 In this commit I propose changing the rules so that any probe whose action is DO_NOTHING, is optional. =20 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. =20 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). =20 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. =20 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. =20 Reviewed-By: Lancelot SIX Diff: --- 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, =20 probes[i] =3D find_probes_in_objfile (os->objfile, "rtld", name); =20 - /* 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 =3D=3D DO_NOTHING) + continue; + else + return false; + } =20 /* Ensure probe arguments can be evaluated. */ for (probe *p : probes[i])