(nonzero_bits): Don't assume arg pointer has same
[official-gcc.git] / gcc / sdbout.c
blobac651a43dc5bbaaea3b2568072eff3cd041a3637
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* mike@tredysvr.Tredydev.Unisys.COM says:
22 I modified the struct.c example and have a nm of a .o resulting from the
23 AT&T C compiler. From the example below I would conclude the following:
25 1. All .defs from structures are emitted as scanned. The example below
26 clearly shows the symbol table entries for BoxRec2 are after the first
27 function.
29 2. All functions and their locals (including statics) are emitted as scanned.
31 3. All nested unnamed union and structure .defs must be emitted before
32 the structure in which they are nested. The AT&T assembler is a
33 one pass beast as far as symbolics are concerned.
35 4. All structure .defs are emitted before the typedefs that refer to them.
37 5. All top level static and external variable definitions are moved to the
38 end of file with all top level statics occurring first before externs.
40 6. All undefined references are at the end of the file.
43 #include "config.h"
45 #ifdef SDB_DEBUGGING_INFO
47 #include "tree.h"
48 #include "rtl.h"
49 #include <stdio.h>
50 #include "regs.h"
51 #include "flags.h"
52 #include "insn-config.h"
53 #include "reload.h"
55 /* Mips systems use the SDB functions to dump out symbols, but
56 do not supply usable syms.h include files. */
57 #if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(_WIN32) && !defined(__linux__)
58 #include <syms.h>
59 /* Use T_INT if we don't have T_VOID. */
60 #ifndef T_VOID
61 #define T_VOID T_INT
62 #endif
63 #else /* not USG, or MIPS */
64 #include "gsyms.h"
65 #endif /* not USG, or MIPS */
67 /* #include <storclass.h> used to be this instead of syms.h. */
69 /* 1 if PARM is passed to this function in memory. */
71 #define PARM_PASSED_IN_MEMORY(PARM) \
72 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
74 /* A C expression for the integer offset value of an automatic variable
75 (C_AUTO) having address X (an RTX). */
76 #ifndef DEBUGGER_AUTO_OFFSET
77 #define DEBUGGER_AUTO_OFFSET(X) \
78 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
79 #endif
81 /* A C expression for the integer offset value of an argument (C_ARG)
82 having address X (an RTX). The nominal offset is OFFSET. */
83 #ifndef DEBUGGER_ARG_OFFSET
84 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
85 #endif
87 /* Line number of beginning of current function, minus one.
88 Negative means not in a function or not using sdb. */
90 int sdb_begin_function_line = -1;
92 /* Counter to generate unique "names" for nameless struct members. */
94 static int unnamed_struct_number = 0;
96 extern FILE *asm_out_file;
98 extern tree current_function_decl;
100 void sdbout_init ();
101 void sdbout_symbol ();
102 void sdbout_types();
104 static char *gen_fake_label PROTO((void));
105 static int plain_type PROTO((tree));
106 static int template_name_p PROTO((tree));
107 static void sdbout_record_type_name PROTO((tree));
108 static int plain_type_1 PROTO((tree, int));
109 static void sdbout_block PROTO((tree));
110 static void sdbout_syms PROTO((tree));
111 static void sdbout_queue_anonymous_type PROTO((tree));
112 static void sdbout_dequeue_anonymous_types PROTO((void));
113 static void sdbout_type PROTO((tree));
114 static void sbdout_field_types PROTO((tree));
115 static void sdbout_one_type PROTO((tree));
116 static void sdbout_parms PROTO((tree));
117 static void sdbout_reg_parms PROTO((tree));
119 /* Define the default sizes for various types. */
121 #ifndef CHAR_TYPE_SIZE
122 #define CHAR_TYPE_SIZE BITS_PER_UNIT
123 #endif
125 #ifndef SHORT_TYPE_SIZE
126 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
127 #endif
129 #ifndef INT_TYPE_SIZE
130 #define INT_TYPE_SIZE BITS_PER_WORD
131 #endif
133 #ifndef LONG_TYPE_SIZE
134 #define LONG_TYPE_SIZE BITS_PER_WORD
135 #endif
137 #ifndef LONG_LONG_TYPE_SIZE
138 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
139 #endif
141 #ifndef FLOAT_TYPE_SIZE
142 #define FLOAT_TYPE_SIZE BITS_PER_WORD
143 #endif
145 #ifndef DOUBLE_TYPE_SIZE
146 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
147 #endif
149 #ifndef LONG_DOUBLE_TYPE_SIZE
150 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
151 #endif
153 /* Random macros describing parts of SDB data. */
155 /* Put something here if lines get too long */
156 #define CONTIN
158 /* Default value of delimiter is ";". */
159 #ifndef SDB_DELIM
160 #define SDB_DELIM ";"
161 #endif
163 /* Maximum number of dimensions the assembler will allow. */
164 #ifndef SDB_MAX_DIM
165 #define SDB_MAX_DIM 4
166 #endif
168 #ifndef PUT_SDB_SCL
169 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
170 #endif
172 #ifndef PUT_SDB_INT_VAL
173 #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM)
174 #endif
176 #ifndef PUT_SDB_VAL
177 #define PUT_SDB_VAL(a) \
178 ( fputs ("\t.val\t", asm_out_file), \
179 output_addr_const (asm_out_file, (a)), \
180 fprintf (asm_out_file, SDB_DELIM))
181 #endif
183 #ifndef PUT_SDB_DEF
184 #define PUT_SDB_DEF(a) \
185 do { fprintf (asm_out_file, "\t.def\t"); \
186 ASM_OUTPUT_LABELREF (asm_out_file, a); \
187 fprintf (asm_out_file, SDB_DELIM); } while (0)
188 #endif
190 #ifndef PUT_SDB_PLAIN_DEF
191 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
192 #endif
194 #ifndef PUT_SDB_ENDEF
195 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
196 #endif
198 #ifndef PUT_SDB_TYPE
199 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
200 #endif
202 #ifndef PUT_SDB_SIZE
203 #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM)
204 #endif
206 #ifndef PUT_SDB_START_DIM
207 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
208 #endif
210 #ifndef PUT_SDB_NEXT_DIM
211 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
212 #endif
214 #ifndef PUT_SDB_LAST_DIM
215 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
216 #endif
218 #ifndef PUT_SDB_TAG
219 #define PUT_SDB_TAG(a) \
220 do { fprintf (asm_out_file, "\t.tag\t"); \
221 ASM_OUTPUT_LABELREF (asm_out_file, a); \
222 fprintf (asm_out_file, SDB_DELIM); } while (0)
223 #endif
225 #ifndef PUT_SDB_BLOCK_START
226 #define PUT_SDB_BLOCK_START(LINE) \
227 fprintf (asm_out_file, \
228 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
229 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
230 #endif
232 #ifndef PUT_SDB_BLOCK_END
233 #define PUT_SDB_BLOCK_END(LINE) \
234 fprintf (asm_out_file, \
235 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
236 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
237 #endif
239 #ifndef PUT_SDB_FUNCTION_START
240 #define PUT_SDB_FUNCTION_START(LINE) \
241 fprintf (asm_out_file, \
242 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
243 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
244 #endif
246 #ifndef PUT_SDB_FUNCTION_END
247 #define PUT_SDB_FUNCTION_END(LINE) \
248 fprintf (asm_out_file, \
249 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
250 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
251 #endif
253 #ifndef PUT_SDB_EPILOGUE_END
254 #define PUT_SDB_EPILOGUE_END(NAME) \
255 do { fprintf (asm_out_file, "\t.def\t"); \
256 ASM_OUTPUT_LABELREF (asm_out_file, NAME); \
257 fprintf (asm_out_file, \
258 "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", \
259 SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
260 #endif
262 #ifndef SDB_GENERATE_FAKE
263 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
264 sprintf ((BUFFER), ".%dfake", (NUMBER));
265 #endif
267 /* Return the sdb tag identifier string for TYPE
268 if TYPE has already been defined; otherwise return a null pointer. */
270 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
272 /* Set the sdb tag identifier string for TYPE to NAME. */
274 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
275 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
277 /* Return the name (a string) of the struct, union or enum tag
278 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
280 #define TAG_NAME(link) \
281 (((link) && TREE_PURPOSE ((link)) \
282 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
283 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
285 /* Ensure we don't output a negative line number. */
286 #define MAKE_LINE_SAFE(line) \
287 if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
289 /* Set up for SDB output at the start of compilation. */
291 void
292 sdbout_init (asm_file, input_file_name, syms)
293 FILE *asm_file;
294 char *input_file_name;
295 tree syms;
297 #ifdef RMS_QUICK_HACK_1
298 tree t;
299 for (t = syms; t; t = TREE_CHAIN (t))
300 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
301 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
302 sdbout_symbol (t, 0);
303 #endif
306 #if 0
308 /* return the tag identifier for type
311 char *
312 tag_of_ru_type (type,link)
313 tree type,link;
315 if (TYPE_SYMTAB_ADDRESS (type))
316 return TYPE_SYMTAB_ADDRESS (type);
317 if (link && TREE_PURPOSE (link)
318 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
319 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
320 else
321 return (char *) TYPE_SYMTAB_ADDRESS (type);
323 #endif
325 /* Return a unique string to name an anonymous type. */
327 static char *
328 gen_fake_label ()
330 char label[10];
331 char *labelstr;
332 SDB_GENERATE_FAKE (label, unnamed_struct_number);
333 unnamed_struct_number++;
334 labelstr = (char *) permalloc (strlen (label) + 1);
335 strcpy (labelstr, label);
336 return labelstr;
339 /* Return the number which describes TYPE for SDB.
340 For pointers, etc., this function is recursive.
341 Each record, union or enumeral type must already have had a
342 tag number output. */
344 /* The number is given by d6d5d4d3d2d1bbbb
345 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
346 Thus, char *foo () has bbbb=T_CHAR
347 d1=D_FCN
348 d2=D_PTR
349 N_BTMASK= 017 1111 basic type field.
350 N_TSHIFT= 2 derived type shift
351 N_BTSHFT= 4 Basic type shift */
353 /* Produce the number that describes a pointer, function or array type.
354 PREV is the number describing the target, value or element type.
355 DT_type describes how to transform that type. */
356 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
357 ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT) \
358 | ((int)DT_type << (int)N_BTSHFT) \
359 | ((PREV) & (int)N_BTMASK))
361 /* Number of elements used in sdb_dims. */
362 static int sdb_n_dims = 0;
364 /* Table of array dimensions of current type. */
365 static int sdb_dims[SDB_MAX_DIM];
367 /* Size of outermost array currently being processed. */
368 static int sdb_type_size = -1;
370 static int
371 plain_type (type)
372 tree type;
374 int val = plain_type_1 (type, 0);
376 /* If we have already saved up some array dimensions, print them now. */
377 if (sdb_n_dims > 0)
379 int i;
380 PUT_SDB_START_DIM;
381 for (i = sdb_n_dims - 1; i > 0; i--)
382 PUT_SDB_NEXT_DIM (sdb_dims[i]);
383 PUT_SDB_LAST_DIM (sdb_dims[0]);
384 sdb_n_dims = 0;
386 sdb_type_size = int_size_in_bytes (type);
387 /* Don't kill sdb if type is not laid out or has variable size. */
388 if (sdb_type_size < 0)
389 sdb_type_size = 0;
391 /* If we have computed the size of an array containing this type,
392 print it now. */
393 if (sdb_type_size >= 0)
395 PUT_SDB_SIZE (sdb_type_size);
396 sdb_type_size = -1;
398 return val;
401 static int
402 template_name_p (name)
403 tree name;
405 register char *ptr = IDENTIFIER_POINTER (name);
406 while (*ptr && *ptr != '<')
407 ptr++;
409 return *ptr != '\0';
412 static void
413 sdbout_record_type_name (type)
414 tree type;
416 char *name = 0;
417 int no_name;
419 if (KNOWN_TYPE_TAG (type))
420 return;
422 if (TYPE_NAME (type) != 0)
424 tree t = 0;
425 /* Find the IDENTIFIER_NODE for the type name. */
426 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
427 t = TYPE_NAME (type);
428 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
430 t = DECL_NAME (TYPE_NAME (type));
431 /* The DECL_NAME for templates includes "<>", which breaks
432 most assemblers. Use its assembler name instead, which
433 has been mangled into being safe. */
434 if (t && template_name_p (t))
435 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
438 /* Now get the name as a string, or invent one. */
439 if (t != NULL_TREE)
440 name = IDENTIFIER_POINTER (t);
443 no_name = (name == 0 || *name == 0);
444 if (no_name)
445 name = gen_fake_label ();
447 SET_KNOWN_TYPE_TAG (type, name);
448 #ifdef SDB_ALLOW_FORWARD_REFERENCES
449 if (no_name)
450 sdbout_queue_anonymous_type (type);
451 #endif
454 /* Return the .type value for type TYPE.
456 LEVEL indicates how many levels deep we have recursed into the type.
457 The SDB debug format can only represent 6 derived levels of types.
458 After that, we must output inaccurate debug info. We deliberately
459 stop before the 7th level, so that ADA recursive types will not give an
460 infinite loop. */
462 static int
463 plain_type_1 (type, level)
464 tree type;
465 int level;
467 if (type == 0)
468 type = void_type_node;
469 else if (type == error_mark_node)
470 type = integer_type_node;
471 else
472 type = TYPE_MAIN_VARIANT (type);
474 switch (TREE_CODE (type))
476 case VOID_TYPE:
477 return T_VOID;
478 case INTEGER_TYPE:
480 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
482 /* Carefully distinguish all the standard types of C,
483 without messing up if the language is not C.
484 Note that we check only for the names that contain spaces;
485 other names might occur by coincidence in other languages. */
486 if (TYPE_NAME (type) != 0
487 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
488 && DECL_NAME (TYPE_NAME (type)) != 0
489 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
491 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
493 if (!strcmp (name, "unsigned char"))
494 return T_UCHAR;
495 if (!strcmp (name, "signed char"))
496 return T_CHAR;
497 if (!strcmp (name, "unsigned int"))
498 return T_UINT;
499 if (!strcmp (name, "short int"))
500 return T_SHORT;
501 if (!strcmp (name, "short unsigned int"))
502 return T_USHORT;
503 if (!strcmp (name, "long int"))
504 return T_LONG;
505 if (!strcmp (name, "long unsigned int"))
506 return T_ULONG;
509 if (size == CHAR_TYPE_SIZE)
510 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
511 if (size == SHORT_TYPE_SIZE)
512 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
513 if (size == INT_TYPE_SIZE)
514 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
515 if (size == LONG_TYPE_SIZE)
516 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
517 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
518 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
519 return 0;
522 case REAL_TYPE:
524 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
525 if (size == FLOAT_TYPE_SIZE)
526 return T_FLOAT;
527 if (size == DOUBLE_TYPE_SIZE)
528 return T_DOUBLE;
529 return 0;
532 case ARRAY_TYPE:
534 int m;
535 if (level >= 6)
536 return T_VOID;
537 else
538 m = plain_type_1 (TREE_TYPE (type), level+1);
539 if (sdb_n_dims < SDB_MAX_DIM)
540 sdb_dims[sdb_n_dims++]
541 = (TYPE_DOMAIN (type)
542 ? (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
543 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
544 : 0);
545 return PUSH_DERIVED_LEVEL (DT_ARY, m);
548 case RECORD_TYPE:
549 case UNION_TYPE:
550 case QUAL_UNION_TYPE:
551 case ENUMERAL_TYPE:
553 char *tag;
554 #ifdef SDB_ALLOW_FORWARD_REFERENCES
555 sdbout_record_type_name (type);
556 #endif
557 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
558 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
559 #ifdef SDB_ALLOW_FORWARD_REFERENCES
560 || TYPE_MODE (type) != VOIDmode
561 #endif
563 #endif
565 /* Output the referenced structure tag name
566 only if the .def has already been finished.
567 At least on 386, the Unix assembler
568 cannot handle forward references to tags. */
569 /* But the 88100, it requires them, sigh... */
570 /* And the MIPS requires unknown refs as well... */
571 tag = KNOWN_TYPE_TAG (type);
572 PUT_SDB_TAG (tag);
573 /* These 3 lines used to follow the close brace.
574 However, a size of 0 without a tag implies a tag of 0,
575 so if we don't know a tag, we can't mention the size. */
576 sdb_type_size = int_size_in_bytes (type);
577 if (sdb_type_size < 0)
578 sdb_type_size = 0;
580 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
581 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
582 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
583 : T_ENUM);
585 case POINTER_TYPE:
586 case REFERENCE_TYPE:
588 int m;
589 if (level >= 6)
590 return T_VOID;
591 else
592 m = plain_type_1 (TREE_TYPE (type), level+1);
593 return PUSH_DERIVED_LEVEL (DT_PTR, m);
595 case FUNCTION_TYPE:
596 case METHOD_TYPE:
598 int m;
599 if (level >= 6)
600 return T_VOID;
601 else
602 m = plain_type_1 (TREE_TYPE (type), level+1);
603 return PUSH_DERIVED_LEVEL (DT_FCN, m);
605 default:
606 return 0;
610 /* Output the symbols defined in block number DO_BLOCK.
611 Set NEXT_BLOCK_NUMBER to 0 before calling.
613 This function works by walking the tree structure of blocks,
614 counting blocks until it finds the desired block. */
616 static int do_block = 0;
618 static int next_block_number;
620 static void
621 sdbout_block (block)
622 register tree block;
624 while (block)
626 /* Ignore blocks never expanded or otherwise marked as real. */
627 if (TREE_USED (block))
629 /* When we reach the specified block, output its symbols. */
630 if (next_block_number == do_block)
632 sdbout_syms (BLOCK_VARS (block));
635 /* If we are past the specified block, stop the scan. */
636 if (next_block_number > do_block)
637 return;
639 next_block_number++;
641 /* Scan the blocks within this block. */
642 sdbout_block (BLOCK_SUBBLOCKS (block));
645 block = BLOCK_CHAIN (block);
649 /* Call sdbout_symbol on each decl in the chain SYMS. */
651 static void
652 sdbout_syms (syms)
653 tree syms;
655 while (syms)
657 if (TREE_CODE (syms) != LABEL_DECL)
658 sdbout_symbol (syms, 1);
659 syms = TREE_CHAIN (syms);
663 /* Output SDB information for a symbol described by DECL.
664 LOCAL is nonzero if the symbol is not file-scope. */
666 void
667 sdbout_symbol (decl, local)
668 tree decl;
669 int local;
671 tree type = TREE_TYPE (decl);
672 tree context = NULL_TREE;
673 rtx value;
674 int regno = -1;
675 char *name;
677 sdbout_one_type (type);
679 #if 0 /* This loses when functions are marked to be ignored,
680 which happens in the C++ front end. */
681 if (DECL_IGNORED_P (decl))
682 return;
683 #endif
685 switch (TREE_CODE (decl))
687 case CONST_DECL:
688 /* Enum values are defined by defining the enum type. */
689 return;
691 case FUNCTION_DECL:
692 /* Don't mention a nested function under its parent. */
693 context = decl_function_context (decl);
694 if (context == current_function_decl)
695 return;
696 /* Check DECL_INITIAL to distinguish declarations from definitions.
697 Don't output debug info here for declarations; they will have
698 a DECL_INITIAL value of 0. */
699 if (! DECL_INITIAL (decl))
700 return;
701 if (GET_CODE (DECL_RTL (decl)) != MEM
702 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
703 return;
704 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
705 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
706 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
707 break;
709 case TYPE_DECL:
710 /* Done with tagged types. */
711 if (DECL_NAME (decl) == 0)
712 return;
713 if (DECL_IGNORED_P (decl))
714 return;
716 /* Output typedef name. */
717 if (template_name_p (DECL_NAME (decl)))
718 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
719 else
720 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
721 PUT_SDB_SCL (C_TPDEF);
722 break;
724 case PARM_DECL:
725 /* Parm decls go in their own separate chains
726 and are output by sdbout_reg_parms and sdbout_parms. */
727 abort ();
729 case VAR_DECL:
730 /* Don't mention a variable that is external.
731 Let the file that defines it describe it. */
732 if (DECL_EXTERNAL (decl))
733 return;
735 /* Ignore __FUNCTION__, etc. */
736 if (DECL_IGNORED_P (decl))
737 return;
739 /* If there was an error in the declaration, don't dump core
740 if there is no RTL associated with the variable doesn't
741 exist. */
742 if (DECL_RTL (decl) == 0)
743 return;
745 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
746 #ifdef LEAF_REG_REMAP
747 if (leaf_function)
748 leaf_renumber_regs_insn (DECL_RTL (decl));
749 #endif
750 value = DECL_RTL (decl);
752 /* Don't mention a variable at all
753 if it was completely optimized into nothingness.
755 If DECL was from an inline function, then its rtl
756 is not identically the rtl that was used in this
757 particular compilation. */
758 if (GET_CODE (value) == REG)
760 regno = REGNO (DECL_RTL (decl));
761 if (regno >= FIRST_PSEUDO_REGISTER)
762 return;
764 else if (GET_CODE (value) == SUBREG)
766 int offset = 0;
767 while (GET_CODE (value) == SUBREG)
769 offset += SUBREG_WORD (value);
770 value = SUBREG_REG (value);
772 if (GET_CODE (value) == REG)
774 regno = REGNO (value);
775 if (regno >= FIRST_PSEUDO_REGISTER)
776 return;
777 regno += offset;
779 alter_subreg (DECL_RTL (decl));
780 value = DECL_RTL (decl);
782 /* Don't output anything if an auto variable
783 gets RTL that is static.
784 GAS version 2.2 can't handle such output. */
785 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
786 && ! TREE_STATIC (decl))
787 return;
789 /* Emit any structure, union, or enum type that has not been output.
790 This occurs for tag-less structs (et al) used to declare variables
791 within functions. */
792 if (TREE_CODE (type) == ENUMERAL_TYPE
793 || TREE_CODE (type) == RECORD_TYPE
794 || TREE_CODE (type) == UNION_TYPE
795 || TREE_CODE (type) == QUAL_UNION_TYPE)
797 if (TYPE_SIZE (type) != 0 /* not a forward reference */
798 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
799 sdbout_one_type (type);
802 /* Defer SDB information for top-level initialized variables! */
803 if (! local
804 && GET_CODE (value) == MEM
805 && DECL_INITIAL (decl))
806 return;
808 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
809 For now, avoid crashing. */
810 if (DECL_NAME (decl) == NULL_TREE)
811 return;
813 /* Record the name for, starting a symtab entry. */
814 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
816 if (GET_CODE (value) == MEM
817 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
819 PUT_SDB_DEF (name);
820 if (TREE_PUBLIC (decl))
822 PUT_SDB_VAL (XEXP (value, 0));
823 PUT_SDB_SCL (C_EXT);
825 else
827 PUT_SDB_VAL (XEXP (value, 0));
828 PUT_SDB_SCL (C_STAT);
831 else if (regno >= 0)
833 PUT_SDB_DEF (name);
834 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
835 PUT_SDB_SCL (C_REG);
837 else if (GET_CODE (value) == MEM
838 && (GET_CODE (XEXP (value, 0)) == MEM
839 || (GET_CODE (XEXP (value, 0)) == REG
840 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
841 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
842 /* If the value is indirect by memory or by a register
843 that isn't the frame pointer
844 then it means the object is variable-sized and address through
845 that register or stack slot. COFF has no way to represent this
846 so all we can do is output the variable as a pointer. */
848 PUT_SDB_DEF (name);
849 if (GET_CODE (XEXP (value, 0)) == REG)
851 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
852 PUT_SDB_SCL (C_REG);
854 else
856 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
857 (CONST_INT...)))).
858 We want the value of that CONST_INT. */
859 /* Encore compiler hates a newline in a macro arg, it seems. */
860 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
861 (XEXP (XEXP (value, 0), 0)));
862 PUT_SDB_SCL (C_AUTO);
865 type = build_pointer_type (TREE_TYPE (decl));
867 else if (GET_CODE (value) == MEM
868 && ((GET_CODE (XEXP (value, 0)) == PLUS
869 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
870 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
871 /* This is for variables which are at offset zero from
872 the frame pointer. This happens on the Alpha.
873 Non-frame pointer registers are excluded above. */
874 || (GET_CODE (XEXP (value, 0)) == REG)))
876 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
877 or (MEM (REG...)). We want the value of that CONST_INT
878 or zero. */
879 PUT_SDB_DEF (name);
880 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
881 PUT_SDB_SCL (C_AUTO);
883 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
885 /* Handle an obscure case which can arise when optimizing and
886 when there are few available registers. (This is *always*
887 the case for i386/i486 targets). The DECL_RTL looks like
888 (MEM (CONST ...)) even though this variable is a local `auto'
889 or a local `register' variable. In effect, what has happened
890 is that the reload pass has seen that all assignments and
891 references for one such a local variable can be replaced by
892 equivalent assignments and references to some static storage
893 variable, thereby avoiding the need for a register. In such
894 cases we're forced to lie to debuggers and tell them that
895 this variable was itself `static'. */
896 PUT_SDB_DEF (name);
897 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
898 PUT_SDB_SCL (C_STAT);
900 else
902 /* It is something we don't know how to represent for SDB. */
903 return;
905 break;
907 PUT_SDB_TYPE (plain_type (type));
908 PUT_SDB_ENDEF;
911 /* Output SDB information for a top-level initialized variable
912 that has been delayed. */
914 void
915 sdbout_toplevel_data (decl)
916 tree decl;
918 tree type = TREE_TYPE (decl);
920 if (DECL_IGNORED_P (decl))
921 return;
923 if (! (TREE_CODE (decl) == VAR_DECL
924 && GET_CODE (DECL_RTL (decl)) == MEM
925 && DECL_INITIAL (decl)))
926 abort ();
928 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
929 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
930 if (TREE_PUBLIC (decl))
932 PUT_SDB_SCL (C_EXT);
934 else
936 PUT_SDB_SCL (C_STAT);
938 PUT_SDB_TYPE (plain_type (type));
939 PUT_SDB_ENDEF;
942 #ifdef SDB_ALLOW_FORWARD_REFERENCES
944 /* Machinery to record and output anonymous types. */
946 static tree anonymous_types;
948 static void
949 sdbout_queue_anonymous_type (type)
950 tree type;
952 anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
955 static void
956 sdbout_dequeue_anonymous_types ()
958 register tree types, link;
960 while (anonymous_types)
962 types = nreverse (anonymous_types);
963 anonymous_types = NULL_TREE;
965 for (link = types; link; link = TREE_CHAIN (link))
967 register tree type = TREE_VALUE (link);
969 if (type && ! TREE_ASM_WRITTEN (type))
970 sdbout_one_type (type);
975 #endif
977 /* Given a chain of ..._TYPE nodes, all of which have names,
978 output definitions of those names, as typedefs. */
980 void
981 sdbout_types (types)
982 register tree types;
984 register tree link;
986 for (link = types; link; link = TREE_CHAIN (link))
987 sdbout_one_type (link);
989 #ifdef SDB_ALLOW_FORWARD_REFERENCES
990 sdbout_dequeue_anonymous_types ();
991 #endif
994 static void
995 sdbout_type (type)
996 tree type;
998 if (type == error_mark_node)
999 type = integer_type_node;
1000 PUT_SDB_TYPE (plain_type (type));
1003 /* Output types of the fields of type TYPE, if they are structs.
1005 Formerly did not chase through pointer types, since that could be circular.
1006 They must come before TYPE, since forward refs are not allowed.
1007 Now james@bigtex.cactus.org says to try them. */
1009 static void
1010 sdbout_field_types (type)
1011 tree type;
1013 tree tail;
1014 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1015 if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
1016 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1017 else
1018 sdbout_one_type (TREE_TYPE (tail));
1021 /* Use this to put out the top level defined record and union types
1022 for later reference. If this is a struct with a name, then put that
1023 name out. Other unnamed structs will have .xxfake labels generated so
1024 that they may be referred to later.
1025 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1026 It may NOT be called recursively. */
1028 static void
1029 sdbout_one_type (type)
1030 tree type;
1032 if (current_function_decl != NULL_TREE
1033 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1034 ; /* Don't change section amid function. */
1035 else
1036 text_section ();
1038 switch (TREE_CODE (type))
1040 case RECORD_TYPE:
1041 case UNION_TYPE:
1042 case QUAL_UNION_TYPE:
1043 case ENUMERAL_TYPE:
1044 type = TYPE_MAIN_VARIANT (type);
1045 /* Don't output a type twice. */
1046 if (TREE_ASM_WRITTEN (type))
1047 /* James said test TREE_ASM_BEING_WRITTEN here. */
1048 return;
1050 /* Output nothing if type is not yet defined. */
1051 if (TYPE_SIZE (type) == 0)
1052 return;
1054 TREE_ASM_WRITTEN (type) = 1;
1055 #if 1
1056 /* This is reputed to cause trouble with the following case,
1057 but perhaps checking TYPE_SIZE above will fix it. */
1059 /* Here is a test case:
1061 struct foo {
1062 struct badstr *bbb;
1063 } forwardref;
1065 typedef struct intermediate {
1066 int aaaa;
1067 } intermediate_ref;
1069 typedef struct badstr {
1070 int ccccc;
1071 } badtype; */
1073 #if 0
1074 TREE_ASM_BEING_WRITTEN (type) = 1;
1075 #endif
1076 /* This change, which ought to make better output,
1077 used to make the COFF assembler unhappy.
1078 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1079 /* Before really doing anything, output types we want to refer to. */
1080 /* Note that in version 1 the following two lines
1081 are not used if forward references are in use. */
1082 if (TREE_CODE (type) != ENUMERAL_TYPE)
1083 sdbout_field_types (type);
1084 #if 0
1085 TREE_ASM_WRITTEN (type) = 1;
1086 #endif
1087 #endif
1089 /* Output a structure type. */
1091 int size = int_size_in_bytes (type);
1092 int member_scl;
1093 tree tem;
1094 int i, n_baseclasses = 0;
1096 /* Record the type tag, but not in its permanent place just yet. */
1097 sdbout_record_type_name (type);
1099 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1101 switch (TREE_CODE (type))
1103 case UNION_TYPE:
1104 case QUAL_UNION_TYPE:
1105 PUT_SDB_SCL (C_UNTAG);
1106 PUT_SDB_TYPE (T_UNION);
1107 member_scl = C_MOU;
1108 break;
1110 case RECORD_TYPE:
1111 PUT_SDB_SCL (C_STRTAG);
1112 PUT_SDB_TYPE (T_STRUCT);
1113 member_scl = C_MOS;
1114 break;
1116 case ENUMERAL_TYPE:
1117 PUT_SDB_SCL (C_ENTAG);
1118 PUT_SDB_TYPE (T_ENUM);
1119 member_scl = C_MOE;
1120 break;
1123 PUT_SDB_SIZE (size);
1124 PUT_SDB_ENDEF;
1126 /* Print out the base class information with fields
1127 named after the types they hold. */
1128 if (TYPE_BINFO (type)
1129 && TYPE_BINFO_BASETYPES (type))
1130 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1131 for (i = 0; i < n_baseclasses; i++)
1133 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1134 tree child_type = BINFO_TYPE (child);
1135 tree child_type_name;
1136 if (TYPE_NAME (child_type) == 0)
1137 continue;
1138 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1139 child_type_name = TYPE_NAME (child_type);
1140 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1142 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1143 if (child_type_name && template_name_p (child_type_name))
1144 child_type_name
1145 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1147 else
1148 continue;
1150 CONTIN;
1151 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1152 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
1153 PUT_SDB_SCL (member_scl);
1154 sdbout_type (BINFO_TYPE (child));
1155 PUT_SDB_ENDEF;
1158 /* output the individual fields */
1160 if (TREE_CODE (type) == ENUMERAL_TYPE)
1161 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1163 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1164 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1165 PUT_SDB_SCL (C_MOE);
1166 PUT_SDB_TYPE (T_MOE);
1167 PUT_SDB_ENDEF;
1170 else /* record or union type */
1171 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1172 /* Output the name, type, position (in bits), size (in bits)
1173 of each field. */
1175 /* Omit here the nameless fields that are used to skip bits.
1176 Also omit fields with variable size or position.
1177 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1178 if (TREE_CODE (tem) == FIELD_DECL
1179 && DECL_NAME (tem) != 0
1180 && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
1181 && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
1183 char *name;
1185 CONTIN;
1186 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
1187 PUT_SDB_DEF (name);
1188 if (DECL_BIT_FIELD_TYPE (tem))
1190 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
1191 PUT_SDB_SCL (C_FIELD);
1192 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1193 PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
1195 else
1197 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
1198 / BITS_PER_UNIT);
1199 PUT_SDB_SCL (member_scl);
1200 sdbout_type (TREE_TYPE (tem));
1202 PUT_SDB_ENDEF;
1204 /* output end of a structure,union, or enumeral definition */
1206 PUT_SDB_PLAIN_DEF ("eos");
1207 PUT_SDB_INT_VAL (size);
1208 PUT_SDB_SCL (C_EOS);
1209 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1210 PUT_SDB_SIZE (size);
1211 PUT_SDB_ENDEF;
1212 break;
1217 /* The following two functions output definitions of function parameters.
1218 Each parameter gets a definition locating it in the parameter list.
1219 Each parameter that is a register variable gets a second definition
1220 locating it in the register.
1222 Printing or argument lists in gdb uses the definitions that
1223 locate in the parameter list. But reference to the variable in
1224 expressions uses preferentially the definition as a register. */
1226 /* Output definitions, referring to storage in the parmlist,
1227 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1229 static void
1230 sdbout_parms (parms)
1231 tree parms;
1233 for (; parms; parms = TREE_CHAIN (parms))
1234 if (DECL_NAME (parms))
1236 int current_sym_value = 0;
1237 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1239 if (name == 0 || *name == 0)
1240 name = gen_fake_label ();
1242 /* Perform any necessary register eliminations on the parameter's rtl,
1243 so that the debugging output will be accurate. */
1244 DECL_INCOMING_RTL (parms) =
1245 eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1246 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1248 if (PARM_PASSED_IN_MEMORY (parms))
1250 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1251 tree type;
1253 /* ??? Here we assume that the parm address is indexed
1254 off the frame pointer or arg pointer.
1255 If that is not true, we produce meaningless results,
1256 but do not crash. */
1257 if (GET_CODE (addr) == PLUS
1258 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1259 current_sym_value = INTVAL (XEXP (addr, 1));
1260 else
1261 current_sym_value = 0;
1263 if (GET_CODE (DECL_RTL (parms)) == REG
1264 && REGNO (DECL_RTL (parms)) >= 0
1265 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1266 type = DECL_ARG_TYPE (parms);
1267 else
1269 int original_sym_value = current_sym_value;
1271 /* This is the case where the parm is passed as an int or
1272 double and it is converted to a char, short or float
1273 and stored back in the parmlist. In this case, describe
1274 the parm with the variable's declared type, and adjust
1275 the address if the least significant bytes (which we are
1276 using) are not the first ones. */
1277 if (BYTES_BIG_ENDIAN
1278 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1279 current_sym_value +=
1280 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1281 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1283 if (GET_CODE (DECL_RTL (parms)) == MEM
1284 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1285 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1286 == CONST_INT)
1287 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1288 == current_sym_value))
1289 type = TREE_TYPE (parms);
1290 else
1292 current_sym_value = original_sym_value;
1293 type = DECL_ARG_TYPE (parms);
1297 PUT_SDB_DEF (name);
1298 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1299 PUT_SDB_SCL (C_ARG);
1300 PUT_SDB_TYPE (plain_type (type));
1301 PUT_SDB_ENDEF;
1303 else if (GET_CODE (DECL_RTL (parms)) == REG)
1305 rtx best_rtl;
1306 /* Parm passed in registers and lives in registers or nowhere. */
1308 /* If parm lives in a register, use that register;
1309 pretend the parm was passed there. It would be more consistent
1310 to describe the register where the parm was passed,
1311 but in practice that register usually holds something else. */
1312 if (REGNO (DECL_RTL (parms)) >= 0
1313 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1314 best_rtl = DECL_RTL (parms);
1315 /* If the parm lives nowhere,
1316 use the register where it was passed. */
1317 else
1318 best_rtl = DECL_INCOMING_RTL (parms);
1320 PUT_SDB_DEF (name);
1321 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1322 PUT_SDB_SCL (C_REGPARM);
1323 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1324 PUT_SDB_ENDEF;
1326 else if (GET_CODE (DECL_RTL (parms)) == MEM
1327 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1329 /* Parm was passed in registers but lives on the stack. */
1331 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1332 in which case we want the value of that CONST_INT,
1333 or (MEM (REG ...)) or (MEM (MEM ...)),
1334 in which case we use a value of zero. */
1335 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1336 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1337 current_sym_value = 0;
1338 else
1339 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1341 /* Again, this assumes the offset is based on the arg pointer. */
1342 PUT_SDB_DEF (name);
1343 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1344 XEXP (DECL_RTL (parms), 0)));
1345 PUT_SDB_SCL (C_ARG);
1346 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1347 PUT_SDB_ENDEF;
1352 /* Output definitions for the places where parms live during the function,
1353 when different from where they were passed, when the parms were passed
1354 in memory.
1356 It is not useful to do this for parms passed in registers
1357 that live during the function in different registers, because it is
1358 impossible to look in the passed register for the passed value,
1359 so we use the within-the-function register to begin with.
1361 PARMS is a chain of PARM_DECL nodes. */
1363 static void
1364 sdbout_reg_parms (parms)
1365 tree parms;
1367 for (; parms; parms = TREE_CHAIN (parms))
1368 if (DECL_NAME (parms))
1370 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1372 /* Report parms that live in registers during the function
1373 but were passed in memory. */
1374 if (GET_CODE (DECL_RTL (parms)) == REG
1375 && REGNO (DECL_RTL (parms)) >= 0
1376 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1377 && PARM_PASSED_IN_MEMORY (parms))
1379 if (name == 0 || *name == 0)
1380 name = gen_fake_label ();
1381 PUT_SDB_DEF (name);
1382 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1383 PUT_SDB_SCL (C_REG);
1384 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1385 PUT_SDB_ENDEF;
1387 /* Report parms that live in memory but not where they were passed. */
1388 else if (GET_CODE (DECL_RTL (parms)) == MEM
1389 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1390 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1391 && PARM_PASSED_IN_MEMORY (parms)
1392 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1394 #if 0 /* ??? It is not clear yet what should replace this. */
1395 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1396 /* A parm declared char is really passed as an int,
1397 so it occupies the least significant bytes.
1398 On a big-endian machine those are not the low-numbered ones. */
1399 if (BYTES_BIG_ENDIAN
1400 && offset != -1
1401 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1402 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1403 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1404 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1405 #endif
1407 if (name == 0 || *name == 0)
1408 name = gen_fake_label ();
1409 PUT_SDB_DEF (name);
1410 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1411 (XEXP (DECL_RTL (parms), 0)));
1412 PUT_SDB_SCL (C_AUTO);
1413 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1414 PUT_SDB_ENDEF;
1420 /* Describe the beginning of an internal block within a function.
1421 Also output descriptions of variables defined in this block.
1423 N is the number of the block, by order of beginning, counting from 1,
1424 and not counting the outermost (function top-level) block.
1425 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1426 if the count starts at 0 for the outermost one. */
1428 void
1429 sdbout_begin_block (file, line, n)
1430 FILE *file;
1431 int line;
1432 int n;
1434 tree decl = current_function_decl;
1435 MAKE_LINE_SAFE (line);
1437 /* The SCO compiler does not emit a separate block for the function level
1438 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1439 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1440 #ifndef MIPS_DEBUGGING_INFO
1441 if (n != 1)
1442 #endif
1443 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1445 if (n == 1)
1447 /* Include the outermost BLOCK's variables in block 1. */
1448 next_block_number = 0;
1449 do_block = 0;
1450 sdbout_block (DECL_INITIAL (decl));
1452 /* If -g1, suppress all the internal symbols of functions
1453 except for arguments. */
1454 if (debug_info_level != DINFO_LEVEL_TERSE)
1456 next_block_number = 0;
1457 do_block = n;
1458 sdbout_block (DECL_INITIAL (decl));
1461 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1462 sdbout_dequeue_anonymous_types ();
1463 #endif
1466 /* Describe the end line-number of an internal block within a function. */
1468 void
1469 sdbout_end_block (file, line, n)
1470 FILE *file;
1471 int line;
1472 int n;
1474 MAKE_LINE_SAFE (line);
1476 /* The SCO compiler does not emit a separate block for the function level
1477 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1478 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1479 #ifndef MIPS_DEBUGGING_INFO
1480 if (n != 1)
1481 #endif
1482 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1485 /* Output sdb info for the current function name.
1486 Called from assemble_start_function. */
1488 void
1489 sdbout_mark_begin_function ()
1491 sdbout_symbol (current_function_decl, 0);
1494 /* Called at beginning of function body (after prologue).
1495 Record the function's starting line number, so we can output
1496 relative line numbers for the other lines.
1497 Describe beginning of outermost block.
1498 Also describe the parameter list. */
1500 void
1501 sdbout_begin_function (line)
1502 int line;
1504 sdb_begin_function_line = line - 1;
1505 PUT_SDB_FUNCTION_START (line);
1506 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1507 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1510 /* Called at end of function (before epilogue).
1511 Describe end of outermost block. */
1513 void
1514 sdbout_end_function (line)
1515 int line;
1517 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1518 sdbout_dequeue_anonymous_types ();
1519 #endif
1521 MAKE_LINE_SAFE (line);
1522 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1524 /* Indicate we are between functions, for line-number output. */
1525 sdb_begin_function_line = -1;
1528 /* Output sdb info for the absolute end of a function.
1529 Called after the epilogue is output. */
1531 void
1532 sdbout_end_epilogue ()
1534 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1535 PUT_SDB_EPILOGUE_END (name);
1538 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1539 is present. */
1541 void
1542 sdbout_label (insn)
1543 register rtx insn;
1545 PUT_SDB_DEF (LABEL_NAME (insn));
1546 PUT_SDB_VAL (insn);
1547 PUT_SDB_SCL (C_LABEL);
1548 PUT_SDB_TYPE (T_NULL);
1549 PUT_SDB_ENDEF;
1552 #endif /* SDB_DEBUGGING_INFO */