]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/symtab: declare variables on first use in find_pc_sect_line
authorSimon Marchi <simon.marchi@efficios.com>
Sat, 11 Oct 2025 04:02:43 +0000 (00:02 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 14 Oct 2025 17:46:29 +0000 (13:46 -0400)
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 <tom@tromey.com>
gdb/symtab.c

index d4089c877929b8934d6e7e3db0e5365b7d300751..8186af900fb5a2ca473b629e25cdf034961ed5c9 100644 (file)
@@ -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.  */