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