From: Alan Hayward <Alan.Hayward@arm.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: nd <nd@arm.com>, Alan Hayward <Alan.Hayward@arm.com>
Subject: [PATCH v2 1/3] Refactor svr4_create_solib_event_breakpoints
Date: Wed, 21 Aug 2019 15:58:00 -0000 [thread overview]
Message-ID: <20190821155816.45504-2-alan.hayward@arm.com> (raw)
In-Reply-To: <20190821155816.45504-1-alan.hayward@arm.com>
Move the bulk of svr4_create_solib_event_breakpoints into a new
function to simplify the logic. No functional changes.
gdb/ChangeLog:
2019-08-21 Alan Hayward <alan.hayward@arm.com>
* solib-svr4.c (svr4_find_and_create_probe_breakpoints): Move
code to here...
(svr4_create_solib_event_breakpoints): ...from here.
---
gdb/solib-svr4.c | 127 ++++++++++++++++++++++-------------------------
1 file changed, 60 insertions(+), 67 deletions(-)
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index c0c505acaa..b21eacb68f 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -2061,6 +2061,61 @@ svr4_create_probe_breakpoints (svr4_info *info, struct gdbarch *gdbarch,
svr4_update_solib_event_breakpoints ();
}
+/* Find all the glibc named probes. Only if all of the probes are found, then
+ create them and return true. Otherwise return false. If WITH_PREFIX is set
+ then add "rtld" to the front of the probe names. */
+static bool
+svr4_find_and_create_probe_breakpoints (svr4_info *info,
+ struct gdbarch *gdbarch,
+ struct obj_section *os,
+ bool with_prefix)
+{
+ std::vector<probe *> probes[NUM_PROBES];
+ bool checked_can_use_probe_arguments = false;
+
+ for (int i = 0; i < NUM_PROBES; i++)
+ {
+ const char *name = probe_info[i].name;
+ char buf[32];
+
+ /* Fedora 17 and Red Hat Enterprise Linux 6.2-6.4 shipped with an early
+ version of the probes code in which the probes' names were prefixed
+ with "rtld_" and the "map_failed" probe did not exist. The locations
+ of the probes are otherwise the same, so we check for probes with
+ prefixed names if probes with unprefixed names are not present. */
+ if (with_prefix)
+ {
+ xsnprintf (buf, sizeof (buf), "rtld_%s", name);
+ name = buf;
+ }
+
+ 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;
+
+ /* Ensure probe arguments can be evaluated. */
+ if (!checked_can_use_probe_arguments)
+ {
+ probe *p = probes[i][0];
+ if (!p->can_evaluate_arguments ())
+ return false;
+ checked_can_use_probe_arguments = true;
+ }
+ }
+
+ /* All probes found. Now create them. */
+ svr4_create_probe_breakpoints (info, gdbarch, probes, os->objfile);
+ return true;
+}
+
/* Both the SunOS and the SVR4 dynamic linkers call a marker function
before and after mapping and unmapping shared libraries. The sole
purpose of this method is to allow debuggers to set a breakpoint so
@@ -2077,74 +2132,12 @@ static void
svr4_create_solib_event_breakpoints (svr4_info *info, struct gdbarch *gdbarch,
CORE_ADDR address)
{
- struct obj_section *os;
-
- os = find_pc_section (address);
- if (os != NULL)
- {
- int with_prefix;
-
- for (with_prefix = 0; with_prefix <= 1; with_prefix++)
- {
- std::vector<probe *> probes[NUM_PROBES];
- int all_probes_found = 1;
- int checked_can_use_probe_arguments = 0;
-
- for (int i = 0; i < NUM_PROBES; i++)
- {
- const char *name = probe_info[i].name;
- probe *p;
- char buf[32];
-
- /* Fedora 17 and Red Hat Enterprise Linux 6.2-6.4
- shipped with an early version of the probes code in
- which the probes' names were prefixed with "rtld_"
- and the "map_failed" probe did not exist. The
- locations of the probes are otherwise the same, so
- we check for probes with prefixed names if probes
- with unprefixed names are not present. */
- if (with_prefix)
- {
- xsnprintf (buf, sizeof (buf), "rtld_%s", name);
- name = buf;
- }
-
- 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 (strcmp (name, "rtld_map_failed") == 0)
- continue;
-
- if (probes[i].empty ())
- {
- all_probes_found = 0;
- break;
- }
-
- /* Ensure probe arguments can be evaluated. */
- if (!checked_can_use_probe_arguments)
- {
- p = probes[i][0];
- if (!p->can_evaluate_arguments ())
- {
- all_probes_found = 0;
- break;
- }
- checked_can_use_probe_arguments = 1;
- }
- }
-
- if (all_probes_found)
- svr4_create_probe_breakpoints (info, gdbarch, probes, os->objfile);
-
- if (all_probes_found)
- return;
- }
- }
+ struct obj_section *os = find_pc_section (address);
- create_solib_event_breakpoint (gdbarch, address);
+ if (os == nullptr
+ || (!svr4_find_and_create_probe_breakpoints (info, gdbarch, os, false)
+ && !svr4_find_and_create_probe_breakpoints (info, gdbarch, os, true)))
+ create_solib_event_breakpoint (gdbarch, address);
}
/* Helper function for gdb_bfd_lookup_symbol. */
--
2.20.1 (Apple Git-117)
next prev parent reply other threads:[~2019-08-21 15:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-21 15:58 [PATCH v2 0/3] Fix stop-on-solib event failures Alan Hayward
2019-08-21 15:58 ` [PATCH v2 2/3] Use gdbarch for probe::get_argument_count Alan Hayward
2019-09-04 17:58 ` Sergio Durigan Junior
2019-09-04 18:00 ` Sergio Durigan Junior
2019-08-21 15:58 ` [PATCH v2 3/3] Check arguments for all probes before using them Alan Hayward
2019-08-21 15:58 ` Alan Hayward [this message]
2019-08-30 15:51 ` [PATCH v2 0/3] Fix stop-on-solib event failures Gary Benson
2019-09-02 13:20 ` Alan Hayward
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190821155816.45504-2-alan.hayward@arm.com \
--to=alan.hayward@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=nd@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox