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