|
|
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,
1.1.1.13! root 691: N_STSYM otherwise. (N_FUN confuses GDB.)
1.1 root 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;
1.1.1.13! root 711: #if 0 /* Note: N_FUN confuses GDB, since GDB expects it to start a new
! 712: nest of N_LBRAC/N_RBRAC, etc. But N_STSYM probably does not
! 713: work either, since it relocates as data segment.
! 714: Probably no standard N_ code works, so we must invent one. */
1.1 root 715: else if (TREE_READONLY (decl) && ! TREE_VOLATILE (decl))
716: /* This is not quite right, but it's the closest
717: of all the codes that Unix defines. */
718: current_sym_code = N_FUN;
1.1.1.13! root 719: #endif
1.1 root 720: else
721: current_sym_code = N_STSYM;
722: }
723: }
1.1.1.2 root 724: else if (GET_CODE (DECL_RTL (decl)) == REG)
725: {
726: letter = 'r';
727: current_sym_code = N_RSYM;
728: current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl)));
729: }
730: else if (GET_CODE (DECL_RTL (decl)) == MEM
731: && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
732: || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
733: && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
1.1.1.6 root 734: /* If the value is indirect by memory or by a register
735: that isn't the frame pointer
1.1.1.2 root 736: then it means the object is variable-sized and address through
737: that register or stack slot. DBX has no way to represent this
1.1.1.5 root 738: so all we can do is output the variable as a pointer.
739: If it's not a parameter, ignore it.
740: (VAR_DECLs like this can be made by integrate.c.) */
1.1 root 741: {
1.1.1.2 root 742: if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1.1 root 743: {
744: letter = 'r';
745: current_sym_code = N_RSYM;
1.1.1.2 root 746: current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (DECL_RTL (decl), 0)));
1.1 root 747: }
748: else
749: {
750: current_sym_code = N_LSYM;
1.1.1.2 root 751: /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
1.1 root 752: We want the value of that CONST_INT. */
1.1.1.2 root 753: current_sym_value = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (decl), 0), 0), 1));
1.1 root 754: }
1.1.1.2 root 755:
756: type = build_pointer_type (TREE_TYPE (decl));
1.1 root 757: }
1.1.1.2 root 758: else if (GET_CODE (DECL_RTL (decl)) == MEM
1.1.1.8 root 759: && GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1.1.1.2 root 760: {
761: current_sym_code = N_LSYM;
1.1.1.8 root 762: current_sym_value = 0;
763: }
764: else if (GET_CODE (DECL_RTL (decl)) == MEM
765: && GET_CODE (XEXP (DECL_RTL (decl), 0)) == PLUS
766: && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 1)) == CONST_INT)
767: {
768: current_sym_code = N_LSYM;
769: /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
770: We want the value of that CONST_INT. */
771: current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1));
1.1.1.2 root 772: }
1.1.1.8 root 773: else
774: /* Address might be a MEM, when DECL is a variable-sized object.
775: Or it might be const0_rtx, meaning previous passes
776: want us to ignore this variable. */
777: break;
778:
779: /* Ok, start a symtab entry and output the variable name. */
1.1.1.9 root 780: FORCE_TEXT;
1.1.1.8 root 781: fprintf (asmfile, ".stabs \"%s:",
782: IDENTIFIER_POINTER (DECL_NAME (decl)));
1.1.1.2 root 783: if (letter) putc (letter, asmfile);
784: dbxout_type (type, 0);
785: dbxout_finish_symbol ();
1.1 root 786: break;
787: }
788: }
789:
790: static void
791: dbxout_finish_symbol ()
792: {
793: fprintf (asmfile, "\",%d,0,0,", current_sym_code);
794: if (current_sym_addr)
795: output_addr_const (asmfile, current_sym_addr);
796: else
797: fprintf (asmfile, "%d", current_sym_value);
798: putc ('\n', asmfile);
799: }
800:
801: /* Output definitions of all the decls in a chain. */
802:
803: static void
804: dbxout_syms (syms)
805: tree syms;
806: {
807: while (syms)
808: {
809: dbxout_symbol (syms, 1);
810: syms = TREE_CHAIN (syms);
811: }
812: }
813:
814: /* The following two functions output definitions of function parameters.
815: Each parameter gets a definition locating it in the parameter list.
816: Each parameter that is a register variable gets a second definition
817: locating it in the register.
818:
819: Printing or argument lists in gdb uses the definitions that
820: locate in the parameter list. But reference to the variable in
821: expressions uses preferentially the definition as a register. */
822:
823: /* Output definitions, referring to storage in the parmlist,
824: of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
825:
826: static void
827: dbxout_parms (parms)
828: tree parms;
829: {
830: for (; parms; parms = TREE_CHAIN (parms))
831: {
1.1.1.2 root 832: if (DECL_OFFSET (parms) >= 0)
833: {
834: current_sym_code = N_PSYM;
835: current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
836: current_sym_addr = 0;
837: current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
838:
1.1.1.9 root 839: FORCE_TEXT;
1.1.1.2 root 840: fprintf (asmfile, ".stabs \"%s:p",
841: IDENTIFIER_POINTER (DECL_NAME (parms)));
842:
843: if (GET_CODE (DECL_RTL (parms)) == REG
844: && REGNO (DECL_RTL (parms)) >= 0
845: && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
846: dbxout_type (DECL_ARG_TYPE (parms), 0);
847: else
848: {
849: /* This is the case where the parm is passed as an int or double
850: and it is converted to a char, short or float and stored back
851: in the parmlist. In this case, describe the parm
852: with the variable's declared type, and adjust the address
853: if the least significant bytes (which we are using) are not
854: the first ones. */
1.1 root 855: #ifdef BYTES_BIG_ENDIAN
1.1.1.2 root 856: if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
857: current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
858: - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1.1 root 859: #endif
860:
1.1.1.2 root 861: if (GET_CODE (DECL_RTL (parms)) == MEM
862: && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
863: && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
864: && INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == current_sym_value)
865: dbxout_type (TREE_TYPE (parms), 0);
866: else
867: {
868: current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
869: dbxout_type (DECL_ARG_TYPE (parms), 0);
870: }
871: }
872: dbxout_finish_symbol ();
873: }
874: /* Parm was passed in registers.
1.1.1.4 root 875: If it lives in a hard register, output a "regparm" symbol
1.1.1.2 root 876: for the register it lives in. */
1.1.1.4 root 877: else if (GET_CODE (DECL_RTL (parms)) == REG
878: && REGNO (DECL_RTL (parms)) >= 0
879: && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1.1.1.2 root 880: {
881: current_sym_code = N_RSYM;
882: current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
883: current_sym_addr = 0;
884: current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
885:
1.1.1.9 root 886: FORCE_TEXT;
1.1.1.2 root 887: fprintf (asmfile, ".stabs \"%s:P",
888: IDENTIFIER_POINTER (DECL_NAME (parms)));
889:
890: dbxout_type (DECL_ARG_TYPE (parms), 0);
891: dbxout_finish_symbol ();
892: }
893: else if (GET_CODE (DECL_RTL (parms)) == MEM
894: && XEXP (DECL_RTL (parms), 0) != const0_rtx)
895: {
896: current_sym_code = N_LSYM;
897: /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
898: We want the value of that CONST_INT. */
899: current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
900: current_sym_addr = 0;
901: current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
902:
1.1.1.9 root 903: FORCE_TEXT;
1.1.1.2 root 904: fprintf (asmfile, ".stabs \"%s:p",
905: IDENTIFIER_POINTER (DECL_NAME (parms)));
906:
907: /* This is the case where the parm is passed as an int or double
908: and it is converted to a char, short or float and stored back
909: in the parmlist. In this case, describe the parm
910: with the variable's declared type, and adjust the address
911: if the least significant bytes (which we are using) are not
912: the first ones. */
913: #ifdef BYTES_BIG_ENDIAN
914: if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
915: current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
916: - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
917: #endif
918:
919: dbxout_type (TREE_TYPE (parms), 0);
920: dbxout_finish_symbol ();
921: }
1.1 root 922: }
923: }
924:
925: /* Output definitions, referring to registers,
926: of all the parms in PARMS which are stored in registers during the function.
927: PARMS is a chain of PARM_DECL nodes. */
928:
929: static void
930: dbxout_reg_parms (parms)
931: tree parms;
932: {
933: while (parms)
934: {
1.1.1.2 root 935: /* Report parms that live in registers during the function. */
1.1 root 936: if (GET_CODE (DECL_RTL (parms)) == REG
1.1.1.2 root 937: && REGNO (DECL_RTL (parms)) >= 0
938: && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
939: && DECL_OFFSET (parms) >= 0)
1.1 root 940: {
941: current_sym_code = N_RSYM;
942: current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
943: current_sym_addr = 0;
1.1.1.6 root 944: current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1.1.1.9 root 945: FORCE_TEXT;
1.1 root 946: fprintf (asmfile, ".stabs \"%s:r",
947: IDENTIFIER_POINTER (DECL_NAME (parms)));
948: dbxout_type (TREE_TYPE (parms), 0);
949: dbxout_finish_symbol ();
950: }
1.1.1.2 root 951: /* Report parms that live in memory but outside the parmlist. */
952: else if (GET_CODE (DECL_RTL (parms)) == MEM
953: && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
954: && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT)
955: {
956: int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
957: /* A parm declared char is really passed as an int,
958: so it occupies the least significant bytes.
959: On a big-endian machine those are not the low-numbered ones. */
960: #ifdef BYTES_BIG_ENDIAN
961: if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
962: offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
963: - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
964: #endif
965: if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset)
966: {
967: current_sym_code = N_LSYM;
968: current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
969: current_sym_addr = 0;
1.1.1.6 root 970: current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1.1.1.9 root 971: FORCE_TEXT;
1.1.1.2 root 972: fprintf (asmfile, ".stabs \"%s:",
973: IDENTIFIER_POINTER (DECL_NAME (parms)));
974: dbxout_type (TREE_TYPE (parms), 0);
975: dbxout_finish_symbol ();
976: }
977: }
1.1 root 978: parms = TREE_CHAIN (parms);
979: }
980: }
981:
1.1.1.6 root 982: /* Given a chain of ..._TYPE nodes (as come in a parameter list),
983: output definitions of those names, in raw form */
984:
985: void
986: dbxout_args (args)
987: tree args;
988: {
989: while (args)
990: {
991: putc (',', asmfile);
992: dbxout_type (TREE_VALUE (args), 0);
993: CHARS (1);
994: args = TREE_CHAIN (args);
995: }
996: }
997:
1.1.1.7 root 998: /* Given a chain of ..._TYPE nodes,
999: find those which have typedef names and output those names.
1000: This is to ensure those types get output. */
1.1 root 1001:
1002: void
1003: dbxout_types (types)
1004: register tree types;
1005: {
1006: while (types)
1007: {
1008: if (TYPE_NAME (types)
1.1.1.7 root 1009: && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL
1010: && ! TREE_ASM_WRITTEN (TYPE_NAME (types)))
1011: dbxout_symbol (TYPE_NAME (types), 1);
1.1 root 1012: types = TREE_CHAIN (types);
1013: }
1014: }
1015:
1016: /* Output the tags (struct, union and enum definitions with names) for a block,
1017: given a list of them (a chain of TREE_LIST nodes) in TAGS.
1018: We must check to include those that have been mentioned already with
1019: only a cross-reference. */
1020:
1021: void
1022: dbxout_tags (tags)
1023: tree tags;
1024: {
1025: register tree link;
1026: for (link = tags; link; link = TREE_CHAIN (link))
1027: {
1.1.1.2 root 1028: register tree type = TYPE_MAIN_VARIANT (TREE_VALUE (link));
1.1 root 1029: if (TREE_PURPOSE (link) != 0
1.1.1.2 root 1030: && ! TREE_ASM_WRITTEN (link)
1.1 root 1031: && TYPE_SIZE (type) != 0)
1032: {
1.1.1.2 root 1033: TREE_ASM_WRITTEN (link) = 1;
1.1 root 1034: current_sym_code = N_LSYM;
1035: current_sym_value = 0;
1036: current_sym_addr = 0;
1.1.1.6 root 1037: current_sym_nchars = 2 + IDENTIFIER_LENGTH (TREE_PURPOSE (link));
1.1 root 1038:
1.1.1.9 root 1039: FORCE_TEXT;
1.1 root 1040: fprintf (asmfile, ".stabs \"%s:T",
1041: IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1042: dbxout_type (type, 1);
1043: dbxout_finish_symbol ();
1044: }
1045: }
1046: }
1047:
1048: /* Output everything about a symbol block (that is to say, a LET_STMT node
1049: that represents a scope level),
1050: including recursive output of contained blocks.
1051:
1052: STMT is the LET_STMT node.
1053: DEPTH is its depth within containing symbol blocks.
1054: ARGS is usually zero; but for the outermost block of the
1055: body of a function, it is a chain of PARM_DECLs for the function parameters.
1056: We output definitions of all the register parms
1057: as if they were local variables of that block.
1058:
1059: Actually, STMT may be several statements chained together.
1060: We handle them all in sequence. */
1061:
1062: static void
1063: dbxout_block (stmt, depth, args)
1064: register tree stmt;
1065: int depth;
1.1.1.2 root 1066: tree args;
1.1 root 1067: {
1068: int blocknum;
1069:
1070: while (stmt)
1071: {
1072: switch (TREE_CODE (stmt))
1073: {
1074: case COMPOUND_STMT:
1075: case LOOP_STMT:
1076: dbxout_block (STMT_BODY (stmt), depth, 0);
1077: break;
1078:
1079: case IF_STMT:
1080: dbxout_block (STMT_THEN (stmt), depth, 0);
1081: dbxout_block (STMT_ELSE (stmt), depth, 0);
1082: break;
1083:
1084: case LET_STMT:
1085: /* In dbx format, the syms of a block come before the N_LBRAC. */
1086: dbxout_tags (STMT_TYPE_TAGS (stmt));
1.1.1.2 root 1087: dbxout_syms (STMT_VARS (stmt));
1.1 root 1088: if (args)
1089: dbxout_reg_parms (args);
1090:
1091: /* Now output an N_LBRAC symbol to represent the beginning of
1092: the block. Use the block's tree-walk order to generate
1093: the assembler symbols LBBn and LBEn
1094: that final will define around the code in this block. */
1095: if (depth > 0)
1096: {
1.1.1.13! root 1097: char buf[20];
1.1 root 1098: blocknum = next_block_number++;
1.1.1.13! root 1099: ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
! 1100: fprintf (asmfile, ".stabn %d,0,0,", N_LBRAC);
! 1101: assemble_name (asmfile, buf);
! 1102: fprintf (asmfile, "\n");
1.1 root 1103: }
1104:
1105: /* Output the interior of the block. */
1106: dbxout_block (STMT_BODY (stmt), depth + 1, 0);
1107:
1108: /* Refer to the marker for the end of the block. */
1109: if (depth > 0)
1.1.1.13! root 1110: {
! 1111: char buf[20];
! 1112: ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
! 1113: fprintf (asmfile, ".stabn %d,0,0,", N_RBRAC);
! 1114: assemble_name (asmfile, buf);
! 1115: fprintf (asmfile, "\n");
! 1116: }
1.1 root 1117: }
1118: stmt = TREE_CHAIN (stmt);
1119: }
1120: }
1121:
1122: /* Output dbx data for a function definition.
1123: This includes a definition of the function name itself (a symbol),
1124: definitions of the parameters (locating them in the parameter list)
1125: and then output the block that makes up the function's body
1126: (including all the auto variables of the function). */
1127:
1128: void
1129: dbxout_function (decl)
1130: tree decl;
1131: {
1132: dbxout_symbol (decl, 0);
1133: dbxout_parms (DECL_ARGUMENTS (decl));
1134: dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1.1.1.13! root 1135:
! 1136: /* If we made any temporary types in this fn that weren't
! 1137: output, output them now. */
! 1138: dbxout_types (get_temporary_types ());
1.1 root 1139: }
1.1.1.2 root 1140:
1.1.1.4 root 1141: #else /* not DBX_DEBUGGING_INFO */
1.1.1.2 root 1142:
1143: void
1144: dbxout_init (asm_file, input_file_name)
1145: FILE *asm_file;
1146: char *input_file_name;
1147: {}
1148:
1149: void
1150: dbxout_symbol (decl, local)
1151: tree decl;
1152: int local;
1153: {}
1154:
1155: void
1156: dbxout_types (types)
1157: register tree types;
1158: {}
1159:
1160: void
1161: dbxout_tags (tags)
1162: tree tags;
1163: {}
1164:
1165: void
1166: dbxout_function (decl)
1167: tree decl;
1168: {}
1169:
1.1.1.4 root 1170: #endif /* DBX_DEBUGGING_INFO */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.