]> gcc.gnu.org Git - gcc.git/blame - gcc/dwarfout.c
(enum dwarf_attribute): Add At_body_begin and AT_body_end.
[gcc.git] / gcc / dwarfout.c
CommitLineData
340ccaab
TW
1/* This file contains code written by Ron Guilmette (rfg@ncd.com) for
2 Network Computing Devices, August, September, October, November 1990.
3
4 Output Dwarf format symbol table information from the GNU C compiler.
5 Copyright (C) 1992 Free Software Foundation, Inc.
6
7This file is part of GNU CC.
8
9GNU CC is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2, or (at your option)
12any later version.
13
14GNU CC is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with GNU CC; see the file COPYING. If not, write to
21the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22
23#include "config.h"
24
25#ifdef DWARF_DEBUGGING_INFO
26#include <stdio.h>
27#include "dwarf.h"
28#include "tree.h"
29#include "flags.h"
30#include "rtl.h"
7f7429ca 31#include "hard-reg-set.h"
340ccaab
TW
32#include "insn-config.h"
33#include "reload.h"
34#include "output.h"
9a631e8e 35#include "defaults.h"
340ccaab 36
648ebe7b
RS
37#ifndef DWARF_VERSION
38#define DWARF_VERSION 1
39#endif
40
340ccaab
TW
41/* #define NDEBUG 1 */
42#include <assert.h>
43
44#if defined(DWARF_TIMESTAMPS)
45#if defined(POSIX)
46#include <time.h>
47#else /* !defined(POSIX) */
48#include <sys/types.h>
49#if defined(__STDC__)
50extern time_t time (time_t *);
51#else /* !defined(__STDC__) */
52extern time_t time ();
53#endif /* !defined(__STDC__) */
54#endif /* !defined(POSIX) */
55#endif /* defined(DWARF_TIMESTAMPS) */
56
9a631e8e 57extern char *getpwd ();
2e494f70 58
3f7cc57a
MS
59extern char *index ();
60extern char *rindex ();
61
340ccaab
TW
62/* IMPORTANT NOTE: Please see the file README.DWARF for important details
63 regarding the GNU implementation of Dwarf. */
64
65/* NOTE: In the comments in this file, many references are made to
66 so called "Debugging Information Entries". For the sake of brevity,
67 this term is abbreviated to `DIE' throughout the remainder of this
68 file. */
69
70/* Note that the implementation of C++ support herein is (as yet) unfinished.
71 If you want to try to complete it, more power to you. */
72
73#if defined(__GNUC__) && (NDEBUG == 1)
74#define inline static inline
75#else
76#define inline static
77#endif
78
79/* How to start an assembler comment. */
80#ifndef ASM_COMMENT_START
81#define ASM_COMMENT_START ";#"
82#endif
83
7f7429ca
RS
84/* How to print out a register name. */
85#ifndef PRINT_REG
86#define PRINT_REG(RTX, CODE, FILE) \
87 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
88#endif
89
340ccaab
TW
90/* Define a macro which returns non-zero for any tagged type which is
91 used (directly or indirectly) in the specification of either some
92 function's return type or some formal parameter of some function.
93 We use this macro when we are operating in "terse" mode to help us
94 know what tagged types have to be represented in Dwarf (even in
95 terse mode) and which ones don't.
96
97 A flag bit with this meaning really should be a part of the normal
98 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
99 for these nodes. For now, we have to just fake it. It it safe for
100 us to simply return zero for all complete tagged types (which will
101 get forced out anyway if they were used in the specification of some
102 formal or return type) and non-zero for all incomplete tagged types.
103*/
104
105#define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
106
340ccaab
TW
107extern int flag_traditional;
108extern char *version_string;
109extern char *language_string;
110
111/* Maximum size (in bytes) of an artificially generated label. */
112
113#define MAX_ARTIFICIAL_LABEL_BYTES 30
114\f
115/* Make sure we know the sizes of the various types dwarf can describe.
116 These are only defaults. If the sizes are different for your target,
117 you should override these values by defining the appropriate symbols
118 in your tm.h file. */
119
120#ifndef CHAR_TYPE_SIZE
121#define CHAR_TYPE_SIZE BITS_PER_UNIT
122#endif
123
124#ifndef SHORT_TYPE_SIZE
125#define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
126#endif
127
128#ifndef INT_TYPE_SIZE
129#define INT_TYPE_SIZE BITS_PER_WORD
130#endif
131
132#ifndef LONG_TYPE_SIZE
133#define LONG_TYPE_SIZE BITS_PER_WORD
134#endif
135
136#ifndef LONG_LONG_TYPE_SIZE
137#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
138#endif
139
140#ifndef WCHAR_TYPE_SIZE
141#define WCHAR_TYPE_SIZE INT_TYPE_SIZE
142#endif
143
144#ifndef WCHAR_UNSIGNED
145#define WCHAR_UNSIGNED 0
146#endif
147
148#ifndef FLOAT_TYPE_SIZE
149#define FLOAT_TYPE_SIZE BITS_PER_WORD
150#endif
151
152#ifndef DOUBLE_TYPE_SIZE
153#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
154#endif
155
156#ifndef LONG_DOUBLE_TYPE_SIZE
157#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
158#endif
159\f
160/* Structure to keep track of source filenames. */
161
162struct filename_entry {
163 unsigned number;
164 char * name;
165};
166
167typedef struct filename_entry filename_entry;
168
169/* Pointer to an array of elements, each one having the structure above. */
170
171static filename_entry *filename_table;
172
173/* Total number of entries in the table (i.e. array) pointed to by
174 `filename_table'. This is the *total* and includes both used and
175 unused slots. */
176
177static unsigned ft_entries_allocated;
178
179/* Number of entries in the filename_table which are actually in use. */
180
181static unsigned ft_entries;
182
183/* Size (in elements) of increments by which we may expand the filename
184 table. Actually, a single hunk of space of this size should be enough
185 for most typical programs. */
186
187#define FT_ENTRIES_INCREMENT 64
188
189/* Local pointer to the name of the main input file. Initialized in
190 dwarfout_init. */
191
192static char *primary_filename;
193
194/* Pointer to the most recent filename for which we produced some line info. */
195
196static char *last_filename;
197
198/* For Dwarf output, we must assign lexical-blocks id numbers
199 in the order in which their beginnings are encountered.
200 We output Dwarf debugging info that refers to the beginnings
201 and ends of the ranges of code for each lexical block with
202 assembler labels ..Bn and ..Bn.e, where n is the block number.
203 The labels themselves are generated in final.c, which assigns
204 numbers to the blocks in the same way. */
205
206static unsigned next_block_number = 2;
207
208/* Counter to generate unique names for DIEs. */
209
210static unsigned next_unused_dienum = 1;
211
212/* Number of the DIE which is currently being generated. */
213
214static unsigned current_dienum;
215
216/* Number to use for the special "pubname" label on the next DIE which
217 represents a function or data object defined in this compilation
218 unit which has "extern" linkage. */
219
220static next_pubname_number = 0;
221
222#define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
223
224/* Pointer to a dynamically allocated list of pre-reserved and still
225 pending sibling DIE numbers. Note that this list will grow as needed. */
226
227static unsigned *pending_sibling_stack;
228
229/* Counter to keep track of the number of pre-reserved and still pending
230 sibling DIE numbers. */
231
232static unsigned pending_siblings;
233
234/* The currently allocated size of the above list (expressed in number of
235 list elements). */
236
237static unsigned pending_siblings_allocated;
238
239/* Size (in elements) of increments by which we may expand the pending
240 sibling stack. Actually, a single hunk of space of this size should
241 be enough for most typical programs. */
242
243#define PENDING_SIBLINGS_INCREMENT 64
244
245/* Non-zero if we are performing our file-scope finalization pass and if
6dc42e49 246 we should force out Dwarf descriptions of any and all file-scope
340ccaab
TW
247 tagged types which are still incomplete types. */
248
249static int finalizing = 0;
250
251/* A pointer to the base of a list of pending types which we haven't
252 generated DIEs for yet, but which we will have to come back to
253 later on. */
254
255static tree *pending_types_list;
256
257/* Number of elements currently allocated for the pending_types_list. */
258
259static unsigned pending_types_allocated;
260
261/* Number of elements of pending_types_list currently in use. */
262
263static unsigned pending_types;
264
265/* Size (in elements) of increments by which we may expand the pending
266 types list. Actually, a single hunk of space of this size should
267 be enough for most typical programs. */
268
269#define PENDING_TYPES_INCREMENT 64
270
6dc42e49 271/* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
340ccaab
TW
272 This is used in a hack to help us get the DIEs describing types of
273 formal parameters to come *after* all of the DIEs describing the formal
274 parameters themselves. That's necessary in order to be compatible
6dc42e49 275 with what the brain-damaged svr4 SDB debugger requires. */
340ccaab
TW
276
277static tree fake_containing_scope;
278
279/* The number of the current function definition that we are generating
280 debugging information for. These numbers range from 1 up to the maximum
281 number of function definitions contained within the current compilation
282 unit. These numbers are used to create unique labels for various things
283 contained within various function definitions. */
284
285static unsigned current_funcdef_number = 1;
286
7f7429ca
RS
287/* A pointer to the ..._DECL node which we have most recently been working
288 on. We keep this around just in case something about it looks screwy
289 and we want to tell the user what the source coordinates for the actual
290 declaration are. */
291
292static tree dwarf_last_decl;
293
340ccaab
TW
294/* Forward declarations for functions defined in this file. */
295
296static void output_type ();
297static void type_attribute ();
298static void output_decls_for_scope ();
299static void output_decl ();
300static unsigned lookup_filename ();
301\f
302/* Definitions of defaults for assembler-dependent names of various
303 pseudo-ops and section names.
304
305 Theses may be overridden in your tm.h file (if necessary) for your
306 particular assembler. The default values provided here correspond to
307 what is expected by "standard" AT&T System V.4 assemblers. */
308
309#ifndef FILE_ASM_OP
2e494f70 310#define FILE_ASM_OP ".file"
340ccaab
TW
311#endif
312#ifndef VERSION_ASM_OP
2e494f70 313#define VERSION_ASM_OP ".version"
340ccaab 314#endif
340ccaab 315#ifndef UNALIGNED_SHORT_ASM_OP
2e494f70 316#define UNALIGNED_SHORT_ASM_OP ".2byte"
340ccaab
TW
317#endif
318#ifndef UNALIGNED_INT_ASM_OP
2e494f70 319#define UNALIGNED_INT_ASM_OP ".4byte"
340ccaab 320#endif
9a631e8e
RS
321#ifndef ASM_BYTE_OP
322#define ASM_BYTE_OP ".byte"
323#endif
648ebe7b
RS
324#ifndef SET_ASM_OP
325#define SET_ASM_OP ".set"
340ccaab 326#endif
85595d1a
RS
327
328/* Pseudo-ops for pushing the current section onto the section stack (and
329 simultaneously changing to a new section) and for poping back to the
330 section we were in immediately before this one. Note that most svr4
331 assemblers only maintain a one level stack... you can push all the
332 sections you want, but you can only pop out one level. (The sparc
648ebe7b 333 svr4 assembler is an exception to this general rule.) That's
85595d1a
RS
334 OK because we only use at most one level of the section stack herein. */
335
336#ifndef PUSHSECTION_ASM_OP
9a631e8e 337#define PUSHSECTION_ASM_OP ".section"
85595d1a
RS
338#endif
339#ifndef POPSECTION_ASM_OP
9a631e8e 340#define POPSECTION_ASM_OP ".previous"
85595d1a
RS
341#endif
342
343/* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
344 to print the PUSHSECTION_ASM_OP and the section name. The default here
345 works for almost all svr4 assemblers, except for the sparc, where the
346 section name must be enclosed in double quotes. (See sparcv4.h.) */
347
348#ifndef PUSHSECTION_FORMAT
349#define PUSHSECTION_FORMAT "%s\t%s\n"
350#endif
351
352#ifndef DEBUG_SECTION
353#define DEBUG_SECTION ".debug"
354#endif
355#ifndef LINE_SECTION
356#define LINE_SECTION ".line"
357#endif
358#ifndef SFNAMES_SECTION
359#define SFNAMES_SECTION ".debug_sfnames"
360#endif
361#ifndef SRCINFO_SECTION
362#define SRCINFO_SECTION ".debug_srcinfo"
363#endif
364#ifndef MACINFO_SECTION
365#define MACINFO_SECTION ".debug_macinfo"
366#endif
367#ifndef PUBNAMES_SECTION
368#define PUBNAMES_SECTION ".debug_pubnames"
369#endif
370#ifndef ARANGES_SECTION
371#define ARANGES_SECTION ".debug_aranges"
372#endif
373#ifndef TEXT_SECTION
374#define TEXT_SECTION ".text"
375#endif
376#ifndef DATA_SECTION
377#define DATA_SECTION ".data"
378#endif
379#ifndef DATA1_SECTION
380#define DATA1_SECTION ".data1"
381#endif
382#ifndef RODATA_SECTION
383#define RODATA_SECTION ".rodata"
384#endif
385#ifndef RODATA1_SECTION
386#define RODATA1_SECTION ".rodata1"
387#endif
388#ifndef BSS_SECTION
389#define BSS_SECTION ".bss"
390#endif
340ccaab
TW
391\f
392/* Definitions of defaults for formats and names of various special
393 (artificial) labels which may be generated within this file (when
394 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
395
396 If necessary, these may be overridden from within your tm.h file,
9a631e8e
RS
397 but typically, you should never need to override these.
398
399 These labels have been hacked (temporarily) so that they all begin with
648ebe7b
RS
400 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
401 stock m88k/svr4 assembler, both of which need to see .L at the start of
402 a label in order to prevent that label from going into the linker symbol
403 table). When I get time, I'll have to fix this the right way so that we
404 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
405 but that will require a rather massive set of changes. For the moment,
406 the following definitions out to produce the right results for all svr4
407 and svr3 assemblers. -- rfg
9a631e8e 408*/
340ccaab
TW
409
410#ifndef TEXT_BEGIN_LABEL
9a631e8e 411#define TEXT_BEGIN_LABEL ".L_text_b"
340ccaab
TW
412#endif
413#ifndef TEXT_END_LABEL
9a631e8e 414#define TEXT_END_LABEL ".L_text_e"
340ccaab
TW
415#endif
416
417#ifndef DATA_BEGIN_LABEL
9a631e8e 418#define DATA_BEGIN_LABEL ".L_data_b"
340ccaab
TW
419#endif
420#ifndef DATA_END_LABEL
9a631e8e 421#define DATA_END_LABEL ".L_data_e"
340ccaab
TW
422#endif
423
424#ifndef DATA1_BEGIN_LABEL
9a631e8e 425#define DATA1_BEGIN_LABEL ".L_data1_b"
340ccaab
TW
426#endif
427#ifndef DATA1_END_LABEL
9a631e8e 428#define DATA1_END_LABEL ".L_data1_e"
340ccaab
TW
429#endif
430
431#ifndef RODATA_BEGIN_LABEL
9a631e8e 432#define RODATA_BEGIN_LABEL ".L_rodata_b"
340ccaab
TW
433#endif
434#ifndef RODATA_END_LABEL
9a631e8e 435#define RODATA_END_LABEL ".L_rodata_e"
340ccaab
TW
436#endif
437
438#ifndef RODATA1_BEGIN_LABEL
9a631e8e 439#define RODATA1_BEGIN_LABEL ".L_rodata1_b"
340ccaab
TW
440#endif
441#ifndef RODATA1_END_LABEL
9a631e8e 442#define RODATA1_END_LABEL ".L_rodata1_e"
340ccaab
TW
443#endif
444
445#ifndef BSS_BEGIN_LABEL
9a631e8e 446#define BSS_BEGIN_LABEL ".L_bss_b"
340ccaab
TW
447#endif
448#ifndef BSS_END_LABEL
9a631e8e 449#define BSS_END_LABEL ".L_bss_e"
340ccaab
TW
450#endif
451
452#ifndef LINE_BEGIN_LABEL
9a631e8e 453#define LINE_BEGIN_LABEL ".L_line_b"
340ccaab
TW
454#endif
455#ifndef LINE_LAST_ENTRY_LABEL
9a631e8e 456#define LINE_LAST_ENTRY_LABEL ".L_line_last"
340ccaab
TW
457#endif
458#ifndef LINE_END_LABEL
9a631e8e 459#define LINE_END_LABEL ".L_line_e"
340ccaab
TW
460#endif
461
462#ifndef DEBUG_BEGIN_LABEL
9a631e8e 463#define DEBUG_BEGIN_LABEL ".L_debug_b"
340ccaab
TW
464#endif
465#ifndef SFNAMES_BEGIN_LABEL
9a631e8e 466#define SFNAMES_BEGIN_LABEL ".L_sfnames_b"
340ccaab
TW
467#endif
468#ifndef SRCINFO_BEGIN_LABEL
9a631e8e 469#define SRCINFO_BEGIN_LABEL ".L_srcinfo_b"
340ccaab
TW
470#endif
471#ifndef MACINFO_BEGIN_LABEL
9a631e8e 472#define MACINFO_BEGIN_LABEL ".L_macinfo_b"
340ccaab
TW
473#endif
474
475#ifndef DIE_BEGIN_LABEL_FMT
9a631e8e 476#define DIE_BEGIN_LABEL_FMT ".L_D%u"
340ccaab
TW
477#endif
478#ifndef DIE_END_LABEL_FMT
9a631e8e 479#define DIE_END_LABEL_FMT ".L_D%u_e"
340ccaab
TW
480#endif
481#ifndef PUB_DIE_LABEL_FMT
9a631e8e 482#define PUB_DIE_LABEL_FMT ".L_P%u"
340ccaab
TW
483#endif
484#ifndef INSN_LABEL_FMT
9a631e8e 485#define INSN_LABEL_FMT ".L_I%u_%u"
340ccaab
TW
486#endif
487#ifndef BLOCK_BEGIN_LABEL_FMT
9a631e8e 488#define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
340ccaab
TW
489#endif
490#ifndef BLOCK_END_LABEL_FMT
9a631e8e 491#define BLOCK_END_LABEL_FMT ".L_B%u_e"
340ccaab
TW
492#endif
493#ifndef SS_BEGIN_LABEL_FMT
9a631e8e 494#define SS_BEGIN_LABEL_FMT ".L_s%u"
340ccaab
TW
495#endif
496#ifndef SS_END_LABEL_FMT
9a631e8e 497#define SS_END_LABEL_FMT ".L_s%u_e"
340ccaab
TW
498#endif
499#ifndef EE_BEGIN_LABEL_FMT
9a631e8e 500#define EE_BEGIN_LABEL_FMT ".L_e%u"
340ccaab
TW
501#endif
502#ifndef EE_END_LABEL_FMT
9a631e8e 503#define EE_END_LABEL_FMT ".L_e%u_e"
340ccaab
TW
504#endif
505#ifndef MT_BEGIN_LABEL_FMT
9a631e8e 506#define MT_BEGIN_LABEL_FMT ".L_t%u"
340ccaab
TW
507#endif
508#ifndef MT_END_LABEL_FMT
9a631e8e 509#define MT_END_LABEL_FMT ".L_t%u_e"
340ccaab
TW
510#endif
511#ifndef LOC_BEGIN_LABEL_FMT
9a631e8e 512#define LOC_BEGIN_LABEL_FMT ".L_l%u"
340ccaab
TW
513#endif
514#ifndef LOC_END_LABEL_FMT
9a631e8e 515#define LOC_END_LABEL_FMT ".L_l%u_e"
340ccaab
TW
516#endif
517#ifndef BOUND_BEGIN_LABEL_FMT
9a631e8e 518#define BOUND_BEGIN_LABEL_FMT ".L_b%u_%u_%c"
340ccaab
TW
519#endif
520#ifndef BOUND_END_LABEL_FMT
9a631e8e 521#define BOUND_END_LABEL_FMT ".L_b%u_%u_%c_e"
340ccaab
TW
522#endif
523#ifndef DERIV_BEGIN_LABEL_FMT
9a631e8e 524#define DERIV_BEGIN_LABEL_FMT ".L_d%u"
340ccaab
TW
525#endif
526#ifndef DERIV_END_LABEL_FMT
9a631e8e 527#define DERIV_END_LABEL_FMT ".L_d%u_e"
340ccaab
TW
528#endif
529#ifndef SL_BEGIN_LABEL_FMT
9a631e8e 530#define SL_BEGIN_LABEL_FMT ".L_sl%u"
340ccaab
TW
531#endif
532#ifndef SL_END_LABEL_FMT
9a631e8e 533#define SL_END_LABEL_FMT ".L_sl%u_e"
340ccaab
TW
534#endif
535#ifndef FUNC_END_LABEL_FMT
9a631e8e 536#define FUNC_END_LABEL_FMT ".L_f%u_e"
340ccaab
TW
537#endif
538#ifndef TYPE_NAME_FMT
9a631e8e 539#define TYPE_NAME_FMT ".L_T%u"
340ccaab 540#endif
04077c53
RS
541#ifndef DECL_NAME_FMT
542#define DECL_NAME_FMT ".L_E%u"
543#endif
340ccaab 544#ifndef LINE_CODE_LABEL_FMT
9a631e8e 545#define LINE_CODE_LABEL_FMT ".L_LC%u"
340ccaab
TW
546#endif
547#ifndef SFNAMES_ENTRY_LABEL_FMT
9a631e8e 548#define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
340ccaab
TW
549#endif
550#ifndef LINE_ENTRY_LABEL_FMT
9a631e8e 551#define LINE_ENTRY_LABEL_FMT ".L_LE%u"
340ccaab
TW
552#endif
553\f
554/* Definitions of defaults for various types of primitive assembly language
555 output operations.
556
557 If necessary, these may be overridden from within your tm.h file,
648ebe7b
RS
558 but typically, you shouldn't need to override these. One known
559 exception is ASM_OUTPUT_DEF which has to be different for stock
560 sparc/svr4 assemblers.
85595d1a
RS
561*/
562
563#ifndef ASM_OUTPUT_PUSH_SECTION
564#define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
565 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
566#endif
567
568#ifndef ASM_OUTPUT_POP_SECTION
569#define ASM_OUTPUT_POP_SECTION(FILE) \
9a631e8e 570 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
85595d1a 571#endif
340ccaab
TW
572
573#ifndef ASM_OUTPUT_SOURCE_FILENAME
574#define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
2e494f70 575 fprintf ((FILE), "\t%s\t\"%s\"\n", FILE_ASM_OP, NAME)
340ccaab
TW
576#endif
577
578#ifndef ASM_OUTPUT_DEF
579#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
648ebe7b 580 do { fprintf ((FILE), "\t%s\t", SET_ASM_OP); \
340ccaab
TW
581 assemble_name (FILE, LABEL1); \
582 fprintf (FILE, ","); \
583 assemble_name (FILE, LABEL2); \
584 fprintf (FILE, "\n"); \
585 } while (0)
586#endif
587
340ccaab
TW
588#ifndef ASM_OUTPUT_DWARF_DELTA2
589#define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
2e494f70 590 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
340ccaab
TW
591 assemble_name (FILE, LABEL1); \
592 fprintf (FILE, "-"); \
593 assemble_name (FILE, LABEL2); \
594 fprintf (FILE, "\n"); \
595 } while (0)
596#endif
597
598#ifndef ASM_OUTPUT_DWARF_DELTA4
599#define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
2e494f70 600 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
340ccaab
TW
601 assemble_name (FILE, LABEL1); \
602 fprintf (FILE, "-"); \
603 assemble_name (FILE, LABEL2); \
604 fprintf (FILE, "\n"); \
605 } while (0)
606#endif
607
608#ifndef ASM_OUTPUT_DWARF_TAG
609#define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
9a631e8e
RS
610 do { \
611 fprintf ((FILE), "\t%s\t0x%x", \
612 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
613 if (flag_verbose_asm) \
614 fprintf ((FILE), "\t%s %s", \
615 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
616 fputc ('\n', (FILE)); \
617 } while (0)
340ccaab
TW
618#endif
619
620#ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
9a631e8e
RS
621#define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
622 do { \
623 fprintf ((FILE), "\t%s\t0x%x", \
624 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
625 if (flag_verbose_asm) \
626 fprintf ((FILE), "\t%s %s", \
627 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
628 fputc ('\n', (FILE)); \
629 } while (0)
340ccaab
TW
630#endif
631
632#ifndef ASM_OUTPUT_DWARF_STACK_OP
633#define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
9a631e8e 634 do { \
648ebe7b 635 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
9a631e8e
RS
636 if (flag_verbose_asm) \
637 fprintf ((FILE), "\t%s %s", \
638 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
639 fputc ('\n', (FILE)); \
640 } while (0)
340ccaab
TW
641#endif
642
643#ifndef ASM_OUTPUT_DWARF_FUND_TYPE
644#define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
9a631e8e
RS
645 do { \
646 fprintf ((FILE), "\t%s\t0x%x", \
647 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
648 if (flag_verbose_asm) \
649 fprintf ((FILE), "\t%s %s", \
650 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
651 fputc ('\n', (FILE)); \
652 } while (0)
340ccaab
TW
653#endif
654
655#ifndef ASM_OUTPUT_DWARF_FMT_BYTE
656#define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
9a631e8e 657 do { \
648ebe7b 658 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
9a631e8e
RS
659 if (flag_verbose_asm) \
660 fprintf ((FILE), "\t%s %s", \
661 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
662 fputc ('\n', (FILE)); \
663 } while (0)
340ccaab
TW
664#endif
665
666#ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
667#define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
9a631e8e 668 do { \
648ebe7b 669 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
9a631e8e
RS
670 if (flag_verbose_asm) \
671 fprintf ((FILE), "\t%s %s", \
672 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
673 fputc ('\n', (FILE)); \
674 } while (0)
340ccaab
TW
675#endif
676\f
677#ifndef ASM_OUTPUT_DWARF_ADDR
678#define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
2e494f70 679 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
340ccaab
TW
680 assemble_name (FILE, LABEL); \
681 fprintf (FILE, "\n"); \
682 } while (0)
683#endif
684
685#ifndef ASM_OUTPUT_DWARF_ADDR_CONST
686#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
648ebe7b
RS
687 do { \
688 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
689 output_addr_const ((FILE), (RTX)); \
690 fputc ('\n', (FILE)); \
691 } while (0)
340ccaab
TW
692#endif
693
694#ifndef ASM_OUTPUT_DWARF_REF
695#define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
2e494f70 696 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
340ccaab
TW
697 assemble_name (FILE, LABEL); \
698 fprintf (FILE, "\n"); \
699 } while (0)
700#endif
701
702#ifndef ASM_OUTPUT_DWARF_DATA1
703#define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
648ebe7b 704 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
340ccaab
TW
705#endif
706
707#ifndef ASM_OUTPUT_DWARF_DATA2
708#define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
2e494f70 709 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
340ccaab
TW
710#endif
711
712#ifndef ASM_OUTPUT_DWARF_DATA4
713#define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
2e494f70 714 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
340ccaab
TW
715#endif
716
717#ifndef ASM_OUTPUT_DWARF_DATA8
718#define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
719 do { \
720 if (WORDS_BIG_ENDIAN) \
721 { \
2e494f70
RS
722 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
723 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
340ccaab
TW
724 } \
725 else \
726 { \
2e494f70
RS
727 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
728 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
340ccaab
TW
729 } \
730 } while (0)
731#endif
732
733#ifndef ASM_OUTPUT_DWARF_STRING
734#define ASM_OUTPUT_DWARF_STRING(FILE,P) \
735 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
736#endif
737\f
738/************************ general utility functions **************************/
739
740inline char *
741xstrdup (s)
742 register char *s;
743{
744 register char *p = (char *) xmalloc (strlen (s) + 1);
745
746 strcpy (p, s);
747 return p;
748}
749
648ebe7b
RS
750inline int
751is_pseudo_reg (rtl)
752 register rtx rtl;
753{
754 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
755 || ((GET_CODE (rtl) == SUBREG)
756 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
757}
758
c7d6dca2
RS
759/* Return non-zero if the given type node represents a tagged type. */
760
761inline int
762is_tagged_type (type)
763 register tree type;
764{
765 register enum tree_code code = TREE_CODE (type);
766
767 return (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE);
768}
769
340ccaab 770static char *
9a631e8e 771dwarf_tag_name (tag)
340ccaab
TW
772 register unsigned tag;
773{
774 switch (tag)
775 {
9a631e8e
RS
776 case TAG_padding: return "TAG_padding";
777 case TAG_array_type: return "TAG_array_type";
778 case TAG_class_type: return "TAG_class_type";
779 case TAG_entry_point: return "TAG_entry_point";
780 case TAG_enumeration_type: return "TAG_enumeration_type";
781 case TAG_formal_parameter: return "TAG_formal_parameter";
782 case TAG_global_subroutine: return "TAG_global_subroutine";
783 case TAG_global_variable: return "TAG_global_variable";
784 case TAG_label: return "TAG_label";
785 case TAG_lexical_block: return "TAG_lexical_block";
786 case TAG_local_variable: return "TAG_local_variable";
787 case TAG_member: return "TAG_member";
788 case TAG_pointer_type: return "TAG_pointer_type";
789 case TAG_reference_type: return "TAG_reference_type";
790 case TAG_compile_unit: return "TAG_compile_unit";
791 case TAG_string_type: return "TAG_string_type";
792 case TAG_structure_type: return "TAG_structure_type";
793 case TAG_subroutine: return "TAG_subroutine";
794 case TAG_subroutine_type: return "TAG_subroutine_type";
795 case TAG_typedef: return "TAG_typedef";
796 case TAG_union_type: return "TAG_union_type";
340ccaab 797 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
9a631e8e
RS
798 case TAG_variant: return "TAG_variant";
799 case TAG_common_block: return "TAG_common_block";
800 case TAG_common_inclusion: return "TAG_common_inclusion";
801 case TAG_inheritance: return "TAG_inheritance";
802 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
803 case TAG_module: return "TAG_module";
804 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
805 case TAG_set_type: return "TAG_set_type";
806 case TAG_subrange_type: return "TAG_subrange_type";
807 case TAG_with_stmt: return "TAG_with_stmt";
808
809 /* GNU extensions. */
810
811 case TAG_format_label: return "TAG_format_label";
812 case TAG_namelist: return "TAG_namelist";
813 case TAG_function_template: return "TAG_function_template";
814 case TAG_class_template: return "TAG_class_template";
815
04077c53 816 default: return "TAG_<unknown>";
340ccaab
TW
817 }
818}
819
820static char *
9a631e8e 821dwarf_attr_name (attr)
340ccaab
TW
822 register unsigned attr;
823{
824 switch (attr)
825 {
9a631e8e
RS
826 case AT_sibling: return "AT_sibling";
827 case AT_location: return "AT_location";
828 case AT_name: return "AT_name";
829 case AT_fund_type: return "AT_fund_type";
830 case AT_mod_fund_type: return "AT_mod_fund_type";
831 case AT_user_def_type: return "AT_user_def_type";
832 case AT_mod_u_d_type: return "AT_mod_u_d_type";
833 case AT_ordering: return "AT_ordering";
834 case AT_subscr_data: return "AT_subscr_data";
835 case AT_byte_size: return "AT_byte_size";
836 case AT_bit_offset: return "AT_bit_offset";
837 case AT_bit_size: return "AT_bit_size";
838 case AT_element_list: return "AT_element_list";
839 case AT_stmt_list: return "AT_stmt_list";
840 case AT_low_pc: return "AT_low_pc";
841 case AT_high_pc: return "AT_high_pc";
842 case AT_language: return "AT_language";
843 case AT_member: return "AT_member";
844 case AT_discr: return "AT_discr";
845 case AT_discr_value: return "AT_discr_value";
846 case AT_string_length: return "AT_string_length";
847 case AT_common_reference: return "AT_common_reference";
848 case AT_comp_dir: return "AT_comp_dir";
849 case AT_const_value_string: return "AT_const_value_string";
850 case AT_const_value_data2: return "AT_const_value_data2";
851 case AT_const_value_data4: return "AT_const_value_data4";
852 case AT_const_value_data8: return "AT_const_value_data8";
853 case AT_const_value_block2: return "AT_const_value_block2";
340ccaab 854 case AT_const_value_block4: return "AT_const_value_block4";
9a631e8e
RS
855 case AT_containing_type: return "AT_containing_type";
856 case AT_default_value_addr: return "AT_default_value_addr";
857 case AT_default_value_data2: return "AT_default_value_data2";
858 case AT_default_value_data4: return "AT_default_value_data4";
859 case AT_default_value_data8: return "AT_default_value_data8";
860 case AT_default_value_string: return "AT_default_value_string";
861 case AT_friends: return "AT_friends";
862 case AT_inline: return "AT_inline";
863 case AT_is_optional: return "AT_is_optional";
864 case AT_lower_bound_ref: return "AT_lower_bound_ref";
865 case AT_lower_bound_data2: return "AT_lower_bound_data2";
866 case AT_lower_bound_data4: return "AT_lower_bound_data4";
867 case AT_lower_bound_data8: return "AT_lower_bound_data8";
868 case AT_private: return "AT_private";
869 case AT_producer: return "AT_producer";
870 case AT_program: return "AT_program";
871 case AT_protected: return "AT_protected";
872 case AT_prototyped: return "AT_prototyped";
873 case AT_public: return "AT_public";
874 case AT_pure_virtual: return "AT_pure_virtual";
875 case AT_return_addr: return "AT_return_addr";
04077c53 876 case AT_abstract_origin: return "AT_abstract_origin";
9a631e8e
RS
877 case AT_start_scope: return "AT_start_scope";
878 case AT_stride_size: return "AT_stride_size";
879 case AT_upper_bound_ref: return "AT_upper_bound_ref";
880 case AT_upper_bound_data2: return "AT_upper_bound_data2";
881 case AT_upper_bound_data4: return "AT_upper_bound_data4";
882 case AT_upper_bound_data8: return "AT_upper_bound_data8";
883 case AT_virtual: return "AT_virtual";
884
885 /* GNU extensions */
886
887 case AT_sf_names: return "AT_sf_names";
888 case AT_src_info: return "AT_src_info";
889 case AT_mac_info: return "AT_mac_info";
890 case AT_src_coords: return "AT_src_coords";
891
04077c53 892 default: return "AT_<unknown>";
340ccaab
TW
893 }
894}
895
896static char *
9a631e8e 897dwarf_stack_op_name (op)
340ccaab
TW
898 register unsigned op;
899{
900 switch (op)
901 {
902 case OP_REG: return "OP_REG";
903 case OP_BASEREG: return "OP_BASEREG";
904 case OP_ADDR: return "OP_ADDR";
905 case OP_CONST: return "OP_CONST";
906 case OP_DEREF2: return "OP_DEREF2";
907 case OP_DEREF4: return "OP_DEREF4";
908 case OP_ADD: return "OP_ADD";
04077c53 909 default: return "OP_<unknown>";
340ccaab
TW
910 }
911}
912
913static char *
9a631e8e 914dwarf_typemod_name (mod)
340ccaab
TW
915 register unsigned mod;
916{
917 switch (mod)
918 {
919 case MOD_pointer_to: return "MOD_pointer_to";
920 case MOD_reference_to: return "MOD_reference_to";
921 case MOD_const: return "MOD_const";
922 case MOD_volatile: return "MOD_volatile";
04077c53 923 default: return "MOD_<unknown>";
340ccaab
TW
924 }
925}
926
927static char *
9a631e8e 928dwarf_fmt_byte_name (fmt)
340ccaab
TW
929 register unsigned fmt;
930{
931 switch (fmt)
932 {
933 case FMT_FT_C_C: return "FMT_FT_C_C";
934 case FMT_FT_C_X: return "FMT_FT_C_X";
935 case FMT_FT_X_C: return "FMT_FT_X_C";
936 case FMT_FT_X_X: return "FMT_FT_X_X";
937 case FMT_UT_C_C: return "FMT_UT_C_C";
938 case FMT_UT_C_X: return "FMT_UT_C_X";
939 case FMT_UT_X_C: return "FMT_UT_X_C";
940 case FMT_UT_X_X: return "FMT_UT_X_X";
941 case FMT_ET: return "FMT_ET";
04077c53 942 default: return "FMT_<unknown>";
340ccaab
TW
943 }
944}
945static char *
9a631e8e 946dwarf_fund_type_name (ft)
340ccaab
TW
947 register unsigned ft;
948{
949 switch (ft)
950 {
951 case FT_char: return "FT_char";
952 case FT_signed_char: return "FT_signed_char";
953 case FT_unsigned_char: return "FT_unsigned_char";
954 case FT_short: return "FT_short";
955 case FT_signed_short: return "FT_signed_short";
956 case FT_unsigned_short: return "FT_unsigned_short";
957 case FT_integer: return "FT_integer";
958 case FT_signed_integer: return "FT_signed_integer";
959 case FT_unsigned_integer: return "FT_unsigned_integer";
960 case FT_long: return "FT_long";
961 case FT_signed_long: return "FT_signed_long";
962 case FT_unsigned_long: return "FT_unsigned_long";
963 case FT_pointer: return "FT_pointer";
964 case FT_float: return "FT_float";
965 case FT_dbl_prec_float: return "FT_dbl_prec_float";
966 case FT_ext_prec_float: return "FT_ext_prec_float";
967 case FT_complex: return "FT_complex";
968 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
969 case FT_void: return "FT_void";
970 case FT_boolean: return "FT_boolean";
9a631e8e
RS
971 case FT_ext_prec_complex: return "FT_ext_prec_complex";
972 case FT_label: return "FT_label";
973
974 /* GNU extensions. */
975
340ccaab
TW
976 case FT_long_long: return "FT_long_long";
977 case FT_signed_long_long: return "FT_signed_long_long";
978 case FT_unsigned_long_long: return "FT_unsigned_long_long";
9a631e8e
RS
979
980 case FT_int8: return "FT_int8";
981 case FT_signed_int8: return "FT_signed_int8";
982 case FT_unsigned_int8: return "FT_unsigned_int8";
983 case FT_int16: return "FT_int16";
984 case FT_signed_int16: return "FT_signed_int16";
985 case FT_unsigned_int16: return "FT_unsigned_int16";
986 case FT_int32: return "FT_int32";
987 case FT_signed_int32: return "FT_signed_int32";
988 case FT_unsigned_int32: return "FT_unsigned_int32";
989 case FT_int64: return "FT_int64";
990 case FT_signed_int64: return "FT_signed_int64";
991 case FT_unsigned_int64: return "FT_signed_int64";
992
993 case FT_real32: return "FT_real32";
994 case FT_real64: return "FT_real64";
995 case FT_real96: return "FT_real96";
996 case FT_real128: return "FT_real128";
997
cb712ad4 998 default: return "FT_<unknown>";
340ccaab
TW
999 }
1000}
cb712ad4
RS
1001
1002/* Determine the "ultimate origin" of a decl. The decl may be an
1003 inlined instance of an inlined instance of a decl which is local
1004 to an inline function, so we have to trace all of the way back
1005 through the origin chain to find out what sort of node actually
1006 served as the original seed for the given block. */
1007
1008static tree
1009decl_ultimate_origin (decl)
1010 register tree decl;
1011{
1012 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1013
1014 if (immediate_origin == NULL)
1015 return NULL;
1016 else
1017 {
1018 register tree ret_val;
1019 register tree lookahead = immediate_origin;
1020
1021 do
1022 {
1023 ret_val = lookahead;
1024 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1025 }
1026 while (lookahead != NULL && lookahead != ret_val);
1027 return ret_val;
1028 }
1029}
1030
ece0ca60
RS
1031/* Determine the "ultimate origin" of a block. The block may be an
1032 inlined instance of an inlined instance of a block which is local
1033 to an inline function, so we have to trace all of the way back
1034 through the origin chain to find out what sort of node actually
1035 served as the original seed for the given block. */
1036
1037static tree
1038block_ultimate_origin (block)
1039 register tree block;
1040{
1041 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1042
1043 if (immediate_origin == NULL)
1044 return NULL;
1045 else
1046 {
1047 register tree ret_val;
1048 register tree lookahead = immediate_origin;
1049
1050 do
1051 {
1052 ret_val = lookahead;
1053 lookahead = (TREE_CODE (ret_val) == BLOCK)
1054 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1055 : NULL;
1056 }
1057 while (lookahead != NULL && lookahead != ret_val);
1058 return ret_val;
1059 }
1060}
1061
cb712ad4
RS
1062static void
1063output_unsigned_leb128 (value)
1064 register unsigned long value;
1065{
1066 register unsigned long orig_value = value;
1067
1068 do
1069 {
1070 register unsigned byte = (value & 0x7f);
1071
1072 value >>= 7;
1073 if (value != 0) /* more bytes to follow */
1074 byte |= 0x80;
1075 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1076 if (flag_verbose_asm && value == 0)
1077 fprintf (asm_out_file, "\t%s ULEB128 number - value = %u",
1078 ASM_COMMENT_START, orig_value);
1079 fputc ('\n', asm_out_file);
1080 }
1081 while (value != 0);
1082}
1083
1084static void
1085output_signed_leb128 (value)
1086 register long value;
1087{
1088 register long orig_value = value;
1089 register int negative = (value < 0);
1090 register int more;
1091
1092 do
1093 {
1094 register unsigned byte = (value & 0x7f);
1095
1096 value >>= 7;
1097 if (negative)
1098 value |= 0xfe000000; /* manually sign extend */
1099 if (((value == 0) && ((byte & 0x40) == 0))
1100 || ((value == -1) && ((byte & 0x40) == 1)))
1101 more = 0;
1102 else
1103 {
1104 byte |= 0x80;
1105 more = 1;
1106 }
1107 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1108 if (flag_verbose_asm && more == 0)
1109 fprintf (asm_out_file, "\t%s SLEB128 number - value = %d",
1110 ASM_COMMENT_START, orig_value);
1111 fputc ('\n', asm_out_file);
1112 }
1113 while (more);
1114}
340ccaab
TW
1115\f
1116/**************** utility functions for attribute functions ******************/
1117
04077c53 1118/* Given a pointer to a BLOCK node return non-zero if (and only if) the
3abacf02
RS
1119 node in question represents the outermost pair of curly braces (i.e.
1120 the "body block") of a function or method.
1121
1122 For any BLOCK node representing a "body block" of a function or method,
1123 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1124 which represents the outermost (function) scope for the function or
1125 method (i.e. the one which includes the formal parameters). The
1126 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1127 FUNCTION_DECL node.
04077c53
RS
1128*/
1129
1130inline int
1131is_body_block (stmt)
1132 register tree stmt;
1133{
3abacf02
RS
1134 if (TREE_CODE (stmt) == BLOCK)
1135 {
1136 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1137
1138 if (TREE_CODE (parent) == BLOCK)
1139 {
1140 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
04077c53 1141
3abacf02
RS
1142 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1143 return 1;
1144 }
1145 }
1146 return 0;
04077c53
RS
1147}
1148
340ccaab
TW
1149/* Given a pointer to a tree node for some type, return a Dwarf fundamental
1150 type code for the given type.
1151
1152 This routine must only be called for GCC type nodes that correspond to
1153 Dwarf fundamental types.
1154
1155 The current Dwarf draft specification calls for Dwarf fundamental types
1156 to accurately reflect the fact that a given type was either a "plain"
3f7cc57a 1157 integral type or an explicitly "signed" integral type. Unfortunately,
340ccaab
TW
1158 we can't always do this, because GCC may already have thrown away the
1159 information about the precise way in which the type was originally
1160 specified, as in:
1161
b083f44d 1162 typedef signed int my_type;
340ccaab 1163
b083f44d 1164 struct s { my_type f; };
340ccaab
TW
1165
1166 Since we may be stuck here without enought information to do exactly
1167 what is called for in the Dwarf draft specification, we do the best
1168 that we can under the circumstances and always use the "plain" integral
1169 fundamental type codes for int, short, and long types. That's probably
1170 good enough. The additional accuracy called for in the current DWARF
1171 draft specification is probably never even useful in practice. */
1172
1173static int
1174fundamental_type_code (type)
1175 register tree type;
1176{
1177 if (TREE_CODE (type) == ERROR_MARK)
1178 return 0;
1179
1180 switch (TREE_CODE (type))
1181 {
1182 case ERROR_MARK:
1183 return FT_void;
1184
1185 case VOID_TYPE:
1186 return FT_void;
1187
1188 case INTEGER_TYPE:
1189 /* Carefully distinguish all the standard types of C,
1190 without messing up if the language is not C.
1191 Note that we check only for the names that contain spaces;
1192 other names might occur by coincidence in other languages. */
1193 if (TYPE_NAME (type) != 0
1194 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1195 && DECL_NAME (TYPE_NAME (type)) != 0
1196 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1197 {
1198 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1199
1200 if (!strcmp (name, "unsigned char"))
1201 return FT_unsigned_char;
1202 if (!strcmp (name, "signed char"))
1203 return FT_signed_char;
1204 if (!strcmp (name, "unsigned int"))
1205 return FT_unsigned_integer;
1206 if (!strcmp (name, "short int"))
1207 return FT_short;
1208 if (!strcmp (name, "short unsigned int"))
1209 return FT_unsigned_short;
1210 if (!strcmp (name, "long int"))
1211 return FT_long;
1212 if (!strcmp (name, "long unsigned int"))
1213 return FT_unsigned_long;
1214 if (!strcmp (name, "long long int"))
1215 return FT_long_long; /* Not grok'ed by svr4 SDB */
1216 if (!strcmp (name, "long long unsigned int"))
1217 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1218 }
1219
1220 /* Most integer types will be sorted out above, however, for the
1221 sake of special `array index' integer types, the following code
1222 is also provided. */
1223
1224 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1225 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1226
1227 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1228 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1229
1230 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1231 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1232
1233 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1234 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1235
1236 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1237 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1238
1239 abort ();
1240
1241 case REAL_TYPE:
1242 /* Carefully distinguish all the standard types of C,
1243 without messing up if the language is not C. */
1244 if (TYPE_NAME (type) != 0
1245 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1246 && DECL_NAME (TYPE_NAME (type)) != 0
1247 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1248 {
1249 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1250
1251 /* Note that here we can run afowl of a serious bug in "classic"
1252 svr4 SDB debuggers. They don't seem to understand the
1253 FT_ext_prec_float type (even though they should). */
1254
1255 if (!strcmp (name, "long double"))
1256 return FT_ext_prec_float;
1257 }
1258
1259 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1260 return FT_dbl_prec_float;
1261 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1262 return FT_float;
1263
1264 /* Note that here we can run afowl of a serious bug in "classic"
1265 svr4 SDB debuggers. They don't seem to understand the
1266 FT_ext_prec_float type (even though they should). */
1267
1268 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1269 return FT_ext_prec_float;
1270 abort ();
1271
1272 case COMPLEX_TYPE:
1273 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1274
1275 case CHAR_TYPE:
1276 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1277
1278 case BOOLEAN_TYPE:
1279 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1280
1281 default:
1282 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1283 }
1284 return 0;
1285}
1286\f
1287/* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1288 the Dwarf "root" type for the given input type. The Dwarf "root" type
1289 of a given type is generally the same as the given type, except that if
1290 the given type is a pointer or reference type, then the root type of
1291 the given type is the root type of the "basis" type for the pointer or
1292 reference type. (This definition of the "root" type is recursive.)
1293 Also, the root type of a `const' qualified type or a `volatile'
1294 qualified type is the root type of the given type without the
1295 qualifiers. */
1296
1297static tree
1298root_type (type)
1299 register tree type;
1300{
1301 if (TREE_CODE (type) == ERROR_MARK)
1302 return error_mark_node;
1303
1304 switch (TREE_CODE (type))
1305 {
1306 case ERROR_MARK:
1307 return error_mark_node;
1308
1309 case POINTER_TYPE:
1310 case REFERENCE_TYPE:
1311 return TYPE_MAIN_VARIANT (root_type (TREE_TYPE (type)));
1312
1313 default:
1314 return TYPE_MAIN_VARIANT (type);
1315 }
1316}
1317
1318/* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1319 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1320
1321static void
1322write_modifier_bytes (type, decl_const, decl_volatile)
1323 register tree type;
1324 register int decl_const;
1325 register int decl_volatile;
1326{
1327 if (TREE_CODE (type) == ERROR_MARK)
1328 return;
1329
1330 if (TYPE_READONLY (type) || decl_const)
1331 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1332 if (TYPE_VOLATILE (type) || decl_volatile)
1333 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1334 switch (TREE_CODE (type))
1335 {
1336 case POINTER_TYPE:
1337 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1338 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1339 return;
1340
1341 case REFERENCE_TYPE:
1342 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1343 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1344 return;
1345
1346 case ERROR_MARK:
1347 default:
1348 return;
1349 }
1350}
1351\f
1352/* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1353 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1354
1355inline int
1356type_is_fundamental (type)
1357 register tree type;
1358{
1359 switch (TREE_CODE (type))
1360 {
1361 case ERROR_MARK:
1362 case VOID_TYPE:
1363 case INTEGER_TYPE:
1364 case REAL_TYPE:
1365 case COMPLEX_TYPE:
1366 case BOOLEAN_TYPE:
1367 case CHAR_TYPE:
1368 return 1;
1369
1370 case SET_TYPE:
1371 case ARRAY_TYPE:
1372 case RECORD_TYPE:
1373 case UNION_TYPE:
1374 case ENUMERAL_TYPE:
1375 case FUNCTION_TYPE:
1376 case METHOD_TYPE:
1377 case POINTER_TYPE:
1378 case REFERENCE_TYPE:
1379 case STRING_TYPE:
1380 case FILE_TYPE:
1381 case OFFSET_TYPE:
1382 case LANG_TYPE:
1383 return 0;
1384
1385 default:
1386 abort ();
1387 }
1388 return 0;
1389}
1390
04077c53
RS
1391/* Given a pointer to some ..._DECL tree node, generate an assembly language
1392 equate directive which will associate a symbolic name with the current DIE.
1393
1394 The name used is an artificial label generated from the DECL_UID number
1395 associated with the given decl node. The name it gets equated to is the
1396 symbolic label that we (previously) output at the start of the DIE that
1397 we are currently generating.
1398
1399 Calling this function while generating some "decl related" form of DIE
1400 makes it possible to later refer to the DIE which represents the given
1401 decl simply by re-generating the symbolic name from the ..._DECL node's
1402 UID number. */
1403
1404static void
1405equate_decl_number_to_die_number (decl)
1406 register tree decl;
1407{
1408 /* In the case where we are generating a DIE for some ..._DECL node
1409 which represents either some inline function declaration or some
1410 entity declared within an inline function declaration/definition,
1411 setup a symbolic name for the current DIE so that we have a name
1412 for this DIE that we can easily refer to later on within
1413 AT_abstract_origin attributes. */
1414
1415 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1416 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1417
1418 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1419 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1420 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1421}
1422
340ccaab 1423/* Given a pointer to some ..._TYPE tree node, generate an assembly language
04077c53 1424 equate directive which will associate a symbolic name with the current DIE.
340ccaab
TW
1425
1426 The name used is an artificial label generated from the TYPE_UID number
1427 associated with the given type node. The name it gets equated to is the
1428 symbolic label that we (previously) output at the start of the DIE that
1429 we are currently generating.
1430
1431 Calling this function while generating some "type related" form of DIE
1432 makes it easy to later refer to the DIE which represents the given type
1433 simply by re-generating the alternative name from the ..._TYPE node's
1434 UID number. */
1435
1436inline void
1437equate_type_number_to_die_number (type)
1438 register tree type;
1439{
1440 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1441 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1442
1443 /* We are generating a DIE to represent the main variant of this type
1444 (i.e the type without any const or volatile qualifiers) so in order
1445 to get the equate to come out right, we need to get the main variant
1446 itself here. */
1447
1448 type = TYPE_MAIN_VARIANT (type);
1449
1450 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1451 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1452 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1453}
1454
7f7429ca
RS
1455static void
1456output_reg_number (rtl)
1457 register rtx rtl;
1458{
1459 register unsigned regno = REGNO (rtl);
1460
1461 if (regno >= FIRST_PSEUDO_REGISTER)
1462 {
1463 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1464 regno);
1465 regno = 0;
1466 }
1467 fprintf (asm_out_file, "\t%s\t0x%x",
1468 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1469 if (flag_verbose_asm)
1470 {
1471 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1472 PRINT_REG (rtl, 0, asm_out_file);
1473 }
1474 fputc ('\n', asm_out_file);
1475}
1476
340ccaab
TW
1477/* The following routine is a nice and simple transducer. It converts the
1478 RTL for a variable or parameter (resident in memory) into an equivalent
1479 Dwarf representation of a mechanism for getting the address of that same
1480 variable onto the top of a hypothetical "address evaluation" stack.
1481
1482 When creating memory location descriptors, we are effectively trans-
1483 forming the RTL for a memory-resident object into its Dwarf postfix
1484 expression equivalent. This routine just recursively descends an
1485 RTL tree, turning it into Dwarf postfix code as it goes. */
1486
1487static void
1488output_mem_loc_descriptor (rtl)
1489 register rtx rtl;
1490{
1491 /* Note that for a dynamically sized array, the location we will
1492 generate a description of here will be the lowest numbered location
1493 which is actually within the array. That's *not* necessarily the
1494 same as the zeroth element of the array. */
1495
1496 switch (GET_CODE (rtl))
1497 {
1498 case SUBREG:
1499
1500 /* The case of a subreg may arise when we have a local (register)
1501 variable or a formal (register) parameter which doesn't quite
1502 fill up an entire register. For now, just assume that it is
1503 legitimate to make the Dwarf info refer to the whole register
1504 which contains the given subreg. */
1505
1506 rtl = XEXP (rtl, 0);
1507 /* Drop thru. */
1508
1509 case REG:
1510
1511 /* Whenever a register number forms a part of the description of
1512 the method for calculating the (dynamic) address of a memory
52cdd5e5 1513 resident object, DWARF rules require the register number to
340ccaab
TW
1514 be referred to as a "base register". This distinction is not
1515 based in any way upon what category of register the hardware
1516 believes the given register belongs to. This is strictly
8c24a2ce 1517 DWARF terminology we're dealing with here.
28b039e3
RS
1518
1519 Note that in cases where the location of a memory-resident data
1520 object could be expressed as:
1521
1522 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1523
1524 the actual DWARF location descriptor that we generate may just
1525 be OP_BASEREG (basereg). This may look deceptively like the
1526 object in question was allocated to a register (rather than
1527 in memory) so DWARF consumers need to be aware of the subtle
52cdd5e5 1528 distinction between OP_REG and OP_BASEREG. */
340ccaab
TW
1529
1530 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
7f7429ca 1531 output_reg_number (rtl);
340ccaab
TW
1532 break;
1533
1534 case MEM:
1535 output_mem_loc_descriptor (XEXP (rtl, 0));
1536 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1537 break;
1538
1539 case CONST:
1540 case SYMBOL_REF:
1541 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1542 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1543 break;
1544
1545 case PLUS:
1546 output_mem_loc_descriptor (XEXP (rtl, 0));
1547 output_mem_loc_descriptor (XEXP (rtl, 1));
1548 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1549 break;
1550
1551 case CONST_INT:
1552 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1553 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1554 break;
1555
1556 default:
1557 abort ();
1558 }
1559}
1560
1561/* Output a proper Dwarf location descriptor for a variable or parameter
1562 which is either allocated in a register or in a memory location. For
1563 a register, we just generate an OP_REG and the register number. For a
1564 memory location we provide a Dwarf postfix expression describing how to
1565 generate the (dynamic) address of the object onto the address stack. */
1566
1567static void
1568output_loc_descriptor (rtl)
1569 register rtx rtl;
1570{
1571 switch (GET_CODE (rtl))
1572 {
1573 case SUBREG:
1574
1575 /* The case of a subreg may arise when we have a local (register)
1576 variable or a formal (register) parameter which doesn't quite
1577 fill up an entire register. For now, just assume that it is
1578 legitimate to make the Dwarf info refer to the whole register
1579 which contains the given subreg. */
1580
1581 rtl = XEXP (rtl, 0);
1582 /* Drop thru. */
1583
1584 case REG:
1585 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
7f7429ca 1586 output_reg_number (rtl);
340ccaab
TW
1587 break;
1588
1589 case MEM:
1590 output_mem_loc_descriptor (XEXP (rtl, 0));
1591 break;
1592
1593 default:
1594 abort (); /* Should never happen */
1595 }
1596}
1597
1598/* Given a tree node describing an array bound (either lower or upper)
1599 output a representation for that bound. */
1600
1601static void
1602output_bound_representation (bound, dim_num, u_or_l)
1603 register tree bound;
1604 register unsigned dim_num; /* For multi-dimensional arrays. */
1605 register char u_or_l; /* Designates upper or lower bound. */
1606{
1607 switch (TREE_CODE (bound))
1608 {
1609
1610 case ERROR_MARK:
1611 return;
1612
1613 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1614
1615 case INTEGER_CST:
1616 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1617 (unsigned) TREE_INT_CST_LOW (bound));
1618 break;
1619
1620 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1621 SAVE_EXPR nodes. */
1622
1623 case NOP_EXPR:
1624 bound = TREE_OPERAND (bound, 0);
1625 /* ... fall thru... */
1626
1627 case SAVE_EXPR:
1628 {
1629 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1630 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1631
1632 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1633 current_dienum, dim_num, u_or_l);
1634
1635 sprintf (end_label, BOUND_END_LABEL_FMT,
1636 current_dienum, dim_num, u_or_l);
1637
1638 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1639 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1640
1641 /* If we are working on a bound for a dynamic dimension in C,
1642 the dynamic dimension in question had better have a static
1643 (zero) lower bound and a dynamic *upper* bound. */
1644
1645 if (u_or_l != 'u')
1646 abort ();
1647
1648 /* If optimization is turned on, the SAVE_EXPRs that describe
1649 how to access the upper bound values are essentially bogus.
1650 They only describe (at best) how to get at these values at
1651 the points in the generated code right after they have just
1652 been computed. Worse yet, in the typical case, the upper
1653 bound values will not even *be* computed in the optimized
1654 code, so these SAVE_EXPRs are entirely bogus.
1655
1656 In order to compensate for this fact, we check here to see
1657 if optimization is enabled, and if so, we effectively create
1658 an empty location description for the (unknown and unknowable)
1659 upper bound.
1660
1661 This should not cause too much trouble for existing (stupid?)
1662 debuggers because they have to deal with empty upper bounds
1663 location descriptions anyway in order to be able to deal with
1664 incomplete array types.
1665
1666 Of course an intelligent debugger (GDB?) should be able to
1667 comprehend that a missing upper bound specification in a
1668 array type used for a storage class `auto' local array variable
1669 indicates that the upper bound is both unknown (at compile-
1670 time) and unknowable (at run-time) due to optimization.
1671 */
1672
1673 if (! optimize)
1674 output_loc_descriptor
906c4e36 1675 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
340ccaab
TW
1676
1677 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1678 }
1679 break;
1680
1681 default:
1682 abort ();
1683 }
1684}
1685
1686/* Recursive function to output a sequence of value/name pairs for
1687 enumeration constants in reversed order. This is called from
1688 enumeration_type_die. */
1689
1690static void
1691output_enumeral_list (link)
1692 register tree link;
1693{
1694 if (link)
1695 {
1696 output_enumeral_list (TREE_CHAIN (link));
1697 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1698 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1699 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1700 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1701 }
1702}
1703
d4d4c5a8
RS
1704/* Given an unsigned value, round it up to the lowest multiple of `boundary'
1705 which is not less than the value itself. */
1706
1707inline unsigned
1708ceiling (value, boundary)
1709 register unsigned value;
1710 register unsigned boundary;
1711{
1712 return (((value + boundary - 1) / boundary) * boundary);
1713}
1714
1715/* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1716 pointer to the declared type for the relevant field variable, or return
1717 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1718
1719inline tree
1720field_type (decl)
1721 register tree decl;
1722{
1723 register tree type;
1724
1725 if (TREE_CODE (decl) == ERROR_MARK)
1726 return integer_type_node;
1727
1728 type = DECL_BIT_FIELD_TYPE (decl);
1729 if (type == NULL)
1730 type = TREE_TYPE (decl);
1731 return type;
1732}
1733
1734/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1735 node, return the alignment in bits for the type, or else return
1736 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1737
1738inline unsigned
1739simple_type_align_in_bits (type)
1740 register tree type;
1741{
1742 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1743}
1744
1745/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1746 node, return the size in bits for the type if it is a constant, or
1747 else return the alignment for the type if the type's size is not
1748 constant, or else return BITS_PER_WORD if the type actually turns out
1749 to be an ERROR_MARK node. */
1750
1751inline unsigned
1752simple_type_size_in_bits (type)
1753 register tree type;
1754{
1755 if (TREE_CODE (type) == ERROR_MARK)
1756 return BITS_PER_WORD;
1757 else
1758 {
1759 register tree type_size_tree = TYPE_SIZE (type);
1760
1761 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1762 return TYPE_ALIGN (type);
1763
1764 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1765 }
1766}
1767
1768/* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1769 return the byte offset of the lowest addressed byte of the "containing
1770 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1771 mine what that offset is, either because the argument turns out to be a
1772 pointer to an ERROR_MARK node, or because the offset is actually variable.
1773 (We can't handle the latter case just yet.) */
1774
1775static unsigned
1776field_byte_offset (decl)
1777 register tree decl;
1778{
1779 register unsigned type_align_in_bytes;
1780 register unsigned type_align_in_bits;
1781 register unsigned type_size_in_bits;
1782 register unsigned object_offset_in_align_units;
1783 register unsigned object_offset_in_bits;
1784 register unsigned object_offset_in_bytes;
1785 register tree type;
1786 register tree bitpos_tree;
1787 register tree field_size_tree;
1788 register unsigned bitpos_int;
1789 register unsigned deepest_bitpos;
1790 register unsigned field_size_in_bits;
1791
1792 if (TREE_CODE (decl) == ERROR_MARK)
1793 return 0;
1794
1795 if (TREE_CODE (decl) != FIELD_DECL)
1796 abort ();
1797
1798 type = field_type (decl);
1799
1800 bitpos_tree = DECL_FIELD_BITPOS (decl);
1801 field_size_tree = DECL_SIZE (decl);
1802
1803 /* We cannot yet cope with fields whose positions or sizes are variable,
1804 so for now, when we see such things, we simply return 0. Someday,
1805 we may be able to handle such cases, but it will be damn difficult. */
1806
1807 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
1808 return 0;
1809 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
1810
1811 if (TREE_CODE (field_size_tree) != INTEGER_CST)
1812 return 0;
1813 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
1814
1815 type_size_in_bits = simple_type_size_in_bits (type);
1816
1817 type_align_in_bits = simple_type_align_in_bits (type);
1818 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
1819
1820 /* Note that the GCC front-end doesn't make any attempt to keep track
1821 of the starting bit offset (relative to the start of the containing
1822 structure type) of the hypothetical "containing object" for a bit-
1823 field. Thus, when computing the byte offset value for the start of
1824 the "containing object" of a bit-field, we must deduce this infor-
1825 mation on our own.
1826
1827 This can be rather tricky to do in some cases. For example, handling
1828 the following structure type definition when compiling for an i386/i486
1829 target (which only aligns long long's to 32-bit boundaries) can be very
1830 tricky:
1831
1832 struct S {
1833 int field1;
1834 long long field2:31;
1835 };
1836
1837 Fortunately, there is a simple rule-of-thumb which can be used in such
1838 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
1839 the structure shown above. It decides to do this based upon one simple
1840 rule for bit-field allocation. Quite simply, GCC allocates each "con-
1841 taining object" for each bit-field at the first (i.e. lowest addressed)
1842 legitimate alignment boundary (based upon the required minimum alignment
1843 for the declared type of the field) which it can possibly use, subject
1844 to the condition that there is still enough available space remaining
1845 in the containing object (when allocated at the selected point) to
1846 fully accomodate all of the bits of the bit-field itself.
1847
1848 This simple rule makes it obvious why GCC allocates 8 bytes for each
1849 object of the structure type shown above. When looking for a place to
1850 allocate the "containing object" for `field2', the compiler simply tries
1851 to allocate a 64-bit "containing object" at each successive 32-bit
1852 boundary (starting at zero) until it finds a place to allocate that 64-
1853 bit field such that at least 31 contiguous (and previously unallocated)
1854 bits remain within that selected 64 bit field. (As it turns out, for
1855 the example above, the compiler finds that it is OK to allocate the
1856 "containing object" 64-bit field at bit-offset zero within the
1857 structure type.)
1858
1859 Here we attempt to work backwards from the limited set of facts we're
1860 given, and we try to deduce from those facts, where GCC must have
1861 believed that the containing object started (within the structure type).
1862
1863 The value we deduce is then used (by the callers of this routine) to
1864 generate AT_location and AT_bit_offset attributes for fields (both
1865 bit-fields and, in the case of AT_location, regular fields as well).
1866 */
1867
1868 /* Figure out the bit-distance from the start of the structure to the
1869 "deepest" bit of the bit-field. */
1870 deepest_bitpos = bitpos_int + field_size_in_bits;
1871
1872 /* This is the tricky part. Use some fancy footwork to deduce where the
1873 lowest addressed bit of the containing object must be. */
1874 object_offset_in_bits
1875 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
1876
1877 /* Compute the offset of the containing object in "alignment units". */
1878 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
1879
1880 /* Compute the offset of the containing object in bytes. */
1881 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
1882
1883 return object_offset_in_bytes;
1884}
1885
340ccaab
TW
1886/****************************** attributes *********************************/
1887
1888/* The following routines are responsible for writing out the various types
1889 of Dwarf attributes (and any following data bytes associated with them).
1890 These routines are listed in order based on the numerical codes of their
1891 associated attributes. */
1892
1893/* Generate an AT_sibling attribute. */
1894
1895inline void
1896sibling_attribute ()
1897{
1898 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1899
1900 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
1901 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
1902 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
1903}
1904
1905/* Output the form of location attributes suitable for whole variables and
1906 whole parameters. Note that the location attributes for struct fields
1907 are generated by the routine `data_member_location_attribute' below. */
1908
1909static void
1910location_attribute (rtl)
1911 register rtx rtl;
1912{
1913 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1914 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1915
1916 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1917 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1918 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1919 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1920 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1921
1922 /* Handle a special case. If we are about to output a location descriptor
2e494f70 1923 for a variable or parameter which has been optimized out of existence,
340ccaab 1924 don't do that. Instead we output a zero-length location descriptor
28b039e3
RS
1925 value as part of the location attribute.
1926
1927 A variable which has been optimized out of existance will have a
1928 DECL_RTL value which denotes a pseudo-reg.
1929
1930 Currently, in some rare cases, variables can have DECL_RTL values
1931 which look like (MEM (REG pseudo-reg#)). These cases are due to
1932 bugs elsewhere in the compiler. We treat such cases
1933 as if the variable(s) in question had been optimized out of existance.
1934
1935 Note that in all cases where we wish to express the fact that a
1936 variable has been optimized out of existance, we do not simply
1937 suppress the generation of the entire location attribute because
1938 the absence of a location attribute in certain kinds of DIEs is
1939 used to indicate something else entirely... i.e. that the DIE
1940 represents an object declaration, but not a definition. So sayeth
1941 the PLSIG.
1942 */
340ccaab 1943
28b039e3
RS
1944 if (! is_pseudo_reg (rtl)
1945 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
906c4e36 1946 output_loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
340ccaab
TW
1947
1948 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1949}
1950
1951/* Output the specialized form of location attribute used for data members
d4d4c5a8 1952 of struct and union types.
9a631e8e
RS
1953
1954 In the special case of a FIELD_DECL node which represents a bit-field,
1955 the "offset" part of this special location descriptor must indicate the
1956 distance in bytes from the lowest-addressed byte of the containing
1957 struct or union type to the lowest-addressed byte of the "containing
d4d4c5a8 1958 object" for the bit-field. (See the `field_byte_offset' function above.)
9a631e8e
RS
1959
1960 For any given bit-field, the "containing object" is a hypothetical
1961 object (of some integral or enum type) within which the given bit-field
1962 lives. The type of this hypothetical "containing object" is always the
d4d4c5a8
RS
1963 same as the declared type of the individual bit-field itself (for GCC
1964 anyway... the DWARF spec doesn't actually mandate this).
9a631e8e
RS
1965
1966 Note that it is the size (in bytes) of the hypothetical "containing
1967 object" which will be given in the AT_byte_size attribute for this
d4d4c5a8
RS
1968 bit-field. (See the `byte_size_attribute' function below.) It is
1969 also used when calculating the value of the AT_bit_offset attribute.
1970 (See the `bit_offset_attribute' function below.)
9a631e8e
RS
1971*/
1972
340ccaab
TW
1973static void
1974data_member_location_attribute (decl)
1975 register tree decl;
1976{
d4d4c5a8 1977 register unsigned object_offset_in_bytes = field_byte_offset (decl);
340ccaab
TW
1978 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1979 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
9a631e8e 1980
340ccaab
TW
1981 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1982 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1983 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1984 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1985 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1986 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
d4d4c5a8 1987 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
340ccaab
TW
1988 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1989 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1990}
1991
1992/* Output an AT_const_value attribute for a variable or a parameter which
1993 does not have a "location" either in memory or in a register. These
1994 things can arise in GNU C when a constant is passed as an actual
1995 parameter to an inlined function. They can also arise in C++ where
1996 declared constants do not necessarily get memory "homes". */
1997
1998static void
1999const_value_attribute (rtl)
2000 register rtx rtl;
2001{
2002 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2003 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2004
2005 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2006 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2007 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2008 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2009 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2010
2011 switch (GET_CODE (rtl))
2012 {
2013 case CONST_INT:
2014 /* Note that a CONST_INT rtx could represent either an integer or
2015 a floating-point constant. A CONST_INT is used whenever the
2016 constant will fit into a single word. In all such cases, the
2017 original mode of the constant value is wiped out, and the
2018 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2019 precise mode information for these constants, we always just
2020 output them using 4 bytes. */
2021
2022 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2023 break;
2024
2025 case CONST_DOUBLE:
2026 /* Note that a CONST_DOUBLE rtx could represent either an integer
2027 or a floating-point constant. A CONST_DOUBLE is used whenever
2028 the constant requires more than one word in order to be adequately
2029 represented. In all such cases, the original mode of the constant
2030 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2031 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2032
2033 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
906c4e36
RK
2034 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2035 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
340ccaab
TW
2036 break;
2037
2038 case CONST_STRING:
2039 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
2040 break;
2041
2042 case SYMBOL_REF:
2043 case LABEL_REF:
2044 case CONST:
2045 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2046 break;
2047
2048 case PLUS:
2049 /* In cases where an inlined instance of an inline function is passed
2050 the address of an `auto' variable (which is local to the caller)
2051 we can get a situation where the DECL_RTL of the artificial
2052 local variable (for the inlining) which acts as a stand-in for
2053 the corresponding formal parameter (of the inline function)
2054 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2055 This is not exactly a compile-time constant expression, but it
2056 isn't the address of the (artificial) local variable either.
2057 Rather, it represents the *value* which the artificial local
2058 variable always has during its lifetime. We currently have no
2059 way to represent such quasi-constant values in Dwarf, so for now
2060 we just punt and generate an AT_const_value attribute with form
2061 FORM_BLOCK4 and a length of zero. */
2062 break;
d4d4c5a8
RS
2063
2064 default:
2065 abort (); /* No other kinds of rtx should be possible here. */
340ccaab
TW
2066 }
2067
2068 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2069}
2070
2071/* Generate *either* an AT_location attribute or else an AT_const_value
2072 data attribute for a variable or a parameter. We generate the
2073 AT_const_value attribute only in those cases where the given
2074 variable or parameter does not have a true "location" either in
2075 memory or in a register. This can happen (for example) when a
2076 constant is passed as an actual argument in a call to an inline
2077 function. (It's possible that these things can crop up in other
2078 ways also.) Note that one type of constant value which can be
2079 passed into an inlined function is a constant pointer. This can
2080 happen for example if an actual argument in an inlined function
2081 call evaluates to a compile-time constant address. */
2082
2083static void
2084location_or_const_value_attribute (decl)
2085 register tree decl;
2086{
2087 register rtx rtl;
2088
2089 if (TREE_CODE (decl) == ERROR_MARK)
2090 return;
2091
2092 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2093 abort ();
2094
9a631e8e 2095 /* Existing Dwarf debuggers need and expect the location descriptors for
648ebe7b
RS
2096 formal parameters to reflect either the place where the parameters get
2097 passed (if they are passed on the stack and in memory) or else the
3f7cc57a 2098 (preserved) registers which the parameters get copied to during the
648ebe7b
RS
2099 function prologue.
2100
2101 At least this is the way things are for most common CISC machines
2102 (e.g. x86 and m68k) where parameters are passed in the stack, and for
2103 most common RISC machines (e.g. i860 and m88k) where parameters are
2104 passed in registers.
2105
2106 The rules for Sparc are a little weird for some reason. The DWARF
2107 generated by the USL C compiler for the Sparc/svr4 reference port says
2108 that the parameters are passed in the stack. I haven't figured out
2109 how to duplicate that behavior here (for the Sparc) yet, or even if
2110 I really need to.
2111
2112 Note that none of this is clearly spelled out in the current Dwarf
9a631e8e
RS
2113 version 1 specification, but it's obvious if you look at the output of
2114 the CI5 compiler, or if you try to use the svr4 SDB debugger. Hopefully,
2115 a later version of the Dwarf specification will clarify this. For now,
2116 we just need to generate the right thing. Note that Dwarf version 2
2117 will provide us with a means to describe *all* of the locations in which
2118 a given variable or parameter resides (and the PC ranges over which it
648ebe7b
RS
2119 occupies each one), but for now we can only describe one "location"
2120 for each formal parameter passed, and so we just try to mimic existing
2121 practice as much as possible.
2122 */
9a631e8e 2123
648ebe7b
RS
2124 if (TREE_CODE (decl) != PARM_DECL)
2125 /* If this decl is not a formal parameter, just use DECL_RTL. */
2126 rtl = DECL_RTL (decl);
2127 else
2128 {
2129 if (GET_CODE (DECL_INCOMING_RTL (decl)) == MEM)
2130 /* Parameter was passed in memory, so say that's where it lives. */
2131 rtl = DECL_INCOMING_RTL (decl);
2132 else
2133 {
2134 /* Parameter was passed in a register, so say it lives in the
2135 register it will be copied to during the prologue. */
2136 rtl = DECL_RTL (decl);
2137
2138 /* Note that in cases where the formal parameter is never used
2139 and where this compilation is done with -O, the copying of
2140 of an incoming register parameter to another register (in
2141 the prologue) can be totally optimized away. (In such cases
2142 the DECL_RTL will indicate a pseudo-register.) We could just
2143 use the DECL_RTL (as we normally do for register parameters)
2144 in these cases, but if we did that, we would end up generating
2145 a null location descriptor. (See `location_attribute' above.)
2146 That would be acceptable (according to the DWARF spec) but it
2147 is probably more useful to say that the formal resides where
2148 it was passed instead of saying that it resides nowhere. */
2149 if (is_pseudo_reg (rtl))
2150 rtl = DECL_INCOMING_RTL (decl);
2151 }
2152 }
340ccaab
TW
2153
2154 if (rtl == NULL)
2155 return;
2156
2157 switch (GET_CODE (rtl))
2158 {
2159 case CONST_INT:
2160 case CONST_DOUBLE:
2161 case CONST_STRING:
2162 case SYMBOL_REF:
2163 case LABEL_REF:
2164 case CONST:
2165 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2166 const_value_attribute (rtl);
2167 break;
2168
2169 case MEM:
2170 case REG:
2171 case SUBREG:
2172 location_attribute (rtl);
2173 break;
2174
2175 default:
2176 abort (); /* Should never happen. */
2177 }
2178}
2179
2180/* Generate an AT_name attribute given some string value to be included as
9a631e8e 2181 the value of the attribute. */
340ccaab
TW
2182
2183inline void
2184name_attribute (name_string)
2185 register char *name_string;
2186{
75791cee
TW
2187 if (name_string && *name_string)
2188 {
2189 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2190 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2191 }
340ccaab
TW
2192}
2193
2194inline void
2195fund_type_attribute (ft_code)
2196 register unsigned ft_code;
2197{
2198 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2199 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2200}
2201
2202static void
2203mod_fund_type_attribute (type, decl_const, decl_volatile)
2204 register tree type;
2205 register int decl_const;
2206 register int decl_volatile;
2207{
2208 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2209 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2210
2211 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2212 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2213 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2214 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2215 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2216 write_modifier_bytes (type, decl_const, decl_volatile);
2217 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2218 fundamental_type_code (root_type (type)));
2219 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2220}
2221
2222inline void
2223user_def_type_attribute (type)
2224 register tree type;
2225{
2226 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2227
2228 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2229 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2230 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2231}
2232
2233static void
2234mod_u_d_type_attribute (type, decl_const, decl_volatile)
2235 register tree type;
2236 register int decl_const;
2237 register int decl_volatile;
2238{
2239 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2240 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2241 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2242
2243 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2244 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2245 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2246 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2247 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2248 write_modifier_bytes (type, decl_const, decl_volatile);
2249 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2250 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2251 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2252}
2253
d4d4c5a8 2254#ifdef USE_ORDERING_ATTRIBUTE
340ccaab
TW
2255inline void
2256ordering_attribute (ordering)
2257 register unsigned ordering;
2258{
2259 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2260 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2261}
d4d4c5a8 2262#endif /* defined(USE_ORDERING_ATTRIBUTE) */
340ccaab
TW
2263
2264/* Note that the block of subscript information for an array type also
2265 includes information about the element type of type given array type. */
2266
2267static void
2268subscript_data_attribute (type)
2269 register tree type;
2270{
2271 register unsigned dimension_number;
2272 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2273 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2274
2275 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2276 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2277 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2278 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2279 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2280
2281 /* The GNU compilers represent multidimensional array types as sequences
2282 of one dimensional array types whose element types are themselves array
2283 types. Here we squish that down, so that each multidimensional array
2284 type gets only one array_type DIE in the Dwarf debugging info. The
2285 draft Dwarf specification say that we are allowed to do this kind
2286 of compression in C (because there is no difference between an
2287 array or arrays and a multidimensional array in C) but for other
2288 source languages (e.g. Ada) we probably shouldn't do this. */
2289
2290 for (dimension_number = 0;
2291 TREE_CODE (type) == ARRAY_TYPE;
2292 type = TREE_TYPE (type), dimension_number++)
2293 {
2294 register tree domain = TYPE_DOMAIN (type);
2295
2296 /* Arrays come in three flavors. Unspecified bounds, fixed
2297 bounds, and (in GNU C only) variable bounds. Handle all
2298 three forms here. */
2299
2300 if (domain)
2301 {
2302 /* We have an array type with specified bounds. */
2303
2304 register tree lower = TYPE_MIN_VALUE (domain);
2305 register tree upper = TYPE_MAX_VALUE (domain);
2306
2307 /* Handle only fundamental types as index types for now. */
2308
2309 if (! type_is_fundamental (domain))
2310 abort ();
2311
2312 /* Output the representation format byte for this dimension. */
2313
2314 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2315 FMT_CODE (1,
2316 TREE_CODE (lower) == INTEGER_CST,
2317 TREE_CODE (upper) == INTEGER_CST));
2318
2319 /* Output the index type for this dimension. */
2320
2321 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2322 fundamental_type_code (domain));
2323
2324 /* Output the representation for the lower bound. */
2325
2326 output_bound_representation (lower, dimension_number, 'l');
2327
2328 /* Output the representation for the upper bound. */
2329
2330 output_bound_representation (upper, dimension_number, 'u');
2331 }
2332 else
2333 {
2334 /* We have an array type with an unspecified length. For C and
2335 C++ we can assume that this really means that (a) the index
2336 type is an integral type, and (b) the lower bound is zero.
2337 Note that Dwarf defines the representation of an unspecified
2338 (upper) bound as being a zero-length location description. */
2339
2340 /* Output the array-bounds format byte. */
2341
2342 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2343
2344 /* Output the (assumed) index type. */
2345
2346 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2347
2348 /* Output the (assumed) lower bound (constant) value. */
2349
2350 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2351
2352 /* Output the (empty) location description for the upper bound. */
2353
2354 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2355 }
2356 }
2357
2358 /* Output the prefix byte that says that the element type is comming up. */
2359
2360 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2361
2362 /* Output a representation of the type of the elements of this array type. */
2363
2364 type_attribute (type, 0, 0);
2365
2366 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2367}
2368
2369static void
2370byte_size_attribute (tree_node)
2371 register tree tree_node;
2372{
2373 register unsigned size;
2374
2375 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2376 switch (TREE_CODE (tree_node))
2377 {
2378 case ERROR_MARK:
2379 size = 0;
2380 break;
2381
2382 case ENUMERAL_TYPE:
2383 case RECORD_TYPE:
2384 case UNION_TYPE:
2385 size = int_size_in_bytes (tree_node);
2386 break;
2387
2388 case FIELD_DECL:
9a631e8e 2389 /* For a data member of a struct or union, the AT_byte_size is
d4d4c5a8 2390 generally given as the number of bytes normally allocated for
9a631e8e
RS
2391 an object of the *declared* type of the member itself. This
2392 is true even for bit-fields. */
d4d4c5a8
RS
2393 size = simple_type_size_in_bits (field_type (tree_node))
2394 / BITS_PER_UNIT;
340ccaab
TW
2395 break;
2396
2397 default:
2398 abort ();
2399 }
9a631e8e
RS
2400
2401 /* Note that `size' might be -1 when we get to this point. If it
2402 is, that indicates that the byte size of the entity in question
2403 is variable. We have no good way of expressing this fact in Dwarf
2404 at the present time, so just let the -1 pass on through. */
2405
340ccaab
TW
2406 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2407}
2408
9a631e8e
RS
2409/* For a FIELD_DECL node which represents a bit-field, output an attribute
2410 which specifies the distance in bits from the highest order bit of the
2411 "containing object" for the bit-field to the highest order bit of the
2412 bit-field itself.
2413
2414 For any given bit-field, the "containing object" is a hypothetical
2415 object (of some integral or enum type) within which the given bit-field
2416 lives. The type of this hypothetical "containing object" is always the
2417 same as the declared type of the individual bit-field itself.
2418
d4d4c5a8
RS
2419 The determination of the exact location of the "containing object" for
2420 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2421 function (above).
2422
9a631e8e
RS
2423 Note that it is the size (in bytes) of the hypothetical "containing
2424 object" which will be given in the AT_byte_size attribute for this
2425 bit-field. (See `byte_size_attribute' above.)
2426*/
340ccaab
TW
2427
2428inline void
2429bit_offset_attribute (decl)
2430 register tree decl;
2431{
d4d4c5a8 2432 register unsigned object_offset_in_bytes = field_byte_offset (decl);
9a631e8e 2433 register tree type = DECL_BIT_FIELD_TYPE (decl);
9a631e8e 2434 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
648ebe7b 2435 register unsigned bitpos_int;
d4d4c5a8
RS
2436 register unsigned highest_order_object_bit_offset;
2437 register unsigned highest_order_field_bit_offset;
2438 register unsigned bit_offset;
9a631e8e 2439
340ccaab 2440 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
9a631e8e
RS
2441 assert (type); /* Must be a bit field. */
2442
d4d4c5a8
RS
2443 /* We can't yet handle bit-fields whose offsets are variable, so if we
2444 encounter such things, just return without generating any attribute
2445 whatsoever. */
9a631e8e 2446
648ebe7b 2447 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
9a631e8e 2448 return;
648ebe7b 2449 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
9a631e8e 2450
d4d4c5a8
RS
2451 /* Note that the bit offset is always the distance (in bits) from the
2452 highest-order bit of the "containing object" to the highest-order
2453 bit of the bit-field itself. Since the "high-order end" of any
2454 object or field is different on big-endian and little-endian machines,
2455 the computation below must take account of these differences. */
9a631e8e 2456
d4d4c5a8
RS
2457 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2458 highest_order_field_bit_offset = bitpos_int;
648ebe7b 2459
d4d4c5a8
RS
2460#if (BYTES_BIG_ENDIAN == 0)
2461 highest_order_field_bit_offset
2462 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
9a631e8e 2463
d4d4c5a8
RS
2464 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2465#endif /* (BYTES_BIG_ENDIAN == 0) */
2466
2467 bit_offset =
2468#if (BYTES_BIG_ENDIAN == 0)
2469 highest_order_object_bit_offset - highest_order_field_bit_offset;
2470#else /* (BYTES_BIG_ENDIAN != 0) */
2471 highest_order_field_bit_offset - highest_order_object_bit_offset;
2472#endif /* (BYTES_BIG_ENDIAN != 0) */
340ccaab
TW
2473
2474 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
d4d4c5a8 2475 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
340ccaab
TW
2476}
2477
2478/* For a FIELD_DECL node which represents a bit field, output an attribute
2479 which specifies the length in bits of the given field. */
2480
2481inline void
2482bit_size_attribute (decl)
2483 register tree decl;
2484{
2485 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2486 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
2487
2488 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2489 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2490 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2491}
2492
2493/* The following routine outputs the `element_list' attribute for enumeration
2494 type DIEs. The element_lits attribute includes the names and values of
2495 all of the enumeration constants associated with the given enumeration
2496 type. */
2497
2498inline void
2499element_list_attribute (element)
2500 register tree element;
2501{
2502 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2503 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2504
2505 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2506 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2507 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2508 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2509 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2510
2511 /* Here we output a list of value/name pairs for each enumeration constant
2512 defined for this enumeration type (as required), but we do it in REVERSE
2513 order. The order is the one required by the draft #5 Dwarf specification
2514 published by the UI/PLSIG. */
2515
2516 output_enumeral_list (element); /* Recursively output the whole list. */
2517
2518 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2519}
2520
2521/* Generate an AT_stmt_list attribute. These are normally present only in
2522 DIEs with a TAG_compile_unit tag. */
2523
2524inline void
2525stmt_list_attribute (label)
2526 register char *label;
2527{
2528 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2529 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2530 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2531}
2532
2533/* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2534 for a subroutine DIE. */
2535
2536inline void
2537low_pc_attribute (asm_low_label)
2538 register char *asm_low_label;
2539{
2540 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2541 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2542}
2543
2544/* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2545 subroutine DIE. */
2546
2547inline void
2548high_pc_attribute (asm_high_label)
2549 register char *asm_high_label;
2550{
2551 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2552 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2553}
2554
2555/* Generate an AT_language attribute given a LANG value. These attributes
2556 are used only within TAG_compile_unit DIEs. */
2557
2558inline void
2559language_attribute (language_code)
2560 register unsigned language_code;
2561{
2562 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2563 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2564}
2565
2566inline void
2567member_attribute (context)
2568 register tree context;
2569{
2570 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2571
2572 /* Generate this attribute only for members in C++. */
2573
c7d6dca2 2574 if (context != NULL && is_tagged_type (context))
340ccaab
TW
2575 {
2576 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2577 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2578 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2579 }
2580}
2581
2582inline void
2583string_length_attribute (upper_bound)
2584 register tree upper_bound;
2585{
2586 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2587 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2588
2589 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2590 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2591 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2592 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2593 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2594 output_bound_representation (upper_bound, 0, 'u');
2595 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2596}
2597
2598inline void
2599comp_dir_attribute (dirname)
2600 register char *dirname;
2601{
2602 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2603 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2604}
2605
2606inline void
2607sf_names_attribute (sf_names_start_label)
2608 register char *sf_names_start_label;
2609{
2610 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2611 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2612 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2613}
2614
2615inline void
2616src_info_attribute (src_info_start_label)
2617 register char *src_info_start_label;
2618{
2619 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2620 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2621 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2622}
2623
2624inline void
2625mac_info_attribute (mac_info_start_label)
2626 register char *mac_info_start_label;
2627{
2628 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2629 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2630 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2631}
2632
2633inline void
2634prototyped_attribute (func_type)
2635 register tree func_type;
2636{
2637 if ((strcmp (language_string, "GNU C") == 0)
2638 && (TYPE_ARG_TYPES (func_type) != NULL))
2639 {
2640 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2641 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2642 }
2643}
2644
2645inline void
2646producer_attribute (producer)
2647 register char *producer;
2648{
2649 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2650 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2651}
2652
2653inline void
2654inline_attribute (decl)
2655 register tree decl;
2656{
0924ddef 2657 if (DECL_INLINE (decl))
340ccaab
TW
2658 {
2659 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2660 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2661 }
2662}
2663
2664inline void
2665containing_type_attribute (containing_type)
2666 register tree containing_type;
2667{
2668 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2669
2670 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2671 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2672 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2673}
2674
04077c53
RS
2675inline void
2676abstract_origin_attribute (origin)
2677 register tree origin;
2678{
2679 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2680
2681 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2682 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2683 {
2684 case 'd':
2685 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2686 break;
2687
2688 case 't':
2689 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2690 break;
2691
2692 default:
2693 abort (); /* Should never happen. */
2694
2695 }
2696 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2697}
2698
2699#ifdef DWARF_DECL_COORDINATES
9a631e8e
RS
2700inline void
2701src_coords_attribute (src_fileno, src_lineno)
2702 register unsigned src_fileno;
2703 register unsigned src_lineno;
2704{
9a631e8e
RS
2705 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2706 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2707 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
9a631e8e 2708}
04077c53
RS
2709#endif /* defined(DWARF_DECL_COORDINATES) */
2710
2711inline void
2712pure_or_virtual_attribute (func_decl)
2713 register tree func_decl;
2714{
2715 if (DECL_VIRTUAL_P (func_decl))
2716 {
ece0ca60 2717#if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
04077c53
RS
2718 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
2719 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
2720 else
ece0ca60 2721#endif
04077c53
RS
2722 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
2723 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2724 }
2725}
9a631e8e 2726
340ccaab
TW
2727/************************* end of attributes *****************************/
2728
2729/********************* utility routines for DIEs *************************/
2730
9a631e8e
RS
2731/* Output an AT_name attribute and an AT_src_coords attribute for the
2732 given decl, but only if it actually has a name. */
2733
d4d4c5a8 2734static void
9a631e8e
RS
2735name_and_src_coords_attributes (decl)
2736 register tree decl;
2737{
2738 register tree decl_name = DECL_NAME (decl);
2739
2740 if (decl_name && IDENTIFIER_POINTER (decl_name))
2741 {
2742 name_attribute (IDENTIFIER_POINTER (decl_name));
75791cee
TW
2743#ifdef DWARF_DECL_COORDINATES
2744 {
2745 register unsigned file_index;
2746
2747 /* This is annoying, but we have to pop out of the .debug section
2748 for a moment while we call `lookup_filename' because calling it
2749 may cause a temporary switch into the .debug_sfnames section and
2750 most svr4 assemblers are not smart enough be be able to nest
2751 section switches to any depth greater than one. Note that we
2752 also can't skirt this issue by delaying all output to the
2753 .debug_sfnames section unit the end of compilation because that
2754 would cause us to have inter-section forward references and
2755 Fred Fish sez that m68k/svr4 assemblers botch those. */
2756
2757 ASM_OUTPUT_POP_SECTION (asm_out_file);
2758 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
2759 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
2760
2761 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
2762 }
d4d4c5a8 2763#endif /* defined(DWARF_DECL_COORDINATES) */
9a631e8e
RS
2764 }
2765}
2766
340ccaab
TW
2767/* Many forms of DIEs contain a "type description" part. The following
2768 routine writes out these "type descriptor" parts. */
2769
2770static void
2771type_attribute (type, decl_const, decl_volatile)
2772 register tree type;
2773 register int decl_const;
2774 register int decl_volatile;
2775{
2776 register enum tree_code code = TREE_CODE (type);
2777 register int root_type_modified;
2778
2779 if (TREE_CODE (type) == ERROR_MARK)
2780 return;
2781
2782 /* Handle a special case. For functions whose return type is void,
2783 we generate *no* type attribute. (Note that no object may have
2784 type `void', so this only applies to function return types. */
2785
2786 if (TREE_CODE (type) == VOID_TYPE)
2787 return;
2788
2789 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
2790 || decl_const || decl_volatile
2791 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
2792
2793 if (type_is_fundamental (root_type (type)))
2794 if (root_type_modified)
2795 mod_fund_type_attribute (type, decl_const, decl_volatile);
2796 else
2797 fund_type_attribute (fundamental_type_code (type));
2798 else
2799 if (root_type_modified)
2800 mod_u_d_type_attribute (type, decl_const, decl_volatile);
2801 else
2802 user_def_type_attribute (type);
2803}
2804
2805/* Given a tree pointer to a struct, class, union, or enum type node, return
2806 a pointer to the (string) tag name for the given type, or zero if the
2807 type was declared without a tag. */
2808
2809static char *
2810type_tag (type)
2811 register tree type;
2812{
2813 register char *name = 0;
2814
2815 if (TYPE_NAME (type) != 0)
2816 {
2817 register tree t = 0;
2818
2819 /* Find the IDENTIFIER_NODE for the type name. */
2820 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2821 t = TYPE_NAME (type);
2822#if 0
2823 /* The g++ front end makes the TYPE_NAME of *each* tagged type point
2824 to a TYPE_DECL node, regardless of whether or not a `typedef' was
2825 involved. This is distinctly different from what the gcc front-end
2826 does. It always makes the TYPE_NAME for each tagged type be either
2827 NULL (signifying an anonymous tagged type) or else a pointer to an
2828 IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf
6dc42e49 2829 for both C and C++, but given this inconsistency in the TREE
340ccaab
TW
2830 representation of tagged types for C and C++ in the GNU front-ends,
2831 we cannot support both languages correctly unless we introduce some
2832 front-end specific code here, and rms objects to that, so we can
2833 only generate correct Dwarf for one of these two languages. C is
2834 more important, so for now we'll do the right thing for C and let
2835 g++ go fish. */
2836
2837 else
2838 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2839 t = DECL_NAME (TYPE_NAME (type));
2840#endif
2841 /* Now get the name as a string, or invent one. */
2842 if (t != 0)
2843 name = IDENTIFIER_POINTER (t);
2844 }
2845
2846 return (name == 0 || *name == '\0') ? 0 : name;
2847}
2848
2849inline void
2850dienum_push ()
2851{
2852 /* Start by checking if the pending_sibling_stack needs to be expanded.
2853 If necessary, expand it. */
2854
2855 if (pending_siblings == pending_siblings_allocated)
2856 {
2857 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
2858 pending_sibling_stack
2859 = (unsigned *) xrealloc (pending_sibling_stack,
2860 pending_siblings_allocated * sizeof(unsigned));
2861 }
2862
2863 pending_siblings++;
2864 NEXT_DIE_NUM = next_unused_dienum++;
2865}
2866
2867/* Pop the sibling stack so that the most recently pushed DIEnum becomes the
2868 NEXT_DIE_NUM. */
2869
2870inline void
2871dienum_pop ()
2872{
2873 pending_siblings--;
2874}
2875
2876inline tree
2877member_declared_type (member)
2878 register tree member;
2879{
2880 return (DECL_BIT_FIELD_TYPE (member))
2881 ? DECL_BIT_FIELD_TYPE (member)
2882 : TREE_TYPE (member);
2883}
2884
2885/******************************* DIEs ************************************/
2886
2887/* Output routines for individual types of DIEs. */
2888
2889/* Note that every type of DIE (except a null DIE) gets a sibling. */
2890
2891static void
2892output_array_type_die (arg)
2893 register void *arg;
2894{
2895 register tree type = arg;
2896
2897 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
2898 sibling_attribute ();
2899 equate_type_number_to_die_number (type);
2900 member_attribute (TYPE_CONTEXT (type));
2901
2902 /* I believe that we can default the array ordering. SDB will probably
2903 do the right things even if AT_ordering is not present. It's not
2904 even an issue until we start to get into multidimensional arrays
9a631e8e
RS
2905 anyway. If SDB is ever caught doing the Wrong Thing for multi-
2906 dimensional arrays, then we'll have to put the AT_ordering attribute
2907 back in. (But if and when we find out that we need to put these in,
2908 we will only do so for multidimensional arrays. After all, we don't
2909 want to waste space in the .debug section now do we?) */
340ccaab 2910
d4d4c5a8 2911#ifdef USE_ORDERING_ATTRIBUTE
340ccaab 2912 ordering_attribute (ORD_row_major);
d4d4c5a8 2913#endif /* defined(USE_ORDERING_ATTRIBUTE) */
340ccaab
TW
2914
2915 subscript_data_attribute (type);
2916}
2917
2918static void
2919output_set_type_die (arg)
2920 register void *arg;
2921{
2922 register tree type = arg;
2923
2924 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
2925 sibling_attribute ();
2926 equate_type_number_to_die_number (type);
2927 member_attribute (TYPE_CONTEXT (type));
2928 type_attribute (TREE_TYPE (type), 0, 0);
2929}
2930
2931#if 0
2932/* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
2933static void
2934output_entry_point_die (arg)
2935 register void *arg;
2936{
2937 register tree decl = arg;
d4d4c5a8 2938 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
2939
2940 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
2941 sibling_attribute ();
2942 dienum_push ();
d4d4c5a8
RS
2943 if (origin != NULL)
2944 abstract_origin_attribute (origin);
2945 else
2946 {
2947 name_and_src_coords_attributes (decl);
2948 member_attribute (DECL_CONTEXT (decl));
2949 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
2950 }
2951 if (DECL_ABSTRACT (decl))
2952 equate_decl_number_to_die_number (decl);
2953 else
2954 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
340ccaab
TW
2955}
2956#endif
2957
d4d4c5a8
RS
2958/* Output a DIE to represent an inlined instance of an enumeration type. */
2959
2960static void
2961output_inlined_enumeration_type_die (arg)
2962 register void *arg;
2963{
2964 register tree type = arg;
2965
2966 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
2967 sibling_attribute ();
2968 assert (TREE_ASM_WRITTEN (type));
2969 abstract_origin_attribute (type);
2970}
2971
2972/* Output a DIE to represent an inlined instance of a structure type. */
2973
2974static void
2975output_inlined_structure_type_die (arg)
2976 register void *arg;
2977{
2978 register tree type = arg;
2979
2980 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
2981 sibling_attribute ();
2982 assert (TREE_ASM_WRITTEN (type));
2983 abstract_origin_attribute (type);
2984}
2985
2986/* Output a DIE to represent an inlined instance of a union type. */
2987
2988static void
2989output_inlined_union_type_die (arg)
2990 register void *arg;
2991{
2992 register tree type = arg;
2993
2994 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
2995 sibling_attribute ();
2996 assert (TREE_ASM_WRITTEN (type));
2997 abstract_origin_attribute (type);
2998}
2999
340ccaab
TW
3000/* Output a DIE to represent an enumeration type. Note that these DIEs
3001 include all of the information about the enumeration values also.
3002 This information is encoded into the element_list attribute. */
3003
3004static void
3005output_enumeration_type_die (arg)
3006 register void *arg;
3007{
3008 register tree type = arg;
3009
3010 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3011 sibling_attribute ();
3012 equate_type_number_to_die_number (type);
3013 name_attribute (type_tag (type));
3014 member_attribute (TYPE_CONTEXT (type));
3015
3016 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3017 given enum type is incomplete, do not generate the AT_byte_size
3018 attribute or the AT_element_list attribute. */
3019
3020 if (TYPE_SIZE (type))
3021 {
3022 byte_size_attribute (type);
3023 element_list_attribute (TYPE_FIELDS (type));
3024 }
3025}
3026
3027/* Output a DIE to represent either a real live formal parameter decl or
3028 to represent just the type of some formal parameter position in some
3029 function type.
3030
3031 Note that this routine is a bit unusual because its argument may be
d4d4c5a8
RS
3032 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3033 represents an inlining of some PARM_DECL) or else some sort of a
3034 ..._TYPE node. If it's the former then this function is being called
3035 to output a DIE to represent a formal parameter object (or some inlining
3036 thereof). If it's the latter, then this function is only being called
3037 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3038 formal argument type of some subprogram type. */
340ccaab
TW
3039
3040static void
3041output_formal_parameter_die (arg)
3042 register void *arg;
3043{
d4d4c5a8 3044 register tree node = arg;
340ccaab
TW
3045
3046 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3047 sibling_attribute ();
d4d4c5a8
RS
3048
3049 switch (TREE_CODE_CLASS (TREE_CODE (node)))
340ccaab 3050 {
d4d4c5a8
RS
3051 case 'd': /* We were called with some kind of a ..._DECL node. */
3052 {
3053 register tree origin = decl_ultimate_origin (node);
3054
3055 if (origin != NULL)
3056 abstract_origin_attribute (origin);
3057 else
3058 {
3059 name_and_src_coords_attributes (node);
3060 type_attribute (TREE_TYPE (node),
3061 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3062 }
3063 if (DECL_ABSTRACT (node))
3064 equate_decl_number_to_die_number (node);
3065 else
3066 location_or_const_value_attribute (node);
3067 }
3068 break;
3069
3070 case 't': /* We were called with some kind of a ..._TYPE node. */
3071 type_attribute (node, 0, 0);
3072 break;
3073
3074 default:
3075 abort (); /* Should never happen. */
340ccaab 3076 }
340ccaab
TW
3077}
3078
3079/* Output a DIE to represent a declared function (either file-scope
3080 or block-local) which has "external linkage" (according to ANSI-C). */
3081
3082static void
3083output_global_subroutine_die (arg)
3084 register void *arg;
3085{
3086 register tree decl = arg;
d4d4c5a8 3087 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3088
3089 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3090 sibling_attribute ();
3091 dienum_push ();
d4d4c5a8
RS
3092 if (origin != NULL)
3093 abstract_origin_attribute (origin);
3094 else
340ccaab 3095 {
d4d4c5a8 3096 register tree type = TREE_TYPE (decl);
340ccaab 3097
d4d4c5a8
RS
3098 name_and_src_coords_attributes (decl);
3099 inline_attribute (decl);
3100 prototyped_attribute (type);
3101 member_attribute (DECL_CONTEXT (decl));
3102 type_attribute (TREE_TYPE (type), 0, 0);
3103 pure_or_virtual_attribute (decl);
3104 }
3105 if (DECL_ABSTRACT (decl))
3106 equate_decl_number_to_die_number (decl);
3107 else
3108 {
0924ddef 3109 if (! DECL_EXTERNAL (decl))
d4d4c5a8
RS
3110 {
3111 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3112
3113 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
3114 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
3115 high_pc_attribute (func_end_label);
3116 }
340ccaab
TW
3117 }
3118}
3119
3120/* Output a DIE to represent a declared data object (either file-scope
3121 or block-local) which has "external linkage" (according to ANSI-C). */
3122
3123static void
3124output_global_variable_die (arg)
3125 register void *arg;
3126{
3127 register tree decl = arg;
d4d4c5a8 3128 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3129
3130 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3131 sibling_attribute ();
d4d4c5a8
RS
3132 if (origin != NULL)
3133 abstract_origin_attribute (origin);
3134 else
340ccaab 3135 {
d4d4c5a8
RS
3136 name_and_src_coords_attributes (decl);
3137 member_attribute (DECL_CONTEXT (decl));
3138 type_attribute (TREE_TYPE (decl),
3139 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3140 }
3141 if (DECL_ABSTRACT (decl))
3142 equate_decl_number_to_die_number (decl);
3143 else
3144 {
0924ddef 3145 if (!DECL_EXTERNAL (decl))
d4d4c5a8 3146 location_or_const_value_attribute (decl);
340ccaab
TW
3147 }
3148}
340ccaab
TW
3149
3150static void
3151output_label_die (arg)
3152 register void *arg;
3153{
3154 register tree decl = arg;
d4d4c5a8 3155 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3156
3157 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3158 sibling_attribute ();
d4d4c5a8
RS
3159 if (origin != NULL)
3160 abstract_origin_attribute (origin);
3161 else
3162 name_and_src_coords_attributes (decl);
3163 if (DECL_ABSTRACT (decl))
3164 equate_decl_number_to_die_number (decl);
3165 else
3166 {
3167 register rtx insn = DECL_RTL (decl);
340ccaab 3168
d4d4c5a8
RS
3169 if (GET_CODE (insn) == CODE_LABEL)
3170 {
3171 char label[MAX_ARTIFICIAL_LABEL_BYTES];
340ccaab 3172
d4d4c5a8
RS
3173 /* When optimization is enabled (via -O) some parts of the compiler
3174 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3175 represent source-level labels which were explicitly declared by
3176 the user. This really shouldn't be happening though, so catch
3177 it if it ever does happen. */
340ccaab 3178
d4d4c5a8
RS
3179 if (INSN_DELETED_P (insn))
3180 abort (); /* Should never happen. */
340ccaab 3181
d4d4c5a8
RS
3182 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3183 (unsigned) INSN_UID (insn));
3184 low_pc_attribute (label);
3185 }
340ccaab
TW
3186 }
3187}
3188
3189static void
3190output_lexical_block_die (arg)
3191 register void *arg;
3192{
3193 register tree stmt = arg;
340ccaab
TW
3194
3195 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3196 sibling_attribute ();
3197 dienum_push ();
d4d4c5a8
RS
3198 if (! BLOCK_ABSTRACT (stmt))
3199 {
3200 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3201 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3202
3203 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3204 low_pc_attribute (begin_label);
3205 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3206 high_pc_attribute (end_label);
3207 }
340ccaab
TW
3208}
3209
3210static void
3211output_inlined_subroutine_die (arg)
3212 register void *arg;
3213{
3214 register tree stmt = arg;
340ccaab
TW
3215
3216 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3217 sibling_attribute ();
3218 dienum_push ();
d4d4c5a8
RS
3219 abstract_origin_attribute (block_ultimate_origin (stmt));
3220 if (! BLOCK_ABSTRACT (stmt))
3221 {
3222 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3223 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3224
3225 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3226 low_pc_attribute (begin_label);
3227 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3228 high_pc_attribute (end_label);
3229 }
340ccaab
TW
3230}
3231
3232/* Output a DIE to represent a declared data object (either file-scope
3233 or block-local) which has "internal linkage" (according to ANSI-C). */
3234
3235static void
3236output_local_variable_die (arg)
3237 register void *arg;
3238{
3239 register tree decl = arg;
d4d4c5a8 3240 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3241
3242 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3243 sibling_attribute ();
d4d4c5a8
RS
3244 if (origin != NULL)
3245 abstract_origin_attribute (origin);
3246 else
3247 {
3248 name_and_src_coords_attributes (decl);
3249 member_attribute (DECL_CONTEXT (decl));
3250 type_attribute (TREE_TYPE (decl),
3251 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3252 }
3253 if (DECL_ABSTRACT (decl))
3254 equate_decl_number_to_die_number (decl);
3255 else
3256 location_or_const_value_attribute (decl);
340ccaab
TW
3257}
3258
3259static void
3260output_member_die (arg)
3261 register void *arg;
3262{
3263 register tree decl = arg;
3264
3265 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3266 sibling_attribute ();
9a631e8e 3267 name_and_src_coords_attributes (decl);
340ccaab
TW
3268 member_attribute (DECL_CONTEXT (decl));
3269 type_attribute (member_declared_type (decl),
3270 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3271 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3272 {
3273 byte_size_attribute (decl);
3274 bit_size_attribute (decl);
3275 bit_offset_attribute (decl);
3276 }
3277 data_member_location_attribute (decl);
3278}
3279
3280#if 0
d4d4c5a8
RS
3281/* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3282 modified types instead.
340ccaab
TW
3283
3284 We keep this code here just in case these types of DIEs may be needed
3285 to represent certain things in other languages (e.g. Pascal) someday.
3286*/
3287
3288static void
3289output_pointer_type_die (arg)
3290 register void *arg;
3291{
3292 register tree type = arg;
3293
3294 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3295 sibling_attribute ();
3296 equate_type_number_to_die_number (type);
3297 member_attribute (TYPE_CONTEXT (type));
3298 type_attribute (TREE_TYPE (type), 0, 0);
3299}
3300
3301static void
3302output_reference_type_die (arg)
3303 register void *arg;
3304{
3305 register tree type = arg;
3306
3307 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3308 sibling_attribute ();
3309 equate_type_number_to_die_number (type);
3310 member_attribute (TYPE_CONTEXT (type));
3311 type_attribute (TREE_TYPE (type), 0, 0);
3312}
3313#endif
3314
d4d4c5a8 3315static void
340ccaab
TW
3316output_ptr_to_mbr_type_die (arg)
3317 register void *arg;
3318{
3319 register tree type = arg;
3320
3321 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3322 sibling_attribute ();
3323 equate_type_number_to_die_number (type);
3324 member_attribute (TYPE_CONTEXT (type));
3325 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3326 type_attribute (TREE_TYPE (type), 0, 0);
3327}
3328
3329static void
3330output_compile_unit_die (arg)
3331 register void *arg;
3332{
3333 register char *main_input_filename = arg;
3334
3335 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3336 sibling_attribute ();
3337 dienum_push ();
3338 name_attribute (main_input_filename);
3339
3340 {
3341 char producer[250];
3342
3343 sprintf (producer, "%s %s", language_string, version_string);
3344 producer_attribute (producer);
3345 }
3346
3347 if (strcmp (language_string, "GNU C++") == 0)
3348 language_attribute (LANG_C_PLUS_PLUS);
3349 else if (flag_traditional)
3350 language_attribute (LANG_C);
3351 else
3352 language_attribute (LANG_C89);
3353 low_pc_attribute (TEXT_BEGIN_LABEL);
3354 high_pc_attribute (TEXT_END_LABEL);
3355 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3356 stmt_list_attribute (LINE_BEGIN_LABEL);
3357 last_filename = xstrdup (main_input_filename);
3358
3359 {
2e494f70
RS
3360 char *wd = getpwd ();
3361 if (wd)
3362 comp_dir_attribute (wd);
340ccaab
TW
3363 }
3364
3365 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3366 {
3367 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3368 src_info_attribute (SRCINFO_BEGIN_LABEL);
3369 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3370 mac_info_attribute (MACINFO_BEGIN_LABEL);
3371 }
3372}
3373
3374static void
3375output_string_type_die (arg)
3376 register void *arg;
3377{
3378 register tree type = arg;
3379
3380 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3381 sibling_attribute ();
3382 member_attribute (TYPE_CONTEXT (type));
3383
3384 /* Fudge the string length attribute for now. */
3385
d4d4c5a8 3386 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
340ccaab
TW
3387}
3388
3389static void
3390output_structure_type_die (arg)
3391 register void *arg;
3392{
3393 register tree type = arg;
3394
3395 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3396 sibling_attribute ();
3397 equate_type_number_to_die_number (type);
3398 name_attribute (type_tag (type));
3399 member_attribute (TYPE_CONTEXT (type));
3400
3401 /* If this type has been completed, then give it a byte_size attribute
3402 and prepare to give a list of members. Otherwise, don't do either of
3403 these things. In the latter case, we will not be generating a list
3404 of members (since we don't have any idea what they might be for an
3405 incomplete type). */
3406
3407 if (TYPE_SIZE (type))
3408 {
3409 dienum_push ();
3410 byte_size_attribute (type);
3411 }
3412}
3413
3414/* Output a DIE to represent a declared function (either file-scope
3415 or block-local) which has "internal linkage" (according to ANSI-C). */
3416
3417static void
3418output_local_subroutine_die (arg)
3419 register void *arg;
3420{
3421 register tree decl = arg;
d4d4c5a8 3422 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3423
3424 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3425 sibling_attribute ();
3426 dienum_push ();
d4d4c5a8
RS
3427 if (origin != NULL)
3428 abstract_origin_attribute (origin);
3429 else
3430 {
3431 register tree type = TREE_TYPE (decl);
340ccaab 3432
d4d4c5a8
RS
3433 name_and_src_coords_attributes (decl);
3434 inline_attribute (decl);
3435 prototyped_attribute (type);
3436 member_attribute (DECL_CONTEXT (decl));
3437 type_attribute (TREE_TYPE (type), 0, 0);
3438 pure_or_virtual_attribute (decl);
3439 }
3440 if (DECL_ABSTRACT (decl))
3441 equate_decl_number_to_die_number (decl);
3442 else
340ccaab 3443 {
d4d4c5a8
RS
3444 /* Avoid getting screwed up in cases where a function was declared
3445 static but where no definition was ever given for it. */
3446
3447 if (TREE_ASM_WRITTEN (decl))
3448 {
3449 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3450
3451 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
3452 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
3453 high_pc_attribute (func_end_label);
3454 }
340ccaab
TW
3455 }
3456}
3457
3458static void
3459output_subroutine_type_die (arg)
3460 register void *arg;
3461{
3462 register tree type = arg;
3463 register tree return_type = TREE_TYPE (type);
3464
3465 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3466 sibling_attribute ();
3467 dienum_push ();
3468 equate_type_number_to_die_number (type);
3469 prototyped_attribute (type);
3470 member_attribute (TYPE_CONTEXT (type));
3471 type_attribute (return_type, 0, 0);
3472}
3473
3474static void
3475output_typedef_die (arg)
3476 register void *arg;
3477{
3478 register tree decl = arg;
d4d4c5a8 3479 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3480
3481 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3482 sibling_attribute ();
d4d4c5a8
RS
3483 if (origin != NULL)
3484 abstract_origin_attribute (origin);
3485 else
3486 {
3487 name_and_src_coords_attributes (decl);
3488 member_attribute (DECL_CONTEXT (decl));
3489 type_attribute (TREE_TYPE (decl),
3490 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3491 }
3492 if (DECL_ABSTRACT (decl))
3493 equate_decl_number_to_die_number (decl);
340ccaab
TW
3494}
3495
3496static void
3497output_union_type_die (arg)
3498 register void *arg;
3499{
3500 register tree type = arg;
3501
3502 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3503 sibling_attribute ();
3504 equate_type_number_to_die_number (type);
3505 name_attribute (type_tag (type));
3506 member_attribute (TYPE_CONTEXT (type));
3507
3508 /* If this type has been completed, then give it a byte_size attribute
3509 and prepare to give a list of members. Otherwise, don't do either of
3510 these things. In the latter case, we will not be generating a list
3511 of members (since we don't have any idea what they might be for an
3512 incomplete type). */
3513
3514 if (TYPE_SIZE (type))
3515 {
3516 dienum_push ();
3517 byte_size_attribute (type);
3518 }
3519}
3520
3521/* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3522 at the end of an (ANSI prototyped) formal parameters list. */
3523
3524static void
3525output_unspecified_parameters_die (arg)
3526 register void *arg;
3527{
3528 register tree decl_or_type = arg;
3529
3530 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3531 sibling_attribute ();
3532
3533 /* This kludge is here only for the sake of being compatible with what
3534 the USL CI5 C compiler does. The specification of Dwarf Version 1
3535 doesn't say that TAG_unspecified_parameters DIEs should contain any
3536 attributes other than the AT_sibling attribute, but they are certainly
3537 allowed to contain additional attributes, and the CI5 compiler
3538 generates AT_name, AT_fund_type, and AT_location attributes within
3539 TAG_unspecified_parameters DIEs which appear in the child lists for
3540 DIEs representing function definitions, so we do likewise here. */
3541
3542 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3543 {
3544 name_attribute ("...");
3545 fund_type_attribute (FT_pointer);
3546 /* location_attribute (?); */
3547 }
3548}
3549
3550static void
3551output_padded_null_die (arg)
3552 register void *arg;
3553{
3554 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3555}
3556
3557/*************************** end of DIEs *********************************/
3558
3559/* Generate some type of DIE. This routine generates the generic outer
3560 wrapper stuff which goes around all types of DIE's (regardless of their
3561 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3562 DIE-length word, followed by the guts of the DIE itself. After the guts
3563 of the DIE, there must always be a terminator label for the DIE. */
3564
3565static void
3566output_die (die_specific_output_function, param)
3567 register void (*die_specific_output_function)();
3568 register void *param;
3569{
3570 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3571 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3572
3573 current_dienum = NEXT_DIE_NUM;
3574 NEXT_DIE_NUM = next_unused_dienum;
3575
3576 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3577 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3578
3579 /* Write a label which will act as the name for the start of this DIE. */
3580
3581 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3582
3583 /* Write the DIE-length word. */
3584
3585 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3586
3587 /* Fill in the guts of the DIE. */
3588
3589 next_unused_dienum++;
3590 die_specific_output_function (param);
3591
3592 /* Write a label which will act as the name for the end of this DIE. */
3593
3594 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3595}
3596
3597static void
3598end_sibling_chain ()
3599{
3600 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3601
3602 current_dienum = NEXT_DIE_NUM;
3603 NEXT_DIE_NUM = next_unused_dienum;
3604
3605 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3606
3607 /* Write a label which will act as the name for the start of this DIE. */
3608
3609 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3610
3611 /* Write the DIE-length word. */
3612
3613 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3614
3615 dienum_pop ();
3616}
3617\f
3618/* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3619 TAG_unspecified_parameters DIE) to represent the types of the formal
3620 parameters as specified in some function type specification (except
3621 for those which appear as part of a function *definition*).
3622
3623 Note that we must be careful here to output all of the parameter DIEs
3624 *before* we output any DIEs needed to represent the types of the formal
3625 parameters. This keeps svr4 SDB happy because it (incorrectly) thinks
3626 that the first non-parameter DIE it sees ends the formal parameter list.
3627*/
3628
3629static void
3630output_formal_types (function_or_method_type)
3631 register tree function_or_method_type;
3632{
3633 register tree link;
d4d4c5a8 3634 register tree formal_type = NULL;
340ccaab
TW
3635 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3636
3637 /* In the case where we are generating a formal types list for a C++
3638 non-static member function type, skip over the first thing on the
3639 TYPE_ARG_TYPES list because it only represents the type of the
3640 hidden `this pointer'. The debugger should be able to figure
3641 out (without being explicitly told) that this non-static member
3642 function type takes a `this pointer' and should be able to figure
3643 what the type of that hidden parameter is from the AT_member
3644 attribute of the parent TAG_subroutine_type DIE. */
3645
3646 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3647 first_parm_type = TREE_CHAIN (first_parm_type);
3648
3649 /* Make our first pass over the list of formal parameter types and output
3650 a TAG_formal_parameter DIE for each one. */
3651
3652 for (link = first_parm_type; link; link = TREE_CHAIN (link))
3653 {
3654 formal_type = TREE_VALUE (link);
3655 if (formal_type == void_type_node)
3656 break;
3657
3658 /* Output a (nameless) DIE to represent the formal parameter itself. */
3659
3660 output_die (output_formal_parameter_die, formal_type);
3661 }
3662
3663 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
3664 DIE to the end of the parameter list. */
3665
3666 if (formal_type != void_type_node)
3667 output_die (output_unspecified_parameters_die, function_or_method_type);
3668
3669 /* Make our second (and final) pass over the list of formal parameter types
3670 and output DIEs to represent those types (as necessary). */
3671
3672 for (link = TYPE_ARG_TYPES (function_or_method_type);
3673 link;
3674 link = TREE_CHAIN (link))
3675 {
3676 formal_type = TREE_VALUE (link);
3677 if (formal_type == void_type_node)
3678 break;
3679
3680 output_type (formal_type, function_or_method_type);
3681 }
3682}
3683\f
3684/* Remember a type in the pending_types_list. */
3685
3686static void
3687pend_type (type)
3688 register tree type;
3689{
3690 if (pending_types == pending_types_allocated)
3691 {
3692 pending_types_allocated += PENDING_TYPES_INCREMENT;
3693 pending_types_list
3694 = (tree *) xrealloc (pending_types_list,
3695 sizeof (tree) * pending_types_allocated);
3696 }
3697 pending_types_list[pending_types++] = type;
3698
3699 /* Mark the pending type as having been output already (even though
3700 it hasn't been). This prevents the type from being added to the
3701 pending_types_list more than once. */
3702
3703 TREE_ASM_WRITTEN (type) = 1;
3704}
3705
3706/* Return non-zero if it is legitimate to output DIEs to represent a
3707 given type while we are generating the list of child DIEs for some
c7d6dca2 3708 DIE (e.g. a function or lexical block DIE) associated with a given scope.
340ccaab 3709
c7d6dca2
RS
3710 See the comments within the function for a description of when it is
3711 considered legitimate to output DIEs for various kinds of types.
340ccaab
TW
3712
3713 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
3714 or it may point to a BLOCK node (for types local to a block), or to a
3715 FUNCTION_DECL node (for types local to the heading of some function
3716 definition), or to a FUNCTION_TYPE node (for types local to the
3717 prototyped parameter list of a function type specification), or to a
3718 RECORD_TYPE or UNION_TYPE node (in the case of C++ nested types).
3719
3720 The `scope' parameter should likewise be NULL or should point to a
3721 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
3722 node, or a UNION_TYPE node.
3723
3724 This function is used only for deciding when to "pend" and when to
3725 "un-pend" types to/from the pending_types_list.
3726
3727 Note that we sometimes make use of this "type pending" feature in a
3728 rather twisted way to temporarily delay the production of DIEs for the
3729 types of formal parameters. (We do this just to make svr4 SDB happy.)
3730 It order to delay the production of DIEs representing types of formal
3731 parameters, callers of this function supply `fake_containing_scope' as
3732 the `scope' parameter to this function. Given that fake_containing_scope
c7d6dca2
RS
3733 is a tagged type which is *not* the containing scope for *any* other type,
3734 the desired effect is achieved, i.e. output of DIEs representing types
3735 is temporarily suspended, and any type DIEs which would have otherwise
3736 been output are instead placed onto the pending_types_list. Later on,
3737 we force these (temporarily pended) types to be output simply by calling
340ccaab
TW
3738 `output_pending_types_for_scope' with an actual argument equal to the
3739 true scope of the types we temporarily pended.
3740*/
3741
c7d6dca2 3742inline int
340ccaab
TW
3743type_ok_for_scope (type, scope)
3744 register tree type;
3745 register tree scope;
3746{
c7d6dca2
RS
3747 /* Tagged types (i.e. struct, union, and enum types) must always be
3748 output only in the scopes where they actually belong (or else the
3749 scoping of their own tag names and the scoping of their member
3750 names will be incorrect). Non-tagged-types on the other hand can
3751 generally be output anywhere, except that svr4 SDB really doesn't
3752 want to see them nested within struct or union types, so here we
3753 say it is always OK to immediately output any such a (non-tagged)
3754 type, so long as we are not within such a context. Note that the
3755 only kinds of non-tagged types which we will be dealing with here
3756 (for C and C++ anyway) will be array types and function types. */
3757
3758 return is_tagged_type (type)
3759 ? (TYPE_CONTEXT (type) == scope)
3760 : (scope == NULL_TREE || ! is_tagged_type (scope));
340ccaab
TW
3761}
3762
3763/* Output any pending types (from the pending_types list) which we can output
c7d6dca2 3764 now (taking into account the scope that we are working on now).
340ccaab
TW
3765
3766 For each type output, remove the given type from the pending_types_list
3767 *before* we try to output it.
3768
3769 Note that we have to process the list in beginning-to-end order,
3770 because the call made here to output_type may cause yet more types
3771 to be added to the end of the list, and we may have to output some
3772 of them too.
3773*/
3774
3775static void
3776output_pending_types_for_scope (containing_scope)
3777 register tree containing_scope;
3778{
3779 register unsigned i;
3780
3781 for (i = 0; i < pending_types; )
3782 {
3783 register tree type = pending_types_list[i];
3784
3785 if (type_ok_for_scope (type, containing_scope))
3786 {
3787 register tree *mover;
3788 register tree *limit;
3789
3790 pending_types--;
3791 limit = &pending_types_list[pending_types];
3792 for (mover = &pending_types_list[i]; mover < limit; mover++)
3793 *mover = *(mover+1);
3794
3795 /* Un-mark the type as having been output already (because it
3796 hasn't been, really). Then call output_type to generate a
3797 Dwarf representation of it. */
3798
3799 TREE_ASM_WRITTEN (type) = 0;
3800 output_type (type, containing_scope);
3801
3802 /* Don't increment the loop counter in this case because we
3803 have shifted all of the subsequent pending types down one
3804 element in the pending_types_list array. */
3805 }
3806 else
3807 i++;
3808 }
3809}
3810
3811static void
3812output_type (type, containing_scope)
3813 register tree type;
3814 register tree containing_scope;
3815{
3816 if (type == 0 || type == error_mark_node)
3817 return;
3818
3819 /* We are going to output a DIE to represent the unqualified version of
3820 of this type (i.e. without any const or volatile qualifiers) so get
3821 the main variant (i.e. the unqualified version) of this type now. */
3822
3823 type = TYPE_MAIN_VARIANT (type);
3824
3825 if (TREE_ASM_WRITTEN (type))
3826 return;
3827
3828 /* Don't generate any DIEs for this type now unless it is OK to do so
3829 (based upon what `type_ok_for_scope' tells us). */
3830
3831 if (! type_ok_for_scope (type, containing_scope))
3832 {
3833 pend_type (type);
3834 return;
3835 }
3836
3837 switch (TREE_CODE (type))
3838 {
3839 case ERROR_MARK:
3840 break;
3841
3842 case POINTER_TYPE:
3843 case REFERENCE_TYPE:
3844 /* For these types, all that is required is that we output a DIE
3845 (or a set of DIEs) to represent that "basis" type. */
3846 output_type (TREE_TYPE (type), containing_scope);
3847 break;
3848
3849 case OFFSET_TYPE:
3850 /* This code is used for C++ pointer-to-data-member types. */
3851 /* Output a description of the relevant class type. */
3852 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
3853 /* Output a description of the type of the object pointed to. */
3854 output_type (TREE_TYPE (type), containing_scope);
3855 /* Now output a DIE to represent this pointer-to-data-member type
3856 itself. */
3857 output_die (output_ptr_to_mbr_type_die, type);
3858 break;
3859
3860 case SET_TYPE:
3861 output_type (TREE_TYPE (type), containing_scope);
3862 output_die (output_set_type_die, type);
3863 break;
3864
3865 case FILE_TYPE:
3866 output_type (TREE_TYPE (type), containing_scope);
6dc42e49 3867 abort (); /* No way to represent these in Dwarf yet! */
340ccaab
TW
3868 break;
3869
3870 case STRING_TYPE:
3871 output_type (TREE_TYPE (type), containing_scope);
3872 output_die (output_string_type_die, type);
3873 break;
3874
3875 case FUNCTION_TYPE:
3876 /* Force out return type (in case it wasn't forced out already). */
3877 output_type (TREE_TYPE (type), containing_scope);
3878 output_die (output_subroutine_type_die, type);
3879 output_formal_types (type);
3880 end_sibling_chain ();
3881 break;
3882
3883 case METHOD_TYPE:
3884 /* Force out return type (in case it wasn't forced out already). */
3885 output_type (TREE_TYPE (type), containing_scope);
3886 output_die (output_subroutine_type_die, type);
3887 output_formal_types (type);
3888 end_sibling_chain ();
3889 break;
3890
3891 case ARRAY_TYPE:
3892 {
3893 register tree element_type;
3894
3895 element_type = TREE_TYPE (type);
3896 while (TREE_CODE (element_type) == ARRAY_TYPE)
3897 element_type = TREE_TYPE (element_type);
3898
3899 output_type (element_type, containing_scope);
3900 output_die (output_array_type_die, type);
3901 }
3902 break;
3903
3904 case ENUMERAL_TYPE:
3905 case RECORD_TYPE:
3906 case UNION_TYPE:
3907
3908 /* For a non-file-scope tagged type, we can always go ahead and
3909 output a Dwarf description of this type right now, even if
3910 the type in question is still incomplete, because if this
3911 local type *was* ever completed anywhere within its scope,
3912 that complete definition would already have been attached to
3913 this RECORD_TYPE, UNION_TYPE or ENUMERAL_TYPE node by the
3914 time we reach this point. That's true because of the way the
3915 front-end does its processing of file-scope declarations (of
3916 functions and class types) within which other types might be
3917 nested. The C and C++ front-ends always gobble up such "local
3918 scope" things en-mass before they try to output *any* debugging
3919 information for any of the stuff contained inside them and thus,
3920 we get the benefit here of what is (in effect) a pre-resolution
3921 of forward references to tagged types in local scopes.
3922
3923 Note however that for file-scope tagged types we cannot assume
3924 that such pre-resolution of forward references has taken place.
3925 A given file-scope tagged type may appear to be incomplete when
3926 we reach this point, but it may yet be given a full definition
3927 (at file-scope) later on during compilation. In order to avoid
3928 generating a premature (and possibly incorrect) set of Dwarf
3929 DIEs for such (as yet incomplete) file-scope tagged types, we
3930 generate nothing at all for as-yet incomplete file-scope tagged
3931 types here unless we are making our special "finalization" pass
3932 for file-scope things at the very end of compilation. At that
3933 time, we will certainly know as much about each file-scope tagged
3934 type as we are ever going to know, so at that point in time, we
3935 can safely generate correct Dwarf descriptions for these file-
3936 scope tagged types.
3937 */
3938
3939 if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing)
3940 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
3941
3942 /* Prevent infinite recursion in cases where the type of some
3943 member of this type is expressed in terms of this type itself. */
3944
3945 TREE_ASM_WRITTEN (type) = 1;
3946
3947 /* Output a DIE to represent the tagged type itself. */
3948
3949 switch (TREE_CODE (type))
3950 {
3951 case ENUMERAL_TYPE:
3952 output_die (output_enumeration_type_die, type);
3953 return; /* a special case -- nothing left to do so just return */
3954
3955 case RECORD_TYPE:
3956 output_die (output_structure_type_die, type);
3957 break;
3958
3959 case UNION_TYPE:
3960 output_die (output_union_type_die, type);
3961 break;
d4d4c5a8
RS
3962
3963 default:
3964 abort (); /* Should never happen. */
340ccaab
TW
3965 }
3966
3967 /* If this is not an incomplete type, output descriptions of
3968 each of its members.
3969
3970 Note that as we output the DIEs necessary to represent the
3971 members of this record or union type, we will also be trying
3972 to output DIEs to represent the *types* of those members.
3973 However the `output_type' function (above) will specifically
3974 avoid generating type DIEs for member types *within* the list
3975 of member DIEs for this (containing) type execpt for those
3976 types (of members) which are explicitly marked as also being
3977 members of this (containing) type themselves. The g++ front-
3978 end can force any given type to be treated as a member of some
3979 other (containing) type by setting the TYPE_CONTEXT of the
3980 given (member) type to point to the TREE node representing the
3981 appropriate (containing) type.
3982 */
3983
3984 if (TYPE_SIZE (type))
3985 {
9a631e8e
RS
3986 {
3987 register tree normal_member;
340ccaab 3988
9a631e8e 3989 /* First output info about the data members and type members. */
340ccaab 3990
9a631e8e
RS
3991 for (normal_member = TYPE_FIELDS (type);
3992 normal_member;
3993 normal_member = TREE_CHAIN (normal_member))
3994 output_decl (normal_member, type);
3995 }
340ccaab 3996
9a631e8e
RS
3997 {
3998 register tree vec_base;
3999
4000 /* Now output info about the function members (if any). */
4001
4002 vec_base = TYPE_METHODS (type);
4003 if (vec_base)
4004 {
4005 register tree first_func_member = TREE_VEC_ELT (vec_base, 0);
4006 register tree func_member;
4007
4008 /* This isn't documented, but the first element of the
4009 vector of member functions can be NULL in cases where
4010 the class type in question didn't have either a
4011 constructor or a destructor declared for it. We have
4012 to make allowances for that here. */
4013
4014 if (first_func_member == NULL)
4015 first_func_member = TREE_VEC_ELT (vec_base, 1);
4016
4017 for (func_member = first_func_member;
4018 func_member;
4019 func_member = TREE_CHAIN (func_member))
4020 output_decl (func_member, type);
4021 }
4022 }
340ccaab 4023
c7d6dca2
RS
4024 /* RECORD_TYPEs and UNION_TYPEs are themselves scopes (at least
4025 in C++) so we must now output any nested pending types which
4026 are local just to this RECORD_TYPE or UNION_TYPE. */
4027
4028 output_pending_types_for_scope (type);
4029
340ccaab
TW
4030 end_sibling_chain (); /* Terminate member chain. */
4031 }
4032
4033 break;
4034
4035 case VOID_TYPE:
4036 case INTEGER_TYPE:
4037 case REAL_TYPE:
4038 case COMPLEX_TYPE:
4039 case BOOLEAN_TYPE:
4040 case CHAR_TYPE:
4041 break; /* No DIEs needed for fundamental types. */
4042
4043 case LANG_TYPE: /* No Dwarf representation currently defined. */
4044 break;
4045
4046 default:
4047 abort ();
4048 }
4049
4050 TREE_ASM_WRITTEN (type) = 1;
4051}
d4d4c5a8
RS
4052
4053static void
4054output_tagged_type_instantiation (type)
4055 register tree type;
4056{
4057 if (type == 0 || type == error_mark_node)
4058 return;
4059
4060 /* We are going to output a DIE to represent the unqualified version of
4061 of this type (i.e. without any const or volatile qualifiers) so make
4062 sure that we have the main variant (i.e. the unqualified version) of
4063 this type now. */
4064
4065 assert (type == TYPE_MAIN_VARIANT (type));
4066
4067 assert (TREE_ASM_WRITTEN (type));
4068
4069 switch (TREE_CODE (type))
4070 {
4071 case ERROR_MARK:
4072 break;
4073
4074 case ENUMERAL_TYPE:
4075 output_die (output_inlined_enumeration_type_die, type);
4076 break;
4077
4078 case RECORD_TYPE:
4079 output_die (output_inlined_structure_type_die, type);
4080 break;
4081
4082 case UNION_TYPE:
4083 output_die (output_inlined_union_type_die, type);
4084 break;
4085
4086 default:
4087 abort (); /* Should never happen. */
4088 }
4089}
340ccaab
TW
4090\f
4091/* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4092 the things which are local to the given block. */
4093
4094static void
4095output_block (stmt)
4096 register tree stmt;
4097{
ece0ca60
RS
4098 register int must_output_die = 0;
4099 register tree origin;
4100 register enum tree_code origin_code;
340ccaab
TW
4101
4102 /* Ignore blocks never really used to make RTL. */
4103
4104 if (! stmt || ! TREE_USED (stmt))
4105 return;
4106
ece0ca60
RS
4107 /* Determine the "ultimate origin" of this block. This block may be an
4108 inlined instance of an inlined instance of inline function, so we
4109 have to trace all of the way back through the origin chain to find
4110 out what sort of node actually served as the original seed for the
4111 creation of the current block. */
340ccaab 4112
ece0ca60
RS
4113 origin = block_ultimate_origin (stmt);
4114 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4115
4116 /* Determine if we need to output any Dwarf DIEs at all to represent this
4117 block. */
340ccaab 4118
ece0ca60
RS
4119 if (origin_code == FUNCTION_DECL)
4120 /* The outer scopes for inlinings *must* always be represented. We
4121 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4122 must_output_die = 1;
4123 else
4124 {
4125 /* In the case where the current block represents an inlining of the
4126 "body block" of an inline function, we must *NOT* output any DIE
4127 for this block because we have already output a DIE to represent
4128 the whole inlined function scope and the "body block" of any
4129 function doesn't really represent a different scope according to
4130 ANSI C rules. So we check here to make sure that this block does
4131 not represent a "body block inlining" before trying to set the
4132 `must_output_die' flag. */
4133
3abacf02 4134 if (origin == NULL || ! is_body_block (origin))
ece0ca60
RS
4135 {
4136 /* Determine if this block directly contains any "significant"
4137 local declarations which we will need to output DIEs for. */
4138
4139 if (debug_info_level > DINFO_LEVEL_TERSE)
4140 /* We are not in terse mode so *any* local declaration counts
4141 as being a "significant" one. */
4142 must_output_die = (BLOCK_VARS (stmt) != NULL);
4143 else
340ccaab 4144 {
ece0ca60
RS
4145 register tree decl;
4146
4147 /* We are in terse mode, so only local (nested) function
4148 definitions count as "significant" local declarations. */
4149
4150 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4151 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4152 {
4153 must_output_die = 1;
4154 break;
4155 }
340ccaab 4156 }
ece0ca60
RS
4157 }
4158 }
340ccaab
TW
4159
4160 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4161 DIE for any block which contains no significant local declarations
4162 at all. Rather, in such cases we just call `output_decls_for_scope'
4163 so that any needed Dwarf info for any sub-blocks will get properly
4164 generated. Note that in terse mode, our definition of what constitutes
4165 a "significant" local declaration gets restricted to include only
4166 inlined function instances and local (nested) function definitions. */
4167
ece0ca60 4168 if (must_output_die)
340ccaab 4169 {
ece0ca60
RS
4170 output_die ((origin_code == FUNCTION_DECL)
4171 ? output_inlined_subroutine_die
4172 : output_lexical_block_die,
340ccaab
TW
4173 stmt);
4174 output_decls_for_scope (stmt);
4175 end_sibling_chain ();
4176 }
4177 else
4178 output_decls_for_scope (stmt);
4179}
4180
4181/* Output all of the decls declared within a given scope (also called
4182 a `binding contour') and (recursively) all of it's sub-blocks. */
4183
4184static void
4185output_decls_for_scope (stmt)
4186 register tree stmt;
4187{
4188 /* Ignore blocks never really used to make RTL. */
4189
4190 if (! stmt || ! TREE_USED (stmt))
4191 return;
4192
ece0ca60
RS
4193 if (! BLOCK_ABSTRACT (stmt))
4194 next_block_number++;
340ccaab
TW
4195
4196 /* Output the DIEs to represent all of the data objects, functions,
4197 typedefs, and tagged types declared directly within this block
4198 but not within any nested sub-blocks. */
4199
4200 {
4201 register tree decl;
4202
4203 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4204 output_decl (decl, stmt);
4205 }
4206
4207 output_pending_types_for_scope (stmt);
4208
4209 /* Output the DIEs to represent all sub-blocks (and the items declared
4210 therein) of this block. */
4211
4212 {
4213 register tree subblocks;
4214
4215 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4216 subblocks;
4217 subblocks = BLOCK_CHAIN (subblocks))
4218 output_block (subblocks);
4219 }
4220}
4221
4222/* Output Dwarf .debug information for a decl described by DECL. */
4223
4224static void
4225output_decl (decl, containing_scope)
4226 register tree decl;
4227 register tree containing_scope;
4228{
7f7429ca
RS
4229 /* Make a note of the decl node we are going to be working on. We may
4230 need to give the user the source coordinates of where it appeared in
4231 case we notice (later on) that something about it looks screwy. */
4232
4233 dwarf_last_decl = decl;
4234
8ac9cb56
RS
4235 if (TREE_CODE (decl) == ERROR_MARK)
4236 return;
4237
4238 /* If this ..._DECL node is marked to be ignored, then ignore it.
4239 But don't ignore a function definition, since that would screw
4240 up our count of blocks, and that it turn will completely screw up the
4241 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4242 attributes (for subsequent blocks). */
4243
4244 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4245 return;
4246
340ccaab
TW
4247 switch (TREE_CODE (decl))
4248 {
340ccaab
TW
4249 case CONST_DECL:
4250 /* The individual enumerators of an enum type get output when we
4251 output the Dwarf representation of the relevant enum type itself. */
4252 break;
4253
4254 case FUNCTION_DECL:
4255 /* If we are in terse mode, don't output any DIEs to represent
648ebe7b
RS
4256 mere external function declarations. Also, if we are conforming
4257 to the DWARF version 1 specification, don't output DIEs for
340ccaab
TW
4258 mere external function declarations. */
4259
0924ddef 4260 if (DECL_EXTERNAL (decl))
648ebe7b
RS
4261#if (DWARF_VERSION > 1)
4262 if (debug_info_level <= DINFO_LEVEL_TERSE)
4263#endif
4264 break;
340ccaab
TW
4265
4266 /* Before we describe the FUNCTION_DECL itself, make sure that we
4267 have described its return type. */
4268
4269 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4270
4271 /* If the following DIE will represent a function definition for a
4272 function with "extern" linkage, output a special "pubnames" DIE
4273 label just ahead of the actual DIE. A reference to this label
4274 was already generated in the .debug_pubnames section sub-entry
4275 for this function definition. */
4276
4277 if (TREE_PUBLIC (decl))
4278 {
4279 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4280
4281 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4282 ASM_OUTPUT_LABEL (asm_out_file, label);
4283 }
4284
4285 /* Now output a DIE to represent the function itself. */
4286
0924ddef 4287 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
340ccaab
TW
4288 ? output_global_subroutine_die
4289 : output_local_subroutine_die,
4290 decl);
4291
4292 /* Now output descriptions of the arguments for this function.
4293 This gets (unnecessarily?) complex because of the fact that
4294 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4295 cases where there was a trailing `...' at the end of the formal
4296 parameter list. In order to find out if there was a trailing
4297 ellipsis or not, we must instead look at the type associated
4298 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4299 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4300 ends with a void_type_node then there should *not* be an ellipsis
4301 at the end. */
4302
4303 /* In the case where we are describing an external function, all
4304 we need to do here (and all we *can* do here) is to describe
4305 the *types* of its formal parameters. */
4306
0924ddef 4307 if (DECL_EXTERNAL (decl))
340ccaab
TW
4308 output_formal_types (TREE_TYPE (decl));
4309 else
4310 {
4311 register tree arg_decls = DECL_ARGUMENTS (decl);
4312
340ccaab
TW
4313 {
4314 register tree last_arg;
4315
4316 last_arg = (arg_decls && TREE_CODE (arg_decls) != ERROR_MARK)
4317 ? tree_last (arg_decls)
4318 : NULL;
4319
4320 /* Generate DIEs to represent all known formal parameters, but
4321 don't do it if this looks like a varargs function. A given
4322 function is considered to be a varargs function if (and only
4323 if) its last named argument is named `__builtin_va_alist'. */
4324
4325 if (! last_arg
4326 || ! DECL_NAME (last_arg)
4327 || strcmp (IDENTIFIER_POINTER (DECL_NAME (last_arg)),
4328 "__builtin_va_alist"))
4329 {
4330 register tree parm;
4331
4332 /* WARNING! Kludge zone ahead! Here we have a special
2e494f70 4333 hack for svr4 SDB compatibility. Instead of passing the
340ccaab
TW
4334 current FUNCTION_DECL node as the second parameter (i.e.
4335 the `containing_scope' parameter) to `output_decl' (as
4336 we ought to) we instead pass a pointer to our own private
4337 fake_containing_scope node. That node is a RECORD_TYPE
4338 node which NO OTHER TYPE may ever actually be a member of.
4339
4340 This pointer will ultimately get passed into `output_type'
4341 as its `containing_scope' parameter. `Output_type' will
4342 then perform its part in the hack... i.e. it will pend
4343 the type of the formal parameter onto the pending_types
4344 list. Later on, when we are done generating the whole
4345 sequence of formal parameter DIEs for this function
4346 definition, we will un-pend all previously pended types
4347 of formal parameters for this function definition.
4348
4349 This whole kludge prevents any type DIEs from being
4350 mixed in with the formal parameter DIEs. That's good
4351 because svr4 SDB believes that the list of formal
4352 parameter DIEs for a function ends wherever the first
4353 non-formal-parameter DIE appears. Thus, we have to
4354 keep the formal parameter DIEs segregated. They must
4355 all appear (consecutively) at the start of the list of
4356 children for the DIE representing the function definition.
4357 Then (and only then) may we output any additional DIEs
4358 needed to represent the types of these formal parameters.
4359 */
4360
4361 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4362 if (TREE_CODE (parm) == PARM_DECL)
4363 output_decl (parm, fake_containing_scope);
4364
4365 /* Now that we have finished generating all of the DIEs to
4366 represent the formal parameters themselves, force out
4367 any DIEs needed to represent their types. We do this
4368 simply by un-pending all previously pended types which
4369 can legitimately go into the chain of children DIEs for
4370 the current FUNCTION_DECL. */
4371
4372 output_pending_types_for_scope (decl);
4373 }
4374 }
4375
4376 /* Now try to decide if we should put an ellipsis at the end. */
4377
4378 {
4379 register int has_ellipsis = TRUE; /* default assumption */
4380 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4381
4382 if (fn_arg_types)
4383 {
4384 /* This function declaration/definition was prototyped. */
4385
4386 /* If the list of formal argument types ends with a
4387 void_type_node, then the formals list did *not* end
4388 with an ellipsis. */
4389
4390 if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node)
4391 has_ellipsis = FALSE;
4392 }
4393 else
4394 {
4395 /* This function declaration/definition was not prototyped. */
4396
4397 /* Note that all non-prototyped function *declarations* are
4398 assumed to represent varargs functions (until proven
4399 otherwise). */
4400
4401 if (DECL_INITIAL (decl)) /* if this is a func definition */
4402 {
4403 if (!arg_decls)
4404 has_ellipsis = FALSE; /* no args == (void) */
4405 else
4406 {
4407 /* For a non-prototyped function definition which
4408 declares one or more formal parameters, if the name
4409 of the first formal parameter is *not*
4410 __builtin_va_alist then we must assume that this
4411 is *not* a varargs function. */
4412
4413 if (DECL_NAME (arg_decls)
4414 && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)),
4415 "__builtin_va_alist"))
4416 has_ellipsis = FALSE;
4417 }
4418 }
4419 }
4420
4421 if (has_ellipsis)
4422 output_die (output_unspecified_parameters_die, decl);
4423 }
4424 }
4425
4426 /* Output Dwarf info for all of the stuff within the body of the
4427 function (if it has one - it may be just a declaration). */
4428
4429 {
4430 register tree outer_scope = DECL_INITIAL (decl);
4431
4432 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4433 {
4434 /* Note that here, `outer_scope' is a pointer to the outermost
d4d4c5a8 4435 BLOCK node created to represent a function.
340ccaab
TW
4436 This outermost BLOCK actually represents the outermost
4437 binding contour for the function, i.e. the contour in which
d4d4c5a8
RS
4438 the function's formal parameters and labels get declared.
4439
4440 Curiously, it appears that the front end doesn't actually
4441 put the PARM_DECL nodes for the current function onto the
4442 BLOCK_VARS list for this outer scope. (They are strung
4443 off of the DECL_ARGUMENTS list for the function instead.)
4444 The BLOCK_VARS list for the `outer_scope' does provide us
4445 with a list of the LABEL_DECL nodes for the function however,
4446 and we output DWARF info for those here.
4447
4448 Just within the `outer_scope' there will be another BLOCK
4449 node representing the function's outermost pair of curly
4450 braces. We musn't generate a lexical_block DIE for this
4451 outermost pair of curly braces because that is not really an
340ccaab 4452 independent scope according to ANSI C rules. Rather, it is
d4d4c5a8 4453 the same scope in which the parameters were declared. */
340ccaab
TW
4454
4455 {
4456 register tree label;
4457
4458 for (label = BLOCK_VARS (outer_scope);
4459 label;
4460 label = TREE_CHAIN (label))
4461 output_decl (label, outer_scope);
4462 }
4463
d4d4c5a8
RS
4464 /* Note here that `BLOCK_SUBBLOCKS (outer_scope)' points to a
4465 list of BLOCK nodes which is always only one element long.
4466 That one element represents the outermost pair of curley
4467 braces for the function body. */
4468
340ccaab
TW
4469 output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope));
4470
4471 /* Finally, force out any pending types which are local to the
4472 outermost block of this function definition. These will
4473 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4474 node itself. */
4475
4476 output_pending_types_for_scope (decl);
4477 }
4478 }
4479
4480 /* Generate a terminator for the list of stuff `owned' by this
4481 function. */
4482
4483 end_sibling_chain ();
4484
4485 break;
4486
4487 case TYPE_DECL:
4488 /* If we are in terse mode, don't generate any DIEs to represent
4489 any actual typedefs. Note that even when we are in terse mode,
4490 we must still output DIEs to represent those tagged types which
4491 are used (directly or indirectly) in the specification of either
4492 a return type or a formal parameter type of some function. */
4493
4494 if (debug_info_level <= DINFO_LEVEL_TERSE)
4495 if (DECL_NAME (decl) != NULL
4496 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4497 return;
4498
d4d4c5a8
RS
4499 /* In the special case of a null-named TYPE_DECL node (representing
4500 the declaration of some type tag), if the given TYPE_DECL is
4501 marked as having been instantiated from some other (original)
4502 TYPE_DECL node (e.g. one which was generated within the original
4503 definition of an inline function) we have to generate a special
4504 (abbreviated) TAG_structure_type, TAG_union_type, or
4505 TAG_enumeration-type DIE here. */
4506
4507 if (! DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl))
4508 {
4509 output_tagged_type_instantiation (TREE_TYPE (decl));
4510 return;
4511 }
4512
340ccaab
TW
4513 output_type (TREE_TYPE (decl), containing_scope);
4514
4515 /* Note that unlike the gcc front end (which generates a NULL named
4516 TYPE_DECL node for each complete tagged type, each array type,
4517 and each function type node created) the g++ front end generates
4518 a *named* TYPE_DECL node for each tagged type node created.
4519 Unfortunately, these g++ TYPE_DECL nodes cause us to output many
4520 superfluous and unnecessary TAG_typedef DIEs here. When g++ is
4521 fixed to stop generating these superfluous named TYPE_DECL nodes,
4522 the superfluous TAG_typedef DIEs will likewise cease. */
4523
4524 if (DECL_NAME (decl))
4525 /* Output a DIE to represent the typedef itself. */
4526 output_die (output_typedef_die, decl);
4527 break;
4528
4529 case LABEL_DECL:
4530 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4531 output_die (output_label_die, decl);
4532 break;
4533
4534 case VAR_DECL:
648ebe7b
RS
4535 /* If we are conforming to the DWARF version 1 specification, don't
4536 generated any DIEs to represent mere external object declarations. */
4537
4538#if (DWARF_VERSION <= 1)
0924ddef 4539 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
648ebe7b
RS
4540 break;
4541#endif
4542
340ccaab
TW
4543 /* If we are in terse mode, don't generate any DIEs to represent
4544 any variable declarations or definitions. */
4545
4546 if (debug_info_level <= DINFO_LEVEL_TERSE)
4547 break;
4548
4549 /* Output any DIEs that are needed to specify the type of this data
4550 object. */
4551
4552 output_type (TREE_TYPE (decl), containing_scope);
4553
4554 /* If the following DIE will represent a data object definition for a
4555 data object with "extern" linkage, output a special "pubnames" DIE
4556 label just ahead of the actual DIE. A reference to this label
4557 was already generated in the .debug_pubnames section sub-entry
4558 for this data object definition. */
4559
d4d4c5a8 4560 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
340ccaab
TW
4561 {
4562 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4563
4564 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4565 ASM_OUTPUT_LABEL (asm_out_file, label);
4566 }
4567
d4d4c5a8
RS
4568 /* Now output the DIE to represent the data object itself. This gets
4569 complicated because of the possibility that the VAR_DECL really
4570 represents an inlined instance of a formal parameter for an inline
4571 function. */
4572
4573 {
4574 register void (*func) ();
4575 register tree origin = decl_ultimate_origin (decl);
340ccaab 4576
d4d4c5a8
RS
4577 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
4578 func = output_formal_parameter_die;
4579 else
4580 {
0924ddef 4581 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
d4d4c5a8
RS
4582 func = output_global_variable_die;
4583 else
4584 func = output_local_variable_die;
4585 }
4586 output_die (func, decl);
4587 }
340ccaab
TW
4588 break;
4589
4590 case FIELD_DECL:
4591 /* Ignore the nameless fields that are used to skip bits. */
4592 if (DECL_NAME (decl) != 0)
4593 {
4594 output_type (member_declared_type (decl), containing_scope);
4595 output_die (output_member_die, decl);
4596 }
4597 break;
4598
4599 case PARM_DECL:
4600 /* Force out the type of this formal, if it was not forced out yet.
4601 Note that here we can run afowl of a bug in "classic" svr4 SDB.
4602 It should be able to grok the presence of type DIEs within a list
4603 of TAG_formal_parameter DIEs, but it doesn't. */
4604
4605 output_type (TREE_TYPE (decl), containing_scope);
4606 output_die (output_formal_parameter_die, decl);
4607 break;
4608
4609 default:
4610 abort ();
4611 }
4612}
4613\f
4614void
4615dwarfout_file_scope_decl (decl, set_finalizing)
4616 register tree decl;
4617 register int set_finalizing;
4618{
8ac9cb56
RS
4619 if (TREE_CODE (decl) == ERROR_MARK)
4620 return;
4621
4622 /* If this ..._DECL node is marked to be ignored, then ignore it. We
4623 gotta hope that the node in question doesn't represent a function
4624 definition. If it does, then totally ignoring it is bound to screw
4625 up our count of blocks, and that it turn will completely screw up the
4626 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4627 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
4628 don't carry their own sequence numbers with them!) */
4629
4630 if (DECL_IGNORED_P (decl))
4631 {
4632 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4633 abort ();
4634 return;
4635 }
4636
340ccaab
TW
4637 switch (TREE_CODE (decl))
4638 {
4639 case FUNCTION_DECL:
4640
8ac9cb56
RS
4641 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
4642 a builtin function. Explicit programmer-supplied declarations of
4643 these same functions should NOT be ignored however. */
340ccaab 4644
0924ddef 4645 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
340ccaab
TW
4646 return;
4647
4648 /* Ignore this FUNCTION_DECL if it refers to a file-scope extern
4649 function declaration and if the declaration was never even
4650 referenced from within this entire compilation unit. We
4651 suppress these DIEs in order to save space in the .debug section
4652 (by eliminating entries which are probably useless). Note that
4653 we must not suppress block-local extern declarations (whether
4654 used or not) because that would screw-up the debugger's name
4655 lookup mechanism and cause it to miss things which really ought
4656 to be in scope at a given point. */
4657
0924ddef 4658 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
340ccaab
TW
4659 return;
4660
d4d4c5a8 4661 if (TREE_PUBLIC (decl)
0924ddef 4662 && ! DECL_EXTERNAL (decl)
d4d4c5a8 4663 && ! DECL_ABSTRACT (decl))
340ccaab
TW
4664 {
4665 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4666
4667 /* Output a .debug_pubnames entry for a public function
4668 defined in this compilation unit. */
4669
4670 fputc ('\n', asm_out_file);
85595d1a 4671 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab
TW
4672 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4673 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4674 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4675 IDENTIFIER_POINTER (DECL_NAME (decl)));
85595d1a 4676 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4677 }
4678
4679 break;
4680
4681 case VAR_DECL:
4682
4683 /* Ignore this VAR_DECL if it refers to a file-scope extern data
4684 object declaration and if the declaration was never even
4685 referenced from within this entire compilation unit. We
4686 suppress these DIEs in order to save space in the .debug section
4687 (by eliminating entries which are probably useless). Note that
4688 we must not suppress block-local extern declarations (whether
4689 used or not) because that would screw-up the debugger's name
4690 lookup mechanism and cause it to miss things which really ought
4691 to be in scope at a given point. */
4692
0924ddef 4693 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
340ccaab
TW
4694 return;
4695
6dc42e49 4696 if (TREE_PUBLIC (decl)
0924ddef 4697 && ! DECL_EXTERNAL (decl)
d4d4c5a8
RS
4698 && GET_CODE (DECL_RTL (decl)) == MEM
4699 && ! DECL_ABSTRACT (decl))
340ccaab
TW
4700 {
4701 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4702
4703 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4704 {
4705 /* Output a .debug_pubnames entry for a public variable
4706 defined in this compilation unit. */
4707
4708 fputc ('\n', asm_out_file);
85595d1a 4709 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab
TW
4710 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4711 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4712 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4713 IDENTIFIER_POINTER (DECL_NAME (decl)));
85595d1a 4714 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4715 }
4716
4717 if (DECL_INITIAL (decl) == NULL)
4718 {
4719 /* Output a .debug_aranges entry for a public variable
6dc42e49 4720 which is tentatively defined in this compilation unit. */
340ccaab
TW
4721
4722 fputc ('\n', asm_out_file);
85595d1a 4723 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
340ccaab 4724 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
9a631e8e 4725 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
340ccaab
TW
4726 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4727 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
85595d1a 4728 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4729 }
4730 }
4731
4732 /* If we are in terse mode, don't generate any DIEs to represent
4733 any variable declarations or definitions. */
4734
4735 if (debug_info_level <= DINFO_LEVEL_TERSE)
4736 return;
4737
4738 break;
4739
4740 case TYPE_DECL:
4741 /* Don't generate any DIEs to represent the standard built-in types. */
4742
4743 if (DECL_SOURCE_LINE (decl) == 0)
4744 return;
4745
4746 /* If we are in terse mode, don't generate any DIEs to represent
4747 any actual typedefs. Note that even when we are in terse mode,
4748 we must still output DIEs to represent those tagged types which
4749 are used (directly or indirectly) in the specification of either
4750 a return type or a formal parameter type of some function. */
4751
4752 if (debug_info_level <= DINFO_LEVEL_TERSE)
4753 if (DECL_NAME (decl) != NULL
4754 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4755 return;
4756
4757 break;
4758
4759 default:
4760 return;
4761 }
4762
4763 fputc ('\n', asm_out_file);
85595d1a 4764 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
340ccaab 4765 finalizing = set_finalizing;
906c4e36 4766 output_decl (decl, NULL_TREE);
340ccaab
TW
4767
4768 /* NOTE: The call above to `output_decl' may have caused one or more
4769 file-scope named types (i.e. tagged types) to be placed onto the
4770 pending_types_list. We have to get those types off of that list
4771 at some point, and this is the perfect time to do it. If we didn't
4772 take them off now, they might still be on the list when cc1 finally
4773 exits. That might be OK if it weren't for the fact that when we put
4774 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
4775 for these types, and that causes them never to be output unless
4776 `output_pending_types_for_scope' takes them off of the list and un-sets
4777 their TREE_ASM_WRITTEN flags. */
4778
906c4e36 4779 output_pending_types_for_scope (NULL_TREE);
340ccaab
TW
4780
4781 /* The above call should have totally emptied the pending_types_list. */
4782
4783 assert (pending_types == 0);
4784
85595d1a 4785 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4786
4787 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4788 current_funcdef_number++;
4789}
4790\f
4791/* Output a marker (i.e. a label) for the beginning of the generated code
4792 for a lexical block. */
4793
4794void
4795dwarfout_begin_block (blocknum)
4796 register unsigned blocknum;
4797{
4798 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4799
4800 text_section ();
4801 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
4802 ASM_OUTPUT_LABEL (asm_out_file, label);
4803}
4804
4805/* Output a marker (i.e. a label) for the end of the generated code
4806 for a lexical block. */
4807
4808void
4809dwarfout_end_block (blocknum)
4810 register unsigned blocknum;
4811{
4812 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4813
4814 text_section ();
4815 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
4816 ASM_OUTPUT_LABEL (asm_out_file, label);
4817}
4818
4819/* Output a marker (i.e. a label) at a point in the assembly code which
4820 corresponds to a given source level label. */
4821
4822void
4823dwarfout_label (insn)
4824 register rtx insn;
4825{
4826 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4827 {
4828 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4829
4830 text_section ();
4831 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
4832 (unsigned) INSN_UID (insn));
4833 ASM_OUTPUT_LABEL (asm_out_file, label);
4834 }
4835}
4836
4837/* Output a marker (i.e. a label) for the absolute end of the generated code
4838 for a function definition. This gets called *after* the epilogue code
4839 has been generated. */
4840
4841void
4842dwarfout_end_epilogue ()
4843{
4844 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4845
4846 /* Output a label to mark the endpoint of the code generated for this
4847 function. */
4848
4849 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4850 ASM_OUTPUT_LABEL (asm_out_file, label);
4851}
4852
4853static void
4854shuffle_filename_entry (new_zeroth)
4855 register filename_entry *new_zeroth;
4856{
4857 filename_entry temp_entry;
4858 register filename_entry *limit_p;
4859 register filename_entry *move_p;
4860
4861 if (new_zeroth == &filename_table[0])
4862 return;
4863
4864 temp_entry = *new_zeroth;
4865
4866 /* Shift entries up in the table to make room at [0]. */
4867
4868 limit_p = &filename_table[0];
4869 for (move_p = new_zeroth; move_p > limit_p; move_p--)
4870 *move_p = *(move_p-1);
4871
4872 /* Install the found entry at [0]. */
4873
4874 filename_table[0] = temp_entry;
4875}
4876
4877/* Create a new (string) entry for the .debug_sfnames section. */
4878
4879static void
4880generate_new_sfname_entry ()
4881{
4882 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4883
4884 fputc ('\n', asm_out_file);
85595d1a 4885 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
340ccaab
TW
4886 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
4887 ASM_OUTPUT_LABEL (asm_out_file, label);
4888 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4889 filename_table[0].name
4890 ? filename_table[0].name
4891 : "");
85595d1a 4892 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4893}
4894
4895/* Lookup a filename (in the list of filenames that we know about here in
4896 dwarfout.c) and return its "index". The index of each (known) filename
4897 is just a unique number which is associated with only that one filename.
4898 We need such numbers for the sake of generating labels (in the
4899 .debug_sfnames section) and references to those unique labels (in the
4900 .debug_srcinfo and .debug_macinfo sections).
4901
4902 If the filename given as an argument is not found in our current list,
4903 add it to the list and assign it the next available unique index number.
4904
4905 Whatever we do (i.e. whether we find a pre-existing filename or add a new
4906 one), we shuffle the filename found (or added) up to the zeroth entry of
4907 our list of filenames (which is always searched linearly). We do this so
4908 as to optimize the most common case for these filename lookups within
4909 dwarfout.c. The most common case by far is the case where we call
4910 lookup_filename to lookup the very same filename that we did a lookup
4911 on the last time we called lookup_filename. We make sure that this
4912 common case is fast because such cases will constitute 99.9% of the
4913 lookups we ever do (in practice).
4914
4915 If we add a new filename entry to our table, we go ahead and generate
4916 the corresponding entry in the .debug_sfnames section right away.
4917 Doing so allows us to avoid tickling an assembler bug (present in some
4918 m68k assemblers) which yields assembly-time errors in cases where the
4919 difference of two label addresses is taken and where the two labels
4920 are in a section *other* than the one where the difference is being
4921 calculated, and where at least one of the two symbol references is a
4922 forward reference. (This bug could be tickled by our .debug_srcinfo
4923 entries if we don't output their corresponding .debug_sfnames entries
4924 before them.)
4925*/
4926
4927static unsigned
4928lookup_filename (file_name)
4929 char *file_name;
4930{
4931 register filename_entry *search_p;
4932 register filename_entry *limit_p = &filename_table[ft_entries];
4933
4934 for (search_p = filename_table; search_p < limit_p; search_p++)
4935 if (!strcmp (file_name, search_p->name))
4936 {
4937 /* When we get here, we have found the filename that we were
4938 looking for in the filename_table. Now we want to make sure
4939 that it gets moved to the zero'th entry in the table (if it
4940 is not already there) so that subsequent attempts to find the
4941 same filename will find it as quickly as possible. */
4942
4943 shuffle_filename_entry (search_p);
4944 return filename_table[0].number;
4945 }
4946
4947 /* We come here whenever we have a new filename which is not registered
4948 in the current table. Here we add it to the table. */
4949
4950 /* Prepare to add a new table entry by making sure there is enough space
4951 in the table to do so. If not, expand the current table. */
4952
4953 if (ft_entries == ft_entries_allocated)
4954 {
4955 ft_entries_allocated += FT_ENTRIES_INCREMENT;
4956 filename_table
4957 = (filename_entry *)
4958 xrealloc (filename_table,
4959 ft_entries_allocated * sizeof (filename_entry));
4960 }
4961
4962 /* Initially, add the new entry at the end of the filename table. */
4963
4964 filename_table[ft_entries].number = ft_entries;
4965 filename_table[ft_entries].name = xstrdup (file_name);
4966
4967 /* Shuffle the new entry into filename_table[0]. */
4968
4969 shuffle_filename_entry (&filename_table[ft_entries]);
4970
4971 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4972 generate_new_sfname_entry ();
4973
4974 ft_entries++;
4975 return filename_table[0].number;
4976}
4977
4978static void
4979generate_srcinfo_entry (line_entry_num, files_entry_num)
4980 unsigned line_entry_num;
4981 unsigned files_entry_num;
4982{
4983 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4984
4985 fputc ('\n', asm_out_file);
85595d1a 4986 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
340ccaab
TW
4987 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
4988 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
4989 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
4990 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
85595d1a 4991 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
4992}
4993
4994void
4995dwarfout_line (filename, line)
4996 register char *filename;
4997 register unsigned line;
4998{
4999 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5000 {
5001 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5002 static unsigned last_line_entry_num = 0;
5003 static unsigned prev_file_entry_num = (unsigned) -1;
5004 register unsigned this_file_entry_num = lookup_filename (filename);
5005
5006 text_section ();
5007 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5008 ASM_OUTPUT_LABEL (asm_out_file, label);
5009
5010 fputc ('\n', asm_out_file);
85595d1a 5011 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
340ccaab
TW
5012
5013 if (this_file_entry_num != prev_file_entry_num)
5014 {
5015 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5016
5017 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5018 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5019 }
5020
5021 {
3f7cc57a 5022 register char *tail = rindex (filename, '/');
340ccaab
TW
5023
5024 if (tail != NULL)
5025 filename = tail;
5026 }
5027
2e494f70 5028 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
340ccaab
TW
5029 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5030 filename, line);
5031 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5032 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
85595d1a 5033 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5034
5035 if (this_file_entry_num != prev_file_entry_num)
5036 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5037 prev_file_entry_num = this_file_entry_num;
5038 }
5039}
5040
5041/* Generate an entry in the .debug_macinfo section. */
5042
5043static void
5044generate_macinfo_entry (type_and_offset, string)
5045 register char *type_and_offset;
5046 register char *string;
5047{
5048 fputc ('\n', asm_out_file);
85595d1a 5049 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
2e494f70 5050 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
340ccaab 5051 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
85595d1a 5052 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5053}
5054
5055void
5056dwarfout_start_new_source_file (filename)
5057 register char *filename;
5058{
5059 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5060 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5061
5062 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5063 sprintf (type_and_offset, "0x%08x+%s-%s",
5064 ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
5065 generate_macinfo_entry (type_and_offset, "");
5066}
5067
5068void
5069dwarfout_resume_previous_source_file (lineno)
5070 register unsigned lineno;
5071{
5072 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5073
5074 sprintf (type_and_offset, "0x%08x+%u",
5075 ((unsigned) MACINFO_resume << 24), lineno);
5076 generate_macinfo_entry (type_and_offset, "");
5077}
5078
5079/* Called from check_newline in c-parse.y. The `buffer' parameter
5080 contains the tail part of the directive line, i.e. the part which
5081 is past the initial whitespace, #, whitespace, directive-name,
5082 whitespace part. */
5083
5084void
5085dwarfout_define (lineno, buffer)
5086 register unsigned lineno;
5087 register char *buffer;
5088{
5089 static int initialized = 0;
5090 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5091
5092 if (!initialized)
5093 {
5094 dwarfout_start_new_source_file (primary_filename);
5095 initialized = 1;
5096 }
5097 sprintf (type_and_offset, "0x%08x+%u",
5098 ((unsigned) MACINFO_define << 24), lineno);
5099 generate_macinfo_entry (type_and_offset, buffer);
5100}
5101
5102/* Called from check_newline in c-parse.y. The `buffer' parameter
5103 contains the tail part of the directive line, i.e. the part which
5104 is past the initial whitespace, #, whitespace, directive-name,
5105 whitespace part. */
5106
5107void
5108dwarfout_undef (lineno, buffer)
5109 register unsigned lineno;
5110 register char *buffer;
5111{
5112 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5113
5114 sprintf (type_and_offset, "0x%08x+%u",
5115 ((unsigned) MACINFO_undef << 24), lineno);
5116 generate_macinfo_entry (type_and_offset, buffer);
5117}
5118
5119/* Set up for Dwarf output at the start of compilation. */
5120
5121void
5122dwarfout_init (asm_out_file, main_input_filename)
5123 register FILE *asm_out_file;
5124 register char *main_input_filename;
5125{
5126 /* Remember the name of the primary input file. */
5127
5128 primary_filename = main_input_filename;
5129
5130 /* Allocate the initial hunk of the pending_sibling_stack. */
5131
5132 pending_sibling_stack
5133 = (unsigned *)
5134 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5135 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5136 pending_siblings = 1;
5137
5138 /* Allocate the initial hunk of the filename_table. */
5139
5140 filename_table
5141 = (filename_entry *)
5142 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5143 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5144 ft_entries = 0;
5145
5146 /* Allocate the initial hunk of the pending_types_list. */
5147
5148 pending_types_list
5149 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5150 pending_types_allocated = PENDING_TYPES_INCREMENT;
5151 pending_types = 0;
5152
5153 /* Create an artificial RECORD_TYPE node which we can use in our hack
5154 to get the DIEs representing types of formal parameters to come out
5155 only *after* the DIEs for the formal parameters themselves. */
5156
5157 fake_containing_scope = make_node (RECORD_TYPE);
5158
5159 /* Output a starting label for the .text section. */
5160
5161 fputc ('\n', asm_out_file);
85595d1a 5162 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
340ccaab 5163 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
85595d1a 5164 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5165
5166 /* Output a starting label for the .data section. */
5167
5168 fputc ('\n', asm_out_file);
85595d1a 5169 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
340ccaab 5170 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
85595d1a 5171 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5172
5173 /* Output a starting label for the .data1 section. */
5174
5175 fputc ('\n', asm_out_file);
85595d1a 5176 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
340ccaab 5177 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
85595d1a 5178 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5179
5180 /* Output a starting label for the .rodata section. */
5181
5182 fputc ('\n', asm_out_file);
85595d1a 5183 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
340ccaab 5184 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
85595d1a 5185 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5186
5187 /* Output a starting label for the .rodata1 section. */
5188
5189 fputc ('\n', asm_out_file);
85595d1a 5190 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
340ccaab 5191 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
85595d1a 5192 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5193
5194 /* Output a starting label for the .bss section. */
5195
5196 fputc ('\n', asm_out_file);
85595d1a 5197 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
340ccaab 5198 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
85595d1a 5199 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5200
5201 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5202 {
5203 /* Output a starting label and an initial (compilation directory)
5204 entry for the .debug_sfnames section. The starting label will be
5205 referenced by the initial entry in the .debug_srcinfo section. */
5206
5207 fputc ('\n', asm_out_file);
85595d1a 5208 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
340ccaab
TW
5209 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5210 {
2e494f70
RS
5211 register char *pwd = getpwd ();
5212 register unsigned len = strlen (pwd);
5213 register char *dirname = (char *) xmalloc (len + 2);
340ccaab 5214
2e494f70
RS
5215 strcpy (dirname, pwd);
5216 strcpy (dirname + len, "/");
340ccaab
TW
5217 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
5218 free (dirname);
5219 }
85595d1a 5220 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5221
5222 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5223 {
5224 /* Output a starting label for the .debug_macinfo section. This
5225 label will be referenced by the AT_mac_info attribute in the
5226 TAG_compile_unit DIE. */
5227
5228 fputc ('\n', asm_out_file);
85595d1a 5229 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
340ccaab 5230 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
85595d1a 5231 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5232 }
5233
5234 /* Generate the initial entry for the .line section. */
5235
5236 fputc ('\n', asm_out_file);
85595d1a 5237 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
340ccaab
TW
5238 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5239 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5240 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
85595d1a 5241 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5242
5243 /* Generate the initial entry for the .debug_srcinfo section. */
5244
5245 fputc ('\n', asm_out_file);
85595d1a 5246 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
340ccaab
TW
5247 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5248 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5249 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5250 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5251 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5252#ifdef DWARF_TIMESTAMPS
5253 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5254#else
5255 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5256#endif
85595d1a 5257 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5258
5259 /* Generate the initial entry for the .debug_pubnames section. */
5260
5261 fputc ('\n', asm_out_file);
85595d1a 5262 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab 5263 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
85595d1a 5264 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5265
5266 /* Generate the initial entry for the .debug_aranges section. */
5267
5268 fputc ('\n', asm_out_file);
85595d1a 5269 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
340ccaab 5270 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
85595d1a 5271 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5272 }
5273
5274 /* Setup first DIE number == 1. */
5275 NEXT_DIE_NUM = next_unused_dienum++;
5276
5277 /* Generate the initial DIE for the .debug section. Note that the
5278 (string) value given in the AT_name attribute of the TAG_compile_unit
5279 DIE will (typically) be a relative pathname and that this pathname
5280 should be taken as being relative to the directory from which the
5281 compiler was invoked when the given (base) source file was compiled. */
5282
5283 fputc ('\n', asm_out_file);
85595d1a 5284 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
340ccaab
TW
5285 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5286 output_die (output_compile_unit_die, main_input_filename);
85595d1a 5287 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5288
5289 fputc ('\n', asm_out_file);
5290}
5291
5292/* Output stuff that dwarf requires at the end of every file. */
5293
5294void
5295dwarfout_finish ()
5296{
5297 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5298
5299 fputc ('\n', asm_out_file);
85595d1a 5300 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
340ccaab
TW
5301
5302 /* Mark the end of the chain of siblings which represent all file-scope
5303 declarations in this compilation unit. */
5304
5305 /* The (null) DIE which represents the terminator for the (sibling linked)
5306 list of file-scope items is *special*. Normally, we would just call
5307 end_sibling_chain at this point in order to output a word with the
5308 value `4' and that word would act as the terminator for the list of
5309 DIEs describing file-scope items. Unfortunately, if we were to simply
5310 do that, the label that would follow this DIE in the .debug section
5311 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5312 machines) to a 4 byte boundary.
5313
5314 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5315 the trick used is to insert extra (otherwise useless) padding bytes
6dc42e49 5316 into the (null) DIE that we know must precede the ..D2 label in the
340ccaab
TW
5317 .debug section. The amount of padding required can be anywhere between
5318 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5319 with the padding) would normally contain the value 4, but now it will
5320 also have to include the padding bytes, so it will instead have some
5321 value in the range 4..7.
5322
5323 Fortunately, the rules of Dwarf say that any DIE whose length word
5324 contains *any* value less than 8 should be treated as a null DIE, so
5325 this trick works out nicely. Clever, eh? Don't give me any credit
5326 (or blame). I didn't think of this scheme. I just conformed to it.
5327 */
5328
5329 output_die (output_padded_null_die, (void *)0);
5330 dienum_pop ();
5331
5332 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5333 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
85595d1a 5334 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5335
5336 /* Output a terminator label for the .text section. */
5337
5338 fputc ('\n', asm_out_file);
85595d1a 5339 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
340ccaab 5340 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
85595d1a 5341 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5342
5343 /* Output a terminator label for the .data section. */
5344
5345 fputc ('\n', asm_out_file);
85595d1a 5346 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
340ccaab 5347 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
85595d1a 5348 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5349
5350 /* Output a terminator label for the .data1 section. */
5351
5352 fputc ('\n', asm_out_file);
85595d1a 5353 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
340ccaab 5354 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
85595d1a 5355 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5356
5357 /* Output a terminator label for the .rodata section. */
5358
5359 fputc ('\n', asm_out_file);
85595d1a 5360 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
340ccaab 5361 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
85595d1a 5362 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5363
5364 /* Output a terminator label for the .rodata1 section. */
5365
5366 fputc ('\n', asm_out_file);
85595d1a 5367 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
340ccaab 5368 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
85595d1a 5369 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5370
5371 /* Output a terminator label for the .bss section. */
5372
5373 fputc ('\n', asm_out_file);
85595d1a 5374 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
340ccaab 5375 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
85595d1a 5376 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5377
5378 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5379 {
5380 /* Output a terminating entry for the .line section. */
5381
5382 fputc ('\n', asm_out_file);
85595d1a 5383 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
340ccaab
TW
5384 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5385 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5386 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5387 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5388 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
85595d1a 5389 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5390
5391 /* Output a terminating entry for the .debug_srcinfo section. */
5392
5393 fputc ('\n', asm_out_file);
85595d1a 5394 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
340ccaab
TW
5395 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5396 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5397 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
85595d1a 5398 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5399
5400 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5401 {
5402 /* Output terminating entries for the .debug_macinfo section. */
5403
5404 dwarfout_resume_previous_source_file (0);
5405
5406 fputc ('\n', asm_out_file);
85595d1a 5407 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
340ccaab
TW
5408 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5409 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
85595d1a 5410 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5411 }
5412
5413 /* Generate the terminating entry for the .debug_pubnames section. */
5414
5415 fputc ('\n', asm_out_file);
85595d1a 5416 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab
TW
5417 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5418 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
85595d1a 5419 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5420
5421 /* Generate the terminating entries for the .debug_aranges section.
5422
5423 Note that we want to do this only *after* we have output the end
5424 labels (for the various program sections) which we are going to
5425 refer to here. This allows us to work around a bug in the m68k
5426 svr4 assembler. That assembler gives bogus assembly-time errors
5427 if (within any given section) you try to take the difference of
5428 two relocatable symbols, both of which are located within some
5429 other section, and if one (or both?) of the symbols involved is
5430 being forward-referenced. By generating the .debug_aranges
5431 entries at this late point in the assembly output, we skirt the
5432 issue simply by avoiding forward-references.
5433 */
5434
5435 fputc ('\n', asm_out_file);
85595d1a 5436 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
340ccaab
TW
5437
5438 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5439 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5440
5441 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5442 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5443
5444 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5445 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5446 DATA1_BEGIN_LABEL);
5447
5448 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5449 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5450 RODATA_BEGIN_LABEL);
5451
5452 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5453 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5454 RODATA1_BEGIN_LABEL);
5455
5456 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5457 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5458
5459 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5460 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5461
85595d1a 5462 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5463 }
5464}
5465
5466#endif /* DWARF_DEBUGGING_INFO */
This page took 0.619939 seconds and 5 git commands to generate.