1130803Smarcel/* Code dealing with blocks for GDB. 2130803Smarcel 3130803Smarcel Copyright 2003 Free Software Foundation, Inc. 4130803Smarcel 5130803Smarcel This file is part of GDB. 6130803Smarcel 7130803Smarcel This program is free software; you can redistribute it and/or modify 8130803Smarcel it under the terms of the GNU General Public License as published by 9130803Smarcel the Free Software Foundation; either version 2 of the License, or 10130803Smarcel (at your option) any later version. 11130803Smarcel 12130803Smarcel This program is distributed in the hope that it will be useful, 13130803Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 14130803Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15130803Smarcel GNU General Public License for more details. 16130803Smarcel 17130803Smarcel You should have received a copy of the GNU General Public License 18130803Smarcel along with this program; if not, write to the Free Software 19130803Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 20130803Smarcel Boston, MA 02111-1307, USA. */ 21130803Smarcel 22130803Smarcel#ifndef BLOCK_H 23130803Smarcel#define BLOCK_H 24130803Smarcel 25130803Smarcel/* Opaque declarations. */ 26130803Smarcel 27130803Smarcelstruct symbol; 28130803Smarcelstruct symtab; 29130803Smarcelstruct block_namespace_info; 30130803Smarcelstruct using_direct; 31130803Smarcelstruct obstack; 32130803Smarcelstruct dictionary; 33130803Smarcel 34130803Smarcel/* All of the name-scope contours of the program 35130803Smarcel are represented by `struct block' objects. 36130803Smarcel All of these objects are pointed to by the blockvector. 37130803Smarcel 38130803Smarcel Each block represents one name scope. 39130803Smarcel Each lexical context has its own block. 40130803Smarcel 41130803Smarcel The blockvector begins with some special blocks. 42130803Smarcel The GLOBAL_BLOCK contains all the symbols defined in this compilation 43130803Smarcel whose scope is the entire program linked together. 44130803Smarcel The STATIC_BLOCK contains all the symbols whose scope is the 45130803Smarcel entire compilation excluding other separate compilations. 46130803Smarcel Blocks starting with the FIRST_LOCAL_BLOCK are not special. 47130803Smarcel 48130803Smarcel Each block records a range of core addresses for the code that 49130803Smarcel is in the scope of the block. The STATIC_BLOCK and GLOBAL_BLOCK 50130803Smarcel give, for the range of code, the entire range of code produced 51130803Smarcel by the compilation that the symbol segment belongs to. 52130803Smarcel 53130803Smarcel The blocks appear in the blockvector 54130803Smarcel in order of increasing starting-address, 55130803Smarcel and, within that, in order of decreasing ending-address. 56130803Smarcel 57130803Smarcel This implies that within the body of one function 58130803Smarcel the blocks appear in the order of a depth-first tree walk. */ 59130803Smarcel 60130803Smarcelstruct block 61130803Smarcel{ 62130803Smarcel 63130803Smarcel /* Addresses in the executable code that are in this block. */ 64130803Smarcel 65130803Smarcel CORE_ADDR startaddr; 66130803Smarcel CORE_ADDR endaddr; 67130803Smarcel 68130803Smarcel /* The symbol that names this block, if the block is the body of a 69130803Smarcel function; otherwise, zero. */ 70130803Smarcel 71130803Smarcel struct symbol *function; 72130803Smarcel 73130803Smarcel /* The `struct block' for the containing block, or 0 if none. 74130803Smarcel 75130803Smarcel The superblock of a top-level local block (i.e. a function in the 76130803Smarcel case of C) is the STATIC_BLOCK. The superblock of the 77130803Smarcel STATIC_BLOCK is the GLOBAL_BLOCK. */ 78130803Smarcel 79130803Smarcel struct block *superblock; 80130803Smarcel 81130803Smarcel /* This is used to store the symbols in the block. */ 82130803Smarcel 83130803Smarcel struct dictionary *dict; 84130803Smarcel 85130803Smarcel /* Used for language-specific info. */ 86130803Smarcel 87130803Smarcel union 88130803Smarcel { 89130803Smarcel struct 90130803Smarcel { 91130803Smarcel /* Contains information about namespace-related info relevant to 92130803Smarcel this block: using directives and the current namespace 93130803Smarcel scope. */ 94130803Smarcel 95130803Smarcel struct block_namespace_info *namespace; 96130803Smarcel } 97130803Smarcel cplus_specific; 98130803Smarcel } 99130803Smarcel language_specific; 100130803Smarcel 101130803Smarcel /* Version of GCC used to compile the function corresponding 102130803Smarcel to this block, or 0 if not compiled with GCC. When possible, 103130803Smarcel GCC should be compatible with the native compiler, or if that 104130803Smarcel is not feasible, the differences should be fixed during symbol 105130803Smarcel reading. As of 16 Apr 93, this flag is never used to distinguish 106130803Smarcel between gcc2 and the native compiler. 107130803Smarcel 108130803Smarcel If there is no function corresponding to this block, this meaning 109130803Smarcel of this flag is undefined. */ 110130803Smarcel 111130803Smarcel unsigned char gcc_compile_flag; 112130803Smarcel}; 113130803Smarcel 114130803Smarcel#define BLOCK_START(bl) (bl)->startaddr 115130803Smarcel#define BLOCK_END(bl) (bl)->endaddr 116130803Smarcel#define BLOCK_FUNCTION(bl) (bl)->function 117130803Smarcel#define BLOCK_SUPERBLOCK(bl) (bl)->superblock 118130803Smarcel#define BLOCK_GCC_COMPILED(bl) (bl)->gcc_compile_flag 119130803Smarcel#define BLOCK_DICT(bl) (bl)->dict 120130803Smarcel#define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace 121130803Smarcel 122130803Smarcel/* Macro to loop through all symbols in a block BL, in no particular 123130803Smarcel order. ITER helps keep track of the iteration, and should be a 124130803Smarcel struct dict_iterator. SYM points to the current symbol. */ 125130803Smarcel 126130803Smarcel#define ALL_BLOCK_SYMBOLS(block, iter, sym) \ 127130803Smarcel ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) 128130803Smarcel 129130803Smarcelstruct blockvector 130130803Smarcel{ 131130803Smarcel /* Number of blocks in the list. */ 132130803Smarcel int nblocks; 133130803Smarcel /* The blocks themselves. */ 134130803Smarcel struct block *block[1]; 135130803Smarcel}; 136130803Smarcel 137130803Smarcel#define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks 138130803Smarcel#define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n] 139130803Smarcel 140130803Smarcel/* Special block numbers */ 141130803Smarcel 142130803Smarcelenum { GLOBAL_BLOCK = 0, STATIC_BLOCK = 1, FIRST_LOCAL_BLOCK = 2 }; 143130803Smarcel 144130803Smarcelextern struct symbol *block_function (const struct block *); 145130803Smarcel 146130803Smarcelextern int contained_in (const struct block *, const struct block *); 147130803Smarcel 148130803Smarcelextern struct blockvector *blockvector_for_pc (CORE_ADDR, int *); 149130803Smarcel 150130803Smarcelextern struct blockvector *blockvector_for_pc_sect (CORE_ADDR, asection *, 151130803Smarcel int *, struct symtab *); 152130803Smarcel 153130803Smarcelextern struct block *block_for_pc (CORE_ADDR); 154130803Smarcel 155130803Smarcelextern struct block *block_for_pc_sect (CORE_ADDR, asection *); 156130803Smarcel 157130803Smarcelextern const char *block_scope (const struct block *block); 158130803Smarcel 159130803Smarcelextern void block_set_scope (struct block *block, const char *scope, 160130803Smarcel struct obstack *obstack); 161130803Smarcel 162130803Smarcelextern struct using_direct *block_using (const struct block *block); 163130803Smarcel 164130803Smarcelextern void block_set_using (struct block *block, 165130803Smarcel struct using_direct *using, 166130803Smarcel struct obstack *obstack); 167130803Smarcel 168130803Smarcelextern const struct block *block_static_block (const struct block *block); 169130803Smarcel 170130803Smarcelextern const struct block *block_global_block (const struct block *block); 171130803Smarcel 172130803Smarcelextern struct block *allocate_block (struct obstack *obstack); 173130803Smarcel 174130803Smarcel#endif /* BLOCK_H */ 175