aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.c
diff options
context:
space:
mode:
authorJohn Gilmore <gnu@cygnus>1994-01-12 08:18:55 +0000
committerJohn Gilmore <gnu@cygnus>1994-01-12 08:18:55 +0000
commite0ea0fbd4169183ce4ddc6563503ea6b9f04c133 (patch)
tree6d45fd738883f0601ffe0b28c2768155cdb9ff89 /gdb/symtab.c
parent011d4ed95fec0aa810775a84e25188a3cd4333b1 (diff)
downloadgdb-e0ea0fbd4169183ce4ddc6563503ea6b9f04c133.zip
gdb-e0ea0fbd4169183ce4ddc6563503ea6b9f04c133.tar.gz
gdb-e0ea0fbd4169183ce4ddc6563503ea6b9f04c133.tar.bz2
* 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.
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r--gdb/symtab.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c
index cf948aa..880ad96 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1026,6 +1026,71 @@ find_pc_symtab (pc)
}
return (s);
}
+
+/* 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,