From patchwork Wed Jan 13 00:34:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 10355 Received: (qmail 71055 invoked by alias); 13 Jan 2016 00:35:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 71038 invoked by uid 89); 13 Jan 2016 00:35:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.0 required=5.0 tests=BAYES_40, FILL_THIS_FORM, RP_MATCHES_RCVD, SPF_HELO_PASS, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 spammy=UD:error, sk:iterate, probes, *found X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 13 Jan 2016 00:35:01 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id D8DCA8CF4D for ; Wed, 13 Jan 2016 00:34:59 +0000 (UTC) Received: from brno.lan (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0D0Ywdg022135 for ; Tue, 12 Jan 2016 19:34:59 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Limit breakpoint re-set to the current program space Date: Wed, 13 Jan 2016 00:34:58 +0000 Message-Id: <1452645298-19600-1-git-send-email-palves@redhat.com> Currently, we always re-set all locations of all breakpoints. This commit makes us re-set only locations of the current program space. If we loaded symbols to a program space (e.g., "file" command or some shared library was loaded), GDB must run through all breakpoints and determine if any new locations need to be added to the breakpoint. However, there's no reason to recreate locations for _other_ program spaces, as those haven't changed. Similarly, when we create a new inferior, through e.g., a fork, GDB must run through all breakpoints and determine if any new locations need to be added to the breakpoint. There's a reason to destroy the locations of the parent inferior and other inferiors. We know those won't change. In addition to being inneficient, resetting breakpoints of inferiors that are currently running is problematic, because: - some targets can't read memory while the inferior is running. - the inferior might exit while we're re-setting its breakpoints, which may confuse prologue skipping. I went through all the places where we call breakpoint_re_set, and it seems to me that all can be changed to only re-set locations of the current program space. The patch that reversed threads order in "info threads" etc. happened to make gdb.threads/fork-plus-thread.exp expose this problem when testing on x86/-m32. The problem was latent and masked out by chance by the code-cache: https://sourceware.org/ml/gdb-patches/2016-01/msg00213.html Tested on x86-64 F20, native (-m64/-m32) and extended-remote gdbserver. Fixes the regression discussed in the url above with --target_board=unix/-m32: -FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: inferior 1 exited +PASS: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: inferior 1 exited -FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: no threads left (timeout) -FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: only inferior 1 left (the program exited) +PASS: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: no threads left +PASS: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: only inferior 1 left gdb/ChangeLog: 2016-01-12 Pedro Alves * ax-gdb.c (agent_command_1): Adjust call to decode_line_full. * break-catch-throw.c (re_set_exception_catchpoint): Pass the current program space down to linespec decoding and breakpoint location updating. * breakpoint.c (parse_breakpoint_sals): Adjust calls to decode_line_full. (until_break_command): Adjust calls to decode_line_1. (base_breakpoint_decode_location, bkpt_decode_location): Add 'search_pspace' parameter. Pass it along. (bkpt_probe_create_sals_from_location): Adjust calls to parse_probes. (tracepoint_decode_location, tracepoint_probe_decode_location) (strace_marker_decode_location): Add 'search_pspace' parameter. Pass it along. (all_locations_are_pending): Rewrite to take a breakpoint and program space as arguments instead. (hoist_existing_locations): New function. (update_breakpoint_locations): Add 'filter_pspace' parameter. Use hoist_existing_locations instead of always removing all locations, and adjust to all_locations_are_pending change. (location_to_sals): Add 'search_pspace' parameter. Pass it along. Don't disable the breakpoint if there are other locations in another program space. (breakpoint_re_set_default): Adjust to pass down the current program space as filter program space. (decode_location_default): Add 'search_pspace' parameter and pass it along. (prepare_re_set_context): Don't switch program space here. (breakpoint_re_set): Use save_current_space_and_thread instead of save_current_program_space. * breakpoint.h (struct breakpoint_ops) : Add 'search_pspace' parameter. (update_breakpoint_locations): Add 'filter_pspace' parameter. * cli/cli-cmds.c (edit_command, list_command): Adjust calls to decode_line_1. * elfread.c (elf_gnu_ifunc_resolver_return_stop): Pass the current program space as filter program space. * linespec.c (struct linespec_state) : New field. (create_sals_line_offset, convert_explicit_location_to_sals) (parse_linespec): Pass the search program space down. (linespec_state_constructor): Add 'search_pspace' parameter. Store it. (linespec_parser_new): Add 'search_pspace' parameter and pass it along. (linespec_lex_to_end): Adjust. (decode_line_full, decode_line_1): Add 'search_pspace' parameter and pass it along. (decode_line_with_last_displayed): Adjust. (collect_symtabs_from_filename, symtabs_from_filename): New 'search_pspace' parameter. Use it. (find_function_symbols): Pass the search program space down. * linespec.h (decode_line_1, decode_line_full): Add 'search_pspace' parameter. * probe.c (parse_probes_in_pspace): New function, factored out from ... (parse_probes): ... this. Add 'search_pspace' parameter and use it. * probe.h (parse_probes): Add pspace' parameter. * python/python.c (gdbpy_decode_line): Adjust. * tracepoint.c (scope_info): Adjust. --- gdb/ax-gdb.c | 2 +- gdb/break-catch-throw.c | 8 +-- gdb/breakpoint.c | 127 +++++++++++++++++++++++++++++++++++------------- gdb/breakpoint.h | 9 ++-- gdb/cli/cli-cmds.c | 8 +-- gdb/elfread.c | 2 +- gdb/linespec.c | 82 +++++++++++++++++++++---------- gdb/linespec.h | 5 ++ gdb/probe.c | 120 +++++++++++++++++++++++++++------------------ gdb/probe.h | 1 + gdb/python/python.c | 2 +- gdb/tracepoint.c | 2 +- 12 files changed, 247 insertions(+), 121 deletions(-) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 7f250e9..dd6eee6 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2649,7 +2649,7 @@ agent_command_1 (char *exp, int eval) init_linespec_result (&canonical); location = new_linespec_location (&exp); old_chain = make_cleanup_delete_event_location (location); - decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, + decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, (struct symtab *) NULL, 0, &canonical, NULL, NULL); make_cleanup_destroy_linespec_result (&canonical); diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c index 96d7b72..f3eec63 100644 --- a/gdb/break-catch-throw.c +++ b/gdb/break-catch-throw.c @@ -212,6 +212,7 @@ re_set_exception_catchpoint (struct breakpoint *self) struct cleanup *cleanup; enum exception_event_kind kind = classify_exception_breakpoint (self); struct event_location *location; + struct program_space *filter_pspace = current_program_space; /* We first try to use the probe interface. */ TRY @@ -219,10 +220,9 @@ re_set_exception_catchpoint (struct breakpoint *self) location = new_probe_location (exception_functions[kind].probe); cleanup = make_cleanup_delete_event_location (location); - sals = parse_probes (location, NULL); + sals = parse_probes (location, filter_pspace, NULL); do_cleanups (cleanup); } - CATCH (e, RETURN_MASK_ERROR) { /* Using the probe interface failed. Let's fallback to the normal @@ -236,7 +236,7 @@ re_set_exception_catchpoint (struct breakpoint *self) = ASTRDUP (exception_functions[kind].function); location = new_explicit_location (&explicit_loc); cleanup = make_cleanup_delete_event_location (location); - self->ops->decode_location (self, location, &sals); + self->ops->decode_location (self, location, filter_pspace, &sals); do_cleanups (cleanup); } CATCH (ex, RETURN_MASK_ERROR) @@ -251,7 +251,7 @@ re_set_exception_catchpoint (struct breakpoint *self) END_CATCH cleanup = make_cleanup (xfree, sals.sals); - update_breakpoint_locations (self, sals, sals_end); + update_breakpoint_locations (self, filter_pspace, sals, sals_end); do_cleanups (cleanup); } diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index d72021e..1396d17 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -125,6 +125,7 @@ static void create_breakpoints_sal_default (struct gdbarch *, static void decode_location_default (struct breakpoint *b, const struct event_location *location, + struct program_space *search_pspace, struct symtabs_and_lines *sals); static void clear_command (char *, int); @@ -9502,7 +9503,7 @@ parse_breakpoint_sals (const struct event_location *location, && strchr ("+-", address[0]) != NULL && address[1] != '[')) { - decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, + decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, get_last_displayed_symtab (), get_last_displayed_line (), canonical, NULL, NULL); @@ -9510,7 +9511,7 @@ parse_breakpoint_sals (const struct event_location *location, } } - decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, + decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, cursal.symtab, cursal.line, canonical, NULL, NULL); } @@ -10409,7 +10410,7 @@ break_range_command (char *arg, int from_tty) where +14 means 14 lines from the start location. */ end_location = string_to_event_location (&arg, current_language); make_cleanup_delete_event_location (end_location); - decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, + decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL, sal_start.symtab, sal_start.line, &canonical_end, NULL, NULL); @@ -11673,12 +11674,12 @@ until_break_command (char *arg, int from_tty, int anywhere) cleanup = make_cleanup_delete_event_location (location); if (last_displayed_sal_is_valid ()) - sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, + sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, get_last_displayed_symtab (), get_last_displayed_line ()); else sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, - (struct symtab *) NULL, 0); + NULL, (struct symtab *) NULL, 0); if (sals.nelts != 1) error (_("Couldn't get information on specified line.")); @@ -12978,6 +12979,7 @@ base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, static void base_breakpoint_decode_location (struct breakpoint *b, const struct event_location *location, + struct program_space *search_pspace, struct symtabs_and_lines *sals) { internal_error_pure_virtual_called (); @@ -13225,9 +13227,10 @@ bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, static void bkpt_decode_location (struct breakpoint *b, const struct event_location *location, + struct program_space *search_pspace, struct symtabs_and_lines *sals) { - decode_location_default (b, location, sals); + decode_location_default (b, location, search_pspace, sals); } /* Virtual table for internal breakpoints. */ @@ -13411,7 +13414,7 @@ bkpt_probe_create_sals_from_location (const struct event_location *location, { struct linespec_sals lsal; - lsal.sals = parse_probes (location, canonical); + lsal.sals = parse_probes (location, NULL, canonical); lsal.canonical = xstrdup (event_location_to_string (canonical->location)); VEC_safe_push (linespec_sals, canonical->sals, &lsal); } @@ -13419,9 +13422,10 @@ bkpt_probe_create_sals_from_location (const struct event_location *location, static void bkpt_probe_decode_location (struct breakpoint *b, const struct event_location *location, + struct program_space *search_pspace, struct symtabs_and_lines *sals) { - *sals = parse_probes (location, NULL); + *sals = parse_probes (location, search_pspace, NULL); if (!sals->sals) error (_("probe not found")); } @@ -13543,9 +13547,10 @@ tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, static void tracepoint_decode_location (struct breakpoint *b, const struct event_location *location, + struct program_space *search_pspace, struct symtabs_and_lines *sals) { - decode_location_default (b, location, sals); + decode_location_default (b, location, search_pspace, sals); } struct breakpoint_ops tracepoint_breakpoint_ops; @@ -13566,10 +13571,11 @@ tracepoint_probe_create_sals_from_location static void tracepoint_probe_decode_location (struct breakpoint *b, const struct event_location *location, + struct program_space *search_pspace, struct symtabs_and_lines *sals) { /* We use the same method for breakpoint on probes. */ - bkpt_probe_decode_location (b, location, sals); + bkpt_probe_decode_location (b, location, search_pspace, sals); } static struct breakpoint_ops tracepoint_probe_breakpoint_ops; @@ -13734,6 +13740,7 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, static void strace_marker_decode_location (struct breakpoint *b, const struct event_location *location, + struct program_space *search_pspace, struct symtabs_and_lines *sals) { struct tracepoint *tp = (struct tracepoint *) b; @@ -13951,11 +13958,19 @@ delete_command (char *arg, int from_tty) map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); } +/* Return true if all locations of B bound to PSPACE are pending. If + PSPACE is NULL, all locations of all program spaces are + considered. */ + static int -all_locations_are_pending (struct bp_location *loc) +all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) { - for (; loc; loc = loc->next) - if (!loc->shlib_disabled + struct bp_location *loc; + + for (loc = b->loc; loc != NULL; loc = loc->next) + if ((pspace == NULL + || loc->pspace == pspace) + && !loc->shlib_disabled && !loc->pspace->executing_startup) return 0; return 1; @@ -14160,17 +14175,58 @@ locations_are_equal (struct bp_location *a, struct bp_location *b) return 1; } -/* Create new breakpoint locations for B (a hardware or software breakpoint) - based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is - a ranged breakpoint. */ +/* Split all locations of B that are bound to PSPACE out of B's + location list to a separate list and return that list's head. If + PSPACE is NULL, hoist out all locations of B. */ + +static struct bp_location * +hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) +{ + struct bp_location head; + struct bp_location *i = b->loc; + struct bp_location **i_link = &b->loc; + struct bp_location *hoisted = &head; + + if (pspace == NULL) + { + i = b->loc; + b->loc = NULL; + return i; + } + + head.next = NULL; + + while (i != NULL) + { + if (i->pspace == pspace) + { + *i_link = i->next; + i->next = NULL; + hoisted->next = i; + hoisted = i; + } + else + i_link = &i->next; + i = *i_link; + } + + return head.next; +} + +/* Create new breakpoint locations for B (a hardware or software + breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not + zero, then B is a ranged breakpoint. Only recreates locations for + FILTER_PSPACE. Locations of other program spaces are left + untouched. */ void update_breakpoint_locations (struct breakpoint *b, + struct program_space *filter_pspace, struct symtabs_and_lines sals, struct symtabs_and_lines sals_end) { int i; - struct bp_location *existing_locations = b->loc; + struct bp_location *existing_locations; if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) { @@ -14190,10 +14246,10 @@ update_breakpoint_locations (struct breakpoint *b, We'd like to retain the location, so that when the library is loaded again, we don't loose the enabled/disabled status of the individual locations. */ - if (all_locations_are_pending (existing_locations) && sals.nelts == 0) + if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) return; - b->loc = NULL; + existing_locations = hoist_existing_locations (b, filter_pspace); for (i = 0; i < sals.nelts; ++i) { @@ -14284,7 +14340,7 @@ update_breakpoint_locations (struct breakpoint *b, static struct symtabs_and_lines location_to_sals (struct breakpoint *b, struct event_location *location, - int *found) + struct program_space *search_pspace, int *found) { struct symtabs_and_lines sals = {0}; struct gdb_exception exception = exception_none; @@ -14293,7 +14349,7 @@ location_to_sals (struct breakpoint *b, struct event_location *location, TRY { - b->ops->decode_location (b, location, &sals); + b->ops->decode_location (b, location, search_pspace, &sals); } CATCH (e, RETURN_MASK_ERROR) { @@ -14309,7 +14365,10 @@ location_to_sals (struct breakpoint *b, struct event_location *location, breakpoint being disabled, and don't want to see more errors. */ if (e.error == NOT_FOUND_ERROR - && (b->condition_not_parsed + && (b->condition_not_parsed + || (b->loc != NULL + && search_pspace != NULL + && b->loc->pspace != search_pspace) || (b->loc && b->loc->shlib_disabled) || (b->loc && b->loc->pspace->executing_startup) || b->enable_state == bp_disabled)) @@ -14378,8 +14437,9 @@ breakpoint_re_set_default (struct breakpoint *b) struct symtabs_and_lines sals, sals_end; struct symtabs_and_lines expanded = {0}; struct symtabs_and_lines expanded_end = {0}; + struct program_space *filter_pspace = current_program_space; - sals = location_to_sals (b, b->location, &found); + sals = location_to_sals (b, b->location, filter_pspace, &found); if (found) { make_cleanup (xfree, sals.sals); @@ -14388,7 +14448,8 @@ breakpoint_re_set_default (struct breakpoint *b) if (b->location_range_end != NULL) { - sals_end = location_to_sals (b, b->location_range_end, &found); + sals_end = location_to_sals (b, b->location_range_end, + filter_pspace, &found); if (found) { make_cleanup (xfree, sals_end.sals); @@ -14396,7 +14457,7 @@ breakpoint_re_set_default (struct breakpoint *b) } } - update_breakpoint_locations (b, expanded, expanded_end); + update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); } /* Default method for creating SALs from an address string. It basically @@ -14440,12 +14501,13 @@ create_breakpoints_sal_default (struct gdbarch *gdbarch, static void decode_location_default (struct breakpoint *b, const struct event_location *location, + struct program_space *search_pspace, struct symtabs_and_lines *sals) { struct linespec_result canonical; init_linespec_result (&canonical); - decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, + decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, (struct symtab *) NULL, 0, &canonical, multiple_symbols_all, b->filter); @@ -14472,15 +14534,10 @@ decode_location_default (struct breakpoint *b, static struct cleanup * prepare_re_set_context (struct breakpoint *b) { - struct cleanup *cleanups; - input_radix = b->input_radix; - cleanups = save_current_space_and_thread (); - if (b->pspace != NULL) - switch_to_program_space_and_thread (b->pspace); set_language (b->language); - return cleanups; + return make_cleanup (null_cleanup, NULL); } /* Reset a breakpoint given it's struct breakpoint * BINT. @@ -14500,7 +14557,9 @@ breakpoint_re_set_one (void *bint) return 0; } -/* Re-set all breakpoints after symbols have been re-loaded. */ +/* Re-set breakpoint locations for the current program space. + Locations bound to other program spaces are left untouched. */ + void breakpoint_re_set (void) { @@ -14511,7 +14570,7 @@ breakpoint_re_set (void) save_language = current_language->la_language; save_input_radix = input_radix; - old_chain = save_current_program_space (); + old_chain = save_current_space_and_thread (); ALL_BREAKPOINTS_SAFE (b, b_tmp) { diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index e76bdab..c1dc6f8 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -599,13 +599,15 @@ struct breakpoint_ops int, const struct breakpoint_ops *, int, int, int, unsigned); - /* Given the location (second parameter), this method decodes it - and provides the SAL locations related to it. For ordinary breakpoints, - it calls `decode_line_full'. + /* Given the location (second parameter), this method decodes it and + provides the SAL locations related to it. For ordinary + breakpoints, it calls `decode_line_full'. If SEARCH_PSPACE is + not NULL, symbol search is restricted to just that program space. This function is called inside `location_to_sals'. */ void (*decode_location) (struct breakpoint *b, const struct event_location *location, + struct program_space *search_pspace, struct symtabs_and_lines *sals); /* Return true if this breakpoint explains a signal. See @@ -1200,6 +1202,7 @@ extern void init_bp_location (struct bp_location *loc, struct breakpoint *owner); extern void update_breakpoint_locations (struct breakpoint *b, + struct program_space *filter_pspace, struct symtabs_and_lines sals, struct symtabs_and_lines sals_end); diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index b871a88..ede4909 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -818,7 +818,7 @@ edit_command (char *arg, int from_tty) arg1 = arg; location = string_to_event_location (&arg1, current_language); cleanup = make_cleanup_delete_event_location (location); - sals = decode_line_1 (location, DECODE_LINE_LIST_MODE, 0, 0); + sals = decode_line_1 (location, DECODE_LINE_LIST_MODE, NULL, NULL, 0); filter_sals (&sals); if (! sals.nelts) @@ -971,7 +971,7 @@ list_command (char *arg, int from_tty) location = string_to_event_location (&arg1, current_language); make_cleanup_delete_event_location (location); - sals = decode_line_1 (location, DECODE_LINE_LIST_MODE, 0, 0); + sals = decode_line_1 (location, DECODE_LINE_LIST_MODE, NULL, NULL, 0); filter_sals (&sals); if (!sals.nelts) @@ -1015,10 +1015,10 @@ list_command (char *arg, int from_tty) make_cleanup_delete_event_location (location); if (dummy_beg) sals_end = decode_line_1 (location, - DECODE_LINE_LIST_MODE, 0, 0); + DECODE_LINE_LIST_MODE, NULL, NULL, 0); else sals_end = decode_line_1 (location, DECODE_LINE_LIST_MODE, - sal.symtab, sal.line); + NULL, sal.symtab, sal.line); filter_sals (&sals_end); if (sals_end.nelts == 0) diff --git a/gdb/elfread.c b/gdb/elfread.c index 1eb341b..f666db6 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -1006,7 +1006,7 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b) sals_end.nelts = 0; b->type = bp_breakpoint; - update_breakpoint_locations (b, sals, sals_end); + update_breakpoint_locations (b, current_program_space, sals, sals_end); } /* A helper function for elf_symfile_read that reads the minimal diff --git a/gdb/linespec.c b/gdb/linespec.c index 50951bd..588ad83 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -123,6 +123,10 @@ struct linespec_state /* The program space as seen when the module was entered. */ struct program_space *program_space; + /* If not NULL, the search is restricted to just this program + space. */ + struct program_space *search_pspace; + /* The default symtab to use, if no other symtab is specified. */ struct symtab *default_symtab; @@ -274,7 +278,8 @@ static struct symtabs_and_lines decode_objc (struct linespec_state *self, linespec_p ls, const char *arg); -static VEC (symtab_ptr) *symtabs_from_filename (const char *); +static VEC (symtab_ptr) *symtabs_from_filename (const char *, + struct program_space *pspace); static VEC (symbolp) *find_label_symbols (struct linespec_state *self, VEC (symbolp) *function_symbols, @@ -302,7 +307,9 @@ static void add_all_symbol_names_from_pspace (struct collect_info *info, struct program_space *pspace, VEC (const_char_ptr) *names); -static VEC (symtab_ptr) *collect_symtabs_from_filename (const char *file); +static VEC (symtab_ptr) * + collect_symtabs_from_filename (const char *file, + struct program_space *pspace); static void decode_digits_ordinary (struct linespec_state *self, linespec_p ls, @@ -1842,7 +1849,8 @@ create_sals_line_offset (struct linespec_state *self, fullname = symtab_to_fullname (self->default_symtab); VEC_pop (symtab_ptr, ls->file_symtabs); VEC_free (symtab_ptr, ls->file_symtabs); - ls->file_symtabs = collect_symtabs_from_filename (fullname); + ls->file_symtabs = collect_symtabs_from_filename (fullname, + self->search_pspace); use_default = 1; } @@ -2094,7 +2102,8 @@ convert_explicit_location_to_sals (struct linespec_state *self, TRY { result->file_symtabs - = symtabs_from_filename (explicit_loc->source_filename); + = symtabs_from_filename (explicit_loc->source_filename, + self->search_pspace); } CATCH (except, RETURN_MASK_ERROR) { @@ -2285,7 +2294,8 @@ parse_linespec (linespec_parser *parser, const char *arg) TRY { PARSER_RESULT (parser)->file_symtabs - = symtabs_from_filename (user_filename); + = symtabs_from_filename (user_filename, + PARSER_STATE (parser)->search_pspace); } CATCH (ex, RETURN_MASK_ERROR) { @@ -2367,6 +2377,7 @@ parse_linespec (linespec_parser *parser, const char *arg) static void linespec_state_constructor (struct linespec_state *self, int flags, const struct language_defn *language, + struct program_space *search_pspace, struct symtab *default_symtab, int default_line, struct linespec_result *canonical) @@ -2375,6 +2386,7 @@ linespec_state_constructor (struct linespec_state *self, self->language = language; self->funfirstline = (flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0; self->list_mode = (flags & DECODE_LINE_LIST_MODE) ? 1 : 0; + self->search_pspace = search_pspace; self->default_symtab = default_symtab; self->default_line = default_line; self->canonical = canonical; @@ -2389,6 +2401,7 @@ linespec_state_constructor (struct linespec_state *self, static void linespec_parser_new (linespec_parser *parser, int flags, const struct language_defn *language, + struct program_space *search_pspace, struct symtab *default_symtab, int default_line, struct linespec_result *canonical) @@ -2398,6 +2411,7 @@ linespec_parser_new (linespec_parser *parser, memset (PARSER_RESULT (parser), 0, sizeof (struct linespec)); PARSER_EXPLICIT (parser)->line_offset.sign = LINE_OFFSET_UNKNOWN; linespec_state_constructor (PARSER_STATE (parser), flags, language, + search_pspace, default_symtab, default_line, canonical); } @@ -2451,7 +2465,7 @@ linespec_lex_to_end (char **stringp) if (stringp == NULL || *stringp == NULL) return; - linespec_parser_new (&parser, 0, current_language, NULL, 0, NULL); + linespec_parser_new (&parser, 0, current_language, NULL, NULL, 0, NULL); cleanup = make_cleanup (linespec_parser_delete, &parser); parser.lexer.saved_arg = *stringp; PARSER_STREAM (&parser) = orig = *stringp; @@ -2530,6 +2544,7 @@ event_location_to_sals (linespec_parser *parser, void decode_line_full (const struct event_location *location, int flags, + struct program_space *search_pspace, struct symtab *default_symtab, int default_line, struct linespec_result *canonical, const char *select_mode, @@ -2550,7 +2565,8 @@ decode_line_full (const struct event_location *location, int flags, || select_mode == multiple_symbols_cancel); gdb_assert ((flags & DECODE_LINE_LIST_MODE) == 0); - linespec_parser_new (&parser, flags, current_language, default_symtab, + linespec_parser_new (&parser, flags, current_language, + search_pspace, default_symtab, default_line, canonical); cleanups = make_cleanup (linespec_parser_delete, &parser); save_current_program_space (); @@ -2603,6 +2619,7 @@ decode_line_full (const struct event_location *location, int flags, struct symtabs_and_lines decode_line_1 (const struct event_location *location, int flags, + struct program_space *search_pspace, struct symtab *default_symtab, int default_line) { @@ -2610,7 +2627,8 @@ decode_line_1 (const struct event_location *location, int flags, linespec_parser parser; struct cleanup *cleanups; - linespec_parser_new (&parser, flags, current_language, default_symtab, + linespec_parser_new (&parser, flags, current_language, + search_pspace, default_symtab, default_line, NULL); cleanups = make_cleanup (linespec_parser_delete, &parser); save_current_program_space (); @@ -2640,7 +2658,7 @@ decode_line_with_current_source (char *string, int flags) location = string_to_event_location (&string, current_language); cleanup = make_cleanup_delete_event_location (location); - sals = decode_line_1 (location, flags, + sals = decode_line_1 (location, flags, NULL, cursal.symtab, cursal.line); if (*string) @@ -2665,11 +2683,11 @@ decode_line_with_last_displayed (char *string, int flags) location = string_to_event_location (&string, current_language); cleanup = make_cleanup_delete_event_location (location); if (last_displayed_sal_is_valid ()) - sals = decode_line_1 (location, flags, + sals = decode_line_1 (location, flags, NULL, get_last_displayed_symtab (), get_last_displayed_line ()); else - sals = decode_line_1 (location, flags, (struct symtab *) NULL, 0); + sals = decode_line_1 (location, flags, NULL, (struct symtab *) NULL, 0); if (*string) error (_("Junk at end of line specification: %s"), string); @@ -3117,10 +3135,13 @@ add_symtabs_to_list (struct symtab *symtab, void *d) return 0; } -/* Given a file name, return a VEC of all matching symtabs. */ +/* Given a file name, return a VEC of all matching symtabs. If + SEARCH_PSPACE is not NULL, the search is restricted to just that + program space. */ static VEC (symtab_ptr) * -collect_symtabs_from_filename (const char *file) +collect_symtabs_from_filename (const char *file, + struct program_space *search_pspace) { struct symtab_collector collector; struct cleanup *cleanups; @@ -3132,27 +3153,37 @@ collect_symtabs_from_filename (const char *file) cleanups = make_cleanup_htab_delete (collector.symtab_table); /* Find that file's data. */ - ALL_PSPACES (pspace) - { - if (pspace->executing_startup) - continue; + if (search_pspace == NULL) + { + ALL_PSPACES (pspace) + { + if (pspace->executing_startup) + continue; - set_current_program_space (pspace); - iterate_over_symtabs (file, add_symtabs_to_list, &collector); - } + set_current_program_space (pspace); + iterate_over_symtabs (file, add_symtabs_to_list, &collector); + } + } + else + { + set_current_program_space (search_pspace); + iterate_over_symtabs (file, add_symtabs_to_list, &collector); + } do_cleanups (cleanups); return collector.symtabs; } -/* Return all the symtabs associated to the FILENAME. */ +/* Return all the symtabs associated to the FILENAME. If SEARCH_PSPACE is + not NULL, the search is restricted to just that program space. */ static VEC (symtab_ptr) * -symtabs_from_filename (const char *filename) +symtabs_from_filename (const char *filename, + struct program_space *search_pspace) { VEC (symtab_ptr) *result; - result = collect_symtabs_from_filename (filename); + result = collect_symtabs_from_filename (filename, search_pspace); if (VEC_empty (symtab_ptr, result)) { @@ -3189,9 +3220,10 @@ find_function_symbols (struct linespec_state *state, /* Try NAME as an Objective-C selector. */ find_imps (name, &symbol_names); if (!VEC_empty (const_char_ptr, symbol_names)) - add_all_symbol_names_from_pspace (&info, NULL, symbol_names); + add_all_symbol_names_from_pspace (&info, state->search_pspace, + symbol_names); else - add_matching_symbols_to_info (name, &info, NULL); + add_matching_symbols_to_info (name, &info, state->search_pspace); do_cleanups (cleanup); diff --git a/gdb/linespec.h b/gdb/linespec.h index 3255d15..b802612 100644 --- a/gdb/linespec.h +++ b/gdb/linespec.h @@ -97,6 +97,7 @@ extern struct cleanup * extern struct symtabs_and_lines decode_line_1 (const struct event_location *location, int flags, + struct program_space *search_pspace, struct symtab *default_symtab, int default_line); /* Parse LOCATION and return results. This is the "full" @@ -106,6 +107,9 @@ extern struct symtabs_and_lines For FLAGS, see decode_line_flags. DECODE_LINE_LIST_MODE is not valid for this function. + If SEARCH_PSPACE is not NULL, symbol search is restricted to just + that program space. + DEFAULT_SYMTAB and DEFAULT_LINE describe the default location. DEFAULT_SYMTAB can be NULL, in which case the current symtab and line are used. @@ -136,6 +140,7 @@ extern struct symtabs_and_lines filtered out. */ extern void decode_line_full (const struct event_location *location, int flags, + struct program_space *search_pspace, struct symtab *default_symtab, int default_line, struct linespec_result *canonical, const char *select_mode, diff --git a/gdb/probe.c b/gdb/probe.c index 374e7a7..56f93da 100644 --- a/gdb/probe.c +++ b/gdb/probe.c @@ -41,18 +41,77 @@ DEF_VEC_O (bound_probe_s); +/* A helper for parse_probes that decodes a probe specification in + SEARCH_PSPACE. It appends matching SALs to RESULT. */ + +static void +parse_probes_in_pspace (const struct probe_ops *probe_ops, + struct program_space *search_pspace, + const char *objfile_namestr, + const char *provider, + const char *name, + struct symtabs_and_lines *result) +{ + struct objfile *objfile; + + ALL_PSPACE_OBJFILES (search_pspace, objfile) + { + VEC (probe_p) *probes; + struct probe *probe; + int ix; + + if (!objfile->sf || !objfile->sf->sym_probe_fns) + continue; + + if (objfile_namestr + && FILENAME_CMP (objfile_name (objfile), objfile_namestr) != 0 + && FILENAME_CMP (lbasename (objfile_name (objfile)), + objfile_namestr) != 0) + continue; + + probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); + + for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) + { + struct symtab_and_line *sal; + + if (probe_ops != &probe_ops_any && probe->pops != probe_ops) + continue; + + if (provider && strcmp (probe->provider, provider) != 0) + continue; + + if (strcmp (probe->name, name) != 0) + continue; + + ++result->nelts; + result->sals = XRESIZEVEC (struct symtab_and_line, result->sals, + result->nelts); + sal = &result->sals[result->nelts - 1]; + + init_sal (sal); + + sal->pc = get_probe_address (probe, objfile); + sal->explicit_pc = 1; + sal->section = find_pc_overlay (sal->pc); + sal->pspace = search_pspace; + sal->probe = probe; + sal->objfile = objfile; + } + } +} + /* See definition in probe.h. */ struct symtabs_and_lines parse_probes (const struct event_location *location, + struct program_space *search_pspace, struct linespec_result *canonical) { char *arg_end, *arg; char *objfile_namestr = NULL, *provider = NULL, *name, *p; struct cleanup *cleanup; struct symtabs_and_lines result; - struct objfile *objfile; - struct program_space *pspace; const struct probe_ops *probe_ops; const char *arg_start, *cs; @@ -114,52 +173,19 @@ parse_probes (const struct event_location *location, if (objfile_namestr && *objfile_namestr == '\0') error (_("invalid objfile name")); - ALL_PSPACES (pspace) - ALL_PSPACE_OBJFILES (pspace, objfile) - { - VEC (probe_p) *probes; - struct probe *probe; - int ix; - - if (!objfile->sf || !objfile->sf->sym_probe_fns) - continue; - - if (objfile_namestr - && FILENAME_CMP (objfile_name (objfile), objfile_namestr) != 0 - && FILENAME_CMP (lbasename (objfile_name (objfile)), - objfile_namestr) != 0) - continue; - - probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); - - for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) - { - struct symtab_and_line *sal; - - if (probe_ops != &probe_ops_any && probe->pops != probe_ops) - continue; - - if (provider && strcmp (probe->provider, provider) != 0) - continue; - - if (strcmp (probe->name, name) != 0) - continue; - - ++result.nelts; - result.sals = XRESIZEVEC (struct symtab_and_line, result.sals, - result.nelts); - sal = &result.sals[result.nelts - 1]; - - init_sal (sal); + if (search_pspace != NULL) + { + parse_probes_in_pspace (probe_ops, search_pspace, objfile_namestr, + provider, name, &result); + } + else + { + struct program_space *pspace; - sal->pc = get_probe_address (probe, objfile); - sal->explicit_pc = 1; - sal->section = find_pc_overlay (sal->pc); - sal->pspace = pspace; - sal->probe = probe; - sal->objfile = objfile; - } - } + ALL_PSPACES (pspace) + parse_probes_in_pspace (probe_ops, pspace, objfile_namestr, + provider, name, &result); + } if (result.nelts == 0) { diff --git a/gdb/probe.h b/gdb/probe.h index 444b239..1e15328 100644 --- a/gdb/probe.h +++ b/gdb/probe.h @@ -228,6 +228,7 @@ struct bound_probe symtabs_and_lines object and updates LOC or throws an error. */ extern struct symtabs_and_lines parse_probes (const struct event_location *loc, + struct program_space *pspace, struct linespec_result *canon); /* Helper function to register the proper probe_ops to a newly created probe. diff --git a/gdb/python/python.c b/gdb/python/python.c index 69d8b0d..7202105 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -748,7 +748,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args) TRY { if (location != NULL) - sals = decode_line_1 (location, 0, 0, 0); + sals = decode_line_1 (location, 0, NULL, NULL, 0); else { set_default_source_symtab_and_line (); diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 55b2e8e..bc45470 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -2720,7 +2720,7 @@ scope_info (char *args, int from_tty) location = string_to_event_location (&args, current_language); back_to = make_cleanup_delete_event_location (location); - sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, 0); + sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, NULL, 0); if (sals.nelts == 0) { /* Presumably decode_line_1 has already warned. */