diff options
author | Alan Hayward <alan.hayward@arm.com> | 2019-08-21 15:05:40 +0100 |
---|---|---|
committer | Alan Hayward <alan.hayward@arm.com> | 2019-09-02 13:57:12 +0100 |
commit | e661ef01e50a2cb38c006b0fe444a1b41bfc9400 (patch) | |
tree | 4710fe6531d6c47170ec76810117b8d1096ce70f /gdb | |
parent | 217d2eaa69c2a5d58cdfd11619c4f2e41c986826 (diff) | |
download | gdb-e661ef01e50a2cb38c006b0fe444a1b41bfc9400.zip gdb-e661ef01e50a2cb38c006b0fe444a1b41bfc9400.tar.gz gdb-e661ef01e50a2cb38c006b0fe444a1b41bfc9400.tar.bz2 |
Refactor svr4_create_solib_event_breakpoints
Move the bulk of svr4_create_solib_event_breakpoints into a new
function to simplify the logic. No functional changes.
gdb/ChangeLog:
* solib-svr4.c (svr4_find_and_create_probe_breakpoints): Move
code to here...
(svr4_create_solib_event_breakpoints): ...from here.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/solib-svr4.c | 127 |
2 files changed, 66 insertions, 67 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ebcfae1..e35ff66 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-09-02 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. + 2019-08-30 Sergio Durigan Junior <sergiodj@redhat.com> * nat/fork-inferior.c (trace_start_error): Remove "\nError: " diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index c0c505a..b21eacb 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. */ |