* ada-lang.c (ada_decode_symbol): Check and set 'ada_mangled'.
[deliverable/binutils-gdb.git] / gdb / blockframe.c
CommitLineData
7cc19214
AC
1/* Get info from stack frames; convert between frames, blocks,
2 functions and pc values.
3
28e7fd62 4 Copyright (C) 1986-2013 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
c5aa993b 11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b 18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
20
21#include "defs.h"
22#include "symtab.h"
23#include "bfd.h"
c906108c
SS
24#include "objfiles.h"
25#include "frame.h"
26#include "gdbcore.h"
7157eed4
UW
27#include "value.h"
28#include "target.h"
29#include "inferior.h"
c906108c 30#include "annotate.h"
4e052eda 31#include "regcache.h"
4f460812 32#include "gdb_assert.h"
9c1412c1 33#include "dummy-frame.h"
51603483
DJ
34#include "command.h"
35#include "gdbcmd.h"
fe898f56 36#include "block.h"
edb3359d 37#include "inline-frame.h"
ccefe4c4 38#include "psymtab.h"
c906108c 39
4a64f543
MS
40/* Return the innermost lexical block in execution in a specified
41 stack frame. The frame address is assumed valid.
ae767bfb
JB
42
43 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the exact code
44 address we used to choose the block. We use this to find a source
45 line, to decide which macro definitions are in scope.
46
47 The value returned in *ADDR_IN_BLOCK isn't necessarily the frame's
48 PC, and may not really be a valid PC at all. For example, in the
49 caller of a function declared to never return, the code at the
50 return address will never be reached, so the call instruction may
51 be the very last instruction in the block. So the address we use
52 to choose the block is actually one byte before the return address
53 --- hopefully pointing us at the call instruction, or its delay
54 slot instruction. */
c906108c
SS
55
56struct block *
ae767bfb 57get_frame_block (struct frame_info *frame, CORE_ADDR *addr_in_block)
c906108c 58{
e3eebbd7 59 CORE_ADDR pc;
edb3359d
DJ
60 struct block *bl;
61 int inline_count;
ae767bfb 62
e3eebbd7
PA
63 if (!get_frame_address_in_block_if_available (frame, &pc))
64 return NULL;
65
ae767bfb
JB
66 if (addr_in_block)
67 *addr_in_block = pc;
68
edb3359d
DJ
69 bl = block_for_pc (pc);
70 if (bl == NULL)
71 return NULL;
72
73 inline_count = frame_inlined_callees (frame);
74
75 while (inline_count > 0)
76 {
77 if (block_inlined_p (bl))
78 inline_count--;
79
80 bl = BLOCK_SUPERBLOCK (bl);
81 gdb_assert (bl != NULL);
82 }
83
84 return bl;
c906108c
SS
85}
86
c906108c 87CORE_ADDR
fba45db2 88get_pc_function_start (CORE_ADDR pc)
c906108c 89{
2cdd89cb
MK
90 struct block *bl;
91 struct minimal_symbol *msymbol;
c906108c 92
2cdd89cb
MK
93 bl = block_for_pc (pc);
94 if (bl)
c906108c 95 {
7f0df278 96 struct symbol *symbol = block_linkage_function (bl);
2cdd89cb
MK
97
98 if (symbol)
99 {
100 bl = SYMBOL_BLOCK_VALUE (symbol);
101 return BLOCK_START (bl);
102 }
c906108c 103 }
2cdd89cb
MK
104
105 msymbol = lookup_minimal_symbol_by_pc (pc);
106 if (msymbol)
c906108c 107 {
2cdd89cb
MK
108 CORE_ADDR fstart = SYMBOL_VALUE_ADDRESS (msymbol);
109
110 if (find_pc_section (fstart))
111 return fstart;
c906108c 112 }
2cdd89cb
MK
113
114 return 0;
c906108c
SS
115}
116
117/* Return the symbol for the function executing in frame FRAME. */
118
119struct symbol *
fba45db2 120get_frame_function (struct frame_info *frame)
c906108c 121{
52f0bd74 122 struct block *bl = get_frame_block (frame, 0);
edb3359d
DJ
123
124 if (bl == NULL)
125 return NULL;
126
127 while (BLOCK_FUNCTION (bl) == NULL && BLOCK_SUPERBLOCK (bl) != NULL)
128 bl = BLOCK_SUPERBLOCK (bl);
129
130 return BLOCK_FUNCTION (bl);
c906108c
SS
131}
132\f
133
c906108c
SS
134/* Return the function containing pc value PC in section SECTION.
135 Returns 0 if function is not known. */
136
137struct symbol *
714835d5 138find_pc_sect_function (CORE_ADDR pc, struct obj_section *section)
c906108c 139{
52f0bd74 140 struct block *b = block_for_pc_sect (pc, section);
cc59ec59 141
c906108c
SS
142 if (b == 0)
143 return 0;
7f0df278 144 return block_linkage_function (b);
c906108c
SS
145}
146
147/* Return the function containing pc value PC.
4a64f543
MS
148 Returns 0 if function is not known.
149 Backward compatibility, no section */
c906108c
SS
150
151struct symbol *
fba45db2 152find_pc_function (CORE_ADDR pc)
c906108c
SS
153{
154 return find_pc_sect_function (pc, find_pc_mapped_section (pc));
155}
156
157/* These variables are used to cache the most recent result
4a64f543 158 of find_pc_partial_function. */
c906108c 159
c5aa993b
JM
160static CORE_ADDR cache_pc_function_low = 0;
161static CORE_ADDR cache_pc_function_high = 0;
2c02bd72 162static const char *cache_pc_function_name = 0;
714835d5 163static struct obj_section *cache_pc_function_section = NULL;
11c81455 164static int cache_pc_function_is_gnu_ifunc = 0;
c906108c 165
4a64f543 166/* Clear cache, e.g. when symbol table is discarded. */
c906108c
SS
167
168void
fba45db2 169clear_pc_function_cache (void)
c906108c
SS
170{
171 cache_pc_function_low = 0;
172 cache_pc_function_high = 0;
c5aa993b 173 cache_pc_function_name = (char *) 0;
c906108c 174 cache_pc_function_section = NULL;
11c81455 175 cache_pc_function_is_gnu_ifunc = 0;
c906108c
SS
176}
177
178/* Finds the "function" (text symbol) that is smaller than PC but
179 greatest of all of the potential text symbols in SECTION. Sets
180 *NAME and/or *ADDRESS conditionally if that pointer is non-null.
181 If ENDADDR is non-null, then set *ENDADDR to be the end of the
182 function (exclusive), but passing ENDADDR as non-null means that
11c81455
JK
183 the function might cause symbols to be read. If IS_GNU_IFUNC_P is provided
184 *IS_GNU_IFUNC_P is set to 1 on return if the function is STT_GNU_IFUNC.
185 This function either succeeds or fails (not halfway succeeds). If it
186 succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real information and
187 returns 1. If it fails, it sets *NAME, *ADDRESS, *ENDADDR and
188 *IS_GNU_IFUNC_P to zero and returns 0. */
c906108c 189
73912b9b
AC
190/* Backward compatibility, no section argument. */
191
c906108c 192int
2c02bd72 193find_pc_partial_function_gnu_ifunc (CORE_ADDR pc, const char **name,
11c81455
JK
194 CORE_ADDR *address, CORE_ADDR *endaddr,
195 int *is_gnu_ifunc_p)
c906108c 196{
714835d5 197 struct obj_section *section;
c5aa993b 198 struct symbol *f;
c906108c 199 struct minimal_symbol *msymbol;
ccefe4c4
TT
200 struct symtab *symtab = NULL;
201 struct objfile *objfile;
c906108c
SS
202 int i;
203 CORE_ADDR mapped_pc;
204
73912b9b
AC
205 /* To ensure that the symbol returned belongs to the correct setion
206 (and that the last [random] symbol from the previous section
207 isn't returned) try to find the section containing PC. First try
208 the overlay code (which by default returns NULL); and second try
209 the normal section code (which almost always succeeds). */
210 section = find_pc_overlay (pc);
211 if (section == NULL)
714835d5 212 section = find_pc_section (pc);
73912b9b 213
c906108c
SS
214 mapped_pc = overlay_mapped_address (pc, section);
215
247055de
MK
216 if (mapped_pc >= cache_pc_function_low
217 && mapped_pc < cache_pc_function_high
218 && section == cache_pc_function_section)
c906108c
SS
219 goto return_cached_value;
220
c906108c 221 msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section);
ccefe4c4
TT
222 ALL_OBJFILES (objfile)
223 {
224 if (objfile->sf)
225 symtab = objfile->sf->qf->find_pc_sect_symtab (objfile, msymbol,
226 mapped_pc, section, 0);
227 if (symtab)
228 break;
229 }
230
231 if (symtab)
c906108c 232 {
ccefe4c4
TT
233 /* Checking whether the msymbol has a larger value is for the
234 "pathological" case mentioned in print_frame_info. */
235 f = find_pc_sect_function (mapped_pc, section);
236 if (f != NULL
237 && (msymbol == NULL
238 || (BLOCK_START (SYMBOL_BLOCK_VALUE (f))
239 >= SYMBOL_VALUE_ADDRESS (msymbol))))
c906108c 240 {
ccefe4c4
TT
241 cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f));
242 cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
243 cache_pc_function_name = SYMBOL_LINKAGE_NAME (f);
244 cache_pc_function_section = section;
11c81455 245 cache_pc_function_is_gnu_ifunc = TYPE_GNU_IFUNC (SYMBOL_TYPE (f));
ccefe4c4 246 goto return_cached_value;
c906108c
SS
247 }
248 }
249
4a64f543
MS
250 /* Not in the normal symbol tables, see if the pc is in a known
251 section. If it's not, then give up. This ensures that anything
252 beyond the end of the text seg doesn't appear to be part of the
253 last function in the text segment. */
c906108c 254
714835d5 255 if (!section)
c906108c
SS
256 msymbol = NULL;
257
258 /* Must be in the minimal symbol table. */
259 if (msymbol == NULL)
260 {
261 /* No available symbol. */
262 if (name != NULL)
263 *name = 0;
264 if (address != NULL)
265 *address = 0;
266 if (endaddr != NULL)
267 *endaddr = 0;
11c81455
JK
268 if (is_gnu_ifunc_p != NULL)
269 *is_gnu_ifunc_p = 0;
c906108c
SS
270 return 0;
271 }
272
c5aa993b 273 cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
3567439c 274 cache_pc_function_name = SYMBOL_LINKAGE_NAME (msymbol);
c906108c 275 cache_pc_function_section = section;
11c81455 276 cache_pc_function_is_gnu_ifunc = MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc;
c906108c 277
29e8a844
DJ
278 /* If the minimal symbol has a size, use it for the cache.
279 Otherwise use the lesser of the next minimal symbol in the same
280 section, or the end of the section, as the end of the
281 function. */
c5aa993b 282
29e8a844
DJ
283 if (MSYMBOL_SIZE (msymbol) != 0)
284 cache_pc_function_high = cache_pc_function_low + MSYMBOL_SIZE (msymbol);
285 else
c906108c 286 {
29e8a844
DJ
287 /* Step over other symbols at this same address, and symbols in
288 other sections, to find the next symbol in this section with
289 a different address. */
c906108c 290
3567439c 291 for (i = 1; SYMBOL_LINKAGE_NAME (msymbol + i) != NULL; i++)
29e8a844 292 {
3e43a32a
MS
293 if (SYMBOL_VALUE_ADDRESS (msymbol + i)
294 != SYMBOL_VALUE_ADDRESS (msymbol)
295 && SYMBOL_OBJ_SECTION (msymbol + i)
296 == SYMBOL_OBJ_SECTION (msymbol))
29e8a844
DJ
297 break;
298 }
299
3567439c 300 if (SYMBOL_LINKAGE_NAME (msymbol + i) != NULL
3e43a32a
MS
301 && SYMBOL_VALUE_ADDRESS (msymbol + i)
302 < obj_section_endaddr (section))
29e8a844
DJ
303 cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + i);
304 else
305 /* We got the start address from the last msymbol in the objfile.
306 So the end address is the end of the section. */
714835d5 307 cache_pc_function_high = obj_section_endaddr (section);
29e8a844 308 }
c906108c 309
247055de 310 return_cached_value:
c906108c
SS
311
312 if (address)
313 {
314 if (pc_in_unmapped_range (pc, section))
c5aa993b 315 *address = overlay_unmapped_address (cache_pc_function_low, section);
c906108c 316 else
c5aa993b 317 *address = cache_pc_function_low;
c906108c 318 }
c5aa993b 319
c906108c
SS
320 if (name)
321 *name = cache_pc_function_name;
322
323 if (endaddr)
324 {
325 if (pc_in_unmapped_range (pc, section))
c5aa993b 326 {
c906108c
SS
327 /* Because the high address is actually beyond the end of
328 the function (and therefore possibly beyond the end of
247055de 329 the overlay), we must actually convert (high - 1) and
4a64f543 330 then add one to that. */
c906108c 331
c5aa993b 332 *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1,
c906108c 333 section);
c5aa993b 334 }
c906108c 335 else
c5aa993b 336 *endaddr = cache_pc_function_high;
c906108c
SS
337 }
338
11c81455
JK
339 if (is_gnu_ifunc_p)
340 *is_gnu_ifunc_p = cache_pc_function_is_gnu_ifunc;
341
c906108c
SS
342 return 1;
343}
344
11c81455
JK
345/* See find_pc_partial_function_gnu_ifunc, only the IS_GNU_IFUNC_P parameter
346 is omitted here for backward API compatibility. */
347
348int
2c02bd72 349find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address,
11c81455
JK
350 CORE_ADDR *endaddr)
351{
352 return find_pc_partial_function_gnu_ifunc (pc, name, address, endaddr, NULL);
353}
354
72384ba3
PH
355/* Return the innermost stack frame that is executing inside of BLOCK and is
356 at least as old as the selected frame. Return NULL if there is no
357 such frame. If BLOCK is NULL, just return NULL. */
c906108c
SS
358
359struct frame_info *
9df2fbc4 360block_innermost_frame (const struct block *block)
c906108c
SS
361{
362 struct frame_info *frame;
c906108c
SS
363
364 if (block == NULL)
365 return NULL;
366
72384ba3
PH
367 frame = get_selected_frame_if_set ();
368 if (frame == NULL)
369 frame = get_current_frame ();
631b0ed0 370 while (frame != NULL)
c906108c 371 {
edb3359d
DJ
372 struct block *frame_block = get_frame_block (frame, NULL);
373 if (frame_block != NULL && contained_in (frame_block, block))
c906108c 374 return frame;
631b0ed0
JB
375
376 frame = get_prev_frame (frame);
c906108c 377 }
631b0ed0
JB
378
379 return NULL;
c906108c 380}
This page took 0.825446 seconds and 4 git commands to generate.