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