1 /* Get info from stack frames; 2 convert between frames, blocks, functions and pc values. 3 Copyright 1986, 1987, 1988, 1989, 1991, 1994, 1995, 1996 4 Free Software Foundation, Inc. 5 6 This file is part of GDB. 7 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 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 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. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 21 22 #include "defs.h" 23 #include "symtab.h" 24 #include "bfd.h" 25 #include "symfile.h" 26 #include "objfiles.h" 27 #include "frame.h" 28 #include "gdbcore.h" 29 #include "value.h" /* for read_register */ 30 #include "target.h" /* for target_has_stack */ 31 #include "inferior.h" /* for read_pc */ 32 #include "annotate.h" 33 34 /* Is ADDR inside the startup file? Note that if your machine 35 has a way to detect the bottom of the stack, there is no need 36 to call this function from FRAME_CHAIN_VALID; the reason for 37 doing so is that some machines have no way of detecting bottom 38 of stack. 39 40 A PC of zero is always considered to be the bottom of the stack. */ 41 42 int 43 inside_entry_file (addr) 44 CORE_ADDR addr; 45 { 46 if (addr == 0) 47 return 1; 48 if (symfile_objfile == 0) 49 return 0; 50 #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT 51 /* Do not stop backtracing if the pc is in the call dummy 52 at the entry point. */ 53 if (PC_IN_CALL_DUMMY (addr, 0, 0)) 54 return 0; 55 #endif 56 return (addr >= symfile_objfile -> ei.entry_file_lowpc && 57 addr < symfile_objfile -> ei.entry_file_highpc); 58 } 59 60 /* Test a specified PC value to see if it is in the range of addresses 61 that correspond to the main() function. See comments above for why 62 we might want to do this. 63 64 Typically called from FRAME_CHAIN_VALID. 65 66 A PC of zero is always considered to be the bottom of the stack. */ 67 68 int 69 inside_main_func (pc) 70 CORE_ADDR pc; 71 { 72 if (pc == 0) 73 return 1; 74 if (symfile_objfile == 0) 75 return 0; 76 77 /* If the addr range is not set up at symbol reading time, set it up now. 78 This is for FRAME_CHAIN_VALID_ALTERNATE. I do this for coff, because 79 it is unable to set it up and symbol reading time. */ 80 81 if (symfile_objfile -> ei.main_func_lowpc == INVALID_ENTRY_LOWPC && 82 symfile_objfile -> ei.main_func_highpc == INVALID_ENTRY_HIGHPC) 83 { 84 struct symbol *mainsym; 85 86 mainsym = lookup_symbol ("main", NULL, VAR_NAMESPACE, NULL, NULL); 87 if (mainsym && SYMBOL_CLASS(mainsym) == LOC_BLOCK) 88 { 89 symfile_objfile->ei.main_func_lowpc = BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym)); 90 symfile_objfile->ei.main_func_highpc = BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym)); 91 } 92 } 93 return (symfile_objfile -> ei.main_func_lowpc <= pc && 94 symfile_objfile -> ei.main_func_highpc > pc); 95 } 96 97 /* Test a specified PC value to see if it is in the range of addresses 98 that correspond to the process entry point function. See comments 99 in objfiles.h for why we might want to do this. 100 101 Typically called from FRAME_CHAIN_VALID. 102 103 A PC of zero is always considered to be the bottom of the stack. */ 104 105 int 106 inside_entry_func (pc) 107 CORE_ADDR pc; 108 { 109 if (pc == 0) 110 return 1; 111 if (symfile_objfile == 0) 112 return 0; 113 #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT 114 /* Do not stop backtracing if the pc is in the call dummy 115 at the entry point. */ 116 if (PC_IN_CALL_DUMMY (pc, 0, 0)) 117 return 0; 118 #endif 119 return (symfile_objfile -> ei.entry_func_lowpc <= pc && 120 symfile_objfile -> ei.entry_func_highpc > pc); 121 } 122 123 /* Info about the innermost stack frame (contents of FP register) */ 124 125 static struct frame_info *current_frame; 126 127 /* Cache for frame addresses already read by gdb. Valid only while 128 inferior is stopped. Control variables for the frame cache should 129 be local to this module. */ 130 131 struct obstack frame_cache_obstack; 132 133 /* Return the innermost (currently executing) stack frame. */ 134 135 struct frame_info * 136 get_current_frame () 137 { 138 if (current_frame == NULL) 139 { 140 if (target_has_stack) 141 current_frame = create_new_frame (read_fp (), read_pc ()); 142 else 143 error ("No stack."); 144 } 145 return current_frame; 146 } 147 148 void 149 set_current_frame (frame) 150 struct frame_info *frame; 151 { 152 current_frame = frame; 153 } 154 155 /* Create an arbitrary (i.e. address specified by user) or innermost frame. 156 Always returns a non-NULL value. */ 157 158 struct frame_info * 159 create_new_frame (addr, pc) 160 CORE_ADDR addr; 161 CORE_ADDR pc; 162 { 163 struct frame_info *fi; 164 char *name; 165 166 fi = (struct frame_info *) 167 obstack_alloc (&frame_cache_obstack, 168 sizeof (struct frame_info)); 169 170 /* Arbitrary frame */ 171 fi->next = NULL; 172 fi->prev = NULL; 173 fi->frame = addr; 174 fi->pc = pc; 175 find_pc_partial_function (pc, &name, (CORE_ADDR *)NULL,(CORE_ADDR *)NULL); 176 fi->signal_handler_caller = IN_SIGTRAMP (fi->pc, name); 177 178 #ifdef INIT_EXTRA_FRAME_INFO 179 INIT_EXTRA_FRAME_INFO (0, fi); 180 #endif 181 182 return fi; 183 } 184 185 /* Return the frame that called FI. 186 If FI is the original frame (it has no caller), return 0. */ 187 188 struct frame_info * 189 get_prev_frame (frame) 190 struct frame_info *frame; 191 { 192 return get_prev_frame_info (frame); 193 } 194 195 /* Return the frame that FRAME calls (NULL if FRAME is the innermost 196 frame). */ 197 198 struct frame_info * 199 get_next_frame (frame) 200 struct frame_info *frame; 201 { 202 return frame->next; 203 } 204 205 /* Flush the entire frame cache. */ 206 207 void 208 flush_cached_frames () 209 { 210 /* Since we can't really be sure what the first object allocated was */ 211 obstack_free (&frame_cache_obstack, 0); 212 obstack_init (&frame_cache_obstack); 213 214 current_frame = NULL; /* Invalidate cache */ 215 select_frame (NULL, -1); 216 annotate_frames_invalid (); 217 } 218 219 /* Flush the frame cache, and start a new one if necessary. */ 220 221 void 222 reinit_frame_cache () 223 { 224 flush_cached_frames (); 225 226 /* FIXME: The inferior_pid test is wrong if there is a corefile. */ 227 if (inferior_pid != 0) 228 { 229 select_frame (get_current_frame (), 0); 230 } 231 } 232 233 /* If a machine allows frameless functions, it should define a macro 234 FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) in param.h. FI is the struct 235 frame_info for the frame, and FRAMELESS should be set to nonzero 236 if it represents a frameless function invocation. */ 237 238 /* Return nonzero if the function for this frame lacks a prologue. Many 239 machines can define FRAMELESS_FUNCTION_INVOCATION to just call this 240 function. */ 241 242 int 243 frameless_look_for_prologue (frame) 244 struct frame_info *frame; 245 { 246 CORE_ADDR func_start, after_prologue; 247 func_start = get_pc_function_start (frame->pc); 248 if (func_start) 249 { 250 func_start += FUNCTION_START_OFFSET; 251 after_prologue = func_start; 252 #ifdef SKIP_PROLOGUE_FRAMELESS_P 253 /* This is faster, since only care whether there *is* a prologue, 254 not how long it is. */ 255 SKIP_PROLOGUE_FRAMELESS_P (after_prologue); 256 #else 257 SKIP_PROLOGUE (after_prologue); 258 #endif 259 return after_prologue == func_start; 260 } 261 else 262 /* If we can't find the start of the function, we don't really 263 know whether the function is frameless, but we should be able 264 to get a reasonable (i.e. best we can do under the 265 circumstances) backtrace by saying that it isn't. */ 266 return 0; 267 } 268 269 /* Default a few macros that people seldom redefine. */ 270 271 #if !defined (INIT_FRAME_PC) 272 #define INIT_FRAME_PC(fromleaf, prev) \ 273 prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \ 274 prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ()); 275 #endif 276 277 #ifndef FRAME_CHAIN_COMBINE 278 #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain) 279 #endif 280 281 /* Return a structure containing various interesting information 282 about the frame that called NEXT_FRAME. Returns NULL 283 if there is no such frame. */ 284 285 struct frame_info * 286 get_prev_frame_info (next_frame) 287 struct frame_info *next_frame; 288 { 289 CORE_ADDR address = 0; 290 struct frame_info *prev; 291 int fromleaf = 0; 292 char *name; 293 294 /* If the requested entry is in the cache, return it. 295 Otherwise, figure out what the address should be for the entry 296 we're about to add to the cache. */ 297 298 if (!next_frame) 299 { 300 #if 0 301 /* This screws value_of_variable, which just wants a nice clean 302 NULL return from block_innermost_frame if there are no frames. 303 I don't think I've ever seen this message happen otherwise. 304 And returning NULL here is a perfectly legitimate thing to do. */ 305 if (!current_frame) 306 { 307 error ("You haven't set up a process's stack to examine."); 308 } 309 #endif 310 311 return current_frame; 312 } 313 314 /* If we have the prev one, return it */ 315 if (next_frame->prev) 316 return next_frame->prev; 317 318 /* On some machines it is possible to call a function without 319 setting up a stack frame for it. On these machines, we 320 define this macro to take two args; a frameinfo pointer 321 identifying a frame and a variable to set or clear if it is 322 or isn't leafless. */ 323 #ifdef FRAMELESS_FUNCTION_INVOCATION 324 /* Still don't want to worry about this except on the innermost 325 frame. This macro will set FROMLEAF if NEXT_FRAME is a 326 frameless function invocation. */ 327 if (!(next_frame->next)) 328 { 329 FRAMELESS_FUNCTION_INVOCATION (next_frame, fromleaf); 330 if (fromleaf) 331 address = FRAME_FP (next_frame); 332 } 333 #endif 334 335 if (!fromleaf) 336 { 337 /* Two macros defined in tm.h specify the machine-dependent 338 actions to be performed here. 339 First, get the frame's chain-pointer. 340 If that is zero, the frame is the outermost frame or a leaf 341 called by the outermost frame. This means that if start 342 calls main without a frame, we'll return 0 (which is fine 343 anyway). 344 345 Nope; there's a problem. This also returns when the current 346 routine is a leaf of main. This is unacceptable. We move 347 this to after the ffi test; I'd rather have backtraces from 348 start go curfluy than have an abort called from main not show 349 main. */ 350 address = FRAME_CHAIN (next_frame); 351 if (!FRAME_CHAIN_VALID (address, next_frame)) 352 return 0; 353 address = FRAME_CHAIN_COMBINE (address, next_frame); 354 } 355 if (address == 0) 356 return 0; 357 358 prev = (struct frame_info *) 359 obstack_alloc (&frame_cache_obstack, 360 sizeof (struct frame_info)); 361 362 if (next_frame) 363 next_frame->prev = prev; 364 prev->next = next_frame; 365 prev->prev = (struct frame_info *) 0; 366 prev->frame = address; 367 prev->signal_handler_caller = 0; 368 369 /* This change should not be needed, FIXME! We should 370 determine whether any targets *need* INIT_FRAME_PC to happen 371 after INIT_EXTRA_FRAME_INFO and come up with a simple way to 372 express what goes on here. 373 374 INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame 375 (where the PC is already set up) and here (where it isn't). 376 INIT_FRAME_PC is only called from here, always after 377 INIT_EXTRA_FRAME_INFO. 378 379 The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the PC 380 value (which hasn't been set yet). Some other machines appear to 381 require INIT_EXTRA_FRAME_INFO before they can do INIT_FRAME_PC. Phoo. 382 383 We shouldn't need INIT_FRAME_PC_FIRST to add more complication to 384 an already overcomplicated part of GDB. gnu@cygnus.com, 15Sep92. 385 386 Assuming that some machines need INIT_FRAME_PC after 387 INIT_EXTRA_FRAME_INFO, one possible scheme: 388 389 SETUP_INNERMOST_FRAME() 390 Default version is just create_new_frame (read_fp ()), 391 read_pc ()). Machines with extra frame info would do that (or the 392 local equivalent) and then set the extra fields. 393 SETUP_ARBITRARY_FRAME(argc, argv) 394 Only change here is that create_new_frame would no longer init extra 395 frame info; SETUP_ARBITRARY_FRAME would have to do that. 396 INIT_PREV_FRAME(fromleaf, prev) 397 Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC. This should 398 also return a flag saying whether to keep the new frame, or 399 whether to discard it, because on some machines (e.g. mips) it 400 is really awkward to have FRAME_CHAIN_VALID called *before* 401 INIT_EXTRA_FRAME_INFO (there is no good way to get information 402 deduced in FRAME_CHAIN_VALID into the extra fields of the new frame). 403 std_frame_pc(fromleaf, prev) 404 This is the default setting for INIT_PREV_FRAME. It just does what 405 the default INIT_FRAME_PC does. Some machines will call it from 406 INIT_PREV_FRAME (either at the beginning, the end, or in the middle). 407 Some machines won't use it. 408 kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94. */ 409 410 #ifdef INIT_FRAME_PC_FIRST 411 INIT_FRAME_PC_FIRST (fromleaf, prev); 412 #endif 413 414 #ifdef INIT_EXTRA_FRAME_INFO 415 INIT_EXTRA_FRAME_INFO(fromleaf, prev); 416 #endif 417 418 /* This entry is in the frame queue now, which is good since 419 FRAME_SAVED_PC may use that queue to figure out its value 420 (see tm-sparc.h). We want the pc saved in the inferior frame. */ 421 INIT_FRAME_PC(fromleaf, prev); 422 423 /* If ->frame and ->pc are unchanged, we are in the process of getting 424 ourselves into an infinite backtrace. Some architectures check this 425 in FRAME_CHAIN or thereabouts, but it seems like there is no reason 426 this can't be an architecture-independent check. */ 427 if (next_frame != NULL) 428 { 429 if (prev->frame == next_frame->frame 430 && prev->pc == next_frame->pc) 431 { 432 next_frame->prev = NULL; 433 obstack_free (&frame_cache_obstack, prev); 434 return NULL; 435 } 436 } 437 438 find_pc_partial_function (prev->pc, &name, 439 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL); 440 if (IN_SIGTRAMP (prev->pc, name)) 441 prev->signal_handler_caller = 1; 442 443 return prev; 444 } 445 446 CORE_ADDR 447 get_frame_pc (frame) 448 struct frame_info *frame; 449 { 450 return frame->pc; 451 } 452 453 #if defined (FRAME_FIND_SAVED_REGS) 454 /* Find the addresses in which registers are saved in FRAME. */ 455 456 void 457 get_frame_saved_regs (frame, saved_regs_addr) 458 struct frame_info *frame; 459 struct frame_saved_regs *saved_regs_addr; 460 { 461 FRAME_FIND_SAVED_REGS (frame, *saved_regs_addr); 462 } 463 #endif 464 465 /* Return the innermost lexical block in execution 466 in a specified stack frame. The frame address is assumed valid. */ 467 468 struct block * 469 get_frame_block (frame) 470 struct frame_info *frame; 471 { 472 CORE_ADDR pc; 473 474 pc = frame->pc; 475 if (frame->next != 0 && frame->next->signal_handler_caller == 0) 476 /* We are not in the innermost frame and we were not interrupted 477 by a signal. We need to subtract one to get the correct block, 478 in case the call instruction was the last instruction of the block. 479 If there are any machines on which the saved pc does not point to 480 after the call insn, we probably want to make frame->pc point after 481 the call insn anyway. */ 482 --pc; 483 return block_for_pc (pc); 484 } 485 486 struct block * 487 get_current_block () 488 { 489 return block_for_pc (read_pc ()); 490 } 491 492 CORE_ADDR 493 get_pc_function_start (pc) 494 CORE_ADDR pc; 495 { 496 register struct block *bl; 497 register struct symbol *symbol; 498 register struct minimal_symbol *msymbol; 499 CORE_ADDR fstart; 500 501 if ((bl = block_for_pc (pc)) != NULL && 502 (symbol = block_function (bl)) != NULL) 503 { 504 bl = SYMBOL_BLOCK_VALUE (symbol); 505 fstart = BLOCK_START (bl); 506 } 507 else if ((msymbol = lookup_minimal_symbol_by_pc (pc)) != NULL) 508 { 509 fstart = SYMBOL_VALUE_ADDRESS (msymbol); 510 } 511 else 512 { 513 fstart = 0; 514 } 515 return (fstart); 516 } 517 518 /* Return the symbol for the function executing in frame FRAME. */ 519 520 struct symbol * 521 get_frame_function (frame) 522 struct frame_info *frame; 523 { 524 register struct block *bl = get_frame_block (frame); 525 if (bl == 0) 526 return 0; 527 return block_function (bl); 528 } 529 530 /* Return the blockvector immediately containing the innermost lexical block 531 containing the specified pc value, or 0 if there is none. 532 PINDEX is a pointer to the index value of the block. If PINDEX 533 is NULL, we don't pass this information back to the caller. */ 534 535 struct blockvector * 536 blockvector_for_pc (pc, pindex) 537 register CORE_ADDR pc; 538 int *pindex; 539 { 540 register struct block *b; 541 register int bot, top, half; 542 register struct symtab *s; 543 struct blockvector *bl; 544 545 /* First search all symtabs for one whose file contains our pc */ 546 s = find_pc_symtab (pc); 547 if (s == 0) 548 return 0; 549 550 bl = BLOCKVECTOR (s); 551 b = BLOCKVECTOR_BLOCK (bl, 0); 552 553 /* Then search that symtab for the smallest block that wins. */ 554 /* Use binary search to find the last block that starts before PC. */ 555 556 bot = 0; 557 top = BLOCKVECTOR_NBLOCKS (bl); 558 559 while (top - bot > 1) 560 { 561 half = (top - bot + 1) >> 1; 562 b = BLOCKVECTOR_BLOCK (bl, bot + half); 563 if (BLOCK_START (b) <= pc) 564 bot += half; 565 else 566 top = bot + half; 567 } 568 569 /* Now search backward for a block that ends after PC. */ 570 571 while (bot >= 0) 572 { 573 b = BLOCKVECTOR_BLOCK (bl, bot); 574 if (BLOCK_END (b) > pc) 575 { 576 if (pindex) 577 *pindex = bot; 578 return bl; 579 } 580 bot--; 581 } 582 583 return 0; 584 } 585 586 /* Return the innermost lexical block containing the specified pc value, 587 or 0 if there is none. */ 588 589 struct block * 590 block_for_pc (pc) 591 register CORE_ADDR pc; 592 { 593 register struct blockvector *bl; 594 int index; 595 596 bl = blockvector_for_pc (pc, &index); 597 if (bl) 598 return BLOCKVECTOR_BLOCK (bl, index); 599 return 0; 600 } 601 602 /* Return the function containing pc value PC. 603 Returns 0 if function is not known. */ 604 605 struct symbol * 606 find_pc_function (pc) 607 CORE_ADDR pc; 608 { 609 register struct block *b = block_for_pc (pc); 610 if (b == 0) 611 return 0; 612 return block_function (b); 613 } 614 615 /* These variables are used to cache the most recent result 616 * of find_pc_partial_function. */ 617 618 static CORE_ADDR cache_pc_function_low = 0; 619 static CORE_ADDR cache_pc_function_high = 0; 620 static char *cache_pc_function_name = 0; 621 622 /* Clear cache, e.g. when symbol table is discarded. */ 623 624 void 625 clear_pc_function_cache() 626 { 627 cache_pc_function_low = 0; 628 cache_pc_function_high = 0; 629 cache_pc_function_name = (char *)0; 630 } 631 632 /* Finds the "function" (text symbol) that is smaller than PC but 633 greatest of all of the potential text symbols. Sets *NAME and/or 634 *ADDRESS conditionally if that pointer is non-null. If ENDADDR is 635 non-null, then set *ENDADDR to be the end of the function 636 (exclusive), but passing ENDADDR as non-null means that the 637 function might cause symbols to be read. This function either 638 succeeds or fails (not halfway succeeds). If it succeeds, it sets 639 *NAME, *ADDRESS, and *ENDADDR to real information and returns 1. 640 If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero 641 and returns 0. */ 642 643 int 644 find_pc_partial_function (pc, name, address, endaddr) 645 CORE_ADDR pc; 646 char **name; 647 CORE_ADDR *address; 648 CORE_ADDR *endaddr; 649 { 650 struct partial_symtab *pst; 651 struct symbol *f; 652 struct minimal_symbol *msymbol; 653 struct partial_symbol *psb; 654 struct obj_section *sec; 655 656 if (pc >= cache_pc_function_low && pc < cache_pc_function_high) 657 goto return_cached_value; 658 659 /* If sigtramp is in the u area, it counts as a function (especially 660 important for step_1). */ 661 #if defined SIGTRAMP_START 662 if (IN_SIGTRAMP (pc, (char *)NULL)) 663 { 664 cache_pc_function_low = SIGTRAMP_START (pc); 665 cache_pc_function_high = SIGTRAMP_END (pc); 666 cache_pc_function_name = "<sigtramp>"; 667 668 goto return_cached_value; 669 } 670 #endif 671 672 msymbol = lookup_minimal_symbol_by_pc (pc); 673 pst = find_pc_psymtab (pc); 674 if (pst) 675 { 676 /* Need to read the symbols to get a good value for the end address. */ 677 if (endaddr != NULL && !pst->readin) 678 { 679 /* Need to get the terminal in case symbol-reading produces 680 output. */ 681 target_terminal_ours_for_output (); 682 PSYMTAB_TO_SYMTAB (pst); 683 } 684 685 if (pst->readin) 686 { 687 /* Checking whether the msymbol has a larger value is for the 688 "pathological" case mentioned in print_frame_info. */ 689 f = find_pc_function (pc); 690 if (f != NULL 691 && (msymbol == NULL 692 || (BLOCK_START (SYMBOL_BLOCK_VALUE (f)) 693 >= SYMBOL_VALUE_ADDRESS (msymbol)))) 694 { 695 cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f)); 696 cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f)); 697 cache_pc_function_name = SYMBOL_NAME (f); 698 goto return_cached_value; 699 } 700 } 701 else 702 { 703 /* Now that static symbols go in the minimal symbol table, perhaps 704 we could just ignore the partial symbols. But at least for now 705 we use the partial or minimal symbol, whichever is larger. */ 706 psb = find_pc_psymbol (pst, pc); 707 708 if (psb 709 && (msymbol == NULL || 710 (SYMBOL_VALUE_ADDRESS (psb) 711 >= SYMBOL_VALUE_ADDRESS (msymbol)))) 712 { 713 /* This case isn't being cached currently. */ 714 if (address) 715 *address = SYMBOL_VALUE_ADDRESS (psb); 716 if (name) 717 *name = SYMBOL_NAME (psb); 718 /* endaddr non-NULL can't happen here. */ 719 return 1; 720 } 721 } 722 } 723 724 /* Not in the normal symbol tables, see if the pc is in a known section. 725 If it's not, then give up. This ensures that anything beyond the end 726 of the text seg doesn't appear to be part of the last function in the 727 text segment. */ 728 729 sec = find_pc_section (pc); 730 731 if (!sec) 732 msymbol = NULL; 733 734 /* Must be in the minimal symbol table. */ 735 if (msymbol == NULL) 736 { 737 /* No available symbol. */ 738 if (name != NULL) 739 *name = 0; 740 if (address != NULL) 741 *address = 0; 742 if (endaddr != NULL) 743 *endaddr = 0; 744 return 0; 745 } 746 747 cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol); 748 cache_pc_function_name = SYMBOL_NAME (msymbol); 749 750 /* Use the lesser of the next minimal symbol, or the end of the section, as 751 the end of the function. */ 752 753 if (SYMBOL_NAME (msymbol + 1) != NULL 754 && SYMBOL_VALUE_ADDRESS (msymbol + 1) < sec->endaddr) 755 cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + 1); 756 else 757 /* We got the start address from the last msymbol in the objfile. 758 So the end address is the end of the section. */ 759 cache_pc_function_high = sec->endaddr; 760 761 return_cached_value: 762 if (address) 763 *address = cache_pc_function_low; 764 if (name) 765 *name = cache_pc_function_name; 766 if (endaddr) 767 *endaddr = cache_pc_function_high; 768 return 1; 769 } 770 771 /* Return the innermost stack frame executing inside of BLOCK, 772 or NULL if there is no such frame. If BLOCK is NULL, just return NULL. */ 773 774 struct frame_info * 775 block_innermost_frame (block) 776 struct block *block; 777 { 778 struct frame_info *frame; 779 register CORE_ADDR start; 780 register CORE_ADDR end; 781 782 if (block == NULL) 783 return NULL; 784 785 start = BLOCK_START (block); 786 end = BLOCK_END (block); 787 788 frame = NULL; 789 while (1) 790 { 791 frame = get_prev_frame (frame); 792 if (frame == NULL) 793 return NULL; 794 if (frame->pc >= start && frame->pc < end) 795 return frame; 796 } 797 } 798 799 /* Return the full FRAME which corresponds to the given CORE_ADDR 800 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */ 801 802 struct frame_info * 803 find_frame_addr_in_frame_chain (frame_addr) 804 CORE_ADDR frame_addr; 805 { 806 struct frame_info *frame = NULL; 807 808 if (frame_addr == (CORE_ADDR)0) 809 return NULL; 810 811 while (1) 812 { 813 frame = get_prev_frame (frame); 814 if (frame == NULL) 815 return NULL; 816 if (FRAME_FP (frame) == frame_addr) 817 return frame; 818 } 819 } 820 821 #ifdef SIGCONTEXT_PC_OFFSET 822 /* Get saved user PC for sigtramp from sigcontext for BSD style sigtramp. */ 823 824 CORE_ADDR 825 sigtramp_saved_pc (frame) 826 struct frame_info *frame; 827 { 828 CORE_ADDR sigcontext_addr; 829 char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT]; 830 int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT; 831 int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT; 832 833 /* Get sigcontext address, it is the third parameter on the stack. */ 834 if (frame->next) 835 sigcontext_addr = read_memory_integer (FRAME_ARGS_ADDRESS (frame->next) 836 + FRAME_ARGS_SKIP 837 + sigcontext_offs, 838 ptrbytes); 839 else 840 sigcontext_addr = read_memory_integer (read_register (SP_REGNUM) 841 + sigcontext_offs, 842 ptrbytes); 843 844 /* Don't cause a memory_error when accessing sigcontext in case the stack 845 layout has changed or the stack is corrupt. */ 846 target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes); 847 return extract_unsigned_integer (buf, ptrbytes); 848 } 849 #endif /* SIGCONTEXT_PC_OFFSET */ 850 851 void 852 _initialize_blockframe () 853 { 854 obstack_init (&frame_cache_obstack); 855 } 856