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