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