|
|
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)));
1.1.1.14! root 410: #ifdef TREE_PRIVATE
! 411: if (use_gdb_dbx_extensions
! 412: && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
! 413: || TREE_CODE (tem) != FIELD_DECL))
1.1.1.6 root 414: {
415: putc ('/', asmfile);
416: putc ((TREE_PRIVATE (tem) ? '0'
417: : TREE_PROTECTED (tem) ? '1' : '2'),
418: asmfile);
419: CHARS (2);
420: if (TREE_CODE (tem) == FUNCTION_DECL)
421: {
422: putc (':', asmfile);
423: CHARS (1);
424: dbxout_type (TREE_TYPE (tem), 0); /* FUNCTION_TYPE */
425: dbxout_args (TYPE_ARG_TYPES (TREE_TYPE (tem)));
426: #ifdef TREE_VIRTUAL
427: fprintf (asmfile, ":%s;%c",
428: XSTR (XEXP (DECL_RTL (tem), 0), 0),
429: TREE_VIRTUAL (tem) ? '*' : '.');
430: #endif
431: CHARS (3 + strlen (XSTR (XEXP (DECL_RTL (tem), 0), 0)));
432: }
433: else
434: dbxout_type (TREE_TYPE (tem), 0);
435: }
436: else
1.1.1.14! root 437: #endif
1.1.1.6 root 438: dbxout_type (TREE_TYPE (tem), 0);
439:
440: if (TREE_CODE (tem) == VAR_DECL)
441: {
442: if (use_gdb_dbx_extensions)
443: {
444: fprintf (asmfile, ":%s",
445: XSTR (XEXP (DECL_RTL (tem), 0), 0));
446: CHARS (2 + strlen (XSTR (XEXP (DECL_RTL (tem), 0), 0)));
447: }
448: else
449: {
450: fprintf (asmfile, ",0,0;");
451: CHARS (5);
452: }
453: }
454: else
455: {
456: fprintf (asmfile, ",%d,%d;", DECL_OFFSET (tem),
457: (TREE_INT_CST_LOW (DECL_SIZE (tem))
458: * DECL_SIZE_UNIT (tem)));
459: CHARS (23);
460: }
1.1 root 461: }
1.1.1.6 root 462:
1.1 root 463: putc (';', asmfile);
464: CHARS (1);
465: break;
466:
467: case ENUMERAL_TYPE:
468: if ((TYPE_NAME (type) != 0 && !full)
469: || TYPE_SIZE (type) == 0)
470: {
471: fprintf (asmfile, "xe");
472: CHARS (3);
473: dbxout_type_name (type);
474: typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
475: fprintf (asmfile, ":");
476: return;
477: }
478: putc ('e', asmfile);
479: CHARS (1);
480: for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
481: {
482: fprintf (asmfile, "%s:%d,", IDENTIFIER_POINTER (TREE_PURPOSE (tem)),
483: TREE_INT_CST_LOW (TREE_VALUE (tem)));
1.1.1.6 root 484: CHARS (11 + IDENTIFIER_LENGTH (TREE_PURPOSE (tem)));
1.1 root 485: if (TREE_CHAIN (tem) != 0)
486: CONTIN;
487: }
488: putc (';', asmfile);
489: CHARS (1);
490: break;
491:
492: case POINTER_TYPE:
493: putc ('*', asmfile);
494: CHARS (1);
495: dbxout_type (TREE_TYPE (type), 0);
496: break;
497:
1.1.1.6 root 498: case METHOD_TYPE:
499: if (use_gdb_dbx_extensions)
500: {
501: putc ('@', asmfile);
502: CHARS (1);
1.1.1.10 root 503: dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
504: putc (',', asmfile);
505: CHARS (1);
506: dbxout_type (TREE_TYPE (type), 0);
507: }
508: else
509: {
510: /* Treat it as a function type. */
511: dbxout_type (TREE_TYPE (type), 0);
512: }
513: break;
514:
515: case OFFSET_TYPE:
516: if (use_gdb_dbx_extensions)
517: {
518: putc ('@', asmfile);
519: CHARS (1);
520: dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1.1.1.6 root 521: putc (',', asmfile);
522: CHARS (1);
523: dbxout_type (TREE_TYPE (type), 0);
524: }
525: else
526: {
527: /* Treat it as a function type. */
528: dbxout_type (TREE_TYPE (type), 0);
529: }
530: break;
531:
532: case REFERENCE_TYPE:
533: putc (use_gdb_dbx_extensions ? '&' : '*', asmfile);
534: CHARS (1);
535: dbxout_type (TREE_TYPE (type), 0);
536: break;
537:
1.1 root 538: case FUNCTION_TYPE:
539: putc ('f', asmfile);
540: CHARS (1);
541: dbxout_type (TREE_TYPE (type), 0);
542: break;
1.1.1.6 root 543:
544: default:
545: abort ();
1.1 root 546: }
547: }
548:
549: /* Output the name of type TYPE, with no punctuation.
550: Such names can be set up either by typedef declarations
551: or by struct, enum and union tags. */
552:
553: static void
554: dbxout_type_name (type)
555: register tree type;
556: {
1.1.1.6 root 557: tree t;
1.1 root 558: if (TYPE_NAME (type) == 0)
559: abort ();
560: if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1.1.1.6 root 561: {
562: t = TYPE_NAME (type);
563: }
1.1 root 564: else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1.1.1.6 root 565: {
566: t = DECL_NAME (TYPE_NAME (type));
567: }
1.1 root 568: else
569: abort ();
570:
1.1.1.6 root 571: fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
572: CHARS (IDENTIFIER_LENGTH (t));
1.1 root 573: }
574:
575: /* Output a .stabs for the symbol defined by DECL,
576: which must be a ..._DECL node in the normal namespace.
577: It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
578: LOCAL is nonzero if the scope is less than the entire file. */
579:
580: void
581: dbxout_symbol (decl, local)
582: tree decl;
583: int local;
584: {
1.1.1.2 root 585: int letter = 0;
586: tree type = TREE_TYPE (decl);
1.1 root 587:
588: /* If global, first output all types and all
589: struct, enum and union tags that have been created
590: and not yet output. */
591:
592: if (local == 0)
593: {
594: dbxout_tags (gettags ());
595: dbxout_types (get_permanent_types ());
596: }
597:
598: current_sym_code = 0;
599: current_sym_value = 0;
600: current_sym_addr = 0;
601:
602: /* The output will always start with the symbol name,
603: so count that always in the length-output-so-far. */
604:
1.1.1.6 root 605: current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1.1 root 606:
607: switch (TREE_CODE (decl))
608: {
609: case CONST_DECL:
610: /* Enum values are defined by defining the enum type. */
611: break;
612:
613: case FUNCTION_DECL:
1.1.1.3 root 614: if (DECL_RTL (decl) == 0)
615: return;
1.1 root 616: if (TREE_EXTERNAL (decl))
617: break;
618: if (GET_CODE (DECL_RTL (decl)) != MEM
619: || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
620: break;
1.1.1.9 root 621: FORCE_TEXT;
1.1 root 622: fprintf (asmfile, ".stabs \"%s:%c",
623: IDENTIFIER_POINTER (DECL_NAME (decl)),
624: TREE_PUBLIC (decl) ? 'F' : 'f');
625:
626: current_sym_code = N_FUN;
627: current_sym_addr = XEXP (DECL_RTL (decl), 0);
628:
629: if (TREE_TYPE (TREE_TYPE (decl)))
630: dbxout_type (TREE_TYPE (TREE_TYPE (decl)), 0);
631: else
632: dbxout_type (void_type_node, 0);
633: dbxout_finish_symbol ();
634: break;
635:
636: case TYPE_DECL:
1.1.1.7 root 637: #if 0
638: /* This seems all wrong. Outputting most kinds of types gives no name
639: at all. A true definition gives no name; a cross-ref for a
640: structure can give the tag name, but not a type name.
641: It seems that no typedef name is defined by outputting a type. */
642:
1.1.1.3 root 643: /* If this typedef name was defined by outputting the type,
644: don't duplicate it. */
645: if (typevec[TYPE_SYMTAB_ADDRESS (type)] == TYPE_DEFINED
646: && TYPE_NAME (TREE_TYPE (decl)) == decl)
647: return;
1.1.1.7 root 648: #endif
649: /* Don't output the same typedef twice. */
650: if (TREE_ASM_WRITTEN (decl))
651: return;
1.1.1.3 root 652:
1.1 root 653: /* Output typedef name. */
1.1.1.9 root 654: FORCE_TEXT;
1.1 root 655: fprintf (asmfile, ".stabs \"%s:t",
656: IDENTIFIER_POINTER (DECL_NAME (decl)));
657:
658: current_sym_code = N_LSYM;
659:
1.1.1.3 root 660: dbxout_type (TREE_TYPE (decl), 1);
1.1 root 661: dbxout_finish_symbol ();
1.1.1.7 root 662:
663: /* Prevent duplicate output of a typedef. */
664: TREE_ASM_WRITTEN (decl) = 1;
1.1 root 665: break;
666:
667: case PARM_DECL:
668: /* Parm decls go in their own separate chains
669: and are output by dbxout_reg_parms and dbxout_parms. */
670: abort ();
671:
672: case VAR_DECL:
1.1.1.3 root 673: if (DECL_RTL (decl) == 0)
674: return;
1.1 root 675: /* Don't mention a variable that is external.
676: Let the file that defines it describe it. */
677: if (TREE_EXTERNAL (decl))
678: break;
679:
680: /* Don't mention a variable at all
681: if it was completely optimized into nothingness. */
682: if (GET_CODE (DECL_RTL (decl)) == REG
1.1.1.2 root 683: && (REGNO (DECL_RTL (decl)) < 0
684: || REGNO (DECL_RTL (decl)) >= FIRST_PSEUDO_REGISTER))
1.1 root 685: break;
686:
687: /* The kind-of-variable letter depends on where
688: the variable is and on the scope of its name:
689: G and N_GSYM for static storage and global scope,
690: S for static storage and file scope,
1.1.1.4 root 691: V for static storage and local scope,
1.1 root 692: for those two, use N_LCSYM if data is in bss segment,
1.1.1.14! root 693: N_STSYM if in data segment, N_FUN otherwise.
! 694: (We used N_FUN originally, then changed to N_STSYM
! 695: to please GDB. However, it seems that confused ld.
! 696: Now GDB has been fixed to like N_FUN, says Kingdon.)
1.1 root 697: no letter at all, and N_LSYM, for auto variable,
698: r and N_RSYM for register variable. */
699:
700: if (GET_CODE (DECL_RTL (decl)) == MEM
701: && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
702: {
703: if (TREE_PUBLIC (decl))
704: {
705: letter = 'G';
706: current_sym_code = N_GSYM;
707: }
708: else
709: {
710: current_sym_addr = XEXP (DECL_RTL (decl), 0);
711:
1.1.1.4 root 712: letter = TREE_PERMANENT (decl) ? 'S' : 'V';
1.1 root 713:
714: if (!DECL_INITIAL (decl))
715: current_sym_code = N_LCSYM;
716: else if (TREE_READONLY (decl) && ! TREE_VOLATILE (decl))
717: /* This is not quite right, but it's the closest
718: of all the codes that Unix defines. */
719: current_sym_code = N_FUN;
720: else
1.1.1.14! root 721: {
! 722: /* Ultrix `as' seems to need this. */
! 723: #ifdef DBX_STATIC_STAB_DATA_SECTION
! 724: data_section ();
! 725: #endif
! 726: current_sym_code = N_STSYM;
! 727: }
1.1 root 728: }
729: }
1.1.1.2 root 730: else if (GET_CODE (DECL_RTL (decl)) == REG)
731: {
732: letter = 'r';
733: current_sym_code = N_RSYM;
734: current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl)));
735: }
736: else if (GET_CODE (DECL_RTL (decl)) == MEM
737: && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
738: || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
739: && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
1.1.1.6 root 740: /* If the value is indirect by memory or by a register
741: that isn't the frame pointer
1.1.1.2 root 742: then it means the object is variable-sized and address through
743: that register or stack slot. DBX has no way to represent this
1.1.1.5 root 744: so all we can do is output the variable as a pointer.
745: If it's not a parameter, ignore it.
746: (VAR_DECLs like this can be made by integrate.c.) */
1.1 root 747: {
1.1.1.2 root 748: if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1.1 root 749: {
750: letter = 'r';
751: current_sym_code = N_RSYM;
1.1.1.2 root 752: current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (DECL_RTL (decl), 0)));
1.1 root 753: }
754: else
755: {
756: current_sym_code = N_LSYM;
1.1.1.2 root 757: /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
1.1 root 758: We want the value of that CONST_INT. */
1.1.1.2 root 759: current_sym_value = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (decl), 0), 0), 1));
1.1 root 760: }
1.1.1.2 root 761:
1.1.1.14! root 762: /* Effectively do build_pointer_type, but don't cache this type,
! 763: since it might be temporary whereas the type it points to
! 764: might have been saved for inlining. */
! 765: type = make_node (POINTER_TYPE);
! 766: TREE_TYPE (type) = TREE_TYPE (decl);
1.1 root 767: }
1.1.1.2 root 768: else if (GET_CODE (DECL_RTL (decl)) == MEM
1.1.1.8 root 769: && GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1.1.1.2 root 770: {
771: current_sym_code = N_LSYM;
1.1.1.8 root 772: current_sym_value = 0;
773: }
774: else if (GET_CODE (DECL_RTL (decl)) == MEM
775: && GET_CODE (XEXP (DECL_RTL (decl), 0)) == PLUS
776: && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 1)) == CONST_INT)
777: {
778: current_sym_code = N_LSYM;
779: /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
780: We want the value of that CONST_INT. */
781: current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1));
1.1.1.2 root 782: }
1.1.1.8 root 783: else
784: /* Address might be a MEM, when DECL is a variable-sized object.
785: Or it might be const0_rtx, meaning previous passes
786: want us to ignore this variable. */
787: break;
788:
789: /* Ok, start a symtab entry and output the variable name. */
1.1.1.9 root 790: FORCE_TEXT;
1.1.1.8 root 791: fprintf (asmfile, ".stabs \"%s:",
792: IDENTIFIER_POINTER (DECL_NAME (decl)));
1.1.1.2 root 793: if (letter) putc (letter, asmfile);
794: dbxout_type (type, 0);
795: dbxout_finish_symbol ();
1.1 root 796: break;
797: }
798: }
799:
800: static void
801: dbxout_finish_symbol ()
802: {
803: fprintf (asmfile, "\",%d,0,0,", current_sym_code);
804: if (current_sym_addr)
805: output_addr_const (asmfile, current_sym_addr);
806: else
807: fprintf (asmfile, "%d", current_sym_value);
808: putc ('\n', asmfile);
809: }
810:
811: /* Output definitions of all the decls in a chain. */
812:
813: static void
814: dbxout_syms (syms)
815: tree syms;
816: {
817: while (syms)
818: {
819: dbxout_symbol (syms, 1);
820: syms = TREE_CHAIN (syms);
821: }
822: }
823:
824: /* The following two functions output definitions of function parameters.
825: Each parameter gets a definition locating it in the parameter list.
826: Each parameter that is a register variable gets a second definition
827: locating it in the register.
828:
829: Printing or argument lists in gdb uses the definitions that
830: locate in the parameter list. But reference to the variable in
831: expressions uses preferentially the definition as a register. */
832:
833: /* Output definitions, referring to storage in the parmlist,
834: of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
835:
836: static void
837: dbxout_parms (parms)
838: tree parms;
839: {
840: for (; parms; parms = TREE_CHAIN (parms))
841: {
1.1.1.2 root 842: if (DECL_OFFSET (parms) >= 0)
843: {
844: current_sym_code = N_PSYM;
845: current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
846: current_sym_addr = 0;
847: current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
848:
1.1.1.9 root 849: FORCE_TEXT;
1.1.1.2 root 850: fprintf (asmfile, ".stabs \"%s:p",
851: IDENTIFIER_POINTER (DECL_NAME (parms)));
852:
853: if (GET_CODE (DECL_RTL (parms)) == REG
854: && REGNO (DECL_RTL (parms)) >= 0
855: && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
856: dbxout_type (DECL_ARG_TYPE (parms), 0);
857: else
858: {
859: /* This is the case where the parm is passed as an int or double
860: and it is converted to a char, short or float and stored back
861: in the parmlist. In this case, describe the parm
862: with the variable's declared type, and adjust the address
863: if the least significant bytes (which we are using) are not
864: the first ones. */
1.1 root 865: #ifdef BYTES_BIG_ENDIAN
1.1.1.2 root 866: if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
867: current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
868: - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1.1 root 869: #endif
870:
1.1.1.2 root 871: if (GET_CODE (DECL_RTL (parms)) == MEM
872: && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
873: && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
874: && INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == current_sym_value)
875: dbxout_type (TREE_TYPE (parms), 0);
876: else
877: {
878: current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
879: dbxout_type (DECL_ARG_TYPE (parms), 0);
880: }
881: }
882: dbxout_finish_symbol ();
883: }
884: /* Parm was passed in registers.
1.1.1.4 root 885: If it lives in a hard register, output a "regparm" symbol
1.1.1.2 root 886: for the register it lives in. */
1.1.1.4 root 887: else if (GET_CODE (DECL_RTL (parms)) == REG
888: && REGNO (DECL_RTL (parms)) >= 0
889: && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1.1.1.2 root 890: {
891: current_sym_code = N_RSYM;
892: current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
893: current_sym_addr = 0;
894: current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
895:
1.1.1.9 root 896: FORCE_TEXT;
1.1.1.2 root 897: fprintf (asmfile, ".stabs \"%s:P",
898: IDENTIFIER_POINTER (DECL_NAME (parms)));
899:
900: dbxout_type (DECL_ARG_TYPE (parms), 0);
901: dbxout_finish_symbol ();
902: }
903: else if (GET_CODE (DECL_RTL (parms)) == MEM
904: && XEXP (DECL_RTL (parms), 0) != const0_rtx)
905: {
906: current_sym_code = N_LSYM;
907: /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
908: We want the value of that CONST_INT. */
909: current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
910: current_sym_addr = 0;
911: current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
912:
1.1.1.9 root 913: FORCE_TEXT;
1.1.1.2 root 914: fprintf (asmfile, ".stabs \"%s:p",
915: IDENTIFIER_POINTER (DECL_NAME (parms)));
916:
1.1.1.14! root 917: #if 0 /* This is actually the case in which a parameter
! 918: is passed in registers but lives on the stack in a local slot.
! 919: The address we are using is already correct, so don't change it. */
! 920:
1.1.1.2 root 921: /* This is the case where the parm is passed as an int or double
922: and it is converted to a char, short or float and stored back
923: in the parmlist. In this case, describe the parm
924: with the variable's declared type, and adjust the address
925: if the least significant bytes (which we are using) are not
926: the first ones. */
927: #ifdef BYTES_BIG_ENDIAN
928: if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
929: current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
930: - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
931: #endif
1.1.1.14! root 932: #endif /* 0 */
1.1.1.2 root 933:
934: dbxout_type (TREE_TYPE (parms), 0);
935: dbxout_finish_symbol ();
936: }
1.1 root 937: }
938: }
939:
940: /* Output definitions, referring to registers,
941: of all the parms in PARMS which are stored in registers during the function.
942: PARMS is a chain of PARM_DECL nodes. */
943:
944: static void
945: dbxout_reg_parms (parms)
946: tree parms;
947: {
948: while (parms)
949: {
1.1.1.2 root 950: /* Report parms that live in registers during the function. */
1.1 root 951: if (GET_CODE (DECL_RTL (parms)) == REG
1.1.1.2 root 952: && REGNO (DECL_RTL (parms)) >= 0
953: && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
954: && DECL_OFFSET (parms) >= 0)
1.1 root 955: {
956: current_sym_code = N_RSYM;
957: current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
958: current_sym_addr = 0;
1.1.1.6 root 959: current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1.1.1.9 root 960: FORCE_TEXT;
1.1 root 961: fprintf (asmfile, ".stabs \"%s:r",
962: IDENTIFIER_POINTER (DECL_NAME (parms)));
963: dbxout_type (TREE_TYPE (parms), 0);
964: dbxout_finish_symbol ();
965: }
1.1.1.2 root 966: /* Report parms that live in memory but outside the parmlist. */
967: else if (GET_CODE (DECL_RTL (parms)) == MEM
968: && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
969: && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT)
970: {
971: int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
972: /* A parm declared char is really passed as an int,
973: so it occupies the least significant bytes.
974: On a big-endian machine those are not the low-numbered ones. */
975: #ifdef BYTES_BIG_ENDIAN
976: if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
977: offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
978: - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
979: #endif
980: if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset)
981: {
982: current_sym_code = N_LSYM;
983: current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
984: current_sym_addr = 0;
1.1.1.6 root 985: current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1.1.1.9 root 986: FORCE_TEXT;
1.1.1.2 root 987: fprintf (asmfile, ".stabs \"%s:",
988: IDENTIFIER_POINTER (DECL_NAME (parms)));
989: dbxout_type (TREE_TYPE (parms), 0);
990: dbxout_finish_symbol ();
991: }
992: }
1.1 root 993: parms = TREE_CHAIN (parms);
994: }
995: }
996:
1.1.1.6 root 997: /* Given a chain of ..._TYPE nodes (as come in a parameter list),
998: output definitions of those names, in raw form */
999:
1000: void
1001: dbxout_args (args)
1002: tree args;
1003: {
1004: while (args)
1005: {
1006: putc (',', asmfile);
1007: dbxout_type (TREE_VALUE (args), 0);
1008: CHARS (1);
1009: args = TREE_CHAIN (args);
1010: }
1011: }
1012:
1.1.1.7 root 1013: /* Given a chain of ..._TYPE nodes,
1014: find those which have typedef names and output those names.
1015: This is to ensure those types get output. */
1.1 root 1016:
1017: void
1018: dbxout_types (types)
1019: register tree types;
1020: {
1021: while (types)
1022: {
1023: if (TYPE_NAME (types)
1.1.1.7 root 1024: && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL
1025: && ! TREE_ASM_WRITTEN (TYPE_NAME (types)))
1026: dbxout_symbol (TYPE_NAME (types), 1);
1.1 root 1027: types = TREE_CHAIN (types);
1028: }
1029: }
1030:
1031: /* Output the tags (struct, union and enum definitions with names) for a block,
1032: given a list of them (a chain of TREE_LIST nodes) in TAGS.
1033: We must check to include those that have been mentioned already with
1034: only a cross-reference. */
1035:
1036: void
1037: dbxout_tags (tags)
1038: tree tags;
1039: {
1040: register tree link;
1041: for (link = tags; link; link = TREE_CHAIN (link))
1042: {
1.1.1.2 root 1043: register tree type = TYPE_MAIN_VARIANT (TREE_VALUE (link));
1.1 root 1044: if (TREE_PURPOSE (link) != 0
1.1.1.2 root 1045: && ! TREE_ASM_WRITTEN (link)
1.1 root 1046: && TYPE_SIZE (type) != 0)
1047: {
1.1.1.2 root 1048: TREE_ASM_WRITTEN (link) = 1;
1.1 root 1049: current_sym_code = N_LSYM;
1050: current_sym_value = 0;
1051: current_sym_addr = 0;
1.1.1.6 root 1052: current_sym_nchars = 2 + IDENTIFIER_LENGTH (TREE_PURPOSE (link));
1.1 root 1053:
1.1.1.9 root 1054: FORCE_TEXT;
1.1 root 1055: fprintf (asmfile, ".stabs \"%s:T",
1056: IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1057: dbxout_type (type, 1);
1058: dbxout_finish_symbol ();
1059: }
1060: }
1061: }
1062:
1063: /* Output everything about a symbol block (that is to say, a LET_STMT node
1064: that represents a scope level),
1065: including recursive output of contained blocks.
1066:
1067: STMT is the LET_STMT node.
1068: DEPTH is its depth within containing symbol blocks.
1069: ARGS is usually zero; but for the outermost block of the
1070: body of a function, it is a chain of PARM_DECLs for the function parameters.
1071: We output definitions of all the register parms
1072: as if they were local variables of that block.
1073:
1074: Actually, STMT may be several statements chained together.
1075: We handle them all in sequence. */
1076:
1077: static void
1078: dbxout_block (stmt, depth, args)
1079: register tree stmt;
1080: int depth;
1.1.1.2 root 1081: tree args;
1.1 root 1082: {
1083: int blocknum;
1084:
1085: while (stmt)
1086: {
1087: switch (TREE_CODE (stmt))
1088: {
1089: case COMPOUND_STMT:
1090: case LOOP_STMT:
1091: dbxout_block (STMT_BODY (stmt), depth, 0);
1092: break;
1093:
1094: case IF_STMT:
1095: dbxout_block (STMT_THEN (stmt), depth, 0);
1096: dbxout_block (STMT_ELSE (stmt), depth, 0);
1097: break;
1098:
1099: case LET_STMT:
1.1.1.14! root 1100: /* Ignore LET_STMTs for blocks never really used to make RTL. */
! 1101: if (! TREE_USED (stmt))
! 1102: break;
1.1 root 1103: /* In dbx format, the syms of a block come before the N_LBRAC. */
1104: dbxout_tags (STMT_TYPE_TAGS (stmt));
1.1.1.2 root 1105: dbxout_syms (STMT_VARS (stmt));
1.1 root 1106: if (args)
1107: dbxout_reg_parms (args);
1108:
1109: /* Now output an N_LBRAC symbol to represent the beginning of
1110: the block. Use the block's tree-walk order to generate
1111: the assembler symbols LBBn and LBEn
1112: that final will define around the code in this block. */
1113: if (depth > 0)
1114: {
1.1.1.13 root 1115: char buf[20];
1.1 root 1116: blocknum = next_block_number++;
1.1.1.13 root 1117: ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
1118: fprintf (asmfile, ".stabn %d,0,0,", N_LBRAC);
1119: assemble_name (asmfile, buf);
1120: fprintf (asmfile, "\n");
1.1 root 1121: }
1122:
1.1.1.14! root 1123: /* Output the subblocks. */
! 1124: dbxout_block (STMT_SUBBLOCKS (stmt), depth + 1, 0);
1.1 root 1125:
1126: /* Refer to the marker for the end of the block. */
1127: if (depth > 0)
1.1.1.13 root 1128: {
1129: char buf[20];
1130: ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
1131: fprintf (asmfile, ".stabn %d,0,0,", N_RBRAC);
1132: assemble_name (asmfile, buf);
1133: fprintf (asmfile, "\n");
1134: }
1.1 root 1135: }
1136: stmt = TREE_CHAIN (stmt);
1137: }
1138: }
1139:
1140: /* Output dbx data for a function definition.
1141: This includes a definition of the function name itself (a symbol),
1142: definitions of the parameters (locating them in the parameter list)
1143: and then output the block that makes up the function's body
1144: (including all the auto variables of the function). */
1145:
1146: void
1147: dbxout_function (decl)
1148: tree decl;
1149: {
1150: dbxout_symbol (decl, 0);
1151: dbxout_parms (DECL_ARGUMENTS (decl));
1152: dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1.1.1.13 root 1153:
1154: /* If we made any temporary types in this fn that weren't
1155: output, output them now. */
1156: dbxout_types (get_temporary_types ());
1.1 root 1157: }
1.1.1.2 root 1158:
1.1.1.4 root 1159: #else /* not DBX_DEBUGGING_INFO */
1.1.1.2 root 1160:
1161: void
1162: dbxout_init (asm_file, input_file_name)
1163: FILE *asm_file;
1164: char *input_file_name;
1165: {}
1166:
1167: void
1168: dbxout_symbol (decl, local)
1169: tree decl;
1170: int local;
1171: {}
1172:
1173: void
1174: dbxout_types (types)
1175: register tree types;
1176: {}
1177:
1178: void
1179: dbxout_tags (tags)
1180: tree tags;
1181: {}
1182:
1183: void
1184: dbxout_function (decl)
1185: tree decl;
1186: {}
1187:
1.1.1.4 root 1188: #endif /* DBX_DEBUGGING_INFO */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.