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