(TARGET_FILE_SWITCHING): Define.
[official-gcc.git] / gcc / sdbout.c
blob12924c02862f60d6cfb3c381927b2fef1ee38b44
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 96, 1997 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 "defaults.h"
52 #include "flags.h"
53 #include "insn-config.h"
54 #include "reload.h"
56 /* Mips systems use the SDB functions to dump out symbols, but do not
57 supply usable syms.h include files. Which syms.h file to use is a
58 target parameter so don't use the native one if we're cross compiling. */
60 #if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(_WIN32) && !defined(__linux__) && !defined(CROSS_COMPILE)
61 #include <syms.h>
62 /* Use T_INT if we don't have T_VOID. */
63 #ifndef T_VOID
64 #define T_VOID T_INT
65 #endif
66 #else
67 #include "gsyms.h"
68 #endif
70 /* #include <storclass.h> used to be this instead of syms.h. */
72 /* 1 if PARM is passed to this function in memory. */
74 #define PARM_PASSED_IN_MEMORY(PARM) \
75 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
77 /* A C expression for the integer offset value of an automatic variable
78 (C_AUTO) having address X (an RTX). */
79 #ifndef DEBUGGER_AUTO_OFFSET
80 #define DEBUGGER_AUTO_OFFSET(X) \
81 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
82 #endif
84 /* A C expression for the integer offset value of an argument (C_ARG)
85 having address X (an RTX). The nominal offset is OFFSET. */
86 #ifndef DEBUGGER_ARG_OFFSET
87 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
88 #endif
90 /* Line number of beginning of current function, minus one.
91 Negative means not in a function or not using sdb. */
93 int sdb_begin_function_line = -1;
95 /* Counter to generate unique "names" for nameless struct members. */
97 static int unnamed_struct_number = 0;
99 extern FILE *asm_out_file;
101 extern tree current_function_decl;
103 void sdbout_init ();
104 void sdbout_symbol ();
105 void sdbout_types();
107 static char *gen_fake_label PROTO((void));
108 static int plain_type PROTO((tree));
109 static int template_name_p PROTO((tree));
110 static void sdbout_record_type_name PROTO((tree));
111 static int plain_type_1 PROTO((tree, int));
112 static void sdbout_block PROTO((tree));
113 static void sdbout_syms PROTO((tree));
114 static void sdbout_queue_anonymous_type PROTO((tree));
115 static void sdbout_dequeue_anonymous_types PROTO((void));
116 static void sdbout_type PROTO((tree));
117 static void sbdout_field_types PROTO((tree));
118 static void sdbout_one_type PROTO((tree));
119 static void sdbout_parms PROTO((tree));
120 static void sdbout_reg_parms PROTO((tree));
122 /* Define the default sizes for various types. */
124 #ifndef CHAR_TYPE_SIZE
125 #define CHAR_TYPE_SIZE BITS_PER_UNIT
126 #endif
128 #ifndef SHORT_TYPE_SIZE
129 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
130 #endif
132 #ifndef INT_TYPE_SIZE
133 #define INT_TYPE_SIZE BITS_PER_WORD
134 #endif
136 #ifndef LONG_TYPE_SIZE
137 #define LONG_TYPE_SIZE BITS_PER_WORD
138 #endif
140 #ifndef LONG_LONG_TYPE_SIZE
141 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
142 #endif
144 #ifndef FLOAT_TYPE_SIZE
145 #define FLOAT_TYPE_SIZE BITS_PER_WORD
146 #endif
148 #ifndef DOUBLE_TYPE_SIZE
149 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
150 #endif
152 #ifndef LONG_DOUBLE_TYPE_SIZE
153 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
154 #endif
156 /* Random macros describing parts of SDB data. */
158 /* Put something here if lines get too long */
159 #define CONTIN
161 /* Default value of delimiter is ";". */
162 #ifndef SDB_DELIM
163 #define SDB_DELIM ";"
164 #endif
166 /* Maximum number of dimensions the assembler will allow. */
167 #ifndef SDB_MAX_DIM
168 #define SDB_MAX_DIM 4
169 #endif
171 #ifndef PUT_SDB_SCL
172 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
173 #endif
175 #ifndef PUT_SDB_INT_VAL
176 #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM)
177 #endif
179 #ifndef PUT_SDB_VAL
180 #define PUT_SDB_VAL(a) \
181 ( fputs ("\t.val\t", asm_out_file), \
182 output_addr_const (asm_out_file, (a)), \
183 fprintf (asm_out_file, SDB_DELIM))
184 #endif
186 #ifndef PUT_SDB_DEF
187 #define PUT_SDB_DEF(a) \
188 do { fprintf (asm_out_file, "\t.def\t"); \
189 ASM_OUTPUT_LABELREF (asm_out_file, a); \
190 fprintf (asm_out_file, SDB_DELIM); } while (0)
191 #endif
193 #ifndef PUT_SDB_PLAIN_DEF
194 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
195 #endif
197 #ifndef PUT_SDB_ENDEF
198 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
199 #endif
201 #ifndef PUT_SDB_TYPE
202 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
203 #endif
205 #ifndef PUT_SDB_SIZE
206 #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM)
207 #endif
209 #ifndef PUT_SDB_START_DIM
210 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
211 #endif
213 #ifndef PUT_SDB_NEXT_DIM
214 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
215 #endif
217 #ifndef PUT_SDB_LAST_DIM
218 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
219 #endif
221 #ifndef PUT_SDB_TAG
222 #define PUT_SDB_TAG(a) \
223 do { fprintf (asm_out_file, "\t.tag\t"); \
224 ASM_OUTPUT_LABELREF (asm_out_file, a); \
225 fprintf (asm_out_file, SDB_DELIM); } while (0)
226 #endif
228 #ifndef PUT_SDB_BLOCK_START
229 #define PUT_SDB_BLOCK_START(LINE) \
230 fprintf (asm_out_file, \
231 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
232 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
233 #endif
235 #ifndef PUT_SDB_BLOCK_END
236 #define PUT_SDB_BLOCK_END(LINE) \
237 fprintf (asm_out_file, \
238 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
239 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
240 #endif
242 #ifndef PUT_SDB_FUNCTION_START
243 #define PUT_SDB_FUNCTION_START(LINE) \
244 fprintf (asm_out_file, \
245 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
246 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
247 #endif
249 #ifndef PUT_SDB_FUNCTION_END
250 #define PUT_SDB_FUNCTION_END(LINE) \
251 fprintf (asm_out_file, \
252 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
253 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
254 #endif
256 #ifndef PUT_SDB_EPILOGUE_END
257 #define PUT_SDB_EPILOGUE_END(NAME) \
258 do { fprintf (asm_out_file, "\t.def\t"); \
259 ASM_OUTPUT_LABELREF (asm_out_file, NAME); \
260 fprintf (asm_out_file, \
261 "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", \
262 SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
263 #endif
265 #ifndef SDB_GENERATE_FAKE
266 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
267 sprintf ((BUFFER), ".%dfake", (NUMBER));
268 #endif
270 /* Return the sdb tag identifier string for TYPE
271 if TYPE has already been defined; otherwise return a null pointer. */
273 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
275 /* Set the sdb tag identifier string for TYPE to NAME. */
277 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
278 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
280 /* Return the name (a string) of the struct, union or enum tag
281 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
283 #define TAG_NAME(link) \
284 (((link) && TREE_PURPOSE ((link)) \
285 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
286 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
288 /* Ensure we don't output a negative line number. */
289 #define MAKE_LINE_SAFE(line) \
290 if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
292 /* Perform linker optimization of merging header file definitions together
293 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
294 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
295 the optimization just won't be done. The native assembler already has the
296 necessary support. */
298 #ifdef MIPS_DEBUGGING_INFO
300 #ifndef PUT_SDB_SRC_FILE
301 #define PUT_SDB_SRC_FILE(FILENAME) \
302 output_file_directive (asm_out_file, (FILENAME))
303 #endif
305 /* ECOFF linkers have an optimization that does the same kind of thing as
306 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
307 executable. To achieve this, GCC must output a .file for each file
308 name change. */
310 /* This is a stack of input files. */
312 struct sdb_file
314 struct sdb_file *next;
315 char *name;
318 /* This is the top of the stack. */
320 static struct sdb_file *current_file;
322 #endif /* MIPS_DEBUGGING_INFO */
324 /* Set up for SDB output at the start of compilation. */
326 void
327 sdbout_init (asm_file, input_file_name, syms)
328 FILE *asm_file;
329 char *input_file_name;
330 tree syms;
332 #ifdef MIPS_DEBUGGING_INFO
333 current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
334 current_file->next = NULL;
335 current_file->name = input_file_name;
336 #endif
338 #ifdef RMS_QUICK_HACK_1
339 tree t;
340 for (t = syms; t; t = TREE_CHAIN (t))
341 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
342 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
343 sdbout_symbol (t, 0);
344 #endif
347 #if 0
349 /* return the tag identifier for type
352 char *
353 tag_of_ru_type (type,link)
354 tree type,link;
356 if (TYPE_SYMTAB_ADDRESS (type))
357 return TYPE_SYMTAB_ADDRESS (type);
358 if (link && TREE_PURPOSE (link)
359 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
360 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
361 else
362 return (char *) TYPE_SYMTAB_ADDRESS (type);
364 #endif
366 /* Return a unique string to name an anonymous type. */
368 static char *
369 gen_fake_label ()
371 char label[10];
372 char *labelstr;
373 SDB_GENERATE_FAKE (label, unnamed_struct_number);
374 unnamed_struct_number++;
375 labelstr = (char *) permalloc (strlen (label) + 1);
376 strcpy (labelstr, label);
377 return labelstr;
380 /* Return the number which describes TYPE for SDB.
381 For pointers, etc., this function is recursive.
382 Each record, union or enumeral type must already have had a
383 tag number output. */
385 /* The number is given by d6d5d4d3d2d1bbbb
386 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
387 Thus, char *foo () has bbbb=T_CHAR
388 d1=D_FCN
389 d2=D_PTR
390 N_BTMASK= 017 1111 basic type field.
391 N_TSHIFT= 2 derived type shift
392 N_BTSHFT= 4 Basic type shift */
394 /* Produce the number that describes a pointer, function or array type.
395 PREV is the number describing the target, value or element type.
396 DT_type describes how to transform that type. */
397 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
398 ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT) \
399 | ((int)DT_type << (int)N_BTSHFT) \
400 | ((PREV) & (int)N_BTMASK))
402 /* Number of elements used in sdb_dims. */
403 static int sdb_n_dims = 0;
405 /* Table of array dimensions of current type. */
406 static int sdb_dims[SDB_MAX_DIM];
408 /* Size of outermost array currently being processed. */
409 static int sdb_type_size = -1;
411 static int
412 plain_type (type)
413 tree type;
415 int val = plain_type_1 (type, 0);
417 /* If we have already saved up some array dimensions, print them now. */
418 if (sdb_n_dims > 0)
420 int i;
421 PUT_SDB_START_DIM;
422 for (i = sdb_n_dims - 1; i > 0; i--)
423 PUT_SDB_NEXT_DIM (sdb_dims[i]);
424 PUT_SDB_LAST_DIM (sdb_dims[0]);
425 sdb_n_dims = 0;
427 sdb_type_size = int_size_in_bytes (type);
428 /* Don't kill sdb if type is not laid out or has variable size. */
429 if (sdb_type_size < 0)
430 sdb_type_size = 0;
432 /* If we have computed the size of an array containing this type,
433 print it now. */
434 if (sdb_type_size >= 0)
436 PUT_SDB_SIZE (sdb_type_size);
437 sdb_type_size = -1;
439 return val;
442 static int
443 template_name_p (name)
444 tree name;
446 register char *ptr = IDENTIFIER_POINTER (name);
447 while (*ptr && *ptr != '<')
448 ptr++;
450 return *ptr != '\0';
453 static void
454 sdbout_record_type_name (type)
455 tree type;
457 char *name = 0;
458 int no_name;
460 if (KNOWN_TYPE_TAG (type))
461 return;
463 if (TYPE_NAME (type) != 0)
465 tree t = 0;
466 /* Find the IDENTIFIER_NODE for the type name. */
467 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
468 t = TYPE_NAME (type);
469 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
471 t = DECL_NAME (TYPE_NAME (type));
472 /* The DECL_NAME for templates includes "<>", which breaks
473 most assemblers. Use its assembler name instead, which
474 has been mangled into being safe. */
475 if (t && template_name_p (t))
476 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
479 /* Now get the name as a string, or invent one. */
480 if (t != NULL_TREE)
481 name = IDENTIFIER_POINTER (t);
484 no_name = (name == 0 || *name == 0);
485 if (no_name)
486 name = gen_fake_label ();
488 SET_KNOWN_TYPE_TAG (type, name);
489 #ifdef SDB_ALLOW_FORWARD_REFERENCES
490 if (no_name)
491 sdbout_queue_anonymous_type (type);
492 #endif
495 /* Return the .type value for type TYPE.
497 LEVEL indicates how many levels deep we have recursed into the type.
498 The SDB debug format can only represent 6 derived levels of types.
499 After that, we must output inaccurate debug info. We deliberately
500 stop before the 7th level, so that ADA recursive types will not give an
501 infinite loop. */
503 static int
504 plain_type_1 (type, level)
505 tree type;
506 int level;
508 if (type == 0)
509 type = void_type_node;
510 else if (type == error_mark_node)
511 type = integer_type_node;
512 else
513 type = TYPE_MAIN_VARIANT (type);
515 switch (TREE_CODE (type))
517 case VOID_TYPE:
518 return T_VOID;
519 case INTEGER_TYPE:
521 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
523 /* Carefully distinguish all the standard types of C,
524 without messing up if the language is not C.
525 Note that we check only for the names that contain spaces;
526 other names might occur by coincidence in other languages. */
527 if (TYPE_NAME (type) != 0
528 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
529 && DECL_NAME (TYPE_NAME (type)) != 0
530 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
532 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
534 if (!strcmp (name, "unsigned char"))
535 return T_UCHAR;
536 if (!strcmp (name, "signed char"))
537 return T_CHAR;
538 if (!strcmp (name, "unsigned int"))
539 return T_UINT;
540 if (!strcmp (name, "short int"))
541 return T_SHORT;
542 if (!strcmp (name, "short unsigned int"))
543 return T_USHORT;
544 if (!strcmp (name, "long int"))
545 return T_LONG;
546 if (!strcmp (name, "long unsigned int"))
547 return T_ULONG;
550 if (size == CHAR_TYPE_SIZE)
551 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
552 if (size == SHORT_TYPE_SIZE)
553 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
554 if (size == INT_TYPE_SIZE)
555 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
556 if (size == LONG_TYPE_SIZE)
557 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
558 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
559 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
560 return 0;
563 case REAL_TYPE:
565 int precision = TYPE_PRECISION (type);
566 if (precision == FLOAT_TYPE_SIZE)
567 return T_FLOAT;
568 if (precision == DOUBLE_TYPE_SIZE)
569 return T_DOUBLE;
570 #ifdef EXTENDED_SDB_BASIC_TYPES
571 if (precision == LONG_DOUBLE_TYPE_SIZE)
572 return T_LNGDBL;
573 #endif
574 return 0;
577 case ARRAY_TYPE:
579 int m;
580 if (level >= 6)
581 return T_VOID;
582 else
583 m = plain_type_1 (TREE_TYPE (type), level+1);
584 if (sdb_n_dims < SDB_MAX_DIM)
585 sdb_dims[sdb_n_dims++]
586 = (TYPE_DOMAIN (type)
587 ? (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
588 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
589 : 0);
590 return PUSH_DERIVED_LEVEL (DT_ARY, m);
593 case RECORD_TYPE:
594 case UNION_TYPE:
595 case QUAL_UNION_TYPE:
596 case ENUMERAL_TYPE:
598 char *tag;
599 #ifdef SDB_ALLOW_FORWARD_REFERENCES
600 sdbout_record_type_name (type);
601 #endif
602 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
603 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
604 #ifdef SDB_ALLOW_FORWARD_REFERENCES
605 || TYPE_MODE (type) != VOIDmode
606 #endif
608 #endif
610 /* Output the referenced structure tag name
611 only if the .def has already been finished.
612 At least on 386, the Unix assembler
613 cannot handle forward references to tags. */
614 /* But the 88100, it requires them, sigh... */
615 /* And the MIPS requires unknown refs as well... */
616 tag = KNOWN_TYPE_TAG (type);
617 PUT_SDB_TAG (tag);
618 /* These 3 lines used to follow the close brace.
619 However, a size of 0 without a tag implies a tag of 0,
620 so if we don't know a tag, we can't mention the size. */
621 sdb_type_size = int_size_in_bytes (type);
622 if (sdb_type_size < 0)
623 sdb_type_size = 0;
625 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
626 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
627 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
628 : T_ENUM);
630 case POINTER_TYPE:
631 case REFERENCE_TYPE:
633 int m;
634 if (level >= 6)
635 return T_VOID;
636 else
637 m = plain_type_1 (TREE_TYPE (type), level+1);
638 return PUSH_DERIVED_LEVEL (DT_PTR, m);
640 case FUNCTION_TYPE:
641 case METHOD_TYPE:
643 int m;
644 if (level >= 6)
645 return T_VOID;
646 else
647 m = plain_type_1 (TREE_TYPE (type), level+1);
648 return PUSH_DERIVED_LEVEL (DT_FCN, m);
650 default:
651 return 0;
655 /* Output the symbols defined in block number DO_BLOCK.
656 Set NEXT_BLOCK_NUMBER to 0 before calling.
658 This function works by walking the tree structure of blocks,
659 counting blocks until it finds the desired block. */
661 static int do_block = 0;
663 static int next_block_number;
665 static void
666 sdbout_block (block)
667 register tree block;
669 while (block)
671 /* Ignore blocks never expanded or otherwise marked as real. */
672 if (TREE_USED (block))
674 /* When we reach the specified block, output its symbols. */
675 if (next_block_number == do_block)
677 sdbout_syms (BLOCK_VARS (block));
680 /* If we are past the specified block, stop the scan. */
681 if (next_block_number > do_block)
682 return;
684 next_block_number++;
686 /* Scan the blocks within this block. */
687 sdbout_block (BLOCK_SUBBLOCKS (block));
690 block = BLOCK_CHAIN (block);
694 /* Call sdbout_symbol on each decl in the chain SYMS. */
696 static void
697 sdbout_syms (syms)
698 tree syms;
700 while (syms)
702 if (TREE_CODE (syms) != LABEL_DECL)
703 sdbout_symbol (syms, 1);
704 syms = TREE_CHAIN (syms);
708 /* Output SDB information for a symbol described by DECL.
709 LOCAL is nonzero if the symbol is not file-scope. */
711 void
712 sdbout_symbol (decl, local)
713 tree decl;
714 int local;
716 tree type = TREE_TYPE (decl);
717 tree context = NULL_TREE;
718 rtx value;
719 int regno = -1;
720 char *name;
722 sdbout_one_type (type);
724 #if 0 /* This loses when functions are marked to be ignored,
725 which happens in the C++ front end. */
726 if (DECL_IGNORED_P (decl))
727 return;
728 #endif
730 switch (TREE_CODE (decl))
732 case CONST_DECL:
733 /* Enum values are defined by defining the enum type. */
734 return;
736 case FUNCTION_DECL:
737 /* Don't mention a nested function under its parent. */
738 context = decl_function_context (decl);
739 if (context == current_function_decl)
740 return;
741 /* Check DECL_INITIAL to distinguish declarations from definitions.
742 Don't output debug info here for declarations; they will have
743 a DECL_INITIAL value of 0. */
744 if (! DECL_INITIAL (decl))
745 return;
746 if (GET_CODE (DECL_RTL (decl)) != MEM
747 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
748 return;
749 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
750 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
751 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
752 break;
754 case TYPE_DECL:
755 /* Done with tagged types. */
756 if (DECL_NAME (decl) == 0)
757 return;
758 if (DECL_IGNORED_P (decl))
759 return;
761 /* Output typedef name. */
762 if (template_name_p (DECL_NAME (decl)))
763 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
764 else
765 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
766 PUT_SDB_SCL (C_TPDEF);
767 break;
769 case PARM_DECL:
770 /* Parm decls go in their own separate chains
771 and are output by sdbout_reg_parms and sdbout_parms. */
772 abort ();
774 case VAR_DECL:
775 /* Don't mention a variable that is external.
776 Let the file that defines it describe it. */
777 if (DECL_EXTERNAL (decl))
778 return;
780 /* Ignore __FUNCTION__, etc. */
781 if (DECL_IGNORED_P (decl))
782 return;
784 /* If there was an error in the declaration, don't dump core
785 if there is no RTL associated with the variable doesn't
786 exist. */
787 if (DECL_RTL (decl) == 0)
788 return;
790 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX, 0);
791 #ifdef LEAF_REG_REMAP
792 if (leaf_function)
793 leaf_renumber_regs_insn (DECL_RTL (decl));
794 #endif
795 value = DECL_RTL (decl);
797 /* Don't mention a variable at all
798 if it was completely optimized into nothingness.
800 If DECL was from an inline function, then its rtl
801 is not identically the rtl that was used in this
802 particular compilation. */
803 if (GET_CODE (value) == REG)
805 regno = REGNO (DECL_RTL (decl));
806 if (regno >= FIRST_PSEUDO_REGISTER)
807 return;
809 else if (GET_CODE (value) == SUBREG)
811 int offset = 0;
812 while (GET_CODE (value) == SUBREG)
814 offset += SUBREG_WORD (value);
815 value = SUBREG_REG (value);
817 if (GET_CODE (value) == REG)
819 regno = REGNO (value);
820 if (regno >= FIRST_PSEUDO_REGISTER)
821 return;
822 regno += offset;
824 alter_subreg (DECL_RTL (decl));
825 value = DECL_RTL (decl);
827 /* Don't output anything if an auto variable
828 gets RTL that is static.
829 GAS version 2.2 can't handle such output. */
830 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
831 && ! TREE_STATIC (decl))
832 return;
834 /* Emit any structure, union, or enum type that has not been output.
835 This occurs for tag-less structs (et al) used to declare variables
836 within functions. */
837 if (TREE_CODE (type) == ENUMERAL_TYPE
838 || TREE_CODE (type) == RECORD_TYPE
839 || TREE_CODE (type) == UNION_TYPE
840 || TREE_CODE (type) == QUAL_UNION_TYPE)
842 if (TYPE_SIZE (type) != 0 /* not a forward reference */
843 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
844 sdbout_one_type (type);
847 /* Defer SDB information for top-level initialized variables! */
848 if (! local
849 && GET_CODE (value) == MEM
850 && DECL_INITIAL (decl))
851 return;
853 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
854 For now, avoid crashing. */
855 if (DECL_NAME (decl) == NULL_TREE)
856 return;
858 /* Record the name for, starting a symtab entry. */
859 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
861 if (GET_CODE (value) == MEM
862 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
864 PUT_SDB_DEF (name);
865 if (TREE_PUBLIC (decl))
867 PUT_SDB_VAL (XEXP (value, 0));
868 PUT_SDB_SCL (C_EXT);
870 else
872 PUT_SDB_VAL (XEXP (value, 0));
873 PUT_SDB_SCL (C_STAT);
876 else if (regno >= 0)
878 PUT_SDB_DEF (name);
879 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
880 PUT_SDB_SCL (C_REG);
882 else if (GET_CODE (value) == MEM
883 && (GET_CODE (XEXP (value, 0)) == MEM
884 || (GET_CODE (XEXP (value, 0)) == REG
885 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
886 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
887 /* If the value is indirect by memory or by a register
888 that isn't the frame pointer
889 then it means the object is variable-sized and address through
890 that register or stack slot. COFF has no way to represent this
891 so all we can do is output the variable as a pointer. */
893 PUT_SDB_DEF (name);
894 if (GET_CODE (XEXP (value, 0)) == REG)
896 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
897 PUT_SDB_SCL (C_REG);
899 else
901 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
902 (CONST_INT...)))).
903 We want the value of that CONST_INT. */
904 /* Encore compiler hates a newline in a macro arg, it seems. */
905 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
906 (XEXP (XEXP (value, 0), 0)));
907 PUT_SDB_SCL (C_AUTO);
910 type = build_pointer_type (TREE_TYPE (decl));
912 else if (GET_CODE (value) == MEM
913 && ((GET_CODE (XEXP (value, 0)) == PLUS
914 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
915 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
916 /* This is for variables which are at offset zero from
917 the frame pointer. This happens on the Alpha.
918 Non-frame pointer registers are excluded above. */
919 || (GET_CODE (XEXP (value, 0)) == REG)))
921 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
922 or (MEM (REG...)). We want the value of that CONST_INT
923 or zero. */
924 PUT_SDB_DEF (name);
925 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
926 PUT_SDB_SCL (C_AUTO);
928 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
930 /* Handle an obscure case which can arise when optimizing and
931 when there are few available registers. (This is *always*
932 the case for i386/i486 targets). The DECL_RTL looks like
933 (MEM (CONST ...)) even though this variable is a local `auto'
934 or a local `register' variable. In effect, what has happened
935 is that the reload pass has seen that all assignments and
936 references for one such a local variable can be replaced by
937 equivalent assignments and references to some static storage
938 variable, thereby avoiding the need for a register. In such
939 cases we're forced to lie to debuggers and tell them that
940 this variable was itself `static'. */
941 PUT_SDB_DEF (name);
942 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
943 PUT_SDB_SCL (C_STAT);
945 else
947 /* It is something we don't know how to represent for SDB. */
948 return;
950 break;
952 PUT_SDB_TYPE (plain_type (type));
953 PUT_SDB_ENDEF;
956 /* Output SDB information for a top-level initialized variable
957 that has been delayed. */
959 void
960 sdbout_toplevel_data (decl)
961 tree decl;
963 tree type = TREE_TYPE (decl);
965 if (DECL_IGNORED_P (decl))
966 return;
968 if (! (TREE_CODE (decl) == VAR_DECL
969 && GET_CODE (DECL_RTL (decl)) == MEM
970 && DECL_INITIAL (decl)))
971 abort ();
973 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
974 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
975 if (TREE_PUBLIC (decl))
977 PUT_SDB_SCL (C_EXT);
979 else
981 PUT_SDB_SCL (C_STAT);
983 PUT_SDB_TYPE (plain_type (type));
984 PUT_SDB_ENDEF;
987 #ifdef SDB_ALLOW_FORWARD_REFERENCES
989 /* Machinery to record and output anonymous types. */
991 static tree anonymous_types;
993 static void
994 sdbout_queue_anonymous_type (type)
995 tree type;
997 anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
1000 static void
1001 sdbout_dequeue_anonymous_types ()
1003 register tree types, link;
1005 while (anonymous_types)
1007 types = nreverse (anonymous_types);
1008 anonymous_types = NULL_TREE;
1010 for (link = types; link; link = TREE_CHAIN (link))
1012 register tree type = TREE_VALUE (link);
1014 if (type && ! TREE_ASM_WRITTEN (type))
1015 sdbout_one_type (type);
1020 #endif
1022 /* Given a chain of ..._TYPE nodes, all of which have names,
1023 output definitions of those names, as typedefs. */
1025 void
1026 sdbout_types (types)
1027 register tree types;
1029 register tree link;
1031 for (link = types; link; link = TREE_CHAIN (link))
1032 sdbout_one_type (link);
1034 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1035 sdbout_dequeue_anonymous_types ();
1036 #endif
1039 static void
1040 sdbout_type (type)
1041 tree type;
1043 if (type == error_mark_node)
1044 type = integer_type_node;
1045 PUT_SDB_TYPE (plain_type (type));
1048 /* Output types of the fields of type TYPE, if they are structs.
1050 Formerly did not chase through pointer types, since that could be circular.
1051 They must come before TYPE, since forward refs are not allowed.
1052 Now james@bigtex.cactus.org says to try them. */
1054 static void
1055 sdbout_field_types (type)
1056 tree type;
1058 tree tail;
1059 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1060 if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
1061 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1062 else
1063 sdbout_one_type (TREE_TYPE (tail));
1066 /* Use this to put out the top level defined record and union types
1067 for later reference. If this is a struct with a name, then put that
1068 name out. Other unnamed structs will have .xxfake labels generated so
1069 that they may be referred to later.
1070 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1071 It may NOT be called recursively. */
1073 static void
1074 sdbout_one_type (type)
1075 tree type;
1077 if (current_function_decl != NULL_TREE
1078 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1079 ; /* Don't change section amid function. */
1080 else
1081 text_section ();
1083 switch (TREE_CODE (type))
1085 case RECORD_TYPE:
1086 case UNION_TYPE:
1087 case QUAL_UNION_TYPE:
1088 case ENUMERAL_TYPE:
1089 type = TYPE_MAIN_VARIANT (type);
1090 /* Don't output a type twice. */
1091 if (TREE_ASM_WRITTEN (type))
1092 /* James said test TREE_ASM_BEING_WRITTEN here. */
1093 return;
1095 /* Output nothing if type is not yet defined. */
1096 if (TYPE_SIZE (type) == 0)
1097 return;
1099 TREE_ASM_WRITTEN (type) = 1;
1100 #if 1
1101 /* This is reputed to cause trouble with the following case,
1102 but perhaps checking TYPE_SIZE above will fix it. */
1104 /* Here is a test case:
1106 struct foo {
1107 struct badstr *bbb;
1108 } forwardref;
1110 typedef struct intermediate {
1111 int aaaa;
1112 } intermediate_ref;
1114 typedef struct badstr {
1115 int ccccc;
1116 } badtype; */
1118 #if 0
1119 TREE_ASM_BEING_WRITTEN (type) = 1;
1120 #endif
1121 /* This change, which ought to make better output,
1122 used to make the COFF assembler unhappy.
1123 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1124 /* Before really doing anything, output types we want to refer to. */
1125 /* Note that in version 1 the following two lines
1126 are not used if forward references are in use. */
1127 if (TREE_CODE (type) != ENUMERAL_TYPE)
1128 sdbout_field_types (type);
1129 #if 0
1130 TREE_ASM_WRITTEN (type) = 1;
1131 #endif
1132 #endif
1134 /* Output a structure type. */
1136 int size = int_size_in_bytes (type);
1137 int member_scl;
1138 tree tem;
1139 int i, n_baseclasses = 0;
1141 /* Record the type tag, but not in its permanent place just yet. */
1142 sdbout_record_type_name (type);
1144 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1146 switch (TREE_CODE (type))
1148 case UNION_TYPE:
1149 case QUAL_UNION_TYPE:
1150 PUT_SDB_SCL (C_UNTAG);
1151 PUT_SDB_TYPE (T_UNION);
1152 member_scl = C_MOU;
1153 break;
1155 case RECORD_TYPE:
1156 PUT_SDB_SCL (C_STRTAG);
1157 PUT_SDB_TYPE (T_STRUCT);
1158 member_scl = C_MOS;
1159 break;
1161 case ENUMERAL_TYPE:
1162 PUT_SDB_SCL (C_ENTAG);
1163 PUT_SDB_TYPE (T_ENUM);
1164 member_scl = C_MOE;
1165 break;
1168 PUT_SDB_SIZE (size);
1169 PUT_SDB_ENDEF;
1171 /* Print out the base class information with fields
1172 named after the types they hold. */
1173 if (TYPE_BINFO (type)
1174 && TYPE_BINFO_BASETYPES (type))
1175 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1176 for (i = 0; i < n_baseclasses; i++)
1178 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1179 tree child_type = BINFO_TYPE (child);
1180 tree child_type_name;
1181 if (TYPE_NAME (child_type) == 0)
1182 continue;
1183 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1184 child_type_name = TYPE_NAME (child_type);
1185 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1187 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1188 if (child_type_name && template_name_p (child_type_name))
1189 child_type_name
1190 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1192 else
1193 continue;
1195 CONTIN;
1196 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1197 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
1198 PUT_SDB_SCL (member_scl);
1199 sdbout_type (BINFO_TYPE (child));
1200 PUT_SDB_ENDEF;
1203 /* output the individual fields */
1205 if (TREE_CODE (type) == ENUMERAL_TYPE)
1206 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1208 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1209 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1210 PUT_SDB_SCL (C_MOE);
1211 PUT_SDB_TYPE (T_MOE);
1212 PUT_SDB_ENDEF;
1215 else /* record or union type */
1216 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1217 /* Output the name, type, position (in bits), size (in bits)
1218 of each field. */
1220 /* Omit here the nameless fields that are used to skip bits.
1221 Also omit fields with variable size or position.
1222 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1223 if (TREE_CODE (tem) == FIELD_DECL
1224 && DECL_NAME (tem) != 0
1225 && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
1226 && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
1228 char *name;
1230 CONTIN;
1231 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
1232 PUT_SDB_DEF (name);
1233 if (DECL_BIT_FIELD_TYPE (tem))
1235 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
1236 PUT_SDB_SCL (C_FIELD);
1237 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1238 PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
1240 else
1242 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
1243 / BITS_PER_UNIT);
1244 PUT_SDB_SCL (member_scl);
1245 sdbout_type (TREE_TYPE (tem));
1247 PUT_SDB_ENDEF;
1249 /* output end of a structure,union, or enumeral definition */
1251 PUT_SDB_PLAIN_DEF ("eos");
1252 PUT_SDB_INT_VAL (size);
1253 PUT_SDB_SCL (C_EOS);
1254 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1255 PUT_SDB_SIZE (size);
1256 PUT_SDB_ENDEF;
1257 break;
1262 /* The following two functions output definitions of function parameters.
1263 Each parameter gets a definition locating it in the parameter list.
1264 Each parameter that is a register variable gets a second definition
1265 locating it in the register.
1267 Printing or argument lists in gdb uses the definitions that
1268 locate in the parameter list. But reference to the variable in
1269 expressions uses preferentially the definition as a register. */
1271 /* Output definitions, referring to storage in the parmlist,
1272 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1274 static void
1275 sdbout_parms (parms)
1276 tree parms;
1278 for (; parms; parms = TREE_CHAIN (parms))
1279 if (DECL_NAME (parms))
1281 int current_sym_value = 0;
1282 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1284 if (name == 0 || *name == 0)
1285 name = gen_fake_label ();
1287 /* Perform any necessary register eliminations on the parameter's rtl,
1288 so that the debugging output will be accurate. */
1289 DECL_INCOMING_RTL (parms) =
1290 eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX, 0);
1291 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX, 0);
1293 if (PARM_PASSED_IN_MEMORY (parms))
1295 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1296 tree type;
1298 /* ??? Here we assume that the parm address is indexed
1299 off the frame pointer or arg pointer.
1300 If that is not true, we produce meaningless results,
1301 but do not crash. */
1302 if (GET_CODE (addr) == PLUS
1303 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1304 current_sym_value = INTVAL (XEXP (addr, 1));
1305 else
1306 current_sym_value = 0;
1308 if (GET_CODE (DECL_RTL (parms)) == REG
1309 && REGNO (DECL_RTL (parms)) >= 0
1310 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1311 type = DECL_ARG_TYPE (parms);
1312 else
1314 int original_sym_value = current_sym_value;
1316 /* This is the case where the parm is passed as an int or
1317 double and it is converted to a char, short or float
1318 and stored back in the parmlist. In this case, describe
1319 the parm with the variable's declared type, and adjust
1320 the address if the least significant bytes (which we are
1321 using) are not the first ones. */
1322 if (BYTES_BIG_ENDIAN
1323 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1324 current_sym_value +=
1325 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1326 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1328 if (GET_CODE (DECL_RTL (parms)) == MEM
1329 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1330 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1331 == CONST_INT)
1332 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1333 == current_sym_value))
1334 type = TREE_TYPE (parms);
1335 else
1337 current_sym_value = original_sym_value;
1338 type = DECL_ARG_TYPE (parms);
1342 PUT_SDB_DEF (name);
1343 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1344 PUT_SDB_SCL (C_ARG);
1345 PUT_SDB_TYPE (plain_type (type));
1346 PUT_SDB_ENDEF;
1348 else if (GET_CODE (DECL_RTL (parms)) == REG)
1350 rtx best_rtl;
1351 /* Parm passed in registers and lives in registers or nowhere. */
1353 /* If parm lives in a register, use that register;
1354 pretend the parm was passed there. It would be more consistent
1355 to describe the register where the parm was passed,
1356 but in practice that register usually holds something else. */
1357 if (REGNO (DECL_RTL (parms)) >= 0
1358 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1359 best_rtl = DECL_RTL (parms);
1360 /* If the parm lives nowhere,
1361 use the register where it was passed. */
1362 else
1363 best_rtl = DECL_INCOMING_RTL (parms);
1365 PUT_SDB_DEF (name);
1366 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1367 PUT_SDB_SCL (C_REGPARM);
1368 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1369 PUT_SDB_ENDEF;
1371 else if (GET_CODE (DECL_RTL (parms)) == MEM
1372 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1374 /* Parm was passed in registers but lives on the stack. */
1376 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1377 in which case we want the value of that CONST_INT,
1378 or (MEM (REG ...)) or (MEM (MEM ...)),
1379 in which case we use a value of zero. */
1380 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1381 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1382 current_sym_value = 0;
1383 else
1384 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1386 /* Again, this assumes the offset is based on the arg pointer. */
1387 PUT_SDB_DEF (name);
1388 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1389 XEXP (DECL_RTL (parms), 0)));
1390 PUT_SDB_SCL (C_ARG);
1391 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1392 PUT_SDB_ENDEF;
1397 /* Output definitions for the places where parms live during the function,
1398 when different from where they were passed, when the parms were passed
1399 in memory.
1401 It is not useful to do this for parms passed in registers
1402 that live during the function in different registers, because it is
1403 impossible to look in the passed register for the passed value,
1404 so we use the within-the-function register to begin with.
1406 PARMS is a chain of PARM_DECL nodes. */
1408 static void
1409 sdbout_reg_parms (parms)
1410 tree parms;
1412 for (; parms; parms = TREE_CHAIN (parms))
1413 if (DECL_NAME (parms))
1415 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1417 /* Report parms that live in registers during the function
1418 but were passed in memory. */
1419 if (GET_CODE (DECL_RTL (parms)) == REG
1420 && REGNO (DECL_RTL (parms)) >= 0
1421 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1422 && PARM_PASSED_IN_MEMORY (parms))
1424 if (name == 0 || *name == 0)
1425 name = gen_fake_label ();
1426 PUT_SDB_DEF (name);
1427 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1428 PUT_SDB_SCL (C_REG);
1429 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1430 PUT_SDB_ENDEF;
1432 /* Report parms that live in memory but not where they were passed. */
1433 else if (GET_CODE (DECL_RTL (parms)) == MEM
1434 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1435 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1436 && PARM_PASSED_IN_MEMORY (parms)
1437 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1439 #if 0 /* ??? It is not clear yet what should replace this. */
1440 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1441 /* A parm declared char is really passed as an int,
1442 so it occupies the least significant bytes.
1443 On a big-endian machine those are not the low-numbered ones. */
1444 if (BYTES_BIG_ENDIAN
1445 && offset != -1
1446 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1447 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1448 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1449 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1450 #endif
1452 if (name == 0 || *name == 0)
1453 name = gen_fake_label ();
1454 PUT_SDB_DEF (name);
1455 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1456 (XEXP (DECL_RTL (parms), 0)));
1457 PUT_SDB_SCL (C_AUTO);
1458 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1459 PUT_SDB_ENDEF;
1465 /* Describe the beginning of an internal block within a function.
1466 Also output descriptions of variables defined in this block.
1468 N is the number of the block, by order of beginning, counting from 1,
1469 and not counting the outermost (function top-level) block.
1470 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1471 if the count starts at 0 for the outermost one. */
1473 void
1474 sdbout_begin_block (file, line, n)
1475 FILE *file;
1476 int line;
1477 int n;
1479 tree decl = current_function_decl;
1480 MAKE_LINE_SAFE (line);
1482 /* The SCO compiler does not emit a separate block for the function level
1483 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1484 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1485 #ifndef MIPS_DEBUGGING_INFO
1486 if (n != 1)
1487 #endif
1488 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1490 if (n == 1)
1492 /* Include the outermost BLOCK's variables in block 1. */
1493 next_block_number = 0;
1494 do_block = 0;
1495 sdbout_block (DECL_INITIAL (decl));
1497 /* If -g1, suppress all the internal symbols of functions
1498 except for arguments. */
1499 if (debug_info_level != DINFO_LEVEL_TERSE)
1501 next_block_number = 0;
1502 do_block = n;
1503 sdbout_block (DECL_INITIAL (decl));
1506 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1507 sdbout_dequeue_anonymous_types ();
1508 #endif
1511 /* Describe the end line-number of an internal block within a function. */
1513 void
1514 sdbout_end_block (file, line, n)
1515 FILE *file;
1516 int line;
1517 int n;
1519 MAKE_LINE_SAFE (line);
1521 /* The SCO compiler does not emit a separate block for the function level
1522 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1523 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1524 #ifndef MIPS_DEBUGGING_INFO
1525 if (n != 1)
1526 #endif
1527 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1530 /* Output sdb info for the current function name.
1531 Called from assemble_start_function. */
1533 void
1534 sdbout_mark_begin_function ()
1536 sdbout_symbol (current_function_decl, 0);
1539 /* Called at beginning of function body (after prologue).
1540 Record the function's starting line number, so we can output
1541 relative line numbers for the other lines.
1542 Describe beginning of outermost block.
1543 Also describe the parameter list. */
1545 void
1546 sdbout_begin_function (line)
1547 int line;
1549 sdb_begin_function_line = line - 1;
1550 PUT_SDB_FUNCTION_START (line);
1551 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1552 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1555 /* Called at end of function (before epilogue).
1556 Describe end of outermost block. */
1558 void
1559 sdbout_end_function (line)
1560 int line;
1562 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1563 sdbout_dequeue_anonymous_types ();
1564 #endif
1566 MAKE_LINE_SAFE (line);
1567 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1569 /* Indicate we are between functions, for line-number output. */
1570 sdb_begin_function_line = -1;
1573 /* Output sdb info for the absolute end of a function.
1574 Called after the epilogue is output. */
1576 void
1577 sdbout_end_epilogue ()
1579 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1580 PUT_SDB_EPILOGUE_END (name);
1583 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1584 is present. */
1586 void
1587 sdbout_label (insn)
1588 register rtx insn;
1590 PUT_SDB_DEF (LABEL_NAME (insn));
1591 PUT_SDB_VAL (insn);
1592 PUT_SDB_SCL (C_LABEL);
1593 PUT_SDB_TYPE (T_NULL);
1594 PUT_SDB_ENDEF;
1597 /* Change to reading from a new source file. */
1599 void
1600 sdbout_start_new_source_file (filename)
1601 char *filename;
1603 #ifdef MIPS_DEBUGGING_INFO
1604 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1606 n->next = current_file;
1607 n->name = filename;
1608 current_file = n;
1609 PUT_SDB_SRC_FILE (filename);
1610 #endif
1613 /* Revert to reading a previous source file. */
1615 void
1616 sdbout_resume_previous_source_file ()
1618 #ifdef MIPS_DEBUGGING_INFO
1619 struct sdb_file *next;
1621 next = current_file->next;
1622 free (current_file);
1623 current_file = next;
1624 PUT_SDB_SRC_FILE (current_file->name);
1625 #endif
1628 #endif /* SDB_DEBUGGING_INFO */