From: Simon Marchi Date: Sat, 11 Oct 2025 04:06:20 +0000 (-0400) Subject: gdb: remove unnecessary use of symtab_and_line in create_sals_line_offset X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=927cb4b7781cb122a2c5ce02a5541a159a1a0627;p=thirdparty%2Fbinutils-gdb.git gdb: remove unnecessary use of symtab_and_line in create_sals_line_offset create_sals_line_offset uses a symtab_and_line essentially just to hold a line number and pass it down to decode_digits_list_mode. Change the local variable to be an int, and change decode_digits_list_mode to accept an int, instead of a symtab_and_line. I think this makes the code a bit simpler. Change-Id: I445d2473f042693c3a4f2693877408f85100cd1f Approved-By: Tom Tromey --- diff --git a/gdb/linespec.c b/gdb/linespec.c index 7489af0ccae..352f3af3afe 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -419,9 +419,7 @@ static std::vector decode_digits_ordinary const linetable_entry **best_entry); static std::vector decode_digits_list_mode - (struct linespec_state *self, - linespec *ls, - struct symtab_and_line val); + (linespec_state *self, linespec *ls, int line); static void minsym_found (struct linespec_state *self, struct objfile *objfile, struct minimal_symbol *msymbol, @@ -2012,24 +2010,24 @@ create_sals_line_offset (struct linespec_state *self, use_default = true; } - symtab_and_line val; - val.line = ls->explicit_loc.line_offset.offset; + int line = ls->explicit_loc.line_offset.offset; + switch (ls->explicit_loc.line_offset.sign) { case LINE_OFFSET_PLUS: if (ls->explicit_loc.line_offset.offset == 0) - val.line = 5; + line = 5; if (use_default) - val.line = self->default_line + val.line; + line = self->default_line + line; break; case LINE_OFFSET_MINUS: if (ls->explicit_loc.line_offset.offset == 0) - val.line = 15; + line = 15; if (use_default) - val.line = self->default_line - val.line; + line = self->default_line - line; else - val.line = -val.line; + line = -line; break; case LINE_OFFSET_NONE: @@ -2038,7 +2036,7 @@ create_sals_line_offset (struct linespec_state *self, std::vector values; if (self->list_mode) - values = decode_digits_list_mode (self, ls, val); + values = decode_digits_list_mode (self, ls, line); else { const linetable_entry *best_entry = NULL; @@ -2049,7 +2047,7 @@ create_sals_line_offset (struct linespec_state *self, bool was_exact = true; std::vector intermediate_results - = decode_digits_ordinary (self, ls, val.line, &best_entry); + = decode_digits_ordinary (self, ls, line, &best_entry); if (intermediate_results.empty () && best_entry != NULL) { was_exact = false; @@ -2130,7 +2128,7 @@ create_sals_line_offset (struct linespec_state *self, && sym != nullptr && sym->loc_class () == LOC_BLOCK && sal.pc == sym->value_block ()->entry_pc () - && val.line < sym->line ()) + && line < sym->line ()) continue; if (self->funfirstline) @@ -2147,11 +2145,11 @@ create_sals_line_offset (struct linespec_state *self, if (ls->explicit_loc.source_filename) throw_error (NOT_FOUND_ERROR, _("No compiled code for line %d in file \"%s\"."), - val.line, ls->explicit_loc.source_filename.get ()); + line, ls->explicit_loc.source_filename.get ()); else throw_error (NOT_FOUND_ERROR, _("No compiled code for line %d in the current file."), - val.line); + line); } return values; @@ -3916,9 +3914,7 @@ find_label_symbols (struct linespec_state *self, /* A helper for create_sals_line_offset that handles the 'list_mode' case. */ static std::vector -decode_digits_list_mode (struct linespec_state *self, - linespec *ls, - struct symtab_and_line val) +decode_digits_list_mode (linespec_state *self, linespec *ls, int line) { gdb_assert (self->list_mode); @@ -3933,7 +3929,9 @@ decode_digits_list_mode (struct linespec_state *self, set_current_program_space (pspace); /* Simplistic search just for the list command. */ - val.symtab = find_line_symtab (elt, val.line, nullptr); + symtab_and_line val; + val.line = line; + val.symtab = find_line_symtab (elt, line, nullptr); if (val.symtab == NULL) val.symtab = elt; val.pspace = pspace;