* symtab.c (find_addr_symbol): New routine that will find the nearest
authorJohn Gilmore <gnu@cygnus>
Wed, 12 Jan 1994 08:18:55 +0000 (08:18 +0000)
committerJohn Gilmore <gnu@cygnus>
Wed, 12 Jan 1994 08:18:55 +0000 (08:18 +0000)
symbol associated with an address.  It does so by exhaustive
search of the symtabs, so it's slow but complete.

gdb/ChangeLog
gdb/symtab.c

index 818e4d0f068b9e16c2fa2f8dbbcf41120eddd82e..1276cc53444a2352ce96712c7bb120e3293ea99d 100644 (file)
@@ -1,3 +1,9 @@
+Wed Jan 12 00:16:26 1994  John Gilmore  (gnu@cygnus.com)
+
+       * symtab.c (find_addr_symbol):  New routine that will find the nearest
+       symbol associated with an address.  It does so by exhaustive
+       search of the symtabs, so it's slow but complete.
+
 Tue Jan 11 23:57:30 1994  John Gilmore  (gnu@cygnus.com)
 
        * coffread.c (read_coff_symtab):  Set PC bounds of _globals_ symtab
index cf948aa0b36fdffacdd96a8c058a633f672cc32d..880ad9663ec744459c3af4d3159d51c68f16fed2 100644 (file)
@@ -1026,6 +1026,71 @@ find_pc_symtab (pc)
     }
   return (s);
 }
+\f
+/* Find the closest symbol value (of any sort -- function or variable)
+   for a given address value.  Slow but complete.  */
+
+struct symbol *
+find_addr_symbol (addr)
+     CORE_ADDR addr;
+{
+  struct symtab *symtab;
+  struct objfile *objfile;
+  register int bot, top;
+  register struct symbol *sym;
+  register CORE_ADDR sym_addr;
+  struct block *block;
+  int blocknum;
+
+  /* Info on best symbol seen so far */
+
+  register CORE_ADDR best_sym_addr = 0;
+  struct symbol *best_sym = 0;
+
+  /* FIXME -- we should pull in all the psymtabs, too!  */
+  ALL_SYMTABS (objfile, symtab)
+    {
+      /* Search the global and static blocks in this symtab for
+        the closest symbol-address to the desired address.  */
+
+      for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++)
+       {
+         QUIT;
+         block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum);
+         top = BLOCK_NSYMS (block);
+         for (bot = 0; bot < top; bot++)
+           {
+             sym = BLOCK_SYM (block, bot);
+             switch (SYMBOL_CLASS (sym))
+               {
+               case LOC_STATIC:        
+               case LOC_LABEL: 
+                 sym_addr = SYMBOL_VALUE_ADDRESS (sym);
+                 break;
+
+               case LOC_BLOCK:
+                 sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
+                 break;
+
+               default:
+                 continue;
+               }
+
+               if (sym_addr <= addr)
+                 if (sym_addr > best_sym_addr)
+                   {
+                     /* Quit if we found an exact match.  */
+                     if (sym_addr == addr)
+                       return sym;
+                     best_sym = sym;
+                     best_sym_addr = sym_addr;
+                   }
+           }
+       }
+    }
+  return best_sym;
+}
+
 
 /* Find the source file and line number for a given PC value.
    Return a structure containing a symtab pointer, a line number,
This page took 0.028369 seconds and 4 git commands to generate.