* config/arm/arm.c (is_load_address): Rename to... (arm_memory_load_p) ... this
[official-gcc.git] / gcc / sdbout.c
blob30565b3dca1fba31c181709e9ec29455167a0e27
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 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"
45 #include "system.h"
46 #include "coretypes.h"
47 #include "tm.h"
48 #include "debug.h"
49 #include "tree.h"
50 #include "ggc.h"
52 static GTY(()) tree anonymous_types;
54 #ifdef SDB_DEBUGGING_INFO
56 #include "rtl.h"
57 #include "regs.h"
58 #include "flags.h"
59 #include "insn-config.h"
60 #include "reload.h"
61 #include "output.h"
62 #include "toplev.h"
63 #include "tm_p.h"
64 #include "gsyms.h"
65 #include "langhooks.h"
66 #include "target.h"
68 /* 1 if PARM is passed to this function in memory. */
70 #define PARM_PASSED_IN_MEMORY(PARM) \
71 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
73 /* A C expression for the integer offset value of an automatic variable
74 (C_AUTO) having address X (an RTX). */
75 #ifndef DEBUGGER_AUTO_OFFSET
76 #define DEBUGGER_AUTO_OFFSET(X) \
77 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
78 #endif
80 /* A C expression for the integer offset value of an argument (C_ARG)
81 having address X (an RTX). The nominal offset is OFFSET. */
82 #ifndef DEBUGGER_ARG_OFFSET
83 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
84 #endif
86 /* Line number of beginning of current function, minus one.
87 Negative means not in a function or not using sdb. */
89 int sdb_begin_function_line = -1;
91 /* Counter to generate unique "names" for nameless struct members. */
93 static int unnamed_struct_number = 0;
95 extern FILE *asm_out_file;
97 extern tree current_function_decl;
99 #include "sdbout.h"
101 static void sdbout_init PARAMS ((const char *));
102 static void sdbout_finish PARAMS ((const char *));
103 static void sdbout_start_source_file PARAMS ((unsigned int, const char *));
104 static void sdbout_end_source_file PARAMS ((unsigned int));
105 static void sdbout_begin_block PARAMS ((unsigned int, unsigned int));
106 static void sdbout_end_block PARAMS ((unsigned int, unsigned int));
107 static void sdbout_source_line PARAMS ((unsigned int, const char *));
108 static void sdbout_end_epilogue PARAMS ((unsigned int, const char *));
109 static void sdbout_global_decl PARAMS ((tree));
110 #ifndef MIPS_DEBUGGING_INFO
111 static void sdbout_begin_prologue PARAMS ((unsigned int, const char *));
112 #endif
113 static void sdbout_end_prologue PARAMS ((unsigned int, const char *));
114 static void sdbout_begin_function PARAMS ((tree));
115 static void sdbout_end_function PARAMS ((unsigned int));
116 static void sdbout_toplevel_data PARAMS ((tree));
117 static void sdbout_label PARAMS ((rtx));
118 static char *gen_fake_label PARAMS ((void));
119 static int plain_type PARAMS ((tree));
120 static int template_name_p PARAMS ((tree));
121 static void sdbout_record_type_name PARAMS ((tree));
122 static int plain_type_1 PARAMS ((tree, int));
123 static void sdbout_block PARAMS ((tree));
124 static void sdbout_syms PARAMS ((tree));
125 #ifdef SDB_ALLOW_FORWARD_REFERENCES
126 static void sdbout_queue_anonymous_type PARAMS ((tree));
127 static void sdbout_dequeue_anonymous_types PARAMS ((void));
128 #endif
129 static void sdbout_type PARAMS ((tree));
130 static void sdbout_field_types PARAMS ((tree));
131 static void sdbout_one_type PARAMS ((tree));
132 static void sdbout_parms PARAMS ((tree));
133 static void sdbout_reg_parms PARAMS ((tree));
134 static void sdbout_global_decl PARAMS ((tree));
136 /* Random macros describing parts of SDB data. */
138 /* Put something here if lines get too long */
139 #define CONTIN
141 /* Default value of delimiter is ";". */
142 #ifndef SDB_DELIM
143 #define SDB_DELIM ";"
144 #endif
146 /* Maximum number of dimensions the assembler will allow. */
147 #ifndef SDB_MAX_DIM
148 #define SDB_MAX_DIM 4
149 #endif
151 #ifndef PUT_SDB_SCL
152 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
153 #endif
155 #ifndef PUT_SDB_INT_VAL
156 #define PUT_SDB_INT_VAL(a) \
157 do { \
158 fputs ("\t.val\t", asm_out_file); \
159 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) (a)); \
160 fprintf (asm_out_file, "%s", SDB_DELIM); \
161 } while (0)
163 #endif
165 #ifndef PUT_SDB_VAL
166 #define PUT_SDB_VAL(a) \
167 ( fputs ("\t.val\t", asm_out_file), \
168 output_addr_const (asm_out_file, (a)), \
169 fprintf (asm_out_file, SDB_DELIM))
170 #endif
172 #ifndef PUT_SDB_DEF
173 #define PUT_SDB_DEF(a) \
174 do { fprintf (asm_out_file, "\t.def\t"); \
175 assemble_name (asm_out_file, a); \
176 fprintf (asm_out_file, SDB_DELIM); } while (0)
177 #endif
179 #ifndef PUT_SDB_PLAIN_DEF
180 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
181 #endif
183 #ifndef PUT_SDB_ENDEF
184 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
185 #endif
187 #ifndef PUT_SDB_TYPE
188 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
189 #endif
191 #ifndef PUT_SDB_SIZE
192 #define PUT_SDB_SIZE(a) \
193 do { \
194 fputs ("\t.size\t", asm_out_file); \
195 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) (a)); \
196 fprintf (asm_out_file, "%s", SDB_DELIM); \
197 } while(0)
198 #endif
200 #ifndef PUT_SDB_START_DIM
201 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
202 #endif
204 #ifndef PUT_SDB_NEXT_DIM
205 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
206 #endif
208 #ifndef PUT_SDB_LAST_DIM
209 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
210 #endif
212 #ifndef PUT_SDB_TAG
213 #define PUT_SDB_TAG(a) \
214 do { fprintf (asm_out_file, "\t.tag\t"); \
215 assemble_name (asm_out_file, a); \
216 fprintf (asm_out_file, SDB_DELIM); } while (0)
217 #endif
219 #ifndef PUT_SDB_BLOCK_START
220 #define PUT_SDB_BLOCK_START(LINE) \
221 fprintf (asm_out_file, \
222 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
223 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
224 #endif
226 #ifndef PUT_SDB_BLOCK_END
227 #define PUT_SDB_BLOCK_END(LINE) \
228 fprintf (asm_out_file, \
229 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
230 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
231 #endif
233 #ifndef PUT_SDB_FUNCTION_START
234 #define PUT_SDB_FUNCTION_START(LINE) \
235 fprintf (asm_out_file, \
236 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
237 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
238 #endif
240 #ifndef PUT_SDB_FUNCTION_END
241 #define PUT_SDB_FUNCTION_END(LINE) \
242 fprintf (asm_out_file, \
243 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
244 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
245 #endif
247 #ifndef SDB_GENERATE_FAKE
248 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
249 sprintf ((BUFFER), ".%dfake", (NUMBER));
250 #endif
252 /* Return the sdb tag identifier string for TYPE
253 if TYPE has already been defined; otherwise return a null pointer. */
255 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
257 /* Set the sdb tag identifier string for TYPE to NAME. */
259 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
260 TYPE_SYMTAB_POINTER (TYPE) = (char *)(NAME)
262 /* Return the name (a string) of the struct, union or enum tag
263 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
265 #define TAG_NAME(link) \
266 (((link) && TREE_PURPOSE ((link)) \
267 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
268 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
270 /* Ensure we don't output a negative line number. */
271 #define MAKE_LINE_SAFE(line) \
272 if ((int) line <= sdb_begin_function_line) \
273 line = sdb_begin_function_line + 1
275 /* Perform linker optimization of merging header file definitions together
276 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
277 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
278 the optimization just won't be done. The native assembler already has the
279 necessary support. */
281 #ifdef MIPS_DEBUGGING_INFO
283 #ifndef PUT_SDB_SRC_FILE
284 #define PUT_SDB_SRC_FILE(FILENAME) \
285 output_file_directive (asm_out_file, (FILENAME))
286 #endif
288 /* ECOFF linkers have an optimization that does the same kind of thing as
289 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
290 executable. To achieve this, GCC must output a .file for each file
291 name change. */
293 /* This is a stack of input files. */
295 struct sdb_file
297 struct sdb_file *next;
298 const char *name;
301 /* This is the top of the stack. */
303 static struct sdb_file *current_file;
305 #endif /* MIPS_DEBUGGING_INFO */
307 /* The debug hooks structure. */
308 const struct gcc_debug_hooks sdb_debug_hooks =
310 sdbout_init, /* init */
311 sdbout_finish, /* finish */
312 debug_nothing_int_charstar, /* define */
313 debug_nothing_int_charstar, /* undef */
314 sdbout_start_source_file, /* start_source_file */
315 sdbout_end_source_file, /* end_source_file */
316 sdbout_begin_block, /* begin_block */
317 sdbout_end_block, /* end_block */
318 debug_true_tree, /* ignore_block */
319 sdbout_source_line, /* source_line */
320 #ifdef MIPS_DEBUGGING_INFO
321 /* Defer on MIPS systems so that parameter descriptions follow
322 function entry. */
323 debug_nothing_int_charstar, /* begin_prologue */
324 sdbout_end_prologue, /* end_prologue */
325 #else
326 sdbout_begin_prologue, /* begin_prologue */
327 debug_nothing_int_charstar, /* end_prologue */
328 #endif
329 sdbout_end_epilogue, /* end_epilogue */
330 sdbout_begin_function, /* begin_function */
331 sdbout_end_function, /* end_function */
332 debug_nothing_tree, /* function_decl */
333 sdbout_global_decl, /* global_decl */
334 debug_nothing_tree, /* deferred_inline_function */
335 debug_nothing_tree, /* outlining_inline_function */
336 sdbout_label
339 #if 0
341 /* return the tag identifier for type
344 char *
345 tag_of_ru_type (type,link)
346 tree type,link;
348 if (TYPE_SYMTAB_ADDRESS (type))
349 return TYPE_SYMTAB_ADDRESS (type);
350 if (link && TREE_PURPOSE (link)
351 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
352 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
353 else
354 return (char *) TYPE_SYMTAB_ADDRESS (type);
356 #endif
358 /* Return a unique string to name an anonymous type. */
360 static char *
361 gen_fake_label ()
363 char label[10];
364 char *labelstr;
365 SDB_GENERATE_FAKE (label, unnamed_struct_number);
366 unnamed_struct_number++;
367 labelstr = xstrdup (label);
368 return labelstr;
371 /* Return the number which describes TYPE for SDB.
372 For pointers, etc., this function is recursive.
373 Each record, union or enumeral type must already have had a
374 tag number output. */
376 /* The number is given by d6d5d4d3d2d1bbbb
377 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
378 Thus, char *foo () has bbbb=T_CHAR
379 d1=D_FCN
380 d2=D_PTR
381 N_BTMASK= 017 1111 basic type field.
382 N_TSHIFT= 2 derived type shift
383 N_BTSHFT= 4 Basic type shift */
385 /* Produce the number that describes a pointer, function or array type.
386 PREV is the number describing the target, value or element type.
387 DT_type describes how to transform that type. */
388 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
389 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
390 | ((int) DT_type << (int) N_BTSHFT) \
391 | ((PREV) & (int) N_BTMASK))
393 /* Number of elements used in sdb_dims. */
394 static int sdb_n_dims = 0;
396 /* Table of array dimensions of current type. */
397 static int sdb_dims[SDB_MAX_DIM];
399 /* Size of outermost array currently being processed. */
400 static int sdb_type_size = -1;
402 static int
403 plain_type (type)
404 tree type;
406 int val = plain_type_1 (type, 0);
408 /* If we have already saved up some array dimensions, print them now. */
409 if (sdb_n_dims > 0)
411 int i;
412 PUT_SDB_START_DIM;
413 for (i = sdb_n_dims - 1; i > 0; i--)
414 PUT_SDB_NEXT_DIM (sdb_dims[i]);
415 PUT_SDB_LAST_DIM (sdb_dims[0]);
416 sdb_n_dims = 0;
418 sdb_type_size = int_size_in_bytes (type);
419 /* Don't kill sdb if type is not laid out or has variable size. */
420 if (sdb_type_size < 0)
421 sdb_type_size = 0;
423 /* If we have computed the size of an array containing this type,
424 print it now. */
425 if (sdb_type_size >= 0)
427 PUT_SDB_SIZE (sdb_type_size);
428 sdb_type_size = -1;
430 return val;
433 static int
434 template_name_p (name)
435 tree name;
437 const char *ptr = IDENTIFIER_POINTER (name);
438 while (*ptr && *ptr != '<')
439 ptr++;
441 return *ptr != '\0';
444 static void
445 sdbout_record_type_name (type)
446 tree type;
448 const char *name = 0;
449 int no_name;
451 if (KNOWN_TYPE_TAG (type))
452 return;
454 if (TYPE_NAME (type) != 0)
456 tree t = 0;
458 /* Find the IDENTIFIER_NODE for the type name. */
459 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
460 t = TYPE_NAME (type);
461 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
463 t = DECL_NAME (TYPE_NAME (type));
464 /* The DECL_NAME for templates includes "<>", which breaks
465 most assemblers. Use its assembler name instead, which
466 has been mangled into being safe. */
467 if (t && template_name_p (t))
468 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
471 /* Now get the name as a string, or invent one. */
472 if (t != NULL_TREE)
473 name = IDENTIFIER_POINTER (t);
476 no_name = (name == 0 || *name == 0);
477 if (no_name)
478 name = gen_fake_label ();
480 SET_KNOWN_TYPE_TAG (type, name);
481 #ifdef SDB_ALLOW_FORWARD_REFERENCES
482 if (no_name)
483 sdbout_queue_anonymous_type (type);
484 #endif
487 /* Return the .type value for type TYPE.
489 LEVEL indicates how many levels deep we have recursed into the type.
490 The SDB debug format can only represent 6 derived levels of types.
491 After that, we must output inaccurate debug info. We deliberately
492 stop before the 7th level, so that ADA recursive types will not give an
493 infinite loop. */
495 static int
496 plain_type_1 (type, level)
497 tree type;
498 int level;
500 if (type == 0)
501 type = void_type_node;
502 else if (type == error_mark_node)
503 type = integer_type_node;
504 else
505 type = TYPE_MAIN_VARIANT (type);
507 switch (TREE_CODE (type))
509 case VOID_TYPE:
510 return T_VOID;
511 case BOOLEAN_TYPE:
512 case INTEGER_TYPE:
514 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
516 /* Carefully distinguish all the standard types of C,
517 without messing up if the language is not C.
518 Note that we check only for the names that contain spaces;
519 other names might occur by coincidence in other languages. */
520 if (TYPE_NAME (type) != 0
521 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
522 && DECL_NAME (TYPE_NAME (type)) != 0
523 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
525 const char *const name
526 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
528 if (!strcmp (name, "char"))
529 return T_CHAR;
530 if (!strcmp (name, "unsigned char"))
531 return T_UCHAR;
532 if (!strcmp (name, "signed char"))
533 return T_CHAR;
534 if (!strcmp (name, "int"))
535 return T_INT;
536 if (!strcmp (name, "unsigned int"))
537 return T_UINT;
538 if (!strcmp (name, "short int"))
539 return T_SHORT;
540 if (!strcmp (name, "short unsigned int"))
541 return T_USHORT;
542 if (!strcmp (name, "long int"))
543 return T_LONG;
544 if (!strcmp (name, "long unsigned int"))
545 return T_ULONG;
548 if (size == INT_TYPE_SIZE)
549 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
550 if (size == CHAR_TYPE_SIZE)
551 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
552 if (size == SHORT_TYPE_SIZE)
553 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
554 if (size == LONG_TYPE_SIZE)
555 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
556 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
557 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
558 return 0;
561 case REAL_TYPE:
563 int precision = TYPE_PRECISION (type);
564 if (precision == FLOAT_TYPE_SIZE)
565 return T_FLOAT;
566 if (precision == DOUBLE_TYPE_SIZE)
567 return T_DOUBLE;
568 #ifdef EXTENDED_SDB_BASIC_TYPES
569 if (precision == LONG_DOUBLE_TYPE_SIZE)
570 return T_LNGDBL;
571 #else
572 if (precision == LONG_DOUBLE_TYPE_SIZE)
573 return T_DOUBLE; /* better than nothing */
574 #endif
575 return 0;
578 case ARRAY_TYPE:
580 int m;
581 if (level >= 6)
582 return T_VOID;
583 else
584 m = plain_type_1 (TREE_TYPE (type), level+1);
585 if (sdb_n_dims < SDB_MAX_DIM)
586 sdb_dims[sdb_n_dims++]
587 = (TYPE_DOMAIN (type)
588 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
589 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
590 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
591 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
592 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
593 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
594 : 0);
596 return PUSH_DERIVED_LEVEL (DT_ARY, m);
599 case RECORD_TYPE:
600 case UNION_TYPE:
601 case QUAL_UNION_TYPE:
602 case ENUMERAL_TYPE:
604 char *tag;
605 #ifdef SDB_ALLOW_FORWARD_REFERENCES
606 sdbout_record_type_name (type);
607 #endif
608 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
609 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
610 #ifdef SDB_ALLOW_FORWARD_REFERENCES
611 || TYPE_MODE (type) != VOIDmode
612 #endif
614 #endif
616 /* Output the referenced structure tag name
617 only if the .def has already been finished.
618 At least on 386, the Unix assembler
619 cannot handle forward references to tags. */
620 /* But the 88100, it requires them, sigh... */
621 /* And the MIPS requires unknown refs as well... */
622 tag = KNOWN_TYPE_TAG (type);
623 PUT_SDB_TAG (tag);
624 /* These 3 lines used to follow the close brace.
625 However, a size of 0 without a tag implies a tag of 0,
626 so if we don't know a tag, we can't mention the size. */
627 sdb_type_size = int_size_in_bytes (type);
628 if (sdb_type_size < 0)
629 sdb_type_size = 0;
631 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
632 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
633 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
634 : T_ENUM);
636 case POINTER_TYPE:
637 case REFERENCE_TYPE:
639 int m;
640 if (level >= 6)
641 return T_VOID;
642 else
643 m = plain_type_1 (TREE_TYPE (type), level+1);
644 return PUSH_DERIVED_LEVEL (DT_PTR, m);
646 case FUNCTION_TYPE:
647 case METHOD_TYPE:
649 int m;
650 if (level >= 6)
651 return T_VOID;
652 else
653 m = plain_type_1 (TREE_TYPE (type), level+1);
654 return PUSH_DERIVED_LEVEL (DT_FCN, m);
656 default:
657 return 0;
661 /* Output the symbols defined in block number DO_BLOCK.
663 This function works by walking the tree structure of blocks,
664 counting blocks until it finds the desired block. */
666 static int do_block = 0;
668 static void
669 sdbout_block (block)
670 tree block;
672 while (block)
674 /* Ignore blocks never expanded or otherwise marked as real. */
675 if (TREE_USED (block))
677 /* When we reach the specified block, output its symbols. */
678 if (BLOCK_NUMBER (block) == do_block)
679 sdbout_syms (BLOCK_VARS (block));
681 /* If we are past the specified block, stop the scan. */
682 if (BLOCK_NUMBER (block) > do_block)
683 return;
685 /* Scan the blocks within this block. */
686 sdbout_block (BLOCK_SUBBLOCKS (block));
689 block = BLOCK_CHAIN (block);
693 /* Call sdbout_symbol on each decl in the chain SYMS. */
695 static void
696 sdbout_syms (syms)
697 tree syms;
699 while (syms)
701 if (TREE_CODE (syms) != LABEL_DECL)
702 sdbout_symbol (syms, 1);
703 syms = TREE_CHAIN (syms);
707 /* Output SDB information for a symbol described by DECL.
708 LOCAL is nonzero if the symbol is not file-scope. */
710 void
711 sdbout_symbol (decl, local)
712 tree decl;
713 int local;
715 tree type = TREE_TYPE (decl);
716 tree context = NULL_TREE;
717 rtx value;
718 int regno = -1;
719 const char *name;
721 sdbout_one_type (type);
723 #if 0 /* This loses when functions are marked to be ignored,
724 which happens in the C++ front end. */
725 if (DECL_IGNORED_P (decl))
726 return;
727 #endif
729 switch (TREE_CODE (decl))
731 case CONST_DECL:
732 /* Enum values are defined by defining the enum type. */
733 return;
735 case FUNCTION_DECL:
736 /* Don't mention a nested function under its parent. */
737 context = decl_function_context (decl);
738 if (context == current_function_decl)
739 return;
740 /* Check DECL_INITIAL to distinguish declarations from definitions.
741 Don't output debug info here for declarations; they will have
742 a DECL_INITIAL value of 0. */
743 if (! DECL_INITIAL (decl))
744 return;
745 if (GET_CODE (DECL_RTL (decl)) != MEM
746 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
747 return;
748 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
749 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
750 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
751 break;
753 case TYPE_DECL:
754 /* Done with tagged types. */
755 if (DECL_NAME (decl) == 0)
756 return;
757 if (DECL_IGNORED_P (decl))
758 return;
760 /* Output typedef name. */
761 if (template_name_p (DECL_NAME (decl)))
762 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
763 else
764 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
765 PUT_SDB_SCL (C_TPDEF);
766 break;
768 case PARM_DECL:
769 /* Parm decls go in their own separate chains
770 and are output by sdbout_reg_parms and sdbout_parms. */
771 abort ();
773 case VAR_DECL:
774 /* Don't mention a variable that is external.
775 Let the file that defines it describe it. */
776 if (DECL_EXTERNAL (decl))
777 return;
779 /* Ignore __FUNCTION__, etc. */
780 if (DECL_IGNORED_P (decl))
781 return;
783 /* If there was an error in the declaration, don't dump core
784 if there is no RTL associated with the variable doesn't
785 exist. */
786 if (!DECL_RTL_SET_P (decl))
787 return;
789 SET_DECL_RTL (decl,
790 eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
791 #ifdef LEAF_REG_REMAP
792 if (current_function_uses_only_leaf_regs)
793 leaf_renumber_regs_insn (DECL_RTL (decl));
794 #endif
795 value = DECL_RTL (decl);
797 /* Don't mention a variable at all
798 if it was completely optimized into nothingness.
800 If DECL was from an inline function, then its rtl
801 is not identically the rtl that was used in this
802 particular compilation. */
803 if (GET_CODE (value) == REG)
805 regno = REGNO (value);
806 if (regno >= FIRST_PSEUDO_REGISTER)
807 return;
809 else if (GET_CODE (value) == SUBREG)
811 while (GET_CODE (value) == SUBREG)
812 value = SUBREG_REG (value);
813 if (GET_CODE (value) == REG)
815 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
816 return;
818 regno = REGNO (alter_subreg (&value));
819 SET_DECL_RTL (decl, value);
821 /* Don't output anything if an auto variable
822 gets RTL that is static.
823 GAS version 2.2 can't handle such output. */
824 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
825 && ! TREE_STATIC (decl))
826 return;
828 /* Emit any structure, union, or enum type that has not been output.
829 This occurs for tag-less structs (et al) used to declare variables
830 within functions. */
831 if (TREE_CODE (type) == ENUMERAL_TYPE
832 || TREE_CODE (type) == RECORD_TYPE
833 || TREE_CODE (type) == UNION_TYPE
834 || TREE_CODE (type) == QUAL_UNION_TYPE)
836 if (COMPLETE_TYPE_P (type) /* not a forward reference */
837 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
838 sdbout_one_type (type);
841 /* Defer SDB information for top-level initialized variables! */
842 if (! local
843 && GET_CODE (value) == MEM
844 && DECL_INITIAL (decl))
845 return;
847 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
848 For now, avoid crashing. */
849 if (DECL_NAME (decl) == NULL_TREE)
850 return;
852 /* Record the name for, starting a symtab entry. */
853 if (local)
854 name = IDENTIFIER_POINTER (DECL_NAME (decl));
855 else
856 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
858 if (GET_CODE (value) == MEM
859 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
861 PUT_SDB_DEF (name);
862 if (TREE_PUBLIC (decl))
864 PUT_SDB_VAL (XEXP (value, 0));
865 PUT_SDB_SCL (C_EXT);
867 else
869 PUT_SDB_VAL (XEXP (value, 0));
870 PUT_SDB_SCL (C_STAT);
873 else if (regno >= 0)
875 PUT_SDB_DEF (name);
876 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
877 PUT_SDB_SCL (C_REG);
879 else if (GET_CODE (value) == MEM
880 && (GET_CODE (XEXP (value, 0)) == MEM
881 || (GET_CODE (XEXP (value, 0)) == REG
882 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
883 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
884 /* If the value is indirect by memory or by a register
885 that isn't the frame pointer
886 then it means the object is variable-sized and address through
887 that register or stack slot. COFF has no way to represent this
888 so all we can do is output the variable as a pointer. */
890 PUT_SDB_DEF (name);
891 if (GET_CODE (XEXP (value, 0)) == REG)
893 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
894 PUT_SDB_SCL (C_REG);
896 else
898 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
899 (CONST_INT...)))).
900 We want the value of that CONST_INT. */
901 /* Encore compiler hates a newline in a macro arg, it seems. */
902 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
903 (XEXP (XEXP (value, 0), 0)));
904 PUT_SDB_SCL (C_AUTO);
907 /* Effectively do build_pointer_type, but don't cache this type,
908 since it might be temporary whereas the type it points to
909 might have been saved for inlining. */
910 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
911 type = make_node (POINTER_TYPE);
912 TREE_TYPE (type) = TREE_TYPE (decl);
914 else if (GET_CODE (value) == MEM
915 && ((GET_CODE (XEXP (value, 0)) == PLUS
916 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
917 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
918 /* This is for variables which are at offset zero from
919 the frame pointer. This happens on the Alpha.
920 Non-frame pointer registers are excluded above. */
921 || (GET_CODE (XEXP (value, 0)) == REG)))
923 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
924 or (MEM (REG...)). We want the value of that CONST_INT
925 or zero. */
926 PUT_SDB_DEF (name);
927 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
928 PUT_SDB_SCL (C_AUTO);
930 else
932 /* It is something we don't know how to represent for SDB. */
933 return;
935 break;
937 default:
938 break;
940 PUT_SDB_TYPE (plain_type (type));
941 PUT_SDB_ENDEF;
944 /* Output SDB information for a top-level initialized variable
945 that has been delayed. */
947 static void
948 sdbout_toplevel_data (decl)
949 tree decl;
951 tree type = TREE_TYPE (decl);
953 if (DECL_IGNORED_P (decl))
954 return;
956 if (! (TREE_CODE (decl) == VAR_DECL
957 && GET_CODE (DECL_RTL (decl)) == MEM
958 && DECL_INITIAL (decl)))
959 abort ();
961 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
962 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
963 if (TREE_PUBLIC (decl))
965 PUT_SDB_SCL (C_EXT);
967 else
969 PUT_SDB_SCL (C_STAT);
971 PUT_SDB_TYPE (plain_type (type));
972 PUT_SDB_ENDEF;
975 #ifdef SDB_ALLOW_FORWARD_REFERENCES
977 /* Machinery to record and output anonymous types. */
979 static void
980 sdbout_queue_anonymous_type (type)
981 tree type;
983 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
986 static void
987 sdbout_dequeue_anonymous_types ()
989 tree types, link;
991 while (anonymous_types)
993 types = nreverse (anonymous_types);
994 anonymous_types = NULL_TREE;
996 for (link = types; link; link = TREE_CHAIN (link))
998 tree type = TREE_VALUE (link);
1000 if (type && ! TREE_ASM_WRITTEN (type))
1001 sdbout_one_type (type);
1006 #endif
1008 /* Given a chain of ..._TYPE nodes, all of which have names,
1009 output definitions of those names, as typedefs. */
1011 void
1012 sdbout_types (types)
1013 tree types;
1015 tree link;
1017 for (link = types; link; link = TREE_CHAIN (link))
1018 sdbout_one_type (link);
1020 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1021 sdbout_dequeue_anonymous_types ();
1022 #endif
1025 static void
1026 sdbout_type (type)
1027 tree type;
1029 if (type == error_mark_node)
1030 type = integer_type_node;
1031 PUT_SDB_TYPE (plain_type (type));
1034 /* Output types of the fields of type TYPE, if they are structs.
1036 Formerly did not chase through pointer types, since that could be circular.
1037 They must come before TYPE, since forward refs are not allowed.
1038 Now james@bigtex.cactus.org says to try them. */
1040 static void
1041 sdbout_field_types (type)
1042 tree type;
1044 tree tail;
1046 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1047 /* This condition should match the one for emitting the actual
1048 members below. */
1049 if (TREE_CODE (tail) == FIELD_DECL
1050 && DECL_NAME (tail)
1051 && DECL_SIZE (tail)
1052 && host_integerp (DECL_SIZE (tail), 1)
1053 && host_integerp (bit_position (tail), 0))
1055 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1056 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1057 else
1058 sdbout_one_type (TREE_TYPE (tail));
1062 /* Use this to put out the top level defined record and union types
1063 for later reference. If this is a struct with a name, then put that
1064 name out. Other unnamed structs will have .xxfake labels generated so
1065 that they may be referred to later.
1066 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1067 It may NOT be called recursively. */
1069 static void
1070 sdbout_one_type (type)
1071 tree type;
1073 if (current_function_decl != NULL_TREE
1074 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1075 ; /* Don't change section amid function. */
1076 else
1077 text_section ();
1079 switch (TREE_CODE (type))
1081 case RECORD_TYPE:
1082 case UNION_TYPE:
1083 case QUAL_UNION_TYPE:
1084 case ENUMERAL_TYPE:
1085 type = TYPE_MAIN_VARIANT (type);
1086 /* Don't output a type twice. */
1087 if (TREE_ASM_WRITTEN (type))
1088 /* James said test TREE_ASM_BEING_WRITTEN here. */
1089 return;
1091 /* Output nothing if type is not yet defined. */
1092 if (!COMPLETE_TYPE_P (type))
1093 return;
1095 TREE_ASM_WRITTEN (type) = 1;
1096 #if 1
1097 /* This is reputed to cause trouble with the following case,
1098 but perhaps checking TYPE_SIZE above will fix it. */
1100 /* Here is a test case:
1102 struct foo {
1103 struct badstr *bbb;
1104 } forwardref;
1106 typedef struct intermediate {
1107 int aaaa;
1108 } intermediate_ref;
1110 typedef struct badstr {
1111 int ccccc;
1112 } badtype; */
1114 #if 0
1115 TREE_ASM_BEING_WRITTEN (type) = 1;
1116 #endif
1117 /* This change, which ought to make better output,
1118 used to make the COFF assembler unhappy.
1119 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1120 /* Before really doing anything, output types we want to refer to. */
1121 /* Note that in version 1 the following two lines
1122 are not used if forward references are in use. */
1123 if (TREE_CODE (type) != ENUMERAL_TYPE)
1124 sdbout_field_types (type);
1125 #if 0
1126 TREE_ASM_WRITTEN (type) = 1;
1127 #endif
1128 #endif
1130 /* Output a structure type. */
1132 int size = int_size_in_bytes (type);
1133 int member_scl = 0;
1134 tree tem;
1135 int i, n_baseclasses = 0;
1137 /* Record the type tag, but not in its permanent place just yet. */
1138 sdbout_record_type_name (type);
1140 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1142 switch (TREE_CODE (type))
1144 case UNION_TYPE:
1145 case QUAL_UNION_TYPE:
1146 PUT_SDB_SCL (C_UNTAG);
1147 PUT_SDB_TYPE (T_UNION);
1148 member_scl = C_MOU;
1149 break;
1151 case RECORD_TYPE:
1152 PUT_SDB_SCL (C_STRTAG);
1153 PUT_SDB_TYPE (T_STRUCT);
1154 member_scl = C_MOS;
1155 break;
1157 case ENUMERAL_TYPE:
1158 PUT_SDB_SCL (C_ENTAG);
1159 PUT_SDB_TYPE (T_ENUM);
1160 member_scl = C_MOE;
1161 break;
1163 default:
1164 break;
1167 PUT_SDB_SIZE (size);
1168 PUT_SDB_ENDEF;
1170 /* Print out the base class information with fields
1171 named after the types they hold. */
1172 /* This is only relevant to aggregate types. TYPE_BINFO is used
1173 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1174 case. */
1175 if (TREE_CODE (type) != ENUMERAL_TYPE)
1177 if (TYPE_BINFO (type)
1178 && TYPE_BINFO_BASETYPES (type))
1179 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1180 for (i = 0; i < n_baseclasses; i++)
1182 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)),
1184 tree child_type = BINFO_TYPE (child);
1185 tree child_type_name;
1186 if (TYPE_NAME (child_type) == 0)
1187 continue;
1188 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1189 child_type_name = TYPE_NAME (child_type);
1190 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1192 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1193 if (child_type_name && template_name_p (child_type_name))
1194 child_type_name
1195 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1197 else
1198 continue;
1200 CONTIN;
1201 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1202 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1203 PUT_SDB_SCL (member_scl);
1204 sdbout_type (BINFO_TYPE (child));
1205 PUT_SDB_ENDEF;
1209 /* output the individual fields */
1211 if (TREE_CODE (type) == ENUMERAL_TYPE)
1213 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1214 if (host_integerp (TREE_VALUE (tem), 0))
1216 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1217 PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem), 0));
1218 PUT_SDB_SCL (C_MOE);
1219 PUT_SDB_TYPE (T_MOE);
1220 PUT_SDB_ENDEF;
1223 else /* record or union type */
1224 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1225 /* Output the name, type, position (in bits), size (in bits)
1226 of each field. */
1228 /* Omit here the nameless fields that are used to skip bits.
1229 Also omit fields with variable size or position.
1230 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1231 if (TREE_CODE (tem) == FIELD_DECL
1232 && DECL_NAME (tem)
1233 && DECL_SIZE (tem)
1234 && host_integerp (DECL_SIZE (tem), 1)
1235 && host_integerp (bit_position (tem), 0))
1237 const char *name;
1239 CONTIN;
1240 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1241 PUT_SDB_DEF (name);
1242 if (DECL_BIT_FIELD_TYPE (tem))
1244 PUT_SDB_INT_VAL (int_bit_position (tem));
1245 PUT_SDB_SCL (C_FIELD);
1246 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1247 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1249 else
1251 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1252 PUT_SDB_SCL (member_scl);
1253 sdbout_type (TREE_TYPE (tem));
1255 PUT_SDB_ENDEF;
1257 /* output end of a structure,union, or enumeral definition */
1259 PUT_SDB_PLAIN_DEF ("eos");
1260 PUT_SDB_INT_VAL (size);
1261 PUT_SDB_SCL (C_EOS);
1262 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1263 PUT_SDB_SIZE (size);
1264 PUT_SDB_ENDEF;
1265 break;
1267 default:
1268 break;
1273 /* The following two functions output definitions of function parameters.
1274 Each parameter gets a definition locating it in the parameter list.
1275 Each parameter that is a register variable gets a second definition
1276 locating it in the register.
1278 Printing or argument lists in gdb uses the definitions that
1279 locate in the parameter list. But reference to the variable in
1280 expressions uses preferentially the definition as a register. */
1282 /* Output definitions, referring to storage in the parmlist,
1283 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1285 static void
1286 sdbout_parms (parms)
1287 tree parms;
1289 for (; parms; parms = TREE_CHAIN (parms))
1290 if (DECL_NAME (parms))
1292 int current_sym_value = 0;
1293 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1295 if (name == 0 || *name == 0)
1296 name = gen_fake_label ();
1298 /* Perform any necessary register eliminations on the parameter's rtl,
1299 so that the debugging output will be accurate. */
1300 DECL_INCOMING_RTL (parms)
1301 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1302 SET_DECL_RTL (parms,
1303 eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
1305 if (PARM_PASSED_IN_MEMORY (parms))
1307 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1308 tree type;
1310 /* ??? Here we assume that the parm address is indexed
1311 off the frame pointer or arg pointer.
1312 If that is not true, we produce meaningless results,
1313 but do not crash. */
1314 if (GET_CODE (addr) == PLUS
1315 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1316 current_sym_value = INTVAL (XEXP (addr, 1));
1317 else
1318 current_sym_value = 0;
1320 if (GET_CODE (DECL_RTL (parms)) == REG
1321 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1322 type = DECL_ARG_TYPE (parms);
1323 else
1325 int original_sym_value = current_sym_value;
1327 /* This is the case where the parm is passed as an int or
1328 double and it is converted to a char, short or float
1329 and stored back in the parmlist. In this case, describe
1330 the parm with the variable's declared type, and adjust
1331 the address if the least significant bytes (which we are
1332 using) are not the first ones. */
1333 if (BYTES_BIG_ENDIAN
1334 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1335 current_sym_value +=
1336 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1337 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1339 if (GET_CODE (DECL_RTL (parms)) == MEM
1340 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1341 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1342 == CONST_INT)
1343 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1344 == current_sym_value))
1345 type = TREE_TYPE (parms);
1346 else
1348 current_sym_value = original_sym_value;
1349 type = DECL_ARG_TYPE (parms);
1353 PUT_SDB_DEF (name);
1354 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1355 PUT_SDB_SCL (C_ARG);
1356 PUT_SDB_TYPE (plain_type (type));
1357 PUT_SDB_ENDEF;
1359 else if (GET_CODE (DECL_RTL (parms)) == REG)
1361 rtx best_rtl;
1362 /* Parm passed in registers and lives in registers or nowhere. */
1364 /* If parm lives in a register, use that register;
1365 pretend the parm was passed there. It would be more consistent
1366 to describe the register where the parm was passed,
1367 but in practice that register usually holds something else. */
1368 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1369 best_rtl = DECL_RTL (parms);
1370 /* If the parm lives nowhere,
1371 use the register where it was passed. */
1372 else
1373 best_rtl = DECL_INCOMING_RTL (parms);
1375 PUT_SDB_DEF (name);
1376 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1377 PUT_SDB_SCL (C_REGPARM);
1378 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1379 PUT_SDB_ENDEF;
1381 else if (GET_CODE (DECL_RTL (parms)) == MEM
1382 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1384 /* Parm was passed in registers but lives on the stack. */
1386 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1387 in which case we want the value of that CONST_INT,
1388 or (MEM (REG ...)) or (MEM (MEM ...)),
1389 in which case we use a value of zero. */
1390 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1391 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1392 current_sym_value = 0;
1393 else
1394 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1396 /* Again, this assumes the offset is based on the arg pointer. */
1397 PUT_SDB_DEF (name);
1398 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1399 XEXP (DECL_RTL (parms), 0)));
1400 PUT_SDB_SCL (C_ARG);
1401 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1402 PUT_SDB_ENDEF;
1407 /* Output definitions for the places where parms live during the function,
1408 when different from where they were passed, when the parms were passed
1409 in memory.
1411 It is not useful to do this for parms passed in registers
1412 that live during the function in different registers, because it is
1413 impossible to look in the passed register for the passed value,
1414 so we use the within-the-function register to begin with.
1416 PARMS is a chain of PARM_DECL nodes. */
1418 static void
1419 sdbout_reg_parms (parms)
1420 tree parms;
1422 for (; parms; parms = TREE_CHAIN (parms))
1423 if (DECL_NAME (parms))
1425 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1427 /* Report parms that live in registers during the function
1428 but were passed in memory. */
1429 if (GET_CODE (DECL_RTL (parms)) == REG
1430 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1431 && PARM_PASSED_IN_MEMORY (parms))
1433 if (name == 0 || *name == 0)
1434 name = gen_fake_label ();
1435 PUT_SDB_DEF (name);
1436 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1437 PUT_SDB_SCL (C_REG);
1438 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1439 PUT_SDB_ENDEF;
1441 /* Report parms that live in memory but not where they were passed. */
1442 else if (GET_CODE (DECL_RTL (parms)) == MEM
1443 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1444 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1445 && PARM_PASSED_IN_MEMORY (parms)
1446 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1448 #if 0 /* ??? It is not clear yet what should replace this. */
1449 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1450 /* A parm declared char is really passed as an int,
1451 so it occupies the least significant bytes.
1452 On a big-endian machine those are not the low-numbered ones. */
1453 if (BYTES_BIG_ENDIAN
1454 && offset != -1
1455 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1456 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1457 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1458 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1459 #endif
1461 if (name == 0 || *name == 0)
1462 name = gen_fake_label ();
1463 PUT_SDB_DEF (name);
1464 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1465 (XEXP (DECL_RTL (parms), 0)));
1466 PUT_SDB_SCL (C_AUTO);
1467 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1468 PUT_SDB_ENDEF;
1474 /* Output debug information for a global DECL. Called from toplev.c
1475 after compilation proper has finished. */
1477 static void
1478 sdbout_global_decl (decl)
1479 tree decl;
1481 if (TREE_CODE (decl) == VAR_DECL
1482 && !DECL_EXTERNAL (decl)
1483 && DECL_RTL_SET_P (decl))
1485 /* The COFF linker can move initialized global vars to the end.
1486 And that can screw up the symbol ordering. Defer those for
1487 sdbout_finish (). */
1488 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1489 sdbout_symbol (decl, 0);
1491 /* Output COFF information for non-global file-scope initialized
1492 variables. */
1493 if (DECL_INITIAL (decl) && GET_CODE (DECL_RTL (decl)) == MEM)
1494 sdbout_toplevel_data (decl);
1498 /* Output initialized global vars at the end, in the order of
1499 definition. See comment in sdbout_global_decl. */
1501 static void
1502 sdbout_finish (main_filename)
1503 const char *main_filename ATTRIBUTE_UNUSED;
1505 tree decl = (*lang_hooks.decls.getdecls) ();
1506 unsigned int len = list_length (decl);
1507 tree *vec = (tree *) xmalloc (sizeof (tree) * len);
1508 unsigned int i;
1510 /* Process the decls in reverse order--earliest first. Put them
1511 into VEC from back to front, then take out from front. */
1513 for (i = 0; i < len; i++, decl = TREE_CHAIN (decl))
1514 vec[len - i - 1] = decl;
1516 for (i = 0; i < len; i++)
1518 decl = vec[i];
1519 if (TREE_CODE (decl) == VAR_DECL
1520 && ! DECL_EXTERNAL (decl)
1521 && DECL_INITIAL (decl)
1522 && TREE_PUBLIC (decl)
1523 && DECL_RTL_SET_P (decl))
1524 sdbout_symbol (decl, 0);
1527 free (vec);
1530 /* Describe the beginning of an internal block within a function.
1531 Also output descriptions of variables defined in this block.
1533 N is the number of the block, by order of beginning, counting from 1,
1534 and not counting the outermost (function top-level) block.
1535 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1536 if the count starts at 0 for the outermost one. */
1538 static void
1539 sdbout_begin_block (line, n)
1540 unsigned int line;
1541 unsigned int n;
1543 tree decl = current_function_decl;
1544 MAKE_LINE_SAFE (line);
1546 /* The SCO compiler does not emit a separate block for the function level
1547 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1548 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1549 #ifndef MIPS_DEBUGGING_INFO
1550 if (n != 1)
1551 #endif
1552 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1554 if (n == 1)
1556 /* Include the outermost BLOCK's variables in block 1. */
1557 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1558 sdbout_block (DECL_INITIAL (decl));
1560 /* If -g1, suppress all the internal symbols of functions
1561 except for arguments. */
1562 if (debug_info_level != DINFO_LEVEL_TERSE)
1564 do_block = n;
1565 sdbout_block (DECL_INITIAL (decl));
1568 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1569 sdbout_dequeue_anonymous_types ();
1570 #endif
1573 /* Describe the end line-number of an internal block within a function. */
1575 static void
1576 sdbout_end_block (line, n)
1577 unsigned int line;
1578 unsigned int n ATTRIBUTE_UNUSED;
1580 MAKE_LINE_SAFE (line);
1582 /* The SCO compiler does not emit a separate block for the function level
1583 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1584 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1585 #ifndef MIPS_DEBUGGING_INFO
1586 if (n != 1)
1587 #endif
1588 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1591 static void
1592 sdbout_source_line (line, filename)
1593 unsigned int line;
1594 const char *filename ATTRIBUTE_UNUSED;
1596 /* COFF relative line numbers must be positive. */
1597 if ((int) line > sdb_begin_function_line)
1599 #ifdef ASM_OUTPUT_SOURCE_LINE
1600 ASM_OUTPUT_SOURCE_LINE (asm_out_file, line);
1601 #else
1602 fprintf (asm_out_file, "\t.ln\t%d\n",
1603 ((sdb_begin_function_line > -1)
1604 ? line - sdb_begin_function_line : 1));
1605 #endif
1609 /* Output sdb info for the current function name.
1610 Called from assemble_start_function. */
1612 static void
1613 sdbout_begin_function (decl)
1614 tree decl ATTRIBUTE_UNUSED;
1616 sdbout_symbol (current_function_decl, 0);
1619 /* Called at beginning of function body (before or after prologue,
1620 depending on MIPS_DEBUGGING_INFO). Record the function's starting
1621 line number, so we can output relative line numbers for the other
1622 lines. Describe beginning of outermost block. Also describe the
1623 parameter list. */
1625 #ifndef MIPS_DEBUGGING_INFO
1626 static void
1627 sdbout_begin_prologue (line, file)
1628 unsigned int line;
1629 const char *file ATTRIBUTE_UNUSED;
1631 sdbout_end_prologue (line, file);
1633 #endif
1635 static void
1636 sdbout_end_prologue (line, file)
1637 unsigned int line;
1638 const char *file ATTRIBUTE_UNUSED;
1640 sdb_begin_function_line = line - 1;
1641 PUT_SDB_FUNCTION_START (line);
1642 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1643 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1646 /* Called at end of function (before epilogue).
1647 Describe end of outermost block. */
1649 static void
1650 sdbout_end_function (line)
1651 unsigned int line;
1653 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1654 sdbout_dequeue_anonymous_types ();
1655 #endif
1657 MAKE_LINE_SAFE (line);
1658 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1660 /* Indicate we are between functions, for line-number output. */
1661 sdb_begin_function_line = -1;
1664 /* Output sdb info for the absolute end of a function.
1665 Called after the epilogue is output. */
1667 static void
1668 sdbout_end_epilogue (line, file)
1669 unsigned int line ATTRIBUTE_UNUSED;
1670 const char *file ATTRIBUTE_UNUSED;
1672 const char *const name ATTRIBUTE_UNUSED
1673 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1675 #ifdef PUT_SDB_EPILOGUE_END
1676 PUT_SDB_EPILOGUE_END (name);
1677 #else
1678 fprintf (asm_out_file, "\t.def\t");
1679 assemble_name (asm_out_file, name);
1680 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1681 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1682 #endif
1685 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1686 is present. */
1688 static void
1689 sdbout_label (insn)
1690 rtx insn;
1692 PUT_SDB_DEF (LABEL_NAME (insn));
1693 PUT_SDB_VAL (insn);
1694 PUT_SDB_SCL (C_LABEL);
1695 PUT_SDB_TYPE (T_NULL);
1696 PUT_SDB_ENDEF;
1699 /* Change to reading from a new source file. */
1701 static void
1702 sdbout_start_source_file (line, filename)
1703 unsigned int line ATTRIBUTE_UNUSED;
1704 const char *filename ATTRIBUTE_UNUSED;
1706 #ifdef MIPS_DEBUGGING_INFO
1707 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1709 n->next = current_file;
1710 n->name = filename;
1711 current_file = n;
1712 PUT_SDB_SRC_FILE (filename);
1713 #endif
1716 /* Revert to reading a previous source file. */
1718 static void
1719 sdbout_end_source_file (line)
1720 unsigned int line ATTRIBUTE_UNUSED;
1722 #ifdef MIPS_DEBUGGING_INFO
1723 struct sdb_file *next;
1725 next = current_file->next;
1726 free (current_file);
1727 current_file = next;
1728 PUT_SDB_SRC_FILE (current_file->name);
1729 #endif
1732 /* Set up for SDB output at the start of compilation. */
1734 static void
1735 sdbout_init (input_file_name)
1736 const char *input_file_name ATTRIBUTE_UNUSED;
1738 #ifdef MIPS_DEBUGGING_INFO
1739 current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
1740 current_file->next = NULL;
1741 current_file->name = input_file_name;
1742 #endif
1744 #ifdef RMS_QUICK_HACK_1
1745 tree t;
1746 for (t = (*lang_hooks.decls.getdecls) (); t; t = TREE_CHAIN (t))
1747 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
1748 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
1749 sdbout_symbol (t, 0);
1750 #endif
1753 #else /* SDB_DEBUGGING_INFO */
1755 /* This should never be used, but its address is needed for comparisons. */
1756 const struct gcc_debug_hooks sdb_debug_hooks;
1758 #endif /* SDB_DEBUGGING_INFO */
1760 #include "gt-sdbout.h"