/* Return the innermost lexical block containing the specified pc value, or 0 if there is none. */ PyObject * gdbpy_block_for_pc (PyObject *self, PyObject *args) { unsigned PY_LONG_LONG pc; struct block *block; struct obj_section *section; struct symtab *symtab; if (!PyArg_ParseTuple (args, "K", &pc)) return NULL; section = find_pc_mapped_section (pc); symtab = find_pc_sect_symtab (pc, section); if (!symtab || symtab->objfile == NULL) { PyErr_SetString (PyExc_RuntimeError, _("Cannot locate object file for block.")); return NULL; } block = block_for_pc (pc); if (block) return block_to_block_object (block, symtab->objfile); Py_RETURN_NONE; }
struct blockvector * blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section, struct block **pblock, struct symtab *symtab) { struct blockvector *bl; struct block *b; 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. */ b = find_block_in_blockvector (bl, pc); if (b == NULL) return NULL; if (pblock) *pblock = b; return bl; }
struct blockvector * blockvector_for_pc_sect (CORE_ADDR pc, struct bfd_section *section, int *pindex, 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); b = BLOCKVECTOR_BLOCK (bl, 0); /* Then search that symtab for the smallest block that wins. */ /* 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 (pindex) *pindex = bot; return bl; } bot--; } return 0; }
/* Return the innermost lexical block containing the specified pc value, or 0 if there is none. */ PyObject * gdbpy_block_for_pc (PyObject *self, PyObject *args) { gdb_py_ulongest pc; struct block *block; struct obj_section *section = NULL; struct symtab *symtab = NULL; volatile struct gdb_exception except; if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc)) return NULL; TRY_CATCH (except, RETURN_MASK_ALL) { section = find_pc_mapped_section (pc); symtab = find_pc_sect_symtab (pc, section); }
struct blockvector * blockvector_for_pc_sect (CORE_ADDR pc, struct bfd_section *section, int *pindex, struct symtab *symtab) { struct block *b; struct block *static_block; int bot, top, half; struct blockvector *bl; if (pindex) *pindex = 0; /* APPLE LOCAL begin cache lookup values for improved performance */ if ((pc == last_blockvector_lookup_pc) && (pc == last_mapped_section_lookup_pc) && (section == cached_mapped_section) && cached_blockvector && (pindex != NULL)) { *pindex = cached_blockvector_index; return cached_blockvector; } last_blockvector_lookup_pc = pc; /* APPLE LOCAL end cache lookup values for improved performance */ 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) /* APPLE LOCAL begin cache lookup values for improved performance */ { cached_blockvector_index = -1; cached_blockvector = NULL; return 0; } /* APPLE LOCAL end cache lookup values for improved performance */ } bl = BLOCKVECTOR(symtab); static_block = BLOCKVECTOR_BLOCK(bl, STATIC_BLOCK); b = BLOCKVECTOR_BLOCK(bl, 0); gdb_assert(b != NULL); /* Then search that symtab for the smallest block that wins. */ /* 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)); /* APPLE LOCAL begin address ranges */ if (BLOCK_LOWEST_PC(b) <= pc) /* APPLE LOCAL end address ranges */ bot += half; else top = bot + half; } /* APPLE LOCAL We start with the block whose start/end address is higher than PC. */ /* Now search backward for a block that ends after PC. */ /* APPLE LOCAL: Stop at the first local block; i.e. don't iterate down to the global/static blocks. */ while (bot >= FIRST_LOCAL_BLOCK) { b = BLOCKVECTOR_BLOCK(bl, bot); /* APPLE LOCAL begin address ranges */ /* This condition is a little tricky. Given a function like func () { { subblock} // pc here } BOT may be pointing to "subblock" and so the BOT block start/end addrs are less than PC. But we don't want to terminate the search in this case - we need to keep iterating backwards to find "func"'s block. So I'm trying to restrict this to only quit searching if we're looking at a function's overall scope and both its highest/lowest addresses are lower than PC. */ if (BLOCK_SUPERBLOCK (b) == static_block && BLOCK_LOWEST_PC (b) < pc && BLOCK_HIGHEST_PC (b) < pc) /* APPLE LOCAL begin cache lookup values for improved performance */ { cached_blockvector_index = -1; cached_blockvector = NULL; return 0; } /* APPLE LOCAL end cache lookup values for improved performance */ if (block_contains_pc(b, pc)) /* APPLE LOCAL end address ranges */ { if (pindex) *pindex = bot; /* APPLE LOCAL begom cache lookup values for improved performance */ cached_blockvector_index = bot; cached_blockvector = bl; /* APPLE LOCAL end cache lookup values for improved performance */ return bl; } bot--; } /* APPLE LOCAL begin cache lookup values for improved performance */ cached_blockvector_index = -1; cached_blockvector = NULL; /* APPLE LOCAL end cache lookup values for improved performance */ return 0; }
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; }