diff options
Diffstat (limited to 'gdb/linespec.c')
-rw-r--r-- | gdb/linespec.c | 141 |
1 files changed, 90 insertions, 51 deletions
diff --git a/gdb/linespec.c b/gdb/linespec.c index 7a1fbc2..d525626 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -23,7 +23,6 @@ #include "symfile.h" #include "objfiles.h" #include "source.h" -#include "demangle.h" #include "value.h" #include "completer.h" #include "cp-abi.h" @@ -34,7 +33,6 @@ #include "linespec.h" #include "language.h" #include "interps.h" -#include "mi/mi-cmds.h" #include "target.h" #include "arch-utils.h" #include <ctype.h> @@ -1156,7 +1154,7 @@ iterate_over_all_matching_symtabs set_current_program_space (pspace); - for (objfile *objfile : current_program_space->objfiles ()) + for (objfile *objfile : pspace->objfiles ()) { objfile->expand_symtabs_matching (NULL, &lookup_name, NULL, NULL, (SEARCH_GLOBAL_BLOCK @@ -1544,15 +1542,15 @@ decode_line_2 (struct linespec_state *self, /* Throw an appropriate error when SYMBOL is not found (optionally in FILENAME). */ -static void ATTRIBUTE_NORETURN +[[noreturn]] static void symbol_not_found_error (const char *symbol, const char *filename) { if (symbol == NULL) symbol = ""; - if (!have_full_symbols () - && !have_partial_symbols () - && !have_minimal_symbols ()) + if (!have_full_symbols (current_program_space) + && !have_partial_symbols (current_program_space) + && !have_minimal_symbols (current_program_space)) throw_error (NOT_FOUND_ERROR, _("No symbol table is loaded. Use the \"file\" command.")); @@ -1586,7 +1584,7 @@ symbol_not_found_error (const char *symbol, const char *filename) /* Throw an appropriate error when an unexpected token is encountered in the input. */ -static void ATTRIBUTE_NORETURN +[[noreturn]] static void unexpected_linespec_error (linespec_parser *parser) { linespec_token token; @@ -1613,7 +1611,7 @@ unexpected_linespec_error (linespec_parser *parser) /* Throw an undefined label error. */ -static void ATTRIBUTE_NORETURN +[[noreturn]] static void undefined_label_error (const char *function, const char *label) { if (function != NULL) @@ -1628,7 +1626,7 @@ undefined_label_error (const char *function, const char *label) /* Throw a source file not found error. */ -static void ATTRIBUTE_NORETURN +[[noreturn]] static void source_file_not_found_error (const char *name) { throw_error (NOT_FOUND_ERROR, _("No source file named %s."), name); @@ -2069,12 +2067,19 @@ create_sals_line_offset (struct linespec_state *self, const linetable_entry *best_entry = NULL; int i, j; + /* True if the provided line gave an exact match. False if we had to + search for the next following line with code. */ + bool was_exact = true; + std::vector<symtab_and_line> intermediate_results = decode_digits_ordinary (self, ls, val.line, &best_entry); if (intermediate_results.empty () && best_entry != NULL) - intermediate_results = decode_digits_ordinary (self, ls, - best_entry->line, - &best_entry); + { + was_exact = false; + intermediate_results = decode_digits_ordinary (self, ls, + best_entry->line, + &best_entry); + } /* For optimized code, the compiler can scatter one source line across disjoint ranges of PC values, even when no duplicate @@ -2117,11 +2122,45 @@ create_sals_line_offset (struct linespec_state *self, struct symbol *sym = (blocks[i] ? blocks[i]->containing_function () : NULL); + symtab_and_line &sal = intermediate_results[i]; + + /* Don't consider a match if: + + - the provided line did not give an exact match (so we + started looking for lines below until we found one with + code associated to it) + - the found location is exactly the start of a function + - the provided line is above the declaration line of the + function + + Consider the following source: + + 10 } // end of a previous function + 11 + 12 int + 13 main (void) + 14 { + 15 int i = 1; + 16 + 17 return 0; + 18 } + + The intent of this heuristic is that a breakpoint requested on + line 11 and 12 will not result in a breakpoint on main, but a + breakpoint on line 13 will. A breakpoint requested on the empty + line 16 will also result in a breakpoint in main, at line 17. */ + if (!was_exact + && sym != nullptr + && sym->aclass () == LOC_BLOCK + && sal.pc == sym->value_block ()->entry_pc () + && val.line < sym->line ()) + continue; if (self->funfirstline) - skip_prologue_sal (&intermediate_results[i]); - intermediate_results[i].symbol = sym; - add_sal_to_sals (self, &values, &intermediate_results[i], + skip_prologue_sal (&sal); + + sal.symbol = sym; + add_sal_to_sals (self, &values, &sal, sym ? sym->natural_name () : NULL, 0); } } @@ -2129,10 +2168,12 @@ create_sals_line_offset (struct linespec_state *self, if (values.empty ()) { if (ls->explicit_loc.source_filename) - throw_error (NOT_FOUND_ERROR, _("No line %d in file \"%s\"."), + throw_error (NOT_FOUND_ERROR, + _("No compiled code for line %d in file \"%s\"."), val.line, ls->explicit_loc.source_filename.get ()); else - throw_error (NOT_FOUND_ERROR, _("No line %d in the current file."), + throw_error (NOT_FOUND_ERROR, + _("No compiled code for line %d in the current file."), val.line); } @@ -2172,7 +2213,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls) for (const auto &sym : ls->labels.label_symbols) { struct program_space *pspace - = sym.symbol->symtab ()->compunit ()->objfile ()->pspace; + = sym.symbol->symtab ()->compunit ()->objfile ()->pspace (); if (symbol_to_sal (&sal, state->funfirstline, sym.symbol) && maybe_add_address (state->addr_set, pspace, sal.pc)) @@ -2194,7 +2235,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls) for (const auto &sym : ls->function_symbols) { program_space *pspace - = sym.symbol->symtab ()->compunit ()->objfile ()->pspace; + = sym.symbol->symtab ()->compunit ()->objfile ()->pspace (); set_current_program_space (pspace); /* Don't skip to the first line of the function if we @@ -2256,7 +2297,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls) for (const auto &elem : ls->minimal_symbols) { - program_space *pspace = elem.objfile->pspace; + program_space *pspace = elem.objfile->pspace (); set_current_program_space (pspace); minsym_found (state, elem.objfile, elem.minsym, &sals); } @@ -3205,7 +3246,8 @@ decode_line_with_current_source (const char *string, int flags) /* We use whatever is set as the current source line. We do not try and get a default source symtab+line or it will recursively call us! */ - symtab_and_line cursal = get_current_source_symtab_and_line (); + symtab_and_line cursal + = get_current_source_symtab_and_line (current_program_space); location_spec_up locspec = string_to_location_spec (&string, current_language); @@ -3255,9 +3297,9 @@ initialize_defaults (struct symtab **default_symtab, int *default_line) /* Use whatever we have for the default source line. We don't use get_current_or_default_symtab_and_line as it can recurse and call us back! */ - struct symtab_and_line cursal = - get_current_source_symtab_and_line (); - + symtab_and_line cursal + = get_current_source_symtab_and_line (current_program_space); + *default_symtab = cursal.symtab; *default_line = cursal.line; } @@ -3437,7 +3479,7 @@ lookup_prefix_sym (struct linespec_state *state, { /* Program spaces that are executing startup should have been filtered out earlier. */ - program_space *pspace = elt->compunit ()->objfile ()->pspace; + program_space *pspace = elt->compunit ()->objfile ()->pspace (); gdb_assert (!pspace->executing_startup); set_current_program_space (pspace); @@ -3459,8 +3501,8 @@ compare_symbols (const block_symbol &a, const block_symbol &b) { uintptr_t uia, uib; - uia = (uintptr_t) a.symbol->symtab ()->compunit ()->objfile ()->pspace; - uib = (uintptr_t) b.symbol->symtab ()->compunit ()->objfile ()->pspace; + uia = (uintptr_t) a.symbol->symtab ()->compunit ()->objfile ()->pspace (); + uib = (uintptr_t) b.symbol->symtab ()->compunit ()->objfile ()->pspace (); if (uia < uib) return true; @@ -3483,8 +3525,8 @@ compare_msymbols (const bound_minimal_symbol &a, const bound_minimal_symbol &b) { uintptr_t uia, uib; - uia = (uintptr_t) a.objfile->pspace; - uib = (uintptr_t) a.objfile->pspace; + uia = (uintptr_t) a.objfile->pspace (); + uib = (uintptr_t) a.objfile->pspace (); if (uia < uib) return true; @@ -3584,7 +3626,7 @@ find_method (struct linespec_state *self, /* Program spaces that are executing startup should have been filtered out earlier. */ - pspace = sym->symtab ()->compunit ()->objfile ()->pspace; + pspace = sym->symtab ()->compunit ()->objfile ()->pspace (); gdb_assert (!pspace->executing_startup); set_current_program_space (pspace); t = check_typedef (sym->type ()); @@ -3596,7 +3638,7 @@ find_method (struct linespec_state *self, if (ix == sym_classes->size () - 1 || (pspace != (sym_classes->at (ix + 1).symbol->symtab () - ->compunit ()->objfile ()->pspace))) + ->compunit ()->objfile ()->pspace ()))) { /* If we did not find a direct implementation anywhere in this program space, consider superclasses. */ @@ -3691,15 +3733,11 @@ collect_symtabs_from_filename (const char *file, if (pspace->executing_startup) continue; - set_current_program_space (pspace); - iterate_over_symtabs (file, collector); + iterate_over_symtabs (pspace, file, collector); } } else - { - set_current_program_space (search_pspace); - iterate_over_symtabs (file, collector); - } + iterate_over_symtabs (search_pspace, file, collector); return collector.release_symtabs (); } @@ -3716,7 +3754,8 @@ symtabs_from_filename (const char *filename, if (result.empty ()) { - if (!have_full_symbols () && !have_partial_symbols ()) + if (!have_full_symbols (current_program_space) + && !have_partial_symbols (current_program_space)) throw_error (NOT_FOUND_ERROR, _("No symbol table is loaded. " "Use the \"file\" command.")); @@ -3963,7 +4002,7 @@ find_label_symbols (struct linespec_state *self, { fn_sym = elt.symbol; set_current_program_space - (fn_sym->symtab ()->compunit ()->objfile ()->pspace); + (fn_sym->symtab ()->compunit ()->objfile ()->pspace ()); block = fn_sym->value_block (); find_label_symbols_in_block (block, name, fn_sym, completion_mode, @@ -3992,7 +4031,7 @@ decode_digits_list_mode (struct linespec_state *self, /* The logic above should ensure this. */ gdb_assert (elt != NULL); - program_space *pspace = elt->compunit ()->objfile ()->pspace; + program_space *pspace = elt->compunit ()->objfile ()->pspace (); set_current_program_space (pspace); /* Simplistic search just for the list command. */ @@ -4027,7 +4066,7 @@ decode_digits_ordinary (struct linespec_state *self, /* The logic above should ensure this. */ gdb_assert (elt != NULL); - program_space *pspace = elt->compunit ()->objfile ()->pspace; + program_space *pspace = elt->compunit ()->objfile ()->pspace (); set_current_program_space (pspace); pcs = find_pcs_for_symtab_line (elt, line, best_entry); @@ -4153,7 +4192,7 @@ minsym_found (struct linespec_state *self, struct objfile *objfile, sal.section = msymbol->obj_section (objfile); - if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc)) + if (maybe_add_address (self->addr_set, objfile->pspace (), sal.pc)) add_sal_to_sals (self, result, &sal, msymbol->natural_name (), 0); } @@ -4163,7 +4202,7 @@ minsym_found (struct linespec_state *self, struct objfile *objfile, static void add_minsym (struct minimal_symbol *minsym, struct objfile *objfile, struct symtab *symtab, int list_mode, - std::vector<struct bound_minimal_symbol> *msyms) + std::vector<bound_minimal_symbol> *msyms) { if (symtab != NULL) { @@ -4200,7 +4239,7 @@ search_minsyms_for_name (struct collect_info *info, struct program_space *search_pspace, struct symtab *symtab) { - std::vector<struct bound_minimal_symbol> minsyms; + std::vector<bound_minimal_symbol> minsyms; if (symtab == NULL) { @@ -4213,7 +4252,7 @@ search_minsyms_for_name (struct collect_info *info, set_current_program_space (pspace); - for (objfile *objfile : current_program_space->objfiles ()) + for (objfile *objfile : pspace->objfiles ()) { iterate_over_minimal_symbols (objfile, name, [&] (struct minimal_symbol *msym) @@ -4228,7 +4267,7 @@ search_minsyms_for_name (struct collect_info *info, } else { - program_space *pspace = symtab->compunit ()->objfile ()->pspace; + program_space *pspace = symtab->compunit ()->objfile ()->pspace (); if (search_pspace == NULL || pspace == search_pspace) { @@ -4322,13 +4361,13 @@ add_matching_symbols_to_info (const char *name, { return info->add_symbol (bsym); }); search_minsyms_for_name (info, lookup_name, pspace, NULL); } - else if (pspace == NULL || pspace == elt->compunit ()->objfile ()->pspace) + else if (pspace == NULL || pspace == elt->compunit ()->objfile ()->pspace ()) { int prev_len = info->result.symbols->size (); /* Program spaces that are executing startup should have been filtered out earlier. */ - program_space *elt_pspace = elt->compunit ()->objfile ()->pspace; + program_space *elt_pspace = elt->compunit ()->objfile ()->pspace (); gdb_assert (!elt_pspace->executing_startup); set_current_program_space (elt_pspace); iterate_over_file_blocks (elt, lookup_name, SEARCH_VFT, @@ -4369,7 +4408,7 @@ symbol_to_sal (struct symtab_and_line *result, result->symbol = sym; result->line = sym->line (); result->pc = sym->value_address (); - result->pspace = result->symtab->compunit ()->objfile ()->pspace; + result->pspace = result->symtab->compunit ()->objfile ()->pspace (); result->explicit_pc = 1; return 1; } @@ -4385,7 +4424,7 @@ symbol_to_sal (struct symtab_and_line *result, result->symbol = sym; result->line = sym->line (); result->pc = sym->value_address (); - result->pspace = result->symtab->compunit ()->objfile ()->pspace; + result->pspace = result->symtab->compunit ()->objfile ()->pspace (); return 1; } } |