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