From d39a6e7c1b01792a2aa4021f6511a3f9173efe48 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 11 Oct 2025 00:02:43 -0400 Subject: [PATCH] gdb/symtab: declare variables on first use in find_pc_sect_line I'm currently looking at this function, and think it makes it easier to process if the variables are declared when actually used. Change-Id: Ie950fc3a7241e55e66ae96a578f79df3a9b45c69 Approved-By: Tom Tromey --- gdb/symtab.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index d4089c87792..8186af900fb 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2904,14 +2904,7 @@ find_symbol_at_address (CORE_ADDR address) struct symtab_and_line find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) { - struct compunit_symtab *cust; - const linetable *l; - int len; - const linetable_entry *item; - const struct blockvector *bv; - /* Info on best line seen so far, and where it starts, and its file. */ - const linetable_entry *best = NULL; CORE_ADDR best_end = 0; struct symtab *best_symtab = 0; @@ -3034,7 +3027,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) symtab_and_line val; val.pspace = current_program_space; - cust = find_pc_sect_compunit_symtab (pc, section); + compunit_symtab *cust = find_pc_sect_compunit_symtab (pc, section); if (cust == NULL) { /* If no symbol information, return previous pc. */ @@ -3044,7 +3037,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) return val; } - bv = cust->blockvector (); + const blockvector *bv = cust->blockvector (); struct objfile *objfile = cust->objfile (); /* Look at all the symtabs that share this blockvector. @@ -3054,10 +3047,11 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) for (symtab *iter_s : cust->filetabs ()) { /* Find the best line in this symtab. */ - l = iter_s->linetable (); + const linetable *l = iter_s->linetable (); if (!l) continue; - len = l->nitems; + + int len = l->nitems; if (len <= 0) { /* I think len can be zero if the symtab lacks line numbers @@ -3068,7 +3062,8 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) } prev = NULL; - item = l->item; /* Get first line info. */ + /* Get first line info. */ + const linetable_entry *item = l->item; /* Is this file's first line closer than the first lines of other files? If so, record this file, and its first line, as best alternate. */ -- 2.47.3