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