]> gcc.gnu.org Git - gcc.git/blob - gcc/sdbout.c
d95945e635b7526749071177cad10d9fcc7ff01d
[gcc.git] / gcc / sdbout.c
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
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.
10
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.
15
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. */
20
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:
24
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.
28
29 2. All functions and their locals (including statics) are emitted as scanned.
30
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.
34
35 4. All structure .defs are emitted before the typedefs that refer to them.
36
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.
39
40 6. All undefined references are at the end of the file.
41 */
42
43 #include "config.h"
44
45 #ifdef SDB_DEBUGGING_INFO
46
47 #include <stdio.h>
48 #include "tree.h"
49 #include "rtl.h"
50 #include "regs.h"
51 #include "defaults.h"
52 #include "flags.h"
53 #include "insn-config.h"
54 #include "reload.h"
55
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. */
59
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
69
70 /* #include <storclass.h> used to be this instead of syms.h. */
71
72 /* 1 if PARM is passed to this function in memory. */
73
74 #define PARM_PASSED_IN_MEMORY(PARM) \
75 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
76
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
83
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
89
90 /* Line number of beginning of current function, minus one.
91 Negative means not in a function or not using sdb. */
92
93 int sdb_begin_function_line = -1;
94
95 /* Counter to generate unique "names" for nameless struct members. */
96
97 static int unnamed_struct_number = 0;
98
99 extern FILE *asm_out_file;
100
101 extern tree current_function_decl;
102
103 void sdbout_init ();
104 void sdbout_symbol ();
105 void sdbout_types();
106
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 sdbout_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));
121 \f
122 /* Define the default sizes for various types. */
123
124 #ifndef CHAR_TYPE_SIZE
125 #define CHAR_TYPE_SIZE BITS_PER_UNIT
126 #endif
127
128 #ifndef SHORT_TYPE_SIZE
129 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
130 #endif
131
132 #ifndef INT_TYPE_SIZE
133 #define INT_TYPE_SIZE BITS_PER_WORD
134 #endif
135
136 #ifndef LONG_TYPE_SIZE
137 #define LONG_TYPE_SIZE BITS_PER_WORD
138 #endif
139
140 #ifndef LONG_LONG_TYPE_SIZE
141 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
142 #endif
143
144 #ifndef FLOAT_TYPE_SIZE
145 #define FLOAT_TYPE_SIZE BITS_PER_WORD
146 #endif
147
148 #ifndef DOUBLE_TYPE_SIZE
149 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
150 #endif
151
152 #ifndef LONG_DOUBLE_TYPE_SIZE
153 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
154 #endif
155 \f
156 /* Random macros describing parts of SDB data. */
157
158 /* Put something here if lines get too long */
159 #define CONTIN
160
161 /* Default value of delimiter is ";". */
162 #ifndef SDB_DELIM
163 #define SDB_DELIM ";"
164 #endif
165
166 /* Maximum number of dimensions the assembler will allow. */
167 #ifndef SDB_MAX_DIM
168 #define SDB_MAX_DIM 4
169 #endif
170
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
174
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
178
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
185
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
192
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
196
197 #ifndef PUT_SDB_ENDEF
198 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
199 #endif
200
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
204
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
208
209 #ifndef PUT_SDB_START_DIM
210 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
211 #endif
212
213 #ifndef PUT_SDB_NEXT_DIM
214 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
215 #endif
216
217 #ifndef PUT_SDB_LAST_DIM
218 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
219 #endif
220
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
227
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
234
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
241
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
248
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
255
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
264
265 #ifndef SDB_GENERATE_FAKE
266 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
267 sprintf ((BUFFER), ".%dfake", (NUMBER));
268 #endif
269
270 /* Return the sdb tag identifier string for TYPE
271 if TYPE has already been defined; otherwise return a null pointer. */
272
273 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
274
275 /* Set the sdb tag identifier string for TYPE to NAME. */
276
277 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
278 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
279
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. */
282
283 #define TAG_NAME(link) \
284 (((link) && TREE_PURPOSE ((link)) \
285 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
286 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
287
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
291
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. */
297
298 #ifdef MIPS_DEBUGGING_INFO
299
300 #ifndef PUT_SDB_SRC_FILE
301 #define PUT_SDB_SRC_FILE(FILENAME) \
302 output_file_directive (asm_out_file, (FILENAME))
303 #endif
304
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. */
309
310 /* This is a stack of input files. */
311
312 struct sdb_file
313 {
314 struct sdb_file *next;
315 char *name;
316 };
317
318 /* This is the top of the stack. */
319
320 static struct sdb_file *current_file;
321
322 #endif /* MIPS_DEBUGGING_INFO */
323 \f
324 /* Set up for SDB output at the start of compilation. */
325
326 void
327 sdbout_init (asm_file, input_file_name, syms)
328 FILE *asm_file;
329 char *input_file_name;
330 tree syms;
331 {
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
337
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
345 }
346
347 #if 0
348
349 /* return the tag identifier for type
350 */
351
352 char *
353 tag_of_ru_type (type,link)
354 tree type,link;
355 {
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);
363 }
364 #endif
365
366 /* Return a unique string to name an anonymous type. */
367
368 static char *
369 gen_fake_label ()
370 {
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;
378 }
379 \f
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. */
384
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 */
393
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))
401
402 /* Number of elements used in sdb_dims. */
403 static int sdb_n_dims = 0;
404
405 /* Table of array dimensions of current type. */
406 static int sdb_dims[SDB_MAX_DIM];
407
408 /* Size of outermost array currently being processed. */
409 static int sdb_type_size = -1;
410
411 static int
412 plain_type (type)
413 tree type;
414 {
415 int val = plain_type_1 (type, 0);
416
417 /* If we have already saved up some array dimensions, print them now. */
418 if (sdb_n_dims > 0)
419 {
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;
426
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;
431 }
432 /* If we have computed the size of an array containing this type,
433 print it now. */
434 if (sdb_type_size >= 0)
435 {
436 PUT_SDB_SIZE (sdb_type_size);
437 sdb_type_size = -1;
438 }
439 return val;
440 }
441
442 static int
443 template_name_p (name)
444 tree name;
445 {
446 register char *ptr = IDENTIFIER_POINTER (name);
447 while (*ptr && *ptr != '<')
448 ptr++;
449
450 return *ptr != '\0';
451 }
452
453 static void
454 sdbout_record_type_name (type)
455 tree type;
456 {
457 char *name = 0;
458 int no_name;
459
460 if (KNOWN_TYPE_TAG (type))
461 return;
462
463 if (TYPE_NAME (type) != 0)
464 {
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)
470 {
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));
477 }
478
479 /* Now get the name as a string, or invent one. */
480 if (t != NULL_TREE)
481 name = IDENTIFIER_POINTER (t);
482 }
483
484 no_name = (name == 0 || *name == 0);
485 if (no_name)
486 name = gen_fake_label ();
487
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
493 }
494
495 /* Return the .type value for type TYPE.
496
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. */
502
503 static int
504 plain_type_1 (type, level)
505 tree type;
506 int level;
507 {
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);
514
515 switch (TREE_CODE (type))
516 {
517 case VOID_TYPE:
518 return T_VOID;
519 case INTEGER_TYPE:
520 {
521 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
522
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)
531 {
532 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
533
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;
548 }
549
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;
561 }
562
563 case REAL_TYPE:
564 {
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;
575 }
576
577 case ARRAY_TYPE:
578 {
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 && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
588 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
589 && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
590 ? (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
591 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
592 : 0);
593 return PUSH_DERIVED_LEVEL (DT_ARY, m);
594 }
595
596 case RECORD_TYPE:
597 case UNION_TYPE:
598 case QUAL_UNION_TYPE:
599 case ENUMERAL_TYPE:
600 {
601 char *tag;
602 #ifdef SDB_ALLOW_FORWARD_REFERENCES
603 sdbout_record_type_name (type);
604 #endif
605 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
606 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
607 #ifdef SDB_ALLOW_FORWARD_REFERENCES
608 || TYPE_MODE (type) != VOIDmode
609 #endif
610 )
611 #endif
612 {
613 /* Output the referenced structure tag name
614 only if the .def has already been finished.
615 At least on 386, the Unix assembler
616 cannot handle forward references to tags. */
617 /* But the 88100, it requires them, sigh... */
618 /* And the MIPS requires unknown refs as well... */
619 tag = KNOWN_TYPE_TAG (type);
620 PUT_SDB_TAG (tag);
621 /* These 3 lines used to follow the close brace.
622 However, a size of 0 without a tag implies a tag of 0,
623 so if we don't know a tag, we can't mention the size. */
624 sdb_type_size = int_size_in_bytes (type);
625 if (sdb_type_size < 0)
626 sdb_type_size = 0;
627 }
628 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
629 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
630 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
631 : T_ENUM);
632 }
633 case POINTER_TYPE:
634 case REFERENCE_TYPE:
635 {
636 int m;
637 if (level >= 6)
638 return T_VOID;
639 else
640 m = plain_type_1 (TREE_TYPE (type), level+1);
641 return PUSH_DERIVED_LEVEL (DT_PTR, m);
642 }
643 case FUNCTION_TYPE:
644 case METHOD_TYPE:
645 {
646 int m;
647 if (level >= 6)
648 return T_VOID;
649 else
650 m = plain_type_1 (TREE_TYPE (type), level+1);
651 return PUSH_DERIVED_LEVEL (DT_FCN, m);
652 }
653 default:
654 return 0;
655 }
656 }
657 \f
658 /* Output the symbols defined in block number DO_BLOCK.
659 Set NEXT_BLOCK_NUMBER to 0 before calling.
660
661 This function works by walking the tree structure of blocks,
662 counting blocks until it finds the desired block. */
663
664 static int do_block = 0;
665
666 static int next_block_number;
667
668 static void
669 sdbout_block (block)
670 register tree block;
671 {
672 while (block)
673 {
674 /* Ignore blocks never expanded or otherwise marked as real. */
675 if (TREE_USED (block))
676 {
677 /* When we reach the specified block, output its symbols. */
678 if (next_block_number == do_block)
679 {
680 sdbout_syms (BLOCK_VARS (block));
681 }
682
683 /* If we are past the specified block, stop the scan. */
684 if (next_block_number > do_block)
685 return;
686
687 next_block_number++;
688
689 /* Scan the blocks within this block. */
690 sdbout_block (BLOCK_SUBBLOCKS (block));
691 }
692
693 block = BLOCK_CHAIN (block);
694 }
695 }
696 \f
697 /* Call sdbout_symbol on each decl in the chain SYMS. */
698
699 static void
700 sdbout_syms (syms)
701 tree syms;
702 {
703 while (syms)
704 {
705 if (TREE_CODE (syms) != LABEL_DECL)
706 sdbout_symbol (syms, 1);
707 syms = TREE_CHAIN (syms);
708 }
709 }
710
711 /* Output SDB information for a symbol described by DECL.
712 LOCAL is nonzero if the symbol is not file-scope. */
713
714 void
715 sdbout_symbol (decl, local)
716 tree decl;
717 int local;
718 {
719 tree type = TREE_TYPE (decl);
720 tree context = NULL_TREE;
721 rtx value;
722 int regno = -1;
723 char *name;
724
725 sdbout_one_type (type);
726
727 #if 0 /* This loses when functions are marked to be ignored,
728 which happens in the C++ front end. */
729 if (DECL_IGNORED_P (decl))
730 return;
731 #endif
732
733 switch (TREE_CODE (decl))
734 {
735 case CONST_DECL:
736 /* Enum values are defined by defining the enum type. */
737 return;
738
739 case FUNCTION_DECL:
740 /* Don't mention a nested function under its parent. */
741 context = decl_function_context (decl);
742 if (context == current_function_decl)
743 return;
744 /* Check DECL_INITIAL to distinguish declarations from definitions.
745 Don't output debug info here for declarations; they will have
746 a DECL_INITIAL value of 0. */
747 if (! DECL_INITIAL (decl))
748 return;
749 if (GET_CODE (DECL_RTL (decl)) != MEM
750 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
751 return;
752 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
753 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
754 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
755 break;
756
757 case TYPE_DECL:
758 /* Done with tagged types. */
759 if (DECL_NAME (decl) == 0)
760 return;
761 if (DECL_IGNORED_P (decl))
762 return;
763
764 /* Output typedef name. */
765 if (template_name_p (DECL_NAME (decl)))
766 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
767 else
768 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
769 PUT_SDB_SCL (C_TPDEF);
770 break;
771
772 case PARM_DECL:
773 /* Parm decls go in their own separate chains
774 and are output by sdbout_reg_parms and sdbout_parms. */
775 abort ();
776
777 case VAR_DECL:
778 /* Don't mention a variable that is external.
779 Let the file that defines it describe it. */
780 if (DECL_EXTERNAL (decl))
781 return;
782
783 /* Ignore __FUNCTION__, etc. */
784 if (DECL_IGNORED_P (decl))
785 return;
786
787 /* If there was an error in the declaration, don't dump core
788 if there is no RTL associated with the variable doesn't
789 exist. */
790 if (DECL_RTL (decl) == 0)
791 return;
792
793 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
794 #ifdef LEAF_REG_REMAP
795 if (leaf_function)
796 leaf_renumber_regs_insn (DECL_RTL (decl));
797 #endif
798 value = DECL_RTL (decl);
799
800 /* Don't mention a variable at all
801 if it was completely optimized into nothingness.
802
803 If DECL was from an inline function, then its rtl
804 is not identically the rtl that was used in this
805 particular compilation. */
806 if (GET_CODE (value) == REG)
807 {
808 regno = REGNO (DECL_RTL (decl));
809 if (regno >= FIRST_PSEUDO_REGISTER)
810 return;
811 }
812 else if (GET_CODE (value) == SUBREG)
813 {
814 int offset = 0;
815 while (GET_CODE (value) == SUBREG)
816 {
817 offset += SUBREG_WORD (value);
818 value = SUBREG_REG (value);
819 }
820 if (GET_CODE (value) == REG)
821 {
822 regno = REGNO (value);
823 if (regno >= FIRST_PSEUDO_REGISTER)
824 return;
825 regno += offset;
826 }
827 alter_subreg (DECL_RTL (decl));
828 value = DECL_RTL (decl);
829 }
830 /* Don't output anything if an auto variable
831 gets RTL that is static.
832 GAS version 2.2 can't handle such output. */
833 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
834 && ! TREE_STATIC (decl))
835 return;
836
837 /* Emit any structure, union, or enum type that has not been output.
838 This occurs for tag-less structs (et al) used to declare variables
839 within functions. */
840 if (TREE_CODE (type) == ENUMERAL_TYPE
841 || TREE_CODE (type) == RECORD_TYPE
842 || TREE_CODE (type) == UNION_TYPE
843 || TREE_CODE (type) == QUAL_UNION_TYPE)
844 {
845 if (TYPE_SIZE (type) != 0 /* not a forward reference */
846 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
847 sdbout_one_type (type);
848 }
849
850 /* Defer SDB information for top-level initialized variables! */
851 if (! local
852 && GET_CODE (value) == MEM
853 && DECL_INITIAL (decl))
854 return;
855
856 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
857 For now, avoid crashing. */
858 if (DECL_NAME (decl) == NULL_TREE)
859 return;
860
861 /* Record the name for, starting a symtab entry. */
862 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
863
864 if (GET_CODE (value) == MEM
865 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
866 {
867 PUT_SDB_DEF (name);
868 if (TREE_PUBLIC (decl))
869 {
870 PUT_SDB_VAL (XEXP (value, 0));
871 PUT_SDB_SCL (C_EXT);
872 }
873 else
874 {
875 PUT_SDB_VAL (XEXP (value, 0));
876 PUT_SDB_SCL (C_STAT);
877 }
878 }
879 else if (regno >= 0)
880 {
881 PUT_SDB_DEF (name);
882 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
883 PUT_SDB_SCL (C_REG);
884 }
885 else if (GET_CODE (value) == MEM
886 && (GET_CODE (XEXP (value, 0)) == MEM
887 || (GET_CODE (XEXP (value, 0)) == REG
888 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
889 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
890 /* If the value is indirect by memory or by a register
891 that isn't the frame pointer
892 then it means the object is variable-sized and address through
893 that register or stack slot. COFF has no way to represent this
894 so all we can do is output the variable as a pointer. */
895 {
896 PUT_SDB_DEF (name);
897 if (GET_CODE (XEXP (value, 0)) == REG)
898 {
899 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
900 PUT_SDB_SCL (C_REG);
901 }
902 else
903 {
904 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
905 (CONST_INT...)))).
906 We want the value of that CONST_INT. */
907 /* Encore compiler hates a newline in a macro arg, it seems. */
908 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
909 (XEXP (XEXP (value, 0), 0)));
910 PUT_SDB_SCL (C_AUTO);
911 }
912
913 type = build_pointer_type (TREE_TYPE (decl));
914 }
915 else if (GET_CODE (value) == MEM
916 && ((GET_CODE (XEXP (value, 0)) == PLUS
917 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
918 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
919 /* This is for variables which are at offset zero from
920 the frame pointer. This happens on the Alpha.
921 Non-frame pointer registers are excluded above. */
922 || (GET_CODE (XEXP (value, 0)) == REG)))
923 {
924 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
925 or (MEM (REG...)). We want the value of that CONST_INT
926 or zero. */
927 PUT_SDB_DEF (name);
928 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
929 PUT_SDB_SCL (C_AUTO);
930 }
931 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
932 {
933 /* Handle an obscure case which can arise when optimizing and
934 when there are few available registers. (This is *always*
935 the case for i386/i486 targets). The DECL_RTL looks like
936 (MEM (CONST ...)) even though this variable is a local `auto'
937 or a local `register' variable. In effect, what has happened
938 is that the reload pass has seen that all assignments and
939 references for one such a local variable can be replaced by
940 equivalent assignments and references to some static storage
941 variable, thereby avoiding the need for a register. In such
942 cases we're forced to lie to debuggers and tell them that
943 this variable was itself `static'. */
944 PUT_SDB_DEF (name);
945 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
946 PUT_SDB_SCL (C_STAT);
947 }
948 else
949 {
950 /* It is something we don't know how to represent for SDB. */
951 return;
952 }
953 break;
954
955 default:
956 break;
957 }
958 PUT_SDB_TYPE (plain_type (type));
959 PUT_SDB_ENDEF;
960 }
961 \f
962 /* Output SDB information for a top-level initialized variable
963 that has been delayed. */
964
965 void
966 sdbout_toplevel_data (decl)
967 tree decl;
968 {
969 tree type = TREE_TYPE (decl);
970
971 if (DECL_IGNORED_P (decl))
972 return;
973
974 if (! (TREE_CODE (decl) == VAR_DECL
975 && GET_CODE (DECL_RTL (decl)) == MEM
976 && DECL_INITIAL (decl)))
977 abort ();
978
979 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
980 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
981 if (TREE_PUBLIC (decl))
982 {
983 PUT_SDB_SCL (C_EXT);
984 }
985 else
986 {
987 PUT_SDB_SCL (C_STAT);
988 }
989 PUT_SDB_TYPE (plain_type (type));
990 PUT_SDB_ENDEF;
991 }
992 \f
993 #ifdef SDB_ALLOW_FORWARD_REFERENCES
994
995 /* Machinery to record and output anonymous types. */
996
997 static tree anonymous_types;
998
999 static void
1000 sdbout_queue_anonymous_type (type)
1001 tree type;
1002 {
1003 anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
1004 }
1005
1006 static void
1007 sdbout_dequeue_anonymous_types ()
1008 {
1009 register tree types, link;
1010
1011 while (anonymous_types)
1012 {
1013 types = nreverse (anonymous_types);
1014 anonymous_types = NULL_TREE;
1015
1016 for (link = types; link; link = TREE_CHAIN (link))
1017 {
1018 register tree type = TREE_VALUE (link);
1019
1020 if (type && ! TREE_ASM_WRITTEN (type))
1021 sdbout_one_type (type);
1022 }
1023 }
1024 }
1025
1026 #endif
1027 \f
1028 /* Given a chain of ..._TYPE nodes, all of which have names,
1029 output definitions of those names, as typedefs. */
1030
1031 void
1032 sdbout_types (types)
1033 register tree types;
1034 {
1035 register tree link;
1036
1037 for (link = types; link; link = TREE_CHAIN (link))
1038 sdbout_one_type (link);
1039
1040 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1041 sdbout_dequeue_anonymous_types ();
1042 #endif
1043 }
1044
1045 static void
1046 sdbout_type (type)
1047 tree type;
1048 {
1049 if (type == error_mark_node)
1050 type = integer_type_node;
1051 PUT_SDB_TYPE (plain_type (type));
1052 }
1053
1054 /* Output types of the fields of type TYPE, if they are structs.
1055
1056 Formerly did not chase through pointer types, since that could be circular.
1057 They must come before TYPE, since forward refs are not allowed.
1058 Now james@bigtex.cactus.org says to try them. */
1059
1060 static void
1061 sdbout_field_types (type)
1062 tree type;
1063 {
1064 tree tail;
1065 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1066 if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
1067 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1068 else
1069 sdbout_one_type (TREE_TYPE (tail));
1070 }
1071
1072 /* Use this to put out the top level defined record and union types
1073 for later reference. If this is a struct with a name, then put that
1074 name out. Other unnamed structs will have .xxfake labels generated so
1075 that they may be referred to later.
1076 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1077 It may NOT be called recursively. */
1078
1079 static void
1080 sdbout_one_type (type)
1081 tree type;
1082 {
1083 if (current_function_decl != NULL_TREE
1084 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1085 ; /* Don't change section amid function. */
1086 else
1087 text_section ();
1088
1089 switch (TREE_CODE (type))
1090 {
1091 case RECORD_TYPE:
1092 case UNION_TYPE:
1093 case QUAL_UNION_TYPE:
1094 case ENUMERAL_TYPE:
1095 type = TYPE_MAIN_VARIANT (type);
1096 /* Don't output a type twice. */
1097 if (TREE_ASM_WRITTEN (type))
1098 /* James said test TREE_ASM_BEING_WRITTEN here. */
1099 return;
1100
1101 /* Output nothing if type is not yet defined. */
1102 if (TYPE_SIZE (type) == 0)
1103 return;
1104
1105 TREE_ASM_WRITTEN (type) = 1;
1106 #if 1
1107 /* This is reputed to cause trouble with the following case,
1108 but perhaps checking TYPE_SIZE above will fix it. */
1109
1110 /* Here is a test case:
1111
1112 struct foo {
1113 struct badstr *bbb;
1114 } forwardref;
1115
1116 typedef struct intermediate {
1117 int aaaa;
1118 } intermediate_ref;
1119
1120 typedef struct badstr {
1121 int ccccc;
1122 } badtype; */
1123
1124 #if 0
1125 TREE_ASM_BEING_WRITTEN (type) = 1;
1126 #endif
1127 /* This change, which ought to make better output,
1128 used to make the COFF assembler unhappy.
1129 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1130 /* Before really doing anything, output types we want to refer to. */
1131 /* Note that in version 1 the following two lines
1132 are not used if forward references are in use. */
1133 if (TREE_CODE (type) != ENUMERAL_TYPE)
1134 sdbout_field_types (type);
1135 #if 0
1136 TREE_ASM_WRITTEN (type) = 1;
1137 #endif
1138 #endif
1139
1140 /* Output a structure type. */
1141 {
1142 int size = int_size_in_bytes (type);
1143 int member_scl;
1144 tree tem;
1145 int i, n_baseclasses = 0;
1146
1147 /* Record the type tag, but not in its permanent place just yet. */
1148 sdbout_record_type_name (type);
1149
1150 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1151
1152 switch (TREE_CODE (type))
1153 {
1154 case UNION_TYPE:
1155 case QUAL_UNION_TYPE:
1156 PUT_SDB_SCL (C_UNTAG);
1157 PUT_SDB_TYPE (T_UNION);
1158 member_scl = C_MOU;
1159 break;
1160
1161 case RECORD_TYPE:
1162 PUT_SDB_SCL (C_STRTAG);
1163 PUT_SDB_TYPE (T_STRUCT);
1164 member_scl = C_MOS;
1165 break;
1166
1167 case ENUMERAL_TYPE:
1168 PUT_SDB_SCL (C_ENTAG);
1169 PUT_SDB_TYPE (T_ENUM);
1170 member_scl = C_MOE;
1171 break;
1172
1173 default:
1174 break;
1175 }
1176
1177 PUT_SDB_SIZE (size);
1178 PUT_SDB_ENDEF;
1179
1180 /* Print out the base class information with fields
1181 named after the types they hold. */
1182 if (TYPE_BINFO (type)
1183 && TYPE_BINFO_BASETYPES (type))
1184 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1185 for (i = 0; i < n_baseclasses; i++)
1186 {
1187 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1188 tree child_type = BINFO_TYPE (child);
1189 tree child_type_name;
1190 if (TYPE_NAME (child_type) == 0)
1191 continue;
1192 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1193 child_type_name = TYPE_NAME (child_type);
1194 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1195 {
1196 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1197 if (child_type_name && template_name_p (child_type_name))
1198 child_type_name
1199 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1200 }
1201 else
1202 continue;
1203
1204 CONTIN;
1205 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1206 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
1207 PUT_SDB_SCL (member_scl);
1208 sdbout_type (BINFO_TYPE (child));
1209 PUT_SDB_ENDEF;
1210 }
1211
1212 /* output the individual fields */
1213
1214 if (TREE_CODE (type) == ENUMERAL_TYPE)
1215 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1216 {
1217 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1218 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1219 PUT_SDB_SCL (C_MOE);
1220 PUT_SDB_TYPE (T_MOE);
1221 PUT_SDB_ENDEF;
1222 }
1223
1224 else /* record or union type */
1225 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1226 /* Output the name, type, position (in bits), size (in bits)
1227 of each field. */
1228
1229 /* Omit here the nameless fields that are used to skip bits.
1230 Also omit fields with variable size or position.
1231 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1232 if (TREE_CODE (tem) == FIELD_DECL
1233 && DECL_NAME (tem) != 0
1234 && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
1235 && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
1236 {
1237 char *name;
1238
1239 CONTIN;
1240 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
1241 PUT_SDB_DEF (name);
1242 if (DECL_BIT_FIELD_TYPE (tem))
1243 {
1244 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
1245 PUT_SDB_SCL (C_FIELD);
1246 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1247 PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
1248 }
1249 else
1250 {
1251 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
1252 / BITS_PER_UNIT);
1253 PUT_SDB_SCL (member_scl);
1254 sdbout_type (TREE_TYPE (tem));
1255 }
1256 PUT_SDB_ENDEF;
1257 }
1258 /* output end of a structure,union, or enumeral definition */
1259
1260 PUT_SDB_PLAIN_DEF ("eos");
1261 PUT_SDB_INT_VAL (size);
1262 PUT_SDB_SCL (C_EOS);
1263 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1264 PUT_SDB_SIZE (size);
1265 PUT_SDB_ENDEF;
1266 break;
1267
1268 default:
1269 break;
1270 }
1271 }
1272 }
1273 \f
1274 /* The following two functions output definitions of function parameters.
1275 Each parameter gets a definition locating it in the parameter list.
1276 Each parameter that is a register variable gets a second definition
1277 locating it in the register.
1278
1279 Printing or argument lists in gdb uses the definitions that
1280 locate in the parameter list. But reference to the variable in
1281 expressions uses preferentially the definition as a register. */
1282
1283 /* Output definitions, referring to storage in the parmlist,
1284 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1285
1286 static void
1287 sdbout_parms (parms)
1288 tree parms;
1289 {
1290 for (; parms; parms = TREE_CHAIN (parms))
1291 if (DECL_NAME (parms))
1292 {
1293 int current_sym_value = 0;
1294 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1295
1296 if (name == 0 || *name == 0)
1297 name = gen_fake_label ();
1298
1299 /* Perform any necessary register eliminations on the parameter's rtl,
1300 so that the debugging output will be accurate. */
1301 DECL_INCOMING_RTL (parms)
1302 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1303 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1304
1305 if (PARM_PASSED_IN_MEMORY (parms))
1306 {
1307 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1308 tree type;
1309
1310 /* ??? Here we assume that the parm address is indexed
1311 off the frame pointer or arg pointer.
1312 If that is not true, we produce meaningless results,
1313 but do not crash. */
1314 if (GET_CODE (addr) == PLUS
1315 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1316 current_sym_value = INTVAL (XEXP (addr, 1));
1317 else
1318 current_sym_value = 0;
1319
1320 if (GET_CODE (DECL_RTL (parms)) == REG
1321 && REGNO (DECL_RTL (parms)) >= 0
1322 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1323 type = DECL_ARG_TYPE (parms);
1324 else
1325 {
1326 int original_sym_value = current_sym_value;
1327
1328 /* This is the case where the parm is passed as an int or
1329 double and it is converted to a char, short or float
1330 and stored back in the parmlist. In this case, describe
1331 the parm with the variable's declared type, and adjust
1332 the address if the least significant bytes (which we are
1333 using) are not the first ones. */
1334 if (BYTES_BIG_ENDIAN
1335 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1336 current_sym_value +=
1337 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1338 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1339
1340 if (GET_CODE (DECL_RTL (parms)) == MEM
1341 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1342 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1343 == CONST_INT)
1344 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1345 == current_sym_value))
1346 type = TREE_TYPE (parms);
1347 else
1348 {
1349 current_sym_value = original_sym_value;
1350 type = DECL_ARG_TYPE (parms);
1351 }
1352 }
1353
1354 PUT_SDB_DEF (name);
1355 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1356 PUT_SDB_SCL (C_ARG);
1357 PUT_SDB_TYPE (plain_type (type));
1358 PUT_SDB_ENDEF;
1359 }
1360 else if (GET_CODE (DECL_RTL (parms)) == REG)
1361 {
1362 rtx best_rtl;
1363 /* Parm passed in registers and lives in registers or nowhere. */
1364
1365 /* If parm lives in a register, use that register;
1366 pretend the parm was passed there. It would be more consistent
1367 to describe the register where the parm was passed,
1368 but in practice that register usually holds something else. */
1369 if (REGNO (DECL_RTL (parms)) >= 0
1370 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1371 best_rtl = DECL_RTL (parms);
1372 /* If the parm lives nowhere,
1373 use the register where it was passed. */
1374 else
1375 best_rtl = DECL_INCOMING_RTL (parms);
1376
1377 PUT_SDB_DEF (name);
1378 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1379 PUT_SDB_SCL (C_REGPARM);
1380 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1381 PUT_SDB_ENDEF;
1382 }
1383 else if (GET_CODE (DECL_RTL (parms)) == MEM
1384 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1385 {
1386 /* Parm was passed in registers but lives on the stack. */
1387
1388 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1389 in which case we want the value of that CONST_INT,
1390 or (MEM (REG ...)) or (MEM (MEM ...)),
1391 in which case we use a value of zero. */
1392 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1393 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1394 current_sym_value = 0;
1395 else
1396 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1397
1398 /* Again, this assumes the offset is based on the arg pointer. */
1399 PUT_SDB_DEF (name);
1400 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1401 XEXP (DECL_RTL (parms), 0)));
1402 PUT_SDB_SCL (C_ARG);
1403 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1404 PUT_SDB_ENDEF;
1405 }
1406 }
1407 }
1408
1409 /* Output definitions for the places where parms live during the function,
1410 when different from where they were passed, when the parms were passed
1411 in memory.
1412
1413 It is not useful to do this for parms passed in registers
1414 that live during the function in different registers, because it is
1415 impossible to look in the passed register for the passed value,
1416 so we use the within-the-function register to begin with.
1417
1418 PARMS is a chain of PARM_DECL nodes. */
1419
1420 static void
1421 sdbout_reg_parms (parms)
1422 tree parms;
1423 {
1424 for (; parms; parms = TREE_CHAIN (parms))
1425 if (DECL_NAME (parms))
1426 {
1427 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1428
1429 /* Report parms that live in registers during the function
1430 but were passed in memory. */
1431 if (GET_CODE (DECL_RTL (parms)) == REG
1432 && REGNO (DECL_RTL (parms)) >= 0
1433 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1434 && PARM_PASSED_IN_MEMORY (parms))
1435 {
1436 if (name == 0 || *name == 0)
1437 name = gen_fake_label ();
1438 PUT_SDB_DEF (name);
1439 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1440 PUT_SDB_SCL (C_REG);
1441 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1442 PUT_SDB_ENDEF;
1443 }
1444 /* Report parms that live in memory but not where they were passed. */
1445 else if (GET_CODE (DECL_RTL (parms)) == MEM
1446 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1447 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1448 && PARM_PASSED_IN_MEMORY (parms)
1449 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1450 {
1451 #if 0 /* ??? It is not clear yet what should replace this. */
1452 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1453 /* A parm declared char is really passed as an int,
1454 so it occupies the least significant bytes.
1455 On a big-endian machine those are not the low-numbered ones. */
1456 if (BYTES_BIG_ENDIAN
1457 && offset != -1
1458 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1459 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1460 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1461 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1462 #endif
1463 {
1464 if (name == 0 || *name == 0)
1465 name = gen_fake_label ();
1466 PUT_SDB_DEF (name);
1467 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1468 (XEXP (DECL_RTL (parms), 0)));
1469 PUT_SDB_SCL (C_AUTO);
1470 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1471 PUT_SDB_ENDEF;
1472 }
1473 }
1474 }
1475 }
1476 \f
1477 /* Describe the beginning of an internal block within a function.
1478 Also output descriptions of variables defined in this block.
1479
1480 N is the number of the block, by order of beginning, counting from 1,
1481 and not counting the outermost (function top-level) block.
1482 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1483 if the count starts at 0 for the outermost one. */
1484
1485 void
1486 sdbout_begin_block (file, line, n)
1487 FILE *file;
1488 int line;
1489 int n;
1490 {
1491 tree decl = current_function_decl;
1492 MAKE_LINE_SAFE (line);
1493
1494 /* The SCO compiler does not emit a separate block for the function level
1495 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1496 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1497 #ifndef MIPS_DEBUGGING_INFO
1498 if (n != 1)
1499 #endif
1500 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1501
1502 if (n == 1)
1503 {
1504 /* Include the outermost BLOCK's variables in block 1. */
1505 next_block_number = 0;
1506 do_block = 0;
1507 sdbout_block (DECL_INITIAL (decl));
1508 }
1509 /* If -g1, suppress all the internal symbols of functions
1510 except for arguments. */
1511 if (debug_info_level != DINFO_LEVEL_TERSE)
1512 {
1513 next_block_number = 0;
1514 do_block = n;
1515 sdbout_block (DECL_INITIAL (decl));
1516 }
1517
1518 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1519 sdbout_dequeue_anonymous_types ();
1520 #endif
1521 }
1522
1523 /* Describe the end line-number of an internal block within a function. */
1524
1525 void
1526 sdbout_end_block (file, line, n)
1527 FILE *file;
1528 int line;
1529 int n;
1530 {
1531 MAKE_LINE_SAFE (line);
1532
1533 /* The SCO compiler does not emit a separate block for the function level
1534 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1535 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1536 #ifndef MIPS_DEBUGGING_INFO
1537 if (n != 1)
1538 #endif
1539 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1540 }
1541
1542 /* Output sdb info for the current function name.
1543 Called from assemble_start_function. */
1544
1545 void
1546 sdbout_mark_begin_function ()
1547 {
1548 sdbout_symbol (current_function_decl, 0);
1549 }
1550
1551 /* Called at beginning of function body (after prologue).
1552 Record the function's starting line number, so we can output
1553 relative line numbers for the other lines.
1554 Describe beginning of outermost block.
1555 Also describe the parameter list. */
1556
1557 void
1558 sdbout_begin_function (line)
1559 int line;
1560 {
1561 sdb_begin_function_line = line - 1;
1562 PUT_SDB_FUNCTION_START (line);
1563 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1564 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1565 }
1566
1567 /* Called at end of function (before epilogue).
1568 Describe end of outermost block. */
1569
1570 void
1571 sdbout_end_function (line)
1572 int line;
1573 {
1574 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1575 sdbout_dequeue_anonymous_types ();
1576 #endif
1577
1578 MAKE_LINE_SAFE (line);
1579 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1580
1581 /* Indicate we are between functions, for line-number output. */
1582 sdb_begin_function_line = -1;
1583 }
1584
1585 /* Output sdb info for the absolute end of a function.
1586 Called after the epilogue is output. */
1587
1588 void
1589 sdbout_end_epilogue ()
1590 {
1591 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1592 PUT_SDB_EPILOGUE_END (name);
1593 }
1594
1595 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1596 is present. */
1597
1598 void
1599 sdbout_label (insn)
1600 register rtx insn;
1601 {
1602 PUT_SDB_DEF (LABEL_NAME (insn));
1603 PUT_SDB_VAL (insn);
1604 PUT_SDB_SCL (C_LABEL);
1605 PUT_SDB_TYPE (T_NULL);
1606 PUT_SDB_ENDEF;
1607 }
1608
1609 /* Change to reading from a new source file. */
1610
1611 void
1612 sdbout_start_new_source_file (filename)
1613 char *filename;
1614 {
1615 #ifdef MIPS_DEBUGGING_INFO
1616 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1617
1618 n->next = current_file;
1619 n->name = filename;
1620 current_file = n;
1621 PUT_SDB_SRC_FILE (filename);
1622 #endif
1623 }
1624
1625 /* Revert to reading a previous source file. */
1626
1627 void
1628 sdbout_resume_previous_source_file ()
1629 {
1630 #ifdef MIPS_DEBUGGING_INFO
1631 struct sdb_file *next;
1632
1633 next = current_file->next;
1634 free (current_file);
1635 current_file = next;
1636 PUT_SDB_SRC_FILE (current_file->name);
1637 #endif
1638 }
1639
1640 #endif /* SDB_DEBUGGING_INFO */
This page took 0.108827 seconds and 4 git commands to generate.