static struct block * find_block_in_blockvector (struct blockvector *bl, CORE_ADDR pc) { struct block *b; int bot, top, half; /* If we have an addrmap mapping code addresses to blocks, then use that. */ if (BLOCKVECTOR_MAP (bl)) return addrmap_find (BLOCKVECTOR_MAP (bl), pc); /* Otherwise, use binary search to find the last block that starts before PC. Note: GLOBAL_BLOCK is block 0, STATIC_BLOCK is block 1. They both have the same START,END values. Historically this code would choose STATIC_BLOCK over GLOBAL_BLOCK but the fact that this choice was made was subtle, now we make it explicit. */ gdb_assert (BLOCKVECTOR_NBLOCKS (bl) >= 2); bot = STATIC_BLOCK; top = BLOCKVECTOR_NBLOCKS (bl); while (top - bot > 1) { half = (top - bot + 1) >> 1; b = BLOCKVECTOR_BLOCK (bl, bot + half); if (BLOCK_START (b) <= pc) bot += half; else top = bot + half; } /* Now search backward for a block that ends after PC. */ while (bot >= STATIC_BLOCK) { b = BLOCKVECTOR_BLOCK (bl, bot); if (BLOCK_END (b) > pc) return b; bot--; } return NULL; }
struct blockvector * blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section, struct block **pblock, struct symtab *symtab) { struct block *b; int bot, top, half; struct blockvector *bl; if (symtab == 0) /* if no symtab specified by caller */ { /* First search all symtabs for one whose file contains our pc */ symtab = find_pc_sect_symtab (pc, section); if (symtab == 0) return 0; } bl = BLOCKVECTOR (symtab); /* Then search that symtab for the smallest block that wins. */ /* If we have an addrmap mapping code addresses to blocks, then use that. */ if (BLOCKVECTOR_MAP (bl)) { b = addrmap_find (BLOCKVECTOR_MAP (bl), pc); if (b) { if (pblock) *pblock = b; return bl; } else return 0; } /* Otherwise, use binary search to find the last block that starts before PC. */ bot = 0; top = BLOCKVECTOR_NBLOCKS (bl); while (top - bot > 1) { half = (top - bot + 1) >> 1; b = BLOCKVECTOR_BLOCK (bl, bot + half); if (BLOCK_START (b) <= pc) bot += half; else top = bot + half; } /* Now search backward for a block that ends after PC. */ while (bot >= 0) { b = BLOCKVECTOR_BLOCK (bl, bot); if (BLOCK_END (b) > pc) { if (pblock) *pblock = b; return bl; } bot--; } return 0; }