Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: gdb/block.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/block.h ('k') | gdb/blockframe.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Block-related functions for the GNU debugger, GDB. 1 /* Block-related functions for the GNU debugger, GDB.
2 2
3 Copyright (C) 2003, 2007-2012 Free Software Foundation, Inc. 3 Copyright (C) 2003, 2007-2012 Free Software Foundation, Inc.
4 4
5 This file is part of GDB. 5 This file is part of GDB.
6 6
7 This program is free software; you can redistribute it and/or modify 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 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or 9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 97
98 /* Return one if BL represents an inlined function. */ 98 /* Return one if BL represents an inlined function. */
99 99
100 int 100 int
101 block_inlined_p (const struct block *bl) 101 block_inlined_p (const struct block *bl)
102 { 102 {
103 return BLOCK_FUNCTION (bl) != NULL && SYMBOL_INLINED (BLOCK_FUNCTION (bl)); 103 return BLOCK_FUNCTION (bl) != NULL && SYMBOL_INLINED (BLOCK_FUNCTION (bl));
104 } 104 }
105 105
106 /* Return the blockvector immediately containing the innermost lexical 106 /* A helper function that checks whether PC is in the blockvector BL.
107 block containing the specified pc value and section, or 0 if there 107 It returns the containing block if there is one, or else NULL. */
108 is none. PBLOCK is a pointer to the block. If PBLOCK is NULL, we
109 don't pass this information back to the caller. */
110 108
111 struct blockvector * 109 static struct block *
112 blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section, 110 find_block_in_blockvector (struct blockvector *bl, CORE_ADDR pc)
113 » » » struct block **pblock, struct symtab *symtab)
114 { 111 {
115 struct block *b; 112 struct block *b;
116 int bot, top, half; 113 int bot, top, half;
117 struct blockvector *bl;
118
119 if (symtab == 0) /* if no symtab specified by caller */
120 {
121 /* First search all symtabs for one whose file contains our pc */
122 symtab = find_pc_sect_symtab (pc, section);
123 if (symtab == 0)
124 return 0;
125 }
126
127 bl = BLOCKVECTOR (symtab);
128
129 /* Then search that symtab for the smallest block that wins. */
130 114
131 /* If we have an addrmap mapping code addresses to blocks, then use 115 /* If we have an addrmap mapping code addresses to blocks, then use
132 that. */ 116 that. */
133 if (BLOCKVECTOR_MAP (bl)) 117 if (BLOCKVECTOR_MAP (bl))
134 { 118 return addrmap_find (BLOCKVECTOR_MAP (bl), pc);
135 b = addrmap_find (BLOCKVECTOR_MAP (bl), pc);
136 if (b)
137 {
138 if (pblock)
139 *pblock = b;
140 return bl;
141 }
142 else
143 return 0;
144 }
145
146 119
147 /* Otherwise, use binary search to find the last block that starts 120 /* Otherwise, use binary search to find the last block that starts
148 before PC. */ 121 before PC.
149 bot = 0; 122 Note: GLOBAL_BLOCK is block 0, STATIC_BLOCK is block 1.
123 They both have the same START,END values.
124 Historically this code would choose STATIC_BLOCK over GLOBAL_BLOCK but the
125 fact that this choice was made was subtle, now we make it explicit. */
126 gdb_assert (BLOCKVECTOR_NBLOCKS (bl) >= 2);
127 bot = STATIC_BLOCK;
150 top = BLOCKVECTOR_NBLOCKS (bl); 128 top = BLOCKVECTOR_NBLOCKS (bl);
151 129
152 while (top - bot > 1) 130 while (top - bot > 1)
153 { 131 {
154 half = (top - bot + 1) >> 1; 132 half = (top - bot + 1) >> 1;
155 b = BLOCKVECTOR_BLOCK (bl, bot + half); 133 b = BLOCKVECTOR_BLOCK (bl, bot + half);
156 if (BLOCK_START (b) <= pc) 134 if (BLOCK_START (b) <= pc)
157 bot += half; 135 bot += half;
158 else 136 else
159 top = bot + half; 137 top = bot + half;
160 } 138 }
161 139
162 /* Now search backward for a block that ends after PC. */ 140 /* Now search backward for a block that ends after PC. */
163 141
164 while (bot >= 0) 142 while (bot >= STATIC_BLOCK)
165 { 143 {
166 b = BLOCKVECTOR_BLOCK (bl, bot); 144 b = BLOCKVECTOR_BLOCK (bl, bot);
167 if (BLOCK_END (b) > pc) 145 if (BLOCK_END (b) > pc)
168 » { 146 » return b;
169 » if (pblock)
170 » *pblock = b;
171 » return bl;
172 » }
173 bot--; 147 bot--;
174 } 148 }
175 return 0; 149
150 return NULL;
151 }
152
153 /* Return the blockvector immediately containing the innermost lexical
154 block containing the specified pc value and section, or 0 if there
155 is none. PBLOCK is a pointer to the block. If PBLOCK is NULL, we
156 don't pass this information back to the caller. */
157
158 struct blockvector *
159 blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section,
160 » » » struct block **pblock, struct symtab *symtab)
161 {
162 struct blockvector *bl;
163 struct block *b;
164
165 if (symtab == 0)» » /* if no symtab specified by caller */
166 {
167 /* First search all symtabs for one whose file contains our pc */
168 symtab = find_pc_sect_symtab (pc, section);
169 if (symtab == 0)
170 » return 0;
171 }
172
173 bl = BLOCKVECTOR (symtab);
174
175 /* Then search that symtab for the smallest block that wins. */
176 b = find_block_in_blockvector (bl, pc);
177 if (b == NULL)
178 return NULL;
179
180 if (pblock)
181 *pblock = b;
182 return bl;
183 }
184
185 /* Return true if the blockvector BV contains PC, false otherwise. */
186
187 int
188 blockvector_contains_pc (struct blockvector *bv, CORE_ADDR pc)
189 {
190 return find_block_in_blockvector (bv, pc) != NULL;
176 } 191 }
177 192
178 /* Return call_site for specified PC in GDBARCH. PC must match exactly, it 193 /* Return call_site for specified PC in GDBARCH. PC must match exactly, it
179 must be the next instruction after call (or after tail call jump). Throw 194 must be the next instruction after call (or after tail call jump). Throw
180 NO_ENTRY_VALUE_ERROR otherwise. This function never returns NULL. */ 195 NO_ENTRY_VALUE_ERROR otherwise. This function never returns NULL. */
181 196
182 struct call_site * 197 struct call_site *
183 call_site_for_pc (struct gdbarch *gdbarch, CORE_ADDR pc) 198 call_site_for_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
184 { 199 {
185 struct symtab *symtab; 200 struct symtab *symtab;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 377
363 BLOCK_START (bl) = 0; 378 BLOCK_START (bl) = 0;
364 BLOCK_END (bl) = 0; 379 BLOCK_END (bl) = 0;
365 BLOCK_FUNCTION (bl) = NULL; 380 BLOCK_FUNCTION (bl) = NULL;
366 BLOCK_SUPERBLOCK (bl) = NULL; 381 BLOCK_SUPERBLOCK (bl) = NULL;
367 BLOCK_DICT (bl) = NULL; 382 BLOCK_DICT (bl) = NULL;
368 BLOCK_NAMESPACE (bl) = NULL; 383 BLOCK_NAMESPACE (bl) = NULL;
369 384
370 return bl; 385 return bl;
371 } 386 }
387
388 /* Allocate a global block. */
389
390 struct block *
391 allocate_global_block (struct obstack *obstack)
392 {
393 struct global_block *bl = OBSTACK_ZALLOC (obstack, struct global_block);
394
395 return &bl->block;
396 }
397
398 /* Set the symtab of the global block. */
399
400 void
401 set_block_symtab (struct block *block, struct symtab *symtab)
402 {
403 struct global_block *gb;
404
405 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
406 gb = (struct global_block *) block;
407 gdb_assert (gb->symtab == NULL);
408 gb->symtab = symtab;
409 }
410
411 /* Return the symtab of the global block. */
412
413 static struct symtab *
414 get_block_symtab (const struct block *block)
415 {
416 struct global_block *gb;
417
418 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
419 gb = (struct global_block *) block;
420 gdb_assert (gb->symtab != NULL);
421 return gb->symtab;
422 }
423
424
425
426 /* Initialize a block iterator, either to iterate over a single block,
427 or, for static and global blocks, all the included symtabs as
428 well. */
429
430 static void
431 initialize_block_iterator (const struct block *block,
432 struct block_iterator *iter)
433 {
434 enum block_enum which;
435 struct symtab *symtab;
436
437 iter->idx = -1;
438
439 if (BLOCK_SUPERBLOCK (block) == NULL)
440 {
441 which = GLOBAL_BLOCK;
442 symtab = get_block_symtab (block);
443 }
444 else if (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL)
445 {
446 which = STATIC_BLOCK;
447 symtab = get_block_symtab (BLOCK_SUPERBLOCK (block));
448 }
449 else
450 {
451 iter->d.block = block;
452 /* A signal value meaning that we're iterating over a single
453 block. */
454 iter->which = FIRST_LOCAL_BLOCK;
455 return;
456 }
457
458 /* If this is an included symtab, find the canonical includer and
459 use it instead. */
460 while (symtab->user != NULL)
461 symtab = symtab->user;
462
463 /* Putting this check here simplifies the logic of the iterator
464 functions. If there are no included symtabs, we only need to
465 search a single block, so we might as well just do that
466 directly. */
467 if (symtab->includes == NULL)
468 {
469 iter->d.block = block;
470 /* A signal value meaning that we're iterating over a single
471 block. */
472 iter->which = FIRST_LOCAL_BLOCK;
473 }
474 else
475 {
476 iter->d.symtab = symtab;
477 iter->which = which;
478 }
479 }
480
481 /* A helper function that finds the current symtab over whose static
482 or global block we should iterate. */
483
484 static struct symtab *
485 find_iterator_symtab (struct block_iterator *iterator)
486 {
487 if (iterator->idx == -1)
488 return iterator->d.symtab;
489 return iterator->d.symtab->includes[iterator->idx];
490 }
491
492 /* Perform a single step for a plain block iterator, iterating across
493 symbol tables as needed. Returns the next symbol, or NULL when
494 iteration is complete. */
495
496 static struct symbol *
497 block_iterator_step (struct block_iterator *iterator, int first)
498 {
499 struct symbol *sym;
500
501 gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);
502
503 while (1)
504 {
505 if (first)
506 {
507 struct symtab *symtab = find_iterator_symtab (iterator);
508 const struct block *block;
509
510 /* Iteration is complete. */
511 if (symtab == NULL)
512 return NULL;
513
514 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), iterator->which);
515 sym = dict_iterator_first (BLOCK_DICT (block), &iterator->dict_iter);
516 }
517 else
518 sym = dict_iterator_next (&iterator->dict_iter);
519
520 if (sym != NULL)
521 return sym;
522
523 /* We have finished iterating the appropriate block of one
524 symtab. Now advance to the next symtab and begin iteration
525 there. */
526 ++iterator->idx;
527 first = 1;
528 }
529 }
530
531 /* See block.h. */
532
533 struct symbol *
534 block_iterator_first (const struct block *block,
535 struct block_iterator *iterator)
536 {
537 initialize_block_iterator (block, iterator);
538
539 if (iterator->which == FIRST_LOCAL_BLOCK)
540 return dict_iterator_first (block->dict, &iterator->dict_iter);
541
542 return block_iterator_step (iterator, 1);
543 }
544
545 /* See block.h. */
546
547 struct symbol *
548 block_iterator_next (struct block_iterator *iterator)
549 {
550 if (iterator->which == FIRST_LOCAL_BLOCK)
551 return dict_iterator_next (&iterator->dict_iter);
552
553 return block_iterator_step (iterator, 0);
554 }
555
556 /* Perform a single step for a "name" block iterator, iterating across
557 symbol tables as needed. Returns the next symbol, or NULL when
558 iteration is complete. */
559
560 static struct symbol *
561 block_iter_name_step (struct block_iterator *iterator, const char *name,
562 int first)
563 {
564 struct symbol *sym;
565
566 gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);
567
568 while (1)
569 {
570 if (first)
571 {
572 struct symtab *symtab = find_iterator_symtab (iterator);
573 const struct block *block;
574
575 /* Iteration is complete. */
576 if (symtab == NULL)
577 return NULL;
578
579 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), iterator->which);
580 sym = dict_iter_name_first (BLOCK_DICT (block), name,
581 &iterator->dict_iter);
582 }
583 else
584 sym = dict_iter_name_next (name, &iterator->dict_iter);
585
586 if (sym != NULL)
587 return sym;
588
589 /* We have finished iterating the appropriate block of one
590 symtab. Now advance to the next symtab and begin iteration
591 there. */
592 ++iterator->idx;
593 first = 1;
594 }
595 }
596
597 /* See block.h. */
598
599 struct symbol *
600 block_iter_name_first (const struct block *block,
601 const char *name,
602 struct block_iterator *iterator)
603 {
604 initialize_block_iterator (block, iterator);
605
606 if (iterator->which == FIRST_LOCAL_BLOCK)
607 return dict_iter_name_first (block->dict, name, &iterator->dict_iter);
608
609 return block_iter_name_step (iterator, name, 1);
610 }
611
612 /* See block.h. */
613
614 struct symbol *
615 block_iter_name_next (const char *name, struct block_iterator *iterator)
616 {
617 if (iterator->which == FIRST_LOCAL_BLOCK)
618 return dict_iter_name_next (name, &iterator->dict_iter);
619
620 return block_iter_name_step (iterator, name, 0);
621 }
622
623 /* Perform a single step for a "match" block iterator, iterating
624 across symbol tables as needed. Returns the next symbol, or NULL
625 when iteration is complete. */
626
627 static struct symbol *
628 block_iter_match_step (struct block_iterator *iterator,
629 const char *name,
630 symbol_compare_ftype *compare,
631 int first)
632 {
633 struct symbol *sym;
634
635 gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);
636
637 while (1)
638 {
639 if (first)
640 {
641 struct symtab *symtab = find_iterator_symtab (iterator);
642 const struct block *block;
643
644 /* Iteration is complete. */
645 if (symtab == NULL)
646 return NULL;
647
648 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), iterator->which);
649 sym = dict_iter_match_first (BLOCK_DICT (block), name,
650 compare, &iterator->dict_iter);
651 }
652 else
653 sym = dict_iter_match_next (name, compare, &iterator->dict_iter);
654
655 if (sym != NULL)
656 return sym;
657
658 /* We have finished iterating the appropriate block of one
659 symtab. Now advance to the next symtab and begin iteration
660 there. */
661 ++iterator->idx;
662 first = 1;
663 }
664 }
665
666 /* See block.h. */
667
668 struct symbol *
669 block_iter_match_first (const struct block *block,
670 const char *name,
671 symbol_compare_ftype *compare,
672 struct block_iterator *iterator)
673 {
674 initialize_block_iterator (block, iterator);
675
676 if (iterator->which == FIRST_LOCAL_BLOCK)
677 return dict_iter_match_first (block->dict, name, compare,
678 &iterator->dict_iter);
679
680 return block_iter_match_step (iterator, name, compare, 1);
681 }
682
683 /* See block.h. */
684
685 struct symbol *
686 block_iter_match_next (const char *name,
687 symbol_compare_ftype *compare,
688 struct block_iterator *iterator)
689 {
690 if (iterator->which == FIRST_LOCAL_BLOCK)
691 return dict_iter_match_next (name, compare, &iterator->dict_iter);
692
693 return block_iter_match_step (iterator, name, compare, 0);
694 }
OLDNEW
« no previous file with comments | « gdb/block.h ('k') | gdb/blockframe.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698