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