sdbout.c (sdbout_field_types): Don't emit the types of fields we won't be emitting.
[gcc.git] / gcc / sdbout.c
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 92-97, 1998 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
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 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* mike@tredysvr.Tredydev.Unisys.COM says:
22 I modified the struct.c example and have a nm of a .o resulting from the
23 AT&T C compiler. From the example below I would conclude the following:
24
25 1. All .defs from structures are emitted as scanned. The example below
26 clearly shows the symbol table entries for BoxRec2 are after the first
27 function.
28
29 2. All functions and their locals (including statics) are emitted as scanned.
30
31 3. All nested unnamed union and structure .defs must be emitted before
32 the structure in which they are nested. The AT&T assembler is a
33 one pass beast as far as symbolics are concerned.
34
35 4. All structure .defs are emitted before the typedefs that refer to them.
36
37 5. All top level static and external variable definitions are moved to the
38 end of file with all top level statics occurring first before externs.
39
40 6. All undefined references are at the end of the file.
41 */
42
43 #include "config.h"
44
45 #ifdef SDB_DEBUGGING_INFO
46
47 #include "system.h"
48 #include "tree.h"
49 #include "rtl.h"
50 #include "regs.h"
51 #include "defaults.h"
52 #include "flags.h"
53 #include "insn-config.h"
54 #include "reload.h"
55 #include "output.h"
56 #include "toplev.h"
57
58 /* Mips systems use the SDB functions to dump out symbols, but do not
59 supply usable syms.h include files. Which syms.h file to use is a
60 target parameter so don't use the native one if we're cross compiling. */
61
62 #if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(_WIN32) && !defined(__linux__) && !defined(CROSS_COMPILE)
63 #include <syms.h>
64 /* Use T_INT if we don't have T_VOID. */
65 #ifndef T_VOID
66 #define T_VOID T_INT
67 #endif
68 #else
69 #include "gsyms.h"
70 #endif
71
72 /* #include <storclass.h> used to be this instead of syms.h. */
73
74 /* 1 if PARM is passed to this function in memory. */
75
76 #define PARM_PASSED_IN_MEMORY(PARM) \
77 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
78
79 /* A C expression for the integer offset value of an automatic variable
80 (C_AUTO) having address X (an RTX). */
81 #ifndef DEBUGGER_AUTO_OFFSET
82 #define DEBUGGER_AUTO_OFFSET(X) \
83 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
84 #endif
85
86 /* A C expression for the integer offset value of an argument (C_ARG)
87 having address X (an RTX). The nominal offset is OFFSET. */
88 #ifndef DEBUGGER_ARG_OFFSET
89 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
90 #endif
91
92 /* Line number of beginning of current function, minus one.
93 Negative means not in a function or not using sdb. */
94
95 int sdb_begin_function_line = -1;
96
97 /* Counter to generate unique "names" for nameless struct members. */
98
99 static int unnamed_struct_number = 0;
100
101 extern FILE *asm_out_file;
102
103 extern tree current_function_decl;
104
105 #include "sdbout.h"
106
107 static char *gen_fake_label PROTO((void));
108 static int plain_type PROTO((tree));
109 static int template_name_p PROTO((tree));
110 static void sdbout_record_type_name PROTO((tree));
111 static int plain_type_1 PROTO((tree, int));
112 static void sdbout_block PROTO((tree));
113 static void sdbout_syms PROTO((tree));
114 static void sdbout_queue_anonymous_type PROTO((tree));
115 static void sdbout_dequeue_anonymous_types PROTO((void));
116 static void sdbout_type PROTO((tree));
117 static void sdbout_field_types PROTO((tree));
118 static void sdbout_one_type PROTO((tree));
119 static void sdbout_parms PROTO((tree));
120 static void sdbout_reg_parms PROTO((tree));
121 \f
122 /* Define the default sizes for various types. */
123
124 #ifndef CHAR_TYPE_SIZE
125 #define CHAR_TYPE_SIZE BITS_PER_UNIT
126 #endif
127
128 #ifndef SHORT_TYPE_SIZE
129 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
130 #endif
131
132 #ifndef INT_TYPE_SIZE
133 #define INT_TYPE_SIZE BITS_PER_WORD
134 #endif
135
136 #ifndef LONG_TYPE_SIZE
137 #define LONG_TYPE_SIZE BITS_PER_WORD
138 #endif
139
140 #ifndef LONG_LONG_TYPE_SIZE
141 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
142 #endif
143
144 #ifndef FLOAT_TYPE_SIZE
145 #define FLOAT_TYPE_SIZE BITS_PER_WORD
146 #endif
147
148 #ifndef DOUBLE_TYPE_SIZE
149 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
150 #endif
151
152 #ifndef LONG_DOUBLE_TYPE_SIZE
153 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
154 #endif
155 \f
156 /* Random macros describing parts of SDB data. */
157
158 /* Put something here if lines get too long */
159 #define CONTIN
160
161 /* Default value of delimiter is ";". */
162 #ifndef SDB_DELIM
163 #define SDB_DELIM ";"
164 #endif
165
166 /* Maximum number of dimensions the assembler will allow. */
167 #ifndef SDB_MAX_DIM
168 #define SDB_MAX_DIM 4
169 #endif
170
171 #ifndef PUT_SDB_SCL
172 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
173 #endif
174
175 #ifndef PUT_SDB_INT_VAL
176 #define PUT_SDB_INT_VAL(a) \
177 do { \
178 fputs ("\t.val\t", asm_out_file); \
179 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
180 fprintf (asm_out_file, "%s", SDB_DELIM); \
181 } while (0)
182
183 #endif
184
185 #ifndef PUT_SDB_VAL
186 #define PUT_SDB_VAL(a) \
187 ( fputs ("\t.val\t", asm_out_file), \
188 output_addr_const (asm_out_file, (a)), \
189 fprintf (asm_out_file, SDB_DELIM))
190 #endif
191
192 #ifndef PUT_SDB_DEF
193 #define PUT_SDB_DEF(a) \
194 do { fprintf (asm_out_file, "\t.def\t"); \
195 ASM_OUTPUT_LABELREF (asm_out_file, a); \
196 fprintf (asm_out_file, SDB_DELIM); } while (0)
197 #endif
198
199 #ifndef PUT_SDB_PLAIN_DEF
200 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
201 #endif
202
203 #ifndef PUT_SDB_ENDEF
204 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
205 #endif
206
207 #ifndef PUT_SDB_TYPE
208 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
209 #endif
210
211 #ifndef PUT_SDB_SIZE
212 #define PUT_SDB_SIZE(a) \
213 do { \
214 fputs ("\t.size\t", asm_out_file); \
215 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
216 fprintf (asm_out_file, "%s", SDB_DELIM); \
217 } while(0)
218 #endif
219
220 #ifndef PUT_SDB_START_DIM
221 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
222 #endif
223
224 #ifndef PUT_SDB_NEXT_DIM
225 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
226 #endif
227
228 #ifndef PUT_SDB_LAST_DIM
229 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
230 #endif
231
232 #ifndef PUT_SDB_TAG
233 #define PUT_SDB_TAG(a) \
234 do { fprintf (asm_out_file, "\t.tag\t"); \
235 ASM_OUTPUT_LABELREF (asm_out_file, a); \
236 fprintf (asm_out_file, SDB_DELIM); } while (0)
237 #endif
238
239 #ifndef PUT_SDB_BLOCK_START
240 #define PUT_SDB_BLOCK_START(LINE) \
241 fprintf (asm_out_file, \
242 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
243 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
244 #endif
245
246 #ifndef PUT_SDB_BLOCK_END
247 #define PUT_SDB_BLOCK_END(LINE) \
248 fprintf (asm_out_file, \
249 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
250 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
251 #endif
252
253 #ifndef PUT_SDB_FUNCTION_START
254 #define PUT_SDB_FUNCTION_START(LINE) \
255 fprintf (asm_out_file, \
256 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
257 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
258 #endif
259
260 #ifndef PUT_SDB_FUNCTION_END
261 #define PUT_SDB_FUNCTION_END(LINE) \
262 fprintf (asm_out_file, \
263 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
264 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
265 #endif
266
267 #ifndef PUT_SDB_EPILOGUE_END
268 #define PUT_SDB_EPILOGUE_END(NAME) \
269 do { fprintf (asm_out_file, "\t.def\t"); \
270 ASM_OUTPUT_LABELREF (asm_out_file, NAME); \
271 fprintf (asm_out_file, \
272 "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", \
273 SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
274 #endif
275
276 #ifndef SDB_GENERATE_FAKE
277 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
278 sprintf ((BUFFER), ".%dfake", (NUMBER));
279 #endif
280
281 /* Return the sdb tag identifier string for TYPE
282 if TYPE has already been defined; otherwise return a null pointer. */
283
284 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
285
286 /* Set the sdb tag identifier string for TYPE to NAME. */
287
288 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
289 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
290
291 /* Return the name (a string) of the struct, union or enum tag
292 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
293
294 #define TAG_NAME(link) \
295 (((link) && TREE_PURPOSE ((link)) \
296 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
297 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
298
299 /* Ensure we don't output a negative line number. */
300 #define MAKE_LINE_SAFE(line) \
301 if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
302
303 /* Perform linker optimization of merging header file definitions together
304 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
305 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
306 the optimization just won't be done. The native assembler already has the
307 necessary support. */
308
309 #ifdef MIPS_DEBUGGING_INFO
310
311 #ifndef PUT_SDB_SRC_FILE
312 #define PUT_SDB_SRC_FILE(FILENAME) \
313 output_file_directive (asm_out_file, (FILENAME))
314 #endif
315
316 /* ECOFF linkers have an optimization that does the same kind of thing as
317 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
318 executable. To achieve this, GCC must output a .file for each file
319 name change. */
320
321 /* This is a stack of input files. */
322
323 struct sdb_file
324 {
325 struct sdb_file *next;
326 char *name;
327 };
328
329 /* This is the top of the stack. */
330
331 static struct sdb_file *current_file;
332
333 #endif /* MIPS_DEBUGGING_INFO */
334 \f
335 /* Set up for SDB output at the start of compilation. */
336
337 void
338 sdbout_init (asm_file, input_file_name, syms)
339 FILE *asm_file;
340 char *input_file_name;
341 tree syms;
342 {
343 #ifdef MIPS_DEBUGGING_INFO
344 current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
345 current_file->next = NULL;
346 current_file->name = input_file_name;
347 #endif
348
349 #ifdef RMS_QUICK_HACK_1
350 tree t;
351 for (t = syms; t; t = TREE_CHAIN (t))
352 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
353 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
354 sdbout_symbol (t, 0);
355 #endif
356 }
357
358 #if 0
359
360 /* return the tag identifier for type
361 */
362
363 char *
364 tag_of_ru_type (type,link)
365 tree type,link;
366 {
367 if (TYPE_SYMTAB_ADDRESS (type))
368 return TYPE_SYMTAB_ADDRESS (type);
369 if (link && TREE_PURPOSE (link)
370 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
371 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
372 else
373 return (char *) TYPE_SYMTAB_ADDRESS (type);
374 }
375 #endif
376
377 /* Return a unique string to name an anonymous type. */
378
379 static char *
380 gen_fake_label ()
381 {
382 char label[10];
383 char *labelstr;
384 SDB_GENERATE_FAKE (label, unnamed_struct_number);
385 unnamed_struct_number++;
386 labelstr = (char *) permalloc (strlen (label) + 1);
387 strcpy (labelstr, label);
388 return labelstr;
389 }
390 \f
391 /* Return the number which describes TYPE for SDB.
392 For pointers, etc., this function is recursive.
393 Each record, union or enumeral type must already have had a
394 tag number output. */
395
396 /* The number is given by d6d5d4d3d2d1bbbb
397 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
398 Thus, char *foo () has bbbb=T_CHAR
399 d1=D_FCN
400 d2=D_PTR
401 N_BTMASK= 017 1111 basic type field.
402 N_TSHIFT= 2 derived type shift
403 N_BTSHFT= 4 Basic type shift */
404
405 /* Produce the number that describes a pointer, function or array type.
406 PREV is the number describing the target, value or element type.
407 DT_type describes how to transform that type. */
408 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
409 ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT) \
410 | ((int)DT_type << (int)N_BTSHFT) \
411 | ((PREV) & (int)N_BTMASK))
412
413 /* Number of elements used in sdb_dims. */
414 static int sdb_n_dims = 0;
415
416 /* Table of array dimensions of current type. */
417 static int sdb_dims[SDB_MAX_DIM];
418
419 /* Size of outermost array currently being processed. */
420 static int sdb_type_size = -1;
421
422 static int
423 plain_type (type)
424 tree type;
425 {
426 int val = plain_type_1 (type, 0);
427
428 /* If we have already saved up some array dimensions, print them now. */
429 if (sdb_n_dims > 0)
430 {
431 int i;
432 PUT_SDB_START_DIM;
433 for (i = sdb_n_dims - 1; i > 0; i--)
434 PUT_SDB_NEXT_DIM (sdb_dims[i]);
435 PUT_SDB_LAST_DIM (sdb_dims[0]);
436 sdb_n_dims = 0;
437
438 sdb_type_size = int_size_in_bytes (type);
439 /* Don't kill sdb if type is not laid out or has variable size. */
440 if (sdb_type_size < 0)
441 sdb_type_size = 0;
442 }
443 /* If we have computed the size of an array containing this type,
444 print it now. */
445 if (sdb_type_size >= 0)
446 {
447 PUT_SDB_SIZE (sdb_type_size);
448 sdb_type_size = -1;
449 }
450 return val;
451 }
452
453 static int
454 template_name_p (name)
455 tree name;
456 {
457 register char *ptr = IDENTIFIER_POINTER (name);
458 while (*ptr && *ptr != '<')
459 ptr++;
460
461 return *ptr != '\0';
462 }
463
464 static void
465 sdbout_record_type_name (type)
466 tree type;
467 {
468 char *name = 0;
469 int no_name;
470
471 if (KNOWN_TYPE_TAG (type))
472 return;
473
474 if (TYPE_NAME (type) != 0)
475 {
476 tree t = 0;
477 /* Find the IDENTIFIER_NODE for the type name. */
478 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
479 t = TYPE_NAME (type);
480 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
481 {
482 t = DECL_NAME (TYPE_NAME (type));
483 /* The DECL_NAME for templates includes "<>", which breaks
484 most assemblers. Use its assembler name instead, which
485 has been mangled into being safe. */
486 if (t && template_name_p (t))
487 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
488 }
489
490 /* Now get the name as a string, or invent one. */
491 if (t != NULL_TREE)
492 name = IDENTIFIER_POINTER (t);
493 }
494
495 no_name = (name == 0 || *name == 0);
496 if (no_name)
497 name = gen_fake_label ();
498
499 SET_KNOWN_TYPE_TAG (type, name);
500 #ifdef SDB_ALLOW_FORWARD_REFERENCES
501 if (no_name)
502 sdbout_queue_anonymous_type (type);
503 #endif
504 }
505
506 /* Return the .type value for type TYPE.
507
508 LEVEL indicates how many levels deep we have recursed into the type.
509 The SDB debug format can only represent 6 derived levels of types.
510 After that, we must output inaccurate debug info. We deliberately
511 stop before the 7th level, so that ADA recursive types will not give an
512 infinite loop. */
513
514 static int
515 plain_type_1 (type, level)
516 tree type;
517 int level;
518 {
519 if (type == 0)
520 type = void_type_node;
521 else if (type == error_mark_node)
522 type = integer_type_node;
523 else
524 type = TYPE_MAIN_VARIANT (type);
525
526 switch (TREE_CODE (type))
527 {
528 case VOID_TYPE:
529 return T_VOID;
530 case INTEGER_TYPE:
531 {
532 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
533
534 /* Carefully distinguish all the standard types of C,
535 without messing up if the language is not C.
536 Note that we check only for the names that contain spaces;
537 other names might occur by coincidence in other languages. */
538 if (TYPE_NAME (type) != 0
539 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
540 && DECL_NAME (TYPE_NAME (type)) != 0
541 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
542 {
543 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
544
545 if (!strcmp (name, "char"))
546 return T_CHAR;
547 if (!strcmp (name, "unsigned char"))
548 return T_UCHAR;
549 if (!strcmp (name, "signed char"))
550 return T_CHAR;
551 if (!strcmp (name, "int"))
552 return T_INT;
553 if (!strcmp (name, "unsigned int"))
554 return T_UINT;
555 if (!strcmp (name, "short int"))
556 return T_SHORT;
557 if (!strcmp (name, "short unsigned int"))
558 return T_USHORT;
559 if (!strcmp (name, "long int"))
560 return T_LONG;
561 if (!strcmp (name, "long unsigned int"))
562 return T_ULONG;
563 }
564
565 if (size == INT_TYPE_SIZE)
566 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
567 if (size == CHAR_TYPE_SIZE)
568 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
569 if (size == SHORT_TYPE_SIZE)
570 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
571 if (size == LONG_TYPE_SIZE)
572 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
573 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
574 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
575 return 0;
576 }
577
578 case REAL_TYPE:
579 {
580 int precision = TYPE_PRECISION (type);
581 if (precision == FLOAT_TYPE_SIZE)
582 return T_FLOAT;
583 if (precision == DOUBLE_TYPE_SIZE)
584 return T_DOUBLE;
585 #ifdef EXTENDED_SDB_BASIC_TYPES
586 if (precision == LONG_DOUBLE_TYPE_SIZE)
587 return T_LNGDBL;
588 #else
589 if (precision == LONG_DOUBLE_TYPE_SIZE)
590 return T_DOUBLE; /* better than nothing */
591 #endif
592 return 0;
593 }
594
595 case ARRAY_TYPE:
596 {
597 int m;
598 if (level >= 6)
599 return T_VOID;
600 else
601 m = plain_type_1 (TREE_TYPE (type), level+1);
602 if (sdb_n_dims < SDB_MAX_DIM)
603 sdb_dims[sdb_n_dims++]
604 = (TYPE_DOMAIN (type)
605 && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
606 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
607 && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
608 ? (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
609 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
610 : 0);
611 return PUSH_DERIVED_LEVEL (DT_ARY, m);
612 }
613
614 case RECORD_TYPE:
615 case UNION_TYPE:
616 case QUAL_UNION_TYPE:
617 case ENUMERAL_TYPE:
618 {
619 char *tag;
620 #ifdef SDB_ALLOW_FORWARD_REFERENCES
621 sdbout_record_type_name (type);
622 #endif
623 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
624 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
625 #ifdef SDB_ALLOW_FORWARD_REFERENCES
626 || TYPE_MODE (type) != VOIDmode
627 #endif
628 )
629 #endif
630 {
631 /* Output the referenced structure tag name
632 only if the .def has already been finished.
633 At least on 386, the Unix assembler
634 cannot handle forward references to tags. */
635 /* But the 88100, it requires them, sigh... */
636 /* And the MIPS requires unknown refs as well... */
637 tag = KNOWN_TYPE_TAG (type);
638 PUT_SDB_TAG (tag);
639 /* These 3 lines used to follow the close brace.
640 However, a size of 0 without a tag implies a tag of 0,
641 so if we don't know a tag, we can't mention the size. */
642 sdb_type_size = int_size_in_bytes (type);
643 if (sdb_type_size < 0)
644 sdb_type_size = 0;
645 }
646 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
647 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
648 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
649 : T_ENUM);
650 }
651 case POINTER_TYPE:
652 case REFERENCE_TYPE:
653 {
654 int m;
655 if (level >= 6)
656 return T_VOID;
657 else
658 m = plain_type_1 (TREE_TYPE (type), level+1);
659 return PUSH_DERIVED_LEVEL (DT_PTR, m);
660 }
661 case FUNCTION_TYPE:
662 case METHOD_TYPE:
663 {
664 int m;
665 if (level >= 6)
666 return T_VOID;
667 else
668 m = plain_type_1 (TREE_TYPE (type), level+1);
669 return PUSH_DERIVED_LEVEL (DT_FCN, m);
670 }
671 default:
672 return 0;
673 }
674 }
675 \f
676 /* Output the symbols defined in block number DO_BLOCK.
677 Set NEXT_BLOCK_NUMBER to 0 before calling.
678
679 This function works by walking the tree structure of blocks,
680 counting blocks until it finds the desired block. */
681
682 static int do_block = 0;
683
684 static int next_block_number;
685
686 static void
687 sdbout_block (block)
688 register tree block;
689 {
690 while (block)
691 {
692 /* Ignore blocks never expanded or otherwise marked as real. */
693 if (TREE_USED (block))
694 {
695 /* When we reach the specified block, output its symbols. */
696 if (next_block_number == do_block)
697 {
698 sdbout_syms (BLOCK_VARS (block));
699 }
700
701 /* If we are past the specified block, stop the scan. */
702 if (next_block_number > do_block)
703 return;
704
705 next_block_number++;
706
707 /* Scan the blocks within this block. */
708 sdbout_block (BLOCK_SUBBLOCKS (block));
709 }
710
711 block = BLOCK_CHAIN (block);
712 }
713 }
714 \f
715 /* Call sdbout_symbol on each decl in the chain SYMS. */
716
717 static void
718 sdbout_syms (syms)
719 tree syms;
720 {
721 while (syms)
722 {
723 if (TREE_CODE (syms) != LABEL_DECL)
724 sdbout_symbol (syms, 1);
725 syms = TREE_CHAIN (syms);
726 }
727 }
728
729 /* Output SDB information for a symbol described by DECL.
730 LOCAL is nonzero if the symbol is not file-scope. */
731
732 void
733 sdbout_symbol (decl, local)
734 tree decl;
735 int local;
736 {
737 tree type = TREE_TYPE (decl);
738 tree context = NULL_TREE;
739 rtx value;
740 int regno = -1;
741 char *name;
742
743 sdbout_one_type (type);
744
745 #if 0 /* This loses when functions are marked to be ignored,
746 which happens in the C++ front end. */
747 if (DECL_IGNORED_P (decl))
748 return;
749 #endif
750
751 switch (TREE_CODE (decl))
752 {
753 case CONST_DECL:
754 /* Enum values are defined by defining the enum type. */
755 return;
756
757 case FUNCTION_DECL:
758 /* Don't mention a nested function under its parent. */
759 context = decl_function_context (decl);
760 if (context == current_function_decl)
761 return;
762 /* Check DECL_INITIAL to distinguish declarations from definitions.
763 Don't output debug info here for declarations; they will have
764 a DECL_INITIAL value of 0. */
765 if (! DECL_INITIAL (decl))
766 return;
767 if (GET_CODE (DECL_RTL (decl)) != MEM
768 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
769 return;
770 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
771 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
772 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
773 break;
774
775 case TYPE_DECL:
776 /* Done with tagged types. */
777 if (DECL_NAME (decl) == 0)
778 return;
779 if (DECL_IGNORED_P (decl))
780 return;
781
782 /* Output typedef name. */
783 if (template_name_p (DECL_NAME (decl)))
784 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
785 else
786 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
787 PUT_SDB_SCL (C_TPDEF);
788 break;
789
790 case PARM_DECL:
791 /* Parm decls go in their own separate chains
792 and are output by sdbout_reg_parms and sdbout_parms. */
793 abort ();
794
795 case VAR_DECL:
796 /* Don't mention a variable that is external.
797 Let the file that defines it describe it. */
798 if (DECL_EXTERNAL (decl))
799 return;
800
801 /* Ignore __FUNCTION__, etc. */
802 if (DECL_IGNORED_P (decl))
803 return;
804
805 /* If there was an error in the declaration, don't dump core
806 if there is no RTL associated with the variable doesn't
807 exist. */
808 if (DECL_RTL (decl) == 0)
809 return;
810
811 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
812 #ifdef LEAF_REG_REMAP
813 if (leaf_function)
814 leaf_renumber_regs_insn (DECL_RTL (decl));
815 #endif
816 value = DECL_RTL (decl);
817
818 /* Don't mention a variable at all
819 if it was completely optimized into nothingness.
820
821 If DECL was from an inline function, then its rtl
822 is not identically the rtl that was used in this
823 particular compilation. */
824 if (GET_CODE (value) == REG)
825 {
826 regno = REGNO (DECL_RTL (decl));
827 if (regno >= FIRST_PSEUDO_REGISTER)
828 return;
829 }
830 else if (GET_CODE (value) == SUBREG)
831 {
832 int offset = 0;
833 while (GET_CODE (value) == SUBREG)
834 {
835 offset += SUBREG_WORD (value);
836 value = SUBREG_REG (value);
837 }
838 if (GET_CODE (value) == REG)
839 {
840 regno = REGNO (value);
841 if (regno >= FIRST_PSEUDO_REGISTER)
842 return;
843 regno += offset;
844 }
845 alter_subreg (DECL_RTL (decl));
846 value = DECL_RTL (decl);
847 }
848 /* Don't output anything if an auto variable
849 gets RTL that is static.
850 GAS version 2.2 can't handle such output. */
851 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
852 && ! TREE_STATIC (decl))
853 return;
854
855 /* Emit any structure, union, or enum type that has not been output.
856 This occurs for tag-less structs (et al) used to declare variables
857 within functions. */
858 if (TREE_CODE (type) == ENUMERAL_TYPE
859 || TREE_CODE (type) == RECORD_TYPE
860 || TREE_CODE (type) == UNION_TYPE
861 || TREE_CODE (type) == QUAL_UNION_TYPE)
862 {
863 if (TYPE_SIZE (type) != 0 /* not a forward reference */
864 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
865 sdbout_one_type (type);
866 }
867
868 /* Defer SDB information for top-level initialized variables! */
869 if (! local
870 && GET_CODE (value) == MEM
871 && DECL_INITIAL (decl))
872 return;
873
874 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
875 For now, avoid crashing. */
876 if (DECL_NAME (decl) == NULL_TREE)
877 return;
878
879 /* Record the name for, starting a symtab entry. */
880 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
881
882 if (GET_CODE (value) == MEM
883 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
884 {
885 PUT_SDB_DEF (name);
886 if (TREE_PUBLIC (decl))
887 {
888 PUT_SDB_VAL (XEXP (value, 0));
889 PUT_SDB_SCL (C_EXT);
890 }
891 else
892 {
893 PUT_SDB_VAL (XEXP (value, 0));
894 PUT_SDB_SCL (C_STAT);
895 }
896 }
897 else if (regno >= 0)
898 {
899 PUT_SDB_DEF (name);
900 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
901 PUT_SDB_SCL (C_REG);
902 }
903 else if (GET_CODE (value) == MEM
904 && (GET_CODE (XEXP (value, 0)) == MEM
905 || (GET_CODE (XEXP (value, 0)) == REG
906 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
907 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
908 /* If the value is indirect by memory or by a register
909 that isn't the frame pointer
910 then it means the object is variable-sized and address through
911 that register or stack slot. COFF has no way to represent this
912 so all we can do is output the variable as a pointer. */
913 {
914 PUT_SDB_DEF (name);
915 if (GET_CODE (XEXP (value, 0)) == REG)
916 {
917 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
918 PUT_SDB_SCL (C_REG);
919 }
920 else
921 {
922 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
923 (CONST_INT...)))).
924 We want the value of that CONST_INT. */
925 /* Encore compiler hates a newline in a macro arg, it seems. */
926 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
927 (XEXP (XEXP (value, 0), 0)));
928 PUT_SDB_SCL (C_AUTO);
929 }
930
931 type = build_pointer_type (TREE_TYPE (decl));
932 }
933 else if (GET_CODE (value) == MEM
934 && ((GET_CODE (XEXP (value, 0)) == PLUS
935 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
936 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
937 /* This is for variables which are at offset zero from
938 the frame pointer. This happens on the Alpha.
939 Non-frame pointer registers are excluded above. */
940 || (GET_CODE (XEXP (value, 0)) == REG)))
941 {
942 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
943 or (MEM (REG...)). We want the value of that CONST_INT
944 or zero. */
945 PUT_SDB_DEF (name);
946 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
947 PUT_SDB_SCL (C_AUTO);
948 }
949 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
950 {
951 /* Handle an obscure case which can arise when optimizing and
952 when there are few available registers. (This is *always*
953 the case for i386/i486 targets). The DECL_RTL looks like
954 (MEM (CONST ...)) even though this variable is a local `auto'
955 or a local `register' variable. In effect, what has happened
956 is that the reload pass has seen that all assignments and
957 references for one such a local variable can be replaced by
958 equivalent assignments and references to some static storage
959 variable, thereby avoiding the need for a register. In such
960 cases we're forced to lie to debuggers and tell them that
961 this variable was itself `static'. */
962 PUT_SDB_DEF (name);
963 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
964 PUT_SDB_SCL (C_STAT);
965 }
966 else
967 {
968 /* It is something we don't know how to represent for SDB. */
969 return;
970 }
971 break;
972
973 default:
974 break;
975 }
976 PUT_SDB_TYPE (plain_type (type));
977 PUT_SDB_ENDEF;
978 }
979 \f
980 /* Output SDB information for a top-level initialized variable
981 that has been delayed. */
982
983 void
984 sdbout_toplevel_data (decl)
985 tree decl;
986 {
987 tree type = TREE_TYPE (decl);
988
989 if (DECL_IGNORED_P (decl))
990 return;
991
992 if (! (TREE_CODE (decl) == VAR_DECL
993 && GET_CODE (DECL_RTL (decl)) == MEM
994 && DECL_INITIAL (decl)))
995 abort ();
996
997 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
998 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
999 if (TREE_PUBLIC (decl))
1000 {
1001 PUT_SDB_SCL (C_EXT);
1002 }
1003 else
1004 {
1005 PUT_SDB_SCL (C_STAT);
1006 }
1007 PUT_SDB_TYPE (plain_type (type));
1008 PUT_SDB_ENDEF;
1009 }
1010 \f
1011 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1012
1013 /* Machinery to record and output anonymous types. */
1014
1015 static tree anonymous_types;
1016
1017 static void
1018 sdbout_queue_anonymous_type (type)
1019 tree type;
1020 {
1021 anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
1022 }
1023
1024 static void
1025 sdbout_dequeue_anonymous_types ()
1026 {
1027 register tree types, link;
1028
1029 while (anonymous_types)
1030 {
1031 types = nreverse (anonymous_types);
1032 anonymous_types = NULL_TREE;
1033
1034 for (link = types; link; link = TREE_CHAIN (link))
1035 {
1036 register tree type = TREE_VALUE (link);
1037
1038 if (type && ! TREE_ASM_WRITTEN (type))
1039 sdbout_one_type (type);
1040 }
1041 }
1042 }
1043
1044 #endif
1045 \f
1046 /* Given a chain of ..._TYPE nodes, all of which have names,
1047 output definitions of those names, as typedefs. */
1048
1049 void
1050 sdbout_types (types)
1051 register tree types;
1052 {
1053 register tree link;
1054
1055 for (link = types; link; link = TREE_CHAIN (link))
1056 sdbout_one_type (link);
1057
1058 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1059 sdbout_dequeue_anonymous_types ();
1060 #endif
1061 }
1062
1063 static void
1064 sdbout_type (type)
1065 tree type;
1066 {
1067 if (type == error_mark_node)
1068 type = integer_type_node;
1069 PUT_SDB_TYPE (plain_type (type));
1070 }
1071
1072 /* Output types of the fields of type TYPE, if they are structs.
1073
1074 Formerly did not chase through pointer types, since that could be circular.
1075 They must come before TYPE, since forward refs are not allowed.
1076 Now james@bigtex.cactus.org says to try them. */
1077
1078 static void
1079 sdbout_field_types (type)
1080 tree type;
1081 {
1082 tree tail;
1083
1084 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1085 /* This condition should match the one for emitting the actual members
1086 below. */
1087 if (TREE_CODE (tail) == FIELD_DECL
1088 && DECL_NAME (tail) != 0
1089 && TREE_CODE (DECL_SIZE (tail)) == INTEGER_CST
1090 && TREE_CODE (DECL_FIELD_BITPOS (tail)) == INTEGER_CST)
1091 {
1092 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1093 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1094 else
1095 sdbout_one_type (TREE_TYPE (tail));
1096 }
1097 }
1098
1099 /* Use this to put out the top level defined record and union types
1100 for later reference. If this is a struct with a name, then put that
1101 name out. Other unnamed structs will have .xxfake labels generated so
1102 that they may be referred to later.
1103 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1104 It may NOT be called recursively. */
1105
1106 static void
1107 sdbout_one_type (type)
1108 tree type;
1109 {
1110 if (current_function_decl != NULL_TREE
1111 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1112 ; /* Don't change section amid function. */
1113 else
1114 text_section ();
1115
1116 switch (TREE_CODE (type))
1117 {
1118 case RECORD_TYPE:
1119 case UNION_TYPE:
1120 case QUAL_UNION_TYPE:
1121 case ENUMERAL_TYPE:
1122 type = TYPE_MAIN_VARIANT (type);
1123 /* Don't output a type twice. */
1124 if (TREE_ASM_WRITTEN (type))
1125 /* James said test TREE_ASM_BEING_WRITTEN here. */
1126 return;
1127
1128 /* Output nothing if type is not yet defined. */
1129 if (TYPE_SIZE (type) == 0)
1130 return;
1131
1132 TREE_ASM_WRITTEN (type) = 1;
1133 #if 1
1134 /* This is reputed to cause trouble with the following case,
1135 but perhaps checking TYPE_SIZE above will fix it. */
1136
1137 /* Here is a test case:
1138
1139 struct foo {
1140 struct badstr *bbb;
1141 } forwardref;
1142
1143 typedef struct intermediate {
1144 int aaaa;
1145 } intermediate_ref;
1146
1147 typedef struct badstr {
1148 int ccccc;
1149 } badtype; */
1150
1151 #if 0
1152 TREE_ASM_BEING_WRITTEN (type) = 1;
1153 #endif
1154 /* This change, which ought to make better output,
1155 used to make the COFF assembler unhappy.
1156 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1157 /* Before really doing anything, output types we want to refer to. */
1158 /* Note that in version 1 the following two lines
1159 are not used if forward references are in use. */
1160 if (TREE_CODE (type) != ENUMERAL_TYPE)
1161 sdbout_field_types (type);
1162 #if 0
1163 TREE_ASM_WRITTEN (type) = 1;
1164 #endif
1165 #endif
1166
1167 /* Output a structure type. */
1168 {
1169 int size = int_size_in_bytes (type);
1170 int member_scl;
1171 tree tem;
1172 int i, n_baseclasses = 0;
1173
1174 /* Record the type tag, but not in its permanent place just yet. */
1175 sdbout_record_type_name (type);
1176
1177 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1178
1179 switch (TREE_CODE (type))
1180 {
1181 case UNION_TYPE:
1182 case QUAL_UNION_TYPE:
1183 PUT_SDB_SCL (C_UNTAG);
1184 PUT_SDB_TYPE (T_UNION);
1185 member_scl = C_MOU;
1186 break;
1187
1188 case RECORD_TYPE:
1189 PUT_SDB_SCL (C_STRTAG);
1190 PUT_SDB_TYPE (T_STRUCT);
1191 member_scl = C_MOS;
1192 break;
1193
1194 case ENUMERAL_TYPE:
1195 PUT_SDB_SCL (C_ENTAG);
1196 PUT_SDB_TYPE (T_ENUM);
1197 member_scl = C_MOE;
1198 break;
1199
1200 default:
1201 break;
1202 }
1203
1204 PUT_SDB_SIZE (size);
1205 PUT_SDB_ENDEF;
1206
1207 /* Print out the base class information with fields
1208 named after the types they hold. */
1209 if (TYPE_BINFO (type)
1210 && TYPE_BINFO_BASETYPES (type))
1211 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1212 for (i = 0; i < n_baseclasses; i++)
1213 {
1214 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1215 tree child_type = BINFO_TYPE (child);
1216 tree child_type_name;
1217 if (TYPE_NAME (child_type) == 0)
1218 continue;
1219 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1220 child_type_name = TYPE_NAME (child_type);
1221 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1222 {
1223 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1224 if (child_type_name && template_name_p (child_type_name))
1225 child_type_name
1226 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1227 }
1228 else
1229 continue;
1230
1231 CONTIN;
1232 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1233 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
1234 PUT_SDB_SCL (member_scl);
1235 sdbout_type (BINFO_TYPE (child));
1236 PUT_SDB_ENDEF;
1237 }
1238
1239 /* output the individual fields */
1240
1241 if (TREE_CODE (type) == ENUMERAL_TYPE)
1242 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1243 {
1244 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1245 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1246 PUT_SDB_SCL (C_MOE);
1247 PUT_SDB_TYPE (T_MOE);
1248 PUT_SDB_ENDEF;
1249 }
1250
1251 else /* record or union type */
1252 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1253 /* Output the name, type, position (in bits), size (in bits)
1254 of each field. */
1255
1256 /* Omit here the nameless fields that are used to skip bits.
1257 Also omit fields with variable size or position.
1258 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1259 if (TREE_CODE (tem) == FIELD_DECL
1260 && DECL_NAME (tem) != 0
1261 && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
1262 && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
1263 {
1264 char *name;
1265
1266 CONTIN;
1267 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
1268 PUT_SDB_DEF (name);
1269 if (DECL_BIT_FIELD_TYPE (tem))
1270 {
1271 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
1272 PUT_SDB_SCL (C_FIELD);
1273 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1274 PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
1275 }
1276 else
1277 {
1278 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
1279 / BITS_PER_UNIT);
1280 PUT_SDB_SCL (member_scl);
1281 sdbout_type (TREE_TYPE (tem));
1282 }
1283 PUT_SDB_ENDEF;
1284 }
1285 /* output end of a structure,union, or enumeral definition */
1286
1287 PUT_SDB_PLAIN_DEF ("eos");
1288 PUT_SDB_INT_VAL (size);
1289 PUT_SDB_SCL (C_EOS);
1290 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1291 PUT_SDB_SIZE (size);
1292 PUT_SDB_ENDEF;
1293 break;
1294
1295 default:
1296 break;
1297 }
1298 }
1299 }
1300 \f
1301 /* The following two functions output definitions of function parameters.
1302 Each parameter gets a definition locating it in the parameter list.
1303 Each parameter that is a register variable gets a second definition
1304 locating it in the register.
1305
1306 Printing or argument lists in gdb uses the definitions that
1307 locate in the parameter list. But reference to the variable in
1308 expressions uses preferentially the definition as a register. */
1309
1310 /* Output definitions, referring to storage in the parmlist,
1311 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1312
1313 static void
1314 sdbout_parms (parms)
1315 tree parms;
1316 {
1317 for (; parms; parms = TREE_CHAIN (parms))
1318 if (DECL_NAME (parms))
1319 {
1320 int current_sym_value = 0;
1321 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1322
1323 if (name == 0 || *name == 0)
1324 name = gen_fake_label ();
1325
1326 /* Perform any necessary register eliminations on the parameter's rtl,
1327 so that the debugging output will be accurate. */
1328 DECL_INCOMING_RTL (parms)
1329 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1330 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1331
1332 if (PARM_PASSED_IN_MEMORY (parms))
1333 {
1334 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1335 tree type;
1336
1337 /* ??? Here we assume that the parm address is indexed
1338 off the frame pointer or arg pointer.
1339 If that is not true, we produce meaningless results,
1340 but do not crash. */
1341 if (GET_CODE (addr) == PLUS
1342 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1343 current_sym_value = INTVAL (XEXP (addr, 1));
1344 else
1345 current_sym_value = 0;
1346
1347 if (GET_CODE (DECL_RTL (parms)) == REG
1348 && REGNO (DECL_RTL (parms)) >= 0
1349 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1350 type = DECL_ARG_TYPE (parms);
1351 else
1352 {
1353 int original_sym_value = current_sym_value;
1354
1355 /* This is the case where the parm is passed as an int or
1356 double and it is converted to a char, short or float
1357 and stored back in the parmlist. In this case, describe
1358 the parm with the variable's declared type, and adjust
1359 the address if the least significant bytes (which we are
1360 using) are not the first ones. */
1361 if (BYTES_BIG_ENDIAN
1362 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1363 current_sym_value +=
1364 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1365 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1366
1367 if (GET_CODE (DECL_RTL (parms)) == MEM
1368 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1369 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1370 == CONST_INT)
1371 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1372 == current_sym_value))
1373 type = TREE_TYPE (parms);
1374 else
1375 {
1376 current_sym_value = original_sym_value;
1377 type = DECL_ARG_TYPE (parms);
1378 }
1379 }
1380
1381 PUT_SDB_DEF (name);
1382 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1383 PUT_SDB_SCL (C_ARG);
1384 PUT_SDB_TYPE (plain_type (type));
1385 PUT_SDB_ENDEF;
1386 }
1387 else if (GET_CODE (DECL_RTL (parms)) == REG)
1388 {
1389 rtx best_rtl;
1390 /* Parm passed in registers and lives in registers or nowhere. */
1391
1392 /* If parm lives in a register, use that register;
1393 pretend the parm was passed there. It would be more consistent
1394 to describe the register where the parm was passed,
1395 but in practice that register usually holds something else. */
1396 if (REGNO (DECL_RTL (parms)) >= 0
1397 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1398 best_rtl = DECL_RTL (parms);
1399 /* If the parm lives nowhere,
1400 use the register where it was passed. */
1401 else
1402 best_rtl = DECL_INCOMING_RTL (parms);
1403
1404 PUT_SDB_DEF (name);
1405 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1406 PUT_SDB_SCL (C_REGPARM);
1407 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1408 PUT_SDB_ENDEF;
1409 }
1410 else if (GET_CODE (DECL_RTL (parms)) == MEM
1411 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1412 {
1413 /* Parm was passed in registers but lives on the stack. */
1414
1415 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1416 in which case we want the value of that CONST_INT,
1417 or (MEM (REG ...)) or (MEM (MEM ...)),
1418 in which case we use a value of zero. */
1419 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1420 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1421 current_sym_value = 0;
1422 else
1423 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1424
1425 /* Again, this assumes the offset is based on the arg pointer. */
1426 PUT_SDB_DEF (name);
1427 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1428 XEXP (DECL_RTL (parms), 0)));
1429 PUT_SDB_SCL (C_ARG);
1430 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1431 PUT_SDB_ENDEF;
1432 }
1433 }
1434 }
1435
1436 /* Output definitions for the places where parms live during the function,
1437 when different from where they were passed, when the parms were passed
1438 in memory.
1439
1440 It is not useful to do this for parms passed in registers
1441 that live during the function in different registers, because it is
1442 impossible to look in the passed register for the passed value,
1443 so we use the within-the-function register to begin with.
1444
1445 PARMS is a chain of PARM_DECL nodes. */
1446
1447 static void
1448 sdbout_reg_parms (parms)
1449 tree parms;
1450 {
1451 for (; parms; parms = TREE_CHAIN (parms))
1452 if (DECL_NAME (parms))
1453 {
1454 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1455
1456 /* Report parms that live in registers during the function
1457 but were passed in memory. */
1458 if (GET_CODE (DECL_RTL (parms)) == REG
1459 && REGNO (DECL_RTL (parms)) >= 0
1460 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1461 && PARM_PASSED_IN_MEMORY (parms))
1462 {
1463 if (name == 0 || *name == 0)
1464 name = gen_fake_label ();
1465 PUT_SDB_DEF (name);
1466 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1467 PUT_SDB_SCL (C_REG);
1468 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1469 PUT_SDB_ENDEF;
1470 }
1471 /* Report parms that live in memory but not where they were passed. */
1472 else if (GET_CODE (DECL_RTL (parms)) == MEM
1473 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1474 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1475 && PARM_PASSED_IN_MEMORY (parms)
1476 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1477 {
1478 #if 0 /* ??? It is not clear yet what should replace this. */
1479 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1480 /* A parm declared char is really passed as an int,
1481 so it occupies the least significant bytes.
1482 On a big-endian machine those are not the low-numbered ones. */
1483 if (BYTES_BIG_ENDIAN
1484 && offset != -1
1485 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1486 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1487 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1488 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1489 #endif
1490 {
1491 if (name == 0 || *name == 0)
1492 name = gen_fake_label ();
1493 PUT_SDB_DEF (name);
1494 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1495 (XEXP (DECL_RTL (parms), 0)));
1496 PUT_SDB_SCL (C_AUTO);
1497 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1498 PUT_SDB_ENDEF;
1499 }
1500 }
1501 }
1502 }
1503 \f
1504 /* Describe the beginning of an internal block within a function.
1505 Also output descriptions of variables defined in this block.
1506
1507 N is the number of the block, by order of beginning, counting from 1,
1508 and not counting the outermost (function top-level) block.
1509 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1510 if the count starts at 0 for the outermost one. */
1511
1512 void
1513 sdbout_begin_block (file, line, n)
1514 FILE *file;
1515 int line;
1516 int n;
1517 {
1518 tree decl = current_function_decl;
1519 MAKE_LINE_SAFE (line);
1520
1521 /* The SCO compiler does not emit a separate block for the function level
1522 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1523 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1524 #ifndef MIPS_DEBUGGING_INFO
1525 if (n != 1)
1526 #endif
1527 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1528
1529 if (n == 1)
1530 {
1531 /* Include the outermost BLOCK's variables in block 1. */
1532 next_block_number = 0;
1533 do_block = 0;
1534 sdbout_block (DECL_INITIAL (decl));
1535 }
1536 /* If -g1, suppress all the internal symbols of functions
1537 except for arguments. */
1538 if (debug_info_level != DINFO_LEVEL_TERSE)
1539 {
1540 next_block_number = 0;
1541 do_block = n;
1542 sdbout_block (DECL_INITIAL (decl));
1543 }
1544
1545 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1546 sdbout_dequeue_anonymous_types ();
1547 #endif
1548 }
1549
1550 /* Describe the end line-number of an internal block within a function. */
1551
1552 void
1553 sdbout_end_block (file, line, n)
1554 FILE *file;
1555 int line;
1556 int n;
1557 {
1558 MAKE_LINE_SAFE (line);
1559
1560 /* The SCO compiler does not emit a separate block for the function level
1561 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1562 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1563 #ifndef MIPS_DEBUGGING_INFO
1564 if (n != 1)
1565 #endif
1566 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1567 }
1568
1569 /* Output sdb info for the current function name.
1570 Called from assemble_start_function. */
1571
1572 void
1573 sdbout_mark_begin_function ()
1574 {
1575 sdbout_symbol (current_function_decl, 0);
1576 }
1577
1578 /* Called at beginning of function body (after prologue).
1579 Record the function's starting line number, so we can output
1580 relative line numbers for the other lines.
1581 Describe beginning of outermost block.
1582 Also describe the parameter list. */
1583
1584 void
1585 sdbout_begin_function (line)
1586 int line;
1587 {
1588 sdb_begin_function_line = line - 1;
1589 PUT_SDB_FUNCTION_START (line);
1590 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1591 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1592 }
1593
1594 /* Called at end of function (before epilogue).
1595 Describe end of outermost block. */
1596
1597 void
1598 sdbout_end_function (line)
1599 int line;
1600 {
1601 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1602 sdbout_dequeue_anonymous_types ();
1603 #endif
1604
1605 MAKE_LINE_SAFE (line);
1606 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1607
1608 /* Indicate we are between functions, for line-number output. */
1609 sdb_begin_function_line = -1;
1610 }
1611
1612 /* Output sdb info for the absolute end of a function.
1613 Called after the epilogue is output. */
1614
1615 void
1616 sdbout_end_epilogue ()
1617 {
1618 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1619 PUT_SDB_EPILOGUE_END (name);
1620 }
1621
1622 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1623 is present. */
1624
1625 void
1626 sdbout_label (insn)
1627 register rtx insn;
1628 {
1629 PUT_SDB_DEF (LABEL_NAME (insn));
1630 PUT_SDB_VAL (insn);
1631 PUT_SDB_SCL (C_LABEL);
1632 PUT_SDB_TYPE (T_NULL);
1633 PUT_SDB_ENDEF;
1634 }
1635
1636 /* Change to reading from a new source file. */
1637
1638 void
1639 sdbout_start_new_source_file (filename)
1640 char *filename;
1641 {
1642 #ifdef MIPS_DEBUGGING_INFO
1643 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1644
1645 n->next = current_file;
1646 n->name = filename;
1647 current_file = n;
1648 PUT_SDB_SRC_FILE (filename);
1649 #endif
1650 }
1651
1652 /* Revert to reading a previous source file. */
1653
1654 void
1655 sdbout_resume_previous_source_file ()
1656 {
1657 #ifdef MIPS_DEBUGGING_INFO
1658 struct sdb_file *next;
1659
1660 next = current_file->next;
1661 free (current_file);
1662 current_file = next;
1663 PUT_SDB_SRC_FILE (current_file->name);
1664 #endif
1665 }
1666
1667 #endif /* SDB_DEBUGGING_INFO */