148861Sbostic /*- 248862Sbostic * 348862Sbostic * This code is derived from software copyrighted by the Free Software 448862Sbostic * Foundation. 548862Sbostic * 6*62051Sbostic * @(#)symseg.h 8.1 (Berkeley) 06/06/93 748861Sbostic */ 848861Sbostic 948852Sbostic /* GDB symbol table format definitions. 1048852Sbostic Copyright (C) 1987, 1988 Free Software Foundation, Inc. 1148852Sbostic 1248852Sbostic This file is part of GNU CC. 1348852Sbostic 1448852Sbostic GNU CC is free software; you can redistribute it and/or modify 1548852Sbostic it under the terms of the GNU General Public License as published by 1648852Sbostic the Free Software Foundation; either version 1, or (at your option) 1748852Sbostic any later version. 1848852Sbostic 1948852Sbostic GNU CC is distributed in the hope that it will be useful, 2048852Sbostic but WITHOUT ANY WARRANTY; without even the implied warranty of 2148852Sbostic MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2248852Sbostic GNU General Public License for more details. 2348852Sbostic 2448852Sbostic You should have received a copy of the GNU General Public License 2548852Sbostic along with GNU CC; see the file COPYING. If not, write to 2648852Sbostic the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 2748852Sbostic 2848852Sbostic /* Format of GDB symbol table data. 2948852Sbostic There is one symbol segment for each source file or 3048852Sbostic independant compilation. These segments are simply concatenated 3148852Sbostic to form the GDB symbol table. A zero word where the beginning 3248852Sbostic of a segment is expected indicates there are no more segments. 3348852Sbostic 3448852Sbostic Format of a symbol segment: 3548852Sbostic 3648852Sbostic The symbol segment begins with a word containing 1 3748852Sbostic if it is in the format described here. Other formats may 3848852Sbostic be designed, with other code numbers. 3948852Sbostic 4048852Sbostic The segment contains many objects which point at each other. 4148852Sbostic The pointers are offsets in bytes from the beginning of the segment. 4248852Sbostic Thus, each segment can be loaded into core and its pointers relocated 4348852Sbostic to make valid in-core pointers. 4448852Sbostic 4548852Sbostic All the data objects in the segment can be found indirectly from 4648852Sbostic one of them, the root object, of type `struct symbol_root'. 4748852Sbostic It appears at the beginning of the segment. 4848852Sbostic 4948852Sbostic The total size of the segment, in bytes, appears as the `length' 5048852Sbostic field of this object. This size includes the size of the 5148852Sbostic root object. 5248852Sbostic 5348852Sbostic All the object data types are defined here to contain pointer types 5448852Sbostic appropriate for in-core use on a relocated symbol segment. 5548852Sbostic Casts to and from type int are required for working with 5648852Sbostic unrelocated symbol segments such as are found in the file. 5748852Sbostic 5848852Sbostic The ldsymaddr word is filled in by the loader to contain 5948852Sbostic the offset (in bytes) within the ld symbol table 6048852Sbostic of the first nonglobal symbol from this compilation. 6148852Sbostic This makes it possible to match those symbols 6248852Sbostic (which contain line number information) reliably with 6348852Sbostic the segment they go with. 6448852Sbostic 6548852Sbostic Core addresses within the program that appear in the symbol segment 6648852Sbostic are not relocated by the loader. They are inserted by the assembler 6748852Sbostic and apply to addresses as output by the assembler, so GDB must 6848852Sbostic relocate them when it loads the symbol segment. It gets the information 6948852Sbostic on how to relocate from the textrel, datarel, bssrel, databeg and bssbeg 7048852Sbostic words of the root object. 7148852Sbostic 7248852Sbostic The words textrel, datarel and bssrel 7348852Sbostic are filled in by ld with the amounts to relocate within-the-file 7448852Sbostic text, data and bss addresses by; databeg and bssbeg can be 7548852Sbostic used to tell which kind of relocation an address needs. */ 7648852Sbostic 7748852Sbostic enum language {language_c}; 7848852Sbostic 7948852Sbostic struct symbol_root 8048852Sbostic { 8148852Sbostic int format; /* Data format version */ 8248852Sbostic int length; /* # bytes in this symbol segment */ 8348852Sbostic int ldsymoff; /* Offset in ld symtab of this file's syms */ 8448852Sbostic int textrel; /* Relocation for text addresses */ 8548852Sbostic int datarel; /* Relocation for data addresses */ 8648852Sbostic int bssrel; /* Relocation for bss addresses */ 8748852Sbostic char *filename; /* Name of main source file compiled */ 8848852Sbostic char *filedir; /* Name of directory it was reached from */ 8948852Sbostic struct blockvector *blockvector; /* Vector of all symbol-naming blocks */ 9048852Sbostic struct typevector *typevector; /* Vector of all data types */ 9148852Sbostic enum language language; /* Code identifying the language used */ 9248852Sbostic char *version; /* Version info. Not fully specified */ 9348852Sbostic char *compilation; /* Compilation info. Not fully specified */ 9448852Sbostic int databeg; /* Address within the file of data start */ 9548852Sbostic int bssbeg; /* Address within the file of bss start */ 9648852Sbostic struct sourcevector *sourcevector; /* Vector of line-number info */ 9748852Sbostic }; 9848852Sbostic 9948852Sbostic /* All data types of symbols in the compiled program 10048852Sbostic are represented by `struct type' objects. 10148852Sbostic All of these objects are pointed to by the typevector. 10248852Sbostic The type vector may have empty slots that contain zero. */ 10348852Sbostic 10448852Sbostic struct typevector 10548852Sbostic { 10648852Sbostic int length; /* Number of types described */ 10748852Sbostic struct type *type[1]; 10848852Sbostic }; 10948852Sbostic 11048852Sbostic /* Different kinds of data types are distinguished by the `code' field. */ 11148852Sbostic 11248852Sbostic enum type_code 11348852Sbostic { 11448852Sbostic TYPE_CODE_UNDEF, /* Not used; catches errors */ 11548852Sbostic TYPE_CODE_PTR, /* Pointer type */ 11648852Sbostic TYPE_CODE_ARRAY, /* Array type, lower bound zero */ 11748852Sbostic TYPE_CODE_STRUCT, /* C struct or Pascal record */ 11848852Sbostic TYPE_CODE_UNION, /* C union or Pascal variant part */ 11948852Sbostic TYPE_CODE_ENUM, /* Enumeration type */ 12048852Sbostic TYPE_CODE_FUNC, /* Function type */ 12148852Sbostic TYPE_CODE_INT, /* Integer type */ 12248852Sbostic TYPE_CODE_FLT, /* Floating type */ 12348852Sbostic TYPE_CODE_VOID, /* Void type (values zero length) */ 12448852Sbostic TYPE_CODE_SET, /* Pascal sets */ 12548852Sbostic TYPE_CODE_RANGE, /* Range (integers within spec'd bounds) */ 12648852Sbostic TYPE_CODE_PASCAL_ARRAY, /* Array with explicit type of index */ 12748852Sbostic }; 12848852Sbostic 12948852Sbostic /* This appears in a type's flags word for an unsigned integer type. */ 13048852Sbostic #define TYPE_FLAG_UNSIGNED 1 13148852Sbostic 13248852Sbostic /* Other flag bits are used with GDB. */ 13348852Sbostic 13448852Sbostic struct type 13548852Sbostic { 13648852Sbostic /* Code for kind of type */ 13748852Sbostic enum type_code code; 13848852Sbostic /* Name of this type, or zero if none. 13948852Sbostic This is used for printing only. 14048852Sbostic Type names specified as input are defined by symbols. */ 14148852Sbostic char *name; 14248852Sbostic /* Length in bytes of storage for a value of this type */ 14348852Sbostic int length; 14448852Sbostic /* For a pointer type, describes the type of object pointed to. 14548852Sbostic For an array type, describes the type of the elements. 14648852Sbostic For a function type, describes the type of the value. 14748852Sbostic Unused otherwise. */ 14848852Sbostic struct type *target_type; 14948852Sbostic /* Type that is a pointer to this type. 15048852Sbostic Zero if no such pointer-to type is known yet. 15148852Sbostic The debugger may add the address of such a type 15248852Sbostic if it has to construct one later. */ 15348852Sbostic struct type *pointer_type; 15448852Sbostic /* Type that is a function returning this type. 15548852Sbostic Zero if no such function type is known here. 15648852Sbostic The debugger may add the address of such a type 15748852Sbostic if it has to construct one later. */ 15848852Sbostic struct type *function_type; 15948852Sbostic /* Flags about this type. */ 16048852Sbostic short flags; 16148852Sbostic /* Number of fields described for this type */ 16248852Sbostic short nfields; 16348852Sbostic /* For structure and union types, a description of each field. 16448852Sbostic For set and pascal array types, there is one "field", 16548852Sbostic whose type is the domain type of the set or array. 16648852Sbostic For range types, there are two "fields", 16748852Sbostic the minimum and maximum values (both inclusive). 16848852Sbostic For enum types, each possible value is described by one "field". 16948852Sbostic For range types, there are two "fields", that record constant values 17048852Sbostic (inclusive) for the minimum and maximum. 17148852Sbostic 17248852Sbostic Using a pointer to a separate array of fields 17348852Sbostic allows all types to have the same size, which is useful 17448852Sbostic because we can allocate the space for a type before 17548852Sbostic we know what to put in it. */ 17648852Sbostic struct field 17748852Sbostic { 17848852Sbostic /* Position of this field, counting in bits from start of 17948852Sbostic containing structure. For a function type, this is the 18048852Sbostic position in the argument list of this argument. 18148852Sbostic For a range bound or enum value, this is the value itself. */ 18248852Sbostic int bitpos; 18348852Sbostic /* Size of this field, in bits, or zero if not packed. 18448852Sbostic For an unpacked field, the field's type's length 18548852Sbostic says how many bytes the field occupies. */ 18648852Sbostic int bitsize; 18748852Sbostic /* In a struct or enum type, type of this field. 18848852Sbostic In a function type, type of this argument. 18948852Sbostic In an array type, the domain-type of the array. */ 19048852Sbostic struct type *type; 19148852Sbostic /* Name of field, value or argument. 19248852Sbostic Zero for range bounds and array domains. */ 19348852Sbostic char *name; 19448852Sbostic } *fields; 19548852Sbostic }; 19648852Sbostic 19748852Sbostic /* All of the name-scope contours of the program 19848852Sbostic are represented by `struct block' objects. 19948852Sbostic All of these objects are pointed to by the blockvector. 20048852Sbostic 20148852Sbostic Each block represents one name scope. 20248852Sbostic Each lexical context has its own block. 20348852Sbostic 20448852Sbostic The first two blocks in the blockvector are special. 20548852Sbostic The first one contains all the symbols defined in this compilation 20648852Sbostic whose scope is the entire program linked together. 20748852Sbostic The second one contains all the symbols whose scope is the 20848852Sbostic entire compilation excluding other separate compilations. 20948852Sbostic In C, these correspond to global symbols and static symbols. 21048852Sbostic 21148852Sbostic Each block records a range of core addresses for the code that 21248852Sbostic is in the scope of the block. The first two special blocks 21348852Sbostic give, for the range of code, the entire range of code produced 21448852Sbostic by the compilation that the symbol segment belongs to. 21548852Sbostic 21648852Sbostic The blocks appear in the blockvector 21748852Sbostic in order of increasing starting-address, 21848852Sbostic and, within that, in order of decreasing ending-address. 21948852Sbostic 22048852Sbostic This implies that within the body of one function 22148852Sbostic the blocks appear in the order of a depth-first tree walk. */ 22248852Sbostic 22348852Sbostic struct blockvector 22448852Sbostic { 22548852Sbostic /* Number of blocks in the list. */ 22648852Sbostic int nblocks; 22748852Sbostic /* The blocks themselves. */ 22848852Sbostic struct block *block[1]; 22948852Sbostic }; 23048852Sbostic 23148852Sbostic struct block 23248852Sbostic { 23348852Sbostic /* Addresses in the executable code that are in this block. 23448852Sbostic Note: in an unrelocated symbol segment in a file, 23548852Sbostic these are always zero. They can be filled in from the 23648852Sbostic N_LBRAC and N_RBRAC symbols in the loader symbol table. */ 23748852Sbostic int startaddr, endaddr; 23848852Sbostic /* The symbol that names this block, 23948852Sbostic if the block is the body of a function; 24048852Sbostic otherwise, zero. 24148852Sbostic Note: In an unrelocated symbol segment in an object file, 24248852Sbostic this field may be zero even when the block has a name. 24348852Sbostic That is because the block is output before the name 24448852Sbostic (since the name resides in a higher block). 24548852Sbostic Since the symbol does point to the block (as its value), 24648852Sbostic it is possible to find the block and set its name properly. */ 24748852Sbostic struct symbol *function; 24848852Sbostic /* The `struct block' for the containing block, or 0 if none. */ 24948852Sbostic /* Note that in an unrelocated symbol segment in an object file 25048852Sbostic this pointer may be zero when the correct value should be 25148852Sbostic the second special block (for symbols whose scope is one compilation). 25248852Sbostic This is because the compiler ouptuts the special blocks at the 25348852Sbostic very end, after the other blocks. */ 25448852Sbostic struct block *superblock; 25548852Sbostic /* Number of local symbols. */ 25648852Sbostic int nsyms; 25748852Sbostic /* The symbols. */ 25848852Sbostic struct symbol *sym[1]; 25948852Sbostic }; 26048852Sbostic 26148852Sbostic /* Represent one symbol name; a variable, constant, function or typedef. */ 26248852Sbostic 26348852Sbostic /* Different name spaces for symbols. Looking up a symbol specifies 26448852Sbostic a namespace and ignores symbol definitions in other name spaces. 26548852Sbostic 26648852Sbostic VAR_NAMESPACE is the usual namespace. 26748852Sbostic In C, this contains variables, function names, typedef names 26848852Sbostic and enum type values. 26948852Sbostic 27048852Sbostic STRUCT_NAMESPACE is used in C to hold struct, union and enum type names. 27148852Sbostic Thus, if `struct foo' is used in a C program, 27248852Sbostic it produces a symbol named `foo' in the STRUCT_NAMESPACE. 27348852Sbostic 27448852Sbostic LABEL_NAMESPACE may be used for names of labels (for gotos); 27548852Sbostic currently it is not used and labels are not recorded at all. */ 27648852Sbostic 27748852Sbostic /* For a non-global symbol allocated statically, 27848852Sbostic the correct core address cannot be determined by the compiler. 27948852Sbostic The compiler puts an index number into the symbol's value field. 28048852Sbostic This index number can be matched with the "desc" field of 28148852Sbostic an entry in the loader symbol table. */ 28248852Sbostic 28348852Sbostic enum namespace 28448852Sbostic { 28548852Sbostic UNDEF_NAMESPACE, VAR_NAMESPACE, STRUCT_NAMESPACE, LABEL_NAMESPACE, 28648852Sbostic }; 28748852Sbostic 28848852Sbostic /* An address-class says where to find the value of the symbol in core. */ 28948852Sbostic 29048852Sbostic enum address_class 29148852Sbostic { 29248852Sbostic LOC_UNDEF, /* Not used; catches errors */ 29348852Sbostic LOC_CONST, /* Value is constant int */ 29448852Sbostic LOC_STATIC, /* Value is at fixed address */ 29548852Sbostic LOC_REGISTER, /* Value is in register */ 29648852Sbostic LOC_ARG, /* Value is at spec'd position in arglist */ 29748852Sbostic LOC_LOCAL, /* Value is at spec'd pos in stack frame */ 29848852Sbostic LOC_TYPEDEF, /* Value not used; definition in SYMBOL_TYPE 29948852Sbostic Symbols in the namespace STRUCT_NAMESPACE 30048852Sbostic all have this class. */ 30148852Sbostic LOC_LABEL, /* Value is address in the code */ 30248852Sbostic LOC_BLOCK, /* Value is address of a `struct block'. 30348852Sbostic Function names have this class. */ 30448852Sbostic LOC_EXTERNAL, /* Value is at address not in this compilation. 30548852Sbostic This is used for .comm symbols 30648852Sbostic and for extern symbols within functions. 30748852Sbostic Inside GDB, this is changed to LOC_STATIC once the 30848852Sbostic real address is obtained from a loader symbol. */ 30948852Sbostic LOC_CONST_BYTES /* Value is a constant byte-sequence. */ 31048852Sbostic }; 31148852Sbostic 31248852Sbostic struct symbol 31348852Sbostic { 31448852Sbostic /* Symbol name */ 31548852Sbostic char *name; 31648852Sbostic /* Name space code. */ 31748852Sbostic enum namespace namespace; 31848852Sbostic /* Address class */ 31948852Sbostic enum address_class class; 32048852Sbostic /* Data type of value */ 32148852Sbostic struct type *type; 32248852Sbostic /* constant value, or address if static, or register number, 32348852Sbostic or offset in arguments, or offset in stack frame. */ 32448852Sbostic union 32548852Sbostic { 32648852Sbostic long value; 32748852Sbostic struct block *block; /* for LOC_BLOCK */ 32848852Sbostic char *bytes; /* for LOC_CONST_BYTES */ 32948852Sbostic } 33048852Sbostic value; 33148852Sbostic }; 33248852Sbostic 33348852Sbostic /* Source-file information. 33448852Sbostic This describes the relation between source files and line numbers 33548852Sbostic and addresses in the program text. */ 33648852Sbostic 33748852Sbostic struct sourcevector 33848852Sbostic { 33948852Sbostic int length; /* Number of source files described */ 34048852Sbostic struct source *source[1]; /* Descriptions of the files */ 34148852Sbostic }; 34248852Sbostic 34348852Sbostic /* Line number and address of one line. */ 34448852Sbostic 34548852Sbostic struct line 34648852Sbostic { 34748852Sbostic int linenum; 34848852Sbostic int address; 34948852Sbostic }; 35048852Sbostic 35148852Sbostic /* All the information on one source file. */ 35248852Sbostic 35348852Sbostic struct source 35448852Sbostic { 35548852Sbostic char *name; /* Name of file */ 35648852Sbostic int nlines; /* Number of lines that follow */ 35748852Sbostic struct line lines[1]; /* Information on each line */ 35848852Sbostic }; 359