|
|
1.1 root 1: /* Output dbx-format symbol table information from GNU compiler.
1.1.1.6 root 2: Copyright (C) 1987, 1988 Free Software Foundation, Inc.
1.1 root 3:
4: This file is part of GNU CC.
5:
1.1.1.12! root 6: GNU CC is free software; you can redistribute it and/or modify
! 7: it under the terms of the GNU General Public License as published by
! 8: the Free Software Foundation; either version 1, or (at your option)
! 9: any later version.
! 10:
1.1 root 11: GNU CC is distributed in the hope that it will be useful,
1.1.1.12! root 12: but WITHOUT ANY WARRANTY; without even the implied warranty of
! 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 14: GNU General Public License for more details.
! 15:
! 16: You should have received a copy of the GNU General Public License
! 17: along with GNU CC; see the file COPYING. If not, write to
! 18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
1.1 root 19:
20:
21: /* Output dbx-format symbol table data.
22: This consists of many symbol table entries, each of them
23: a .stabs assembler pseudo-op with four operands:
24: a "name" which is really a description of one symbol and its type,
25: a "code", which is a symbol defined in stab.h whose name starts with N_,
26: an unused operand always 0,
27: and a "value" which is an address or an offset.
28: The name is enclosed in doublequote characters.
29:
30: Each function, variable, typedef, and structure tag
31: has a symbol table entry to define it.
32: The beginning and end of each level of name scoping within
33: a function are also marked by special symbol table entries.
34:
35: The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
36: and a data type number. The data type number may be followed by
37: "=" and a type definition; normally this will happen the first time
38: the type number is mentioned. The type definition may refer to
39: other types by number, and those type numbers may be followed
40: by "=" and nested definitions.
41:
42: This can make the "name" quite long.
43: When a name is more than 80 characters, we split the .stabs pseudo-op
44: into two .stabs pseudo-ops, both sharing the same "code" and "value".
45: The first one is marked as continued with a double-backslash at the
46: end of its "name".
47:
48: The kind-of-symbol letter distinguished function names from global
49: variables from file-scope variables from parameters from auto
50: variables in memory from typedef names from register variables.
51: See `dbxout_symbol'.
52:
53: The "code" is mostly redundant with the kind-of-symbol letter
54: that goes in the "name", but not entirely: for symbols located
55: in static storage, the "code" says which segment the address is in,
56: which controls how it is relocated.
57:
58: The "value" for a symbol in static storage
59: is the core address of the symbol (actually, the assembler
60: label for the symbol). For a symbol located in a stack slot
61: it is the stack offset; for one in a register, the register number.
62: For a typedef symbol, it is zero.
63:
1.1.1.9 root 64: If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
65: output while in the text section.
66:
1.1 root 67: For more on data type definitions, see `dbxout_type'. */
68:
69: #include "config.h"
70: #include "tree.h"
71: #include "rtl.h"
1.1.1.6 root 72: #include "flags.h"
1.1 root 73: #include <stdio.h>
1.1.1.2 root 74:
75: /* Typical USG systems don't have stab.h, and they also have
76: no use for DBX-format debugging info. */
77:
1.1.1.4 root 78: #ifdef DBX_DEBUGGING_INFO
1.1.1.2 root 79:
1.1.1.9 root 80: #ifdef DEBUG_SYMS_TEXT
81: #define FORCE_TEXT text_section ();
82: #else
83: #define FORCE_TEXT
84: #endif
85:
1.1.1.11 root 86: #ifdef USG
87: #include "stab.h" /* If doing DBX on sysV, use our own stab.h. */
88: #else
89: #include <stab.h> /* On BSD, use the system's stab.h. */
90: #endif /* not USG */
1.1.1.2 root 91:
1.1 root 92: /* Stream for writing to assembler file. */
93:
94: static FILE *asmfile;
95:
96: enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
97:
98: /* Vector recording the status of describing C data types.
99: When we first notice a data type (a tree node),
100: we assign it a number using next_type_number.
101: That is its index in this vector.
102: The vector element says whether we have yet output
103: the definition of the type. TYPE_XREF says we have
104: output it as a cross-reference only. */
105:
106: enum typestatus *typevec;
107:
108: /* Number of elements of space allocated in `typevec'. */
109:
110: static int typevec_len;
111:
112: /* In dbx output, each type gets a unique number.
113: This is the number for the next type output.
114: The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
115:
116: static int next_type_number;
117:
118: /* In dbx output, we must assign symbol-blocks id numbers
119: in the order in which their beginnings are encountered.
120: We output debugging info that refers to the beginning and
121: end of the ranges of code in each block
122: with assembler labels LBBn and LBEn, where n is the block number.
123: The labels are generated in final, which assigns numbers to the
124: blocks in the same way. */
125:
126: static int next_block_number;
127:
128: /* These variables are for dbxout_symbol to communicate to
129: dbxout_finish_symbol.
130: current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
131: current_sym_value and current_sym_addr are two ways to address the
132: value to store in the symtab entry.
133: current_sym_addr if nonzero represents the value as an rtx.
134: If that is zero, current_sym_value is used. This is used
135: when the value is an offset (such as for auto variables,
136: register variables and parms). */
137:
138: static int current_sym_code;
139: static int current_sym_value;
140: static rtx current_sym_addr;
141:
142: /* Number of chars of symbol-description generated so far for the
143: current symbol. Used by CHARS and CONTIN. */
144:
145: static int current_sym_nchars;
146:
147: /* Report having output N chars of the current symbol-description. */
148:
149: #define CHARS(N) (current_sym_nchars += (N))
150:
151: /* Break the current symbol-description, generating a continuation,
152: if it has become long. */
153:
1.1.1.2 root 154: #ifndef DBX_CONTIN_LENGTH
155: #define DBX_CONTIN_LENGTH 80
156: #endif
157:
158: #if DBX_CONTIN_LENGTH > 0
1.1 root 159: #define CONTIN \
1.1.1.2 root 160: do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
161: #else
162: #define CONTIN
163: #endif
1.1 root 164:
165: void dbxout_types ();
166: void dbxout_tags ();
1.1.1.6 root 167: void dbxout_args ();
1.1.1.7 root 168: void dbxout_symbol ();
1.1 root 169: static void dbxout_type_name ();
170: static void dbxout_type ();
171: static void dbxout_finish_symbol ();
172: static void dbxout_continue ();
173:
174: /* At the beginning of compilation, start writing the symbol table.
175: Initialize `typevec' and output the standard data types of C. */
176:
177: void
178: dbxout_init (asm_file, input_file_name)
179: FILE *asm_file;
180: char *input_file_name;
181: {
182: asmfile = asm_file;
183:
184: typevec_len = 100;
185: typevec = (enum typestatus *) xmalloc (typevec_len * sizeof typevec[0]);
186: bzero (typevec, typevec_len * sizeof typevec[0]);
1.1.1.6 root 187:
1.1.1.5 root 188: /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
1.1 root 189: fprintf (asmfile,
1.1.1.5 root 190: "\t.stabs \"%s\",%d,0,0,Ltext\nLtext:\n",
1.1.1.2 root 191: input_file_name, N_SO);
1.1 root 192:
193: next_type_number = 1;
194: next_block_number = 2;
195:
196: /* Make sure that types `int' and `char' have numbers 1 and 2.
197: Definitions of other integer types will refer to those numbers. */
198:
1.1.1.10 root 199: dbxout_symbol (TYPE_NAME (integer_type_node), 0);
200: dbxout_symbol (TYPE_NAME (char_type_node), 0);
1.1 root 201:
1.1.1.2 root 202: /* Get all permanent types not yet gotten, and output them. */
1.1 root 203:
204: dbxout_types (get_permanent_types ());
205: }
206:
207: /* Continue a symbol-description that gets too big.
208: End one symbol table entry with a double-backslash
209: and start a new one, eventually producing something like
210: .stabs "start......\\",code,0,value
211: .stabs "...rest",code,0,value */
212:
213: static void
214: dbxout_continue ()
215: {
1.1.1.2 root 216: #ifdef DBX_CONTIN_CHAR
217: fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
218: #else
1.1 root 219: fprintf (asmfile, "\\\\");
1.1.1.2 root 220: #endif
1.1 root 221: dbxout_finish_symbol ();
222: fprintf (asmfile, ".stabs \"");
223: current_sym_nchars = 0;
224: }
225:
226: /* Output a reference to a type. If the type has not yet been
227: described in the dbx output, output its definition now.
228: For a type already defined, just refer to its definition
229: using the type number.
230:
231: If FULL is nonzero, and the type has been described only with
232: a forward-reference, output the definition now.
233: If FULL is zero in this case, just refer to the forward-reference
234: using the number previously allocated. */
235:
236: static void
237: dbxout_type (type, full)
238: tree type;
239: int full;
240: {
241: register tree tem;
242:
1.1.1.2 root 243: /* If there was an input error and we don't really have a type,
244: avoid crashing and write something that is at least valid
245: by assuming `int'. */
246: if (type == error_mark_node)
247: type = integer_type_node;
248: else if (TYPE_SIZE (type) == 0)
249: type = TYPE_MAIN_VARIANT (type);
250:
1.1 root 251: if (TYPE_SYMTAB_ADDRESS (type) == 0)
252: {
253: /* Type has no dbx number assigned. Assign next available number. */
254: TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
255:
256: /* Make sure type vector is long enough to record about this type. */
257:
258: if (next_type_number == typevec_len)
259: {
260: typevec = (enum typestatus *) xrealloc (typevec, typevec_len * 2 * sizeof typevec[0]);
261: bzero (typevec + typevec_len, typevec_len * sizeof typevec[0]);
262: typevec_len *= 2;
263: }
264: }
265:
266: /* Output the number of this type, to refer to it. */
267: fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
268: CHARS (3);
269:
270: /* If this type's definition has been output or is now being output,
271: that is all. */
272:
273: switch (typevec[TYPE_SYMTAB_ADDRESS (type)])
274: {
275: case TYPE_UNSEEN:
276: break;
277: case TYPE_XREF:
278: if (! full)
279: return;
280: break;
281: case TYPE_DEFINED:
282: return;
283: }
284:
1.1.1.2 root 285: #ifdef DBX_NO_XREFS
286: /* For systems where dbx output does not allow the `=xsNAME:' syntax,
287: leave the type-number completely undefined rather than output
288: a cross-reference. */
289: if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
290: || TREE_CODE (type) == ENUMERAL_TYPE)
291:
292: if ((TYPE_NAME (type) != 0 && !full)
293: || TYPE_SIZE (type) == 0)
294: {
295: typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
296: return;
297: }
298: #endif
299:
1.1 root 300: /* Output a definition now. */
301:
302: fprintf (asmfile, "=");
303: CHARS (1);
304:
305: /* Mark it as defined, so that if it is self-referent
306: we will not get into an infinite recursion of definitions. */
307:
308: typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_DEFINED;
309:
310: switch (TREE_CODE (type))
311: {
312: case VOID_TYPE:
313: /* For a void type, just define it as itself; ie, "5=5".
314: This makes us consider it defined
315: without saying what it is. The debugger will make it
316: a void type when the reference is seen, and nothing will
317: ever override that default. */
318: fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
319: CHARS (3);
320: break;
321:
322: case INTEGER_TYPE:
1.1.1.2 root 323: if (type == char_type_node && ! TREE_UNSIGNED (type))
1.1 root 324: /* Output the type `char' as a subrange of itself!
325: I don't understand this definition, just copied it
326: from the output of pcc. */
327: fprintf (asmfile, "r2;0;127;");
328: else
329: /* Output other integer types as subranges of `int'. */
330: fprintf (asmfile, "r1;%d;%d;",
331: TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)),
332: TREE_INT_CST_LOW (TYPE_MAX_VALUE (type)));
333: CHARS (25);
334: break;
335:
336: case REAL_TYPE:
337: /* This must be magic. */
338: fprintf (asmfile, "r1;%d;0;",
339: TREE_INT_CST_LOW (size_in_bytes (type)));
340: CHARS (16);
341: break;
342:
343: case ARRAY_TYPE:
344: /* Output "a" followed by a range type definition
345: for the index type of the array
346: followed by a reference to the target-type.
347: ar1;0;N;M for an array of type M and size N. */
348: fprintf (asmfile, "ar1;0;%d;",
1.1.1.2 root 349: (TYPE_DOMAIN (type)
350: ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
351: : -1));
1.1 root 352: CHARS (17);
353: dbxout_type (TREE_TYPE (type), 0);
354: break;
355:
356: case RECORD_TYPE:
357: case UNION_TYPE:
358: /* Output a structure type. */
359: if ((TYPE_NAME (type) != 0 && !full)
360: || TYPE_SIZE (type) == 0)
361: {
362: /* If the type is just a cross reference, output one
363: and mark the type as partially described.
364: If it later becomes defined, we will output
1.1.1.2 root 365: its real definition.
1.1.1.7 root 366: If the type has a name, don't nest its definition within
1.1.1.2 root 367: another type's definition; instead, output an xref
368: and let the definition come when the name is defined. */
1.1 root 369: fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
370: CHARS (3);
1.1.1.10 root 371: #if 0 /* This assertion is legitimately false in C++. */
1.1.1.7 root 372: /* We shouldn't be outputting a reference to a type before its
373: definition unless the type has a tag name.
374: A typedef name without a tag name should be impossible. */
375: if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
376: abort ();
1.1.1.10 root 377: #endif
1.1 root 378: dbxout_type_name (type);
379: fprintf (asmfile, ":");
380: typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
381: break;
382: }
383: tem = size_in_bytes (type);
384: fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "s%d" : "u%d",
385: TREE_INT_CST_LOW (tem));
1.1.1.6 root 386:
387: if (TYPE_BASETYPES (type) && use_gdb_dbx_extensions)
388: {
389: putc ('!', asmfile);
390: putc ((TREE_PUBLIC (TYPE_BASETYPES (type)) ? '2' : '0'),
391: asmfile);
392: dbxout_type (TREE_VALUE (TYPE_BASETYPES (type)), 0);
393: putc (',', asmfile);
394: CHARS (3);
395: }
1.1 root 396: CHARS (11);
1.1.1.6 root 397:
1.1 root 398: for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
399: /* Output the name, type, position (in bits), size (in bits)
400: of each field. */
401: /* Omit here the nameless fields that are used to skip bits. */
402: if (DECL_NAME (tem) != 0)
403: {
1.1.1.2 root 404: /* Continue the line if necessary,
405: but not before the first field. */
406: if (tem != TYPE_FIELDS (type))
407: CONTIN;
1.1 root 408: fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
1.1.1.6 root 409: CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
410: if (use_gdb_dbx_extensions)
411: {
412: putc ('/', asmfile);
413: #ifdef TREE_PRIVATE
414: putc ((TREE_PRIVATE (tem) ? '0'
415: : TREE_PROTECTED (tem) ? '1' : '2'),
416: asmfile);
417: #endif
418: CHARS (2);
419: if (TREE_CODE (tem) == FUNCTION_DECL)
420: {
421: putc (':', asmfile);
422: CHARS (1);
423: dbxout_type (TREE_TYPE (tem), 0); /* FUNCTION_TYPE */
424: dbxout_args (TYPE_ARG_TYPES (TREE_TYPE (tem)));
425: #ifdef TREE_VIRTUAL
426: fprintf (asmfile, ":%s;%c",
427: XSTR (XEXP (DECL_RTL (tem), 0), 0),
428: TREE_VIRTUAL (tem) ? '*' : '.');
429: #endif
430: CHARS (3 + strlen (XSTR (XEXP (DECL_RTL (tem), 0), 0)));
431: }
432: else
433: dbxout_type (TREE_TYPE (tem), 0);
434: }
435: else
436: dbxout_type (TREE_TYPE (tem), 0);
437:
438: if (TREE_CODE (tem) == VAR_DECL)
439: {
440: if (use_gdb_dbx_extensions)
441: {
442: fprintf (asmfile, ":%s",
443: XSTR (XEXP (DECL_RTL (tem), 0), 0));
444: CHARS (2 + strlen (XSTR (XEXP (DECL_RTL (tem), 0), 0)));
445: }
446: else
447: {
448: fprintf (asmfile, ",0,0;");
449: CHARS (5);
450: }
451: }
452: else
453: {
454: fprintf (asmfile, ",%d,%d;", DECL_OFFSET (tem),
455: (TREE_INT_CST_LOW (DECL_SIZE (tem))
456: * DECL_SIZE_UNIT (tem)));
457: CHARS (23);
458: }
1.1 root 459: }
1.1.1.6 root 460:
1.1 root 461: putc (';', asmfile);
462: CHARS (1);
463: break;
464:
465: case ENUMERAL_TYPE:
466: if ((TYPE_NAME (type) != 0 && !full)
467: || TYPE_SIZE (type) == 0)
468: {
469: fprintf (asmfile, "xe");
470: CHARS (3);
471: dbxout_type_name (type);
472: typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
473: fprintf (asmfile, ":");
474: return;
475: }
476: putc ('e', asmfile);
477: CHARS (1);
478: for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
479: {
480: fprintf (asmfile, "%s:%d,", IDENTIFIER_POINTER (TREE_PURPOSE (tem)),
481: TREE_INT_CST_LOW (TREE_VALUE (tem)));
1.1.1.6 root 482: CHARS (11 + IDENTIFIER_LENGTH (TREE_PURPOSE (tem)));
1.1 root 483: if (TREE_CHAIN (tem) != 0)
484: CONTIN;
485: }
486: putc (';', asmfile);
487: CHARS (1);
488: break;
489:
490: case POINTER_TYPE:
491: putc ('*', asmfile);
492: CHARS (1);
493: dbxout_type (TREE_TYPE (type), 0);
494: break;
495:
1.1.1.6 root 496: case METHOD_TYPE:
497: if (use_gdb_dbx_extensions)
498: {
499: putc ('@', asmfile);
500: CHARS (1);
1.1.1.10 root 501: dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
502: putc (',', asmfile);
503: CHARS (1);
504: dbxout_type (TREE_TYPE (type), 0);
505: }
506: else
507: {
508: /* Treat it as a function type. */
509: dbxout_type (TREE_TYPE (type), 0);
510: }
511: break;
512:
513: case OFFSET_TYPE:
514: if (use_gdb_dbx_extensions)
515: {
516: putc ('@', asmfile);
517: CHARS (1);
518: dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1.1.1.6 root 519: putc (',', asmfile);
520: CHARS (1);
521: dbxout_type (TREE_TYPE (type), 0);
522: }
523: else
524: {
525: /* Treat it as a function type. */
526: dbxout_type (TREE_TYPE (type), 0);
527: }
528: break;
529:
530: case REFERENCE_TYPE:
531: putc (use_gdb_dbx_extensions ? '&' : '*', asmfile);
532: CHARS (1);
533: dbxout_type (TREE_TYPE (type), 0);
534: break;
535:
1.1 root 536: case FUNCTION_TYPE:
537: putc ('f', asmfile);
538: CHARS (1);
539: dbxout_type (TREE_TYPE (type), 0);
540: break;
1.1.1.6 root 541:
542: default:
543: abort ();
1.1 root 544: }
545: }
546:
547: /* Output the name of type TYPE, with no punctuation.
548: Such names can be set up either by typedef declarations
549: or by struct, enum and union tags. */
550:
551: static void
552: dbxout_type_name (type)
553: register tree type;
554: {
1.1.1.6 root 555: tree t;
1.1 root 556: if (TYPE_NAME (type) == 0)
557: abort ();
558: if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1.1.1.6 root 559: {
560: t = TYPE_NAME (type);
561: }
1.1 root 562: else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1.1.1.6 root 563: {
564: t = DECL_NAME (TYPE_NAME (type));
565: }
1.1 root 566: else
567: abort ();
568:
1.1.1.6 root 569: fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
570: CHARS (IDENTIFIER_LENGTH (t));
1.1 root 571: }
572:
573: /* Output a .stabs for the symbol defined by DECL,
574: which must be a ..._DECL node in the normal namespace.
575: It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
576: LOCAL is nonzero if the scope is less than the entire file. */
577:
578: void
579: dbxout_symbol (decl, local)
580: tree decl;
581: int local;
582: {
1.1.1.2 root 583: int letter = 0;
584: tree type = TREE_TYPE (decl);
1.1 root 585:
586: /* If global, first output all types and all
587: struct, enum and union tags that have been created
588: and not yet output. */
589:
590: if (local == 0)
591: {
592: dbxout_tags (gettags ());
593: dbxout_types (get_permanent_types ());
594: }
595:
596: current_sym_code = 0;
597: current_sym_value = 0;
598: current_sym_addr = 0;
599:
600: /* The output will always start with the symbol name,
601: so count that always in the length-output-so-far. */
602:
1.1.1.6 root 603: current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1.1 root 604:
605: switch (TREE_CODE (decl))
606: {
607: case CONST_DECL:
608: /* Enum values are defined by defining the enum type. */
609: break;
610:
611: case FUNCTION_DECL:
1.1.1.3 root 612: if (DECL_RTL (decl) == 0)
613: return;
1.1 root 614: if (TREE_EXTERNAL (decl))
615: break;
616: if (GET_CODE (DECL_RTL (decl)) != MEM
617: || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
618: break;
1.1.1.9 root 619: FORCE_TEXT;
1.1 root 620: fprintf (asmfile, ".stabs \"%s:%c",
621: IDENTIFIER_POINTER (DECL_NAME (decl)),
622: TREE_PUBLIC (decl) ? 'F' : 'f');
623:
624: current_sym_code = N_FUN;
625: current_sym_addr = XEXP (DECL_RTL (decl), 0);
626:
627: if (TREE_TYPE (TREE_TYPE (decl)))
628: dbxout_type (TREE_TYPE (TREE_TYPE (decl)), 0);
629: else
630: dbxout_type (void_type_node, 0);
631: dbxout_finish_symbol ();
632: break;
633:
634: case TYPE_DECL:
1.1.1.7 root 635: #if 0
636: /* This seems all wrong. Outputting most kinds of types gives no name
637: at all. A true definition gives no name; a cross-ref for a
638: structure can give the tag name, but not a type name.
639: It seems that no typedef name is defined by outputting a type. */
640:
1.1.1.3 root 641: /* If this typedef name was defined by outputting the type,
642: don't duplicate it. */
643: if (typevec[TYPE_SYMTAB_ADDRESS (type)] == TYPE_DEFINED
644: && TYPE_NAME (TREE_TYPE (decl)) == decl)
645: return;
1.1.1.7 root 646: #endif
647: /* Don't output the same typedef twice. */
648: if (TREE_ASM_WRITTEN (decl))
649: return;
1.1.1.3 root 650:
1.1 root 651: /* Output typedef name. */
1.1.1.9 root 652: FORCE_TEXT;
1.1 root 653: fprintf (asmfile, ".stabs \"%s:t",
654: IDENTIFIER_POINTER (DECL_NAME (decl)));
655:
656: current_sym_code = N_LSYM;
657:
1.1.1.3 root 658: dbxout_type (TREE_TYPE (decl), 1);
1.1 root 659: dbxout_finish_symbol ();
1.1.1.7 root 660:
661: /* Prevent duplicate output of a typedef. */
662: TREE_ASM_WRITTEN (decl) = 1;
1.1 root 663: break;
664:
665: case PARM_DECL:
666: /* Parm decls go in their own separate chains
667: and are output by dbxout_reg_parms and dbxout_parms. */
668: abort ();
669:
670: case VAR_DECL:
1.1.1.3 root 671: if (DECL_RTL (decl) == 0)
672: return;
1.1 root 673: /* Don't mention a variable that is external.
674: Let the file that defines it describe it. */
675: if (TREE_EXTERNAL (decl))
676: break;
677:
678: /* Don't mention a variable at all
679: if it was completely optimized into nothingness. */
680: if (GET_CODE (DECL_RTL (decl)) == REG
1.1.1.2 root 681: && (REGNO (DECL_RTL (decl)) < 0
682: || REGNO (DECL_RTL (decl)) >= FIRST_PSEUDO_REGISTER))
1.1 root 683: break;
684:
685: /* The kind-of-variable letter depends on where
686: the variable is and on the scope of its name:
687: G and N_GSYM for static storage and global scope,
688: S for static storage and file scope,
1.1.1.4 root 689: V for static storage and local scope,
1.1 root 690: for those two, use N_LCSYM if data is in bss segment,
691: N_STSYM if it is in data segment, or N_FUN if in text segment.
692: no letter at all, and N_LSYM, for auto variable,
693: r and N_RSYM for register variable. */
694:
695: if (GET_CODE (DECL_RTL (decl)) == MEM
696: && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
697: {
698: if (TREE_PUBLIC (decl))
699: {
700: letter = 'G';
701: current_sym_code = N_GSYM;
702: }
703: else
704: {
705: current_sym_addr = XEXP (DECL_RTL (decl), 0);
706:
1.1.1.4 root 707: letter = TREE_PERMANENT (decl) ? 'S' : 'V';
1.1 root 708:
709: if (!DECL_INITIAL (decl))
710: current_sym_code = N_LCSYM;
711: else if (TREE_READONLY (decl) && ! TREE_VOLATILE (decl))
712: /* This is not quite right, but it's the closest
713: of all the codes that Unix defines. */
714: current_sym_code = N_FUN;
715: else
716: current_sym_code = N_STSYM;
717: }
718: }
1.1.1.2 root 719: else if (GET_CODE (DECL_RTL (decl)) == REG)
720: {
721: letter = 'r';
722: current_sym_code = N_RSYM;
723: current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl)));
724: }
725: else if (GET_CODE (DECL_RTL (decl)) == MEM
726: && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
727: || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
728: && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
1.1.1.6 root 729: /* If the value is indirect by memory or by a register
730: that isn't the frame pointer
1.1.1.2 root 731: then it means the object is variable-sized and address through
732: that register or stack slot. DBX has no way to represent this
1.1.1.5 root 733: so all we can do is output the variable as a pointer.
734: If it's not a parameter, ignore it.
735: (VAR_DECLs like this can be made by integrate.c.) */
1.1 root 736: {
1.1.1.2 root 737: if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1.1 root 738: {
739: letter = 'r';
740: current_sym_code = N_RSYM;
1.1.1.2 root 741: current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (DECL_RTL (decl), 0)));
1.1 root 742: }
743: else
744: {
745: current_sym_code = N_LSYM;
1.1.1.2 root 746: /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
1.1 root 747: We want the value of that CONST_INT. */
1.1.1.2 root 748: current_sym_value = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (decl), 0), 0), 1));
1.1 root 749: }
1.1.1.2 root 750:
751: type = build_pointer_type (TREE_TYPE (decl));
1.1 root 752: }
1.1.1.2 root 753: else if (GET_CODE (DECL_RTL (decl)) == MEM
1.1.1.8 root 754: && GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1.1.1.2 root 755: {
756: current_sym_code = N_LSYM;
1.1.1.8 root 757: current_sym_value = 0;
758: }
759: else if (GET_CODE (DECL_RTL (decl)) == MEM
760: && GET_CODE (XEXP (DECL_RTL (decl), 0)) == PLUS
761: && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 1)) == CONST_INT)
762: {
763: current_sym_code = N_LSYM;
764: /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
765: We want the value of that CONST_INT. */
766: current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1));
1.1.1.2 root 767: }
1.1.1.8 root 768: else
769: /* Address might be a MEM, when DECL is a variable-sized object.
770: Or it might be const0_rtx, meaning previous passes
771: want us to ignore this variable. */
772: break;
773:
774: /* Ok, start a symtab entry and output the variable name. */
1.1.1.9 root 775: FORCE_TEXT;
1.1.1.8 root 776: fprintf (asmfile, ".stabs \"%s:",
777: IDENTIFIER_POINTER (DECL_NAME (decl)));
1.1.1.2 root 778: if (letter) putc (letter, asmfile);
779: dbxout_type (type, 0);
780: dbxout_finish_symbol ();
1.1 root 781: break;
782: }
783: }
784:
785: static void
786: dbxout_finish_symbol ()
787: {
788: fprintf (asmfile, "\",%d,0,0,", current_sym_code);
789: if (current_sym_addr)
790: output_addr_const (asmfile, current_sym_addr);
791: else
792: fprintf (asmfile, "%d", current_sym_value);
793: putc ('\n', asmfile);
794: }
795:
796: /* Output definitions of all the decls in a chain. */
797:
798: static void
799: dbxout_syms (syms)
800: tree syms;
801: {
802: while (syms)
803: {
804: dbxout_symbol (syms, 1);
805: syms = TREE_CHAIN (syms);
806: }
807: }
808:
809: /* The following two functions output definitions of function parameters.
810: Each parameter gets a definition locating it in the parameter list.
811: Each parameter that is a register variable gets a second definition
812: locating it in the register.
813:
814: Printing or argument lists in gdb uses the definitions that
815: locate in the parameter list. But reference to the variable in
816: expressions uses preferentially the definition as a register. */
817:
818: /* Output definitions, referring to storage in the parmlist,
819: of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
820:
821: static void
822: dbxout_parms (parms)
823: tree parms;
824: {
825: for (; parms; parms = TREE_CHAIN (parms))
826: {
1.1.1.2 root 827: if (DECL_OFFSET (parms) >= 0)
828: {
829: current_sym_code = N_PSYM;
830: current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
831: current_sym_addr = 0;
832: current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
833:
1.1.1.9 root 834: FORCE_TEXT;
1.1.1.2 root 835: fprintf (asmfile, ".stabs \"%s:p",
836: IDENTIFIER_POINTER (DECL_NAME (parms)));
837:
838: if (GET_CODE (DECL_RTL (parms)) == REG
839: && REGNO (DECL_RTL (parms)) >= 0
840: && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
841: dbxout_type (DECL_ARG_TYPE (parms), 0);
842: else
843: {
844: /* This is the case where the parm is passed as an int or double
845: and it is converted to a char, short or float and stored back
846: in the parmlist. In this case, describe the parm
847: with the variable's declared type, and adjust the address
848: if the least significant bytes (which we are using) are not
849: the first ones. */
1.1 root 850: #ifdef BYTES_BIG_ENDIAN
1.1.1.2 root 851: if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
852: current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
853: - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1.1 root 854: #endif
855:
1.1.1.2 root 856: if (GET_CODE (DECL_RTL (parms)) == MEM
857: && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
858: && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
859: && INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == current_sym_value)
860: dbxout_type (TREE_TYPE (parms), 0);
861: else
862: {
863: current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
864: dbxout_type (DECL_ARG_TYPE (parms), 0);
865: }
866: }
867: dbxout_finish_symbol ();
868: }
869: /* Parm was passed in registers.
1.1.1.4 root 870: If it lives in a hard register, output a "regparm" symbol
1.1.1.2 root 871: for the register it lives in. */
1.1.1.4 root 872: else if (GET_CODE (DECL_RTL (parms)) == REG
873: && REGNO (DECL_RTL (parms)) >= 0
874: && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1.1.1.2 root 875: {
876: current_sym_code = N_RSYM;
877: current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
878: current_sym_addr = 0;
879: current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
880:
1.1.1.9 root 881: FORCE_TEXT;
1.1.1.2 root 882: fprintf (asmfile, ".stabs \"%s:P",
883: IDENTIFIER_POINTER (DECL_NAME (parms)));
884:
885: dbxout_type (DECL_ARG_TYPE (parms), 0);
886: dbxout_finish_symbol ();
887: }
888: else if (GET_CODE (DECL_RTL (parms)) == MEM
889: && XEXP (DECL_RTL (parms), 0) != const0_rtx)
890: {
891: current_sym_code = N_LSYM;
892: /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
893: We want the value of that CONST_INT. */
894: current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
895: current_sym_addr = 0;
896: current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
897:
1.1.1.9 root 898: FORCE_TEXT;
1.1.1.2 root 899: fprintf (asmfile, ".stabs \"%s:p",
900: IDENTIFIER_POINTER (DECL_NAME (parms)));
901:
902: /* This is the case where the parm is passed as an int or double
903: and it is converted to a char, short or float and stored back
904: in the parmlist. In this case, describe the parm
905: with the variable's declared type, and adjust the address
906: if the least significant bytes (which we are using) are not
907: the first ones. */
908: #ifdef BYTES_BIG_ENDIAN
909: if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
910: current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
911: - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
912: #endif
913:
914: dbxout_type (TREE_TYPE (parms), 0);
915: dbxout_finish_symbol ();
916: }
1.1 root 917: }
918: }
919:
920: /* Output definitions, referring to registers,
921: of all the parms in PARMS which are stored in registers during the function.
922: PARMS is a chain of PARM_DECL nodes. */
923:
924: static void
925: dbxout_reg_parms (parms)
926: tree parms;
927: {
928: while (parms)
929: {
1.1.1.2 root 930: /* Report parms that live in registers during the function. */
1.1 root 931: if (GET_CODE (DECL_RTL (parms)) == REG
1.1.1.2 root 932: && REGNO (DECL_RTL (parms)) >= 0
933: && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
934: && DECL_OFFSET (parms) >= 0)
1.1 root 935: {
936: current_sym_code = N_RSYM;
937: current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
938: current_sym_addr = 0;
1.1.1.6 root 939: current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1.1.1.9 root 940: FORCE_TEXT;
1.1 root 941: fprintf (asmfile, ".stabs \"%s:r",
942: IDENTIFIER_POINTER (DECL_NAME (parms)));
943: dbxout_type (TREE_TYPE (parms), 0);
944: dbxout_finish_symbol ();
945: }
1.1.1.2 root 946: /* Report parms that live in memory but outside the parmlist. */
947: else if (GET_CODE (DECL_RTL (parms)) == MEM
948: && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
949: && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT)
950: {
951: int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
952: /* A parm declared char is really passed as an int,
953: so it occupies the least significant bytes.
954: On a big-endian machine those are not the low-numbered ones. */
955: #ifdef BYTES_BIG_ENDIAN
956: if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
957: offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
958: - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
959: #endif
960: if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset)
961: {
962: current_sym_code = N_LSYM;
963: current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
964: current_sym_addr = 0;
1.1.1.6 root 965: current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1.1.1.9 root 966: FORCE_TEXT;
1.1.1.2 root 967: fprintf (asmfile, ".stabs \"%s:",
968: IDENTIFIER_POINTER (DECL_NAME (parms)));
969: dbxout_type (TREE_TYPE (parms), 0);
970: dbxout_finish_symbol ();
971: }
972: }
1.1 root 973: parms = TREE_CHAIN (parms);
974: }
975: }
976:
1.1.1.6 root 977: /* Given a chain of ..._TYPE nodes (as come in a parameter list),
978: output definitions of those names, in raw form */
979:
980: void
981: dbxout_args (args)
982: tree args;
983: {
984: while (args)
985: {
986: putc (',', asmfile);
987: dbxout_type (TREE_VALUE (args), 0);
988: CHARS (1);
989: args = TREE_CHAIN (args);
990: }
991: }
992:
1.1.1.7 root 993: /* Given a chain of ..._TYPE nodes,
994: find those which have typedef names and output those names.
995: This is to ensure those types get output. */
1.1 root 996:
997: void
998: dbxout_types (types)
999: register tree types;
1000: {
1001: while (types)
1002: {
1003: if (TYPE_NAME (types)
1.1.1.7 root 1004: && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL
1005: && ! TREE_ASM_WRITTEN (TYPE_NAME (types)))
1006: dbxout_symbol (TYPE_NAME (types), 1);
1.1 root 1007: types = TREE_CHAIN (types);
1008: }
1009: }
1010:
1011: /* Output the tags (struct, union and enum definitions with names) for a block,
1012: given a list of them (a chain of TREE_LIST nodes) in TAGS.
1013: We must check to include those that have been mentioned already with
1014: only a cross-reference. */
1015:
1016: void
1017: dbxout_tags (tags)
1018: tree tags;
1019: {
1020: register tree link;
1021: for (link = tags; link; link = TREE_CHAIN (link))
1022: {
1.1.1.2 root 1023: register tree type = TYPE_MAIN_VARIANT (TREE_VALUE (link));
1.1 root 1024: if (TREE_PURPOSE (link) != 0
1.1.1.2 root 1025: && ! TREE_ASM_WRITTEN (link)
1.1 root 1026: && TYPE_SIZE (type) != 0)
1027: {
1.1.1.2 root 1028: TREE_ASM_WRITTEN (link) = 1;
1.1 root 1029: current_sym_code = N_LSYM;
1030: current_sym_value = 0;
1031: current_sym_addr = 0;
1.1.1.6 root 1032: current_sym_nchars = 2 + IDENTIFIER_LENGTH (TREE_PURPOSE (link));
1.1 root 1033:
1.1.1.9 root 1034: FORCE_TEXT;
1.1 root 1035: fprintf (asmfile, ".stabs \"%s:T",
1036: IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1037: dbxout_type (type, 1);
1038: dbxout_finish_symbol ();
1039: }
1040: }
1041: }
1042:
1043: /* Output everything about a symbol block (that is to say, a LET_STMT node
1044: that represents a scope level),
1045: including recursive output of contained blocks.
1046:
1047: STMT is the LET_STMT node.
1048: DEPTH is its depth within containing symbol blocks.
1049: ARGS is usually zero; but for the outermost block of the
1050: body of a function, it is a chain of PARM_DECLs for the function parameters.
1051: We output definitions of all the register parms
1052: as if they were local variables of that block.
1053:
1054: Actually, STMT may be several statements chained together.
1055: We handle them all in sequence. */
1056:
1057: static void
1058: dbxout_block (stmt, depth, args)
1059: register tree stmt;
1060: int depth;
1.1.1.2 root 1061: tree args;
1.1 root 1062: {
1063: int blocknum;
1064:
1065: while (stmt)
1066: {
1067: switch (TREE_CODE (stmt))
1068: {
1069: case COMPOUND_STMT:
1070: case LOOP_STMT:
1071: dbxout_block (STMT_BODY (stmt), depth, 0);
1072: break;
1073:
1074: case IF_STMT:
1075: dbxout_block (STMT_THEN (stmt), depth, 0);
1076: dbxout_block (STMT_ELSE (stmt), depth, 0);
1077: break;
1078:
1079: case LET_STMT:
1080: /* In dbx format, the syms of a block come before the N_LBRAC. */
1081: dbxout_tags (STMT_TYPE_TAGS (stmt));
1.1.1.2 root 1082: dbxout_syms (STMT_VARS (stmt));
1.1 root 1083: if (args)
1084: dbxout_reg_parms (args);
1085:
1086: /* Now output an N_LBRAC symbol to represent the beginning of
1087: the block. Use the block's tree-walk order to generate
1088: the assembler symbols LBBn and LBEn
1089: that final will define around the code in this block. */
1090: if (depth > 0)
1091: {
1092: blocknum = next_block_number++;
1093: fprintf (asmfile, ".stabn %d,0,0,LBB%d\n", N_LBRAC, blocknum);
1094: }
1095:
1096: /* Output the interior of the block. */
1097: dbxout_block (STMT_BODY (stmt), depth + 1, 0);
1098:
1099: /* Refer to the marker for the end of the block. */
1100: if (depth > 0)
1101: fprintf (asmfile, ".stabn %d,0,0,LBE%d\n", N_RBRAC, blocknum);
1102: }
1103: stmt = TREE_CHAIN (stmt);
1104: }
1105: }
1106:
1107: /* Output dbx data for a function definition.
1108: This includes a definition of the function name itself (a symbol),
1109: definitions of the parameters (locating them in the parameter list)
1110: and then output the block that makes up the function's body
1111: (including all the auto variables of the function). */
1112:
1113: void
1114: dbxout_function (decl)
1115: tree decl;
1116: {
1117: dbxout_symbol (decl, 0);
1118: dbxout_parms (DECL_ARGUMENTS (decl));
1119: dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1120: }
1.1.1.2 root 1121:
1.1.1.4 root 1122: #else /* not DBX_DEBUGGING_INFO */
1.1.1.2 root 1123:
1124: void
1125: dbxout_init (asm_file, input_file_name)
1126: FILE *asm_file;
1127: char *input_file_name;
1128: {}
1129:
1130: void
1131: dbxout_symbol (decl, local)
1132: tree decl;
1133: int local;
1134: {}
1135:
1136: void
1137: dbxout_types (types)
1138: register tree types;
1139: {}
1140:
1141: void
1142: dbxout_tags (tags)
1143: tree tags;
1144: {}
1145:
1146: void
1147: dbxout_function (decl)
1148: tree decl;
1149: {}
1150:
1.1.1.4 root 1151: #endif /* DBX_DEBUGGING_INFO */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.