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