1 /* Block-related functions for the GNU debugger, GDB.
3 Copyright 2003 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 /* Return Nonzero if block a is lexically nested within block b,
28 or if a and b have the same pc range.
29 Return zero otherwise. */
32 contained_in (struct block *a, struct block *b)
36 return BLOCK_START (a) >= BLOCK_START (b)
37 && BLOCK_END (a) <= BLOCK_END (b);
41 /* Return the symbol for the function which contains a specified
42 lexical block, described by a struct block BL. */
45 block_function (struct block *bl)
47 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
48 bl = BLOCK_SUPERBLOCK (bl);
50 return BLOCK_FUNCTION (bl);
53 /* Return the blockvector immediately containing the innermost lexical block
54 containing the specified pc value and section, or 0 if there is none.
55 PINDEX is a pointer to the index value of the block. If PINDEX
56 is NULL, we don't pass this information back to the caller. */
59 blockvector_for_pc_sect (register CORE_ADDR pc, struct sec *section,
60 int *pindex, struct symtab *symtab)
62 register struct block *b;
63 register int bot, top, half;
64 struct blockvector *bl;
66 if (symtab == 0) /* if no symtab specified by caller */
68 /* First search all symtabs for one whose file contains our pc */
69 if ((symtab = find_pc_sect_symtab (pc, section)) == 0)
73 bl = BLOCKVECTOR (symtab);
74 b = BLOCKVECTOR_BLOCK (bl, 0);
76 /* Then search that symtab for the smallest block that wins. */
77 /* Use binary search to find the last block that starts before PC. */
80 top = BLOCKVECTOR_NBLOCKS (bl);
84 half = (top - bot + 1) >> 1;
85 b = BLOCKVECTOR_BLOCK (bl, bot + half);
86 if (BLOCK_START (b) <= pc)
92 /* Now search backward for a block that ends after PC. */
96 b = BLOCKVECTOR_BLOCK (bl, bot);
97 if (BLOCK_END (b) > pc)
108 /* Return the blockvector immediately containing the innermost lexical block
109 containing the specified pc value, or 0 if there is none.
110 Backward compatibility, no section. */
113 blockvector_for_pc (register CORE_ADDR pc, int *pindex)
115 return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
119 /* Return the innermost lexical block containing the specified pc value
120 in the specified section, or 0 if there is none. */
123 block_for_pc_sect (register CORE_ADDR pc, struct sec *section)
125 register struct blockvector *bl;
128 bl = blockvector_for_pc_sect (pc, section, &index, NULL);
130 return BLOCKVECTOR_BLOCK (bl, index);
134 /* Return the innermost lexical block containing the specified pc value,
135 or 0 if there is none. Backward compatibility, no section. */
138 block_for_pc (register CORE_ADDR pc)
140 return block_for_pc_sect (pc, find_pc_mapped_section (pc));