dbxout.c, [...]: Always include gstab.h, not system stab.h.
[gcc.git] / gcc / sdbout.c
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 /* mike@tredysvr.Tredydev.Unisys.COM says:
23 I modified the struct.c example and have a nm of a .o resulting from the
24 AT&T C compiler. From the example below I would conclude the following:
25
26 1. All .defs from structures are emitted as scanned. The example below
27 clearly shows the symbol table entries for BoxRec2 are after the first
28 function.
29
30 2. All functions and their locals (including statics) are emitted as scanned.
31
32 3. All nested unnamed union and structure .defs must be emitted before
33 the structure in which they are nested. The AT&T assembler is a
34 one pass beast as far as symbolics are concerned.
35
36 4. All structure .defs are emitted before the typedefs that refer to them.
37
38 5. All top level static and external variable definitions are moved to the
39 end of file with all top level statics occurring first before externs.
40
41 6. All undefined references are at the end of the file.
42 */
43
44 #include "config.h"
45
46 #ifdef SDB_DEBUGGING_INFO
47
48 #include "system.h"
49 #include "tree.h"
50 #include "rtl.h"
51 #include "regs.h"
52 #include "flags.h"
53 #include "insn-config.h"
54 #include "reload.h"
55 #include "output.h"
56 #include "toplev.h"
57 #include "ggc.h"
58 #include "tm_p.h"
59 #include "gsyms.h"
60
61 /* 1 if PARM is passed to this function in memory. */
62
63 #define PARM_PASSED_IN_MEMORY(PARM) \
64 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
65
66 /* A C expression for the integer offset value of an automatic variable
67 (C_AUTO) having address X (an RTX). */
68 #ifndef DEBUGGER_AUTO_OFFSET
69 #define DEBUGGER_AUTO_OFFSET(X) \
70 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
71 #endif
72
73 /* A C expression for the integer offset value of an argument (C_ARG)
74 having address X (an RTX). The nominal offset is OFFSET. */
75 #ifndef DEBUGGER_ARG_OFFSET
76 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
77 #endif
78
79 /* Line number of beginning of current function, minus one.
80 Negative means not in a function or not using sdb. */
81
82 int sdb_begin_function_line = -1;
83
84 /* Counter to generate unique "names" for nameless struct members. */
85
86 static int unnamed_struct_number = 0;
87
88 extern FILE *asm_out_file;
89
90 extern tree current_function_decl;
91
92 #include "sdbout.h"
93
94 static char *gen_fake_label PARAMS ((void));
95 static int plain_type PARAMS ((tree));
96 static int template_name_p PARAMS ((tree));
97 static void sdbout_record_type_name PARAMS ((tree));
98 static int plain_type_1 PARAMS ((tree, int));
99 static void sdbout_block PARAMS ((tree));
100 static void sdbout_syms PARAMS ((tree));
101 #ifdef SDB_ALLOW_FORWARD_REFERENCES
102 static void sdbout_queue_anonymous_type PARAMS ((tree));
103 static void sdbout_dequeue_anonymous_types PARAMS ((void));
104 #endif
105 static void sdbout_type PARAMS ((tree));
106 static void sdbout_field_types PARAMS ((tree));
107 static void sdbout_one_type PARAMS ((tree));
108 static void sdbout_parms PARAMS ((tree));
109 static void sdbout_reg_parms PARAMS ((tree));
110 \f
111 /* Random macros describing parts of SDB data. */
112
113 /* Put something here if lines get too long */
114 #define CONTIN
115
116 /* Default value of delimiter is ";". */
117 #ifndef SDB_DELIM
118 #define SDB_DELIM ";"
119 #endif
120
121 /* Maximum number of dimensions the assembler will allow. */
122 #ifndef SDB_MAX_DIM
123 #define SDB_MAX_DIM 4
124 #endif
125
126 #ifndef PUT_SDB_SCL
127 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
128 #endif
129
130 #ifndef PUT_SDB_INT_VAL
131 #define PUT_SDB_INT_VAL(a) \
132 do { \
133 fputs ("\t.val\t", asm_out_file); \
134 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
135 fprintf (asm_out_file, "%s", SDB_DELIM); \
136 } while (0)
137
138 #endif
139
140 #ifndef PUT_SDB_VAL
141 #define PUT_SDB_VAL(a) \
142 ( fputs ("\t.val\t", asm_out_file), \
143 output_addr_const (asm_out_file, (a)), \
144 fprintf (asm_out_file, SDB_DELIM))
145 #endif
146
147 #ifndef PUT_SDB_DEF
148 #define PUT_SDB_DEF(a) \
149 do { fprintf (asm_out_file, "\t.def\t"); \
150 assemble_name (asm_out_file, a); \
151 fprintf (asm_out_file, SDB_DELIM); } while (0)
152 #endif
153
154 #ifndef PUT_SDB_PLAIN_DEF
155 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
156 #endif
157
158 #ifndef PUT_SDB_ENDEF
159 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
160 #endif
161
162 #ifndef PUT_SDB_TYPE
163 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
164 #endif
165
166 #ifndef PUT_SDB_SIZE
167 #define PUT_SDB_SIZE(a) \
168 do { \
169 fputs ("\t.size\t", asm_out_file); \
170 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
171 fprintf (asm_out_file, "%s", SDB_DELIM); \
172 } while(0)
173 #endif
174
175 #ifndef PUT_SDB_START_DIM
176 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
177 #endif
178
179 #ifndef PUT_SDB_NEXT_DIM
180 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
181 #endif
182
183 #ifndef PUT_SDB_LAST_DIM
184 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
185 #endif
186
187 #ifndef PUT_SDB_TAG
188 #define PUT_SDB_TAG(a) \
189 do { fprintf (asm_out_file, "\t.tag\t"); \
190 assemble_name (asm_out_file, a); \
191 fprintf (asm_out_file, SDB_DELIM); } while (0)
192 #endif
193
194 #ifndef PUT_SDB_BLOCK_START
195 #define PUT_SDB_BLOCK_START(LINE) \
196 fprintf (asm_out_file, \
197 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
198 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
199 #endif
200
201 #ifndef PUT_SDB_BLOCK_END
202 #define PUT_SDB_BLOCK_END(LINE) \
203 fprintf (asm_out_file, \
204 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
205 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
206 #endif
207
208 #ifndef PUT_SDB_FUNCTION_START
209 #define PUT_SDB_FUNCTION_START(LINE) \
210 fprintf (asm_out_file, \
211 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
212 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
213 #endif
214
215 #ifndef PUT_SDB_FUNCTION_END
216 #define PUT_SDB_FUNCTION_END(LINE) \
217 fprintf (asm_out_file, \
218 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
219 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
220 #endif
221
222 #ifndef PUT_SDB_EPILOGUE_END
223 #define PUT_SDB_EPILOGUE_END(NAME) \
224 do { fprintf (asm_out_file, "\t.def\t"); \
225 assemble_name (asm_out_file, NAME); \
226 fprintf (asm_out_file, \
227 "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", \
228 SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
229 #endif
230
231 #ifndef SDB_GENERATE_FAKE
232 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
233 sprintf ((BUFFER), ".%dfake", (NUMBER));
234 #endif
235
236 /* Return the sdb tag identifier string for TYPE
237 if TYPE has already been defined; otherwise return a null pointer. */
238
239 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
240
241 /* Set the sdb tag identifier string for TYPE to NAME. */
242
243 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
244 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
245
246 /* Return the name (a string) of the struct, union or enum tag
247 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
248
249 #define TAG_NAME(link) \
250 (((link) && TREE_PURPOSE ((link)) \
251 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
252 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
253
254 /* Ensure we don't output a negative line number. */
255 #define MAKE_LINE_SAFE(line) \
256 if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
257
258 /* Perform linker optimization of merging header file definitions together
259 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
260 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
261 the optimization just won't be done. The native assembler already has the
262 necessary support. */
263
264 #ifdef MIPS_DEBUGGING_INFO
265
266 #ifndef PUT_SDB_SRC_FILE
267 #define PUT_SDB_SRC_FILE(FILENAME) \
268 output_file_directive (asm_out_file, (FILENAME))
269 #endif
270
271 /* ECOFF linkers have an optimization that does the same kind of thing as
272 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
273 executable. To achieve this, GCC must output a .file for each file
274 name change. */
275
276 /* This is a stack of input files. */
277
278 struct sdb_file
279 {
280 struct sdb_file *next;
281 const char *name;
282 };
283
284 /* This is the top of the stack. */
285
286 static struct sdb_file *current_file;
287
288 #endif /* MIPS_DEBUGGING_INFO */
289 \f
290
291 #if 0
292
293 /* return the tag identifier for type
294 */
295
296 char *
297 tag_of_ru_type (type,link)
298 tree type,link;
299 {
300 if (TYPE_SYMTAB_ADDRESS (type))
301 return TYPE_SYMTAB_ADDRESS (type);
302 if (link && TREE_PURPOSE (link)
303 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
304 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
305 else
306 return (char *) TYPE_SYMTAB_ADDRESS (type);
307 }
308 #endif
309
310 /* Return a unique string to name an anonymous type. */
311
312 static char *
313 gen_fake_label ()
314 {
315 char label[10];
316 char *labelstr;
317 SDB_GENERATE_FAKE (label, unnamed_struct_number);
318 unnamed_struct_number++;
319 labelstr = (char *) permalloc (strlen (label) + 1);
320 strcpy (labelstr, label);
321 return labelstr;
322 }
323 \f
324 /* Return the number which describes TYPE for SDB.
325 For pointers, etc., this function is recursive.
326 Each record, union or enumeral type must already have had a
327 tag number output. */
328
329 /* The number is given by d6d5d4d3d2d1bbbb
330 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
331 Thus, char *foo () has bbbb=T_CHAR
332 d1=D_FCN
333 d2=D_PTR
334 N_BTMASK= 017 1111 basic type field.
335 N_TSHIFT= 2 derived type shift
336 N_BTSHFT= 4 Basic type shift */
337
338 /* Produce the number that describes a pointer, function or array type.
339 PREV is the number describing the target, value or element type.
340 DT_type describes how to transform that type. */
341 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
342 ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT) \
343 | ((int)DT_type << (int)N_BTSHFT) \
344 | ((PREV) & (int)N_BTMASK))
345
346 /* Number of elements used in sdb_dims. */
347 static int sdb_n_dims = 0;
348
349 /* Table of array dimensions of current type. */
350 static int sdb_dims[SDB_MAX_DIM];
351
352 /* Size of outermost array currently being processed. */
353 static int sdb_type_size = -1;
354
355 static int
356 plain_type (type)
357 tree type;
358 {
359 int val = plain_type_1 (type, 0);
360
361 /* If we have already saved up some array dimensions, print them now. */
362 if (sdb_n_dims > 0)
363 {
364 int i;
365 PUT_SDB_START_DIM;
366 for (i = sdb_n_dims - 1; i > 0; i--)
367 PUT_SDB_NEXT_DIM (sdb_dims[i]);
368 PUT_SDB_LAST_DIM (sdb_dims[0]);
369 sdb_n_dims = 0;
370
371 sdb_type_size = int_size_in_bytes (type);
372 /* Don't kill sdb if type is not laid out or has variable size. */
373 if (sdb_type_size < 0)
374 sdb_type_size = 0;
375 }
376 /* If we have computed the size of an array containing this type,
377 print it now. */
378 if (sdb_type_size >= 0)
379 {
380 PUT_SDB_SIZE (sdb_type_size);
381 sdb_type_size = -1;
382 }
383 return val;
384 }
385
386 static int
387 template_name_p (name)
388 tree name;
389 {
390 register const char *ptr = IDENTIFIER_POINTER (name);
391 while (*ptr && *ptr != '<')
392 ptr++;
393
394 return *ptr != '\0';
395 }
396
397 static void
398 sdbout_record_type_name (type)
399 tree type;
400 {
401 const char *name = 0;
402 int no_name;
403
404 if (KNOWN_TYPE_TAG (type))
405 return;
406
407 if (TYPE_NAME (type) != 0)
408 {
409 tree t = 0;
410 /* Find the IDENTIFIER_NODE for the type name. */
411 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
412 t = TYPE_NAME (type);
413 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
414 {
415 t = DECL_NAME (TYPE_NAME (type));
416 /* The DECL_NAME for templates includes "<>", which breaks
417 most assemblers. Use its assembler name instead, which
418 has been mangled into being safe. */
419 if (t && template_name_p (t))
420 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
421 }
422
423 /* Now get the name as a string, or invent one. */
424 if (t != NULL_TREE)
425 name = IDENTIFIER_POINTER (t);
426 }
427
428 no_name = (name == 0 || *name == 0);
429 if (no_name)
430 name = gen_fake_label ();
431
432 SET_KNOWN_TYPE_TAG (type, name);
433 #ifdef SDB_ALLOW_FORWARD_REFERENCES
434 if (no_name)
435 sdbout_queue_anonymous_type (type);
436 #endif
437 }
438
439 /* Return the .type value for type TYPE.
440
441 LEVEL indicates how many levels deep we have recursed into the type.
442 The SDB debug format can only represent 6 derived levels of types.
443 After that, we must output inaccurate debug info. We deliberately
444 stop before the 7th level, so that ADA recursive types will not give an
445 infinite loop. */
446
447 static int
448 plain_type_1 (type, level)
449 tree type;
450 int level;
451 {
452 if (type == 0)
453 type = void_type_node;
454 else if (type == error_mark_node)
455 type = integer_type_node;
456 else
457 type = TYPE_MAIN_VARIANT (type);
458
459 switch (TREE_CODE (type))
460 {
461 case VOID_TYPE:
462 return T_VOID;
463 case BOOLEAN_TYPE:
464 case INTEGER_TYPE:
465 {
466 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
467
468 /* Carefully distinguish all the standard types of C,
469 without messing up if the language is not C.
470 Note that we check only for the names that contain spaces;
471 other names might occur by coincidence in other languages. */
472 if (TYPE_NAME (type) != 0
473 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
474 && DECL_NAME (TYPE_NAME (type)) != 0
475 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
476 {
477 const char *name
478 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
479
480 if (!strcmp (name, "char"))
481 return T_CHAR;
482 if (!strcmp (name, "unsigned char"))
483 return T_UCHAR;
484 if (!strcmp (name, "signed char"))
485 return T_CHAR;
486 if (!strcmp (name, "int"))
487 return T_INT;
488 if (!strcmp (name, "unsigned int"))
489 return T_UINT;
490 if (!strcmp (name, "short int"))
491 return T_SHORT;
492 if (!strcmp (name, "short unsigned int"))
493 return T_USHORT;
494 if (!strcmp (name, "long int"))
495 return T_LONG;
496 if (!strcmp (name, "long unsigned int"))
497 return T_ULONG;
498 }
499
500 if (size == INT_TYPE_SIZE)
501 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
502 if (size == CHAR_TYPE_SIZE)
503 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
504 if (size == SHORT_TYPE_SIZE)
505 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
506 if (size == LONG_TYPE_SIZE)
507 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
508 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
509 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
510 return 0;
511 }
512
513 case REAL_TYPE:
514 {
515 int precision = TYPE_PRECISION (type);
516 if (precision == FLOAT_TYPE_SIZE)
517 return T_FLOAT;
518 if (precision == DOUBLE_TYPE_SIZE)
519 return T_DOUBLE;
520 #ifdef EXTENDED_SDB_BASIC_TYPES
521 if (precision == LONG_DOUBLE_TYPE_SIZE)
522 return T_LNGDBL;
523 #else
524 if (precision == LONG_DOUBLE_TYPE_SIZE)
525 return T_DOUBLE; /* better than nothing */
526 #endif
527 return 0;
528 }
529
530 case ARRAY_TYPE:
531 {
532 int m;
533 if (level >= 6)
534 return T_VOID;
535 else
536 m = plain_type_1 (TREE_TYPE (type), level+1);
537 if (sdb_n_dims < SDB_MAX_DIM)
538 sdb_dims[sdb_n_dims++]
539 = (TYPE_DOMAIN (type)
540 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
541 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
542 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
543 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
544 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
545 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
546 : 0);
547
548 return PUSH_DERIVED_LEVEL (DT_ARY, m);
549 }
550
551 case RECORD_TYPE:
552 case UNION_TYPE:
553 case QUAL_UNION_TYPE:
554 case ENUMERAL_TYPE:
555 {
556 char *tag;
557 #ifdef SDB_ALLOW_FORWARD_REFERENCES
558 sdbout_record_type_name (type);
559 #endif
560 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
561 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
562 #ifdef SDB_ALLOW_FORWARD_REFERENCES
563 || TYPE_MODE (type) != VOIDmode
564 #endif
565 )
566 #endif
567 {
568 /* Output the referenced structure tag name
569 only if the .def has already been finished.
570 At least on 386, the Unix assembler
571 cannot handle forward references to tags. */
572 /* But the 88100, it requires them, sigh... */
573 /* And the MIPS requires unknown refs as well... */
574 tag = KNOWN_TYPE_TAG (type);
575 PUT_SDB_TAG (tag);
576 /* These 3 lines used to follow the close brace.
577 However, a size of 0 without a tag implies a tag of 0,
578 so if we don't know a tag, we can't mention the size. */
579 sdb_type_size = int_size_in_bytes (type);
580 if (sdb_type_size < 0)
581 sdb_type_size = 0;
582 }
583 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
584 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
585 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
586 : T_ENUM);
587 }
588 case POINTER_TYPE:
589 case REFERENCE_TYPE:
590 {
591 int m;
592 if (level >= 6)
593 return T_VOID;
594 else
595 m = plain_type_1 (TREE_TYPE (type), level+1);
596 return PUSH_DERIVED_LEVEL (DT_PTR, m);
597 }
598 case FUNCTION_TYPE:
599 case METHOD_TYPE:
600 {
601 int m;
602 if (level >= 6)
603 return T_VOID;
604 else
605 m = plain_type_1 (TREE_TYPE (type), level+1);
606 return PUSH_DERIVED_LEVEL (DT_FCN, m);
607 }
608 default:
609 return 0;
610 }
611 }
612 \f
613 /* Output the symbols defined in block number DO_BLOCK.
614
615 This function works by walking the tree structure of blocks,
616 counting blocks until it finds the desired block. */
617
618 static int do_block = 0;
619
620 static void
621 sdbout_block (block)
622 register tree block;
623 {
624 while (block)
625 {
626 /* Ignore blocks never expanded or otherwise marked as real. */
627 if (TREE_USED (block))
628 {
629 /* When we reach the specified block, output its symbols. */
630 if (BLOCK_NUMBER (block) == do_block)
631 sdbout_syms (BLOCK_VARS (block));
632
633 /* If we are past the specified block, stop the scan. */
634 if (BLOCK_NUMBER (block) > do_block)
635 return;
636
637 /* Scan the blocks within this block. */
638 sdbout_block (BLOCK_SUBBLOCKS (block));
639 }
640
641 block = BLOCK_CHAIN (block);
642 }
643 }
644 \f
645 /* Call sdbout_symbol on each decl in the chain SYMS. */
646
647 static void
648 sdbout_syms (syms)
649 tree syms;
650 {
651 while (syms)
652 {
653 if (TREE_CODE (syms) != LABEL_DECL)
654 sdbout_symbol (syms, 1);
655 syms = TREE_CHAIN (syms);
656 }
657 }
658
659 /* Output SDB information for a symbol described by DECL.
660 LOCAL is nonzero if the symbol is not file-scope. */
661
662 void
663 sdbout_symbol (decl, local)
664 tree decl;
665 int local;
666 {
667 tree type = TREE_TYPE (decl);
668 tree context = NULL_TREE;
669 rtx value;
670 int regno = -1;
671 const char *name;
672
673 sdbout_one_type (type);
674
675 #if 0 /* This loses when functions are marked to be ignored,
676 which happens in the C++ front end. */
677 if (DECL_IGNORED_P (decl))
678 return;
679 #endif
680
681 switch (TREE_CODE (decl))
682 {
683 case CONST_DECL:
684 /* Enum values are defined by defining the enum type. */
685 return;
686
687 case FUNCTION_DECL:
688 /* Don't mention a nested function under its parent. */
689 context = decl_function_context (decl);
690 if (context == current_function_decl)
691 return;
692 /* Check DECL_INITIAL to distinguish declarations from definitions.
693 Don't output debug info here for declarations; they will have
694 a DECL_INITIAL value of 0. */
695 if (! DECL_INITIAL (decl))
696 return;
697 if (GET_CODE (DECL_RTL (decl)) != MEM
698 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
699 return;
700 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
701 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
702 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
703 break;
704
705 case TYPE_DECL:
706 /* Done with tagged types. */
707 if (DECL_NAME (decl) == 0)
708 return;
709 if (DECL_IGNORED_P (decl))
710 return;
711
712 /* Output typedef name. */
713 if (template_name_p (DECL_NAME (decl)))
714 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
715 else
716 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
717 PUT_SDB_SCL (C_TPDEF);
718 break;
719
720 case PARM_DECL:
721 /* Parm decls go in their own separate chains
722 and are output by sdbout_reg_parms and sdbout_parms. */
723 abort ();
724
725 case VAR_DECL:
726 /* Don't mention a variable that is external.
727 Let the file that defines it describe it. */
728 if (DECL_EXTERNAL (decl))
729 return;
730
731 /* Ignore __FUNCTION__, etc. */
732 if (DECL_IGNORED_P (decl))
733 return;
734
735 /* If there was an error in the declaration, don't dump core
736 if there is no RTL associated with the variable doesn't
737 exist. */
738 if (!DECL_RTL_SET_P (decl))
739 return;
740
741 SET_DECL_RTL (decl,
742 eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
743 #ifdef LEAF_REG_REMAP
744 if (current_function_uses_only_leaf_regs)
745 leaf_renumber_regs_insn (DECL_RTL (decl));
746 #endif
747 value = DECL_RTL (decl);
748
749 /* Don't mention a variable at all
750 if it was completely optimized into nothingness.
751
752 If DECL was from an inline function, then its rtl
753 is not identically the rtl that was used in this
754 particular compilation. */
755 if (GET_CODE (value) == REG)
756 {
757 regno = REGNO (DECL_RTL (decl));
758 if (regno >= FIRST_PSEUDO_REGISTER)
759 return;
760 }
761 else if (GET_CODE (value) == SUBREG)
762 {
763 int offset = 0;
764
765 while (GET_CODE (value) == SUBREG)
766 value = SUBREG_REG (value);
767 if (GET_CODE (value) == REG)
768 {
769 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
770 return;
771 }
772 regno = REGNO (alter_subreg (DECL_RTL (decl)));
773 value = DECL_RTL (decl);
774 }
775 /* Don't output anything if an auto variable
776 gets RTL that is static.
777 GAS version 2.2 can't handle such output. */
778 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
779 && ! TREE_STATIC (decl))
780 return;
781
782 /* Emit any structure, union, or enum type that has not been output.
783 This occurs for tag-less structs (et al) used to declare variables
784 within functions. */
785 if (TREE_CODE (type) == ENUMERAL_TYPE
786 || TREE_CODE (type) == RECORD_TYPE
787 || TREE_CODE (type) == UNION_TYPE
788 || TREE_CODE (type) == QUAL_UNION_TYPE)
789 {
790 if (COMPLETE_TYPE_P (type) /* not a forward reference */
791 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
792 sdbout_one_type (type);
793 }
794
795 /* Defer SDB information for top-level initialized variables! */
796 if (! local
797 && GET_CODE (value) == MEM
798 && DECL_INITIAL (decl))
799 return;
800
801 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
802 For now, avoid crashing. */
803 if (DECL_NAME (decl) == NULL_TREE)
804 return;
805
806 /* Record the name for, starting a symtab entry. */
807 if (local)
808 name = IDENTIFIER_POINTER (DECL_NAME (decl));
809 else
810 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
811
812 if (GET_CODE (value) == MEM
813 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
814 {
815 PUT_SDB_DEF (name);
816 if (TREE_PUBLIC (decl))
817 {
818 PUT_SDB_VAL (XEXP (value, 0));
819 PUT_SDB_SCL (C_EXT);
820 }
821 else
822 {
823 PUT_SDB_VAL (XEXP (value, 0));
824 PUT_SDB_SCL (C_STAT);
825 }
826 }
827 else if (regno >= 0)
828 {
829 PUT_SDB_DEF (name);
830 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
831 PUT_SDB_SCL (C_REG);
832 }
833 else if (GET_CODE (value) == MEM
834 && (GET_CODE (XEXP (value, 0)) == MEM
835 || (GET_CODE (XEXP (value, 0)) == REG
836 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
837 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
838 /* If the value is indirect by memory or by a register
839 that isn't the frame pointer
840 then it means the object is variable-sized and address through
841 that register or stack slot. COFF has no way to represent this
842 so all we can do is output the variable as a pointer. */
843 {
844 PUT_SDB_DEF (name);
845 if (GET_CODE (XEXP (value, 0)) == REG)
846 {
847 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
848 PUT_SDB_SCL (C_REG);
849 }
850 else
851 {
852 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
853 (CONST_INT...)))).
854 We want the value of that CONST_INT. */
855 /* Encore compiler hates a newline in a macro arg, it seems. */
856 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
857 (XEXP (XEXP (value, 0), 0)));
858 PUT_SDB_SCL (C_AUTO);
859 }
860
861 /* Effectively do build_pointer_type, but don't cache this type,
862 since it might be temporary whereas the type it points to
863 might have been saved for inlining. */
864 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
865 type = make_node (POINTER_TYPE);
866 TREE_TYPE (type) = TREE_TYPE (decl);
867 }
868 else if (GET_CODE (value) == MEM
869 && ((GET_CODE (XEXP (value, 0)) == PLUS
870 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
871 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
872 /* This is for variables which are at offset zero from
873 the frame pointer. This happens on the Alpha.
874 Non-frame pointer registers are excluded above. */
875 || (GET_CODE (XEXP (value, 0)) == REG)))
876 {
877 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
878 or (MEM (REG...)). We want the value of that CONST_INT
879 or zero. */
880 PUT_SDB_DEF (name);
881 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
882 PUT_SDB_SCL (C_AUTO);
883 }
884 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
885 {
886 /* Handle an obscure case which can arise when optimizing and
887 when there are few available registers. (This is *always*
888 the case for i386/i486 targets). The DECL_RTL looks like
889 (MEM (CONST ...)) even though this variable is a local `auto'
890 or a local `register' variable. In effect, what has happened
891 is that the reload pass has seen that all assignments and
892 references for one such a local variable can be replaced by
893 equivalent assignments and references to some static storage
894 variable, thereby avoiding the need for a register. In such
895 cases we're forced to lie to debuggers and tell them that
896 this variable was itself `static'. */
897 PUT_SDB_DEF (name);
898 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
899 PUT_SDB_SCL (C_STAT);
900 }
901 else
902 {
903 /* It is something we don't know how to represent for SDB. */
904 return;
905 }
906 break;
907
908 default:
909 break;
910 }
911 PUT_SDB_TYPE (plain_type (type));
912 PUT_SDB_ENDEF;
913 }
914 \f
915 /* Output SDB information for a top-level initialized variable
916 that has been delayed. */
917
918 void
919 sdbout_toplevel_data (decl)
920 tree decl;
921 {
922 tree type = TREE_TYPE (decl);
923
924 if (DECL_IGNORED_P (decl))
925 return;
926
927 if (! (TREE_CODE (decl) == VAR_DECL
928 && GET_CODE (DECL_RTL (decl)) == MEM
929 && DECL_INITIAL (decl)))
930 abort ();
931
932 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
933 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
934 if (TREE_PUBLIC (decl))
935 {
936 PUT_SDB_SCL (C_EXT);
937 }
938 else
939 {
940 PUT_SDB_SCL (C_STAT);
941 }
942 PUT_SDB_TYPE (plain_type (type));
943 PUT_SDB_ENDEF;
944 }
945 \f
946 #ifdef SDB_ALLOW_FORWARD_REFERENCES
947
948 /* Machinery to record and output anonymous types. */
949
950 static tree anonymous_types;
951
952 static void
953 sdbout_queue_anonymous_type (type)
954 tree type;
955 {
956 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
957 }
958
959 static void
960 sdbout_dequeue_anonymous_types ()
961 {
962 register tree types, link;
963
964 while (anonymous_types)
965 {
966 types = nreverse (anonymous_types);
967 anonymous_types = NULL_TREE;
968
969 for (link = types; link; link = TREE_CHAIN (link))
970 {
971 register tree type = TREE_VALUE (link);
972
973 if (type && ! TREE_ASM_WRITTEN (type))
974 sdbout_one_type (type);
975 }
976 }
977 }
978
979 #endif
980 \f
981 /* Given a chain of ..._TYPE nodes, all of which have names,
982 output definitions of those names, as typedefs. */
983
984 void
985 sdbout_types (types)
986 register tree types;
987 {
988 register tree link;
989
990 for (link = types; link; link = TREE_CHAIN (link))
991 sdbout_one_type (link);
992
993 #ifdef SDB_ALLOW_FORWARD_REFERENCES
994 sdbout_dequeue_anonymous_types ();
995 #endif
996 }
997
998 static void
999 sdbout_type (type)
1000 tree type;
1001 {
1002 if (type == error_mark_node)
1003 type = integer_type_node;
1004 PUT_SDB_TYPE (plain_type (type));
1005 }
1006
1007 /* Output types of the fields of type TYPE, if they are structs.
1008
1009 Formerly did not chase through pointer types, since that could be circular.
1010 They must come before TYPE, since forward refs are not allowed.
1011 Now james@bigtex.cactus.org says to try them. */
1012
1013 static void
1014 sdbout_field_types (type)
1015 tree type;
1016 {
1017 tree tail;
1018
1019 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1020 /* This condition should match the one for emitting the actual
1021 members below. */
1022 if (TREE_CODE (tail) == FIELD_DECL
1023 && DECL_NAME (tail)
1024 && DECL_SIZE (tail)
1025 && host_integerp (DECL_SIZE (tail), 1)
1026 && host_integerp (bit_position (tail), 0))
1027 {
1028 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1029 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1030 else
1031 sdbout_one_type (TREE_TYPE (tail));
1032 }
1033 }
1034
1035 /* Use this to put out the top level defined record and union types
1036 for later reference. If this is a struct with a name, then put that
1037 name out. Other unnamed structs will have .xxfake labels generated so
1038 that they may be referred to later.
1039 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1040 It may NOT be called recursively. */
1041
1042 static void
1043 sdbout_one_type (type)
1044 tree type;
1045 {
1046 if (current_function_decl != NULL_TREE
1047 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1048 ; /* Don't change section amid function. */
1049 else
1050 text_section ();
1051
1052 switch (TREE_CODE (type))
1053 {
1054 case RECORD_TYPE:
1055 case UNION_TYPE:
1056 case QUAL_UNION_TYPE:
1057 case ENUMERAL_TYPE:
1058 type = TYPE_MAIN_VARIANT (type);
1059 /* Don't output a type twice. */
1060 if (TREE_ASM_WRITTEN (type))
1061 /* James said test TREE_ASM_BEING_WRITTEN here. */
1062 return;
1063
1064 /* Output nothing if type is not yet defined. */
1065 if (!COMPLETE_TYPE_P (type))
1066 return;
1067
1068 TREE_ASM_WRITTEN (type) = 1;
1069 #if 1
1070 /* This is reputed to cause trouble with the following case,
1071 but perhaps checking TYPE_SIZE above will fix it. */
1072
1073 /* Here is a test case:
1074
1075 struct foo {
1076 struct badstr *bbb;
1077 } forwardref;
1078
1079 typedef struct intermediate {
1080 int aaaa;
1081 } intermediate_ref;
1082
1083 typedef struct badstr {
1084 int ccccc;
1085 } badtype; */
1086
1087 #if 0
1088 TREE_ASM_BEING_WRITTEN (type) = 1;
1089 #endif
1090 /* This change, which ought to make better output,
1091 used to make the COFF assembler unhappy.
1092 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1093 /* Before really doing anything, output types we want to refer to. */
1094 /* Note that in version 1 the following two lines
1095 are not used if forward references are in use. */
1096 if (TREE_CODE (type) != ENUMERAL_TYPE)
1097 sdbout_field_types (type);
1098 #if 0
1099 TREE_ASM_WRITTEN (type) = 1;
1100 #endif
1101 #endif
1102
1103 /* Output a structure type. */
1104 {
1105 int size = int_size_in_bytes (type);
1106 int member_scl = 0;
1107 tree tem;
1108 int i, n_baseclasses = 0;
1109
1110 /* Record the type tag, but not in its permanent place just yet. */
1111 sdbout_record_type_name (type);
1112
1113 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1114
1115 switch (TREE_CODE (type))
1116 {
1117 case UNION_TYPE:
1118 case QUAL_UNION_TYPE:
1119 PUT_SDB_SCL (C_UNTAG);
1120 PUT_SDB_TYPE (T_UNION);
1121 member_scl = C_MOU;
1122 break;
1123
1124 case RECORD_TYPE:
1125 PUT_SDB_SCL (C_STRTAG);
1126 PUT_SDB_TYPE (T_STRUCT);
1127 member_scl = C_MOS;
1128 break;
1129
1130 case ENUMERAL_TYPE:
1131 PUT_SDB_SCL (C_ENTAG);
1132 PUT_SDB_TYPE (T_ENUM);
1133 member_scl = C_MOE;
1134 break;
1135
1136 default:
1137 break;
1138 }
1139
1140 PUT_SDB_SIZE (size);
1141 PUT_SDB_ENDEF;
1142
1143 /* Print out the base class information with fields
1144 named after the types they hold. */
1145 /* This is only relevent to aggregate types. TYPE_BINFO is used
1146 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1147 case. */
1148 if (TREE_CODE (type) != ENUMERAL_TYPE)
1149 {
1150 if (TYPE_BINFO (type)
1151 && TYPE_BINFO_BASETYPES (type))
1152 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1153 for (i = 0; i < n_baseclasses; i++)
1154 {
1155 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)),
1156 i);
1157 tree child_type = BINFO_TYPE (child);
1158 tree child_type_name;
1159 if (TYPE_NAME (child_type) == 0)
1160 continue;
1161 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1162 child_type_name = TYPE_NAME (child_type);
1163 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1164 {
1165 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1166 if (child_type_name && template_name_p (child_type_name))
1167 child_type_name
1168 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1169 }
1170 else
1171 continue;
1172
1173 CONTIN;
1174 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1175 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1176 PUT_SDB_SCL (member_scl);
1177 sdbout_type (BINFO_TYPE (child));
1178 PUT_SDB_ENDEF;
1179 }
1180 }
1181
1182 /* output the individual fields */
1183
1184 if (TREE_CODE (type) == ENUMERAL_TYPE)
1185 {
1186 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1187 if (host_integerp (TREE_VALUE (tem), 0))
1188 {
1189 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1190 PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem), 0));
1191 PUT_SDB_SCL (C_MOE);
1192 PUT_SDB_TYPE (T_MOE);
1193 PUT_SDB_ENDEF;
1194 }
1195 }
1196 else /* record or union type */
1197 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1198 /* Output the name, type, position (in bits), size (in bits)
1199 of each field. */
1200
1201 /* Omit here the nameless fields that are used to skip bits.
1202 Also omit fields with variable size or position.
1203 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1204 if (TREE_CODE (tem) == FIELD_DECL
1205 && DECL_NAME (tem)
1206 && DECL_SIZE (tem)
1207 && host_integerp (DECL_SIZE (tem), 1)
1208 && host_integerp (bit_position (tem), 0))
1209 {
1210 const char *name;
1211
1212 CONTIN;
1213 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1214 PUT_SDB_DEF (name);
1215 if (DECL_BIT_FIELD_TYPE (tem))
1216 {
1217 PUT_SDB_INT_VAL (int_bit_position (tem));
1218 PUT_SDB_SCL (C_FIELD);
1219 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1220 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1221 }
1222 else
1223 {
1224 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1225 PUT_SDB_SCL (member_scl);
1226 sdbout_type (TREE_TYPE (tem));
1227 }
1228 PUT_SDB_ENDEF;
1229 }
1230 /* output end of a structure,union, or enumeral definition */
1231
1232 PUT_SDB_PLAIN_DEF ("eos");
1233 PUT_SDB_INT_VAL (size);
1234 PUT_SDB_SCL (C_EOS);
1235 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1236 PUT_SDB_SIZE (size);
1237 PUT_SDB_ENDEF;
1238 break;
1239
1240 default:
1241 break;
1242 }
1243 }
1244 }
1245 \f
1246 /* The following two functions output definitions of function parameters.
1247 Each parameter gets a definition locating it in the parameter list.
1248 Each parameter that is a register variable gets a second definition
1249 locating it in the register.
1250
1251 Printing or argument lists in gdb uses the definitions that
1252 locate in the parameter list. But reference to the variable in
1253 expressions uses preferentially the definition as a register. */
1254
1255 /* Output definitions, referring to storage in the parmlist,
1256 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1257
1258 static void
1259 sdbout_parms (parms)
1260 tree parms;
1261 {
1262 for (; parms; parms = TREE_CHAIN (parms))
1263 if (DECL_NAME (parms))
1264 {
1265 int current_sym_value = 0;
1266 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1267
1268 if (name == 0 || *name == 0)
1269 name = gen_fake_label ();
1270
1271 /* Perform any necessary register eliminations on the parameter's rtl,
1272 so that the debugging output will be accurate. */
1273 DECL_INCOMING_RTL (parms)
1274 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1275 SET_DECL_RTL (parms,
1276 eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
1277
1278 if (PARM_PASSED_IN_MEMORY (parms))
1279 {
1280 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1281 tree type;
1282
1283 /* ??? Here we assume that the parm address is indexed
1284 off the frame pointer or arg pointer.
1285 If that is not true, we produce meaningless results,
1286 but do not crash. */
1287 if (GET_CODE (addr) == PLUS
1288 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1289 current_sym_value = INTVAL (XEXP (addr, 1));
1290 else
1291 current_sym_value = 0;
1292
1293 if (GET_CODE (DECL_RTL (parms)) == REG
1294 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1295 type = DECL_ARG_TYPE (parms);
1296 else
1297 {
1298 int original_sym_value = current_sym_value;
1299
1300 /* This is the case where the parm is passed as an int or
1301 double and it is converted to a char, short or float
1302 and stored back in the parmlist. In this case, describe
1303 the parm with the variable's declared type, and adjust
1304 the address if the least significant bytes (which we are
1305 using) are not the first ones. */
1306 if (BYTES_BIG_ENDIAN
1307 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1308 current_sym_value +=
1309 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1310 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1311
1312 if (GET_CODE (DECL_RTL (parms)) == MEM
1313 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1314 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1315 == CONST_INT)
1316 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1317 == current_sym_value))
1318 type = TREE_TYPE (parms);
1319 else
1320 {
1321 current_sym_value = original_sym_value;
1322 type = DECL_ARG_TYPE (parms);
1323 }
1324 }
1325
1326 PUT_SDB_DEF (name);
1327 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1328 PUT_SDB_SCL (C_ARG);
1329 PUT_SDB_TYPE (plain_type (type));
1330 PUT_SDB_ENDEF;
1331 }
1332 else if (GET_CODE (DECL_RTL (parms)) == REG)
1333 {
1334 rtx best_rtl;
1335 /* Parm passed in registers and lives in registers or nowhere. */
1336
1337 /* If parm lives in a register, use that register;
1338 pretend the parm was passed there. It would be more consistent
1339 to describe the register where the parm was passed,
1340 but in practice that register usually holds something else. */
1341 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1342 best_rtl = DECL_RTL (parms);
1343 /* If the parm lives nowhere,
1344 use the register where it was passed. */
1345 else
1346 best_rtl = DECL_INCOMING_RTL (parms);
1347
1348 PUT_SDB_DEF (name);
1349 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1350 PUT_SDB_SCL (C_REGPARM);
1351 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1352 PUT_SDB_ENDEF;
1353 }
1354 else if (GET_CODE (DECL_RTL (parms)) == MEM
1355 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1356 {
1357 /* Parm was passed in registers but lives on the stack. */
1358
1359 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1360 in which case we want the value of that CONST_INT,
1361 or (MEM (REG ...)) or (MEM (MEM ...)),
1362 in which case we use a value of zero. */
1363 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1364 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1365 current_sym_value = 0;
1366 else
1367 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1368
1369 /* Again, this assumes the offset is based on the arg pointer. */
1370 PUT_SDB_DEF (name);
1371 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1372 XEXP (DECL_RTL (parms), 0)));
1373 PUT_SDB_SCL (C_ARG);
1374 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1375 PUT_SDB_ENDEF;
1376 }
1377 }
1378 }
1379
1380 /* Output definitions for the places where parms live during the function,
1381 when different from where they were passed, when the parms were passed
1382 in memory.
1383
1384 It is not useful to do this for parms passed in registers
1385 that live during the function in different registers, because it is
1386 impossible to look in the passed register for the passed value,
1387 so we use the within-the-function register to begin with.
1388
1389 PARMS is a chain of PARM_DECL nodes. */
1390
1391 static void
1392 sdbout_reg_parms (parms)
1393 tree parms;
1394 {
1395 for (; parms; parms = TREE_CHAIN (parms))
1396 if (DECL_NAME (parms))
1397 {
1398 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1399
1400 /* Report parms that live in registers during the function
1401 but were passed in memory. */
1402 if (GET_CODE (DECL_RTL (parms)) == REG
1403 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1404 && PARM_PASSED_IN_MEMORY (parms))
1405 {
1406 if (name == 0 || *name == 0)
1407 name = gen_fake_label ();
1408 PUT_SDB_DEF (name);
1409 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1410 PUT_SDB_SCL (C_REG);
1411 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1412 PUT_SDB_ENDEF;
1413 }
1414 /* Report parms that live in memory but not where they were passed. */
1415 else if (GET_CODE (DECL_RTL (parms)) == MEM
1416 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1417 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1418 && PARM_PASSED_IN_MEMORY (parms)
1419 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1420 {
1421 #if 0 /* ??? It is not clear yet what should replace this. */
1422 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1423 /* A parm declared char is really passed as an int,
1424 so it occupies the least significant bytes.
1425 On a big-endian machine those are not the low-numbered ones. */
1426 if (BYTES_BIG_ENDIAN
1427 && offset != -1
1428 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1429 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1430 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1431 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1432 #endif
1433 {
1434 if (name == 0 || *name == 0)
1435 name = gen_fake_label ();
1436 PUT_SDB_DEF (name);
1437 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1438 (XEXP (DECL_RTL (parms), 0)));
1439 PUT_SDB_SCL (C_AUTO);
1440 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1441 PUT_SDB_ENDEF;
1442 }
1443 }
1444 }
1445 }
1446 \f
1447 /* Describe the beginning of an internal block within a function.
1448 Also output descriptions of variables defined in this block.
1449
1450 N is the number of the block, by order of beginning, counting from 1,
1451 and not counting the outermost (function top-level) block.
1452 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1453 if the count starts at 0 for the outermost one. */
1454
1455 void
1456 sdbout_begin_block (file, line, n)
1457 FILE *file ATTRIBUTE_UNUSED;
1458 int line;
1459 int n;
1460 {
1461 tree decl = current_function_decl;
1462 MAKE_LINE_SAFE (line);
1463
1464 /* The SCO compiler does not emit a separate block for the function level
1465 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1466 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1467 #ifndef MIPS_DEBUGGING_INFO
1468 if (n != 1)
1469 #endif
1470 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1471
1472 if (n == 1)
1473 {
1474 /* Include the outermost BLOCK's variables in block 1. */
1475 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1476 sdbout_block (DECL_INITIAL (decl));
1477 }
1478 /* If -g1, suppress all the internal symbols of functions
1479 except for arguments. */
1480 if (debug_info_level != DINFO_LEVEL_TERSE)
1481 {
1482 do_block = n;
1483 sdbout_block (DECL_INITIAL (decl));
1484 }
1485
1486 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1487 sdbout_dequeue_anonymous_types ();
1488 #endif
1489 }
1490
1491 /* Describe the end line-number of an internal block within a function. */
1492
1493 void
1494 sdbout_end_block (file, line, n)
1495 FILE *file ATTRIBUTE_UNUSED;
1496 int line;
1497 int n ATTRIBUTE_UNUSED;
1498 {
1499 MAKE_LINE_SAFE (line);
1500
1501 /* The SCO compiler does not emit a separate block for the function level
1502 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1503 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1504 #ifndef MIPS_DEBUGGING_INFO
1505 if (n != 1)
1506 #endif
1507 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1508 }
1509
1510 /* Output sdb info for the current function name.
1511 Called from assemble_start_function. */
1512
1513 void
1514 sdbout_mark_begin_function ()
1515 {
1516 sdbout_symbol (current_function_decl, 0);
1517 }
1518
1519 /* Called at beginning of function body (after prologue).
1520 Record the function's starting line number, so we can output
1521 relative line numbers for the other lines.
1522 Describe beginning of outermost block.
1523 Also describe the parameter list. */
1524
1525 void
1526 sdbout_begin_function (line)
1527 int line;
1528 {
1529 sdb_begin_function_line = line - 1;
1530 PUT_SDB_FUNCTION_START (line);
1531 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1532 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1533 }
1534
1535 /* Called at end of function (before epilogue).
1536 Describe end of outermost block. */
1537
1538 void
1539 sdbout_end_function (line)
1540 int line;
1541 {
1542 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1543 sdbout_dequeue_anonymous_types ();
1544 #endif
1545
1546 MAKE_LINE_SAFE (line);
1547 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1548
1549 /* Indicate we are between functions, for line-number output. */
1550 sdb_begin_function_line = -1;
1551 }
1552
1553 /* Output sdb info for the absolute end of a function.
1554 Called after the epilogue is output. */
1555
1556 void
1557 sdbout_end_epilogue ()
1558 {
1559 PUT_SDB_EPILOGUE_END
1560 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)));
1561 }
1562
1563 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1564 is present. */
1565
1566 void
1567 sdbout_label (insn)
1568 register rtx insn;
1569 {
1570 PUT_SDB_DEF (LABEL_NAME (insn));
1571 PUT_SDB_VAL (insn);
1572 PUT_SDB_SCL (C_LABEL);
1573 PUT_SDB_TYPE (T_NULL);
1574 PUT_SDB_ENDEF;
1575 }
1576
1577 /* Change to reading from a new source file. */
1578
1579 void
1580 sdbout_start_new_source_file (filename)
1581 const char *filename ATTRIBUTE_UNUSED;
1582 {
1583 #ifdef MIPS_DEBUGGING_INFO
1584 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1585
1586 n->next = current_file;
1587 n->name = filename;
1588 current_file = n;
1589 PUT_SDB_SRC_FILE (filename);
1590 #endif
1591 }
1592
1593 /* Revert to reading a previous source file. */
1594
1595 void
1596 sdbout_resume_previous_source_file ()
1597 {
1598 #ifdef MIPS_DEBUGGING_INFO
1599 struct sdb_file *next;
1600
1601 next = current_file->next;
1602 free (current_file);
1603 current_file = next;
1604 PUT_SDB_SRC_FILE (current_file->name);
1605 #endif
1606 }
1607
1608 /* Set up for SDB output at the start of compilation. */
1609
1610 void
1611 sdbout_init (asm_file, input_file_name, syms)
1612 FILE *asm_file ATTRIBUTE_UNUSED;
1613 const char *input_file_name ATTRIBUTE_UNUSED;
1614 tree syms ATTRIBUTE_UNUSED;
1615 {
1616 #ifdef MIPS_DEBUGGING_INFO
1617 current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
1618 current_file->next = NULL;
1619 current_file->name = input_file_name;
1620 #endif
1621
1622 #ifdef RMS_QUICK_HACK_1
1623 tree t;
1624 for (t = syms; t; t = TREE_CHAIN (t))
1625 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
1626 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
1627 sdbout_symbol (t, 0);
1628 #endif
1629
1630 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1631 ggc_add_tree_root (&anonymous_types, 1);
1632 #endif
1633 }
1634
1635 #endif /* SDB_DEBUGGING_INFO */