dbxout.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /* Output dbx-format symbol table information from GNU compiler.
  2. Copyright (C) 1987 Free Software Foundation, Inc.
  3. This file is part of GNU CC.
  4. GNU CC is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the GNU CC General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. GNU CC, but only under the conditions described in the
  12. GNU CC General Public License. A copy of this license is
  13. supposed to have been given to you along with GNU CC so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. /* Output dbx-format symbol table data.
  18. This consists of many symbol table entries, each of them
  19. a .stabs assembler pseudo-op with four operands:
  20. a "name" which is really a description of one symbol and its type,
  21. a "code", which is a symbol defined in stab.h whose name starts with N_,
  22. an unused operand always 0,
  23. and a "value" which is an address or an offset.
  24. The name is enclosed in doublequote characters.
  25. Each function, variable, typedef, and structure tag
  26. has a symbol table entry to define it.
  27. The beginning and end of each level of name scoping within
  28. a function are also marked by special symbol table entries.
  29. The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
  30. and a data type number. The data type number may be followed by
  31. "=" and a type definition; normally this will happen the first time
  32. the type number is mentioned. The type definition may refer to
  33. other types by number, and those type numbers may be followed
  34. by "=" and nested definitions.
  35. This can make the "name" quite long.
  36. When a name is more than 80 characters, we split the .stabs pseudo-op
  37. into two .stabs pseudo-ops, both sharing the same "code" and "value".
  38. The first one is marked as continued with a double-backslash at the
  39. end of its "name".
  40. The kind-of-symbol letter distinguished function names from global
  41. variables from file-scope variables from parameters from auto
  42. variables in memory from typedef names from register variables.
  43. See `dbxout_symbol'.
  44. The "code" is mostly redundant with the kind-of-symbol letter
  45. that goes in the "name", but not entirely: for symbols located
  46. in static storage, the "code" says which segment the address is in,
  47. which controls how it is relocated.
  48. The "value" for a symbol in static storage
  49. is the core address of the symbol (actually, the assembler
  50. label for the symbol). For a symbol located in a stack slot
  51. it is the stack offset; for one in a register, the register number.
  52. For a typedef symbol, it is zero.
  53. For more on data type definitions, see `dbxout_type'. */
  54. #include "config.h"
  55. #include "tree.h"
  56. #include "rtl.h"
  57. #include "c-tree.h"
  58. #include <stdio.h>
  59. #include <stab.h>
  60. /* Stream for writing to assembler file. */
  61. static FILE *asmfile;
  62. enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
  63. /* Vector recording the status of describing C data types.
  64. When we first notice a data type (a tree node),
  65. we assign it a number using next_type_number.
  66. That is its index in this vector.
  67. The vector element says whether we have yet output
  68. the definition of the type. TYPE_XREF says we have
  69. output it as a cross-reference only. */
  70. enum typestatus *typevec;
  71. /* Number of elements of space allocated in `typevec'. */
  72. static int typevec_len;
  73. /* In dbx output, each type gets a unique number.
  74. This is the number for the next type output.
  75. The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
  76. static int next_type_number;
  77. /* In dbx output, we must assign symbol-blocks id numbers
  78. in the order in which their beginnings are encountered.
  79. We output debugging info that refers to the beginning and
  80. end of the ranges of code in each block
  81. with assembler labels LBBn and LBEn, where n is the block number.
  82. The labels are generated in final, which assigns numbers to the
  83. blocks in the same way. */
  84. static int next_block_number;
  85. /* These variables are for dbxout_symbol to communicate to
  86. dbxout_finish_symbol.
  87. current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
  88. current_sym_value and current_sym_addr are two ways to address the
  89. value to store in the symtab entry.
  90. current_sym_addr if nonzero represents the value as an rtx.
  91. If that is zero, current_sym_value is used. This is used
  92. when the value is an offset (such as for auto variables,
  93. register variables and parms). */
  94. static int current_sym_code;
  95. static int current_sym_value;
  96. static rtx current_sym_addr;
  97. /* Number of chars of symbol-description generated so far for the
  98. current symbol. Used by CHARS and CONTIN. */
  99. static int current_sym_nchars;
  100. /* Report having output N chars of the current symbol-description. */
  101. #define CHARS(N) (current_sym_nchars += (N))
  102. /* Break the current symbol-description, generating a continuation,
  103. if it has become long. */
  104. #define CONTIN \
  105. do {if (current_sym_nchars > 80) dbxout_continue ();} while (0)
  106. void dbxout_types ();
  107. void dbxout_tags ();
  108. static void dbxout_type_name ();
  109. static void dbxout_type ();
  110. static void dbxout_type_def ();
  111. static void dbxout_finish_symbol ();
  112. static void dbxout_continue ();
  113. /* At the beginning of compilation, start writing the symbol table.
  114. Initialize `typevec' and output the standard data types of C. */
  115. void
  116. dbxout_init (asm_file, input_file_name)
  117. FILE *asm_file;
  118. char *input_file_name;
  119. {
  120. asmfile = asm_file;
  121. typevec_len = 100;
  122. typevec = (enum typestatus *) xmalloc (typevec_len * sizeof typevec[0]);
  123. bzero (typevec, typevec_len * sizeof typevec[0]);
  124. fprintf (asmfile,
  125. "Ltext:\t.stabs \"%s\",%d,0,0,Ltext\n",
  126. input_filename, N_SO);
  127. next_type_number = 1;
  128. next_block_number = 2;
  129. /* Make sure that types `int' and `char' have numbers 1 and 2.
  130. Definitions of other integer types will refer to those numbers. */
  131. dbxout_type_def (integer_type_node);
  132. dbxout_type_def (char_type_node);
  133. /* Get all permanent types not yet gotten
  134. and output them. */
  135. dbxout_types (get_permanent_types ());
  136. }
  137. /* Continue a symbol-description that gets too big.
  138. End one symbol table entry with a double-backslash
  139. and start a new one, eventually producing something like
  140. .stabs "start......\\",code,0,value
  141. .stabs "...rest",code,0,value */
  142. static void
  143. dbxout_continue ()
  144. {
  145. fprintf (asmfile, "\\\\");
  146. dbxout_finish_symbol ();
  147. fprintf (asmfile, ".stabs \"");
  148. current_sym_nchars = 0;
  149. }
  150. /* Output a reference to a type. If the type has not yet been
  151. described in the dbx output, output its definition now.
  152. For a type already defined, just refer to its definition
  153. using the type number.
  154. If FULL is nonzero, and the type has been described only with
  155. a forward-reference, output the definition now.
  156. If FULL is zero in this case, just refer to the forward-reference
  157. using the number previously allocated. */
  158. static void
  159. dbxout_type (type, full)
  160. tree type;
  161. int full;
  162. {
  163. register tree tem;
  164. if (TYPE_SYMTAB_ADDRESS (type) == 0)
  165. {
  166. /* Type has no dbx number assigned. Assign next available number. */
  167. TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
  168. /* Make sure type vector is long enough to record about this type. */
  169. if (next_type_number == typevec_len)
  170. {
  171. typevec = (enum typestatus *) xrealloc (typevec, typevec_len * 2 * sizeof typevec[0]);
  172. bzero (typevec + typevec_len, typevec_len * sizeof typevec[0]);
  173. typevec_len *= 2;
  174. }
  175. }
  176. /* Output the number of this type, to refer to it. */
  177. fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
  178. CHARS (3);
  179. /* If this type's definition has been output or is now being output,
  180. that is all. */
  181. switch (typevec[TYPE_SYMTAB_ADDRESS (type)])
  182. {
  183. case TYPE_UNSEEN:
  184. break;
  185. case TYPE_XREF:
  186. if (! full)
  187. return;
  188. break;
  189. case TYPE_DEFINED:
  190. return;
  191. }
  192. /* Output a definition now. */
  193. fprintf (asmfile, "=");
  194. CHARS (1);
  195. /* Mark it as defined, so that if it is self-referent
  196. we will not get into an infinite recursion of definitions. */
  197. typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_DEFINED;
  198. switch (TREE_CODE (type))
  199. {
  200. case VOID_TYPE:
  201. /* For a void type, just define it as itself; ie, "5=5".
  202. This makes us consider it defined
  203. without saying what it is. The debugger will make it
  204. a void type when the reference is seen, and nothing will
  205. ever override that default. */
  206. fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
  207. CHARS (3);
  208. break;
  209. case INTEGER_TYPE:
  210. if (type == char_type_node)
  211. /* Output the type `char' as a subrange of itself!
  212. I don't understand this definition, just copied it
  213. from the output of pcc. */
  214. fprintf (asmfile, "r2;0;127;");
  215. else
  216. /* Output other integer types as subranges of `int'. */
  217. fprintf (asmfile, "r1;%d;%d;",
  218. TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)),
  219. TREE_INT_CST_LOW (TYPE_MAX_VALUE (type)));
  220. CHARS (25);
  221. break;
  222. case REAL_TYPE:
  223. /* This must be magic. */
  224. fprintf (asmfile, "r1;%d;0;",
  225. TREE_INT_CST_LOW (size_in_bytes (type)));
  226. CHARS (16);
  227. break;
  228. case ARRAY_TYPE:
  229. /* Output "a" followed by a range type definition
  230. for the index type of the array
  231. followed by a reference to the target-type.
  232. ar1;0;N;M for an array of type M and size N. */
  233. fprintf (asmfile, "ar1;0;%d;",
  234. TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))));
  235. CHARS (17);
  236. dbxout_type (TREE_TYPE (type), 0);
  237. break;
  238. case RECORD_TYPE:
  239. case UNION_TYPE:
  240. /* Output a structure type. */
  241. if ((TYPE_NAME (type) != 0 && !full)
  242. || TYPE_SIZE (type) == 0)
  243. {
  244. /* If the type is just a cross reference, output one
  245. and mark the type as partially described.
  246. If it later becomes defined, we will output
  247. its real definition. */
  248. fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
  249. CHARS (3);
  250. dbxout_type_name (type);
  251. fprintf (asmfile, ":");
  252. typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
  253. break;
  254. }
  255. tem = size_in_bytes (type);
  256. fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "s%d" : "u%d",
  257. TREE_INT_CST_LOW (tem));
  258. CHARS (11);
  259. for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  260. /* Output the name, type, position (in bits), size (in bits)
  261. of each field. */
  262. /* Omit here the nameless fields that are used to skip bits. */
  263. if (DECL_NAME (tem) != 0)
  264. {
  265. CONTIN;
  266. fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
  267. CHARS (1 + strlen (IDENTIFIER_POINTER (DECL_NAME (tem))));
  268. dbxout_type (TREE_TYPE (tem), 0);
  269. fprintf (asmfile, ",%d,%d;", DECL_OFFSET (tem),
  270. TREE_INT_CST_LOW (DECL_SIZE (tem)) * DECL_SIZE_UNIT (tem));
  271. CHARS (23);
  272. }
  273. putc (';', asmfile);
  274. CHARS (1);
  275. break;
  276. case ENUMERAL_TYPE:
  277. if ((TYPE_NAME (type) != 0 && !full)
  278. || TYPE_SIZE (type) == 0)
  279. {
  280. fprintf (asmfile, "xe");
  281. CHARS (3);
  282. dbxout_type_name (type);
  283. typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
  284. fprintf (asmfile, ":");
  285. return;
  286. }
  287. putc ('e', asmfile);
  288. CHARS (1);
  289. for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
  290. {
  291. fprintf (asmfile, "%s:%d,", IDENTIFIER_POINTER (TREE_PURPOSE (tem)),
  292. TREE_INT_CST_LOW (TREE_VALUE (tem)));
  293. CHARS (11 + strlen (IDENTIFIER_POINTER (TREE_PURPOSE (tem))));
  294. if (TREE_CHAIN (tem) != 0)
  295. CONTIN;
  296. }
  297. putc (';', asmfile);
  298. CHARS (1);
  299. break;
  300. case POINTER_TYPE:
  301. putc ('*', asmfile);
  302. CHARS (1);
  303. dbxout_type (TREE_TYPE (type), 0);
  304. break;
  305. case FUNCTION_TYPE:
  306. putc ('f', asmfile);
  307. CHARS (1);
  308. dbxout_type (TREE_TYPE (type), 0);
  309. break;
  310. }
  311. }
  312. /* Output the name of type TYPE, with no punctuation.
  313. Such names can be set up either by typedef declarations
  314. or by struct, enum and union tags. */
  315. static void
  316. dbxout_type_name (type)
  317. register tree type;
  318. {
  319. register char *name;
  320. if (TYPE_NAME (type) == 0)
  321. abort ();
  322. if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  323. name = IDENTIFIER_POINTER (TYPE_NAME (type));
  324. else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  325. name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  326. else
  327. abort ();
  328. fprintf (asmfile, "%s", name);
  329. CHARS (strlen (name));
  330. }
  331. /* Output a .stabs for the symbol defined by DECL,
  332. which must be a ..._DECL node in the normal namespace.
  333. It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
  334. LOCAL is nonzero if the scope is less than the entire file. */
  335. void
  336. dbxout_symbol (decl, local)
  337. tree decl;
  338. int local;
  339. {
  340. int symcode;
  341. int letter;
  342. /* If global, first output all types and all
  343. struct, enum and union tags that have been created
  344. and not yet output. */
  345. if (local == 0)
  346. {
  347. dbxout_tags (gettags ());
  348. dbxout_types (get_permanent_types ());
  349. }
  350. current_sym_code = 0;
  351. current_sym_value = 0;
  352. current_sym_addr = 0;
  353. /* The output will always start with the symbol name,
  354. so count that always in the length-output-so-far. */
  355. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (decl)));
  356. switch (TREE_CODE (decl))
  357. {
  358. case CONST_DECL:
  359. /* Enum values are defined by defining the enum type. */
  360. break;
  361. case FUNCTION_DECL:
  362. if (TREE_EXTERNAL (decl))
  363. break;
  364. if (GET_CODE (DECL_RTL (decl)) != MEM
  365. || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
  366. break;
  367. fprintf (asmfile, ".stabs \"%s:%c",
  368. IDENTIFIER_POINTER (DECL_NAME (decl)),
  369. TREE_PUBLIC (decl) ? 'F' : 'f');
  370. current_sym_code = N_FUN;
  371. current_sym_addr = XEXP (DECL_RTL (decl), 0);
  372. if (TREE_TYPE (TREE_TYPE (decl)))
  373. dbxout_type (TREE_TYPE (TREE_TYPE (decl)), 0);
  374. else
  375. dbxout_type (void_type_node, 0);
  376. dbxout_finish_symbol ();
  377. break;
  378. case TYPE_DECL:
  379. /* Output typedef name. */
  380. fprintf (asmfile, ".stabs \"%s:t",
  381. IDENTIFIER_POINTER (DECL_NAME (decl)));
  382. current_sym_code = N_LSYM;
  383. dbxout_type (TREE_TYPE (decl), 0);
  384. dbxout_finish_symbol ();
  385. break;
  386. case PARM_DECL:
  387. /* Parm decls go in their own separate chains
  388. and are output by dbxout_reg_parms and dbxout_parms. */
  389. abort ();
  390. case VAR_DECL:
  391. /* Don't mention a variable that is external.
  392. Let the file that defines it describe it. */
  393. if (TREE_EXTERNAL (decl))
  394. break;
  395. /* Don't mention a variable at all
  396. if it was completely optimized into nothingness. */
  397. if (GET_CODE (DECL_RTL (decl)) == REG
  398. && REGNO (DECL_RTL (decl)) == -1)
  399. break;
  400. /* Ok, start a symtab entry and output the variable name. */
  401. fprintf (asmfile, ".stabs \"%s:",
  402. IDENTIFIER_POINTER (DECL_NAME (decl)));
  403. /* The kind-of-variable letter depends on where
  404. the variable is and on the scope of its name:
  405. G and N_GSYM for static storage and global scope,
  406. S for static storage and file scope,
  407. v for static storage and local scope,
  408. for those two, use N_LCSYM if data is in bss segment,
  409. N_STSYM if it is in data segment, or N_FUN if in text segment.
  410. no letter at all, and N_LSYM, for auto variable,
  411. r and N_RSYM for register variable. */
  412. if (GET_CODE (DECL_RTL (decl)) == MEM
  413. && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
  414. {
  415. if (TREE_PUBLIC (decl))
  416. {
  417. letter = 'G';
  418. current_sym_code = N_GSYM;
  419. }
  420. else
  421. {
  422. current_sym_addr = XEXP (DECL_RTL (decl), 0);
  423. letter = TREE_PERMANENT (decl) ? 'S' : 'v';
  424. if (!DECL_INITIAL (decl))
  425. current_sym_code = N_LCSYM;
  426. else if (TREE_READONLY (decl) && ! TREE_VOLATILE (decl))
  427. /* This is not quite right, but it's the closest
  428. of all the codes that Unix defines. */
  429. current_sym_code = N_FUN;
  430. else
  431. current_sym_code = N_STSYM;
  432. }
  433. putc (letter, asmfile);
  434. dbxout_type (TREE_TYPE (decl), 0);
  435. dbxout_finish_symbol ();
  436. }
  437. else
  438. {
  439. if (GET_CODE (DECL_RTL (decl)) == REG)
  440. {
  441. letter = 'r';
  442. current_sym_code = N_RSYM;
  443. current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl)));
  444. }
  445. else
  446. {
  447. letter = 0;
  448. current_sym_code = N_LSYM;
  449. /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
  450. We want the value of that CONST_INT. */
  451. current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1));
  452. }
  453. if (letter) putc (letter, asmfile);
  454. dbxout_type (TREE_TYPE (decl), 0);
  455. dbxout_finish_symbol ();
  456. }
  457. break;
  458. }
  459. }
  460. static void
  461. dbxout_finish_symbol ()
  462. {
  463. fprintf (asmfile, "\",%d,0,0,", current_sym_code);
  464. if (current_sym_addr)
  465. output_addr_const (asmfile, current_sym_addr);
  466. else
  467. fprintf (asmfile, "%d", current_sym_value);
  468. putc ('\n', asmfile);
  469. }
  470. /* Output definitions of all the decls in a chain. */
  471. static void
  472. dbxout_syms (syms)
  473. tree syms;
  474. {
  475. while (syms)
  476. {
  477. dbxout_symbol (syms, 1);
  478. syms = TREE_CHAIN (syms);
  479. }
  480. }
  481. /* The following two functions output definitions of function parameters.
  482. Each parameter gets a definition locating it in the parameter list.
  483. Each parameter that is a register variable gets a second definition
  484. locating it in the register.
  485. Printing or argument lists in gdb uses the definitions that
  486. locate in the parameter list. But reference to the variable in
  487. expressions uses preferentially the definition as a register. */
  488. /* Output definitions, referring to storage in the parmlist,
  489. of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
  490. static void
  491. dbxout_parms (parms)
  492. tree parms;
  493. {
  494. for (; parms; parms = TREE_CHAIN (parms))
  495. {
  496. current_sym_code = N_PSYM;
  497. current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  498. /* A parm declared char is really passed as an int,
  499. so it occupies the least significant bytes.
  500. On a big-endian machine those are not the low-numbered ones. */
  501. #ifdef BYTES_BIG_ENDIAN
  502. current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  503. - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  504. #endif
  505. current_sym_addr = 0;
  506. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
  507. fprintf (asmfile, ".stabs \"%s:p",
  508. IDENTIFIER_POINTER (DECL_NAME (parms)));
  509. dbxout_type (TREE_TYPE (parms), 0);
  510. dbxout_finish_symbol ();
  511. }
  512. }
  513. /* Output definitions, referring to registers,
  514. of all the parms in PARMS which are stored in registers during the function.
  515. PARMS is a chain of PARM_DECL nodes. */
  516. static void
  517. dbxout_reg_parms (parms)
  518. tree parms;
  519. {
  520. while (parms)
  521. {
  522. if (GET_CODE (DECL_RTL (parms)) == REG
  523. && REGNO (DECL_RTL (parms)) >= 0)
  524. {
  525. current_sym_code = N_RSYM;
  526. current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
  527. current_sym_addr = 0;
  528. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
  529. fprintf (asmfile, ".stabs \"%s:r",
  530. IDENTIFIER_POINTER (DECL_NAME (parms)));
  531. dbxout_type (TREE_TYPE (parms), 0);
  532. dbxout_finish_symbol ();
  533. }
  534. parms = TREE_CHAIN (parms);
  535. }
  536. }
  537. /* Given a chain of ..._TYPE nodes, all of which have names,
  538. output definitions of those names, as typedefs. */
  539. void
  540. dbxout_types (types)
  541. register tree types;
  542. {
  543. while (types)
  544. {
  545. if (TYPE_NAME (types)
  546. && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL)
  547. dbxout_type_def (types);
  548. types = TREE_CHAIN (types);
  549. }
  550. }
  551. /* Output a definition of a typedef name.
  552. It works much like any other kind of symbol definition. */
  553. static void
  554. dbxout_type_def (type)
  555. tree type;
  556. {
  557. current_sym_code = N_LSYM;
  558. current_sym_value = 0;
  559. current_sym_addr = 0;
  560. current_sym_nchars = 0;
  561. current_sym_nchars
  562. = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  563. fprintf (asmfile, ".stabs \"%s:t",
  564. IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  565. dbxout_type (type, 1);
  566. dbxout_finish_symbol ();
  567. }
  568. /* Output the tags (struct, union and enum definitions with names) for a block,
  569. given a list of them (a chain of TREE_LIST nodes) in TAGS.
  570. We must check to include those that have been mentioned already with
  571. only a cross-reference. */
  572. void
  573. dbxout_tags (tags)
  574. tree tags;
  575. {
  576. register tree link;
  577. for (link = tags; link; link = TREE_CHAIN (link))
  578. {
  579. register tree type = TREE_VALUE (link);
  580. if (TREE_PURPOSE (link) != 0
  581. && (TYPE_SYMTAB_ADDRESS (type) == 0
  582. || (typevec[TYPE_SYMTAB_ADDRESS (type)] != TYPE_DEFINED))
  583. && TYPE_SIZE (type) != 0)
  584. {
  585. current_sym_code = N_LSYM;
  586. current_sym_value = 0;
  587. current_sym_addr = 0;
  588. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (TREE_PURPOSE (link)));
  589. fprintf (asmfile, ".stabs \"%s:T",
  590. IDENTIFIER_POINTER (TREE_PURPOSE (link)));
  591. dbxout_type (type, 1);
  592. dbxout_finish_symbol ();
  593. typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_DEFINED;
  594. }
  595. }
  596. }
  597. /* Output everything about a symbol block (that is to say, a LET_STMT node
  598. that represents a scope level),
  599. including recursive output of contained blocks.
  600. STMT is the LET_STMT node.
  601. DEPTH is its depth within containing symbol blocks.
  602. ARGS is usually zero; but for the outermost block of the
  603. body of a function, it is a chain of PARM_DECLs for the function parameters.
  604. We output definitions of all the register parms
  605. as if they were local variables of that block.
  606. Actually, STMT may be several statements chained together.
  607. We handle them all in sequence. */
  608. static void
  609. dbxout_block (stmt, depth, args)
  610. register tree stmt;
  611. int depth;
  612. {
  613. int blocknum;
  614. while (stmt)
  615. {
  616. switch (TREE_CODE (stmt))
  617. {
  618. case COMPOUND_STMT:
  619. case LOOP_STMT:
  620. dbxout_block (STMT_BODY (stmt), depth, 0);
  621. break;
  622. case IF_STMT:
  623. dbxout_block (STMT_THEN (stmt), depth, 0);
  624. dbxout_block (STMT_ELSE (stmt), depth, 0);
  625. break;
  626. case LET_STMT:
  627. /* In dbx format, the syms of a block come before the N_LBRAC. */
  628. dbxout_tags (STMT_TYPE_TAGS (stmt));
  629. dbxout_syms (STMT_VARS (stmt), 1);
  630. if (args)
  631. dbxout_reg_parms (args);
  632. /* Now output an N_LBRAC symbol to represent the beginning of
  633. the block. Use the block's tree-walk order to generate
  634. the assembler symbols LBBn and LBEn
  635. that final will define around the code in this block. */
  636. if (depth > 0)
  637. {
  638. blocknum = next_block_number++;
  639. fprintf (asmfile, ".stabn %d,0,0,LBB%d\n", N_LBRAC, blocknum);
  640. }
  641. /* Output the interior of the block. */
  642. dbxout_block (STMT_BODY (stmt), depth + 1, 0);
  643. /* Refer to the marker for the end of the block. */
  644. if (depth > 0)
  645. fprintf (asmfile, ".stabn %d,0,0,LBE%d\n", N_RBRAC, blocknum);
  646. }
  647. stmt = TREE_CHAIN (stmt);
  648. }
  649. }
  650. /* Output dbx data for a function definition.
  651. This includes a definition of the function name itself (a symbol),
  652. definitions of the parameters (locating them in the parameter list)
  653. and then output the block that makes up the function's body
  654. (including all the auto variables of the function). */
  655. void
  656. dbxout_function (decl)
  657. tree decl;
  658. {
  659. dbxout_symbol (decl, 0);
  660. dbxout_parms (DECL_ARGUMENTS (decl));
  661. dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
  662. }