* gcconfig.h (DYNAMIC_LOADING): Define for PPC Linux.
[official-gcc.git] / gcc / sdbout.c
blob6433c67a2a15c6d0149f3d6a2794e04d37e095d5
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_MIN_VALUE (TYPE_DOMAIN (type)) != 0
611 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
612 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
613 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
614 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
615 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
616 : 0);
618 return PUSH_DERIVED_LEVEL (DT_ARY, m);
621 case RECORD_TYPE:
622 case UNION_TYPE:
623 case QUAL_UNION_TYPE:
624 case ENUMERAL_TYPE:
626 char *tag;
627 #ifdef SDB_ALLOW_FORWARD_REFERENCES
628 sdbout_record_type_name (type);
629 #endif
630 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
631 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
632 #ifdef SDB_ALLOW_FORWARD_REFERENCES
633 || TYPE_MODE (type) != VOIDmode
634 #endif
636 #endif
638 /* Output the referenced structure tag name
639 only if the .def has already been finished.
640 At least on 386, the Unix assembler
641 cannot handle forward references to tags. */
642 /* But the 88100, it requires them, sigh... */
643 /* And the MIPS requires unknown refs as well... */
644 tag = KNOWN_TYPE_TAG (type);
645 PUT_SDB_TAG (tag);
646 /* These 3 lines used to follow the close brace.
647 However, a size of 0 without a tag implies a tag of 0,
648 so if we don't know a tag, we can't mention the size. */
649 sdb_type_size = int_size_in_bytes (type);
650 if (sdb_type_size < 0)
651 sdb_type_size = 0;
653 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
654 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
655 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
656 : T_ENUM);
658 case POINTER_TYPE:
659 case REFERENCE_TYPE:
661 int m;
662 if (level >= 6)
663 return T_VOID;
664 else
665 m = plain_type_1 (TREE_TYPE (type), level+1);
666 return PUSH_DERIVED_LEVEL (DT_PTR, m);
668 case FUNCTION_TYPE:
669 case METHOD_TYPE:
671 int m;
672 if (level >= 6)
673 return T_VOID;
674 else
675 m = plain_type_1 (TREE_TYPE (type), level+1);
676 return PUSH_DERIVED_LEVEL (DT_FCN, m);
678 default:
679 return 0;
683 /* Output the symbols defined in block number DO_BLOCK.
685 This function works by walking the tree structure of blocks,
686 counting blocks until it finds the desired block. */
688 static int do_block = 0;
690 static void
691 sdbout_block (block)
692 register tree block;
694 while (block)
696 /* Ignore blocks never expanded or otherwise marked as real. */
697 if (TREE_USED (block))
699 /* When we reach the specified block, output its symbols. */
700 if (BLOCK_NUMBER (block) == do_block)
701 sdbout_syms (BLOCK_VARS (block));
703 /* If we are past the specified block, stop the scan. */
704 if (BLOCK_NUMBER (block) > do_block)
705 return;
707 /* Scan the blocks within this block. */
708 sdbout_block (BLOCK_SUBBLOCKS (block));
711 block = BLOCK_CHAIN (block);
715 /* Call sdbout_symbol on each decl in the chain SYMS. */
717 static void
718 sdbout_syms (syms)
719 tree syms;
721 while (syms)
723 if (TREE_CODE (syms) != LABEL_DECL)
724 sdbout_symbol (syms, 1);
725 syms = TREE_CHAIN (syms);
729 /* Output SDB information for a symbol described by DECL.
730 LOCAL is nonzero if the symbol is not file-scope. */
732 void
733 sdbout_symbol (decl, local)
734 tree decl;
735 int local;
737 tree type = TREE_TYPE (decl);
738 tree context = NULL_TREE;
739 rtx value;
740 int regno = -1;
741 char *name;
743 sdbout_one_type (type);
745 #if 0 /* This loses when functions are marked to be ignored,
746 which happens in the C++ front end. */
747 if (DECL_IGNORED_P (decl))
748 return;
749 #endif
751 switch (TREE_CODE (decl))
753 case CONST_DECL:
754 /* Enum values are defined by defining the enum type. */
755 return;
757 case FUNCTION_DECL:
758 /* Don't mention a nested function under its parent. */
759 context = decl_function_context (decl);
760 if (context == current_function_decl)
761 return;
762 /* Check DECL_INITIAL to distinguish declarations from definitions.
763 Don't output debug info here for declarations; they will have
764 a DECL_INITIAL value of 0. */
765 if (! DECL_INITIAL (decl))
766 return;
767 if (GET_CODE (DECL_RTL (decl)) != MEM
768 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
769 return;
770 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
771 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
772 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
773 break;
775 case TYPE_DECL:
776 /* Done with tagged types. */
777 if (DECL_NAME (decl) == 0)
778 return;
779 if (DECL_IGNORED_P (decl))
780 return;
782 /* Output typedef name. */
783 if (template_name_p (DECL_NAME (decl)))
784 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
785 else
786 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
787 PUT_SDB_SCL (C_TPDEF);
788 break;
790 case PARM_DECL:
791 /* Parm decls go in their own separate chains
792 and are output by sdbout_reg_parms and sdbout_parms. */
793 abort ();
795 case VAR_DECL:
796 /* Don't mention a variable that is external.
797 Let the file that defines it describe it. */
798 if (DECL_EXTERNAL (decl))
799 return;
801 /* Ignore __FUNCTION__, etc. */
802 if (DECL_IGNORED_P (decl))
803 return;
805 /* If there was an error in the declaration, don't dump core
806 if there is no RTL associated with the variable doesn't
807 exist. */
808 if (DECL_RTL (decl) == 0)
809 return;
811 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
812 #ifdef LEAF_REG_REMAP
813 if (current_function_uses_only_leaf_regs)
814 leaf_renumber_regs_insn (DECL_RTL (decl));
815 #endif
816 value = DECL_RTL (decl);
818 /* Don't mention a variable at all
819 if it was completely optimized into nothingness.
821 If DECL was from an inline function, then its rtl
822 is not identically the rtl that was used in this
823 particular compilation. */
824 if (GET_CODE (value) == REG)
826 regno = REGNO (DECL_RTL (decl));
827 if (regno >= FIRST_PSEUDO_REGISTER)
828 return;
830 else if (GET_CODE (value) == SUBREG)
832 int offset = 0;
833 while (GET_CODE (value) == SUBREG)
835 offset += SUBREG_WORD (value);
836 value = SUBREG_REG (value);
838 if (GET_CODE (value) == REG)
840 regno = REGNO (value);
841 if (regno >= FIRST_PSEUDO_REGISTER)
842 return;
843 regno += offset;
845 alter_subreg (DECL_RTL (decl));
846 value = DECL_RTL (decl);
848 /* Don't output anything if an auto variable
849 gets RTL that is static.
850 GAS version 2.2 can't handle such output. */
851 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
852 && ! TREE_STATIC (decl))
853 return;
855 /* Emit any structure, union, or enum type that has not been output.
856 This occurs for tag-less structs (et al) used to declare variables
857 within functions. */
858 if (TREE_CODE (type) == ENUMERAL_TYPE
859 || TREE_CODE (type) == RECORD_TYPE
860 || TREE_CODE (type) == UNION_TYPE
861 || TREE_CODE (type) == QUAL_UNION_TYPE)
863 if (COMPLETE_TYPE_P (type) /* not a forward reference */
864 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
865 sdbout_one_type (type);
868 /* Defer SDB information for top-level initialized variables! */
869 if (! local
870 && GET_CODE (value) == MEM
871 && DECL_INITIAL (decl))
872 return;
874 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
875 For now, avoid crashing. */
876 if (DECL_NAME (decl) == NULL_TREE)
877 return;
879 /* Record the name for, starting a symtab entry. */
880 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
882 if (GET_CODE (value) == MEM
883 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
885 PUT_SDB_DEF (name);
886 if (TREE_PUBLIC (decl))
888 PUT_SDB_VAL (XEXP (value, 0));
889 PUT_SDB_SCL (C_EXT);
891 else
893 PUT_SDB_VAL (XEXP (value, 0));
894 PUT_SDB_SCL (C_STAT);
897 else if (regno >= 0)
899 PUT_SDB_DEF (name);
900 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
901 PUT_SDB_SCL (C_REG);
903 else if (GET_CODE (value) == MEM
904 && (GET_CODE (XEXP (value, 0)) == MEM
905 || (GET_CODE (XEXP (value, 0)) == REG
906 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
907 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
908 /* If the value is indirect by memory or by a register
909 that isn't the frame pointer
910 then it means the object is variable-sized and address through
911 that register or stack slot. COFF has no way to represent this
912 so all we can do is output the variable as a pointer. */
914 PUT_SDB_DEF (name);
915 if (GET_CODE (XEXP (value, 0)) == REG)
917 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
918 PUT_SDB_SCL (C_REG);
920 else
922 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
923 (CONST_INT...)))).
924 We want the value of that CONST_INT. */
925 /* Encore compiler hates a newline in a macro arg, it seems. */
926 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
927 (XEXP (XEXP (value, 0), 0)));
928 PUT_SDB_SCL (C_AUTO);
931 /* Effectively do build_pointer_type, but don't cache this type,
932 since it might be temporary whereas the type it points to
933 might have been saved for inlining. */
934 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
935 type = make_node (POINTER_TYPE);
936 TREE_TYPE (type) = TREE_TYPE (decl);
938 else if (GET_CODE (value) == MEM
939 && ((GET_CODE (XEXP (value, 0)) == PLUS
940 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
941 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
942 /* This is for variables which are at offset zero from
943 the frame pointer. This happens on the Alpha.
944 Non-frame pointer registers are excluded above. */
945 || (GET_CODE (XEXP (value, 0)) == REG)))
947 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
948 or (MEM (REG...)). We want the value of that CONST_INT
949 or zero. */
950 PUT_SDB_DEF (name);
951 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
952 PUT_SDB_SCL (C_AUTO);
954 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
956 /* Handle an obscure case which can arise when optimizing and
957 when there are few available registers. (This is *always*
958 the case for i386/i486 targets). The DECL_RTL looks like
959 (MEM (CONST ...)) even though this variable is a local `auto'
960 or a local `register' variable. In effect, what has happened
961 is that the reload pass has seen that all assignments and
962 references for one such a local variable can be replaced by
963 equivalent assignments and references to some static storage
964 variable, thereby avoiding the need for a register. In such
965 cases we're forced to lie to debuggers and tell them that
966 this variable was itself `static'. */
967 PUT_SDB_DEF (name);
968 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
969 PUT_SDB_SCL (C_STAT);
971 else
973 /* It is something we don't know how to represent for SDB. */
974 return;
976 break;
978 default:
979 break;
981 PUT_SDB_TYPE (plain_type (type));
982 PUT_SDB_ENDEF;
985 /* Output SDB information for a top-level initialized variable
986 that has been delayed. */
988 void
989 sdbout_toplevel_data (decl)
990 tree decl;
992 tree type = TREE_TYPE (decl);
994 if (DECL_IGNORED_P (decl))
995 return;
997 if (! (TREE_CODE (decl) == VAR_DECL
998 && GET_CODE (DECL_RTL (decl)) == MEM
999 && DECL_INITIAL (decl)))
1000 abort ();
1002 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1003 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
1004 if (TREE_PUBLIC (decl))
1006 PUT_SDB_SCL (C_EXT);
1008 else
1010 PUT_SDB_SCL (C_STAT);
1012 PUT_SDB_TYPE (plain_type (type));
1013 PUT_SDB_ENDEF;
1016 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1018 /* Machinery to record and output anonymous types. */
1020 static tree anonymous_types;
1022 static void
1023 sdbout_queue_anonymous_type (type)
1024 tree type;
1026 anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
1029 static void
1030 sdbout_dequeue_anonymous_types ()
1032 register tree types, link;
1034 while (anonymous_types)
1036 types = nreverse (anonymous_types);
1037 anonymous_types = NULL_TREE;
1039 for (link = types; link; link = TREE_CHAIN (link))
1041 register tree type = TREE_VALUE (link);
1043 if (type && ! TREE_ASM_WRITTEN (type))
1044 sdbout_one_type (type);
1049 #endif
1051 /* Given a chain of ..._TYPE nodes, all of which have names,
1052 output definitions of those names, as typedefs. */
1054 void
1055 sdbout_types (types)
1056 register tree types;
1058 register tree link;
1060 for (link = types; link; link = TREE_CHAIN (link))
1061 sdbout_one_type (link);
1063 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1064 sdbout_dequeue_anonymous_types ();
1065 #endif
1068 static void
1069 sdbout_type (type)
1070 tree type;
1072 if (type == error_mark_node)
1073 type = integer_type_node;
1074 PUT_SDB_TYPE (plain_type (type));
1077 /* Output types of the fields of type TYPE, if they are structs.
1079 Formerly did not chase through pointer types, since that could be circular.
1080 They must come before TYPE, since forward refs are not allowed.
1081 Now james@bigtex.cactus.org says to try them. */
1083 static void
1084 sdbout_field_types (type)
1085 tree type;
1087 tree tail;
1089 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1090 /* This condition should match the one for emitting the actual members
1091 below. */
1092 if (TREE_CODE (tail) == FIELD_DECL
1093 && DECL_NAME (tail) != 0
1094 && ! host_integerp (DECL_SIZE (tail), 1)
1095 && ! host_integerp (bit_position (tail), 0))
1097 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1098 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1099 else
1100 sdbout_one_type (TREE_TYPE (tail));
1104 /* Use this to put out the top level defined record and union types
1105 for later reference. If this is a struct with a name, then put that
1106 name out. Other unnamed structs will have .xxfake labels generated so
1107 that they may be referred to later.
1108 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1109 It may NOT be called recursively. */
1111 static void
1112 sdbout_one_type (type)
1113 tree type;
1115 if (current_function_decl != NULL_TREE
1116 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1117 ; /* Don't change section amid function. */
1118 else
1119 text_section ();
1121 switch (TREE_CODE (type))
1123 case RECORD_TYPE:
1124 case UNION_TYPE:
1125 case QUAL_UNION_TYPE:
1126 case ENUMERAL_TYPE:
1127 type = TYPE_MAIN_VARIANT (type);
1128 /* Don't output a type twice. */
1129 if (TREE_ASM_WRITTEN (type))
1130 /* James said test TREE_ASM_BEING_WRITTEN here. */
1131 return;
1133 /* Output nothing if type is not yet defined. */
1134 if (!COMPLETE_TYPE_P (type))
1135 return;
1137 TREE_ASM_WRITTEN (type) = 1;
1138 #if 1
1139 /* This is reputed to cause trouble with the following case,
1140 but perhaps checking TYPE_SIZE above will fix it. */
1142 /* Here is a test case:
1144 struct foo {
1145 struct badstr *bbb;
1146 } forwardref;
1148 typedef struct intermediate {
1149 int aaaa;
1150 } intermediate_ref;
1152 typedef struct badstr {
1153 int ccccc;
1154 } badtype; */
1156 #if 0
1157 TREE_ASM_BEING_WRITTEN (type) = 1;
1158 #endif
1159 /* This change, which ought to make better output,
1160 used to make the COFF assembler unhappy.
1161 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1162 /* Before really doing anything, output types we want to refer to. */
1163 /* Note that in version 1 the following two lines
1164 are not used if forward references are in use. */
1165 if (TREE_CODE (type) != ENUMERAL_TYPE)
1166 sdbout_field_types (type);
1167 #if 0
1168 TREE_ASM_WRITTEN (type) = 1;
1169 #endif
1170 #endif
1172 /* Output a structure type. */
1174 int size = int_size_in_bytes (type);
1175 int member_scl = 0;
1176 tree tem;
1177 int i, n_baseclasses = 0;
1179 /* Record the type tag, but not in its permanent place just yet. */
1180 sdbout_record_type_name (type);
1182 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1184 switch (TREE_CODE (type))
1186 case UNION_TYPE:
1187 case QUAL_UNION_TYPE:
1188 PUT_SDB_SCL (C_UNTAG);
1189 PUT_SDB_TYPE (T_UNION);
1190 member_scl = C_MOU;
1191 break;
1193 case RECORD_TYPE:
1194 PUT_SDB_SCL (C_STRTAG);
1195 PUT_SDB_TYPE (T_STRUCT);
1196 member_scl = C_MOS;
1197 break;
1199 case ENUMERAL_TYPE:
1200 PUT_SDB_SCL (C_ENTAG);
1201 PUT_SDB_TYPE (T_ENUM);
1202 member_scl = C_MOE;
1203 break;
1205 default:
1206 break;
1209 PUT_SDB_SIZE (size);
1210 PUT_SDB_ENDEF;
1212 /* Print out the base class information with fields
1213 named after the types they hold. */
1214 /* This is only relevent to aggregate types. TYPE_BINFO is used
1215 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1216 case. */
1217 if (TREE_CODE (type) != ENUMERAL_TYPE)
1219 if (TYPE_BINFO (type)
1220 && TYPE_BINFO_BASETYPES (type))
1221 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1222 for (i = 0; i < n_baseclasses; i++)
1224 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)),
1226 tree child_type = BINFO_TYPE (child);
1227 tree child_type_name;
1228 if (TYPE_NAME (child_type) == 0)
1229 continue;
1230 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1231 child_type_name = TYPE_NAME (child_type);
1232 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1234 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1235 if (child_type_name && template_name_p (child_type_name))
1236 child_type_name
1237 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1239 else
1240 continue;
1242 CONTIN;
1243 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1244 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1245 PUT_SDB_SCL (member_scl);
1246 sdbout_type (BINFO_TYPE (child));
1247 PUT_SDB_ENDEF;
1251 /* output the individual fields */
1253 if (TREE_CODE (type) == ENUMERAL_TYPE)
1255 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1256 if (host_integerp (TREE_VALUE (tem), 0))
1258 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1259 PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem), 0));
1260 PUT_SDB_SCL (C_MOE);
1261 PUT_SDB_TYPE (T_MOE);
1262 PUT_SDB_ENDEF;
1265 else /* record or union type */
1266 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1267 /* Output the name, type, position (in bits), size (in bits)
1268 of each field. */
1270 /* Omit here the nameless fields that are used to skip bits.
1271 Also omit fields with variable size or position.
1272 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1273 if (TREE_CODE (tem) == FIELD_DECL
1274 && DECL_NAME (tem) != 0
1275 && host_integerp (DECL_SIZE (tem), 1)
1276 && host_integerp (bit_position (tem), 0))
1278 char *name;
1280 CONTIN;
1281 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
1282 PUT_SDB_DEF (name);
1283 if (DECL_BIT_FIELD_TYPE (tem))
1285 PUT_SDB_INT_VAL (int_bit_position (tem));
1286 PUT_SDB_SCL (C_FIELD);
1287 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1288 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1290 else
1292 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1293 PUT_SDB_SCL (member_scl);
1294 sdbout_type (TREE_TYPE (tem));
1296 PUT_SDB_ENDEF;
1298 /* output end of a structure,union, or enumeral definition */
1300 PUT_SDB_PLAIN_DEF ("eos");
1301 PUT_SDB_INT_VAL (size);
1302 PUT_SDB_SCL (C_EOS);
1303 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1304 PUT_SDB_SIZE (size);
1305 PUT_SDB_ENDEF;
1306 break;
1308 default:
1309 break;
1314 /* The following two functions output definitions of function parameters.
1315 Each parameter gets a definition locating it in the parameter list.
1316 Each parameter that is a register variable gets a second definition
1317 locating it in the register.
1319 Printing or argument lists in gdb uses the definitions that
1320 locate in the parameter list. But reference to the variable in
1321 expressions uses preferentially the definition as a register. */
1323 /* Output definitions, referring to storage in the parmlist,
1324 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1326 static void
1327 sdbout_parms (parms)
1328 tree parms;
1330 for (; parms; parms = TREE_CHAIN (parms))
1331 if (DECL_NAME (parms))
1333 int current_sym_value = 0;
1334 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1336 if (name == 0 || *name == 0)
1337 name = gen_fake_label ();
1339 /* Perform any necessary register eliminations on the parameter's rtl,
1340 so that the debugging output will be accurate. */
1341 DECL_INCOMING_RTL (parms)
1342 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1343 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1345 if (PARM_PASSED_IN_MEMORY (parms))
1347 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1348 tree type;
1350 /* ??? Here we assume that the parm address is indexed
1351 off the frame pointer or arg pointer.
1352 If that is not true, we produce meaningless results,
1353 but do not crash. */
1354 if (GET_CODE (addr) == PLUS
1355 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1356 current_sym_value = INTVAL (XEXP (addr, 1));
1357 else
1358 current_sym_value = 0;
1360 if (GET_CODE (DECL_RTL (parms)) == REG
1361 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1362 type = DECL_ARG_TYPE (parms);
1363 else
1365 int original_sym_value = current_sym_value;
1367 /* This is the case where the parm is passed as an int or
1368 double and it is converted to a char, short or float
1369 and stored back in the parmlist. In this case, describe
1370 the parm with the variable's declared type, and adjust
1371 the address if the least significant bytes (which we are
1372 using) are not the first ones. */
1373 if (BYTES_BIG_ENDIAN
1374 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1375 current_sym_value +=
1376 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1377 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1379 if (GET_CODE (DECL_RTL (parms)) == MEM
1380 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1381 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1382 == CONST_INT)
1383 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1384 == current_sym_value))
1385 type = TREE_TYPE (parms);
1386 else
1388 current_sym_value = original_sym_value;
1389 type = DECL_ARG_TYPE (parms);
1393 PUT_SDB_DEF (name);
1394 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1395 PUT_SDB_SCL (C_ARG);
1396 PUT_SDB_TYPE (plain_type (type));
1397 PUT_SDB_ENDEF;
1399 else if (GET_CODE (DECL_RTL (parms)) == REG)
1401 rtx best_rtl;
1402 /* Parm passed in registers and lives in registers or nowhere. */
1404 /* If parm lives in a register, use that register;
1405 pretend the parm was passed there. It would be more consistent
1406 to describe the register where the parm was passed,
1407 but in practice that register usually holds something else. */
1408 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1409 best_rtl = DECL_RTL (parms);
1410 /* If the parm lives nowhere,
1411 use the register where it was passed. */
1412 else
1413 best_rtl = DECL_INCOMING_RTL (parms);
1415 PUT_SDB_DEF (name);
1416 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1417 PUT_SDB_SCL (C_REGPARM);
1418 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1419 PUT_SDB_ENDEF;
1421 else if (GET_CODE (DECL_RTL (parms)) == MEM
1422 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1424 /* Parm was passed in registers but lives on the stack. */
1426 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1427 in which case we want the value of that CONST_INT,
1428 or (MEM (REG ...)) or (MEM (MEM ...)),
1429 in which case we use a value of zero. */
1430 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1431 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1432 current_sym_value = 0;
1433 else
1434 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1436 /* Again, this assumes the offset is based on the arg pointer. */
1437 PUT_SDB_DEF (name);
1438 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1439 XEXP (DECL_RTL (parms), 0)));
1440 PUT_SDB_SCL (C_ARG);
1441 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1442 PUT_SDB_ENDEF;
1447 /* Output definitions for the places where parms live during the function,
1448 when different from where they were passed, when the parms were passed
1449 in memory.
1451 It is not useful to do this for parms passed in registers
1452 that live during the function in different registers, because it is
1453 impossible to look in the passed register for the passed value,
1454 so we use the within-the-function register to begin with.
1456 PARMS is a chain of PARM_DECL nodes. */
1458 static void
1459 sdbout_reg_parms (parms)
1460 tree parms;
1462 for (; parms; parms = TREE_CHAIN (parms))
1463 if (DECL_NAME (parms))
1465 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1467 /* Report parms that live in registers during the function
1468 but were passed in memory. */
1469 if (GET_CODE (DECL_RTL (parms)) == REG
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 */