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