dbxout.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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 <stdio.h>
  58. /* Typical USG systems don't have stab.h, and they also have
  59. no use for DBX-format debugging info. */
  60. #ifndef NO_DBX_FORMAT
  61. #include <stab.h>
  62. /* Stream for writing to assembler file. */
  63. static FILE *asmfile;
  64. enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
  65. /* Vector recording the status of describing C data types.
  66. When we first notice a data type (a tree node),
  67. we assign it a number using next_type_number.
  68. That is its index in this vector.
  69. The vector element says whether we have yet output
  70. the definition of the type. TYPE_XREF says we have
  71. output it as a cross-reference only. */
  72. enum typestatus *typevec;
  73. /* Number of elements of space allocated in `typevec'. */
  74. static int typevec_len;
  75. /* In dbx output, each type gets a unique number.
  76. This is the number for the next type output.
  77. The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
  78. static int next_type_number;
  79. /* In dbx output, we must assign symbol-blocks id numbers
  80. in the order in which their beginnings are encountered.
  81. We output debugging info that refers to the beginning and
  82. end of the ranges of code in each block
  83. with assembler labels LBBn and LBEn, where n is the block number.
  84. The labels are generated in final, which assigns numbers to the
  85. blocks in the same way. */
  86. static int next_block_number;
  87. /* These variables are for dbxout_symbol to communicate to
  88. dbxout_finish_symbol.
  89. current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
  90. current_sym_value and current_sym_addr are two ways to address the
  91. value to store in the symtab entry.
  92. current_sym_addr if nonzero represents the value as an rtx.
  93. If that is zero, current_sym_value is used. This is used
  94. when the value is an offset (such as for auto variables,
  95. register variables and parms). */
  96. static int current_sym_code;
  97. static int current_sym_value;
  98. static rtx current_sym_addr;
  99. /* Number of chars of symbol-description generated so far for the
  100. current symbol. Used by CHARS and CONTIN. */
  101. static int current_sym_nchars;
  102. /* Report having output N chars of the current symbol-description. */
  103. #define CHARS(N) (current_sym_nchars += (N))
  104. /* Break the current symbol-description, generating a continuation,
  105. if it has become long. */
  106. #ifndef DBX_CONTIN_LENGTH
  107. #define DBX_CONTIN_LENGTH 80
  108. #endif
  109. #if DBX_CONTIN_LENGTH > 0
  110. #define CONTIN \
  111. do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
  112. #else
  113. #define CONTIN
  114. #endif
  115. void dbxout_types ();
  116. void dbxout_tags ();
  117. static void dbxout_type_name ();
  118. static void dbxout_type ();
  119. static void dbxout_type_def ();
  120. static void dbxout_finish_symbol ();
  121. static void dbxout_continue ();
  122. /* At the beginning of compilation, start writing the symbol table.
  123. Initialize `typevec' and output the standard data types of C. */
  124. void
  125. dbxout_init (asm_file, input_file_name)
  126. FILE *asm_file;
  127. char *input_file_name;
  128. {
  129. asmfile = asm_file;
  130. typevec_len = 100;
  131. typevec = (enum typestatus *) xmalloc (typevec_len * sizeof typevec[0]);
  132. bzero (typevec, typevec_len * sizeof typevec[0]);
  133. fprintf (asmfile,
  134. "Ltext:\t.stabs \"%s\",%d,0,0,Ltext\n",
  135. input_file_name, N_SO);
  136. next_type_number = 1;
  137. next_block_number = 2;
  138. /* Make sure that types `int' and `char' have numbers 1 and 2.
  139. Definitions of other integer types will refer to those numbers. */
  140. dbxout_type_def (integer_type_node);
  141. dbxout_type_def (char_type_node);
  142. /* Get all permanent types not yet gotten, and output them. */
  143. dbxout_types (get_permanent_types ());
  144. }
  145. /* Continue a symbol-description that gets too big.
  146. End one symbol table entry with a double-backslash
  147. and start a new one, eventually producing something like
  148. .stabs "start......\\",code,0,value
  149. .stabs "...rest",code,0,value */
  150. static void
  151. dbxout_continue ()
  152. {
  153. #ifdef DBX_CONTIN_CHAR
  154. fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
  155. #else
  156. fprintf (asmfile, "\\\\");
  157. #endif
  158. dbxout_finish_symbol ();
  159. fprintf (asmfile, ".stabs \"");
  160. current_sym_nchars = 0;
  161. }
  162. /* Output a reference to a type. If the type has not yet been
  163. described in the dbx output, output its definition now.
  164. For a type already defined, just refer to its definition
  165. using the type number.
  166. If FULL is nonzero, and the type has been described only with
  167. a forward-reference, output the definition now.
  168. If FULL is zero in this case, just refer to the forward-reference
  169. using the number previously allocated. */
  170. static void
  171. dbxout_type (type, full)
  172. tree type;
  173. int full;
  174. {
  175. register tree tem;
  176. /* If there was an input error and we don't really have a type,
  177. avoid crashing and write something that is at least valid
  178. by assuming `int'. */
  179. if (type == error_mark_node)
  180. type = integer_type_node;
  181. else if (TYPE_SIZE (type) == 0)
  182. type = TYPE_MAIN_VARIANT (type);
  183. if (TYPE_SYMTAB_ADDRESS (type) == 0)
  184. {
  185. /* Type has no dbx number assigned. Assign next available number. */
  186. TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
  187. /* Make sure type vector is long enough to record about this type. */
  188. if (next_type_number == typevec_len)
  189. {
  190. typevec = (enum typestatus *) xrealloc (typevec, typevec_len * 2 * sizeof typevec[0]);
  191. bzero (typevec + typevec_len, typevec_len * sizeof typevec[0]);
  192. typevec_len *= 2;
  193. }
  194. }
  195. /* Output the number of this type, to refer to it. */
  196. fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
  197. CHARS (3);
  198. /* If this type's definition has been output or is now being output,
  199. that is all. */
  200. switch (typevec[TYPE_SYMTAB_ADDRESS (type)])
  201. {
  202. case TYPE_UNSEEN:
  203. break;
  204. case TYPE_XREF:
  205. if (! full)
  206. return;
  207. break;
  208. case TYPE_DEFINED:
  209. return;
  210. }
  211. #ifdef DBX_NO_XREFS
  212. /* For systems where dbx output does not allow the `=xsNAME:' syntax,
  213. leave the type-number completely undefined rather than output
  214. a cross-reference. */
  215. if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
  216. || TREE_CODE (type) == ENUMERAL_TYPE)
  217. if ((TYPE_NAME (type) != 0 && !full)
  218. || TYPE_SIZE (type) == 0)
  219. {
  220. typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
  221. return;
  222. }
  223. #endif
  224. /* Output a definition now. */
  225. fprintf (asmfile, "=");
  226. CHARS (1);
  227. /* Mark it as defined, so that if it is self-referent
  228. we will not get into an infinite recursion of definitions. */
  229. typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_DEFINED;
  230. switch (TREE_CODE (type))
  231. {
  232. case VOID_TYPE:
  233. /* For a void type, just define it as itself; ie, "5=5".
  234. This makes us consider it defined
  235. without saying what it is. The debugger will make it
  236. a void type when the reference is seen, and nothing will
  237. ever override that default. */
  238. fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
  239. CHARS (3);
  240. break;
  241. case INTEGER_TYPE:
  242. if (type == char_type_node && ! TREE_UNSIGNED (type))
  243. /* Output the type `char' as a subrange of itself!
  244. I don't understand this definition, just copied it
  245. from the output of pcc. */
  246. fprintf (asmfile, "r2;0;127;");
  247. else
  248. /* Output other integer types as subranges of `int'. */
  249. fprintf (asmfile, "r1;%d;%d;",
  250. TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)),
  251. TREE_INT_CST_LOW (TYPE_MAX_VALUE (type)));
  252. CHARS (25);
  253. break;
  254. case REAL_TYPE:
  255. /* This must be magic. */
  256. fprintf (asmfile, "r1;%d;0;",
  257. TREE_INT_CST_LOW (size_in_bytes (type)));
  258. CHARS (16);
  259. break;
  260. case ARRAY_TYPE:
  261. /* Output "a" followed by a range type definition
  262. for the index type of the array
  263. followed by a reference to the target-type.
  264. ar1;0;N;M for an array of type M and size N. */
  265. fprintf (asmfile, "ar1;0;%d;",
  266. (TYPE_DOMAIN (type)
  267. ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
  268. : -1));
  269. CHARS (17);
  270. dbxout_type (TREE_TYPE (type), 0);
  271. break;
  272. case RECORD_TYPE:
  273. case UNION_TYPE:
  274. /* Output a structure type. */
  275. if ((TYPE_NAME (type) != 0 && !full)
  276. || TYPE_SIZE (type) == 0)
  277. {
  278. /* If the type is just a cross reference, output one
  279. and mark the type as partially described.
  280. If it later becomes defined, we will output
  281. its real definition.
  282. If the type has a name, don't nest its name within
  283. another type's definition; instead, output an xref
  284. and let the definition come when the name is defined. */
  285. fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
  286. CHARS (3);
  287. dbxout_type_name (type);
  288. fprintf (asmfile, ":");
  289. typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
  290. break;
  291. }
  292. tem = size_in_bytes (type);
  293. fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "s%d" : "u%d",
  294. TREE_INT_CST_LOW (tem));
  295. CHARS (11);
  296. for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  297. /* Output the name, type, position (in bits), size (in bits)
  298. of each field. */
  299. /* Omit here the nameless fields that are used to skip bits. */
  300. if (DECL_NAME (tem) != 0)
  301. {
  302. /* Continue the line if necessary,
  303. but not before the first field. */
  304. if (tem != TYPE_FIELDS (type))
  305. CONTIN;
  306. fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
  307. CHARS (1 + strlen (IDENTIFIER_POINTER (DECL_NAME (tem))));
  308. dbxout_type (TREE_TYPE (tem), 0);
  309. fprintf (asmfile, ",%d,%d;", DECL_OFFSET (tem),
  310. TREE_INT_CST_LOW (DECL_SIZE (tem)) * DECL_SIZE_UNIT (tem));
  311. CHARS (23);
  312. }
  313. putc (';', asmfile);
  314. CHARS (1);
  315. break;
  316. case ENUMERAL_TYPE:
  317. if ((TYPE_NAME (type) != 0 && !full)
  318. || TYPE_SIZE (type) == 0)
  319. {
  320. fprintf (asmfile, "xe");
  321. CHARS (3);
  322. dbxout_type_name (type);
  323. typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
  324. fprintf (asmfile, ":");
  325. return;
  326. }
  327. putc ('e', asmfile);
  328. CHARS (1);
  329. for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
  330. {
  331. fprintf (asmfile, "%s:%d,", IDENTIFIER_POINTER (TREE_PURPOSE (tem)),
  332. TREE_INT_CST_LOW (TREE_VALUE (tem)));
  333. CHARS (11 + strlen (IDENTIFIER_POINTER (TREE_PURPOSE (tem))));
  334. if (TREE_CHAIN (tem) != 0)
  335. CONTIN;
  336. }
  337. putc (';', asmfile);
  338. CHARS (1);
  339. break;
  340. case POINTER_TYPE:
  341. putc ('*', asmfile);
  342. CHARS (1);
  343. dbxout_type (TREE_TYPE (type), 0);
  344. break;
  345. case FUNCTION_TYPE:
  346. putc ('f', asmfile);
  347. CHARS (1);
  348. dbxout_type (TREE_TYPE (type), 0);
  349. break;
  350. }
  351. }
  352. /* Output the name of type TYPE, with no punctuation.
  353. Such names can be set up either by typedef declarations
  354. or by struct, enum and union tags. */
  355. static void
  356. dbxout_type_name (type)
  357. register tree type;
  358. {
  359. register char *name;
  360. if (TYPE_NAME (type) == 0)
  361. abort ();
  362. if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  363. name = IDENTIFIER_POINTER (TYPE_NAME (type));
  364. else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  365. name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  366. else
  367. abort ();
  368. fprintf (asmfile, "%s", name);
  369. CHARS (strlen (name));
  370. }
  371. /* Output a .stabs for the symbol defined by DECL,
  372. which must be a ..._DECL node in the normal namespace.
  373. It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
  374. LOCAL is nonzero if the scope is less than the entire file. */
  375. void
  376. dbxout_symbol (decl, local)
  377. tree decl;
  378. int local;
  379. {
  380. int letter = 0;
  381. tree type = TREE_TYPE (decl);
  382. /* If global, first output all types and all
  383. struct, enum and union tags that have been created
  384. and not yet output. */
  385. if (local == 0)
  386. {
  387. dbxout_tags (gettags ());
  388. dbxout_types (get_permanent_types ());
  389. }
  390. /* If the decl lacks rtl representation, avoid fault below. */
  391. if (DECL_RTL (decl) == 0)
  392. return;
  393. current_sym_code = 0;
  394. current_sym_value = 0;
  395. current_sym_addr = 0;
  396. /* The output will always start with the symbol name,
  397. so count that always in the length-output-so-far. */
  398. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (decl)));
  399. switch (TREE_CODE (decl))
  400. {
  401. case CONST_DECL:
  402. /* Enum values are defined by defining the enum type. */
  403. break;
  404. case FUNCTION_DECL:
  405. if (TREE_EXTERNAL (decl))
  406. break;
  407. if (GET_CODE (DECL_RTL (decl)) != MEM
  408. || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
  409. break;
  410. fprintf (asmfile, ".stabs \"%s:%c",
  411. IDENTIFIER_POINTER (DECL_NAME (decl)),
  412. TREE_PUBLIC (decl) ? 'F' : 'f');
  413. current_sym_code = N_FUN;
  414. current_sym_addr = XEXP (DECL_RTL (decl), 0);
  415. if (TREE_TYPE (TREE_TYPE (decl)))
  416. dbxout_type (TREE_TYPE (TREE_TYPE (decl)), 0);
  417. else
  418. dbxout_type (void_type_node, 0);
  419. dbxout_finish_symbol ();
  420. break;
  421. case TYPE_DECL:
  422. /* Output typedef name. */
  423. fprintf (asmfile, ".stabs \"%s:t",
  424. IDENTIFIER_POINTER (DECL_NAME (decl)));
  425. current_sym_code = N_LSYM;
  426. dbxout_type (TREE_TYPE (decl), 0);
  427. dbxout_finish_symbol ();
  428. break;
  429. case PARM_DECL:
  430. /* Parm decls go in their own separate chains
  431. and are output by dbxout_reg_parms and dbxout_parms. */
  432. abort ();
  433. case VAR_DECL:
  434. /* Don't mention a variable that is external.
  435. Let the file that defines it describe it. */
  436. if (TREE_EXTERNAL (decl))
  437. break;
  438. /* Don't mention a variable at all
  439. if it was completely optimized into nothingness. */
  440. if (GET_CODE (DECL_RTL (decl)) == REG
  441. && (REGNO (DECL_RTL (decl)) < 0
  442. || REGNO (DECL_RTL (decl)) >= FIRST_PSEUDO_REGISTER))
  443. break;
  444. /* Ok, start a symtab entry and output the variable name. */
  445. fprintf (asmfile, ".stabs \"%s:",
  446. IDENTIFIER_POINTER (DECL_NAME (decl)));
  447. /* The kind-of-variable letter depends on where
  448. the variable is and on the scope of its name:
  449. G and N_GSYM for static storage and global scope,
  450. S for static storage and file scope,
  451. v for static storage and local scope,
  452. for those two, use N_LCSYM if data is in bss segment,
  453. N_STSYM if it is in data segment, or N_FUN if in text segment.
  454. no letter at all, and N_LSYM, for auto variable,
  455. r and N_RSYM for register variable. */
  456. if (GET_CODE (DECL_RTL (decl)) == MEM
  457. && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
  458. {
  459. if (TREE_PUBLIC (decl))
  460. {
  461. letter = 'G';
  462. current_sym_code = N_GSYM;
  463. }
  464. else
  465. {
  466. current_sym_addr = XEXP (DECL_RTL (decl), 0);
  467. letter = TREE_PERMANENT (decl) ? 'S' : 'v';
  468. if (!DECL_INITIAL (decl))
  469. current_sym_code = N_LCSYM;
  470. else if (TREE_READONLY (decl) && ! TREE_VOLATILE (decl))
  471. /* This is not quite right, but it's the closest
  472. of all the codes that Unix defines. */
  473. current_sym_code = N_FUN;
  474. else
  475. current_sym_code = N_STSYM;
  476. }
  477. }
  478. else if (GET_CODE (DECL_RTL (decl)) == REG)
  479. {
  480. letter = 'r';
  481. current_sym_code = N_RSYM;
  482. current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl)));
  483. }
  484. else if (GET_CODE (DECL_RTL (decl)) == MEM
  485. && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
  486. || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
  487. && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
  488. /* If the value is indirect by memory or by a register
  489. that isn't the frame pointer
  490. then it means the object is variable-sized and address through
  491. that register or stack slot. DBX has no way to represent this
  492. so all we can do is output the variable as a pointer. */
  493. {
  494. if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
  495. {
  496. letter = 'r';
  497. current_sym_code = N_RSYM;
  498. current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (DECL_RTL (decl), 0)));
  499. }
  500. else
  501. {
  502. current_sym_code = N_LSYM;
  503. /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
  504. We want the value of that CONST_INT. */
  505. current_sym_value = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (decl), 0), 0), 1));
  506. }
  507. type = build_pointer_type (TREE_TYPE (decl));
  508. }
  509. else if (GET_CODE (DECL_RTL (decl)) == MEM
  510. && XEXP (DECL_RTL (decl), 0) != const0_rtx)
  511. /* const0_rtx is used as the address for a variable that
  512. is a dummy due to an erroneous declaration.
  513. Ignore such vars. */
  514. {
  515. current_sym_code = N_LSYM;
  516. if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
  517. current_sym_value = 0;
  518. else
  519. /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
  520. We want the value of that CONST_INT. */
  521. current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1));
  522. }
  523. if (letter) putc (letter, asmfile);
  524. dbxout_type (type, 0);
  525. dbxout_finish_symbol ();
  526. break;
  527. }
  528. }
  529. static void
  530. dbxout_finish_symbol ()
  531. {
  532. fprintf (asmfile, "\",%d,0,0,", current_sym_code);
  533. if (current_sym_addr)
  534. output_addr_const (asmfile, current_sym_addr);
  535. else
  536. fprintf (asmfile, "%d", current_sym_value);
  537. putc ('\n', asmfile);
  538. }
  539. /* Output definitions of all the decls in a chain. */
  540. static void
  541. dbxout_syms (syms)
  542. tree syms;
  543. {
  544. while (syms)
  545. {
  546. dbxout_symbol (syms, 1);
  547. syms = TREE_CHAIN (syms);
  548. }
  549. }
  550. /* The following two functions output definitions of function parameters.
  551. Each parameter gets a definition locating it in the parameter list.
  552. Each parameter that is a register variable gets a second definition
  553. locating it in the register.
  554. Printing or argument lists in gdb uses the definitions that
  555. locate in the parameter list. But reference to the variable in
  556. expressions uses preferentially the definition as a register. */
  557. /* Output definitions, referring to storage in the parmlist,
  558. of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
  559. static void
  560. dbxout_parms (parms)
  561. tree parms;
  562. {
  563. for (; parms; parms = TREE_CHAIN (parms))
  564. {
  565. if (DECL_OFFSET (parms) >= 0)
  566. {
  567. current_sym_code = N_PSYM;
  568. current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  569. current_sym_addr = 0;
  570. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
  571. fprintf (asmfile, ".stabs \"%s:p",
  572. IDENTIFIER_POINTER (DECL_NAME (parms)));
  573. if (GET_CODE (DECL_RTL (parms)) == REG
  574. && REGNO (DECL_RTL (parms)) >= 0
  575. && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  576. dbxout_type (DECL_ARG_TYPE (parms), 0);
  577. else
  578. {
  579. /* This is the case where the parm is passed as an int or double
  580. and it is converted to a char, short or float and stored back
  581. in the parmlist. In this case, describe the parm
  582. with the variable's declared type, and adjust the address
  583. if the least significant bytes (which we are using) are not
  584. the first ones. */
  585. #ifdef BYTES_BIG_ENDIAN
  586. if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  587. current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  588. - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  589. #endif
  590. if (GET_CODE (DECL_RTL (parms)) == MEM
  591. && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  592. && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
  593. && INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == current_sym_value)
  594. dbxout_type (TREE_TYPE (parms), 0);
  595. else
  596. {
  597. current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  598. dbxout_type (DECL_ARG_TYPE (parms), 0);
  599. }
  600. }
  601. dbxout_finish_symbol ();
  602. }
  603. /* Parm was passed in registers.
  604. If it is in a register, output a "regparm" symbol
  605. for the register it lives in. */
  606. else if (GET_CODE (DECL_RTL (parms)) == REG)
  607. {
  608. current_sym_code = N_RSYM;
  609. current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
  610. current_sym_addr = 0;
  611. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
  612. fprintf (asmfile, ".stabs \"%s:P",
  613. IDENTIFIER_POINTER (DECL_NAME (parms)));
  614. dbxout_type (DECL_ARG_TYPE (parms), 0);
  615. dbxout_finish_symbol ();
  616. }
  617. else if (GET_CODE (DECL_RTL (parms)) == MEM
  618. && XEXP (DECL_RTL (parms), 0) != const0_rtx)
  619. {
  620. current_sym_code = N_LSYM;
  621. /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
  622. We want the value of that CONST_INT. */
  623. current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
  624. current_sym_addr = 0;
  625. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
  626. fprintf (asmfile, ".stabs \"%s:p",
  627. IDENTIFIER_POINTER (DECL_NAME (parms)));
  628. /* This is the case where the parm is passed as an int or double
  629. and it is converted to a char, short or float and stored back
  630. in the parmlist. In this case, describe the parm
  631. with the variable's declared type, and adjust the address
  632. if the least significant bytes (which we are using) are not
  633. the first ones. */
  634. #ifdef BYTES_BIG_ENDIAN
  635. if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  636. current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  637. - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  638. #endif
  639. dbxout_type (TREE_TYPE (parms), 0);
  640. dbxout_finish_symbol ();
  641. }
  642. }
  643. }
  644. /* Output definitions, referring to registers,
  645. of all the parms in PARMS which are stored in registers during the function.
  646. PARMS is a chain of PARM_DECL nodes. */
  647. static void
  648. dbxout_reg_parms (parms)
  649. tree parms;
  650. {
  651. while (parms)
  652. {
  653. /* Report parms that live in registers during the function. */
  654. if (GET_CODE (DECL_RTL (parms)) == REG
  655. && REGNO (DECL_RTL (parms)) >= 0
  656. && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
  657. && DECL_OFFSET (parms) >= 0)
  658. {
  659. current_sym_code = N_RSYM;
  660. current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
  661. current_sym_addr = 0;
  662. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
  663. fprintf (asmfile, ".stabs \"%s:r",
  664. IDENTIFIER_POINTER (DECL_NAME (parms)));
  665. dbxout_type (TREE_TYPE (parms), 0);
  666. dbxout_finish_symbol ();
  667. }
  668. /* Report parms that live in memory but outside the parmlist. */
  669. else if (GET_CODE (DECL_RTL (parms)) == MEM
  670. && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  671. && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT)
  672. {
  673. int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
  674. /* A parm declared char is really passed as an int,
  675. so it occupies the least significant bytes.
  676. On a big-endian machine those are not the low-numbered ones. */
  677. #ifdef BYTES_BIG_ENDIAN
  678. if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  679. offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  680. - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  681. #endif
  682. if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset)
  683. {
  684. current_sym_code = N_LSYM;
  685. current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
  686. current_sym_addr = 0;
  687. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
  688. fprintf (asmfile, ".stabs \"%s:",
  689. IDENTIFIER_POINTER (DECL_NAME (parms)));
  690. dbxout_type (TREE_TYPE (parms), 0);
  691. dbxout_finish_symbol ();
  692. }
  693. }
  694. parms = TREE_CHAIN (parms);
  695. }
  696. }
  697. /* Given a chain of ..._TYPE nodes, all of which have names,
  698. output definitions of those names, as typedefs. */
  699. void
  700. dbxout_types (types)
  701. register tree types;
  702. {
  703. while (types)
  704. {
  705. if (TYPE_NAME (types)
  706. && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL)
  707. dbxout_type_def (types);
  708. types = TREE_CHAIN (types);
  709. }
  710. }
  711. /* Output a definition of a typedef name.
  712. It works much like any other kind of symbol definition.
  713. Output nothing if TYPE's definition has been output already. */
  714. static void
  715. dbxout_type_def (type)
  716. tree type;
  717. {
  718. #if 0 /* Incorrect; causes some type NAMES not to be defined,
  719. whose TYPES were defined already. */
  720. if (TYPE_SYMTAB_ADDRESS (type) != 0
  721. && typevec[TYPE_SYMTAB_ADDRESS (type)] == TYPE_DEFINED)
  722. return;
  723. #endif
  724. current_sym_code = N_LSYM;
  725. current_sym_value = 0;
  726. current_sym_addr = 0;
  727. current_sym_nchars = 0;
  728. current_sym_nchars
  729. = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  730. fprintf (asmfile, ".stabs \"%s:t",
  731. IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  732. dbxout_type (type, 1);
  733. dbxout_finish_symbol ();
  734. }
  735. /* Output the tags (struct, union and enum definitions with names) for a block,
  736. given a list of them (a chain of TREE_LIST nodes) in TAGS.
  737. We must check to include those that have been mentioned already with
  738. only a cross-reference. */
  739. void
  740. dbxout_tags (tags)
  741. tree tags;
  742. {
  743. register tree link;
  744. for (link = tags; link; link = TREE_CHAIN (link))
  745. {
  746. register tree type = TYPE_MAIN_VARIANT (TREE_VALUE (link));
  747. if (TREE_PURPOSE (link) != 0
  748. && ! TREE_ASM_WRITTEN (link)
  749. && TYPE_SIZE (type) != 0)
  750. {
  751. TREE_ASM_WRITTEN (link) = 1;
  752. current_sym_code = N_LSYM;
  753. current_sym_value = 0;
  754. current_sym_addr = 0;
  755. current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (TREE_PURPOSE (link)));
  756. fprintf (asmfile, ".stabs \"%s:T",
  757. IDENTIFIER_POINTER (TREE_PURPOSE (link)));
  758. dbxout_type (type, 1);
  759. dbxout_finish_symbol ();
  760. }
  761. }
  762. }
  763. /* Output everything about a symbol block (that is to say, a LET_STMT node
  764. that represents a scope level),
  765. including recursive output of contained blocks.
  766. STMT is the LET_STMT node.
  767. DEPTH is its depth within containing symbol blocks.
  768. ARGS is usually zero; but for the outermost block of the
  769. body of a function, it is a chain of PARM_DECLs for the function parameters.
  770. We output definitions of all the register parms
  771. as if they were local variables of that block.
  772. Actually, STMT may be several statements chained together.
  773. We handle them all in sequence. */
  774. static void
  775. dbxout_block (stmt, depth, args)
  776. register tree stmt;
  777. int depth;
  778. tree args;
  779. {
  780. int blocknum;
  781. while (stmt)
  782. {
  783. switch (TREE_CODE (stmt))
  784. {
  785. case COMPOUND_STMT:
  786. case LOOP_STMT:
  787. dbxout_block (STMT_BODY (stmt), depth, 0);
  788. break;
  789. case IF_STMT:
  790. dbxout_block (STMT_THEN (stmt), depth, 0);
  791. dbxout_block (STMT_ELSE (stmt), depth, 0);
  792. break;
  793. case LET_STMT:
  794. /* In dbx format, the syms of a block come before the N_LBRAC. */
  795. dbxout_tags (STMT_TYPE_TAGS (stmt));
  796. dbxout_syms (STMT_VARS (stmt));
  797. if (args)
  798. dbxout_reg_parms (args);
  799. /* Now output an N_LBRAC symbol to represent the beginning of
  800. the block. Use the block's tree-walk order to generate
  801. the assembler symbols LBBn and LBEn
  802. that final will define around the code in this block. */
  803. if (depth > 0)
  804. {
  805. blocknum = next_block_number++;
  806. fprintf (asmfile, ".stabn %d,0,0,LBB%d\n", N_LBRAC, blocknum);
  807. }
  808. /* Output the interior of the block. */
  809. dbxout_block (STMT_BODY (stmt), depth + 1, 0);
  810. /* Refer to the marker for the end of the block. */
  811. if (depth > 0)
  812. fprintf (asmfile, ".stabn %d,0,0,LBE%d\n", N_RBRAC, blocknum);
  813. }
  814. stmt = TREE_CHAIN (stmt);
  815. }
  816. }
  817. /* Output dbx data for a function definition.
  818. This includes a definition of the function name itself (a symbol),
  819. definitions of the parameters (locating them in the parameter list)
  820. and then output the block that makes up the function's body
  821. (including all the auto variables of the function). */
  822. void
  823. dbxout_function (decl)
  824. tree decl;
  825. {
  826. dbxout_symbol (decl, 0);
  827. dbxout_parms (DECL_ARGUMENTS (decl));
  828. dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
  829. }
  830. #else /* NO_DBX_FORMAT */
  831. void
  832. dbxout_init (asm_file, input_file_name)
  833. FILE *asm_file;
  834. char *input_file_name;
  835. {}
  836. void
  837. dbxout_symbol (decl, local)
  838. tree decl;
  839. int local;
  840. {}
  841. void
  842. dbxout_types (types)
  843. register tree types;
  844. {}
  845. void
  846. dbxout_tags (tags)
  847. tree tags;
  848. {}
  849. void
  850. dbxout_function (decl)
  851. tree decl;
  852. {}
  853. #endif /* NO_DBX_FORMAT */