symseg.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /* GDB symbol table format definitions.
  2. Copyright (C) 1986 Free Software Foundation, Inc.
  3. Hacked by Michael Tiemann (tiemann@mcc.com)
  4. GDB is distributed in the hope that it will be useful, but WITHOUT ANY
  5. WARRANTY. No author or distributor accepts responsibility to anyone
  6. for the consequences of using it or for whether it serves any
  7. particular purpose or works at all, unless he says so in writing.
  8. Refer to the GDB General Public License for full details.
  9. Everyone is granted permission to copy, modify and redistribute GDB,
  10. but only under the conditions described in the GDB General Public
  11. License. A copy of this license is supposed to have been given to you
  12. along with GDB so you can know your rights and responsibilities. It
  13. should be in a file named COPYING. Among other things, the copyright
  14. notice and this notice must be preserved on all copies.
  15. In other words, go ahead and share GDB, but don't try to stop
  16. anyone else from sharing it farther. Help stamp out software hoarding!
  17. */
  18. /* Format of GDB symbol table data.
  19. There is one symbol segment for each source file or
  20. independant compilation. These segments are simply concatenated
  21. to form the GDB symbol table. A zero word where the beginning
  22. of a segment is expected indicates there are no more segments.
  23. Format of a symbol segment:
  24. The symbol segment begins with a word containing 1
  25. if it is in the format described here. Other formats may
  26. be designed, with other code numbers.
  27. The segment contains many objects which point at each other.
  28. The pointers are offsets in bytes from the beginning of the segment.
  29. Thus, each segment can be loaded into core and its pointers relocated
  30. to make valid in-core pointers.
  31. All the data objects in the segment can be found indirectly from
  32. one of them, the root object, of type `struct symbol_root'.
  33. It appears at the beginning of the segment.
  34. The total size of the segment, in bytes, appears as the `length'
  35. field of this object. This size includes the size of the
  36. root object.
  37. All the object data types are defined here to contain pointer types
  38. appropriate for in-core use on a relocated symbol segment.
  39. Casts to and from type int are required for working with
  40. unrelocated symbol segments such as are found in the file.
  41. The ldsymaddr word is filled in by the loader to contain
  42. the offset (in bytes) within the ld symbol table
  43. of the first nonglobal symbol from this compilation.
  44. This makes it possible to match those symbols
  45. (which contain line number information) reliably with
  46. the segment they go with.
  47. Core addresses within the program that appear in the symbol segment
  48. are not relocated by the loader. They are inserted by the assembler
  49. and apply to addresses as output by the assembler, so GDB must
  50. relocate them when it loads the symbol segment. It gets the information
  51. on how to relocate from the textrel, datarel, bssrel, databeg and bssbeg
  52. words of the root object.
  53. The words textrel, datarel and bssrel
  54. are filled in by ld with the amounts to relocate within-the-file
  55. text, data and bss addresses by; databeg and bssbeg can be
  56. used to tell which kind of relocation an address needs. */
  57. enum language {language_c};
  58. struct symbol_root
  59. {
  60. int format; /* Data format version */
  61. int length; /* # bytes in this symbol segment */
  62. int ldsymoff; /* Offset in ld symtab of this file's syms */
  63. int textrel; /* Relocation for text addresses */
  64. int datarel; /* Relocation for data addresses */
  65. int bssrel; /* Relocation for bss addresses */
  66. char *filename; /* Name of main source file compiled */
  67. char *filedir; /* Name of directory it was reached from */
  68. struct blockvector *blockvector; /* Vector of all symbol-naming blocks */
  69. struct typevector *typevector; /* Vector of all data types */
  70. enum language language; /* Code identifying the language used */
  71. char *version; /* Version info. Not fully specified */
  72. char *compilation; /* Compilation info. Not fully specified */
  73. int databeg; /* Address within the file of data start */
  74. int bssbeg; /* Address within the file of bss start */
  75. struct sourcevector *sourcevector; /* Vector of line-number info */
  76. };
  77. /* All data types of symbols in the compiled program
  78. are represented by `struct type' objects.
  79. All of these objects are pointed to by the typevector.
  80. The type vector may have empty slots that contain zero. */
  81. struct typevector
  82. {
  83. int length; /* Number of types described */
  84. struct type *type[1];
  85. };
  86. /* Different kinds of data types are distinguished by the `code' field. */
  87. enum type_code
  88. {
  89. TYPE_CODE_UNDEF, /* Not used; catches errors */
  90. TYPE_CODE_PTR, /* Pointer type */
  91. TYPE_CODE_ARRAY, /* Array type, lower bound zero */
  92. TYPE_CODE_STRUCT, /* C struct or Pascal record */
  93. TYPE_CODE_UNION, /* C union or Pascal variant part */
  94. TYPE_CODE_ENUM, /* Enumeration type */
  95. TYPE_CODE_FUNC, /* Function type */
  96. TYPE_CODE_INT, /* Integer type */
  97. TYPE_CODE_FLT, /* Floating type */
  98. TYPE_CODE_VOID, /* Void type (values zero length) */
  99. TYPE_CODE_SET, /* Pascal sets */
  100. TYPE_CODE_RANGE, /* Range (integers within spec'd bounds) */
  101. TYPE_CODE_PASCAL_ARRAY, /* Array with explicit type of index */
  102. /* C++ */
  103. TYPE_CODE_MEMBER, /* Member type */
  104. TYPE_CODE_REF, /* C++ Reference types */
  105. };
  106. /* This appears in a type's flags word for an unsigned integer type. */
  107. #define TYPE_FLAG_UNSIGNED 1
  108. /* Other flag bits are used with GDB. */
  109. #define TYPE_FLAG_HAS_CONSTRUCTOR 256
  110. #define TYPE_FLAG_HAS_DESTRUCTOR 512
  111. #define TYPE_FLAG_VIA_PUBLIC 1024
  112. #define TYPE_FLAG_VIA_VIRTUAL 2048
  113. struct type
  114. {
  115. /* Code for kind of type */
  116. enum type_code code;
  117. /* Name of this type, or zero if none.
  118. This is used for printing only.
  119. Type names specified as input are defined by symbols. */
  120. char *name;
  121. /* Length in bytes of storage for a value of this type */
  122. int length;
  123. /* For a pointer type, describes the type of object pointed to.
  124. For an array type, describes the type of the elements.
  125. For a function type, describes the type of the value.
  126. Unused otherwise. */
  127. struct type *target_type;
  128. /* Type that is a pointer to this type.
  129. Zero if no such pointer-to type is known yet.
  130. The debugger may add the address of such a type
  131. if it has to construct one later. */
  132. struct type *pointer_type;
  133. /* C++: also need a reference type. */
  134. struct type *reference_type;
  135. /* Type that is a function returning this type.
  136. Zero if no such function type is known here.
  137. The debugger may add the address of such a type
  138. if it has to construct one later. */
  139. struct type *function_type;
  140. /* Handling of pointers to members:
  141. TYPE_MAIN_VARIANT is used for pointer and pointer
  142. to member types. Normally it the value of the address of its
  143. containing type. However, for pointers to members, we must be
  144. able to allocate pointer to member types and look them up
  145. from some place of reference.
  146. NEXT_VARIANT is the next element in the chain. */
  147. struct type *main_variant, *next_variant;
  148. /* Flags about this type. */
  149. short flags;
  150. /* Number of fields described for this type */
  151. short nfields;
  152. /* For structure and union types, a description of each field.
  153. For set and pascal array types, there is one "field",
  154. whose type is the domain type of the set or array.
  155. For range types, there are two "fields",
  156. the minimum and maximum values (both inclusive).
  157. For enum types, each possible value is described by one "field".
  158. For range types, there are two "fields", that record constant values
  159. (inclusive) for the minimum and maximum.
  160. Using a pointer to a separate array of fields
  161. allows all types to have the same size, which is useful
  162. because we can allocate the space for a type before
  163. we know what to put in it. */
  164. struct field
  165. {
  166. /* Position of this field, counting in bits from start of
  167. containing structure. For a function type, this is the
  168. position in the argument list of this argument.
  169. For a range bound or enum value, this is the value itself. */
  170. int bitpos;
  171. /* Size of this field, in bits, or zero if not packed.
  172. For an unpacked field, the field's type's length
  173. says how many bytes the field occupies. */
  174. int bitsize;
  175. /* In a struct or enum type, type of this field.
  176. In a function type, type of this argument.
  177. In an array type, the domain-type of the array. */
  178. struct type *type;
  179. /* Name of field, value or argument.
  180. Zero for range bounds and array domains. */
  181. char *name;
  182. } *fields;
  183. /* C++ */
  184. int *private_field_bits;
  185. int *protected_field_bits;
  186. /* Number of methods described for this type */
  187. short nfn_fields;
  188. /* Number of base classes this type derives from. */
  189. short n_baseclasses;
  190. /* Number of methods described for this type plus all the
  191. methods that it derives from. */
  192. int nfn_fields_total;
  193. /* For classes, structures, and unions, a description of each field,
  194. which consists of an overloaded name, followed by the types of
  195. arguments that the method expects, and then the name after it
  196. has been renamed to make it distinct. */
  197. struct fn_fieldlist
  198. {
  199. /* The overloaded name. */
  200. char *name;
  201. /* The number of methods with this name. */
  202. int length;
  203. /* The list of methods. */
  204. struct fn_field
  205. {
  206. #if 0
  207. /* The overloaded name */
  208. char *name;
  209. #endif
  210. /* The type of the argument */
  211. struct type *type;
  212. /* The argument list */
  213. struct type **args;
  214. /* The name after it has been processed */
  215. char *physname;
  216. /* If this is a virtual function, the offset into the vtbl-1,
  217. else 0. */
  218. int voffset;
  219. } *fn_fields;
  220. int *private_fn_field_bits;
  221. int *protected_fn_field_bits;
  222. } *fn_fieldlists;
  223. unsigned char via_protected;
  224. unsigned char via_public;
  225. /* For types with virtual functions, VPTR_BASETYPE is the base class which
  226. defined the virtual function table pointer. VPTR_FIELDNO is
  227. the field number of that pointer in the structure.
  228. For types that are pointer to member types, VPTR_BASETYPE
  229. ifs the type that this pointer is a member of.
  230. Unused otherwise. */
  231. struct type *vptr_basetype;
  232. int vptr_fieldno;
  233. /* If this type has a base class, put it here.
  234. If this type is a pointer type, the chain of member pointer
  235. types goes here.
  236. Unused otherwise. */
  237. struct type **baseclasses;
  238. };
  239. /* All of the name-scope contours of the program
  240. are represented by `struct block' objects.
  241. All of these objects are pointed to by the blockvector.
  242. Each block represents one name scope.
  243. Each lexical context has its own block.
  244. The first two blocks in the blockvector are special.
  245. The first one contains all the symbols defined in this compilation
  246. whose scope is the entire program linked together.
  247. The second one contains all the symbols whose scope is the
  248. entire compilation excluding other separate compilations.
  249. In C, these correspond to global symbols and static symbols.
  250. Each block records a range of core addresses for the code that
  251. is in the scope of the block. The first two special blocks
  252. give, for the range of code, the entire range of code produced
  253. by the compilation that the symbol segment belongs to.
  254. The blocks appear in the blockvector
  255. in order of increasing starting-address,
  256. and, within that, in order of decreasing ending-address.
  257. This implies that within the body of one function
  258. the blocks appear in the order of a depth-first tree walk. */
  259. struct blockvector
  260. {
  261. /* Number of blocks in the list. */
  262. int nblocks;
  263. /* The blocks themselves. */
  264. struct block *block[1];
  265. };
  266. struct block
  267. {
  268. /* Addresses in the executable code that are in this block.
  269. Note: in an unrelocated symbol segment in a file,
  270. these are always zero. They can be filled in from the
  271. N_LBRAC and N_RBRAC symbols in the loader symbol table. */
  272. int startaddr, endaddr;
  273. /* The symbol that names this block,
  274. if the block is the body of a function;
  275. otherwise, zero.
  276. Note: In an unrelocated symbol segment in an object file,
  277. this field may be zero even when the block has a name.
  278. That is because the block is output before the name
  279. (since the name resides in a higher block).
  280. Since the symbol does point to the block (as its value),
  281. it is possible to find the block and set its name properly. */
  282. struct symbol *function;
  283. /* The `struct block' for the containing block, or 0 if none. */
  284. /* Note that in an unrelocated symbol segment in an object file
  285. this pointer may be zero when the correct value should be
  286. the second special block (for symbols whose scope is one compilation).
  287. This is because the compiler ouptuts the special blocks at the
  288. very end, after the other blocks. */
  289. struct block *superblock;
  290. /* A flag indicating whether or not the fucntion corresponding
  291. to this block was compiled with gcc or not. If there is no
  292. function corresponding to this block, this meaning of this flag
  293. is undefined. (In practice it will be 1 if the block was created
  294. while processing a file compiled with gcc and 0 when not). */
  295. unsigned char gcc_compile_flag;
  296. /* Number of local symbols. */
  297. int nsyms;
  298. /* The symbols. */
  299. struct symbol *sym[1];
  300. };
  301. /* Represent one symbol name; a variable, constant, function or typedef. */
  302. /* Different name spaces for symbols. Looking up a symbol specifies
  303. a namespace and ignores symbol definitions in other name spaces.
  304. VAR_NAMESPACE is the usual namespace.
  305. In C, this contains variables, function names, typedef names
  306. and enum type values.
  307. STRUCT_NAMESPACE is used in C to hold struct, union and enum type names.
  308. Thus, if `struct foo' is used in a C program,
  309. it produces a symbol named `foo' in the STRUCT_NAMESPACE.
  310. LABEL_NAMESPACE may be used for names of labels (for gotos);
  311. currently it is not used and labels are not recorded at all. */
  312. /* For a non-global symbol allocated statically,
  313. the correct core address cannot be determined by the compiler.
  314. The compiler puts an index number into the symbol's value field.
  315. This index number can be matched with the "desc" field of
  316. an entry in the loader symbol table. */
  317. enum namespace
  318. {
  319. UNDEF_NAMESPACE, VAR_NAMESPACE, STRUCT_NAMESPACE, LABEL_NAMESPACE,
  320. };
  321. /* An address-class says where to find the value of the symbol in core. */
  322. enum address_class
  323. {
  324. LOC_UNDEF, /* Not used; catches errors */
  325. LOC_CONST, /* Value is constant int */
  326. LOC_STATIC, /* Value is at fixed address */
  327. LOC_REGISTER, /* Value is in register */
  328. LOC_ARG, /* Value is at spec'd position in arglist */
  329. LOC_REGPARM, /* Value is at spec'd position in register window */
  330. LOC_LOCAL, /* Value is at spec'd pos in stack frame */
  331. LOC_TYPEDEF, /* Value not used; definition in SYMBOL_TYPE
  332. Symbols in the namespace STRUCT_NAMESPACE
  333. all have this class. */
  334. LOC_LABEL, /* Value is address in the code */
  335. LOC_BLOCK, /* Value is address of a `struct block'.
  336. Function names have this class. */
  337. LOC_EXTERNAL, /* Value is at address not in this compilation.
  338. This is used for .comm symbols
  339. and for extern symbols within functions.
  340. Inside GDB, this is changed to LOC_STATIC once the
  341. real address is obtained from a loader symbol. */
  342. LOC_CONST_BYTES /* Value is a constant byte-sequence. */
  343. };
  344. struct symbol
  345. {
  346. /* Symbol name */
  347. char *name;
  348. /* Name space code. */
  349. enum namespace namespace;
  350. /* Address class */
  351. enum address_class class;
  352. /* Data type of value */
  353. struct type *type;
  354. /* constant value, or address if static, or register number,
  355. or offset in arguments, or offset in stack frame. */
  356. union
  357. {
  358. long value;
  359. struct block *block; /* for LOC_BLOCK */
  360. char *bytes; /* for LOC_CONST_BYTES */
  361. }
  362. value;
  363. };
  364. struct partial_symbol
  365. {
  366. /* Symbol name */
  367. char *name;
  368. /* Name space code. */
  369. enum namespace namespace;
  370. /* Address class (for info_symbols) */
  371. enum address_class class;
  372. };
  373. /*
  374. * Vectors of all partial symbols read in from file; actually declared
  375. * and used in dbxread.c.
  376. */
  377. extern struct partial_symbol *global_psymbols, *static_psymbols;
  378. /* Source-file information.
  379. This describes the relation between source files and line numbers
  380. and addresses in the program text. */
  381. struct sourcevector
  382. {
  383. int length; /* Number of source files described */
  384. struct source *source[1]; /* Descriptions of the files */
  385. };
  386. /* Each item represents a line-->pc (or the reverse) mapping. This is
  387. somewhat more wasteful of space than one might wish, but since only
  388. the files which are actually debugged are read in to core, we don't
  389. waste much space.
  390. Each item used to be an int; either minus a line number, or a
  391. program counter. If it represents a line number, that is the line
  392. described by the next program counter value. If it is positive, it
  393. is the program counter at which the code for the next line starts. */
  394. struct linetable_entry
  395. {
  396. int line;
  397. CORE_ADDR pc;
  398. };
  399. struct linetable
  400. {
  401. int nitems;
  402. struct linetable_entry item[1];
  403. };
  404. /* All the information on one source file. */
  405. struct source
  406. {
  407. char *name; /* Name of file */
  408. struct linetable contents;
  409. };