symseg.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /* GDB symbol table format definitions.
  2. Copyright (C) 1986 Free Software Foundation, Inc.
  3. GDB is distributed in the hope that it will be useful, but WITHOUT ANY
  4. WARRANTY. No author or distributor accepts responsibility to anyone
  5. for the consequences of using it or for whether it serves any
  6. particular purpose or works at all, unless he says so in writing.
  7. Refer to the GDB General Public License for full details.
  8. Everyone is granted permission to copy, modify and redistribute GDB,
  9. but only under the conditions described in the GDB General Public
  10. License. A copy of this license is supposed to have been given to you
  11. along with GDB so you can know your rights and responsibilities. It
  12. should be in a file named COPYING. Among other things, the copyright
  13. notice and this notice must be preserved on all copies.
  14. In other words, go ahead and share GDB, but don't try to stop
  15. anyone else from sharing it farther. Help stamp out software hoarding!
  16. */
  17. /* Format of GDB symbol table data.
  18. There is one symbol segment for each source file or
  19. independant compilation. These segments are simply concatenated
  20. to form the GDB symbol table. A zero word where the beginning
  21. of a segment is expected indicates there are no more segments.
  22. Format of a symbol segment:
  23. The symbol segment begins with a word containing 1
  24. if it is in the format described here. Other formats may
  25. be designed, with other code numbers.
  26. The segment contains many objects which point at each other.
  27. The pointers are offsets in bytes from the beginning of the segment.
  28. Thus, each segment can be loaded into core and its pointers relocated
  29. to make valid in-core pointers.
  30. All the data objects in the segment can be found indirectly from
  31. one of them, the root object, of type `struct symbol_root'.
  32. It appears at the beginning of the segment.
  33. The total size of the segment, in bytes, appears as the `length'
  34. field of this object. This size includes the size of the
  35. root object.
  36. All the object data types are defined here to contain pointer types
  37. appropriate for in-core use on a relocated symbol segment.
  38. Casts to and from type int are required for working with
  39. unrelocated symbol segments such as are found in the file.
  40. The ldsymaddr word is filled in by the loader to contain
  41. the offset (in bytes) within the ld symbol table
  42. of the first nonglobal symbol from this compilation.
  43. This makes it possible to match those symbols
  44. (which contain line number information) reliably with
  45. the segment they go with.
  46. Core addresses within the program that appear in the symbol segment
  47. are not relocated by the loader. They are inserted by the assembler
  48. and apply to addresses as output by the assembler, so GDB must
  49. relocate them when it loads the symbol segment. It gets the information
  50. on how to relocate from the textrel, datarel, bssrel, databeg and bssbeg
  51. words of the root object.
  52. The words textrel, datarel and bssrel
  53. are filled in by ld with the amounts to relocate within-the-file
  54. text, data and bss addresses by; databeg and bssbeg can be
  55. used to tell which kind of relocation an address needs. */
  56. enum language {language_c};
  57. struct symbol_root
  58. {
  59. int format; /* Data format version */
  60. int length; /* # bytes in this symbol segment */
  61. int ldsymoff; /* Offset in ld symtab of this file's syms */
  62. int textrel; /* Relocation for text addresses */
  63. int datarel; /* Relocation for data addresses */
  64. int bssrel; /* Relocation for bss addresses */
  65. char *filename; /* Name of source file compiled */
  66. char *filedir; /* Name of directory it was reached from */
  67. struct blockvector *blockvector; /* Vector of all symbol naming blocks */
  68. struct typevector *typevector; /* Vector of all data types */
  69. enum language language; /* Code identifying the language used */
  70. char *version; /* Version info. Not fully specified */
  71. char *compilation; /* Compilation info. Not fully specified */
  72. int databeg; /* Address within the file of data start */
  73. int bssbeg; /* Address within the file of bss start */
  74. };
  75. /* All data types of symbols in the compiled program
  76. are represented by `struct type' objects.
  77. All of these objects are pointed to by the typevector.
  78. The type vector may have empty slots that contain zero. */
  79. struct typevector
  80. {
  81. int length;
  82. struct type *type[1];
  83. };
  84. /* Different kinds of data types are distinguished by the `code' field. */
  85. enum type_code
  86. {
  87. TYPE_CODE_UNDEF, /* Not used; catches errors */
  88. TYPE_CODE_PTR, /* Pointer type */
  89. TYPE_CODE_ARRAY, /* Array type, lower bound zero */
  90. TYPE_CODE_STRUCT, /* C struct or Pascal record */
  91. TYPE_CODE_UNION, /* C union or Pascal variant part */
  92. TYPE_CODE_ENUM, /* Enumeration type */
  93. TYPE_CODE_FUNC, /* Function type */
  94. TYPE_CODE_INT, /* Integer type */
  95. TYPE_CODE_FLT, /* Floating type */
  96. TYPE_CODE_VOID, /* Void type (values zero length) */
  97. TYPE_CODE_SET, /* Pascal sets */
  98. TYPE_CODE_RANGE, /* Range (integers within spec'd bounds) */
  99. TYPE_CODE_PASCAL_ARRAY, /* Array with explicit type of index */
  100. };
  101. /* This appears in a type's flags word for an unsigned integer type. */
  102. #define TYPE_FLAG_UNSIGNED 1
  103. /* Other flag bits are used with GDB. */
  104. struct type
  105. {
  106. /* Code for kind of type */
  107. enum type_code code;
  108. /* Name of this type, or zero if none.
  109. This is used for printing only.
  110. Type names specified as input are defined by symbols. */
  111. char *name;
  112. /* Length in bytes of storage for a value of this type */
  113. int length;
  114. /* For a pointer type, describes the type of object pointed to.
  115. For an array type, describes the type of the elements.
  116. For a function type, describes the type of the value.
  117. Unused otherwise. */
  118. struct type *target_type;
  119. /* Type that is a pointer to this type.
  120. Zero if no such pointer-to type is known yet.
  121. The debugger may add the address of such a type
  122. if it has to construct one later. */
  123. struct type *pointer_type;
  124. /* Type that is a function returning this type.
  125. Zero if no such function type is known here.
  126. The debugger may add the address of such a type
  127. if it has to construct one later. */
  128. struct type *function_type;
  129. /* Flags about this type. */
  130. short flags;
  131. /* Number of fields described for this type */
  132. short nfields;
  133. /* For structure and union types, a description of each field.
  134. For set and pascal array types, there is one "field",
  135. whose type is the domain type of the set or array.
  136. For range types, there are two "fields",
  137. the minimum and maximum values (both inclusive).
  138. For enum types, each possible value is described by one "field".
  139. For range types, there are two "fields", that record constant values
  140. (inclusive) for the minimum and maximum.
  141. Using a pointer to a separate array of fields
  142. allows all types to have the same size, which is useful
  143. because we can allocate the space for a type before
  144. we know what to put in it. */
  145. struct field
  146. {
  147. /* Position of this field, counting in bits from start of
  148. containing structure. For a function type, this is the
  149. position in the argument list of this argument.
  150. For a range bound or enum value, this is the value itself. */
  151. int bitpos;
  152. /* Size of this field, in bits, or zero if not packed.
  153. For an unpacked field, the field's type's length
  154. says how many bytes the field occupies. */
  155. int bitsize;
  156. /* In a struct or enum type, type of this field.
  157. In a function type, type of this argument.
  158. In an array type, the domain-type of the array. */
  159. struct type *type;
  160. /* Name of field, value or argument.
  161. Zero for range bounds and array domains. */
  162. char *name;
  163. } *fields;
  164. };
  165. /* All of the name-scope contours of the program
  166. are represented by `struct block' objects.
  167. All of these objects are pointed to by the blockvector.
  168. Each block represents one name scope.
  169. Each lexical context has its own block.
  170. The first two blocks in the blockvector are special.
  171. The first one contains all the symbols defined in this compilation
  172. whose scope is the entire program linked together.
  173. The second one contains all the symbols whose scope is the
  174. entire compilation excluding other separate compilations.
  175. In C, these correspond to global symbols and static symbols.
  176. Each block records a range of core addresses for the code that
  177. is in the scope of the block. The first two special blocks
  178. give, for the range of code, the entire range of code produced
  179. by the compilation that the symbol segment belongs to.
  180. The blocks appear in the blockvector
  181. in order of increasing starting-address,
  182. and, within that, in order of decreasing ending-address.
  183. This implies that within the body of one function
  184. the blocks appear in the order of a depth-first tree walk. */
  185. struct blockvector
  186. {
  187. /* Number of blocks in the list. */
  188. int nblocks;
  189. /* The blocks themselves. */
  190. struct block *block[1];
  191. };
  192. struct block
  193. {
  194. /* Addresses in the executable code that are in this block.
  195. Note: in an unrelocated symbol segment in a file,
  196. these are always zero. They can be filled in from the
  197. N_LBRAC and N_RBRAC symbols in the loader symbol table. */
  198. int startaddr, endaddr;
  199. /* The symbol that names this block,
  200. if the block is the body of a function;
  201. otherwise, zero.
  202. Note: In an unrelocated symbol segment in an object file,
  203. this field may be zero even when the block has a name.
  204. That is because the block is output before the name
  205. (since the name resides in a higher block).
  206. Since the symbol does point to the block (as its value),
  207. it is possible to find the block and set its name properly. */
  208. struct symbol *function;
  209. /* The `struct block' for the containing block, or 0 if none. */
  210. /* Note that in an unrelocated symbol segment in an object file
  211. this pointer may be zero when the correct value should be
  212. the second special block (for symbols whose scope is one compilation).
  213. This is because the compiler ouptuts the special blocks at the
  214. very end, after the other blocks. */
  215. struct block *superblock;
  216. /* Number of local symbols. */
  217. int nsyms;
  218. /* The symbols. */
  219. struct symbol *sym[1];
  220. };
  221. /* Represent one symbol name; a variable, constant, function or typedef. */
  222. /* Different name spaces for symbols. Looking up a symbol specifies
  223. a namespace and ignores symbol definitions in other name spaces.
  224. VAR_NAMESPACE is the usual namespace.
  225. In C, this contains variables, function names, typedef names
  226. and enum type values.
  227. STRUCT_NAMESPACE is used in C to hold struct, union and enum type names.
  228. Thus, if `struct foo' is used in a C program,
  229. it produces a symbol named `foo' in the STRUCT_NAMESPACE.
  230. LABEL_NAMESPACE may be used for names of labels (for gotos);
  231. currently it is not used and labels are not recorded at all. */
  232. /* For a non-global symbol allocated statically,
  233. the correct core address cannot be determined by the compiler.
  234. The compiler puts an index number into the symbol's value field.
  235. This index number can be matched with the "desc" field of
  236. an entry in the loader symbol table. */
  237. enum namespace
  238. {
  239. UNDEF_NAMESPACE, VAR_NAMESPACE, STRUCT_NAMESPACE, LABEL_NAMESPACE,
  240. };
  241. /* An address-class says where to find the value of the symbol in core. */
  242. enum address_class
  243. {
  244. LOC_UNDEF, /* Not used; catches errors */
  245. LOC_CONST, /* Value is constant (enum type value name) */
  246. LOC_STATIC, /* Value is at fixed address */
  247. LOC_REGISTER, /* Value is in register */
  248. LOC_ARG, /* Value is at spec'd position in arglist */
  249. LOC_LOCAL, /* Value is at spec'd pos in stack frame */
  250. LOC_TYPEDEF, /* Value not used; definition in SYMBOL_TYPE
  251. Symbols in the namespace STRUCT_NAMESPACE
  252. all have this class. */
  253. LOC_LABEL, /* Value is address in the code */
  254. LOC_BLOCK, /* Value is address of a `struct block'.
  255. Function names have this class. */
  256. LOC_EXTERNAL /* Value is at address not in this compilation.
  257. This is used for .comm symbols
  258. and for extern symbols within functions.
  259. Inside GDB, this is changed to LOC_STATIC once the
  260. real address is obtained from a loader symbol. */
  261. };
  262. struct symbol
  263. {
  264. /* Symbol name */
  265. char *name;
  266. /* Name space code. */
  267. enum namespace namespace;
  268. /* Address class */
  269. enum address_class class;
  270. /* Data type of value */
  271. struct type *type;
  272. /* constant value, or address if static, or register number,
  273. or offset in arguments, or offset in stack frame. */
  274. union
  275. {
  276. long value;
  277. struct block *block;
  278. }
  279. value;
  280. };