]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/dwarf2out.c
(COMMENT_BEGIN): Delete.
[thirdparty/gcc.git] / gcc / dwarf2out.c
CommitLineData
a3f97cbb
JW
1/* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com). Derived from the
4 DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com).
5
6This file is part of GNU CC.
7
8GNU CC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
13GNU CC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU CC; see the file COPYING. If not, write to
20the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22#include "config.h"
23
9a666dda 24#ifdef DWARF2_DEBUGGING_INFO
a3f97cbb
JW
25#include <stdio.h>
26#include "dwarf2.h"
27#include "tree.h"
28#include "flags.h"
29#include "rtl.h"
30#include "hard-reg-set.h"
31#include "regs.h"
32#include "insn-config.h"
33#include "reload.h"
34#include "output.h"
35#include "defaults.h"
36
37/* #define NDEBUG 1 */
38#include "assert.h"
39#if defined(DWARF_TIMESTAMPS)
40#if defined(POSIX)
41#include <time.h>
42#else /* !defined(POSIX) */
43#include <sys/types.h>
44#if defined(__STDC__)
45extern time_t time (time_t *);
46#else /* !defined(__STDC__) */
47extern time_t time ();
48#endif /* !defined(__STDC__) */
49#endif /* !defined(POSIX) */
50#endif /* defined(DWARF_TIMESTAMPS) */
51
52extern char *getpwd ();
53extern char *index ();
54extern char *rindex ();
55
56/* IMPORTANT NOTE: Please see the file README.DWARF for important details
57 regarding the GNU implementation of DWARF. */
58
59/* NOTE: In the comments in this file, many references are made to
60 "Debugging Information Entries". This term is abbreviated as `DIE'
61 throughout the remainder of this file. */
62
63/* NOTE: The implementation of C++ support is unfinished. */
64
65#if defined(__GNUC__) && (NDEBUG == 1)
66#define inline static inline
67#else
68#define inline static
69#endif
70
71
72/* An internal representation of the DWARF output is built, and then
73 walked to generate the DWARF debugging info. The walk of the internal
74 representation is done after the entire program has been compiled.
75 The types below are used to describe the internal representation. */
76
77/* Each DIE may have a series of attribute/value pairs. Values
78 can take on several forms. The forms that are used in this
79 impelementation are listed below. */
80typedef enum
81 {
82 dw_val_class_addr,
83 dw_val_class_loc,
84 dw_val_class_const,
85 dw_val_class_unsigned_const,
86 dw_val_class_double_const,
87 dw_val_class_flag,
88 dw_val_class_die_ref,
89 dw_val_class_fde_ref,
90 dw_val_class_lbl_id,
91 dw_val_class_section_offset,
92 dw_val_class_str
93 }
94dw_val_class;
95
96/* Various DIE's use offsets relative to the beginning of the
97 .debug_info section to refer to each other. */
98typedef long int dw_offset;
99
100/* Define typedefs here to avoid circular dependencies. */
101typedef struct die_struct *dw_die_ref;
102typedef struct dw_attr_struct *dw_attr_ref;
103typedef struct dw_val_struct *dw_val_ref;
104typedef struct dw_line_info_struct *dw_line_info_ref;
e90b62db 105typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
a3f97cbb
JW
106typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
107typedef struct dw_cfi_struct *dw_cfi_ref;
108typedef struct dw_fde_struct *dw_fde_ref;
109typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
d291dd49
JM
110typedef struct pubname_struct *pubname_ref;
111typedef dw_die_ref *arange_ref;
a3f97cbb
JW
112
113/* Describe a double word constant value. */
114typedef struct dw_double_const_struct
115 {
116 unsigned long dw_dbl_hi;
117 unsigned long dw_dbl_low;
118 }
119dw_dbl_const;
120
121/* Each entry in the line_info_table maintains the file and
122 line nuber associated with the label generated for that
123 entry. The label gives the PC value associated with
124 the line number entry. */
125typedef struct dw_line_info_struct
126 {
127 unsigned long dw_file_num;
128 unsigned long dw_line_num;
129 }
130dw_line_info_entry;
131
e90b62db
JM
132/* Line information for functions in separate sections; each one gets its
133 own sequence. */
134typedef struct dw_separate_line_info_struct
135 {
136 unsigned long dw_file_num;
137 unsigned long dw_line_num;
138 unsigned long function;
139 }
140dw_separate_line_info_entry;
141
a3f97cbb
JW
142/* The dw_val_node describes an attibute's value, as it is
143 represnted internally. */
144typedef struct dw_val_struct
145 {
146 dw_val_class val_class;
147 union
148 {
149 char *val_addr;
150 dw_loc_descr_ref val_loc;
151 long int val_int;
152 long unsigned val_unsigned;
153 dw_dbl_const val_dbl_const;
154 dw_die_ref val_die_ref;
155 unsigned val_fde_index;
156 char *val_str;
157 char *val_lbl_id;
158 char *val_section;
159 unsigned char val_flag;
160 }
161 v;
162 }
163dw_val_node;
164
165/* Locations in memory are described using a sequence of stack machine
166 operations. */
167typedef struct dw_loc_descr_struct
168 {
169 dw_loc_descr_ref dw_loc_next;
170 enum dwarf_location_atom dw_loc_opc;
171 dw_val_node dw_loc_oprnd1;
172 dw_val_node dw_loc_oprnd2;
173 }
174dw_loc_descr_node;
175
176/* Each DIE attribute has a field specifying the attribute kind,
177 a link to the next attribute in the chain, and an attribute value.
178 Attributes are typically linked below the DIE they modify. */
179typedef struct dw_attr_struct
180 {
181 enum dwarf_attribute dw_attr;
182 dw_attr_ref dw_attr_next;
183 dw_val_node dw_attr_val;
184 }
185dw_attr_node;
186
187/* Call frames are described using a sequence of Call Frame
188 Information instructions. The register number, offset
189 and address fields are provided as possible operands;
190 their use is selected by the opcode field. */
191typedef union dw_cfi_oprnd_struct
192 {
193 unsigned long dw_cfi_reg_num;
194 long int dw_cfi_offset;
195 char *dw_cfi_addr;
196 }
197dw_cfi_oprnd;
198
199typedef struct dw_cfi_struct
200 {
201 dw_cfi_ref dw_cfi_next;
202 enum dwarf_call_frame_info dw_cfi_opc;
203 dw_cfi_oprnd dw_cfi_oprnd1;
204 dw_cfi_oprnd dw_cfi_oprnd2;
205 }
206dw_cfi_node;
207
208/* All call frame descriptions (FDE's) in the GCC generated DWARF
4b674448 209 refer to a single Common Information Entry (CIE), defined at
a3f97cbb
JW
210 the beginning of the .debug_frame section. This used of a single
211 CIE obviates the need to keep track of multiple CIE's
212 in the DWARF generation routines below. */
213typedef struct dw_fde_struct
214 {
215 unsigned long dw_fde_offset;
216 char *dw_fde_begin;
217 char *dw_fde_end_prolog;
218 char *dw_fde_begin_epilogue;
219 char *dw_fde_end;
220 dw_cfi_ref dw_fde_cfi;
221 }
222dw_fde_node;
223
224/* The Debugging Information Entry (DIE) structure */
225typedef struct die_struct
226 {
227 enum dwarf_tag die_tag;
228 dw_attr_ref die_attr;
229 dw_attr_ref die_attr_last;
230 dw_die_ref die_parent;
231 dw_die_ref die_child;
232 dw_die_ref die_child_last;
233 dw_die_ref die_sib;
234 dw_offset die_offset;
235 unsigned long die_abbrev;
236 }
237die_node;
238
d291dd49
JM
239/* The pubname structure */
240typedef struct pubname_struct
241{
242 dw_die_ref die;
243 char * name;
244}
245pubname_entry;
246
a3f97cbb
JW
247/* How to start an assembler comment. */
248#ifndef ASM_COMMENT_START
249#define ASM_COMMENT_START ";#"
250#endif
251
5c90448c
JM
252/* Define a macro which returns non-zero for a TYPE_DECL which was
253 implicitly generated for a tagged type.
254
255 Note that unlike the gcc front end (which generates a NULL named
256 TYPE_DECL node for each complete tagged type, each array type, and
257 each function type node created) the g++ front end generates a
258 _named_ TYPE_DECL node for each tagged type node created.
259 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
260 generate a DW_TAG_typedef DIE for them. */
261#define TYPE_DECL_IS_STUB(decl) \
262 (DECL_NAME (decl) == NULL \
263 || (DECL_ARTIFICIAL (decl) \
264 && is_tagged_type (TREE_TYPE (decl)) \
265 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
266
a3f97cbb
JW
267/* Information concerning the compilation unit's programming
268 language, and compiler version. */
269extern int flag_traditional;
270extern char *version_string;
271extern char *language_string;
272
273/* Maximum size (in bytes) of an artificially generated label. */
274#define MAX_ARTIFICIAL_LABEL_BYTES 30
275
276/* Make sure we know the sizes of the various types dwarf can describe. These
277 are only defaults. If the sizes are different for your target, you should
278 override these values by defining the appropriate symbols in your tm.h
279 file. */
280#ifndef CHAR_TYPE_SIZE
281#define CHAR_TYPE_SIZE BITS_PER_UNIT
282#endif
a3f97cbb 283#ifndef PTR_SIZE
a9d38797 284#define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
a3f97cbb
JW
285#endif
286
7e23cb16
JM
287/* The size in bytes of a DWARF field indicating an offset or length
288 relative to a debug info section, specified to be 4 bytes in the DWARF-2
289 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
290#ifndef DWARF_OFFSET_SIZE
291#define DWARF_OFFSET_SIZE 4
292#endif
293
9a666dda
JM
294#define DWARF_VERSION 2
295
a3f97cbb 296/* Fixed size portion of the DWARF compilation unit header. */
7e23cb16 297#define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
a3f97cbb
JW
298
299/* Fixed size portion of debugging line information prolog. */
300#define DWARF_LINE_PROLOG_HEADER_SIZE 5
301
302/* Fixed size portion of public names info. */
7e23cb16
JM
303#define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
304
305/* Round SIZE up to the nearest BOUNDARY. */
306#define DWARF_ROUND(SIZE,BOUNDARY) \
307 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
a3f97cbb
JW
308
309/* Fixed size portion of the address range info. */
7e23cb16
JM
310#define DWARF_ARANGES_HEADER_SIZE \
311 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
a3f97cbb 312
c8cc5c4a
JM
313/* Length of the target-dependent instructions in the
314 Common Information Entry (CIE).
315 ??? This should be computed when the frame info is genericized. */
316#ifdef MIPS_DEBUGGING_INFO
317#define DWARF_CIE_INSN_SIZE (2*3)
318#endif
319
320#ifndef DWARF_CIE_INSN_SIZE
321#define DWARF_CIE_INSN_SIZE 0
322#endif
323
324/* Fixed size portion of the CIE (including the length field). */
325#define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 5 + DWARF_CIE_INSN_SIZE)
a3f97cbb
JW
326
327/* Fixed size of the Common Information Entry in the call frame
7e23cb16
JM
328 information (.debug_frame) section rounded up to a word boundary. */
329#define DWARF_CIE_SIZE DWARF_ROUND (DWARF_CIE_HEADER_SIZE, PTR_SIZE)
a3f97cbb
JW
330
331/* Offsets recorded in opcodes are a multiple of this alignment factor. */
332#define DWARF_CIE_DATA_ALIGNMENT -4
333
334/* Fixed size portion of the FDE. */
7e23cb16 335#define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
a3f97cbb
JW
336
337/* Define the architecture-dependent minimum instruction length (in bytes).
338 In this implementation of DWARF, this field is used for information
339 purposes only. Since GCC generates assembly language, we have
340 no a priori knowledge of how many instruction bytes are generated
341 for each source line, and therefore can use only the DW_LNE_set_address
342 and DW_LNS_fixed_advance_pc line information commands. */
343#ifndef DWARF_LINE_MIN_INSTR_LENGTH
344#define DWARF_LINE_MIN_INSTR_LENGTH 4
345#endif
346
347/* Minimum line offset in a special line info. opcode.
348 This value was chosen to give a reasonable range of values. */
349#define DWARF_LINE_BASE -10
350
351/* First special line opcde - leave room for the standard opcodes. */
352#define DWARF_LINE_OPCODE_BASE 10
353
354/* Range of line offsets in a special line info. opcode. */
355#define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
356
357/* Flag that indicates the initial value of the is_stmt_start flag.
358 In the present implementation, we do not mark any lines as
359 the beginning of a source statement, because that information
360 is not made available by the GCC front-end. */
361#define DWARF_LINE_DEFAULT_IS_STMT_START 1
362
363/* This location is used by calc_die_sizes() to keep track
364 the offset of each DIE within the .debug_info section. */
365static unsigned long next_die_offset;
366
367/* This location is used by calc_fde_sizes() to keep track
368 the offset of each FDE within the .debug_frame section. */
369static unsigned long next_fde_offset;
370
371/* Record the root of the DIE's built for the current compilation unit. */
372dw_die_ref comp_unit_die;
373
374/* Pointer to an array of filenames referenced by this compilation unit. */
375static char **file_table;
376
377/* Total number of entries in the table (i.e. array) pointed to by
378 `file_table'. This is the *total* and includes both used and unused
379 slots. */
380static unsigned file_table_allocated;
381
382/* Number of entries in the file_table which are actually in use. */
383static unsigned file_table_in_use;
384
385/* Size (in elements) of increments by which we may expand the filename
386 table. */
387#define FILE_TABLE_INCREMENT 64
388
389/* Local pointer to the name of the main input file. Initialized in
9a666dda 390 dwarf2out_init. */
a3f97cbb
JW
391static char *primary_filename;
392
393/* For Dwarf output, we must assign lexical-blocks id numbers in the order in
394 which their beginnings are encountered. We output Dwarf debugging info
395 that refers to the beginnings and ends of the ranges of code for each
396 lexical block. The labels themselves are generated in final.c, which
397 assigns numbers to the blocks in the same way. */
398static unsigned next_block_number = 2;
399
a3f97cbb
JW
400/* A pointer to the base of a list of references to DIE's that describe
401 types. The table is indexed by TYPE_UID() which is a unique number,
402 indentifying each type. */
403static dw_die_ref *type_die_table;
404
405/* Number of elements currently allocated for type_die_table. */
406static unsigned type_die_table_allocated;
407
408/* Number of elements in type_die_table currently in use. */
409static unsigned type_die_table_in_use;
410
411/* Size (in elements) of increments by which we may expand the
412 type_die_table. */
413#define TYPE_DIE_TABLE_INCREMENT 4096
414
415/* A pointer to the base of a table of references to DIE's that describe
416 declarations. The table is indexed by DECL_UID() which is a unique
417 number, indentifying each decl. */
418static dw_die_ref *decl_die_table;
419
420/* Number of elements currently allocated for the decl_die_table. */
421static unsigned decl_die_table_allocated;
422
423/* Number of elements in decl_die_table currently in use. */
424static unsigned decl_die_table_in_use;
425
426/* Size (in elements) of increments by which we may expand the
427 decl_die_table. */
428#define DECL_DIE_TABLE_INCREMENT 256
429
430/* A pointer to the base of a table of references to declaration
431 scopes. This table is a display which tracks the nesting
432 of declaration scopes at the current scope and containing
433 scopes. This table is used to find the proper place to
434 define type declaration DIE's. */
435static tree *decl_scope_table;
436
437/* Number of elements currently allocated for the decl_scope_table. */
438static unsigned decl_scope_table_allocated;
439
440/* Current level of nesting of declataion scopes. */
441static unsigned decl_scope_depth;
442
443/* Size (in elements) of increments by which we may expand the
444 decl_scope_table. */
445#define DECL_SCOPE_TABLE_INCREMENT 64
446
447/* A pointer to the base of a list of references to DIE's that
448 are uniquely identified by their tag, presence/absence of
449 children DIE's, and list of attribute/value pairs. */
450static dw_die_ref *abbrev_die_table;
451
452/* Number of elements currently allocated for abbrev_die_table. */
453static unsigned abbrev_die_table_allocated;
454
455/* Number of elements in type_die_table currently in use. */
456static unsigned abbrev_die_table_in_use;
457
458/* Size (in elements) of increments by which we may expand the
459 abbrev_die_table. */
460#define ABBREV_DIE_TABLE_INCREMENT 256
461
462/* A pointer to the base of a table that contains line information
e90b62db 463 for each source code line in .text in the compilation unit. */
a3f97cbb
JW
464static dw_line_info_ref line_info_table;
465
466/* Number of elements currently allocated for line_info_table. */
467static unsigned line_info_table_allocated;
468
e90b62db
JM
469/* Number of elements in separate_line_info_table currently in use. */
470static unsigned separate_line_info_table_in_use;
471
472/* A pointer to the base of a table that contains line information
473 for each source code line outside of .text in the compilation unit. */
474static dw_separate_line_info_ref separate_line_info_table;
475
476/* Number of elements currently allocated for separate_line_info_table. */
477static unsigned separate_line_info_table_allocated;
478
a3f97cbb
JW
479/* Number of elements in line_info_table currently in use. */
480static unsigned line_info_table_in_use;
481
482/* Size (in elements) of increments by which we may expand the
483 line_info_table. */
484#define LINE_INFO_TABLE_INCREMENT 1024
485
a3f97cbb
JW
486/* A pointer to the base of a table that contains frame description
487 information for each routine. */
488static dw_fde_ref fde_table;
489
490/* Number of elements currently allocated for fde_table. */
491static unsigned fde_table_allocated;
492
493/* Number of elements in fde_table currently in use. */
494static unsigned fde_table_in_use;
495
496/* Size (in elements) of increments by which we may expand the
497 fde_table. */
498#define FDE_TABLE_INCREMENT 256
499
d291dd49
JM
500/* A pointer to the base of a table that contains a list of publicly
501 accessible names. */
502static pubname_ref pubname_table;
503
504/* Number of elements currently allocated for pubname_table. */
505static unsigned pubname_table_allocated;
506
507/* Number of elements in pubname_table currently in use. */
508static unsigned pubname_table_in_use;
509
510/* Size (in elements) of increments by which we may expand the
511 pubname_table. */
512#define PUBNAME_TABLE_INCREMENT 64
513
514/* A pointer to the base of a table that contains a list of publicly
515 accessible names. */
516static arange_ref arange_table;
517
518/* Number of elements currently allocated for arange_table. */
519static unsigned arange_table_allocated;
520
521/* Number of elements in arange_table currently in use. */
522static unsigned arange_table_in_use;
523
524/* Size (in elements) of increments by which we may expand the
525 arange_table. */
526#define ARANGE_TABLE_INCREMENT 64
527
a3f97cbb
JW
528/* The number of the current function definition for which debugging
529 information is being generated. These numbers range from 1 up to the
530 maximum number of function definitions contained within the current
531 compilation unit. These numbers are used to create unique label id's
532 unique to each function definition. */
533static unsigned current_funcdef_number = 1;
534
535/* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
536 attribute that accelerates the lookup of the FDE associated
537 with the subprogram. This variable holds the table index of the FDE
538 associated with the current function (body) definition. */
539static unsigned current_funcdef_fde;
540
541/* Record the size of the frame, so that the DW_AT_frame_base
542 attribute can be set properly in gen_subprogram_die. */
543static long int current_funcdef_frame_size = 0;
544
7e23cb16
JM
545/* Record whether the function being analyzed contains inlined functions. */
546static int current_function_has_inlines;
547static int comp_unit_has_inlines;
548
a3f97cbb
JW
549/* A pointer to the ..._DECL node which we have most recently been working
550 on. We keep this around just in case something about it looks screwy and
551 we want to tell the user what the source coordinates for the actual
552 declaration are. */
553static tree dwarf_last_decl;
554
a3f97cbb
JW
555/* Forward declarations for functions defined in this file. */
556static void gen_type_die ();
557static void add_type_attribute ();
558static void decls_for_scope ();
559static void gen_decl_die ();
560static unsigned lookup_filename ();
7e23cb16 561static int constant_size PROTO((long unsigned));
f37230f0 562static enum dwarf_form value_format PROTO((dw_val_ref));
a3f97cbb
JW
563
564/* Definitions of defaults for assembler-dependent names of various
565 pseudo-ops and section names.
566 Theses may be overridden in the tm.h file (if necessary) for a particular
567 assembler. */
568#ifndef UNALIGNED_SHORT_ASM_OP
569#define UNALIGNED_SHORT_ASM_OP ".2byte"
570#endif
571#ifndef UNALIGNED_INT_ASM_OP
572#define UNALIGNED_INT_ASM_OP ".4byte"
573#endif
7e23cb16
JM
574#ifndef UNALIGNED_DOUBLE_INT_ASM_OP
575#define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
576#endif
a3f97cbb
JW
577#ifndef ASM_BYTE_OP
578#define ASM_BYTE_OP ".byte"
579#endif
580
7e23cb16
JM
581#ifndef UNALIGNED_OFFSET_ASM_OP
582#define UNALIGNED_OFFSET_ASM_OP \
583 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
584#endif
585
586#ifndef UNALIGNED_WORD_ASM_OP
587#define UNALIGNED_WORD_ASM_OP \
588 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
589#endif
590
591/* Data and reference forms for relocatable data. */
592#define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
593#define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
594
a3f97cbb
JW
595/* Pseudo-op for defining a new section. */
596#ifndef SECTION_ASM_OP
597#define SECTION_ASM_OP ".section"
598#endif
599
600/* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
601 print the SECTION_ASM_OP and the section name. The default here works for
602 almost all svr4 assemblers, except for the sparc, where the section name
603 must be enclosed in double quotes. (See sparcv4.h). */
604#ifndef SECTION_FORMAT
605#define SECTION_FORMAT "\t%s\t%s\n"
606#endif
607
608/* Section names used to hold DWARF debugging information. */
609#ifndef DEBUG_SECTION
610#define DEBUG_SECTION ".debug_info"
611#endif
612#ifndef ABBREV_SECTION
613#define ABBREV_SECTION ".debug_abbrev"
614#endif
615#ifndef ARANGES_SECTION
616#define ARANGES_SECTION ".debug_aranges"
617#endif
618#ifndef DW_MACINFO_SECTION
619#define DW_MACINFO_SECTION ".debug_macinfo"
620#endif
621#ifndef FRAME_SECTION
622#define FRAME_SECTION ".debug_frame"
623#endif
624#ifndef LINE_SECTION
625#define LINE_SECTION ".debug_line"
626#endif
627#ifndef LOC_SECTION
628#define LOC_SECTION ".debug_loc"
629#endif
630#ifndef PUBNAMES_SECTION
631#define PUBNAMES_SECTION ".debug_pubnames"
632#endif
633#ifndef STR_SECTION
634#define STR_SECTION ".debug_str"
635#endif
636
637/* Standerd ELF section names for compiled code and data. */
638#ifndef TEXT_SECTION
639#define TEXT_SECTION ".text"
640#endif
641#ifndef DATA_SECTION
642#define DATA_SECTION ".data"
643#endif
a3f97cbb
JW
644#ifndef BSS_SECTION
645#define BSS_SECTION ".bss"
646#endif
647
648
649/* Definitions of defaults for formats and names of various special
650 (artificial) labels which may be generated within this file (when the -g
651 options is used and DWARF_DEBUGGING_INFO is in effect.
652 If necessary, these may be overridden from within the tm.h file, but
5c90448c
JM
653 typically, overriding these defaults is unnecessary. */
654
655char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
656
a3f97cbb 657#ifndef TEXT_END_LABEL
5c90448c 658#define TEXT_END_LABEL "Letext"
a3f97cbb
JW
659#endif
660#ifndef DATA_END_LABEL
5c90448c 661#define DATA_END_LABEL "Ledata"
a3f97cbb
JW
662#endif
663#ifndef BSS_END_LABEL
5c90448c 664#define BSS_END_LABEL "Lebss"
a3f97cbb
JW
665#endif
666#ifndef INSN_LABEL_FMT
5c90448c 667#define INSN_LABEL_FMT "LI%u_"
a3f97cbb 668#endif
5c90448c
JM
669#ifndef BLOCK_BEGIN_LABEL
670#define BLOCK_BEGIN_LABEL "LBB"
a3f97cbb 671#endif
5c90448c
JM
672#ifndef BLOCK_END_LABEL
673#define BLOCK_END_LABEL "LBE"
a3f97cbb 674#endif
5c90448c
JM
675#ifndef BODY_BEGIN_LABEL
676#define BODY_BEGIN_LABEL "Lbb"
a3f97cbb 677#endif
5c90448c
JM
678#ifndef BODY_END_LABEL
679#define BODY_END_LABEL "Lbe"
d291dd49 680#endif
5c90448c
JM
681#ifndef FUNC_BEGIN_LABEL
682#define FUNC_BEGIN_LABEL "LFB"
a3f97cbb 683#endif
5c90448c
JM
684#ifndef FUNC_END_LABEL
685#define FUNC_END_LABEL "LFE"
a3f97cbb 686#endif
5c90448c
JM
687#ifndef LINE_CODE_LABEL
688#define LINE_CODE_LABEL "LM"
e90b62db 689#endif
5c90448c
JM
690#ifndef SEPARATE_LINE_CODE_LABEL
691#define SEPARATE_LINE_CODE_LABEL "LSM"
a3f97cbb
JW
692#endif
693
a3f97cbb
JW
694/* Definitions of defaults for various types of primitive assembly language
695 output operations. These may be overridden from within the tm.h file,
696 but typically, that is unecessary. */
697#ifndef ASM_OUTPUT_SECTION
698#define ASM_OUTPUT_SECTION(FILE, SECTION) \
699 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
700#endif
701
702#ifndef ASM_OUTPUT_DWARF_DELTA2
703#define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
704 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
705 assemble_name (FILE, LABEL1); \
706 fprintf (FILE, "-"); \
707 assemble_name (FILE, LABEL2); \
708 } while (0)
709#endif
710
711#ifndef ASM_OUTPUT_DWARF_DELTA4
712#define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
713 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
714 assemble_name (FILE, LABEL1); \
715 fprintf (FILE, "-"); \
716 assemble_name (FILE, LABEL2); \
717 } while (0)
718#endif
719
7e23cb16
JM
720#ifndef ASM_OUTPUT_DWARF_DELTA
721#define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
722 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
723 assemble_name (FILE, LABEL1); \
724 fprintf (FILE, "-"); \
725 assemble_name (FILE, LABEL2); \
726 } while (0)
727#endif
728
729#ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
730#define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
731 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
732 assemble_name (FILE, LABEL1); \
733 fprintf (FILE, "-"); \
734 assemble_name (FILE, LABEL2); \
735 } while (0)
736#endif
737
a3f97cbb
JW
738#ifndef ASM_OUTPUT_DWARF_ADDR
739#define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
7e23cb16 740 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
a3f97cbb
JW
741 assemble_name (FILE, LABEL); \
742 } while (0)
743#endif
744
745#ifndef ASM_OUTPUT_DWARF_ADDR_CONST
746#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
7e23cb16
JM
747 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
748#endif
749
750#ifndef ASM_OUTPUT_DWARF_OFFSET
751#define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
752 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
753 assemble_name (FILE, LABEL); \
754 } while (0)
a3f97cbb
JW
755#endif
756
757#ifndef ASM_OUTPUT_DWARF_DATA1
758#define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
759 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
760#endif
761
762#ifndef ASM_OUTPUT_DWARF_DATA2
763#define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
764 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
765#endif
766
767#ifndef ASM_OUTPUT_DWARF_DATA4
768#define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
769 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
770#endif
771
7e23cb16
JM
772#ifndef ASM_OUTPUT_DWARF_DATA
773#define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
774 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
775 (unsigned long) VALUE)
776#endif
777
778#ifndef ASM_OUTPUT_DWARF_ADDR_DATA
779#define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
780 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
781 (unsigned long) VALUE)
782#endif
783
a3f97cbb
JW
784#ifndef ASM_OUTPUT_DWARF_DATA8
785#define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
786 do { \
787 if (WORDS_BIG_ENDIAN) \
788 { \
789 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
790 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
791 } \
792 else \
793 { \
794 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
795 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
796 } \
797 } while (0)
798#endif
799
800/* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
801 newline is produced. When flag_verbose_asm is asserted, we add commnetary
802 at the end of the line, so we must avoid output of a newline here. */
803#ifndef ASM_OUTPUT_DWARF_STRING
804#define ASM_OUTPUT_DWARF_STRING(FILE,P) \
805 do { \
806 register int slen = strlen(P); \
807 register char *p = (P); \
808 register int i; \
809 fprintf (FILE, "\t.ascii \""); \
810 for (i = 0; i < slen; i++) \
811 { \
812 register int c = p[i]; \
813 if (c == '\"' || c == '\\') \
814 putc ('\\', FILE); \
815 if (c >= ' ' && c < 0177) \
816 putc (c, FILE); \
817 else \
818 { \
819 fprintf (FILE, "\\%o", c); \
820 } \
821 } \
822 fprintf (FILE, "\\0\""); \
823 } \
824 while (0)
825#endif
826
827/* Convert a reference to the assembler name of a C-level name. This
828 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
829 a string rather than writing to a file. */
830#ifndef ASM_NAME_TO_STRING
831#define ASM_NAME_TO_STRING(STR, NAME) \
832 do { \
833 if ((NAME)[0] == '*') \
834 strcpy (STR, NAME+1); \
835 else \
836 strcpy (STR, NAME); \
837 } \
838 while (0)
839#endif
840
c8cc5c4a
JM
841/* The DWARF 2 CFA column which tracks the return address. Normally this
842 is the first column after all of the hard registers. */
843#ifndef DWARF_FRAME_RETURN_COLUMN
844#define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
845#endif
846
847/* The mapping from gcc register number to DWARF 2 CFA column number. By
848 default, we provide columns for all registers after the CFA column. */
849#ifndef DWARF_FRAME_REGNUM
850#define DWARF_FRAME_REGNUM(REG) (DBX_REGISTER_NUMBER (REG) + 1)
851#endif
a3f97cbb
JW
852\f
853/************************ general utility functions **************************/
854
855/* Return a pointer to a copy of the section string name 's' with all
856 attributes stripped off. */
857inline char *
858stripattributes (s)
859 register char *s;
860{
861 register char *stripped, *p;
862 stripped = xstrdup (s);
863 p = stripped;
864 while (*p && *p != ',')
865 p++;
866 *p = '\0';
867 return stripped;
868}
869
870/* Convert an integer constant expression into assembler syntax.
871 Addition and subtraction are the only arithmetic
872 that may appear in these expressions. This is an adaptation
873 of output_addr_const() in final.c. Here, the target of the
874 conversion is a string buffer. We can't use output_addr_const
875 directly, because it writes to a file. */
876static void
877addr_const_to_string (str, x)
878 char *str;
879 rtx x;
880{
881 char buf1[256];
882 char buf2[256];
883
884restart:
885 str[0] = '\0';
886 switch (GET_CODE (x))
887 {
888 case PC:
889 if (flag_pic)
890 strcat (str, ",");
891 else
892 abort ();
893 break;
894
895 case SYMBOL_REF:
896 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
897 strcat (str, buf1);
898 break;
899
900 case LABEL_REF:
901 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
902 ASM_NAME_TO_STRING (buf2, buf1);
903 strcat (str, buf2);
904 break;
905
906 case CODE_LABEL:
907 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
908 ASM_NAME_TO_STRING (buf2, buf1);
909 strcat (str, buf2);
910 break;
911
912 case CONST_INT:
913 sprintf (buf1,
914#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
915 "%d",
916#else
917 "%ld",
918#endif
919 INTVAL (x));
920 strcat (str, buf1);
921 break;
922
923 case CONST:
924 /* This used to output parentheses around the expression, but that does
925 not work on the 386 (either ATT or BSD assembler). */
926 addr_const_to_string (buf1, XEXP (x, 0));
927 strcat (str, buf1);
928 break;
929
930 case CONST_DOUBLE:
931 if (GET_MODE (x) == VOIDmode)
932 {
933 /* We can use %d if the number is one word and positive. */
934 if (CONST_DOUBLE_HIGH (x))
935 sprintf (buf1,
936#if HOST_BITS_PER_WIDE_INT == 64
937#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
938 "0x%lx%016lx",
939#else
940 "0x%x%016x",
941#endif
942#else
943#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
944 "0x%lx%08lx",
945#else
946 "0x%x%08x",
947#endif
948#endif
949 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
950 else if (CONST_DOUBLE_LOW (x) < 0)
951 sprintf (buf1,
952#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
953 "0x%x",
954#else
955 "0x%lx",
956#endif
957 CONST_DOUBLE_LOW (x));
958 else
959 sprintf (buf1,
960#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
961 "%d",
962#else
963 "%ld",
964#endif
965 CONST_DOUBLE_LOW (x));
966 strcat (str, buf1);
967 }
968 else
969 /* We can't handle floating point constants; PRINT_OPERAND must
970 handle them. */
971 output_operand_lossage ("floating constant misused");
972 break;
973
974 case PLUS:
975 /* Some assemblers need integer constants to appear last (eg masm). */
976 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
977 {
978 addr_const_to_string (buf1, XEXP (x, 1));
979 strcat (str, buf1);
980 if (INTVAL (XEXP (x, 0)) >= 0)
981 strcat (str, "+");
982 addr_const_to_string (buf1, XEXP (x, 0));
983 strcat (str, buf1);
984 }
985 else
986 {
987 addr_const_to_string (buf1, XEXP (x, 0));
988 strcat (str, buf1);
bdb669cb 989 if (INTVAL (XEXP (x, 1)) >= 0)
a3f97cbb
JW
990 strcat (str, "+");
991 addr_const_to_string (buf1, XEXP (x, 1));
bdb669cb 992 strcat (str, buf1);
a3f97cbb
JW
993 }
994 break;
995
996 case MINUS:
997 /* Avoid outputting things like x-x or x+5-x, since some assemblers
998 can't handle that. */
999 x = simplify_subtraction (x);
1000 if (GET_CODE (x) != MINUS)
1001 goto restart;
1002
1003 addr_const_to_string (buf1, XEXP (x, 0));
1004 strcat (str, buf1);
1005 strcat (str, "-");
1006 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1007 && INTVAL (XEXP (x, 1)) < 0)
1008 {
1009 strcat (str, ASM_OPEN_PAREN);
1010 addr_const_to_string (buf1, XEXP (x, 1));
1011 strcat (str, buf1);
1012 strcat (str, ASM_CLOSE_PAREN);
1013 }
1014 else
1015 {
1016 addr_const_to_string (buf1, XEXP (x, 1));
1017 strcat (str, buf1);
1018 }
1019 break;
1020
1021 case ZERO_EXTEND:
1022 case SIGN_EXTEND:
1023 addr_const_to_string (buf1, XEXP (x, 0));
1024 strcat (str, buf1);
1025 break;
1026
1027 default:
1028 output_operand_lossage ("invalid expression as operand");
1029 }
1030}
1031
1032/* Convert an address constant to a string, and return a pointer to
1033 a copy of the result, located on the heap. */
1034static char *
1035addr_to_string (x)
1036 rtx x;
1037{
1038 char buf[1024];
1039 addr_const_to_string (buf, x);
1040 return xstrdup (buf);
1041}
1042
1043/* Test if rtl node points to a psuedo register. */
1044inline int
1045is_pseudo_reg (rtl)
1046 register rtx rtl;
1047{
1048 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1049 || ((GET_CODE (rtl) == SUBREG)
1050 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1051}
1052
1053
1054/* Return a reference to a type, with its const and volatile qualifiers
1055 removed. */
1056inline tree
1057type_main_variant (type)
1058 register tree type;
1059{
1060 type = TYPE_MAIN_VARIANT (type);
1061
1062 /* There really should be only one main variant among any group of variants
1063 of a given type (and all of the MAIN_VARIANT values for all members of
1064 the group should point to that one type) but sometimes the C front-end
1065 messes this up for array types, so we work around that bug here. */
1066 if (TREE_CODE (type) == ARRAY_TYPE)
1067 {
1068 while (type != TYPE_MAIN_VARIANT (type))
1069 type = TYPE_MAIN_VARIANT (type);
1070 }
1071 return type;
1072}
1073
1074/* Return non-zero if the given type node represents a tagged type. */
1075inline int
1076is_tagged_type (type)
1077 register tree type;
1078{
1079 register enum tree_code code = TREE_CODE (type);
1080
1081 return (code == RECORD_TYPE || code == UNION_TYPE
1082 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1083}
1084
1085/* Convert a DIE tag into its string name. */
1086static char *
1087dwarf_tag_name (tag)
1088 register unsigned tag;
1089{
1090 switch (tag)
1091 {
1092 case DW_TAG_padding:
1093 return "DW_TAG_padding";
1094 case DW_TAG_array_type:
1095 return "DW_TAG_array_type";
1096 case DW_TAG_class_type:
1097 return "DW_TAG_class_type";
1098 case DW_TAG_entry_point:
1099 return "DW_TAG_entry_point";
1100 case DW_TAG_enumeration_type:
1101 return "DW_TAG_enumeration_type";
1102 case DW_TAG_formal_parameter:
1103 return "DW_TAG_formal_parameter";
1104 case DW_TAG_imported_declaration:
1105 return "DW_TAG_imported_declaration";
1106 case DW_TAG_label:
1107 return "DW_TAG_label";
1108 case DW_TAG_lexical_block:
1109 return "DW_TAG_lexical_block";
1110 case DW_TAG_member:
1111 return "DW_TAG_member";
1112 case DW_TAG_pointer_type:
1113 return "DW_TAG_pointer_type";
1114 case DW_TAG_reference_type:
1115 return "DW_TAG_reference_type";
1116 case DW_TAG_compile_unit:
1117 return "DW_TAG_compile_unit";
1118 case DW_TAG_string_type:
1119 return "DW_TAG_string_type";
1120 case DW_TAG_structure_type:
1121 return "DW_TAG_structure_type";
1122 case DW_TAG_subroutine_type:
1123 return "DW_TAG_subroutine_type";
1124 case DW_TAG_typedef:
1125 return "DW_TAG_typedef";
1126 case DW_TAG_union_type:
1127 return "DW_TAG_union_type";
1128 case DW_TAG_unspecified_parameters:
1129 return "DW_TAG_unspecified_parameters";
1130 case DW_TAG_variant:
1131 return "DW_TAG_variant";
1132 case DW_TAG_common_block:
1133 return "DW_TAG_common_block";
1134 case DW_TAG_common_inclusion:
1135 return "DW_TAG_common_inclusion";
1136 case DW_TAG_inheritance:
1137 return "DW_TAG_inheritance";
1138 case DW_TAG_inlined_subroutine:
1139 return "DW_TAG_inlined_subroutine";
1140 case DW_TAG_module:
1141 return "DW_TAG_module";
1142 case DW_TAG_ptr_to_member_type:
1143 return "DW_TAG_ptr_to_member_type";
1144 case DW_TAG_set_type:
1145 return "DW_TAG_set_type";
1146 case DW_TAG_subrange_type:
1147 return "DW_TAG_subrange_type";
1148 case DW_TAG_with_stmt:
1149 return "DW_TAG_with_stmt";
1150 case DW_TAG_access_declaration:
1151 return "DW_TAG_access_declaration";
1152 case DW_TAG_base_type:
1153 return "DW_TAG_base_type";
1154 case DW_TAG_catch_block:
1155 return "DW_TAG_catch_block";
1156 case DW_TAG_const_type:
1157 return "DW_TAG_const_type";
1158 case DW_TAG_constant:
1159 return "DW_TAG_constant";
1160 case DW_TAG_enumerator:
1161 return "DW_TAG_enumerator";
1162 case DW_TAG_file_type:
1163 return "DW_TAG_file_type";
1164 case DW_TAG_friend:
1165 return "DW_TAG_friend";
1166 case DW_TAG_namelist:
1167 return "DW_TAG_namelist";
1168 case DW_TAG_namelist_item:
1169 return "DW_TAG_namelist_item";
1170 case DW_TAG_packed_type:
1171 return "DW_TAG_packed_type";
1172 case DW_TAG_subprogram:
1173 return "DW_TAG_subprogram";
1174 case DW_TAG_template_type_param:
1175 return "DW_TAG_template_type_param";
1176 case DW_TAG_template_value_param:
1177 return "DW_TAG_template_value_param";
1178 case DW_TAG_thrown_type:
1179 return "DW_TAG_thrown_type";
1180 case DW_TAG_try_block:
1181 return "DW_TAG_try_block";
1182 case DW_TAG_variant_part:
1183 return "DW_TAG_variant_part";
1184 case DW_TAG_variable:
1185 return "DW_TAG_variable";
1186 case DW_TAG_volatile_type:
1187 return "DW_TAG_volatile_type";
1188 case DW_TAG_MIPS_loop:
1189 return "DW_TAG_MIPS_loop";
1190 case DW_TAG_format_label:
1191 return "DW_TAG_format_label";
1192 case DW_TAG_function_template:
1193 return "DW_TAG_function_template";
1194 case DW_TAG_class_template:
1195 return "DW_TAG_class_template";
1196 default:
1197 return "DW_TAG_<unknown>";
1198 }
1199}
1200
1201/* Convert a DWARF attribute code into its string name. */
1202static char *
1203dwarf_attr_name (attr)
1204 register unsigned attr;
1205{
1206 switch (attr)
1207 {
1208 case DW_AT_sibling:
1209 return "DW_AT_sibling";
1210 case DW_AT_location:
1211 return "DW_AT_location";
1212 case DW_AT_name:
1213 return "DW_AT_name";
1214 case DW_AT_ordering:
1215 return "DW_AT_ordering";
1216 case DW_AT_subscr_data:
1217 return "DW_AT_subscr_data";
1218 case DW_AT_byte_size:
1219 return "DW_AT_byte_size";
1220 case DW_AT_bit_offset:
1221 return "DW_AT_bit_offset";
1222 case DW_AT_bit_size:
1223 return "DW_AT_bit_size";
1224 case DW_AT_element_list:
1225 return "DW_AT_element_list";
1226 case DW_AT_stmt_list:
1227 return "DW_AT_stmt_list";
1228 case DW_AT_low_pc:
1229 return "DW_AT_low_pc";
1230 case DW_AT_high_pc:
1231 return "DW_AT_high_pc";
1232 case DW_AT_language:
1233 return "DW_AT_language";
1234 case DW_AT_member:
1235 return "DW_AT_member";
1236 case DW_AT_discr:
1237 return "DW_AT_discr";
1238 case DW_AT_discr_value:
1239 return "DW_AT_discr_value";
1240 case DW_AT_visibility:
1241 return "DW_AT_visibility";
1242 case DW_AT_import:
1243 return "DW_AT_import";
1244 case DW_AT_string_length:
1245 return "DW_AT_string_length";
1246 case DW_AT_common_reference:
1247 return "DW_AT_common_reference";
1248 case DW_AT_comp_dir:
1249 return "DW_AT_comp_dir";
1250 case DW_AT_const_value:
1251 return "DW_AT_const_value";
1252 case DW_AT_containing_type:
1253 return "DW_AT_containing_type";
1254 case DW_AT_default_value:
1255 return "DW_AT_default_value";
1256 case DW_AT_inline:
1257 return "DW_AT_inline";
1258 case DW_AT_is_optional:
1259 return "DW_AT_is_optional";
1260 case DW_AT_lower_bound:
1261 return "DW_AT_lower_bound";
1262 case DW_AT_producer:
1263 return "DW_AT_producer";
1264 case DW_AT_prototyped:
1265 return "DW_AT_prototyped";
1266 case DW_AT_return_addr:
1267 return "DW_AT_return_addr";
1268 case DW_AT_start_scope:
1269 return "DW_AT_start_scope";
1270 case DW_AT_stride_size:
1271 return "DW_AT_stride_size";
1272 case DW_AT_upper_bound:
1273 return "DW_AT_upper_bound";
1274 case DW_AT_abstract_origin:
1275 return "DW_AT_abstract_origin";
1276 case DW_AT_accessibility:
1277 return "DW_AT_accessibility";
1278 case DW_AT_address_class:
1279 return "DW_AT_address_class";
1280 case DW_AT_artificial:
1281 return "DW_AT_artificial";
1282 case DW_AT_base_types:
1283 return "DW_AT_base_types";
1284 case DW_AT_calling_convention:
1285 return "DW_AT_calling_convention";
1286 case DW_AT_count:
1287 return "DW_AT_count";
1288 case DW_AT_data_member_location:
1289 return "DW_AT_data_member_location";
1290 case DW_AT_decl_column:
1291 return "DW_AT_decl_column";
1292 case DW_AT_decl_file:
1293 return "DW_AT_decl_file";
1294 case DW_AT_decl_line:
1295 return "DW_AT_decl_line";
1296 case DW_AT_declaration:
1297 return "DW_AT_declaration";
1298 case DW_AT_discr_list:
1299 return "DW_AT_discr_list";
1300 case DW_AT_encoding:
1301 return "DW_AT_encoding";
1302 case DW_AT_external:
1303 return "DW_AT_external";
1304 case DW_AT_frame_base:
1305 return "DW_AT_frame_base";
1306 case DW_AT_friend:
1307 return "DW_AT_friend";
1308 case DW_AT_identifier_case:
1309 return "DW_AT_identifier_case";
1310 case DW_AT_macro_info:
1311 return "DW_AT_macro_info";
1312 case DW_AT_namelist_items:
1313 return "DW_AT_namelist_items";
1314 case DW_AT_priority:
1315 return "DW_AT_priority";
1316 case DW_AT_segment:
1317 return "DW_AT_segment";
1318 case DW_AT_specification:
1319 return "DW_AT_specification";
1320 case DW_AT_static_link:
1321 return "DW_AT_static_link";
1322 case DW_AT_type:
1323 return "DW_AT_type";
1324 case DW_AT_use_location:
1325 return "DW_AT_use_location";
1326 case DW_AT_variable_parameter:
1327 return "DW_AT_variable_parameter";
1328 case DW_AT_virtuality:
1329 return "DW_AT_virtuality";
1330 case DW_AT_vtable_elem_location:
1331 return "DW_AT_vtable_elem_location";
1332
a3f97cbb
JW
1333 case DW_AT_MIPS_fde:
1334 return "DW_AT_MIPS_fde";
1335 case DW_AT_MIPS_loop_begin:
1336 return "DW_AT_MIPS_loop_begin";
1337 case DW_AT_MIPS_tail_loop_begin:
1338 return "DW_AT_MIPS_tail_loop_begin";
1339 case DW_AT_MIPS_epilog_begin:
1340 return "DW_AT_MIPS_epilog_begin";
1341 case DW_AT_MIPS_loop_unroll_factor:
1342 return "DW_AT_MIPS_loop_unroll_factor";
1343 case DW_AT_MIPS_software_pipeline_depth:
1344 return "DW_AT_MIPS_software_pipeline_depth";
1345 case DW_AT_MIPS_linkage_name:
1346 return "DW_AT_MIPS_linkage_name";
7e23cb16
JM
1347 case DW_AT_MIPS_stride:
1348 return "DW_AT_MIPS_stride";
1349 case DW_AT_MIPS_abstract_name:
1350 return "DW_AT_MIPS_abstract_name";
1351 case DW_AT_MIPS_clone_origin:
1352 return "DW_AT_MIPS_clone_origin";
1353 case DW_AT_MIPS_has_inlines:
1354 return "DW_AT_MIPS_has_inlines";
a3f97cbb
JW
1355
1356 case DW_AT_sf_names:
1357 return "DW_AT_sf_names";
1358 case DW_AT_src_info:
1359 return "DW_AT_src_info";
1360 case DW_AT_mac_info:
1361 return "DW_AT_mac_info";
1362 case DW_AT_src_coords:
1363 return "DW_AT_src_coords";
1364 case DW_AT_body_begin:
1365 return "DW_AT_body_begin";
1366 case DW_AT_body_end:
1367 return "DW_AT_body_end";
1368 default:
1369 return "DW_AT_<unknown>";
1370 }
1371}
1372
1373/* Convert a DWARF value form code into its string name. */
1374static char *
1375dwarf_form_name (form)
1376 register unsigned form;
1377{
1378 switch (form)
1379 {
1380 case DW_FORM_addr:
1381 return "DW_FORM_addr";
1382 case DW_FORM_block2:
1383 return "DW_FORM_block2";
1384 case DW_FORM_block4:
1385 return "DW_FORM_block4";
1386 case DW_FORM_data2:
1387 return "DW_FORM_data2";
1388 case DW_FORM_data4:
1389 return "DW_FORM_data4";
1390 case DW_FORM_data8:
1391 return "DW_FORM_data8";
1392 case DW_FORM_string:
1393 return "DW_FORM_string";
1394 case DW_FORM_block:
1395 return "DW_FORM_block";
1396 case DW_FORM_block1:
1397 return "DW_FORM_block1";
1398 case DW_FORM_data1:
1399 return "DW_FORM_data1";
1400 case DW_FORM_flag:
1401 return "DW_FORM_flag";
1402 case DW_FORM_sdata:
1403 return "DW_FORM_sdata";
1404 case DW_FORM_strp:
1405 return "DW_FORM_strp";
1406 case DW_FORM_udata:
1407 return "DW_FORM_udata";
1408 case DW_FORM_ref_addr:
1409 return "DW_FORM_ref_addr";
1410 case DW_FORM_ref1:
1411 return "DW_FORM_ref1";
1412 case DW_FORM_ref2:
1413 return "DW_FORM_ref2";
1414 case DW_FORM_ref4:
1415 return "DW_FORM_ref4";
1416 case DW_FORM_ref8:
1417 return "DW_FORM_ref8";
1418 case DW_FORM_ref_udata:
1419 return "DW_FORM_ref_udata";
1420 case DW_FORM_indirect:
1421 return "DW_FORM_indirect";
1422 default:
1423 return "DW_FORM_<unknown>";
1424 }
1425}
1426
1427/* Convert a DWARF stack opcode into its string name. */
1428static char *
1429dwarf_stack_op_name (op)
1430 register unsigned op;
1431{
1432 switch (op)
1433 {
1434 case DW_OP_addr:
1435 return "DW_OP_addr";
1436 case DW_OP_deref:
1437 return "DW_OP_deref";
1438 case DW_OP_const1u:
1439 return "DW_OP_const1u";
1440 case DW_OP_const1s:
1441 return "DW_OP_const1s";
1442 case DW_OP_const2u:
1443 return "DW_OP_const2u";
1444 case DW_OP_const2s:
1445 return "DW_OP_const2s";
1446 case DW_OP_const4u:
1447 return "DW_OP_const4u";
1448 case DW_OP_const4s:
1449 return "DW_OP_const4s";
1450 case DW_OP_const8u:
1451 return "DW_OP_const8u";
1452 case DW_OP_const8s:
1453 return "DW_OP_const8s";
1454 case DW_OP_constu:
1455 return "DW_OP_constu";
1456 case DW_OP_consts:
1457 return "DW_OP_consts";
1458 case DW_OP_dup:
1459 return "DW_OP_dup";
1460 case DW_OP_drop:
1461 return "DW_OP_drop";
1462 case DW_OP_over:
1463 return "DW_OP_over";
1464 case DW_OP_pick:
1465 return "DW_OP_pick";
1466 case DW_OP_swap:
1467 return "DW_OP_swap";
1468 case DW_OP_rot:
1469 return "DW_OP_rot";
1470 case DW_OP_xderef:
1471 return "DW_OP_xderef";
1472 case DW_OP_abs:
1473 return "DW_OP_abs";
1474 case DW_OP_and:
1475 return "DW_OP_and";
1476 case DW_OP_div:
1477 return "DW_OP_div";
1478 case DW_OP_minus:
1479 return "DW_OP_minus";
1480 case DW_OP_mod:
1481 return "DW_OP_mod";
1482 case DW_OP_mul:
1483 return "DW_OP_mul";
1484 case DW_OP_neg:
1485 return "DW_OP_neg";
1486 case DW_OP_not:
1487 return "DW_OP_not";
1488 case DW_OP_or:
1489 return "DW_OP_or";
1490 case DW_OP_plus:
1491 return "DW_OP_plus";
1492 case DW_OP_plus_uconst:
1493 return "DW_OP_plus_uconst";
1494 case DW_OP_shl:
1495 return "DW_OP_shl";
1496 case DW_OP_shr:
1497 return "DW_OP_shr";
1498 case DW_OP_shra:
1499 return "DW_OP_shra";
1500 case DW_OP_xor:
1501 return "DW_OP_xor";
1502 case DW_OP_bra:
1503 return "DW_OP_bra";
1504 case DW_OP_eq:
1505 return "DW_OP_eq";
1506 case DW_OP_ge:
1507 return "DW_OP_ge";
1508 case DW_OP_gt:
1509 return "DW_OP_gt";
1510 case DW_OP_le:
1511 return "DW_OP_le";
1512 case DW_OP_lt:
1513 return "DW_OP_lt";
1514 case DW_OP_ne:
1515 return "DW_OP_ne";
1516 case DW_OP_skip:
1517 return "DW_OP_skip";
1518 case DW_OP_lit0:
1519 return "DW_OP_lit0";
1520 case DW_OP_lit1:
1521 return "DW_OP_lit1";
1522 case DW_OP_lit2:
1523 return "DW_OP_lit2";
1524 case DW_OP_lit3:
1525 return "DW_OP_lit3";
1526 case DW_OP_lit4:
1527 return "DW_OP_lit4";
1528 case DW_OP_lit5:
1529 return "DW_OP_lit5";
1530 case DW_OP_lit6:
1531 return "DW_OP_lit6";
1532 case DW_OP_lit7:
1533 return "DW_OP_lit7";
1534 case DW_OP_lit8:
1535 return "DW_OP_lit8";
1536 case DW_OP_lit9:
1537 return "DW_OP_lit9";
1538 case DW_OP_lit10:
1539 return "DW_OP_lit10";
1540 case DW_OP_lit11:
1541 return "DW_OP_lit11";
1542 case DW_OP_lit12:
1543 return "DW_OP_lit12";
1544 case DW_OP_lit13:
1545 return "DW_OP_lit13";
1546 case DW_OP_lit14:
1547 return "DW_OP_lit14";
1548 case DW_OP_lit15:
1549 return "DW_OP_lit15";
1550 case DW_OP_lit16:
1551 return "DW_OP_lit16";
1552 case DW_OP_lit17:
1553 return "DW_OP_lit17";
1554 case DW_OP_lit18:
1555 return "DW_OP_lit18";
1556 case DW_OP_lit19:
1557 return "DW_OP_lit19";
1558 case DW_OP_lit20:
1559 return "DW_OP_lit20";
1560 case DW_OP_lit21:
1561 return "DW_OP_lit21";
1562 case DW_OP_lit22:
1563 return "DW_OP_lit22";
1564 case DW_OP_lit23:
1565 return "DW_OP_lit23";
1566 case DW_OP_lit24:
1567 return "DW_OP_lit24";
1568 case DW_OP_lit25:
1569 return "DW_OP_lit25";
1570 case DW_OP_lit26:
1571 return "DW_OP_lit26";
1572 case DW_OP_lit27:
1573 return "DW_OP_lit27";
1574 case DW_OP_lit28:
1575 return "DW_OP_lit28";
1576 case DW_OP_lit29:
1577 return "DW_OP_lit29";
1578 case DW_OP_lit30:
1579 return "DW_OP_lit30";
1580 case DW_OP_lit31:
1581 return "DW_OP_lit31";
1582 case DW_OP_reg0:
1583 return "DW_OP_reg0";
1584 case DW_OP_reg1:
1585 return "DW_OP_reg1";
1586 case DW_OP_reg2:
1587 return "DW_OP_reg2";
1588 case DW_OP_reg3:
1589 return "DW_OP_reg3";
1590 case DW_OP_reg4:
1591 return "DW_OP_reg4";
1592 case DW_OP_reg5:
1593 return "DW_OP_reg5";
1594 case DW_OP_reg6:
1595 return "DW_OP_reg6";
1596 case DW_OP_reg7:
1597 return "DW_OP_reg7";
1598 case DW_OP_reg8:
1599 return "DW_OP_reg8";
1600 case DW_OP_reg9:
1601 return "DW_OP_reg9";
1602 case DW_OP_reg10:
1603 return "DW_OP_reg10";
1604 case DW_OP_reg11:
1605 return "DW_OP_reg11";
1606 case DW_OP_reg12:
1607 return "DW_OP_reg12";
1608 case DW_OP_reg13:
1609 return "DW_OP_reg13";
1610 case DW_OP_reg14:
1611 return "DW_OP_reg14";
1612 case DW_OP_reg15:
1613 return "DW_OP_reg15";
1614 case DW_OP_reg16:
1615 return "DW_OP_reg16";
1616 case DW_OP_reg17:
1617 return "DW_OP_reg17";
1618 case DW_OP_reg18:
1619 return "DW_OP_reg18";
1620 case DW_OP_reg19:
1621 return "DW_OP_reg19";
1622 case DW_OP_reg20:
1623 return "DW_OP_reg20";
1624 case DW_OP_reg21:
1625 return "DW_OP_reg21";
1626 case DW_OP_reg22:
1627 return "DW_OP_reg22";
1628 case DW_OP_reg23:
1629 return "DW_OP_reg23";
1630 case DW_OP_reg24:
1631 return "DW_OP_reg24";
1632 case DW_OP_reg25:
1633 return "DW_OP_reg25";
1634 case DW_OP_reg26:
1635 return "DW_OP_reg26";
1636 case DW_OP_reg27:
1637 return "DW_OP_reg27";
1638 case DW_OP_reg28:
1639 return "DW_OP_reg28";
1640 case DW_OP_reg29:
1641 return "DW_OP_reg29";
1642 case DW_OP_reg30:
1643 return "DW_OP_reg30";
1644 case DW_OP_reg31:
1645 return "DW_OP_reg31";
1646 case DW_OP_breg0:
1647 return "DW_OP_breg0";
1648 case DW_OP_breg1:
1649 return "DW_OP_breg1";
1650 case DW_OP_breg2:
1651 return "DW_OP_breg2";
1652 case DW_OP_breg3:
1653 return "DW_OP_breg3";
1654 case DW_OP_breg4:
1655 return "DW_OP_breg4";
1656 case DW_OP_breg5:
1657 return "DW_OP_breg5";
1658 case DW_OP_breg6:
1659 return "DW_OP_breg6";
1660 case DW_OP_breg7:
1661 return "DW_OP_breg7";
1662 case DW_OP_breg8:
1663 return "DW_OP_breg8";
1664 case DW_OP_breg9:
1665 return "DW_OP_breg9";
1666 case DW_OP_breg10:
1667 return "DW_OP_breg10";
1668 case DW_OP_breg11:
1669 return "DW_OP_breg11";
1670 case DW_OP_breg12:
1671 return "DW_OP_breg12";
1672 case DW_OP_breg13:
1673 return "DW_OP_breg13";
1674 case DW_OP_breg14:
1675 return "DW_OP_breg14";
1676 case DW_OP_breg15:
1677 return "DW_OP_breg15";
1678 case DW_OP_breg16:
1679 return "DW_OP_breg16";
1680 case DW_OP_breg17:
1681 return "DW_OP_breg17";
1682 case DW_OP_breg18:
1683 return "DW_OP_breg18";
1684 case DW_OP_breg19:
1685 return "DW_OP_breg19";
1686 case DW_OP_breg20:
1687 return "DW_OP_breg20";
1688 case DW_OP_breg21:
1689 return "DW_OP_breg21";
1690 case DW_OP_breg22:
1691 return "DW_OP_breg22";
1692 case DW_OP_breg23:
1693 return "DW_OP_breg23";
1694 case DW_OP_breg24:
1695 return "DW_OP_breg24";
1696 case DW_OP_breg25:
1697 return "DW_OP_breg25";
1698 case DW_OP_breg26:
1699 return "DW_OP_breg26";
1700 case DW_OP_breg27:
1701 return "DW_OP_breg27";
1702 case DW_OP_breg28:
1703 return "DW_OP_breg28";
1704 case DW_OP_breg29:
1705 return "DW_OP_breg29";
1706 case DW_OP_breg30:
1707 return "DW_OP_breg30";
1708 case DW_OP_breg31:
1709 return "DW_OP_breg31";
1710 case DW_OP_regx:
1711 return "DW_OP_regx";
1712 case DW_OP_fbreg:
1713 return "DW_OP_fbreg";
1714 case DW_OP_bregx:
1715 return "DW_OP_bregx";
1716 case DW_OP_piece:
1717 return "DW_OP_piece";
1718 case DW_OP_deref_size:
1719 return "DW_OP_deref_size";
1720 case DW_OP_xderef_size:
1721 return "DW_OP_xderef_size";
1722 case DW_OP_nop:
1723 return "DW_OP_nop";
1724 default:
1725 return "OP_<unknown>";
1726 }
1727}
1728
1729/* Convert a DWARF type code into its string name. */
1730static char *
1731dwarf_type_encoding_name (enc)
1732 register unsigned enc;
1733{
1734 switch (enc)
1735 {
1736 case DW_ATE_address:
1737 return "DW_ATE_address";
1738 case DW_ATE_boolean:
1739 return "DW_ATE_boolean";
1740 case DW_ATE_complex_float:
1741 return "DW_ATE_complex_float";
1742 case DW_ATE_float:
1743 return "DW_ATE_float";
1744 case DW_ATE_signed:
1745 return "DW_ATE_signed";
1746 case DW_ATE_signed_char:
1747 return "DW_ATE_signed_char";
1748 case DW_ATE_unsigned:
1749 return "DW_ATE_unsigned";
1750 case DW_ATE_unsigned_char:
1751 return "DW_ATE_unsigned_char";
1752 default:
1753 return "DW_ATE_<unknown>";
1754 }
1755}
1756
1757/* Convert a DWARF call frame info. operation to its string name */
1758static char *
1759dwarf_cfi_name (cfi_opc)
1760 register unsigned cfi_opc;
1761{
1762 switch (cfi_opc)
1763 {
1764 case DW_CFA_advance_loc:
1765 return "DW_CFA_advance_loc";
1766 case DW_CFA_offset:
1767 return "DW_CFA_offset";
1768 case DW_CFA_restore:
1769 return "DW_CFA_restore";
1770 case DW_CFA_nop:
1771 return "DW_CFA_nop";
1772 case DW_CFA_set_loc:
1773 return "DW_CFA_set_loc";
1774 case DW_CFA_advance_loc1:
1775 return "DW_CFA_advance_loc1";
1776 case DW_CFA_advance_loc2:
1777 return "DW_CFA_advance_loc2";
1778 case DW_CFA_advance_loc4:
1779 return "DW_CFA_advance_loc4";
1780 case DW_CFA_offset_extended:
1781 return "DW_CFA_offset_extended";
1782 case DW_CFA_restore_extended:
1783 return "DW_CFA_restore_extended";
1784 case DW_CFA_undefined:
1785 return "DW_CFA_undefined";
1786 case DW_CFA_same_value:
1787 return "DW_CFA_same_value";
1788 case DW_CFA_register:
1789 return "DW_CFA_register";
1790 case DW_CFA_remember_state:
1791 return "DW_CFA_remember_state";
1792 case DW_CFA_restore_state:
1793 return "DW_CFA_restore_state";
1794 case DW_CFA_def_cfa:
1795 return "DW_CFA_def_cfa";
1796 case DW_CFA_def_cfa_register:
1797 return "DW_CFA_def_cfa_register";
1798 case DW_CFA_def_cfa_offset:
1799 return "DW_CFA_def_cfa_offset";
1800 /* SGI/MIPS specific */
1801 case DW_CFA_MIPS_advance_loc8:
1802 return "DW_CFA_MIPS_advance_loc8";
1803 default:
1804 return "DW_CFA_<unknown>";
1805 }
1806}
1807\f
1808/* Determine the "ultimate origin" of a decl. The decl may be an inlined
1809 instance of an inlined instance of a decl which is local to an inline
1810 function, so we have to trace all of the way back through the origin chain
1811 to find out what sort of node actually served as the original seed for the
1812 given block. */
1813static tree
1814decl_ultimate_origin (decl)
1815 register tree decl;
1816{
1817 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1818
1819 if (immediate_origin == NULL)
1820 return NULL;
1821 else
1822 {
1823 register tree ret_val;
1824 register tree lookahead = immediate_origin;
1825
1826 do
1827 {
1828 ret_val = lookahead;
1829 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1830 }
1831 while (lookahead != NULL && lookahead != ret_val);
1832 return ret_val;
1833 }
1834}
1835
1836/* Determine the "ultimate origin" of a block. The block may be an inlined
1837 instance of an inlined instance of a block which is local to an inline
1838 function, so we have to trace all of the way back through the origin chain
1839 to find out what sort of node actually served as the original seed for the
1840 given block. */
1841static tree
1842block_ultimate_origin (block)
1843 register tree block;
1844{
1845 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1846
1847 if (immediate_origin == NULL)
1848 return NULL;
1849 else
1850 {
1851 register tree ret_val;
1852 register tree lookahead = immediate_origin;
1853
1854 do
1855 {
1856 ret_val = lookahead;
1857 lookahead = (TREE_CODE (ret_val) == BLOCK)
1858 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1859 : NULL;
1860 }
1861 while (lookahead != NULL && lookahead != ret_val);
1862 return ret_val;
1863 }
1864}
bdb669cb
JM
1865
1866/* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1867 of a virtual function may refer to a base class, so we check the 'this'
1868 parameter. */
1869
1870tree
1871decl_class_context (decl)
1872 tree decl;
1873{
1874 tree context = NULL_TREE;
1875 if (TREE_CODE (decl) != FUNCTION_DECL
1876 || ! DECL_VIRTUAL_P (decl))
1877 context = DECL_CONTEXT (decl);
1878 else
1879 context = TYPE_MAIN_VARIANT
1880 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1881
1882 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1883 context = NULL_TREE;
1884
1885 return context;
1886}
a3f97cbb
JW
1887\f
1888/**************** DIE internal representation constturction *******************/
1889
1890/* Add an attribute/value pair to a DIE */
1891inline void
1892add_dwarf_attr (die, attr)
1893 register dw_die_ref die;
1894 register dw_attr_ref attr;
1895{
1896 if (die != NULL && attr != NULL)
1897 {
1898 if (die->die_attr == NULL)
1899 {
1900 die->die_attr = attr;
1901 die->die_attr_last = attr;
1902 }
1903 else
1904 {
1905 die->die_attr_last->dw_attr_next = attr;
1906 die->die_attr_last = attr;
1907 }
1908 }
1909}
1910
1911/* Add a flag value attribute to a DIE. */
1912inline void
1913add_AT_flag (die, attr_kind, flag)
1914 register dw_die_ref die;
1915 register enum dwarf_attribute attr_kind;
1916 register unsigned flag;
1917{
1918 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1919 if (attr != NULL)
1920 {
1921 attr->dw_attr_next = NULL;
1922 attr->dw_attr = attr_kind;
1923 attr->dw_attr_val.val_class = dw_val_class_flag;
1924 attr->dw_attr_val.v.val_flag = flag;
1925 add_dwarf_attr (die, attr);
1926 }
1927}
1928
1929/* Add a signed integer attribute value to a DIE. */
1930inline void
1931add_AT_int (die, attr_kind, int_val)
1932 register dw_die_ref die;
1933 register enum dwarf_attribute attr_kind;
1934 register long int int_val;
1935{
1936 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1937 if (attr != NULL)
1938 {
1939 attr->dw_attr_next = NULL;
1940 attr->dw_attr = attr_kind;
1941 attr->dw_attr_val.val_class = dw_val_class_const;
1942 attr->dw_attr_val.v.val_int = int_val;
1943 add_dwarf_attr (die, attr);
1944 }
1945}
1946
1947/* Add an unsigned integer attribute value to a DIE. */
1948inline void
1949add_AT_unsigned (die, attr_kind, unsigned_val)
1950 register dw_die_ref die;
1951 register enum dwarf_attribute attr_kind;
1952 register unsigned long unsigned_val;
1953{
1954 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1955 if (attr != NULL)
1956 {
1957 attr->dw_attr_next = NULL;
1958 attr->dw_attr = attr_kind;
1959 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
1960 attr->dw_attr_val.v.val_unsigned = unsigned_val;
1961 add_dwarf_attr (die, attr);
1962 }
1963}
1964
1965/* Add an unsigned double integer attribute value to a DIE. */
1966inline void
1967add_AT_double (die, attr_kind, val_hi, val_low)
1968 register dw_die_ref die;
1969 register enum dwarf_attribute attr_kind;
1970 register unsigned long val_hi;
1971 register unsigned long val_low;
1972{
1973 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1974 if (attr != NULL)
1975 {
1976 attr->dw_attr_next = NULL;
1977 attr->dw_attr = attr_kind;
1978 attr->dw_attr_val.val_class = dw_val_class_double_const;
1979 attr->dw_attr_val.v.val_dbl_const.dw_dbl_hi = val_hi;
1980 attr->dw_attr_val.v.val_dbl_const.dw_dbl_low = val_low;
1981 add_dwarf_attr (die, attr);
1982 }
1983}
1984
1985/* Add a string attribute value to a DIE. */
1986inline void
1987add_AT_string (die, attr_kind, str)
1988 register dw_die_ref die;
1989 register enum dwarf_attribute attr_kind;
1990 register char *str;
1991{
1992 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1993 if (attr != NULL)
1994 {
1995 attr->dw_attr_next = NULL;
1996 attr->dw_attr = attr_kind;
1997 attr->dw_attr_val.val_class = dw_val_class_str;
1998 attr->dw_attr_val.v.val_str = xstrdup (str);
1999 add_dwarf_attr (die, attr);
2000 }
2001}
2002
2003/* Add a DIE reference attribute value to a DIE. */
2004inline void
2005add_AT_die_ref (die, attr_kind, targ_die)
2006 register dw_die_ref die;
2007 register enum dwarf_attribute attr_kind;
2008 register dw_die_ref targ_die;
2009{
2010 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2011 if (attr != NULL)
2012 {
2013 attr->dw_attr_next = NULL;
2014 attr->dw_attr = attr_kind;
2015 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2016 attr->dw_attr_val.v.val_die_ref = targ_die;
2017 add_dwarf_attr (die, attr);
2018 }
2019}
2020
2021/* Add an FDE reference attribute value to a DIE. */
2022inline void
2023add_AT_fde_ref (die, attr_kind, targ_fde)
2024 register dw_die_ref die;
2025 register enum dwarf_attribute attr_kind;
2026 register unsigned targ_fde;
2027{
2028 register dw_attr_ref attr;
2029
2030 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2031 if (attr != NULL)
2032 {
2033 attr->dw_attr_next = NULL;
2034 attr->dw_attr = attr_kind;
2035 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
2036 attr->dw_attr_val.v.val_fde_index = targ_fde;
2037 add_dwarf_attr (die, attr);
2038 }
2039}
2040
2041/* Add a location description attribute value to a DIE. */
2042inline void
2043add_AT_loc (die, attr_kind, loc)
2044 register dw_die_ref die;
2045 register enum dwarf_attribute attr_kind;
2046 register dw_loc_descr_ref loc;
2047{
2048 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2049 if (attr != NULL)
2050 {
2051 attr->dw_attr_next = NULL;
2052 attr->dw_attr = attr_kind;
2053 attr->dw_attr_val.val_class = dw_val_class_loc;
2054 attr->dw_attr_val.v.val_loc = loc;
2055 add_dwarf_attr (die, attr);
2056 }
2057}
2058
2059/* Add an address constant attribute value to a DIE. */
2060inline void
2061add_AT_addr (die, attr_kind, addr)
2062 register dw_die_ref die;
2063 register enum dwarf_attribute attr_kind;
2064 char *addr;
2065{
2066 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2067 if (attr != NULL)
2068 {
2069 attr->dw_attr_next = NULL;
2070 attr->dw_attr = attr_kind;
2071 attr->dw_attr_val.val_class = dw_val_class_addr;
2072 attr->dw_attr_val.v.val_addr = addr;
2073 add_dwarf_attr (die, attr);
2074 }
2075}
2076
2077/* Add a label identifier attribute value to a DIE. */
2078inline void
2079add_AT_lbl_id (die, attr_kind, lbl_id)
2080 register dw_die_ref die;
2081 register enum dwarf_attribute attr_kind;
2082 register char *lbl_id;
2083{
2084 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2085 if (attr != NULL)
2086 {
2087 attr->dw_attr_next = NULL;
2088 attr->dw_attr = attr_kind;
2089 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
2090 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
2091 add_dwarf_attr (die, attr);
2092 }
2093}
2094
2095/* Add a section offset attribute value to a DIE. */
2096inline void
2097add_AT_section_offset (die, attr_kind, section)
2098 register dw_die_ref die;
2099 register enum dwarf_attribute attr_kind;
2100 register char *section;
2101{
2102 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2103 if (attr != NULL)
2104 {
2105 attr->dw_attr_next = NULL;
2106 attr->dw_attr = attr_kind;
2107 attr->dw_attr_val.val_class = dw_val_class_section_offset;
2108 attr->dw_attr_val.v.val_section = section;
2109 add_dwarf_attr (die, attr);
2110 }
2111}
2112
a3f97cbb
JW
2113/* Test if die refers to an external subroutine. */
2114inline int
2115is_extern_subr_die (die)
2116 register dw_die_ref die;
2117{
2118 register dw_attr_ref a;
2119 register int is_subr = FALSE;
2120 register int is_extern = FALSE;
2121 if (die != NULL && die->die_tag == DW_TAG_subprogram)
2122 {
2123 is_subr = TRUE;
2124 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2125 {
2126 if (a->dw_attr == DW_AT_external
2127 && a->dw_attr_val.val_class == dw_val_class_flag
2128 && a->dw_attr_val.v.val_flag != 0)
2129 {
2130 is_extern = TRUE;
2131 break;
2132 }
2133 }
2134 }
2135 return is_subr && is_extern;
2136}
2137
d291dd49
JM
2138/* Get the attribute of type attr_kind. */
2139inline dw_attr_ref
2140get_AT (die, attr_kind)
a3f97cbb 2141 register dw_die_ref die;
d291dd49 2142 register enum dwarf_attribute attr_kind;
a3f97cbb
JW
2143{
2144 register dw_attr_ref a;
7e23cb16 2145 register dw_die_ref spec = NULL;
d291dd49 2146
a3f97cbb
JW
2147 if (die != NULL)
2148 {
2149 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2150 {
d291dd49
JM
2151 if (a->dw_attr == attr_kind)
2152 return a;
2153 if (a->dw_attr == DW_AT_specification
2154 || a->dw_attr == DW_AT_abstract_origin)
2155 spec = a->dw_attr_val.v.val_die_ref;
a3f97cbb 2156 }
d291dd49
JM
2157 if (spec)
2158 return get_AT (spec, attr_kind);
a3f97cbb 2159 }
d291dd49
JM
2160 return NULL;
2161}
2162
2163/* Return the "low pc" attribute value, typically associated with
2164 a subprogram DIE. Return null if the "low pc" attribute is
2165 either not prsent, or if it cannot be represented as an
2166 assembler label identifier. */
2167inline char *
2168get_AT_low_pc (die)
2169 register dw_die_ref die;
2170{
2171 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
2172 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2173 return a->dw_attr_val.v.val_lbl_id;
2174 return NULL;
2175}
2176
2177/* Return the "high pc" attribute value, typically associated with
2178 a subprogram DIE. Return null if the "high pc" attribute is
2179 either not prsent, or if it cannot be represented as an
2180 assembler label identifier. */
2181inline char *
2182get_AT_hi_pc (die)
2183 register dw_die_ref die;
2184{
2185 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
2186 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2187 return a->dw_attr_val.v.val_lbl_id;
2188 return NULL;
2189}
2190
2191/* Return the value of the string attribute designated by ATTR_KIND, or
2192 NULL if it is not present. */
2193inline char *
2194get_AT_string (die, attr_kind)
2195 register dw_die_ref die;
2196 register enum dwarf_attribute attr_kind;
2197{
2198 register dw_attr_ref a = get_AT (die, attr_kind);
2199 if (a && a->dw_attr_val.val_class == dw_val_class_str)
2200 return a->dw_attr_val.v.val_str;
2201 return NULL;
a3f97cbb
JW
2202}
2203
bdb669cb
JM
2204/* Return the value of the flag attribute designated by ATTR_KIND, or -1
2205 if it is not present. */
2206inline int
2207get_AT_flag (die, attr_kind)
2208 register dw_die_ref die;
2209 register enum dwarf_attribute attr_kind;
2210{
d291dd49
JM
2211 register dw_attr_ref a = get_AT (die, attr_kind);
2212 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
2213 return a->dw_attr_val.v.val_flag;
bdb669cb
JM
2214 return -1;
2215}
2216
2217/* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
2218 if it is not present. */
2219inline unsigned
2220get_AT_unsigned (die, attr_kind)
2221 register dw_die_ref die;
2222 register enum dwarf_attribute attr_kind;
2223{
d291dd49
JM
2224 register dw_attr_ref a = get_AT (die, attr_kind);
2225 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
2226 return a->dw_attr_val.v.val_unsigned;
bdb669cb
JM
2227 return 0;
2228}
a3f97cbb 2229
a9d38797
JM
2230inline int
2231is_c_family ()
2232{
2233 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2234 return (lang == DW_LANG_C || lang == DW_LANG_C89
2235 || lang == DW_LANG_C_plus_plus);
2236}
2237
2238inline int
2239is_fortran ()
2240{
2241 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2242 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
2243}
2244
4b674448
JM
2245/* Remove the specified attribute if present. */
2246inline void
2247remove_AT (die, attr_kind)
2248 register dw_die_ref die;
2249 register enum dwarf_attribute attr_kind;
2250{
2251 register dw_attr_ref a;
2252 register dw_attr_ref removed = NULL;;
2253 if (die != NULL)
2254 {
2255 if (die->die_attr->dw_attr == attr_kind)
2256 {
2257 removed = die->die_attr;
2258 if (die->die_attr_last == die->die_attr)
2259 die->die_attr_last = NULL;
2260 die->die_attr = die->die_attr->dw_attr_next;
2261 }
2262 else for (a = die->die_attr; a->dw_attr_next != NULL;
2263 a = a->dw_attr_next)
2264 if (a->dw_attr_next->dw_attr == attr_kind)
2265 {
2266 removed = a->dw_attr_next;
2267 if (die->die_attr_last == a->dw_attr_next)
2268 die->die_attr_last = a;
2269 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
e90b62db 2270 break;
4b674448
JM
2271 }
2272 if (removed)
2273 free (removed);
2274 }
2275}
2276
2277/* Discard the children of this DIE. */
2278inline void
2279remove_children (die)
2280 register dw_die_ref die;
2281{
2282 register dw_die_ref child_die = die->die_child;
2283 die->die_child = NULL;
2284 die->die_child_last = NULL;
2285 while (child_die != NULL)
2286 {
2287 register dw_die_ref tmp_die = child_die;
2288 register dw_attr_ref a;
2289 child_die = child_die->die_sib;
2290
2291 for (a = tmp_die->die_attr; a != NULL; )
2292 {
2293 register dw_attr_ref tmp_a = a;
2294 a = a->dw_attr_next;
2295 free (tmp_a);
2296 }
2297 free (tmp_die);
2298 }
2299}
2300
a3f97cbb
JW
2301/* Add a child DIE below its parent. */
2302inline void
2303add_child_die (die, child_die)
2304 register dw_die_ref die;
2305 register dw_die_ref child_die;
2306{
2307 if (die != NULL && child_die != NULL)
2308 {
2309 assert (die != child_die);
2310 child_die->die_parent = die;
2311 child_die->die_sib = NULL;
2312 if (die->die_child == NULL)
2313 {
2314 die->die_child = child_die;
2315 die->die_child_last = child_die;
2316 }
2317 else
2318 {
2319 die->die_child_last->die_sib = child_die;
2320 die->die_child_last = child_die;
2321 }
2322 }
2323}
2324
2325/* Return a pointer to a newly created DIE node. */
2326inline dw_die_ref
2327new_die (tag_value, parent_die)
2328 register enum dwarf_tag tag_value;
2329 register dw_die_ref parent_die;
2330{
2331 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
2332 if (die != NULL)
2333 {
2334 die->die_tag = tag_value;
2335 die->die_abbrev = 0;
2336 die->die_offset = 0;
2337 die->die_child = NULL;
2338 die->die_parent = NULL;
2339 die->die_sib = NULL;
2340 die->die_child_last = NULL;
2341 die->die_attr = NULL;
2342 die->die_attr_last = NULL;
2343 if (parent_die != NULL)
2344 {
2345 add_child_die (parent_die, die);
2346 }
2347 }
2348 return die;
2349}
2350
2351/* Return the DIE associated with the given type specifier. */
2352inline dw_die_ref
2353lookup_type_die (type)
2354 register tree type;
2355{
2356 register unsigned type_id = TYPE_UID (type);
2357 return (type_id < type_die_table_in_use)
2358 ? type_die_table[type_id] : NULL;
2359}
2360
2361/* Equate a DIE to a given type specifier. */
2362static void
2363equate_type_number_to_die (type, type_die)
2364 register tree type;
2365 register dw_die_ref type_die;
2366{
2367 register unsigned type_id = TYPE_UID (type);
a3f97cbb
JW
2368 register unsigned num_allocated;
2369 if (type_id >= type_die_table_allocated)
2370 {
2371 num_allocated = (((type_id + 1)
2372 + TYPE_DIE_TABLE_INCREMENT - 1)
2373 / TYPE_DIE_TABLE_INCREMENT)
2374 * TYPE_DIE_TABLE_INCREMENT;
2375 type_die_table = (dw_die_ref *) xrealloc (type_die_table,
2376 sizeof (dw_die_ref) * num_allocated);
2377 bzero (&type_die_table[type_die_table_allocated],
2378 (num_allocated - type_die_table_allocated) * sizeof (dw_die_ref));
2379 type_die_table_allocated = num_allocated;
2380 }
2381 if (type_id >= type_die_table_in_use)
2382 {
2383 type_die_table_in_use = (type_id + 1);
2384 }
2385 type_die_table[type_id] = type_die;
2386}
2387
2388/* Return the DIE associated with a given declaration. */
2389inline dw_die_ref
2390lookup_decl_die (decl)
2391 register tree decl;
2392{
2393 register unsigned decl_id = DECL_UID (decl);
2394 return (decl_id < decl_die_table_in_use)
2395 ? decl_die_table[decl_id] : NULL;
2396}
2397
2398/* Equate a DIE to a particular declaration. */
2399static void
2400equate_decl_number_to_die (decl, decl_die)
2401 register tree decl;
2402 register dw_die_ref decl_die;
2403{
2404 register unsigned decl_id = DECL_UID (decl);
2405 register unsigned i;
2406 register unsigned num_allocated;
2407 if (decl_id >= decl_die_table_allocated)
2408 {
2409 num_allocated = (((decl_id + 1)
2410 + DECL_DIE_TABLE_INCREMENT - 1)
2411 / DECL_DIE_TABLE_INCREMENT)
2412 * DECL_DIE_TABLE_INCREMENT;
2413 decl_die_table = (dw_die_ref *) xrealloc (decl_die_table,
2414 sizeof (dw_die_ref) * num_allocated);
2415 bzero (&decl_die_table[decl_die_table_allocated],
2416 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
2417 decl_die_table_allocated = num_allocated;
2418 }
2419 if (decl_id >= decl_die_table_in_use)
2420 {
2421 decl_die_table_in_use = (decl_id + 1);
2422 }
2423 decl_die_table[decl_id] = decl_die;
2424}
2425
2426/* Return a pointer to a newly allocated location description. Location
2427 descriptions are simple expression terms that can be strung
2428 together to form more complicated location (address) descriptions. */
2429inline dw_loc_descr_ref
2430new_loc_descr (op, oprnd1, oprnd2)
2431 register enum dwarf_location_atom op;
2432 register unsigned long oprnd1;
2433 register unsigned long oprnd2;
2434{
2435 register dw_loc_descr_ref descr =
2436 (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2437 if (descr != NULL)
2438 {
2439 descr->dw_loc_next = NULL;
2440 descr->dw_loc_opc = op;
2441 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2442 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2443 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2444 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2445 }
2446 return descr;
2447}
2448
2449/* Add a location description term to a location description expression. */
2450inline void
2451add_loc_descr (list_head, descr)
2452 register dw_loc_descr_ref *list_head;
2453 register dw_loc_descr_ref descr;
2454{
2455 register dw_loc_descr_ref *d;
2456 /* find the end of the chain. */
2457 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2458 {
2459 /* nothing */ ;
2460 }
2461 *d = descr;
2462}
2463
2464/* Return a pointer to a newly allocated Call Frame Instruction. */
2465inline dw_cfi_ref
2466new_cfi ()
2467{
2468 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
2469 if (cfi != NULL)
2470 {
2471 cfi->dw_cfi_next = NULL;
2472 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
2473 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
2474 }
2475 return cfi;
2476}
2477
2478/* Add a Call Frame Instruction to list of instructions. */
2479inline void
2480add_cfi (list_head, cfi)
2481 register dw_cfi_ref *list_head;
2482 register dw_cfi_ref cfi;
2483{
2484 register dw_cfi_ref *p;
2485 /* find the end of the chain. */
2486 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
2487 {
2488 /* nothing */ ;
2489 }
2490 *p = cfi;
2491}
2492\f
2493/********* Print DWARF Internal Representation (debugging aids) ***************/
2494
2495/* Keep track of the number of spaces used to indent the
2496 output of the debugging routines that print the structure of
2497 the DIE internal representation. */
2498static int print_indent;
2499
2500/* Indent the line the number of spaces given by print_indent. */
2501inline void
2502print_spaces (outfile)
2503 FILE *outfile;
2504{
2505 fprintf (outfile, "%*s", print_indent, "");
2506}
2507
2508/* Print the information assoaciated with a given DIE, and its children.
2509 This routine is a debugging aid only. */
2510static void
2511print_die (die, outfile)
2512 dw_die_ref die;
2513 FILE *outfile;
2514{
2515 register dw_attr_ref a;
2516 register dw_die_ref c;
2517 print_spaces (outfile);
2518 fprintf (outfile, "DIE %4u: %s\n",
2519 die->die_offset, dwarf_tag_name (die->die_tag));
2520 print_spaces (outfile);
2521 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
2522 fprintf (outfile, " offset: %u\n", die->die_offset);
2523 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2524 {
2525 print_spaces (outfile);
2526 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
2527 switch (a->dw_attr_val.val_class)
2528 {
2529 case dw_val_class_addr:
2530 fprintf (outfile, "address");
2531 break;
2532 case dw_val_class_loc:
2533 fprintf (outfile, "location descriptor");
2534 break;
2535 case dw_val_class_const:
2536 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
2537 break;
2538 case dw_val_class_unsigned_const:
2539 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
2540 break;
2541 case dw_val_class_double_const:
2542 fprintf (outfile, "constant (%u,%u)",
2543 a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
2544 a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
2545 break;
2546 case dw_val_class_flag:
2547 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
2548 break;
2549 case dw_val_class_die_ref:
2550 if (a->dw_attr_val.v.val_die_ref != NULL)
2551 {
2552 fprintf (outfile, "die -> %u",
2553 a->dw_attr_val.v.val_die_ref->die_offset);
2554 }
2555 else
2556 {
2557 fprintf (outfile, "die -> <null>");
2558 }
2559 break;
2560 case dw_val_class_lbl_id:
2561 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
2562 break;
2563 case dw_val_class_section_offset:
2564 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
2565 break;
2566 case dw_val_class_str:
2567 if (a->dw_attr_val.v.val_str != NULL)
2568 {
2569 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
2570 }
2571 else
2572 {
2573 fprintf (outfile, "<null>");
2574 }
2575 break;
2576 }
2577 fprintf (outfile, "\n");
2578 }
2579 if (die->die_child != NULL)
2580 {
2581 print_indent += 4;
2582 for (c = die->die_child; c != NULL; c = c->die_sib)
2583 {
2584 print_die (c, outfile);
2585 }
2586 print_indent -= 4;
2587 }
2588}
2589
2590/* Print the contents of the source code line number correspondence table.
2591 This routine is a debugging aid only. */
2592static void
2593print_dwarf_line_table (outfile)
2594 FILE *outfile;
2595{
2596 register unsigned i;
2597 register dw_line_info_ref line_info;
2598 fprintf (outfile, "\n\nDWARF source line information\n");
2599 for (i = 1; i < line_info_table_in_use; ++i)
2600 {
2601 line_info = &line_info_table[i];
2602 fprintf (outfile, "%5d: ", i);
2603 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
2604 fprintf (outfile, "%6d", line_info->dw_line_num);
2605 fprintf (outfile, "\n");
2606 }
2607 fprintf (outfile, "\n\n");
2608}
2609
2610/* Print the information collected for a given DIE. */
2611void
2612debug_dwarf_die (die)
2613 dw_die_ref die;
2614{
2615 print_die (die, stderr);
2616}
2617
2618/* Print all DWARF informaiton collected for the compilation unit.
2619 This routine is a debugging aid only. */
2620void
2621debug_dwarf ()
2622{
2623 print_indent = 0;
2624 print_die (comp_unit_die, stderr);
2625 print_dwarf_line_table (stderr);
2626}
2627
2628\f
2629/***************** DWARF Information Construction Support *********************/
2630
2631/* Traverse the DIE, and add a sibling attribute if it may have the
2632 effect of speeding up access to siblings. To save some space,
2633 avoid generating sibling attributes for DIE's without children. */
2634static void
2635add_sibling_attributes(die)
2636 register dw_die_ref die;
2637{
2638 register dw_die_ref c;
2639 register dw_attr_ref attr;
2640 if (die != comp_unit_die && die->die_child != NULL)
2641 {
2642 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2643 if (attr != NULL)
2644 {
2645 attr->dw_attr_next = NULL;
2646 attr->dw_attr = DW_AT_sibling;
2647 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2648 attr->dw_attr_val.v.val_die_ref = die->die_sib;
2649 }
2650 /* add the sibling link to the front of the attribute list. */
2651 attr->dw_attr_next = die->die_attr;
2652 if (die->die_attr == NULL)
2653 {
2654 die->die_attr_last = attr;
2655 }
2656 die->die_attr = attr;
2657 }
2658 for (c = die->die_child; c != NULL; c = c->die_sib)
2659 {
2660 add_sibling_attributes (c);
2661 }
2662}
2663
2664/* The format of each DIE (and its attribute value pairs)
2665 is encoded in an abbreviation table. This routine builds the
2666 abbreviation table and assigns a unique abbreviation id for
2667 each abbreviation entry. The children of each die are visited
2668 recursively. */
2669static void
2670build_abbrev_table (die)
2671 register dw_die_ref die;
2672{
2673 register unsigned long abbrev_id;
2674 register unsigned long n_alloc;
2675 register dw_die_ref c;
2676 register dw_attr_ref d_attr, a_attr;
2677 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
2678 {
2679 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
2680 if (abbrev->die_tag == die->die_tag)
2681 {
2682 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
2683 {
2684 a_attr = abbrev->die_attr;
2685 d_attr = die->die_attr;
2686 while (a_attr != NULL && d_attr != NULL)
2687 {
2688 if ((a_attr->dw_attr != d_attr->dw_attr)
f37230f0
JM
2689 || (value_format (&a_attr->dw_attr_val)
2690 != value_format (&d_attr->dw_attr_val)))
a3f97cbb
JW
2691 {
2692 break;
2693 }
2694 a_attr = a_attr->dw_attr_next;
2695 d_attr = d_attr->dw_attr_next;
2696 }
2697 if (a_attr == NULL && d_attr == NULL)
2698 {
2699 break;
2700 }
2701 }
2702 }
2703 }
2704 if (abbrev_id >= abbrev_die_table_in_use)
2705 {
2706 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
2707 {
2708 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
2709 abbrev_die_table = (dw_die_ref *)
2710 xmalloc (abbrev_die_table,
2711 sizeof (dw_die_ref) * n_alloc);
2712 bzero (&abbrev_die_table[abbrev_die_table_allocated],
2713 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
2714 abbrev_die_table_allocated = n_alloc;
2715 }
2716 ++abbrev_die_table_in_use;
2717 abbrev_die_table[abbrev_id] = die;
2718 }
2719 die->die_abbrev = abbrev_id;
2720 for (c = die->die_child; c != NULL; c = c->die_sib)
2721 {
2722 build_abbrev_table (c);
2723 }
2724}
2725
2726\f
2727/********************** DWARF Information Sizing *****************************/
2728
2729/* Return the size of an unsigned LEB128 quantity. */
2730inline unsigned long
2731size_of_uleb128 (value)
2732 register unsigned long value;
2733{
2734 register unsigned long size = 0;
2735 register unsigned byte;
2736 do
2737 {
2738 byte = (value & 0x7f);
2739 value >>= 7;
2740 size += 1;
2741 }
2742 while (value != 0);
2743 return size;
2744}
2745
2746/* Return the size of a signed LEB128 quantity. */
2747inline unsigned long
2748size_of_sleb128 (value)
2749 register long value;
2750{
2751 register unsigned long size = 0;
2752 register unsigned byte;
2753 do
2754 {
2755 byte = (value & 0x7f);
2756 value >>= 7;
2757 size += 1;
2758 }
2759 while (!(((value == 0) && ((byte & 0x40) == 0))
2760 || ((value == -1) && ((byte & 0x40) != 0))));
2761 return size;
2762}
2763
2764/* Return the size of a string, including the null byte. */
2765static unsigned long
2766size_of_string (str)
2767 register char *str;
2768{
2769 register unsigned long size = 0;
2770 register unsigned long slen = strlen (str);
2771 register unsigned long i;
2772 register unsigned c;
2773 for (i = 0; i < slen; ++i)
2774 {
2775 c = str[i];
2776 if (c == '\\')
2777 {
2778 ++i;
2779 }
2780 size += 1;
2781 }
2782 /* Null terminator. */
2783 size += 1;
2784 return size;
2785}
2786
2787/* Return the size of a location descriptor. */
2788static unsigned long
2789size_of_loc_descr (loc)
2790 register dw_loc_descr_ref loc;
2791{
2792 register unsigned long size = 1;
2793 switch (loc->dw_loc_opc)
2794 {
2795 case DW_OP_addr:
2796 size += PTR_SIZE;
2797 break;
2798 case DW_OP_const1u:
2799 case DW_OP_const1s:
2800 size += 1;
2801 break;
2802 case DW_OP_const2u:
2803 case DW_OP_const2s:
2804 size += 2;
2805 break;
2806 case DW_OP_const4u:
2807 case DW_OP_const4s:
2808 size += 4;
2809 break;
2810 case DW_OP_const8u:
2811 case DW_OP_const8s:
2812 size += 8;
2813 break;
2814 case DW_OP_constu:
2815 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2816 break;
2817 case DW_OP_consts:
2818 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2819 break;
2820 case DW_OP_pick:
2821 size += 1;
2822 break;
2823 case DW_OP_plus_uconst:
2824 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2825 break;
2826 case DW_OP_skip:
2827 case DW_OP_bra:
2828 size += 2;
2829 break;
2830 case DW_OP_breg0:
2831 case DW_OP_breg1:
2832 case DW_OP_breg2:
2833 case DW_OP_breg3:
2834 case DW_OP_breg4:
2835 case DW_OP_breg5:
2836 case DW_OP_breg6:
2837 case DW_OP_breg7:
2838 case DW_OP_breg8:
2839 case DW_OP_breg9:
2840 case DW_OP_breg10:
2841 case DW_OP_breg11:
2842 case DW_OP_breg12:
2843 case DW_OP_breg13:
2844 case DW_OP_breg14:
2845 case DW_OP_breg15:
2846 case DW_OP_breg16:
2847 case DW_OP_breg17:
2848 case DW_OP_breg18:
2849 case DW_OP_breg19:
2850 case DW_OP_breg20:
2851 case DW_OP_breg21:
2852 case DW_OP_breg22:
2853 case DW_OP_breg23:
2854 case DW_OP_breg24:
2855 case DW_OP_breg25:
2856 case DW_OP_breg26:
2857 case DW_OP_breg27:
2858 case DW_OP_breg28:
2859 case DW_OP_breg29:
2860 case DW_OP_breg30:
2861 case DW_OP_breg31:
2862 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2863 break;
2864 case DW_OP_regx:
2865 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2866 break;
2867 case DW_OP_fbreg:
2868 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2869 break;
2870 case DW_OP_bregx:
2871 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2872 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2873 break;
2874 case DW_OP_piece:
2875 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2876 break;
2877 case DW_OP_deref_size:
2878 case DW_OP_xderef_size:
2879 size += 1;
2880 break;
2881 default:
2882 break;
2883 }
2884 return size;
2885}
2886
f37230f0
JM
2887/* Return the size of a series of location descriptors. */
2888static unsigned long
2889size_of_locs (loc)
2890 register dw_loc_descr_ref loc;
2891{
2892 register unsigned long size = 0;
2893 for (; loc != NULL; loc = loc->dw_loc_next)
2894 size += size_of_loc_descr (loc);
2895 return size;
2896}
2897
7e23cb16
JM
2898/* Return the power-of-two number of bytes necessary to represent VALUE. */
2899static int
2900constant_size (value)
2901 long unsigned value;
2902{
2903 int log;
2904
2905 if (value == 0)
2906 log = 0;
2907 else
2908 log = floor_log2 (value);
2909
2910 log = log / 8;
2911 log = 1 << (floor_log2 (log) + 1);
2912
2913 return log;
2914}
2915
a3f97cbb
JW
2916/* Return the size of a DIE, as it is represented in the
2917 .debug_info section. */
2918static unsigned long
2919size_of_die (die)
2920 register dw_die_ref die;
2921{
2922 register unsigned long size = 0;
2923 register dw_attr_ref a;
a3f97cbb
JW
2924 size += size_of_uleb128 (die->die_abbrev);
2925 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2926 {
2927 switch (a->dw_attr_val.val_class)
2928 {
2929 case dw_val_class_addr:
7e23cb16 2930 size += PTR_SIZE;
a3f97cbb
JW
2931 break;
2932 case dw_val_class_loc:
f37230f0
JM
2933 {
2934 register unsigned long lsize
2935 = size_of_locs (a->dw_attr_val.v.val_loc);
2936
2937 /* Block length. */
2938 size += constant_size (lsize);
2939 size += lsize;
2940 }
a3f97cbb
JW
2941 break;
2942 case dw_val_class_const:
2943 size += 4;
2944 break;
2945 case dw_val_class_unsigned_const:
7e23cb16 2946 size += constant_size (a->dw_attr_val.v.val_unsigned);
a3f97cbb
JW
2947 break;
2948 case dw_val_class_double_const:
2949 size += 8;
2950 break;
2951 case dw_val_class_flag:
2952 size += 1;
2953 break;
2954 case dw_val_class_die_ref:
7e23cb16 2955 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
2956 break;
2957 case dw_val_class_fde_ref:
7e23cb16 2958 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
2959 break;
2960 case dw_val_class_lbl_id:
7e23cb16 2961 size += PTR_SIZE;
a3f97cbb
JW
2962 break;
2963 case dw_val_class_section_offset:
7e23cb16 2964 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
2965 break;
2966 case dw_val_class_str:
2967 size += size_of_string (a->dw_attr_val.v.val_str);
2968 break;
2969 default:
2970 abort ();
2971 }
2972 }
2973 return size;
2974}
2975
2976/* Size the debgging information associted with a given DIE.
2977 Visits the DIE's children recursively. Updates the global
2978 variable next_die_offset, on each time through. Uses the
2979 current value of next_die_offset to updete the die_offset
2980 field in each DIE. */
2981static void
2982calc_die_sizes (die)
2983 dw_die_ref die;
2984{
2985 register dw_die_ref c;
a3f97cbb
JW
2986 die->die_offset = next_die_offset;
2987 next_die_offset += size_of_die (die);
2988 for (c = die->die_child; c != NULL; c = c->die_sib)
2989 {
2990 calc_die_sizes (c);
2991 }
2992 if (die->die_child != NULL)
2993 {
2994 /* Count the null byte used to terminate sibling lists. */
2995 next_die_offset += 1;
2996 }
2997}
2998
2999/* Return the size of the line information prolog generated for the
3000 compilation unit. */
3001static unsigned long
3002size_of_line_prolog ()
3003{
3004 register unsigned long size;
a3f97cbb
JW
3005 register unsigned long ft_index;
3006 size = DWARF_LINE_PROLOG_HEADER_SIZE;
3007 /* Count the size of the table giving number of args for each
3008 standard opcode. */
3009 size += DWARF_LINE_OPCODE_BASE - 1;
3010 /* Include directory table is empty (at present). Count only the
3011 the null byte used to terminate the table. */
3012 size += 1;
3013 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
3014 {
3015 /* File name entry. */
3016 size += size_of_string (file_table[ft_index]);
3017 /* Include directory index. */
3018 size += size_of_uleb128 (0);
3019 /* Modification time. */
3020 size += size_of_uleb128 (0);
3021 /* File length in bytes. */
3022 size += size_of_uleb128 (0);
3023 }
3024 /* Count the file table terminator. */
3025 size += 1;
3026 return size;
3027}
3028
3029/* Return the size of the line information generated for this
3030 compilation unit. */
3031static unsigned long
3032size_of_line_info ()
3033{
3034 register unsigned long size;
a3f97cbb
JW
3035 register unsigned long lt_index;
3036 register unsigned long current_line;
3037 register long line_offset;
3038 register long line_delta;
3039 register unsigned long current_file;
e90b62db 3040 register unsigned long function;
a3f97cbb
JW
3041 /* Version number. */
3042 size = 2;
3043 /* Prolog length specifier. */
7e23cb16 3044 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
3045 /* Prolog. */
3046 size += size_of_line_prolog ();
3047 /* Set address register instruction. */
3048 size += 1 + size_of_uleb128 (1 + PTR_SIZE)
3049 + 1 + PTR_SIZE;
3050 current_file = 1;
3051 current_line = 1;
3052 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
3053 {
e90b62db 3054 register dw_line_info_ref line_info;
a3f97cbb
JW
3055 /* Advance pc instruction. */
3056 size += 1 + 2;
3057 line_info = &line_info_table[lt_index];
3058 if (line_info->dw_file_num != current_file)
3059 {
3060 /* Set file number instruction. */
3061 size += 1;
3062 current_file = line_info->dw_file_num;
3063 size += size_of_uleb128 (current_file);
3064 }
3065 if (line_info->dw_line_num != current_line)
3066 {
3067 line_offset = line_info->dw_line_num - current_line;
3068 line_delta = line_offset - DWARF_LINE_BASE;
3069 current_line = line_info->dw_line_num;
3070 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3071 {
3072 /* 1-byte special line number instruction. */
3073 size += 1;
3074 }
3075 else
3076 {
3077 /* Advance line instruction. */
3078 size += 1;
3079 size += size_of_sleb128 (line_offset);
3080 /* Generate line entry instruction. */
3081 size += 1;
3082 }
3083 }
3084 }
bdb669cb
JM
3085 /* Advance pc instruction. */
3086 size += 1 + 2;
a3f97cbb
JW
3087 /* End of line number info. marker. */
3088 size += 1 + size_of_uleb128 (1) + 1;
e90b62db
JM
3089 function = 0;
3090 current_file = 1;
3091 current_line = 1;
3092 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
3093 {
3094 register dw_separate_line_info_ref line_info
3095 = &separate_line_info_table[lt_index];
3096 if (function != line_info->function)
3097 {
3098 function = line_info->function;
3099 /* Set address register instruction. */
3100 size += 1 + size_of_uleb128 (1 + PTR_SIZE)
3101 + 1 + PTR_SIZE;
3102 }
3103 else
3104 {
3105 /* Advance pc instruction. */
3106 size += 1 + 2;
3107 }
3108 if (line_info->dw_file_num != current_file)
3109 {
3110 /* Set file number instruction. */
3111 size += 1;
3112 current_file = line_info->dw_file_num;
3113 size += size_of_uleb128 (current_file);
3114 }
3115 if (line_info->dw_line_num != current_line)
3116 {
3117 line_offset = line_info->dw_line_num - current_line;
3118 line_delta = line_offset - DWARF_LINE_BASE;
3119 current_line = line_info->dw_line_num;
3120 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3121 {
3122 /* 1-byte special line number instruction. */
3123 size += 1;
3124 }
3125 else
3126 {
3127 /* Advance line instruction. */
3128 size += 1;
3129 size += size_of_sleb128 (line_offset);
3130 /* Generate line entry instruction. */
3131 size += 1;
3132 }
3133 }
3134 ++lt_index;
3135
3136 /* If we're done with a function, end its sequence. */
3137 if (lt_index == separate_line_info_table_in_use
3138 || separate_line_info_table[lt_index].function != function)
3139 {
3140 current_file = 1;
3141 current_line = 1;
3142 /* Advance pc instruction. */
3143 size += 1 + 2;
3144 /* End of line number info. marker. */
3145 size += 1 + size_of_uleb128 (1) + 1;
3146 }
3147 }
a3f97cbb
JW
3148 return size;
3149}
3150
3151/* Return the size of the .debug_pubnames table generated for the
3152 compilation unit. */
3153static unsigned long
3154size_of_pubnames ()
3155{
a3f97cbb 3156 register unsigned long size;
d291dd49
JM
3157 register unsigned i;
3158
a3f97cbb 3159 size = DWARF_PUBNAMES_HEADER_SIZE;
d291dd49 3160 for (i = 0; i < pubname_table_in_use; ++i)
a3f97cbb 3161 {
d291dd49 3162 register pubname_ref p = &pubname_table[i];
7e23cb16 3163 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
a3f97cbb 3164 }
7e23cb16 3165 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
3166 return size;
3167}
3168
3169/* Return the size of the information in the .debug_aranges seciton. */
3170static unsigned long
3171size_of_aranges ()
3172{
3173 register unsigned long size;
3174 size = DWARF_ARANGES_HEADER_SIZE;
3175 /* Count the address/length pair for this compilation unit. */
7e23cb16
JM
3176 size += 2 * PTR_SIZE;
3177 size += 2 * PTR_SIZE * arange_table_in_use;
a3f97cbb 3178 /* Count the two zero words used to terminated the address range table. */
7e23cb16 3179 size += 2 * PTR_SIZE;
a3f97cbb
JW
3180 return size;
3181}
3182\f
3183/**************** DWARF Debug Information Output *****************************/
3184
3185/* Output an unsigned LEB128 quantity. */
3186static void
3187output_uleb128 (value)
3188 register unsigned long value;
3189{
3190 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3191 do
3192 {
3193 register unsigned byte = (value & 0x7f);
3194 value >>= 7;
3195 if (value != 0)
3196 {
3197 /* More bytes to follow. */
3198 byte |= 0x80;
3199 }
3200 fprintf (asm_out_file, "0x%x", byte);
3201 if (value != 0)
3202 {
3203 fprintf (asm_out_file, ",");
3204 }
3205 }
3206 while (value != 0);
3207}
3208
3209/* Output an signed LEB128 quantity. */
3210static void
3211output_sleb128 (value)
3212 register long value;
3213{
3214 register int more;
3215 register unsigned byte;
3216 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3217 do
3218 {
3219 byte = (value & 0x7f);
3220 /* arithmetic shift */
3221 value >>= 7;
3222 more = !((((value == 0) && ((byte & 0x40) == 0))
3223 || ((value == -1) && ((byte & 0x40) != 0))));
3224 if (more)
3225 {
3226 byte |= 0x80;
3227 }
3228 fprintf (asm_out_file, "0x%x", byte);
3229 if (more)
3230 {
3231 fprintf (asm_out_file, ",");
3232 }
3233 }
3234 while (more);
3235}
3236
f37230f0
JM
3237/* Select the encoding of an attribute value. */
3238static enum dwarf_form
3239value_format (v)
a3f97cbb
JW
3240 dw_val_ref v;
3241{
a3f97cbb
JW
3242 switch (v->val_class)
3243 {
3244 case dw_val_class_addr:
f37230f0 3245 return DW_FORM_addr;
a3f97cbb 3246 case dw_val_class_loc:
f37230f0
JM
3247 switch (constant_size (size_of_locs (v->v.val_loc)))
3248 {
3249 case 1:
3250 return DW_FORM_block1;
3251 case 2:
3252 return DW_FORM_block2;
3253 default:
3254 abort ();
3255 }
a3f97cbb 3256 case dw_val_class_const:
f37230f0 3257 return DW_FORM_data4;
a3f97cbb 3258 case dw_val_class_unsigned_const:
7e23cb16
JM
3259 switch (constant_size (v->v.val_unsigned))
3260 {
3261 case 1:
f37230f0 3262 return DW_FORM_data1;
7e23cb16 3263 case 2:
f37230f0 3264 return DW_FORM_data2;
7e23cb16 3265 case 4:
f37230f0 3266 return DW_FORM_data4;
7e23cb16
JM
3267 default:
3268 abort ();
3269 }
a3f97cbb 3270 case dw_val_class_double_const:
f37230f0 3271 return DW_FORM_data8;
a3f97cbb 3272 case dw_val_class_flag:
f37230f0 3273 return DW_FORM_flag;
a3f97cbb 3274 case dw_val_class_die_ref:
f37230f0 3275 return DW_FORM_ref;
a3f97cbb 3276 case dw_val_class_fde_ref:
f37230f0 3277 return DW_FORM_data;
a3f97cbb 3278 case dw_val_class_lbl_id:
f37230f0 3279 return DW_FORM_addr;
a3f97cbb 3280 case dw_val_class_section_offset:
f37230f0 3281 return DW_FORM_data;
a3f97cbb 3282 case dw_val_class_str:
f37230f0 3283 return DW_FORM_string;
a3f97cbb
JW
3284 default:
3285 abort ();
3286 }
f37230f0
JM
3287}
3288
3289/* Output the encoding of an attribute value. */
3290static void
3291output_value_format (v)
3292 dw_val_ref v;
3293{
3294 enum dwarf_form form = value_format (v);
a3f97cbb
JW
3295 output_uleb128 (form);
3296 if (flag_verbose_asm)
3297 {
3298 fprintf (asm_out_file, "\t%s %s",
3299 ASM_COMMENT_START, dwarf_form_name (form));
3300 }
3301 fputc ('\n', asm_out_file);
3302}
3303
3304/* Output the .debug_abbrev section which defines the DIE abbreviation
3305 table. */
3306static void
3307output_abbrev_section ()
3308{
3309 unsigned long abbrev_id;
3310 dw_attr_ref a_attr;
3311 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3312 {
3313 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3314 output_uleb128 (abbrev_id);
3315 if (flag_verbose_asm)
3316 {
3317 fprintf (asm_out_file, "\t%s abbrev code = %u",
3318 ASM_COMMENT_START, abbrev_id);
3319 }
3320 fputc ('\n', asm_out_file);
3321 output_uleb128 (abbrev->die_tag);
3322 if (flag_verbose_asm)
3323 {
3324 fprintf (asm_out_file, "\t%s TAG: %s",
3325 ASM_COMMENT_START, dwarf_tag_name (abbrev->die_tag));
3326 }
3327 fputc ('\n', asm_out_file);
3328 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
3329 (abbrev->die_child != NULL)
3330 ? DW_children_yes : DW_children_no);
3331 if (flag_verbose_asm)
3332 {
3333 fprintf (asm_out_file, "\t%s %s",
3334 ASM_COMMENT_START,
3335 (abbrev->die_child != NULL)
3336 ? "DW_children_yes" : "DW_children_no");
3337 }
3338 fputc ('\n', asm_out_file);
3339 for (a_attr = abbrev->die_attr; a_attr != NULL;
3340 a_attr = a_attr->dw_attr_next)
3341 {
3342 output_uleb128 (a_attr->dw_attr);
3343 if (flag_verbose_asm)
3344 {
3345 fprintf (asm_out_file, "\t%s %s",
3346 ASM_COMMENT_START,
3347 dwarf_attr_name (a_attr->dw_attr));
3348 }
3349 fputc ('\n', asm_out_file);
3350 output_value_format (&a_attr->dw_attr_val);
3351 }
3352 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
3353 }
3354}
3355
3356/* Output location description stack opcode's operands (if any). */
3357static void
3358output_loc_operands (loc)
3359 register dw_loc_descr_ref loc;
3360{
3361 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
3362 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
3363 switch (loc->dw_loc_opc)
3364 {
3365 case DW_OP_addr:
3366 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
3367 fputc ('\n', asm_out_file);
3368 break;
3369 case DW_OP_const1u:
3370 case DW_OP_const1s:
3371 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3372 fputc ('\n', asm_out_file);
3373 break;
3374 case DW_OP_const2u:
3375 case DW_OP_const2s:
3376 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3377 fputc ('\n', asm_out_file);
3378 break;
3379 case DW_OP_const4u:
3380 case DW_OP_const4s:
3381 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
3382 fputc ('\n', asm_out_file);
3383 break;
3384 case DW_OP_const8u:
3385 case DW_OP_const8s:
3386 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3387 val1->v.val_dbl_const.dw_dbl_hi,
3388 val2->v.val_dbl_const.dw_dbl_low);
3389 fputc ('\n', asm_out_file);
3390 break;
3391 case DW_OP_constu:
3392 output_uleb128 (val1->v.val_unsigned);
3393 fputc ('\n', asm_out_file);
3394 break;
3395 case DW_OP_consts:
3396 output_sleb128 (val1->v.val_unsigned);
3397 fputc ('\n', asm_out_file);
3398 break;
3399 case DW_OP_pick:
3400 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
3401 fputc ('\n', asm_out_file);
3402 break;
3403 case DW_OP_plus_uconst:
3404 output_uleb128 (val1->v.val_unsigned);
3405 fputc ('\n', asm_out_file);
3406 break;
3407 case DW_OP_skip:
3408 case DW_OP_bra:
3409 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3410 fputc ('\n', asm_out_file);
3411 break;
3412 case DW_OP_breg0:
3413 case DW_OP_breg1:
3414 case DW_OP_breg2:
3415 case DW_OP_breg3:
3416 case DW_OP_breg4:
3417 case DW_OP_breg5:
3418 case DW_OP_breg6:
3419 case DW_OP_breg7:
3420 case DW_OP_breg8:
3421 case DW_OP_breg9:
3422 case DW_OP_breg10:
3423 case DW_OP_breg11:
3424 case DW_OP_breg12:
3425 case DW_OP_breg13:
3426 case DW_OP_breg14:
3427 case DW_OP_breg15:
3428 case DW_OP_breg16:
3429 case DW_OP_breg17:
3430 case DW_OP_breg18:
3431 case DW_OP_breg19:
3432 case DW_OP_breg20:
3433 case DW_OP_breg21:
3434 case DW_OP_breg22:
3435 case DW_OP_breg23:
3436 case DW_OP_breg24:
3437 case DW_OP_breg25:
3438 case DW_OP_breg26:
3439 case DW_OP_breg27:
3440 case DW_OP_breg28:
3441 case DW_OP_breg29:
3442 case DW_OP_breg30:
3443 case DW_OP_breg31:
3444 output_sleb128 (val1->v.val_int);
3445 fputc ('\n', asm_out_file);
3446 break;
3447 case DW_OP_regx:
3448 output_uleb128 (val1->v.val_unsigned);
3449 fputc ('\n', asm_out_file);
3450 break;
3451 case DW_OP_fbreg:
3452 output_sleb128 (val1->v.val_unsigned);
3453 fputc ('\n', asm_out_file);
3454 break;
3455 case DW_OP_bregx:
3456 output_uleb128 (val1->v.val_unsigned);
3457 fputc ('\n', asm_out_file);
3458 output_sleb128 (val2->v.val_unsigned);
3459 fputc ('\n', asm_out_file);
3460 break;
3461 case DW_OP_piece:
3462 output_uleb128 (val1->v.val_unsigned);
3463 fputc ('\n', asm_out_file);
3464 break;
3465 case DW_OP_deref_size:
3466 case DW_OP_xderef_size:
3467 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3468 fputc ('\n', asm_out_file);
3469 break;
3470 default:
3471 break;
3472 }
3473}
3474
3475/* Compute the offset of a sibling. */
3476static unsigned long
3477sibling_offset (die)
3478 dw_die_ref die;
3479{
3480 unsigned long offset;
3481 if (die->die_child_last == NULL)
3482 {
3483 offset = die->die_offset + size_of_die (die);
3484 }
3485 else
3486 {
3487 offset = sibling_offset (die->die_child_last) + 1;
3488 }
3489 return offset;
3490}
3491
3492/* Output the DIE and its attributes. Called recursively to generate
3493 the definitions of each child DIE. */
3494static void
3495output_die (die)
3496 register dw_die_ref die;
3497{
3498 register dw_attr_ref a;
3499 register dw_die_ref c;
3500 register unsigned long ref_offset;
3501 register unsigned long size;
3502 register dw_loc_descr_ref loc;
3503 output_uleb128 (die->die_abbrev);
3504 if (flag_verbose_asm)
3505 {
3506 fprintf (asm_out_file, "\t%s DIE (0x%x) %s",
3507 ASM_COMMENT_START,
3508 die->die_offset,
3509 dwarf_tag_name (die->die_tag));
3510 }
3511 fputc ('\n', asm_out_file);
3512 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3513 {
3514 switch (a->dw_attr_val.val_class)
3515 {
3516 case dw_val_class_addr:
3517 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
3518 a->dw_attr_val.v.val_addr);
3519 break;
3520 case dw_val_class_loc:
f37230f0
JM
3521 size = size_of_locs (a->dw_attr_val.v.val_loc);
3522 /* Output the block length for this list of location operations. */
3523 switch (constant_size (size))
a3f97cbb 3524 {
f37230f0
JM
3525 case 1:
3526 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
3527 break;
3528 case 2:
3529 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
3530 break;
3531 default:
3532 abort ();
a3f97cbb 3533 }
a3f97cbb
JW
3534 if (flag_verbose_asm)
3535 {
3536 fprintf (asm_out_file, "\t%s %s",
3537 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3538 }
3539 fputc ('\n', asm_out_file);
3540 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3541 loc = loc->dw_loc_next)
3542 {
3543 /* Output the opcode. */
3544 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3545 if (flag_verbose_asm)
3546 {
3547 fprintf (asm_out_file, "\t%s %s",
3548 ASM_COMMENT_START,
3549 dwarf_stack_op_name (loc->dw_loc_opc));
3550 }
3551 fputc ('\n', asm_out_file);
3552 /* Output the operand(s) (if any). */
3553 output_loc_operands (loc);
3554 }
3555 break;
3556 case dw_val_class_const:
3557 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
3558 break;
3559 case dw_val_class_unsigned_const:
7e23cb16
JM
3560 switch (constant_size (a->dw_attr_val.v.val_unsigned))
3561 {
3562 case 1:
3563 ASM_OUTPUT_DWARF_DATA1
3564 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3565 break;
3566 case 2:
3567 ASM_OUTPUT_DWARF_DATA2
3568 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3569 break;
3570 case 4:
3571 ASM_OUTPUT_DWARF_DATA4
3572 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3573 break;
3574 default:
3575 abort ();
3576 }
a3f97cbb
JW
3577 break;
3578 case dw_val_class_double_const:
3579 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3580 a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
3581 a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
3582 break;
3583 case dw_val_class_flag:
3584 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
3585 break;
3586 case dw_val_class_die_ref:
3587 if (a->dw_attr_val.v.val_die_ref != NULL)
3588 {
3589 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
3590 }
3591 else if (a->dw_attr == DW_AT_sibling)
3592 {
3593 ref_offset = sibling_offset(die);
3594 }
3595 else
3596 {
3597 abort ();
3598 }
7e23cb16 3599 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
a3f97cbb
JW
3600 break;
3601 case dw_val_class_fde_ref:
3602 ref_offset = fde_table[a->dw_attr_val.v.val_fde_index].dw_fde_offset;
7e23cb16 3603 fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_OFFSET_ASM_OP,
a3f97cbb
JW
3604 stripattributes (FRAME_SECTION), ref_offset);
3605 break;
3606 case dw_val_class_lbl_id:
3607 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
3608 break;
3609 case dw_val_class_section_offset:
7e23cb16
JM
3610 ASM_OUTPUT_DWARF_OFFSET
3611 (asm_out_file, stripattributes (a->dw_attr_val.v.val_section));
a3f97cbb
JW
3612 break;
3613 case dw_val_class_str:
3614 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
3615 break;
3616 default:
3617 abort ();
3618 }
3619 if (a->dw_attr_val.val_class != dw_val_class_loc)
3620 {
3621 if (flag_verbose_asm)
3622 {
3623 fprintf (asm_out_file, "\t%s %s",
3624 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3625 }
3626 fputc ('\n', asm_out_file);
3627 }
3628 }
3629 for (c = die->die_child; c != NULL; c = c->die_sib)
3630 {
3631 output_die (c);
3632 }
3633 if (die->die_child != NULL)
3634 {
3635 /* Add null byte to terminate sibling list. */
3636 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3637 fputc ('\n', asm_out_file);
3638 }
3639}
3640
3641/* Output the compilation unit that appears at the beginning of the
3642 .debug_info section, and precedes the DIE descriptions. */
3643static void
3644output_compilation_unit_header ()
3645{
7e23cb16 3646 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
a3f97cbb
JW
3647 if (flag_verbose_asm)
3648 {
3649 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
3650 ASM_COMMENT_START);
3651 }
3652 fputc ('\n', asm_out_file);
7e23cb16 3653 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
a3f97cbb
JW
3654 if (flag_verbose_asm)
3655 {
3656 fprintf (asm_out_file, "\t%s DWARF version number",
3657 ASM_COMMENT_START);
3658 }
3659 fputc ('\n', asm_out_file);
7e23cb16 3660 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
a3f97cbb
JW
3661 if (flag_verbose_asm)
3662 {
3663 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
3664 ASM_COMMENT_START);
3665 }
3666 fputc ('\n', asm_out_file);
7e23cb16 3667 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
a3f97cbb
JW
3668 if (flag_verbose_asm)
3669 {
3670 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)",
3671 ASM_COMMENT_START);
3672 }
3673 fputc ('\n', asm_out_file);
3674}
3675
3676/* Return the size of a Call Frame Instruction. */
3677static unsigned long
3678size_of_cfi (cfi)
3679 dw_cfi_ref cfi;
3680{
3681 register unsigned long size;
3682 /* count the 1-byte opcode */
3683 size = 1;
3684 switch (cfi->dw_cfi_opc)
3685 {
3686 case DW_CFA_offset:
3687 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3688 break;
3689 case DW_CFA_set_loc:
3690 size += PTR_SIZE;
3691 break;
3692 case DW_CFA_advance_loc1:
3693 size += 1;
3694 break;
3695 case DW_CFA_advance_loc2:
3696 size += 2;
3697 break;
3698 case DW_CFA_advance_loc4:
3699 size += 4;
3700 break;
3701#ifdef MIPS_DEBUGGING_INFO
3702 case DW_CFA_MIPS_advance_loc8:
3703 size += 8;
3704 break;
3705#endif
3706 case DW_CFA_offset_extended:
3707 case DW_CFA_def_cfa:
3708 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3709 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3710 break;
3711 case DW_CFA_restore_extended:
3712 case DW_CFA_undefined:
3713 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3714 break;
3715 case DW_CFA_same_value:
3716 case DW_CFA_def_cfa_register:
3717 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3718 break;
3719 case DW_CFA_register:
3720 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3721 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3722 break;
3723 case DW_CFA_def_cfa_offset:
3724 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
3725 break;
3726 default:
3727 break;
3728 }
3729 return size;
3730}
3731
3732/* Return the size of an FDE sans the length word. */
3733inline unsigned long
3734size_of_fde (fde, npad)
3735 dw_fde_ref fde;
3736 unsigned long *npad;
3737{
3738 register dw_cfi_ref cfi;
3739 register unsigned long aligned_size;
3740 register unsigned long size;
3741 size = DWARF_FDE_HEADER_SIZE;
3742 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3743 {
3744 size += size_of_cfi(cfi);
3745 }
7e23cb16
JM
3746 /* Round the size up to a word boundary. */
3747 aligned_size = DWARF_ROUND (size, PTR_SIZE);
a3f97cbb
JW
3748 *npad = aligned_size - size;
3749 return aligned_size;
3750}
3751
3752/* Calculate the size of the FDE table, and establish the offset
3753 of each FDE in the .debug_frame section. */
3754static void
3755calc_fde_sizes ()
3756{
3757 register unsigned long i;
3758 register dw_fde_ref fde;
3759 register unsigned long fde_size;
3760 unsigned long fde_pad;
3761 for (i = 0; i < fde_table_in_use; ++i)
3762 {
3763 fde = &fde_table[i];
3764 fde->dw_fde_offset = next_fde_offset;
3765 fde_size = size_of_fde (fde, &fde_pad);
3766 next_fde_offset += fde_size;
3767 }
3768}
3769
3770/* Output a Call Frame Information opcode and its operand(s). */
3771static void
3772output_cfi (cfi, fde)
3773 register dw_cfi_ref cfi;
3774 register dw_fde_ref fde;
3775{
3776 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3777 {
3778 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3779 cfi->dw_cfi_opc
3780 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
3781 if (flag_verbose_asm)
3782 {
3783 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc", ASM_COMMENT_START);
3784 }
3785 fputc ('\n', asm_out_file);
3786 }
3787 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3788 {
3789 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3790 cfi->dw_cfi_opc
3791 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3792 if (flag_verbose_asm)
3793 {
3794 fprintf (asm_out_file, "\t%s DW_CFA_offset", ASM_COMMENT_START);
3795 }
3796 fputc ('\n', asm_out_file);
3797 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3798 fputc ('\n', asm_out_file);
3799 }
3800 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3801 {
3802 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3803 cfi->dw_cfi_opc
3804 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3805 if (flag_verbose_asm)
3806 {
3807 fprintf (asm_out_file, "\t%s DW_CFA_restore", ASM_COMMENT_START);
3808 }
3809 fputc ('\n', asm_out_file);
3810 }
3811 else
3812 {
3813 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
3814 if (flag_verbose_asm)
3815 {
3816 fprintf (asm_out_file, "\t%s %s",
3817 ASM_COMMENT_START,
3818 dwarf_cfi_name (cfi->dw_cfi_opc));
3819 }
3820 fputc ('\n', asm_out_file);
3821 switch (cfi->dw_cfi_opc)
3822 {
3823 case DW_CFA_set_loc:
3824 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
3825 cfi->dw_cfi_oprnd1.dw_cfi_addr);
3826 fputc ('\n', asm_out_file);
3827 break;
3828 case DW_CFA_advance_loc1:
3829 /* TODO: not currently implemented. */
3830 abort ();
3831 break;
3832 case DW_CFA_advance_loc2:
3833 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
3834 cfi->dw_cfi_oprnd1.dw_cfi_addr,
3835 fde->dw_fde_begin);
3836 fputc ('\n', asm_out_file);
3837 break;
3838 case DW_CFA_advance_loc4:
3839 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
3840 cfi->dw_cfi_oprnd1.dw_cfi_addr,
3841 fde->dw_fde_begin);
3842 fputc ('\n', asm_out_file);
3843 break;
3844#ifdef MIPS_DEBUGGING_INFO
3845 case DW_CFA_MIPS_advance_loc8:
3846 /* TODO: not currently implemented. */
3847 abort ();
3848 break;
3849#endif
3850 case DW_CFA_offset_extended:
3851 case DW_CFA_def_cfa:
3852 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3853 fputc ('\n', asm_out_file);
3854 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3855 fputc ('\n', asm_out_file);
3856 break;
3857 case DW_CFA_restore_extended:
3858 case DW_CFA_undefined:
3859 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3860 fputc ('\n', asm_out_file);
3861 break;
3862 case DW_CFA_same_value:
3863 case DW_CFA_def_cfa_register:
3864 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3865 fputc ('\n', asm_out_file);
3866 break;
3867 case DW_CFA_register:
3868 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3869 fputc ('\n', asm_out_file);
3870 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3871 fputc ('\n', asm_out_file);
3872 break;
3873 case DW_CFA_def_cfa_offset:
3874 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
3875 fputc ('\n', asm_out_file);
3876 break;
3877 default:
3878 break;
3879 }
3880 }
3881}
3882
3883/* Output the call frame information used to used to record information
3884 that relates to calculating the frame pointer, and records the
3885 location of saved registers. */
3886static void
3887output_call_frame_info ()
3888{
3889 register unsigned long i, j;
3890 register dw_fde_ref fde;
3891 register unsigned long fde_size;
3892 dw_cfi_node cfi_node;
3893 register dw_cfi_ref cfi;
3894 unsigned long fde_pad;
3895
3896 /* Output the CIE. */
7e23cb16 3897 ASM_OUTPUT_DWARF_DATA (asm_out_file, DWARF_CIE_SIZE - DWARF_OFFSET_SIZE);
a3f97cbb
JW
3898 if (flag_verbose_asm)
3899 {
3900 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
3901 ASM_COMMENT_START);
3902 }
3903 fputc ('\n', asm_out_file);
3904 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
3905 if (flag_verbose_asm)
3906 {
3907 fprintf (asm_out_file, "\t%s CIE Identifier Tag",
3908 ASM_COMMENT_START);
3909 }
3910 fputc ('\n', asm_out_file);
7e23cb16
JM
3911 if (DWARF_OFFSET_SIZE == 8)
3912 {
3913 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
3914 fputc ('\n', asm_out_file);
3915 }
a3f97cbb
JW
3916 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
3917 if (flag_verbose_asm)
3918 {
3919 fprintf (asm_out_file, "\t%s CIE Version",
3920 ASM_COMMENT_START);
3921 }
3922 fputc ('\n', asm_out_file);
3923 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3924 if (flag_verbose_asm)
3925 {
3926 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
3927 ASM_COMMENT_START);
3928 }
3929 fputc ('\n', asm_out_file);
3930 output_uleb128 (1);
3931 if (flag_verbose_asm)
3932 {
3933 fprintf (asm_out_file, "\t%s CIE Code Alignment Factor",
3934 ASM_COMMENT_START);
3935 }
3936 fputc ('\n', asm_out_file);
3937 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
3938 if (flag_verbose_asm)
3939 {
3940 fprintf (asm_out_file, "\t%s CIE Data Alignment Factor",
3941 ASM_COMMENT_START);
3942 }
3943 fputc ('\n', asm_out_file);
c8cc5c4a 3944 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
a3f97cbb
JW
3945 if (flag_verbose_asm)
3946 {
3947 fprintf (asm_out_file, "\t%s CIE RA Column",
3948 ASM_COMMENT_START);
3949 }
3950 fputc ('\n', asm_out_file);
3951
3952 /* Output the CFA instructions common to all FDE's. */
3953
3954#ifdef MIPS_DEBUGGING_INFO
3955
a3f97cbb
JW
3956 bzero (&cfi_node, sizeof (dw_cfi_node));
3957 cfi = &cfi_node;
c8cc5c4a
JM
3958
3959 /* On entry, the Call Frame Address is in the stack pointer register. */
3960 cfi->dw_cfi_opc = DW_CFA_def_cfa;
3961 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
3962 = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
3963 cfi->dw_cfi_oprnd2.dw_cfi_offset = 0;
3964 output_cfi (cfi);
3965
3966 /* Set the RA on entry to be the contents of r31. */
a3f97cbb 3967 cfi->dw_cfi_opc = DW_CFA_register;
c8cc5c4a
JM
3968 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_RETURN_COLUMN;
3969 cfi->dw_cfi_oprnd2.dw_cfi_reg_num
3970 = DWARF_FRAME_REGNUM (GP_REG_FIRST + 31);
a3f97cbb
JW
3971 output_cfi (cfi);
3972
3973#endif
3974
3975 /* Pad the CIE out to an address sized boundary. */
3976 for (i = DWARF_CIE_HEADER_SIZE; i < DWARF_CIE_SIZE; ++i)
3977 {
3978 /* Pad out to a pointer size boundary */
3979 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
3980 if (flag_verbose_asm)
3981 {
3982 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
3983 ASM_COMMENT_START);
3984 }
3985 fputc ('\n', asm_out_file);
3986 }
3987
3988 /* Loop through all of the FDE's. */
3989 for (i = 0; i < fde_table_in_use; ++i)
3990 {
3991 fde = &fde_table[i];
3992 fde_size = size_of_fde (fde, &fde_pad);
7e23cb16 3993 ASM_OUTPUT_DWARF_DATA (asm_out_file, fde_size - DWARF_OFFSET_SIZE);
a3f97cbb
JW
3994 if (flag_verbose_asm)
3995 {
3996 fprintf (asm_out_file, "\t%s FDE Length",
3997 ASM_COMMENT_START);
3998 }
3999 fputc ('\n', asm_out_file);
7e23cb16 4000 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
a3f97cbb
JW
4001 if (flag_verbose_asm)
4002 {
4003 fprintf (asm_out_file, "\t%s FDE CIE offset",
4004 ASM_COMMENT_START);
4005 }
4006 fputc ('\n', asm_out_file);
4007 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
4008 if (flag_verbose_asm)
4009 {
4010 fprintf (asm_out_file, "\t%s FDE initial location",
4011 ASM_COMMENT_START);
4012 }
4013 fputc ('\n', asm_out_file);
7e23cb16
JM
4014 ASM_OUTPUT_DWARF_ADDR_DELTA
4015 (asm_out_file, fde->dw_fde_end, fde->dw_fde_begin);
a3f97cbb
JW
4016 if (flag_verbose_asm)
4017 {
4018 fprintf (asm_out_file, "\t%s FDE address range",
4019 ASM_COMMENT_START);
4020 }
4021 fputc ('\n', asm_out_file);
4022
4023 /* Loop through the Call Frame Instructions associated with
4024 this FDE. */
4025 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
4026 {
4027 output_cfi (cfi, fde);
4028 }
4029
4030 /* Pad to a double word boundary. */
4031 for (j = 0; j < fde_pad; ++j)
4032 {
4033 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4034 if (flag_verbose_asm)
4035 {
4036 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4037 ASM_COMMENT_START);
4038 }
4039 fputc ('\n', asm_out_file);
4040 }
4041 }
4042}
4043
d291dd49
JM
4044/* Add a new entry to .debug_pubnames if appropriate. */
4045static void
4046add_pubname (decl, die)
4047 tree decl;
4048 dw_die_ref die;
4049{
4050 pubname_ref p;
4051
4052 if (! TREE_PUBLIC (decl))
4053 return;
4054
4055 if (pubname_table_in_use == pubname_table_allocated)
4056 {
4057 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
4058 pubname_table = (pubname_ref) xrealloc
4059 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
4060 }
4061 p = &pubname_table[pubname_table_in_use++];
4062 p->die = die;
4063 p->name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4064}
4065
a3f97cbb
JW
4066/* Output the public names table used to speed up access to externally
4067 visible names. For now, only generate entries for externally
4068 visible procedures. */
4069static void
4070output_pubnames ()
4071{
d291dd49
JM
4072 register unsigned i;
4073 {
4074 register unsigned long pubnames_length = size_of_pubnames ();
7e23cb16 4075 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
d291dd49 4076 }
a3f97cbb
JW
4077 if (flag_verbose_asm)
4078 {
4079 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
4080 ASM_COMMENT_START);
4081 }
4082 fputc ('\n', asm_out_file);
4083 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4084 if (flag_verbose_asm)
4085 {
4086 fprintf (asm_out_file, "\t%s DWARF Version",
4087 ASM_COMMENT_START);
4088 }
4089 fputc ('\n', asm_out_file);
7e23cb16 4090 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
a3f97cbb
JW
4091 if (flag_verbose_asm)
4092 {
4093 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4094 ASM_COMMENT_START);
4095 }
4096 fputc ('\n', asm_out_file);
7e23cb16 4097 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
a3f97cbb
JW
4098 if (flag_verbose_asm)
4099 {
4100 fprintf (asm_out_file, "\t%s Compilation Unit Length",
4101 ASM_COMMENT_START);
4102 }
4103 fputc ('\n', asm_out_file);
d291dd49 4104 for (i = 0; i < pubname_table_in_use; ++i)
a3f97cbb 4105 {
d291dd49 4106 register pubname_ref pub = &pubname_table[i];
7e23cb16 4107 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
d291dd49 4108 if (flag_verbose_asm)
a3f97cbb 4109 {
d291dd49
JM
4110 fprintf (asm_out_file, "\t%s DIE offset",
4111 ASM_COMMENT_START);
a3f97cbb 4112 }
d291dd49
JM
4113 fputc ('\n', asm_out_file);
4114
4115 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
4116 if (flag_verbose_asm)
4117 {
4118 fprintf (asm_out_file, "%s external name",
4119 ASM_COMMENT_START);
4120 }
4121 fputc ('\n', asm_out_file);
a3f97cbb 4122 }
7e23cb16 4123 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
a3f97cbb
JW
4124 fputc ('\n', asm_out_file);
4125}
4126
d291dd49
JM
4127/* Add a new entry to .debug_aranges if appropriate. */
4128static void
4129add_arange (decl, die)
4130 tree decl;
4131 dw_die_ref die;
4132{
4133 if (! DECL_SECTION_NAME (decl))
4134 return;
4135
4136 if (arange_table_in_use == arange_table_allocated)
4137 {
4138 arange_table_allocated += ARANGE_TABLE_INCREMENT;
4139 arange_table = (arange_ref) xrealloc
4140 (arange_table, arange_table_allocated * sizeof (dw_die_ref));
4141 }
4142 arange_table[arange_table_in_use++] = die;
4143}
4144
a3f97cbb
JW
4145/* Output the information that goes into the .debug_aranges table.
4146 Namely, define the beginning and ending address range of the
4147 text section generated for this compilation unit. */
4148static void
4149output_aranges ()
4150{
d291dd49
JM
4151 register unsigned i;
4152 {
4153 register unsigned long aranges_length = size_of_aranges ();
7e23cb16 4154 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
d291dd49 4155 }
a3f97cbb
JW
4156 if (flag_verbose_asm)
4157 {
4158 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
4159 ASM_COMMENT_START);
4160 }
4161 fputc ('\n', asm_out_file);
4162 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4163 if (flag_verbose_asm)
4164 {
4165 fprintf (asm_out_file, "\t%s DWARF Version",
4166 ASM_COMMENT_START);
4167 }
4168 fputc ('\n', asm_out_file);
7e23cb16 4169 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
a3f97cbb
JW
4170 if (flag_verbose_asm)
4171 {
4172 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4173 ASM_COMMENT_START);
4174 }
4175 fputc ('\n', asm_out_file);
4176 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
4177 if (flag_verbose_asm)
4178 {
4179 fprintf (asm_out_file, "\t%s Size of Address",
4180 ASM_COMMENT_START);
4181 }
4182 fputc ('\n', asm_out_file);
4183 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4184 if (flag_verbose_asm)
4185 {
4186 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
4187 ASM_COMMENT_START);
4188 }
4189 fputc ('\n', asm_out_file);
4190 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
7e23cb16
JM
4191 if (PTR_SIZE == 8)
4192 fprintf (asm_out_file, ",0,0");
a3f97cbb
JW
4193 if (flag_verbose_asm)
4194 {
7e23cb16
JM
4195 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
4196 ASM_COMMENT_START, 2 * PTR_SIZE);
a3f97cbb
JW
4197 }
4198 fputc ('\n', asm_out_file);
bdb669cb 4199 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
a3f97cbb
JW
4200 if (flag_verbose_asm)
4201 {
4202 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4203 }
4204 fputc ('\n', asm_out_file);
5c90448c 4205 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
a3f97cbb
JW
4206 if (flag_verbose_asm)
4207 {
4208 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4209 }
4210 fputc ('\n', asm_out_file);
d291dd49
JM
4211 for (i = 0; i < arange_table_in_use; ++i)
4212 {
4213 dw_die_ref a = arange_table[i];
4214 if (a->die_tag == DW_TAG_subprogram)
4215 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
4216 else
4217 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_string (a, DW_AT_name));
4218 if (flag_verbose_asm)
4219 {
4220 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4221 }
4222 fputc ('\n', asm_out_file);
4223 if (a->die_tag == DW_TAG_subprogram)
7e23cb16
JM
4224 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
4225 get_AT_low_pc (a));
d291dd49 4226 else
7e23cb16
JM
4227 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
4228 get_AT_unsigned (a, DW_AT_byte_size));
d291dd49
JM
4229 if (flag_verbose_asm)
4230 {
4231 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4232 }
4233 fputc ('\n', asm_out_file);
4234 }
a3f97cbb 4235 /* Output the terminator words. */
7e23cb16 4236 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
a3f97cbb 4237 fputc ('\n', asm_out_file);
7e23cb16 4238 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
a3f97cbb
JW
4239 fputc ('\n', asm_out_file);
4240}
4241
4242/* Output the source line number correspondence information. This
4243 information goes into the .debug_line section. */
4244static void
4245output_line_info ()
4246{
a3f97cbb
JW
4247 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4248 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4249 register unsigned opc;
4250 register unsigned n_op_args;
a3f97cbb
JW
4251 register unsigned long ft_index;
4252 register unsigned long lt_index;
4253 register unsigned long current_line;
4254 register long line_offset;
4255 register long line_delta;
4256 register unsigned long current_file;
e90b62db 4257 register unsigned long function;
7e23cb16 4258 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
a3f97cbb
JW
4259 if (flag_verbose_asm)
4260 {
4261 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
4262 ASM_COMMENT_START);
4263 }
4264 fputc ('\n', asm_out_file);
4265 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4266 if (flag_verbose_asm)
4267 {
4268 fprintf (asm_out_file, "\t%s DWARF Version",
4269 ASM_COMMENT_START);
4270 }
4271 fputc ('\n', asm_out_file);
7e23cb16 4272 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
a3f97cbb
JW
4273 if (flag_verbose_asm)
4274 {
4275 fprintf (asm_out_file, "\t%s Prolog Length",
4276 ASM_COMMENT_START);
4277 }
4278 fputc ('\n', asm_out_file);
4279 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
4280 if (flag_verbose_asm)
4281 {
4282 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
4283 ASM_COMMENT_START);
4284 }
4285 fputc ('\n', asm_out_file);
4286 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
4287 if (flag_verbose_asm)
4288 {
4289 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
4290 ASM_COMMENT_START);
4291 }
4292 fputc ('\n', asm_out_file);
4293 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
4294 if (flag_verbose_asm)
4295 {
4296 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
4297 ASM_COMMENT_START);
4298 }
4299 fputc ('\n', asm_out_file);
4300 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
4301 if (flag_verbose_asm)
4302 {
4303 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
4304 ASM_COMMENT_START);
4305 }
4306 fputc ('\n', asm_out_file);
4307 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
4308 if (flag_verbose_asm)
4309 {
4310 fprintf (asm_out_file, "\t%s Special Opcode Base",
4311 ASM_COMMENT_START);
4312 }
4313 fputc ('\n', asm_out_file);
4314 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
4315 {
4316 switch (opc)
4317 {
4318 case DW_LNS_advance_pc:
4319 case DW_LNS_advance_line:
4320 case DW_LNS_set_file:
4321 case DW_LNS_set_column:
4322 case DW_LNS_fixed_advance_pc:
4323 n_op_args = 1;
4324 break;
4325 default:
4326 n_op_args = 0;
4327 break;
4328 }
4329 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
4330 if (flag_verbose_asm)
4331 {
4332 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
4333 ASM_COMMENT_START, opc, n_op_args);
4334 }
4335 fputc ('\n', asm_out_file);
4336 }
4337 if (flag_verbose_asm)
4338 {
4339 fprintf (asm_out_file, "%s Include Directory Table\n",
4340 ASM_COMMENT_START);
4341 }
4342 /* Include directory table is empty, at present */
4343 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4344 fputc ('\n', asm_out_file);
4345 if (flag_verbose_asm)
4346 {
4347 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
4348 }
4349 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4350 {
4351 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
4352 if (flag_verbose_asm)
4353 {
4354 fprintf (asm_out_file, "%s File Entry: 0x%x",
4355 ASM_COMMENT_START, ft_index);
4356 }
4357 fputc ('\n', asm_out_file);
4358 /* Include directory index */
4359 output_uleb128 (0);
4360 fputc ('\n', asm_out_file);
4361 /* Modification time */
4362 output_uleb128 (0);
4363 fputc ('\n', asm_out_file);
4364 /* File length in bytes */
4365 output_uleb128 (0);
4366 fputc ('\n', asm_out_file);
4367 }
4368 /* Terminate the file name table */
4369 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4370 fputc ('\n', asm_out_file);
4371
4372 /* Set the address register to the first location in the text section */
4373 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4374 if (flag_verbose_asm)
4375 {
4376 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
4377 }
4378 fputc ('\n', asm_out_file);
4379 output_uleb128 (1 + PTR_SIZE);
4380 fputc ('\n', asm_out_file);
4381 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4382 fputc ('\n', asm_out_file);
bdb669cb 4383 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
a3f97cbb
JW
4384 fputc ('\n', asm_out_file);
4385
4386 /* Generate the line number to PC correspondence table, encoded as
4387 a series of state machine operations. */
4388 current_file = 1;
4389 current_line = 1;
bdb669cb 4390 strcpy (prev_line_label, TEXT_SECTION);
a3f97cbb
JW
4391 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4392 {
e90b62db 4393 register dw_line_info_ref line_info;
a3f97cbb
JW
4394 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4395 if (flag_verbose_asm)
4396 {
4397 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4398 ASM_COMMENT_START);
4399 }
4400 fputc ('\n', asm_out_file);
5c90448c 4401 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
a3f97cbb
JW
4402 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4403 fputc ('\n', asm_out_file);
4404 line_info = &line_info_table[lt_index];
4405 if (line_info->dw_file_num != current_file)
4406 {
4407 current_file = line_info->dw_file_num;
4408 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
4409 if (flag_verbose_asm)
4410 {
4411 fprintf (asm_out_file,
4412 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4413 }
4414 fputc ('\n', asm_out_file);
4415 output_uleb128 (current_file);
4416 if (flag_verbose_asm)
4417 {
4418 fprintf (asm_out_file, "\t%s \"%s\"",
4419 ASM_COMMENT_START, file_table[current_file]);
4420 }
4421 fputc ('\n', asm_out_file);
4422 }
4423 if (line_info->dw_line_num != current_line)
4424 {
4425 line_offset = line_info->dw_line_num - current_line;
4426 line_delta = line_offset - DWARF_LINE_BASE;
4427 current_line = line_info->dw_line_num;
4428 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4429 {
4430 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4431 DWARF_LINE_OPCODE_BASE + line_delta);
4432 if (flag_verbose_asm)
4433 {
4434 fprintf (asm_out_file,
4435 "\t%s line %d", ASM_COMMENT_START, current_line);
4436 }
4437 fputc ('\n', asm_out_file);
4438 }
4439 else
4440 {
4441 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4442 if (flag_verbose_asm)
4443 {
4444 fprintf (asm_out_file,
4445 "\t%s advance to line %d",
4446 ASM_COMMENT_START, current_line);
4447 }
4448 fputc ('\n', asm_out_file);
4449 output_sleb128 (line_offset);
4450 fputc ('\n', asm_out_file);
4451 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
4452 fputc ('\n', asm_out_file);
4453 }
4454 }
4455 strcpy (prev_line_label, line_label);
4456 }
4457
bdb669cb 4458 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
a3f97cbb
JW
4459 if (flag_verbose_asm)
4460 {
bdb669cb
JM
4461 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4462 ASM_COMMENT_START);
a3f97cbb
JW
4463 }
4464 fputc ('\n', asm_out_file);
5c90448c 4465 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
a3f97cbb 4466 fputc ('\n', asm_out_file);
bdb669cb 4467
a3f97cbb
JW
4468 /* Output the marker for the end of the line number info. */
4469 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4470 if (flag_verbose_asm)
4471 {
4472 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
4473 }
4474 fputc ('\n', asm_out_file);
4475 output_uleb128 (1);
4476 fputc ('\n', asm_out_file);
4477 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
4478 fputc ('\n', asm_out_file);
e90b62db
JM
4479
4480 function = 0;
4481 current_file = 1;
4482 current_line = 1;
4483 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4484 {
4485 register dw_separate_line_info_ref line_info
4486 = &separate_line_info_table[lt_index];
5c90448c
JM
4487 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
4488 lt_index);
e90b62db
JM
4489 if (function != line_info->function)
4490 {
4491 function = line_info->function;
4492 /* Set the address register to the first line in the function */
4493 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4494 if (flag_verbose_asm)
4495 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
4496 ASM_COMMENT_START);
4497 fputc ('\n', asm_out_file);
4498 output_uleb128 (1 + PTR_SIZE);
4499 fputc ('\n', asm_out_file);
4500 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4501 fputc ('\n', asm_out_file);
4502 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
4503 fputc ('\n', asm_out_file);
4504 }
4505 else
4506 {
4507 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4508 if (flag_verbose_asm)
4509 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4510 ASM_COMMENT_START);
4511 fputc ('\n', asm_out_file);
4512 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4513 fputc ('\n', asm_out_file);
4514 }
4515 if (line_info->dw_file_num != current_file)
4516 {
4517 current_file = line_info->dw_file_num;
4518 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
4519 if (flag_verbose_asm)
4520 {
4521 fprintf (asm_out_file,
4522 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4523 }
4524 fputc ('\n', asm_out_file);
4525 output_uleb128 (current_file);
4526 if (flag_verbose_asm)
4527 {
4528 fprintf (asm_out_file, "\t%s \"%s\"",
4529 ASM_COMMENT_START, file_table[current_file]);
4530 }
4531 fputc ('\n', asm_out_file);
4532 }
4533 if (line_info->dw_line_num != current_line)
4534 {
4535 line_offset = line_info->dw_line_num - current_line;
4536 line_delta = line_offset - DWARF_LINE_BASE;
4537 current_line = line_info->dw_line_num;
4538 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4539 {
4540 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4541 DWARF_LINE_OPCODE_BASE + line_delta);
4542 if (flag_verbose_asm)
4543 {
4544 fprintf (asm_out_file,
4545 "\t%s line %d", ASM_COMMENT_START, current_line);
4546 }
4547 fputc ('\n', asm_out_file);
4548 }
4549 else
4550 {
4551 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4552 if (flag_verbose_asm)
4553 {
4554 fprintf (asm_out_file,
4555 "\t%s advance to line %d",
4556 ASM_COMMENT_START, current_line);
4557 }
4558 fputc ('\n', asm_out_file);
4559 output_sleb128 (line_offset);
4560 fputc ('\n', asm_out_file);
4561 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
4562 fputc ('\n', asm_out_file);
4563 }
4564 }
4565 ++lt_index;
4566 strcpy (prev_line_label, line_label);
4567
4568 /* If we're done with a function, end its sequence. */
4569 if (lt_index == separate_line_info_table_in_use
4570 || separate_line_info_table[lt_index].function != function)
4571 {
4572 current_file = 1;
4573 current_line = 1;
4574 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4575 if (flag_verbose_asm)
4576 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4577 ASM_COMMENT_START);
4578 fputc ('\n', asm_out_file);
5c90448c 4579 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
e90b62db
JM
4580 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4581 fputc ('\n', asm_out_file);
4582
4583 /* Output the marker for the end of this sequence. */
4584 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4585 if (flag_verbose_asm)
4586 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
4587 ASM_COMMENT_START);
4588 fputc ('\n', asm_out_file);
4589 output_uleb128 (1);
4590 fputc ('\n', asm_out_file);
4591 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
4592 fputc ('\n', asm_out_file);
4593 }
4594 }
a3f97cbb
JW
4595}
4596\f
4597/**************** attribute support utilities ********************************/
4598
4599/*
4600 * Given a pointer to a BLOCK node return non-zero if (and only if) the node
4601 * in question represents the outermost pair of curly braces (i.e. the "body
4602 * block") of a function or method.
4603 *
4604 * For any BLOCK node representing a "body block" of a function or method, the
4605 * BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
4606 * represents the outermost (function) scope for the function or method (i.e.
4607 * the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
4608 * *that* node in turn will point to the relevant FUNCTION_DECL node.
4609 */
4610inline int
4611is_body_block (stmt)
4612 register tree stmt;
4613{
4614 if (TREE_CODE (stmt) == BLOCK)
4615 {
4616 register tree parent = BLOCK_SUPERCONTEXT (stmt);
4617
4618 if (TREE_CODE (parent) == BLOCK)
4619 {
4620 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
4621
4622 if (TREE_CODE (grandparent) == FUNCTION_DECL)
4623 return 1;
4624 }
4625 }
4626 return 0;
4627}
4628
a3f97cbb
JW
4629/* Given a pointer to a tree node for some base type, return a pointer to
4630 a DIE that describes the given type.
4631
4632 This routine must only be called for GCC type nodes that correspond to
4633 Dwarf base (fundamental) types. */
4634static dw_die_ref
4635base_type_die (type)
4636 register tree type;
4637{
a9d38797
JM
4638 register dw_die_ref base_type_result;
4639 register char *type_name;
4640 register enum dwarf_type encoding;
a3f97cbb 4641
a9d38797
JM
4642 if (TREE_CODE (type) == ERROR_MARK
4643 || TREE_CODE (type) == VOID_TYPE)
a3f97cbb
JW
4644 return 0;
4645
a9d38797
JM
4646 {
4647 register tree name = TYPE_NAME (type);
4648 if (TREE_CODE (name) == TYPE_DECL)
4649 name = DECL_NAME (name);
4650 type_name = IDENTIFIER_POINTER (name);
4651 }
4652
a3f97cbb
JW
4653 switch (TREE_CODE (type))
4654 {
a3f97cbb 4655 case INTEGER_TYPE:
a9d38797 4656 /* Carefully distinguish the C character types, without messing
a3f97cbb
JW
4657 up if the language is not C. Note that we check only for the names
4658 that contain spaces; other names might occur by coincidence in other
4659 languages. */
a9d38797
JM
4660 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
4661 && (type == char_type_node
4662 || ! strcmp (type_name, "signed char")
4663 || ! strcmp (type_name, "unsigned char"))))
a3f97cbb 4664 {
a9d38797
JM
4665 if (TREE_UNSIGNED (type))
4666 encoding = DW_ATE_unsigned;
4667 else
4668 encoding = DW_ATE_signed;
4669 break;
a3f97cbb 4670 }
a9d38797 4671 /* else fall through */
a3f97cbb 4672
a9d38797
JM
4673 case CHAR_TYPE:
4674 /* GNU Pascal/Ada CHAR type. Not used in C. */
4675 if (TREE_UNSIGNED (type))
4676 encoding = DW_ATE_unsigned_char;
4677 else
4678 encoding = DW_ATE_signed_char;
a3f97cbb
JW
4679 break;
4680
4681 case REAL_TYPE:
a9d38797 4682 encoding = DW_ATE_float;
a3f97cbb
JW
4683 break;
4684
4685 case COMPLEX_TYPE:
a9d38797 4686 encoding = DW_ATE_complex_float;
a3f97cbb
JW
4687 break;
4688
4689 case BOOLEAN_TYPE:
a9d38797
JM
4690 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
4691 encoding = DW_ATE_boolean;
a3f97cbb
JW
4692 break;
4693
4694 default:
a9d38797 4695 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
a3f97cbb
JW
4696 }
4697
a9d38797
JM
4698 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
4699 add_AT_string (base_type_result, DW_AT_name, type_name);
4700 add_AT_unsigned (base_type_result, DW_AT_byte_size,
4701 TYPE_PRECISION (type) / BITS_PER_UNIT);
4702 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
a3f97cbb
JW
4703
4704 return base_type_result;
4705}
4706
4707/* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
4708 the Dwarf "root" type for the given input type. The Dwarf "root" type of
4709 a given type is generally the same as the given type, except that if the
4710 given type is a pointer or reference type, then the root type of the given
4711 type is the root type of the "basis" type for the pointer or reference
4712 type. (This definition of the "root" type is recursive.) Also, the root
4713 type of a `const' qualified type or a `volatile' qualified type is the
4714 root type of the given type without the qualifiers. */
4715static tree
4716root_type (type)
4717 register tree type;
4718{
4719 if (TREE_CODE (type) == ERROR_MARK)
4720 return error_mark_node;
4721
4722 switch (TREE_CODE (type))
4723 {
4724 case ERROR_MARK:
4725 return error_mark_node;
4726
4727 case POINTER_TYPE:
4728 case REFERENCE_TYPE:
4729 return type_main_variant (root_type (TREE_TYPE (type)));
4730
4731 default:
4732 return type_main_variant (type);
4733 }
4734}
4735
4736/* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
4737 given input type is a Dwarf "fundamental" type. Otherwise return null. */
4738inline int
4739is_base_type (type)
4740 register tree type;
4741{
4742 switch (TREE_CODE (type))
4743 {
4744 case ERROR_MARK:
4745 case VOID_TYPE:
4746 case INTEGER_TYPE:
4747 case REAL_TYPE:
4748 case COMPLEX_TYPE:
4749 case BOOLEAN_TYPE:
4750 case CHAR_TYPE:
4751 return 1;
4752
4753 case SET_TYPE:
4754 case ARRAY_TYPE:
4755 case RECORD_TYPE:
4756 case UNION_TYPE:
4757 case QUAL_UNION_TYPE:
4758 case ENUMERAL_TYPE:
4759 case FUNCTION_TYPE:
4760 case METHOD_TYPE:
4761 case POINTER_TYPE:
4762 case REFERENCE_TYPE:
4763 case FILE_TYPE:
4764 case OFFSET_TYPE:
4765 case LANG_TYPE:
4766 return 0;
4767
4768 default:
4769 abort ();
4770 }
4771 return 0;
4772}
4773
4774/* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
4775 entry that chains various modifiers in front of the given type. */
4776static dw_die_ref
4777modified_type_die (type, is_const_type, is_volatile_type, context_die)
4778 register tree type;
4779 register int is_const_type;
4780 register int is_volatile_type;
4781 register dw_die_ref context_die;
4782{
4783 register enum tree_code code = TREE_CODE (type);
4784 register dw_die_ref mod_type_die = NULL;
4785 register dw_die_ref sub_die = NULL;
4786 register tree item_type;
4787
4788 if (code != ERROR_MARK)
4789 {
a9d38797
JM
4790 /* Take the MAIN_VARIANT here to avoid C typedef types. */
4791 type = build_type_variant (TYPE_MAIN_VARIANT (type),
4792 is_const_type, is_volatile_type);
bdb669cb
JM
4793
4794 mod_type_die = lookup_type_die (type);
4795 if (mod_type_die)
4796 return mod_type_die;
4797
a3f97cbb
JW
4798 if (is_const_type)
4799 {
ab72d377 4800 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
a9d38797 4801 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
a3f97cbb
JW
4802 }
4803 else if (is_volatile_type)
4804 {
ab72d377 4805 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
a9d38797 4806 sub_die = modified_type_die (type, 0, 0, context_die);
a3f97cbb
JW
4807 }
4808 else if (code == POINTER_TYPE)
4809 {
ab72d377 4810 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
a3f97cbb 4811 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
61b32c02 4812#if 0
a3f97cbb 4813 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
61b32c02 4814#endif
a3f97cbb
JW
4815 item_type = TREE_TYPE (type);
4816 sub_die = modified_type_die (item_type,
4817 TYPE_READONLY (item_type),
4818 TYPE_VOLATILE (item_type),
4819 context_die);
4820 }
4821 else if (code == REFERENCE_TYPE)
4822 {
ab72d377 4823 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
a3f97cbb 4824 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
61b32c02 4825#if 0
a3f97cbb 4826 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
61b32c02 4827#endif
a3f97cbb
JW
4828 item_type = TREE_TYPE (type);
4829 sub_die = modified_type_die (item_type,
4830 TYPE_READONLY (item_type),
4831 TYPE_VOLATILE (item_type),
4832 context_die);
4833 }
4834 else if (is_base_type (type))
4835 {
4836 mod_type_die = base_type_die (type);
4837 }
4838 else
4839 {
4b674448
JM
4840 gen_type_die (type, context_die);
4841
a3f97cbb
JW
4842 /* We have to get the type_main_variant here (and pass that to the
4843 `lookup_type_die' routine) because the ..._TYPE node we have
4844 might simply be a *copy* of some original type node (where the
4845 copy was created to help us keep track of typedef names) and
4846 that copy might have a different TYPE_UID from the original
4847 ..._TYPE node. (Note that when `equate_type_number_to_die' is
4848 labeling a given type DIE for future reference, it always only
4849 handles DIEs representing *main variants*, and it never even
4850 knows about non-main-variants.). */
4851 mod_type_die = lookup_type_die (type_main_variant (type));
a3f97cbb 4852 if (mod_type_die == NULL)
4b674448 4853 abort ();
a3f97cbb
JW
4854 }
4855 }
4856 if (sub_die != NULL)
4857 {
4858 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
4859 }
bdb669cb 4860 equate_type_number_to_die (type, mod_type_die);
a3f97cbb
JW
4861 return mod_type_die;
4862}
4863
a3f97cbb
JW
4864/* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
4865 an enumerated type. */
4866inline int
4867type_is_enum (type)
4868 register tree type;
4869{
4870 return TREE_CODE (type) == ENUMERAL_TYPE;
4871}
4872
4873/* Return the register number described by a given RTL node. */
4874static unsigned
4875reg_number (rtl)
4876 register rtx rtl;
4877{
4878 register unsigned regno = REGNO (rtl);
4879
4880 if (regno >= FIRST_PSEUDO_REGISTER)
4881 {
4882 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
4883 regno);
4884 regno = 0;
4885 }
4886 regno = DBX_REGISTER_NUMBER (regno);
4887 return regno;
4888}
4889
4890/* Return a location descriptor that designates a machine register. */
4891static dw_loc_descr_ref
4892reg_loc_descriptor (rtl)
4893 register rtx rtl;
4894{
4895 register dw_loc_descr_ref loc_result = NULL;
4896 register unsigned reg = reg_number (rtl);
4897 if (reg >= 0 && reg <= 31)
4898 {
4899 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0);
4900 }
4901 else
4902 {
4903 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
4904 }
4905 return loc_result;
4906}
4907
4908/* Return a location descriptor that designates a base+offset location. */
4909static dw_loc_descr_ref
4910based_loc_descr (reg, offset)
4911 unsigned reg;
4912 long int offset;
4913{
4914 register dw_loc_descr_ref loc_result;
810429b7
JM
4915 /* For the "frame base", we use the frame pointer or stack pointer
4916 registers, since the RTL for local variables is relative to one of
4917 them. */
4918 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
4919 ? FRAME_POINTER_REGNUM
4920 : STACK_POINTER_REGNUM);
a3f97cbb
JW
4921 if (reg == fp_reg)
4922 {
810429b7 4923 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
a3f97cbb
JW
4924 }
4925 else if (reg >= 0 && reg <= 31)
4926 {
4927 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset);
4928 }
4929 else
4930 {
4931 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
4932 }
4933 return loc_result;
4934}
4935
4936/* Return true if this RTL expression describes a base+offset calculation. */
4937inline int
4938is_based_loc (rtl)
4939 register rtx rtl;
4940{
4941 return GET_CODE (rtl) == PLUS
4942 && ((GET_CODE (XEXP (rtl, 0)) == REG
4943 && GET_CODE (XEXP (rtl, 1)) == CONST_INT));
4944}
4945
4946/* The following routine converts the RTL for a variable or parameter
4947 (resident in memory) into an equivalent Dwarf representation of a
4948 mechanism for getting the address of that same variable onto the top of a
4949 hypothetical "address evaluation" stack.
4950 When creating memory location descriptors, we are effectively transforming
4951 the RTL for a memory-resident object into its Dwarf postfix expression
4952 equivalent. This routine recursively descends an RTL tree, turning
4953 it into Dwarf postfix code as it goes. */
4954static dw_loc_descr_ref
4955mem_loc_descriptor (rtl)
4956 register rtx rtl;
4957{
4958 dw_loc_descr_ref mem_loc_result = NULL;
4959 /* Note that for a dynamically sized array, the location we will generate a
4960 description of here will be the lowest numbered location which is
4961 actually within the array. That's *not* necessarily the same as the
4962 zeroth element of the array. */
4963 switch (GET_CODE (rtl))
4964 {
4965 case SUBREG:
4966 /* The case of a subreg may arise when we have a local (register)
4967 variable or a formal (register) parameter which doesn't quite fill
4968 up an entire register. For now, just assume that it is
4969 legitimate to make the Dwarf info refer to the whole register which
4970 contains the given subreg. */
4971 rtl = XEXP (rtl, 0);
4972 /* Drop thru. */
4973
4974 case REG:
4975 /* Whenever a register number forms a part of the description of the
4976 method for calculating the (dynamic) address of a memory resident
4977 object, DWARF rules require the register number be referred to as
4978 a "base register". This distinction is not based in any way upon
4979 what category of register the hardware believes the given register
4980 belongs to. This is strictly DWARF terminology we're dealing with
4981 here. Note that in cases where the location of a memory-resident
4982 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
4983 OP_CONST (0)) the actual DWARF location descriptor that we generate
4984 may just be OP_BASEREG (basereg). This may look deceptively like
4985 the object in question was allocated to a register (rather than in
4986 memory) so DWARF consumers need to be aware of the subtle
4987 distinction between OP_REG and OP_BASEREG. */
4988 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
4989 break;
4990
4991 case MEM:
4992 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
4993 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
4994 break;
4995
4996 case CONST:
4997 case SYMBOL_REF:
4998 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
4999 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
5000 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
5001 break;
5002
5003 case PLUS:
5004 if (is_based_loc (rtl))
5005 {
5006 mem_loc_result = based_loc_descr (
5007 reg_number (XEXP (rtl, 0)),
5008 INTVAL (XEXP (rtl, 1)));
5009 }
5010 else
5011 {
5012 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5013 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5014 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
5015 }
5016 break;
5017
5018 case CONST_INT:
5019 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
5020 break;
5021
5022 default:
5023 abort ();
5024 }
5025 return mem_loc_result;
5026}
5027
5028/* Output a proper Dwarf location descriptor for a variable or parameter
5029 which is either allocated in a register or in a memory location. For a
5030 register, we just generate an OP_REG and the register number. For a
5031 memory location we provide a Dwarf postfix expression describing how to
5032 generate the (dynamic) address of the object onto the address stack. */
5033static dw_loc_descr_ref
5034loc_descriptor (rtl)
5035 register rtx rtl;
5036{
5037 dw_loc_descr_ref loc_result = NULL;
5038 switch (GET_CODE (rtl))
5039 {
5040 case SUBREG:
5041
5042 /* The case of a subreg may arise when we have a local (register)
5043 variable or a formal (register) parameter which doesn't quite fill
5044 up an entire register. For now, just assume that it is
5045 legitimate to make the Dwarf info refer to the whole register which
5046 contains the given subreg. */
5047
5048 rtl = XEXP (rtl, 0);
5c90448c 5049 /* fall through */
a3f97cbb
JW
5050
5051 case REG:
5c90448c 5052 loc_result = reg_loc_descriptor (rtl);
a3f97cbb
JW
5053 break;
5054
5055 case MEM:
5056 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5057 break;
5058
5059 default:
5060 abort (); /* Should never happen */
5061 }
5062 return loc_result;
5063}
5064
5065/* Given an unsigned value, round it up to the lowest multiple of `boundary'
5066 which is not less than the value itself. */
5067inline unsigned
5068ceiling (value, boundary)
5069 register unsigned value;
5070 register unsigned boundary;
5071{
5072 return (((value + boundary - 1) / boundary) * boundary);
5073}
5074
5075/* Given a pointer to what is assumed to be a FIELD_DECL node, return a
5076 pointer to the declared type for the relevant field variable, or return
5077 `integer_type_node' if the given node turns out to be an
5078 ERROR_MARK node. */
5079inline tree
5080field_type (decl)
5081 register tree decl;
5082{
5083 register tree type;
5084
5085 if (TREE_CODE (decl) == ERROR_MARK)
5086 return integer_type_node;
5087
5088 type = DECL_BIT_FIELD_TYPE (decl);
5089 if (type == NULL)
5090 type = TREE_TYPE (decl);
5091
5092 return type;
5093}
5094
5095/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5096 node, return the alignment in bits for the type, or else return
5097 BITS_PER_WORD if the node actually turns out to be an
5098 ERROR_MARK node. */
5099inline unsigned
5100simple_type_align_in_bits (type)
5101 register tree type;
5102{
5103 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
5104}
5105
5106/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5107 node, return the size in bits for the type if it is a constant, or else
5108 return the alignment for the type if the type's size is not constant, or
5109 else return BITS_PER_WORD if the type actually turns out to be an
5110 ERROR_MARK node. */
5111inline unsigned
5112simple_type_size_in_bits (type)
5113 register tree type;
5114{
5115 if (TREE_CODE (type) == ERROR_MARK)
5116 return BITS_PER_WORD;
5117 else
5118 {
5119 register tree type_size_tree = TYPE_SIZE (type);
5120
5121 if (TREE_CODE (type_size_tree) != INTEGER_CST)
5122 return TYPE_ALIGN (type);
5123
5124 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
5125 }
5126}
5127
5128/* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
5129 return the byte offset of the lowest addressed byte of the "containing
5130 object" for the given FIELD_DECL, or return 0 if we are unable to
5131 determine what that offset is, either because the argument turns out to
5132 be a pointer to an ERROR_MARK node, or because the offset is actually
5133 variable. (We can't handle the latter case just yet). */
5134static unsigned
5135field_byte_offset (decl)
5136 register tree decl;
5137{
5138 register unsigned type_align_in_bytes;
5139 register unsigned type_align_in_bits;
5140 register unsigned type_size_in_bits;
5141 register unsigned object_offset_in_align_units;
5142 register unsigned object_offset_in_bits;
5143 register unsigned object_offset_in_bytes;
5144 register tree type;
5145 register tree bitpos_tree;
5146 register tree field_size_tree;
5147 register unsigned bitpos_int;
5148 register unsigned deepest_bitpos;
5149 register unsigned field_size_in_bits;
5150
5151 if (TREE_CODE (decl) == ERROR_MARK)
5152 return 0;
5153
5154 if (TREE_CODE (decl) != FIELD_DECL)
5155 abort ();
5156
5157 type = field_type (decl);
5158
5159 bitpos_tree = DECL_FIELD_BITPOS (decl);
5160 field_size_tree = DECL_SIZE (decl);
5161
5162 /* We cannot yet cope with fields whose positions or sizes are variable, so
5163 for now, when we see such things, we simply return 0. Someday, we may
5164 be able to handle such cases, but it will be damn difficult. */
5165 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5166 return 0;
5167 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5168
5169 if (TREE_CODE (field_size_tree) != INTEGER_CST)
5170 return 0;
5171 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
5172
5173 type_size_in_bits = simple_type_size_in_bits (type);
5174
5175 type_align_in_bits = simple_type_align_in_bits (type);
5176 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
5177
5178 /* Note that the GCC front-end doesn't make any attempt to keep track of
5179 the starting bit offset (relative to the start of the containing
5180 structure type) of the hypothetical "containing object" for a bit-
5181 field. Thus, when computing the byte offset value for the start of the
5182 "containing object" of a bit-field, we must deduce this information on
5183 our own. This can be rather tricky to do in some cases. For example,
5184 handling the following structure type definition when compiling for an
5185 i386/i486 target (which only aligns long long's to 32-bit boundaries)
5186 can be very tricky:
5187
5188 struct S { int field1; long long field2:31; };
5189
5190 Fortunately, there is a simple rule-of-thumb which can be
5191 used in such cases. When compiling for an i386/i486, GCC will allocate
5192 8 bytes for the structure shown above. It decides to do this based upon
5193 one simple rule for bit-field allocation. Quite simply, GCC allocates
5194 each "containing object" for each bit-field at the first (i.e. lowest
5195 addressed) legitimate alignment boundary (based upon the required
5196 minimum alignment for the declared type of the field) which it can
5197 possibly use, subject to the condition that there is still enough
5198 available space remaining in the containing object (when allocated at
5199 the selected point) to fully accommodate all of the bits of the
5200 bit-field itself. This simple rule makes it obvious why GCC allocates
5201 8 bytes for each object of the structure type shown above. When looking
5202 for a place to allocate the "containing object" for `field2', the
5203 compiler simply tries to allocate a 64-bit "containing object" at each
5204 successive 32-bit boundary (starting at zero) until it finds a place to
5205 allocate that 64- bit field such that at least 31 contiguous (and
5206 previously unallocated) bits remain within that selected 64 bit field.
5207 (As it turns out, for the example above, the compiler finds that it is
5208 OK to allocate the "containing object" 64-bit field at bit-offset zero
5209 within the structure type.) Here we attempt to work backwards from the
5210 limited set of facts we're given, and we try to deduce from those facts,
5211 where GCC must have believed that the containing object started (within
5212 the structure type). The value we deduce is then used (by the callers of
5213 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
5214 for fields (both bit-fields and, in the case of DW_AT_location, regular
5215 fields as well). */
5216
5217 /* Figure out the bit-distance from the start of the structure to the
5218 "deepest" bit of the bit-field. */
5219 deepest_bitpos = bitpos_int + field_size_in_bits;
5220
5221 /* This is the tricky part. Use some fancy footwork to deduce where the
5222 lowest addressed bit of the containing object must be. */
5223 object_offset_in_bits
5224 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
5225
5226 /* Compute the offset of the containing object in "alignment units". */
5227 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
5228
5229 /* Compute the offset of the containing object in bytes. */
5230 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
5231
5232 return object_offset_in_bytes;
5233}
5234
5235
5236\f
5237/****************************** attributes *********************************/
5238
5239/* The following routines define various Dwarf attributes
5240 (and any data associated with them). */
5241
5242
5243/* Output the form of location attributes suitable for whole variables and
5244 whole parameters. Note that the location attributes for struct fields are
5245 generated by the routine `data_member_location_attribute' below. */
5246static void
5247add_location_attribute (die, rtl)
5248 dw_die_ref die;
5249 register rtx rtl;
5250{
5251 dw_loc_descr_ref loc_descr = NULL;
5252
5253 /* Handle a special case. If we are about to output a location descriptor
5254 for a variable or parameter which has been optimized out of existence,
5255 don't do that. Instead we output a null location descriptor value as
5256 part of the location attribute. A variable which has been optimized out
5257 of existence will have a DECL_RTL value which denotes a pseudo-reg.
5258 Currently, in some rare cases, variables can have DECL_RTL values which
5259 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
5260 elsewhere in the compiler. We treat such cases as if the variable(s) in
5261 question had been optimized out of existence. Note that in all cases
5262 where we wish to express the fact that a variable has been optimized out
5263 of existence, we do not simply suppress the generation of the entire
5264 location attribute because the absence of a location attribute in
5265 certain kinds of DIEs is used to indicate something else entirely...
5266 i.e. that the DIE represents an object declaration, but not a
5267 definition. So sayeth the PLSIG. */
5268 if (!is_pseudo_reg (rtl)
5269 && (GET_CODE (rtl) != MEM
5270 || !is_pseudo_reg (XEXP (rtl, 0))))
5271 {
5272 loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
5273 }
5274
5275#ifdef MIPS_DEBUGGING_INFO
5276 /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
5277 location descriptor. Lets just use r0 for now to represent a
5278 variable that has been optimized away. */
5279 if (loc_descr == NULL)
5280 {
5281 loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0));
5282 }
5283#endif
5284
5285 add_AT_loc (die, DW_AT_location, loc_descr);
5286}
5287
5288/* Attach the specialized form of location attribute used for data
5289 members of struct and union types. In the special case of a
5290 FIELD_DECL node which represents a bit-field, the "offset" part
5291 of this special location descriptor must indicate the distance
5292 in bytes from the lowest-addressed byte of the containing struct
5293 or union type to the lowest-addressed byte of the "containing
5294 object" for the bit-field. (See the `field_byte_offset' function
5295 above).. For any given bit-field, the "containing object" is a
5296 hypothetical object (of some integral or enum type) within which
5297 the given bit-field lives. The type of this hypothetical
5298 "containing object" is always the same as the declared type of
5299 the individual bit-field itself (for GCC anyway... the DWARF
5300 spec doesn't actually mandate this). Note that it is the size
5301 (in bytes) of the hypothetical "containing object" which will
5302 be given in the DW_AT_byte_size attribute for this bit-field.
5303 (See the `byte_size_attribute' function below.) It is also used
5304 when calculating the value of the DW_AT_bit_offset attribute.
5305 (See the `bit_offset_attribute' function below). */
5306static void
5307add_data_member_location_attribute (die, decl)
5308 register dw_die_ref die;
5309 register tree decl;
5310{
61b32c02 5311 register unsigned long offset;
a3f97cbb
JW
5312 register dw_loc_descr_ref loc_descr;
5313 register enum dwarf_location_atom op;
5314
61b32c02
JM
5315 if (TREE_CODE (decl) == TREE_VEC)
5316 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
5317 else
5318 offset = field_byte_offset (decl);
5319
a3f97cbb
JW
5320 /* The DWARF2 standard says that we should assume that the structure address
5321 is already on the stack, so we can specify a structure field address
5322 by using DW_OP_plus_uconst. */
5323#ifdef MIPS_DEBUGGING_INFO
5324 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
5325 correctly. It works only if we leave the offset on the stack. */
5326 op = DW_OP_constu;
5327#else
5328 op = DW_OP_plus_uconst;
5329#endif
5330 loc_descr = new_loc_descr (op, offset, 0);
5331 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
5332}
5333
5334/* Attach an DW_AT_const_value attribute for a variable or a parameter which
5335 does not have a "location" either in memory or in a register. These
5336 things can arise in GNU C when a constant is passed as an actual parameter
5337 to an inlined function. They can also arise in C++ where declared
5338 constants do not necessarily get memory "homes". */
5339static void
5340add_const_value_attribute (die, rtl)
5341 register dw_die_ref die;
5342 register rtx rtl;
5343{
5344 switch (GET_CODE (rtl))
5345 {
5346 case CONST_INT:
5347 /* Note that a CONST_INT rtx could represent either an integer or a
5348 floating-point constant. A CONST_INT is used whenever the constant
5349 will fit into a single word. In all such cases, the original mode
5350 of the constant value is wiped out, and the CONST_INT rtx is
5351 assigned VOIDmode. */
5352 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
5353 break;
5354
5355 case CONST_DOUBLE:
5356 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
5357 floating-point constant. A CONST_DOUBLE is used whenever the
5358 constant requires more than one word in order to be adequately
5359 represented. In all such cases, the original mode of the constant
5360 value is preserved as the mode of the CONST_DOUBLE rtx, but for
5361 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
5362 add_AT_double (die, DW_AT_const_value,
5363 (unsigned) CONST_DOUBLE_HIGH (rtl),
5364 (unsigned) CONST_DOUBLE_LOW (rtl));
5365 break;
5366
5367 case CONST_STRING:
5368 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
5369 break;
5370
5371 case SYMBOL_REF:
5372 case LABEL_REF:
5373 case CONST:
5374 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
5375 break;
5376
5377 case PLUS:
5378 /* In cases where an inlined instance of an inline function is passed
5379 the address of an `auto' variable (which is local to the caller) we
5380 can get a situation where the DECL_RTL of the artificial local
5381 variable (for the inlining) which acts as a stand-in for the
5382 corresponding formal parameter (of the inline function) will look
5383 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
5384 exactly a compile-time constant expression, but it isn't the address
5385 of the (artificial) local variable either. Rather, it represents the
5386 *value* which the artificial local variable always has during its
5387 lifetime. We currently have no way to represent such quasi-constant
5388 values in Dwarf, so for now we just punt and generate an
5389 DW_AT_const_value attribute with null address. */
5390 add_AT_addr (die, DW_AT_const_value, addr_to_string (const0_rtx));
5391 break;
5392
5393 default:
5394 /* No other kinds of rtx should be possible here. */
5395 abort ();
5396 }
5397
5398}
5399
5400/* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
5401 data attribute for a variable or a parameter. We generate the
5402 DW_AT_const_value attribute only in those cases where the given variable
5403 or parameter does not have a true "location" either in memory or in a
5404 register. This can happen (for example) when a constant is passed as an
5405 actual argument in a call to an inline function. (It's possible that
5406 these things can crop up in other ways also.) Note that one type of
5407 constant value which can be passed into an inlined function is a constant
5408 pointer. This can happen for example if an actual argument in an inlined
5409 function call evaluates to a compile-time constant address. */
5410static void
5411add_location_or_const_value_attribute (die, decl)
5412 register dw_die_ref die;
5413 register tree decl;
5414{
5415 register rtx rtl;
5416 register tree declared_type;
5417 register tree passed_type;
5418
5419 if (TREE_CODE (decl) == ERROR_MARK)
5420 {
5421 return;
5422 }
5423 if ((TREE_CODE (decl) != VAR_DECL)
5424 && (TREE_CODE (decl) != PARM_DECL))
5425 {
5426 /* Should never happen. */
5427 abort ();
5428 return;
5429 }
5430 /* Here we have to decide where we are going to say the parameter "lives"
5431 (as far as the debugger is concerned). We only have a couple of
5432 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
5433 DECL_RTL normally indicates where the parameter lives during most of the
5434 activa- tion of the function. If optimization is enabled however, this
5435 could be either NULL or else a pseudo-reg. Both of those cases indicate
5436 that the parameter doesn't really live anywhere (as far as the code
5437 generation parts of GCC are concerned) during most of the function's
5438 activation. That will happen (for example) if the parameter is never
5439 referenced within the function. We could just generate a location
5440 descriptor here for all non-NULL non-pseudo values of DECL_RTL and
5441 ignore all of the rest, but we can be a little nicer than that if we
5442 also consider DECL_INCOMING_RTL in cases where DECL_RTL is NULL or is a
5443 pseudo-reg. Note however that we can only get away with using
5444 DECL_INCOMING_RTL as a backup substitute for DECL_RTL in certain limited
5445 cases. In cases where DECL_ARG_TYPE(decl) indicates the same type as
5446 TREE_TYPE(decl) we can be sure that the parameter was passed using the
5447 same type as it is declared to have within the function, and that its
5448 DECL_INCOMING_RTL points us to a place where a value of that type is
5449 passed. In cases where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are
5450 different types however, we cannot (in general) use DECL_INCOMING_RTL as
5451 a backup substitute for DECL_RTL because in these cases,
5452 DECL_INCOMING_RTL points us to a value of some type which is *different*
5453 from the type of the parameter itself. Thus, if we tried to use
5454 DECL_INCOMING_RTL to generate a location attribute in such cases, the
5455 debugger would end up (for example) trying to fetch a `float' from a
5456 place which actually contains the first part of a `double'. That would
5457 lead to really incorrect and confusing output at debug-time, and we
5458 don't want that now do we? So in general, we DO NOT use
5459 DECL_INCOMING_RTL as a backup for DECL_RTL in cases where
5460 DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a couple of cute
5461 exceptions however. On little-endian machines we can get away with
5462 using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is not the same as
5463 TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is an integral type
5464 which is smaller than TREE_TYPE(decl). These cases arise when (on a
5465 little-endian machine) a non-prototyped function has a parameter
5466 declared to be of type `short' or `char'. In such cases,
5467 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
5468 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
5469 passed `int' value. If the debugger then uses that address to fetch a
5470 `short' or a `char' (on a little-endian machine) the result will be the
5471 correct data, so we allow for such exceptional cases below. Note that
5472 our goal here is to describe the place where the given formal parameter
5473 lives during most of the function's activation (i.e. between the end of
5474 the prologue and the start of the epilogue). We'll do that as best as
5475 we can. Note however that if the given formal parameter is modified
5476 sometime during the execution of the function, then a stack backtrace
5477 (at debug-time) will show the function as having been called with the
5478 *new* value rather than the value which was originally passed in. This
5479 happens rarely enough that it is not a major problem, but it *is* a
9a666dda 5480 problem, and I'd like to fix it. A future version of dwarf2out.c may
a3f97cbb
JW
5481 generate two additional attributes for any given DW_TAG_formal_parameter
5482 DIE which will describe the "passed type" and the "passed location" for
5483 the given formal parameter in addition to the attributes we now generate
5484 to indicate the "declared type" and the "active location" for each
5485 parameter. This additional set of attributes could be used by debuggers
5486 for stack backtraces. Separately, note that sometimes DECL_RTL can be
5487 NULL and DECL_INCOMING_RTL can be NULL also. This happens (for example)
5488 for inlined-instances of inline function formal parameters which are
5489 never referenced. This really shouldn't be happening. All PARM_DECL
5490 nodes should get valid non-NULL DECL_INCOMING_RTL values, but
5491 integrate.c doesn't currently generate these values for inlined
5492 instances of inline function parameters, so when we see such cases, we
5493 are just SOL (shit-out-of-luck) for the time being (until integrate.c
5494 gets fixed). */
5495
5496 /* Use DECL_RTL as the "location" unless we find something better. */
5497 rtl = DECL_RTL (decl);
5498
5499 if (TREE_CODE (decl) == PARM_DECL)
5500 {
5501 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
5502 {
5503 declared_type = type_main_variant (TREE_TYPE (decl));
5504 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
5505 /* This decl represents a formal parameter which was
5506 optimized out.
5507
5508 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
5509 all* cases where (rtl == NULL_RTX) just below. */
5510 if (declared_type == passed_type)
5511 {
5512 rtl = DECL_INCOMING_RTL (decl);
5513 }
5514 else if (!BYTES_BIG_ENDIAN)
5515 {
5516 if (TREE_CODE (declared_type) == INTEGER_TYPE)
5517 {
5518 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
5519 {
5520 rtl = DECL_INCOMING_RTL (decl);
5521 }
5522 }
5523 }
a3f97cbb
JW
5524 }
5525 }
61b32c02
JM
5526 if (rtl == NULL_RTX)
5527 return;
5528
a3f97cbb
JW
5529 switch (GET_CODE (rtl))
5530 {
5531 case CONST_INT:
5532 case CONST_DOUBLE:
5533 case CONST_STRING:
5534 case SYMBOL_REF:
5535 case LABEL_REF:
5536 case CONST:
5537 case PLUS:
5538 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
5539 add_const_value_attribute (die, rtl);
5540 break;
5541
5542 case MEM:
5543 case REG:
5544 case SUBREG:
5545 add_location_attribute (die, rtl);
5546 break;
5547
5548 default:
5549 abort (); /* Should never happen. */
5550 }
5551}
5552
5553/* Generate an DW_AT_name attribute given some string value to be included as
5554 the value of the attribute. */
5555inline void
5556add_name_attribute (die, name_string)
5557 register dw_die_ref die;
5558 register char *name_string;
5559{
5560 if (name_string && *name_string)
5561 {
5562 add_AT_string (die, DW_AT_name, name_string);
5563 }
5564}
5565
5566/* Given a tree node describing an array bound (either lower or upper) output
a9d38797
JM
5567 a representation for that bound.
5568
5569 FIXME: This uses location descriptions for variable bounds, whereas the
5570 DWARF-2 spec only allowes for constants or DIE references. */
a3f97cbb
JW
5571static void
5572add_bound_info (subrange_die, bound_attr, bound)
5573 register dw_die_ref subrange_die;
5574 register enum dwarf_attribute bound_attr;
5575 register tree bound;
5576{
5577 register dw_loc_descr_ref bound_loc = NULL;
5578 register unsigned bound_value = 0;
5579 switch (TREE_CODE (bound))
5580 {
5581 case ERROR_MARK:
5582 return;
5583
5584 /* All fixed-bounds are represented by INTEGER_CST nodes. */
5585 case INTEGER_CST:
5586 bound_value = TREE_INT_CST_LOW (bound);
5587 /* TODO: we need to check for C language below, or some flag
5588 derived from the language. C implies a lower bound of 0. */
5589 if (!(bound_attr == DW_AT_lower_bound && bound_value == 0))
5590 {
5591 add_AT_unsigned (subrange_die, bound_attr, bound_value);
5592 }
5593 break;
5594
5595 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
5596 SAVE_EXPR nodes. */
5597 case NOP_EXPR:
5598 bound = TREE_OPERAND (bound, 0);
5599 /* ... fall thru... */
5600
5601 case SAVE_EXPR:
5602 /* If optimization is turned on, the SAVE_EXPRs that describe how to
5603 access the upper bound values are essentially bogus. They only
5604 describe (at best) how to get at these values at the points in the
5605 generated code right after they have just been computed. Worse yet,
5606 in the typical case, the upper bound values will not even *be*
5607 computed in the optimized code, so these SAVE_EXPRs are entirely
5608 bogus. In order to compensate for this fact, we check here to see if
5609 optimization is enabled, and if so, we effectively create an empty
5610 location description for the (unknown and unknowable) upper bound.
5611 This should not cause too much trouble for existing (stupid?)
5612 debuggers because they have to deal with empty upper bounds location
5613 descriptions anyway in order to be able to deal with incomplete array
5614 types. Of course an intelligent debugger (GDB?) should be able to
5615 comprehend that a missing upper bound specification in a array type
5616 used for a storage class `auto' local array variable indicates that
5617 the upper bound is both unknown (at compile- time) and unknowable (at
5618 run-time) due to optimization. */
5619 if (!optimize)
5620 {
5621 bound_loc = mem_loc_descriptor (
5622 eliminate_regs (SAVE_EXPR_RTL (bound),
5623 0, NULL_RTX));
5624 }
5625 else
5626 {
5627 bound_loc = NULL;
5628 }
5629 add_AT_loc (subrange_die, bound_attr, bound_loc);
5630 break;
5631
5632 default:
5633 abort ();
5634 }
5635}
5636
5637/* Note that the block of subscript information for an array type also
5638 includes information about the element type of type given array type. */
5639static void
5640add_subscript_info (type_die, type)
5641 register dw_die_ref type_die;
5642 register tree type;
5643{
5644 register unsigned dimension_number;
5645 register tree lower, upper;
5646 register dw_die_ref subrange_die;
5647
5648 /* The GNU compilers represent multidimensional array types as sequences of
5649 one dimensional array types whose element types are themselves array
5650 types. Here we squish that down, so that each multidimensional array
5651 type gets only one array_type DIE in the Dwarf debugging info. The draft
5652 Dwarf specification say that we are allowed to do this kind of
5653 compression in C (because there is no difference between an array or
5654 arrays and a multidimensional array in C) but for other source languages
5655 (e.g. Ada) we probably shouldn't do this. */
5656 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
5657 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
5658 We work around this by disabling this feature. See also
5659 gen_array_type_die. */
5660#ifndef MIPS_DEBUGGING_INFO
5661 for (dimension_number = 0;
5662 TREE_CODE (type) == ARRAY_TYPE;
5663 type = TREE_TYPE (type), dimension_number++)
5664 {
5665#endif
5666 register tree domain = TYPE_DOMAIN (type);
5667
5668 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
5669 and (in GNU C only) variable bounds. Handle all three forms
5670 here. */
5671 subrange_die = new_die (DW_TAG_subrange_type, type_die);
5672 if (domain)
5673 {
5674 /* We have an array type with specified bounds. */
5675 lower = TYPE_MIN_VALUE (domain);
5676 upper = TYPE_MAX_VALUE (domain);
5677
a9d38797
JM
5678 /* define the index type. */
5679 if (TREE_TYPE (domain))
5680 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
5681 type_die);
5682
5683 if (! is_c_family () && ! is_fortran ())
5684 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
a3f97cbb
JW
5685 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
5686 }
5687 else
5688 {
a9d38797
JM
5689 /* We have an array type with an unspecified length. The DWARF-2
5690 spec does not say how to handle this; let's just leave out the
5691 bounds. */
a3f97cbb
JW
5692 }
5693#ifndef MIPS_DEBUGGING_INFO
5694 }
5695#endif
5696}
5697
5698static void
5699add_byte_size_attribute (die, tree_node)
5700 dw_die_ref die;
5701 register tree tree_node;
5702{
5703 register unsigned size;
5704
5705 switch (TREE_CODE (tree_node))
5706 {
5707 case ERROR_MARK:
5708 size = 0;
5709 break;
5710 case ENUMERAL_TYPE:
5711 case RECORD_TYPE:
5712 case UNION_TYPE:
5713 case QUAL_UNION_TYPE:
5714 size = int_size_in_bytes (tree_node);
5715 break;
5716 case FIELD_DECL:
5717 /* For a data member of a struct or union, the DW_AT_byte_size is
5718 generally given as the number of bytes normally allocated for an
5719 object of the *declared* type of the member itself. This is true
5720 even for bit-fields. */
5721 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
5722 break;
5723 default:
5724 abort ();
5725 }
5726
5727 /* Note that `size' might be -1 when we get to this point. If it is, that
5728 indicates that the byte size of the entity in question is variable. We
5729 have no good way of expressing this fact in Dwarf at the present time,
5730 so just let the -1 pass on through. */
5731
5732 add_AT_unsigned (die, DW_AT_byte_size, size);
5733}
5734
5735/* For a FIELD_DECL node which represents a bit-field, output an attribute
5736 which specifies the distance in bits from the highest order bit of the
5737 "containing object" for the bit-field to the highest order bit of the
5738 bit-field itself.
5739
5740 For any given bit-field, the "containing object" is a hypothetical object (of
5741 some integral or enum type) within which the given bit-field lives. The
5742 type of this hypothetical "containing object" is always the same as the
5743 declared type of the individual bit-field itself.
5744 The determination of the exact location of the "containing object" for a
5745 bit-field is rather complicated. It's handled by the `field_byte_offset'
5746 function (above).
5747
5748 Note that it is the size (in bytes) of the hypothetical "containing object"
5749 which will be given in the DW_AT_byte_size attribute for this bit-field.
5750 (See `byte_size_attribute' above). */
5751inline void
5752add_bit_offset_attribute (die, decl)
5753 register dw_die_ref die;
5754 register tree decl;
5755{
5756 register unsigned object_offset_in_bytes = field_byte_offset (decl);
5757 register tree type = DECL_BIT_FIELD_TYPE (decl);
5758 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
5759 register unsigned bitpos_int;
5760 register unsigned highest_order_object_bit_offset;
5761 register unsigned highest_order_field_bit_offset;
5762 register unsigned bit_offset;
5763
5764 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
5765 assert (type); /* Must be a bit field. */
5766
5767 /* We can't yet handle bit-fields whose offsets are variable, so if we
5768 encounter such things, just return without generating any attribute
5769 whatsoever. */
5770 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5771 {
5772 return;
5773 }
5774 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5775
5776 /* Note that the bit offset is always the distance (in bits) from the
5777 highest-order bit of the "containing object" to the highest-order bit of
5778 the bit-field itself. Since the "high-order end" of any object or field
5779 is different on big-endian and little-endian machines, the computation
5780 below must take account of these differences. */
5781 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
5782 highest_order_field_bit_offset = bitpos_int;
5783
5784 if (!BYTES_BIG_ENDIAN)
5785 {
5786 highest_order_field_bit_offset
5787 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
5788
5789 highest_order_object_bit_offset += simple_type_size_in_bits (type);
5790 }
5791 bit_offset =
5792 (!BYTES_BIG_ENDIAN
5793 ? highest_order_object_bit_offset - highest_order_field_bit_offset
5794 : highest_order_field_bit_offset - highest_order_object_bit_offset);
5795
5796 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
5797}
5798
5799/* For a FIELD_DECL node which represents a bit field, output an attribute
5800 which specifies the length in bits of the given field. */
5801inline void
5802add_bit_size_attribute (die, decl)
5803 register dw_die_ref die;
5804 register tree decl;
5805{
5806 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
5807 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
5808 add_AT_unsigned (die, DW_AT_bit_size,
5809 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
5810}
5811
a3f97cbb
JW
5812/* If the compiled language is GNU C, then add a 'prototyped'
5813 attribute, if arg types are given for the parameters of a function. */
5814inline void
5815add_prototyped_attribute (die, func_type)
5816 register dw_die_ref die;
5817 register tree func_type;
5818{
5819 if ((strcmp (language_string, "GNU C") == 0)
5820 && (TYPE_ARG_TYPES (func_type) != NULL))
5821 {
5822 add_AT_flag (die, DW_AT_prototyped, 0);
5823 }
5824}
5825
5826
5827/* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
5828 by looking in either the type declaration or object declaration
5829 equate table. */
5830inline void
5831add_abstract_origin_attribute (die, origin)
5832 register dw_die_ref die;
5833 register tree origin;
5834{
5835 dw_die_ref origin_die = NULL;
5836 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
5837 {
5838 origin_die = lookup_decl_die (origin);
5839 }
5840 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
5841 {
5842 origin_die = lookup_type_die (origin);
5843 }
5844 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
5845}
5846
bdb669cb
JM
5847/* We do not currently support the pure_virtual attribute. */
5848
a3f97cbb
JW
5849inline void
5850add_pure_or_virtual_attribute (die, func_decl)
5851 register dw_die_ref die;
5852 register tree func_decl;
5853{
5854 if (DECL_VIRTUAL_P (func_decl))
5855 {
bdb669cb 5856 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
61b32c02
JM
5857 add_AT_loc (die, DW_AT_vtable_elem_location, new_loc_descr
5858 (DW_OP_constu, TREE_INT_CST_LOW (DECL_VINDEX (func_decl))));
a3f97cbb
JW
5859 }
5860}
5861\f
5862/********************* utility routines for DIEs *************************/
5863
5864/* Add an DW_AT_name attribute and source coordinate attribute for the
5865 given decl, but only if it actually has a name. */
5866static void
5867add_name_and_src_coords_attributes (die, decl)
5868 register dw_die_ref die;
5869 register tree decl;
5870{
61b32c02 5871 register tree decl_name;
a3f97cbb 5872 register unsigned file_index;
273dbe67 5873 if (TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
61b32c02
JM
5874 decl_name = DECL_ASSEMBLER_NAME (decl);
5875 else
5876 decl_name = DECL_NAME (decl);
5877
a3f97cbb
JW
5878 if (decl_name && IDENTIFIER_POINTER (decl_name))
5879 {
5880 add_name_attribute (die, IDENTIFIER_POINTER (decl_name));
5881 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
5882 add_AT_unsigned (die, DW_AT_decl_file, file_index);
5883 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
5884 }
5885}
5886
5887/* Push a new declaration scope. */
5888static void
5889push_decl_scope (scope)
5890 tree scope;
5891{
5892 /* Make room in the decl_scope_table, if necessary. */
5893 if (decl_scope_table_allocated == decl_scope_depth)
5894 {
5895 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
5896 decl_scope_table = (tree *) xrealloc (decl_scope_table,
5897 decl_scope_table_allocated * sizeof (tree));
5898 }
5899 decl_scope_table[decl_scope_depth++] = scope;
5900}
5901
5902/* Return the DIE for the scope the immediately contains this declaration. */
5903static dw_die_ref
ab72d377
JM
5904scope_die_for (t, context_die)
5905 register tree t;
a3f97cbb
JW
5906 register dw_die_ref context_die;
5907{
5908 register dw_die_ref scope_die = NULL;
5909 register tree containing_scope;
5910 register unsigned long i;
5911
5912 /* Walk back up the declaration tree looking for a place to define
5913 this type. */
ab72d377
JM
5914 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
5915 containing_scope = TYPE_CONTEXT (t);
5916 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VIRTUAL_P (t))
5917 containing_scope = decl_class_context (t);
5918 else
5919 containing_scope = DECL_CONTEXT (t);
5920
a3f97cbb
JW
5921 if (containing_scope == NULL)
5922 {
5923 scope_die = comp_unit_die;
5924 }
5925 else
5926 {
ab72d377
JM
5927 for (i = decl_scope_depth, scope_die = context_die;
5928 i > 0 && decl_scope_table[i - 1] != containing_scope;
7d4440be
JM
5929 scope_die = scope_die->die_parent, --i)
5930 /* nothing */ ;
ab72d377 5931 if (i == 0)
a3f97cbb 5932 {
ab72d377
JM
5933 assert (scope_die == comp_unit_die);
5934 assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't');
4927276d
JM
5935 if (debug_info_level > DINFO_LEVEL_TERSE)
5936 assert (TREE_ASM_WRITTEN (containing_scope));
a3f97cbb
JW
5937 }
5938 }
5939 return scope_die;
5940}
5941
5942/* Pop a declaration scope. */
5943inline void
5944pop_decl_scope ()
5945{
5946 assert (decl_scope_depth > 0);
5947 --decl_scope_depth;
5948}
5949
5950/* Many forms of DIEs require a "type description" attribute. This
5951 routine locates the proper "type descriptor" die for the type given
5952 by 'type', and adds an DW_AT_type attribute below the given die. */
5953static void
5954add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
5955 register dw_die_ref object_die;
5956 register tree type;
5957 register int decl_const;
5958 register int decl_volatile;
5959 register dw_die_ref context_die;
5960{
5961 register enum tree_code code = TREE_CODE (type);
a3f97cbb
JW
5962 register dw_die_ref type_die = NULL;
5963
5964 if (code == ERROR_MARK)
5965 {
5966 return;
5967 }
5968
5969 /* Handle a special case. For functions whose return type is void, we
5970 generate *no* type attribute. (Note that no object may have type
5971 `void', so this only applies to function return types). */
5972 if (code == VOID_TYPE)
5973 {
5974 return;
5975 }
5976
a3f97cbb
JW
5977 type_die = modified_type_die (type,
5978 decl_const || TYPE_READONLY (type),
5979 decl_volatile || TYPE_VOLATILE (type),
ab72d377 5980 context_die);
a3f97cbb
JW
5981 if (type_die != NULL)
5982 {
5983 add_AT_die_ref (object_die, DW_AT_type, type_die);
5984 }
5985}
5986
5987/* Given a tree pointer to a struct, class, union, or enum type node, return
5988 a pointer to the (string) tag name for the given type, or zero if the type
5989 was declared without a tag. */
5990static char *
5991type_tag (type)
5992 register tree type;
5993{
5994 register char *name = 0;
5995
5996 if (TYPE_NAME (type) != 0)
5997 {
5998 register tree t = 0;
5999
6000 /* Find the IDENTIFIER_NODE for the type name. */
6001 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
6002 t = TYPE_NAME (type);
bdb669cb 6003
a3f97cbb
JW
6004 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
6005 a TYPE_DECL node, regardless of whether or not a `typedef' was
bdb669cb 6006 involved. */
a3f97cbb
JW
6007 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
6008 t = DECL_NAME (TYPE_NAME (type));
bdb669cb 6009
a3f97cbb
JW
6010 /* Now get the name as a string, or invent one. */
6011 if (t != 0)
6012 {
6013 name = IDENTIFIER_POINTER (t);
6014 }
6015 }
6016 return (name == 0 || *name == '\0') ? 0 : name;
6017}
6018
6019/* Return the type associated with a data member, make a special check
6020 for bit field types. */
6021inline tree
6022member_declared_type (member)
6023 register tree member;
6024{
6025 return (DECL_BIT_FIELD_TYPE (member))
6026 ? DECL_BIT_FIELD_TYPE (member)
6027 : TREE_TYPE (member);
6028}
6029
d291dd49 6030/* Get the decl's label, as described by its RTL. This may be different
a3f97cbb
JW
6031 from the DECL_NAME name used in the source file. */
6032static char *
d291dd49 6033decl_start_label (decl)
a3f97cbb
JW
6034 register tree decl;
6035{
6036 rtx x;
6037 char *fnname;
6038 x = DECL_RTL (decl);
6039 if (GET_CODE (x) != MEM)
6040 {
6041 abort ();
6042 }
6043 x = XEXP (x, 0);
6044 if (GET_CODE (x) != SYMBOL_REF)
6045 {
6046 abort ();
6047 }
6048 fnname = XSTR (x, 0);
6049 return fnname;
6050}
6051\f
6052/******************************* DIE Generation *************************/
6053
6054/* These routines generate the internnal representation of the DIE's for
6055 the compilation unit. Debugging information is collected by walking
9a666dda 6056 the declaration trees passed in from dwarf2out_file_scope_decl(). */
a3f97cbb
JW
6057
6058static void
6059gen_array_type_die (type, context_die)
6060 register tree type;
6061 register dw_die_ref context_die;
6062{
ab72d377 6063 register dw_die_ref scope_die = scope_die_for (type, context_die);
a9d38797 6064 register dw_die_ref array_die;
a3f97cbb 6065 register tree element_type;
bdb669cb 6066
a9d38797
JM
6067 /* ??? The SGI dwarf reader fails for array of array of enum types unless
6068 the inner array type comes before the outer array type. Thus we must
6069 call gen_type_die before we call new_die. See below also. */
6070#ifdef MIPS_DEBUGGING_INFO
6071 gen_type_die (TREE_TYPE (type), context_die);
6072#endif
6073
6074 array_die = new_die (DW_TAG_array_type, scope_die);
6075
a3f97cbb
JW
6076#if 0
6077 /* We default the array ordering. SDB will probably do
6078 the right things even if DW_AT_ordering is not present. It's not even
6079 an issue until we start to get into multidimensional arrays anyway. If
6080 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
6081 then we'll have to put the DW_AT_ordering attribute back in. (But if
6082 and when we find out that we need to put these in, we will only do so
6083 for multidimensional arrays. */
6084 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
6085#endif
6086
a9d38797
JM
6087#ifdef MIPS_DEBUGGING_INFO
6088 if (! TYPE_DOMAIN (type))
6089 add_AT_unsigned (array_die, DW_AT_declaration, 1);
6090 else
6091#endif
6092 add_subscript_info (array_die, type);
a3f97cbb
JW
6093
6094 equate_type_number_to_die (type, array_die);
6095
6096 /* Add representation of the type of the elements of this array type. */
6097 element_type = TREE_TYPE (type);
6098 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6099 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
6100 We work around this by disabling this feature. See also
6101 add_subscript_info. */
6102#ifndef MIPS_DEBUGGING_INFO
6103 while (TREE_CODE (element_type) == ARRAY_TYPE)
6104 {
6105 element_type = TREE_TYPE (element_type);
6106 }
a3f97cbb 6107 gen_type_die (element_type, context_die);
a9d38797 6108#endif
a3f97cbb
JW
6109
6110 add_type_attribute (array_die, element_type, 0, 0, context_die);
6111}
6112
6113static void
6114gen_set_type_die (type, context_die)
6115 register tree type;
6116 register dw_die_ref context_die;
6117{
ab72d377
JM
6118 register dw_die_ref type_die = new_die
6119 (DW_TAG_set_type, scope_die_for (type, context_die));
a3f97cbb 6120 equate_type_number_to_die (type, type_die);
a3f97cbb
JW
6121 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
6122}
6123
6124static void
6125gen_entry_point_die (decl, context_die)
6126 register tree decl;
6127 register dw_die_ref context_die;
6128{
6129 register tree origin = decl_ultimate_origin (decl);
6130 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
6131 if (origin != NULL)
6132 {
6133 add_abstract_origin_attribute (decl_die, origin);
6134 }
6135 else
6136 {
6137 add_name_and_src_coords_attributes (decl_die, decl);
a3f97cbb
JW
6138 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
6139 0, 0, context_die);
6140 }
6141 if (DECL_ABSTRACT (decl))
6142 {
6143 equate_decl_number_to_die (decl, decl_die);
6144 }
6145 else
6146 {
d291dd49 6147 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
a3f97cbb
JW
6148 }
6149}
6150
6151/* Generate a DIE to represent an inlined instance of an enumeration type. */
6152static void
6153gen_inlined_enumeration_type_die (type, context_die)
6154 register tree type;
6155 register dw_die_ref context_die;
6156{
6157 register dw_die_ref type_die;
6158 type_die = new_die (DW_TAG_enumeration_type,
ab72d377 6159 scope_die_for (type, context_die));
a3f97cbb
JW
6160 assert (TREE_ASM_WRITTEN (type));
6161 add_abstract_origin_attribute (type_die, type);
6162}
6163
6164/* Generate a DIE to represent an inlined instance of a structure type. */
6165static void
6166gen_inlined_structure_type_die (type, context_die)
6167 register tree type;
6168 register dw_die_ref context_die;
6169{
6170 register dw_die_ref type_die;
6171 type_die = new_die (DW_TAG_structure_type,
ab72d377 6172 scope_die_for (type, context_die));
a3f97cbb
JW
6173 assert (TREE_ASM_WRITTEN (type));
6174 add_abstract_origin_attribute (type_die, type);
6175}
6176
6177/* Generate a DIE to represent an inlined instance of a union type. */
6178static void
6179gen_inlined_union_type_die (type, context_die)
6180 register tree type;
6181 register dw_die_ref context_die;
6182{
6183 register dw_die_ref type_die;
6184 type_die = new_die (DW_TAG_union_type,
ab72d377 6185 scope_die_for (type, context_die));
a3f97cbb
JW
6186 assert (TREE_ASM_WRITTEN (type));
6187 add_abstract_origin_attribute (type_die, type);
6188}
6189
6190/* Generate a DIE to represent an enumeration type. Note that these DIEs
6191 include all of the information about the enumeration values also. Each
273dbe67
JM
6192 enumerated type name/value is listed as a child of the enumerated type
6193 DIE. */
a3f97cbb 6194static void
273dbe67 6195gen_enumeration_type_die (type, context_die)
a3f97cbb 6196 register tree type;
a3f97cbb
JW
6197 register dw_die_ref context_die;
6198{
273dbe67
JM
6199 register dw_die_ref type_die = lookup_type_die (type);
6200
a3f97cbb
JW
6201 if (type_die == NULL)
6202 {
6203 type_die = new_die (DW_TAG_enumeration_type,
ab72d377 6204 scope_die_for (type, context_die));
a3f97cbb
JW
6205 equate_type_number_to_die (type, type_die);
6206 add_name_attribute (type_die, type_tag (type));
a3f97cbb 6207 }
273dbe67
JM
6208 else if (! TYPE_SIZE (type))
6209 return;
6210 else
6211 remove_AT (type_die, DW_AT_declaration);
6212
6213 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
6214 given enum type is incomplete, do not generate the DW_AT_byte_size
6215 attribute or the DW_AT_element_list attribute. */
6216 if (TYPE_SIZE (type))
a3f97cbb 6217 {
273dbe67 6218 register tree link;
a082c85a 6219 TREE_ASM_WRITTEN (type) = 1;
273dbe67
JM
6220 add_byte_size_attribute (type_die, type);
6221 for (link = TYPE_FIELDS (type);
6222 link != NULL; link = TREE_CHAIN (link))
a3f97cbb 6223 {
273dbe67
JM
6224 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
6225 add_name_attribute (enum_die,
6226 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
6227 add_AT_unsigned (enum_die, DW_AT_const_value,
a3f97cbb 6228 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
a3f97cbb
JW
6229 }
6230 }
273dbe67
JM
6231 else
6232 add_AT_flag (type_die, DW_AT_declaration, 1);
a3f97cbb
JW
6233}
6234
6235
6236/* Generate a DIE to represent either a real live formal parameter decl or to
6237 represent just the type of some formal parameter position in some function
6238 type.
6239 Note that this routine is a bit unusual because its argument may be a
6240 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
6241 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
6242 node. If it's the former then this function is being called to output a
6243 DIE to represent a formal parameter object (or some inlining thereof). If
6244 it's the latter, then this function is only being called to output a
6245 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
6246 argument type of some subprogram type. */
6247static void
6248gen_formal_parameter_die (node, context_die)
6249 register tree node;
6250 register dw_die_ref context_die;
6251{
6252 register dw_die_ref parm_die = new_die (DW_TAG_formal_parameter,
6253 context_die);
6254 register tree origin;
6255 switch (TREE_CODE_CLASS (TREE_CODE (node)))
6256 {
6257 /* We were called with some kind of a ..._DECL node. */
6258 case 'd':
6259 origin = decl_ultimate_origin (node);
6260 if (origin != NULL)
6261 {
6262 add_abstract_origin_attribute (parm_die, origin);
6263 }
6264 else
6265 {
6266 add_name_and_src_coords_attributes (parm_die, node);
6267 add_type_attribute (parm_die, TREE_TYPE (node),
6268 TREE_READONLY (node),
6269 TREE_THIS_VOLATILE (node),
6270 context_die);
bdb669cb
JM
6271 if (DECL_ARTIFICIAL (node))
6272 add_AT_flag (parm_die, DW_AT_artificial, 1);
a3f97cbb
JW
6273 }
6274 if (DECL_ABSTRACT (node))
6275 {
6276 equate_decl_number_to_die (node, parm_die);
6277 }
6278 else
6279 {
6280 add_location_or_const_value_attribute (parm_die, node);
6281 }
6282 break;
6283
6284 /* We were called with some kind of a ..._TYPE node. */
6285 case 't':
6286 add_type_attribute (parm_die, node, 0, 0, context_die);
6287 break;
6288
6289 /* Should never happen. */
6290 default:
6291 abort ();
6292 }
6293}
6294
6295/* Generate a special type of DIE used as a stand-in for a trailing ellipsis
6296 at the end of an (ANSI prototyped) formal parameters list. */
6297static void
6298gen_unspecified_parameters_die (decl_or_type, context_die)
6299 register tree decl_or_type;
6300 register dw_die_ref context_die;
6301{
6302 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
6303 context_die);
a3f97cbb
JW
6304}
6305
6306/* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
6307 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
6308 parameters as specified in some function type specification (except for
6309 those which appear as part of a function *definition*).
6310 Note that we must be careful here to output all of the parameter DIEs before*
6311 we output any DIEs needed to represent the types of the formal parameters.
6312 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
6313 non-parameter DIE it sees ends the formal parameter list. */
6314static void
6315gen_formal_types_die (function_or_method_type, context_die)
6316 register tree function_or_method_type;
6317 register dw_die_ref context_die;
6318{
6319 register tree link;
6320 register tree formal_type = NULL;
6321 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
6322
bdb669cb 6323#if 0
a3f97cbb
JW
6324 /* In the case where we are generating a formal types list for a C++
6325 non-static member function type, skip over the first thing on the
6326 TYPE_ARG_TYPES list because it only represents the type of the hidden
6327 `this pointer'. The debugger should be able to figure out (without
6328 being explicitly told) that this non-static member function type takes a
6329 `this pointer' and should be able to figure what the type of that hidden
6330 parameter is from the DW_AT_member attribute of the parent
6331 DW_TAG_subroutine_type DIE. */
6332 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
6333 first_parm_type = TREE_CHAIN (first_parm_type);
bdb669cb 6334#endif
a3f97cbb
JW
6335
6336 /* Make our first pass over the list of formal parameter types and output a
6337 DW_TAG_formal_parameter DIE for each one. */
6338 for (link = first_parm_type; link; link = TREE_CHAIN (link))
6339 {
6340 formal_type = TREE_VALUE (link);
6341 if (formal_type == void_type_node)
6342 break;
6343
6344 /* Output a (nameless) DIE to represent the formal parameter itself. */
6345 gen_formal_parameter_die (formal_type, context_die);
6346 }
6347
6348 /* If this function type has an ellipsis, add a
6349 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
6350 if (formal_type != void_type_node)
6351 gen_unspecified_parameters_die (function_or_method_type, context_die);
6352
6353 /* Make our second (and final) pass over the list of formal parameter types
6354 and output DIEs to represent those types (as necessary). */
6355 for (link = TYPE_ARG_TYPES (function_or_method_type);
6356 link;
6357 link = TREE_CHAIN (link))
6358 {
6359 formal_type = TREE_VALUE (link);
6360 if (formal_type == void_type_node)
6361 break;
6362
b50c02f9 6363 gen_type_die (formal_type, context_die);
a3f97cbb
JW
6364 }
6365}
6366
6367/* Generate a DIE to represent a declared function (either file-scope or
6368 block-local). */
6369static void
6370gen_subprogram_die (decl, context_die)
6371 register tree decl;
6372 register dw_die_ref context_die;
6373{
6374 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
6375 register tree origin = decl_ultimate_origin (decl);
4b674448 6376 register dw_die_ref subr_die;
a3f97cbb
JW
6377 register dw_loc_descr_ref fp_loc = NULL;
6378 register unsigned fp_reg;
a3f97cbb
JW
6379 register tree fn_arg_types;
6380 register tree outer_scope;
bdb669cb 6381 dw_die_ref old_die = lookup_decl_die (decl);
a3f97cbb 6382
a3f97cbb
JW
6383 if (origin != NULL)
6384 {
4b674448 6385 subr_die = new_die (DW_TAG_subprogram, context_die);
a3f97cbb
JW
6386 add_abstract_origin_attribute (subr_die, origin);
6387 }
bdb669cb
JM
6388 else if (old_die)
6389 {
4b674448
JM
6390 register unsigned file_index
6391 = lookup_filename (DECL_SOURCE_FILE (decl));
bdb669cb
JM
6392 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
6393 abort ();
4b674448
JM
6394
6395 /* If the definition comes from the same place as the declaration,
6396 use the old DIE. */
6397 if (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
6398 && (get_AT_unsigned (old_die, DW_AT_decl_line)
6399 == DECL_SOURCE_LINE (decl)))
bdb669cb 6400 {
4b674448
JM
6401 subr_die = old_die;
6402
6403 /* Clear out the declaration attribute and the parm types. */
6404 remove_AT (subr_die, DW_AT_declaration);
6405 remove_children (subr_die);
6406 }
6407 else
6408 {
6409 subr_die = new_die (DW_TAG_subprogram, context_die);
6410 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
bdb669cb
JM
6411 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
6412 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
6413 if (get_AT_unsigned (old_die, DW_AT_decl_line)
6414 != DECL_SOURCE_LINE (decl))
6415 add_AT_unsigned
6416 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6417 }
6418 }
a3f97cbb
JW
6419 else
6420 {
ab72d377
JM
6421 subr_die = new_die (DW_TAG_subprogram,
6422 scope_die_for (decl, context_die));
273dbe67
JM
6423 if (TREE_PUBLIC (decl))
6424 add_AT_flag (subr_die, DW_AT_external, 1);
a3f97cbb 6425 add_name_and_src_coords_attributes (subr_die, decl);
4927276d
JM
6426 if (debug_info_level > DINFO_LEVEL_TERSE)
6427 {
6428 register tree type = TREE_TYPE (decl);
6429 add_prototyped_attribute (subr_die, type);
6430 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
6431 }
a3f97cbb 6432 add_pure_or_virtual_attribute (subr_die, decl);
273dbe67
JM
6433 if (DECL_ARTIFICIAL (decl))
6434 add_AT_flag (subr_die, DW_AT_artificial, 1);
bdb669cb
JM
6435
6436 /* The first time we see a member function, it is in the context of
6437 the class to which it belongs. We make sure of this by emitting
6438 the class first. The next time is the definition, which is
6439 handled above. The two may come from the same source text. */
6440 if (! DECL_INITIAL (decl))
6441 add_AT_flag (subr_die, DW_AT_declaration, 1);
a3f97cbb 6442 }
61b32c02 6443 if (DECL_ABSTRACT (decl))
a3f97cbb 6444 {
61b32c02
JM
6445 if (DECL_DEFER_OUTPUT (decl))
6446 {
6447 if (DECL_INLINE (decl))
6448 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
6449 else
6450 add_AT_unsigned (subr_die, DW_AT_inline,
6451 DW_INL_declared_not_inlined);
6452 }
6453 else if (DECL_INLINE (decl))
6454 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
6455 else
6456 abort ();
6457
a3f97cbb
JW
6458 equate_decl_number_to_die (decl, subr_die);
6459 }
61b32c02
JM
6460 else if (!DECL_INITIAL (decl))
6461 equate_decl_number_to_die (decl, subr_die);
a3f97cbb
JW
6462 else if (!DECL_EXTERNAL (decl))
6463 {
ba7b35df
JW
6464 if (origin == NULL)
6465 equate_decl_number_to_die (decl, subr_die);
5c90448c
JM
6466 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
6467 current_funcdef_number);
7d4440be 6468 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
5c90448c
JM
6469 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
6470 current_funcdef_number);
a3f97cbb
JW
6471 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
6472
d291dd49
JM
6473 add_pubname (decl, subr_die);
6474 add_arange (decl, subr_die);
6475
a3f97cbb 6476#ifdef MIPS_DEBUGGING_INFO
a3f97cbb
JW
6477 /* Add a reference to the FDE for this routine. */
6478 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
6479#endif
6480
810429b7
JM
6481 /* Define the "frame base" location for this routine. We use the
6482 frame pointer or stack pointer registers, since the RTL for local
6483 variables is relative to one of them. */
6484 fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6485 ? FRAME_POINTER_REGNUM
6486 : STACK_POINTER_REGNUM);
a3f97cbb 6487 assert (fp_reg >= 0 && fp_reg <= 31);
810429b7 6488 fp_loc = new_loc_descr (DW_OP_reg0 + fp_reg);
a3f97cbb
JW
6489 add_AT_loc (subr_die, DW_AT_frame_base, fp_loc);
6490
6491#ifdef DWARF_GNU_EXTENSIONS
5c90448c
JM
6492 ASM_GENERATE_INTERNAL_LABEL (label_id, BODY_BEGIN_LABEL,
6493 current_funcdef_number);
a3f97cbb 6494 add_AT_lbl_id (subr_die, DW_AT_body_begin, label_id);
5c90448c
JM
6495 ASM_GENERATE_INTERNAL_LABEL (label_id, BODY_END_LABEL,
6496 current_funcdef_number);
a3f97cbb
JW
6497 add_AT_lbl_id (subr_die, DW_AT_body_end, label_id);
6498#endif
6499
6500 }
6501
6502 /* Now output descriptions of the arguments for this function. This gets
6503 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
6504 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
6505 `...' at the end of the formal parameter list. In order to find out if
6506 there was a trailing ellipsis or not, we must instead look at the type
6507 associated with the FUNCTION_DECL. This will be a node of type
6508 FUNCTION_TYPE. If the chain of type nodes hanging off of this
6509 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
6510 an ellipsis at the end. */
6511
ab72d377 6512 push_decl_scope (decl);
a3f97cbb
JW
6513 /* In the case where we are describing a mere function declaration, all we
6514 need to do here (and all we *can* do here) is to describe the *types* of
6515 its formal parameters. */
4927276d
JM
6516 if (debug_info_level <= DINFO_LEVEL_TERSE)
6517 /* do nothing */;
6518 else if (DECL_INITIAL (decl) == NULL_TREE)
a3f97cbb
JW
6519 {
6520 gen_formal_types_die (TREE_TYPE (decl), subr_die);
6521 }
6522 else
6523 {
6524 /* Generate DIEs to represent all known formal parameters */
6525 register tree arg_decls = DECL_ARGUMENTS (decl);
6526 register tree parm;
6527
6528 /* When generating DIEs, generate the unspecified_parameters DIE
6529 instead if we come across the arg "__builtin_va_alist" */
6530 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
6531 {
6532 if (TREE_CODE (parm) == PARM_DECL)
6533 {
6534 if (DECL_NAME (parm) &&
6535 !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
6536 "__builtin_va_alist"))
6537 {
6538 gen_unspecified_parameters_die (parm, subr_die);
6539 }
6540 else
6541 {
6542 gen_decl_die (parm, subr_die);
6543 }
6544 }
6545 }
6546
6547 /* Decide whether we need a unspecified_parameters DIE at the end.
6548 There are 2 more cases to do this for: 1) the ansi ... declaration -
6549 this is detectable when the end of the arg list is not a
6550 void_type_node 2) an unprototyped function declaration (not a
6551 definition). This just means that we have no info about the
6552 parameters at all. */
6553 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
6554 if (fn_arg_types)
6555 {
6556 /* this is the prototyped case, check for ... */
6557 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
6558 {
6559 gen_unspecified_parameters_die (decl, subr_die);
6560 }
6561 }
6562 else
6563 {
6564 /* this is unprotoyped, check for undefined (just declaration) */
6565 if (!DECL_INITIAL (decl))
6566 {
6567 gen_unspecified_parameters_die (decl, subr_die);
6568 }
6569 }
6570 }
6571
6572 /* Output Dwarf info for all of the stuff within the body of the function
6573 (if it has one - it may be just a declaration). */
6574 outer_scope = DECL_INITIAL (decl);
6575
d7248bff
JM
6576 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
6577 node created to represent a function. This outermost BLOCK actually
6578 represents the outermost binding contour for the function, i.e. the
6579 contour in which the function's formal parameters and labels get
6580 declared. Curiously, it appears that the front end doesn't actually
6581 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
6582 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
6583 list for the function instead.) The BLOCK_VARS list for the
6584 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
6585 the function however, and we output DWARF info for those in
6586 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
6587 node representing the function's outermost pair of curly braces, and
6588 any blocks used for the base and member initializers of a C++
6589 constructor function. */
a3f97cbb 6590 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
7e23cb16
JM
6591 {
6592 current_function_has_inlines = 0;
6593 decls_for_scope (outer_scope, subr_die, 0);
ce61cc73 6594#if 0 && defined (MIPS_DEBUGGING_INFO)
7e23cb16
JM
6595 if (current_function_has_inlines)
6596 {
6597 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
6598 if (! comp_unit_has_inlines)
6599 {
6600 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
6601 comp_unit_has_inlines = 1;
6602 }
6603 }
6604#endif
6605 }
ab72d377 6606 pop_decl_scope ();
a3f97cbb
JW
6607}
6608
6609/* Generate a DIE to represent a declared data object. */
6610static void
6611gen_variable_die (decl, context_die)
6612 register tree decl;
6613 register dw_die_ref context_die;
6614{
6615 register tree origin = decl_ultimate_origin (decl);
6616 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
bdb669cb
JM
6617 dw_die_ref old_die = lookup_decl_die (decl);
6618
a3f97cbb
JW
6619 if (origin != NULL)
6620 {
6621 add_abstract_origin_attribute (var_die, origin);
6622 }
bdb669cb
JM
6623 else if (old_die)
6624 {
6625 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
6626 abort ();
6627 add_AT_die_ref (var_die, DW_AT_specification, old_die);
6628 if (DECL_NAME (decl))
6629 {
6630 register unsigned file_index
6631 = lookup_filename (DECL_SOURCE_FILE (decl));
6632 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
6633 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
6634 if (get_AT_unsigned (old_die, DW_AT_decl_line)
6635 != DECL_SOURCE_LINE (decl))
6636 add_AT_unsigned
6637 (var_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6638 }
6639 }
a3f97cbb
JW
6640 else
6641 {
6642 add_name_and_src_coords_attributes (var_die, decl);
a3f97cbb
JW
6643 add_type_attribute (var_die, TREE_TYPE (decl),
6644 TREE_READONLY (decl),
6645 TREE_THIS_VOLATILE (decl), context_die);
273dbe67
JM
6646 if (TREE_PUBLIC (decl))
6647 add_AT_flag (var_die, DW_AT_external, 1);
6648 if (DECL_ARTIFICIAL (decl))
6649 add_AT_flag (var_die, DW_AT_artificial, 1);
a3f97cbb
JW
6650 }
6651 if (DECL_ABSTRACT (decl))
6652 {
6653 equate_decl_number_to_die (decl, var_die);
6654 }
6655 else if (!DECL_EXTERNAL (decl))
6656 {
7e23cb16
JM
6657 if (TREE_STATIC (decl))
6658 equate_decl_number_to_die (decl, var_die);
a3f97cbb 6659 add_location_or_const_value_attribute (var_die, decl);
d291dd49 6660 add_pubname (decl, var_die);
a3f97cbb 6661 }
bdb669cb
JM
6662 else if (decl_class_context (decl))
6663 {
6664 equate_decl_number_to_die (decl, var_die);
6665 add_AT_flag (var_die, DW_AT_declaration, 1);
6666 }
a3f97cbb
JW
6667}
6668
6669/* Generate a DIE to represent a label identifier. */
6670static void
6671gen_label_die (decl, context_die)
6672 register tree decl;
6673 register dw_die_ref context_die;
6674{
6675 register tree origin = decl_ultimate_origin (decl);
6676 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
6677 register rtx insn;
6678 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5c90448c 6679 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
a3f97cbb
JW
6680 if (origin != NULL)
6681 {
6682 add_abstract_origin_attribute (lbl_die, origin);
6683 }
6684 else
6685 {
6686 add_name_and_src_coords_attributes (lbl_die, decl);
6687 }
6688 if (DECL_ABSTRACT (decl))
6689 {
6690 equate_decl_number_to_die (decl, lbl_die);
6691 }
6692 else
6693 {
6694 insn = DECL_RTL (decl);
6695 if (GET_CODE (insn) == CODE_LABEL)
6696 {
6697 /* When optimization is enabled (via -O) some parts of the compiler
6698 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
6699 represent source-level labels which were explicitly declared by
6700 the user. This really shouldn't be happening though, so catch
6701 it if it ever does happen. */
6702 if (INSN_DELETED_P (insn))
6703 {
6704 abort (); /* Should never happen. */
6705 }
5c90448c
JM
6706 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
6707 ASM_GENERATE_INTERNAL_LABEL (label, label2,
6708 (unsigned) INSN_UID (insn));
a3f97cbb
JW
6709 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
6710 }
6711 }
6712}
6713
6714/* Generate a DIE for a lexical block. */
6715static void
d7248bff 6716gen_lexical_block_die (stmt, context_die, depth)
a3f97cbb
JW
6717 register tree stmt;
6718 register dw_die_ref context_die;
d7248bff 6719 int depth;
a3f97cbb
JW
6720{
6721 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
6722 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6723 if (!BLOCK_ABSTRACT (stmt))
6724 {
5c90448c
JM
6725 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
6726 next_block_number);
a3f97cbb 6727 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
5c90448c 6728 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
a3f97cbb
JW
6729 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
6730 }
7d4440be 6731 push_decl_scope (stmt);
d7248bff 6732 decls_for_scope (stmt, stmt_die, depth);
7d4440be 6733 pop_decl_scope ();
a3f97cbb
JW
6734}
6735
6736/* Generate a DIE for an inlined subprogram. */
6737static void
d7248bff 6738gen_inlined_subroutine_die (stmt, context_die, depth)
a3f97cbb
JW
6739 register tree stmt;
6740 register dw_die_ref context_die;
d7248bff 6741 int depth;
a3f97cbb 6742{
a3f97cbb
JW
6743 if (!BLOCK_ABSTRACT (stmt))
6744 {
d7248bff 6745 register dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine,
7e23cb16 6746 context_die);
ab72d377 6747 register tree decl = block_ultimate_origin (stmt);
d7248bff 6748 char label[MAX_ARTIFICIAL_LABEL_BYTES];
ab72d377 6749 add_abstract_origin_attribute (subr_die, decl);
5c90448c
JM
6750 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
6751 next_block_number);
a3f97cbb 6752 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
5c90448c 6753 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
a3f97cbb 6754 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
ab72d377 6755 push_decl_scope (decl);
d7248bff 6756 decls_for_scope (stmt, subr_die, depth);
ab72d377 6757 pop_decl_scope ();
7e23cb16 6758 current_function_has_inlines = 1;
a3f97cbb 6759 }
a3f97cbb
JW
6760}
6761
6762/* Generate a DIE for a field in a record, or structure. */
6763static void
6764gen_field_die (decl, context_die)
6765 register tree decl;
6766 register dw_die_ref context_die;
6767{
6768 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
6769 add_name_and_src_coords_attributes (decl_die, decl);
a3f97cbb
JW
6770 add_type_attribute (decl_die, member_declared_type (decl),
6771 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
6772 context_die);
6773 /* If this is a bit field... */
6774 if (DECL_BIT_FIELD_TYPE (decl))
6775 {
6776 add_byte_size_attribute (decl_die, decl);
6777 add_bit_size_attribute (decl_die, decl);
6778 add_bit_offset_attribute (decl_die, decl);
6779 }
6780 add_data_member_location_attribute (decl_die, decl);
273dbe67
JM
6781 if (DECL_ARTIFICIAL (decl))
6782 add_AT_flag (decl_die, DW_AT_artificial, 1);
a3f97cbb
JW
6783}
6784
ab72d377
JM
6785#if 0
6786/* Don't generate either pointer_type DIEs or reference_type DIEs here.
6787 Use modified_type_die instead.
a3f97cbb
JW
6788 We keep this code here just in case these types of DIEs may be needed to
6789 represent certain things in other languages (e.g. Pascal) someday. */
6790static void
6791gen_pointer_type_die (type, context_die)
6792 register tree type;
6793 register dw_die_ref context_die;
6794{
273dbe67
JM
6795 register dw_die_ref ptr_die = new_die
6796 (DW_TAG_pointer_type, scope_die_for (type, context_die));
a3f97cbb 6797 equate_type_number_to_die (type, ptr_die);
a3f97cbb 6798 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
ab72d377 6799 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
a3f97cbb
JW
6800}
6801
ab72d377
JM
6802/* Don't generate either pointer_type DIEs or reference_type DIEs here.
6803 Use modified_type_die instead.
a3f97cbb
JW
6804 We keep this code here just in case these types of DIEs may be needed to
6805 represent certain things in other languages (e.g. Pascal) someday. */
6806static void
6807gen_reference_type_die (type, context_die)
6808 register tree type;
6809 register dw_die_ref context_die;
6810{
273dbe67
JM
6811 register dw_die_ref ref_die = new_die
6812 (DW_TAG_reference_type, scope_die_for (type, context_die));
a3f97cbb 6813 equate_type_number_to_die (type, ref_die);
a3f97cbb 6814 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
ab72d377 6815 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
a3f97cbb 6816}
ab72d377 6817#endif
a3f97cbb
JW
6818
6819/* Generate a DIE for a pointer to a member type. */
6820static void
6821gen_ptr_to_mbr_type_die (type, context_die)
6822 register tree type;
6823 register dw_die_ref context_die;
6824{
ab72d377 6825 register dw_die_ref ptr_die = new_die
273dbe67 6826 (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
a3f97cbb 6827 equate_type_number_to_die (type, ptr_die);
a3f97cbb 6828 add_AT_die_ref (ptr_die, DW_AT_containing_type,
bdb669cb 6829 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
a3f97cbb
JW
6830 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
6831}
6832
6833/* Generate the DIE for the compilation unit. */
6834static void
6835gen_compile_unit_die (main_input_filename)
6836 register char *main_input_filename;
6837{
6838 char producer[250];
a3f97cbb
JW
6839 char *wd = getpwd ();
6840
6841 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
6842
bdb669cb
JM
6843 add_name_attribute (comp_unit_die, main_input_filename);
6844
6845 if (wd)
a3f97cbb 6846 {
bdb669cb 6847 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
a3f97cbb
JW
6848 }
6849
6850 sprintf (producer, "%s %s", language_string, version_string);
6851
6852#ifdef MIPS_DEBUGGING_INFO
6853 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
6854 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
6855 not appear in the producer string, the debugger reaches the conclusion
6856 that the object file is stripped and has no debugging information.
6857 To get the MIPS/SGI debugger to believe that there is debugging
6858 information in the object file, we add a -g to the producer string. */
4927276d
JM
6859 if (debug_info_level > DINFO_LEVEL_TERSE)
6860 strcat (producer, " -g");
a3f97cbb
JW
6861#endif
6862
6863 add_AT_string (comp_unit_die, DW_AT_producer, producer);
a9d38797 6864
a3f97cbb 6865 if (strcmp (language_string, "GNU C++") == 0)
a9d38797 6866 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
a3f97cbb 6867 else if (strcmp (language_string, "GNU Ada") == 0)
a9d38797
JM
6868 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
6869 else if (strcmp (language_string, "GNU F77") == 0)
6870 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
a3f97cbb 6871 else if (flag_traditional)
a9d38797 6872 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
a3f97cbb 6873 else
a9d38797
JM
6874 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
6875
6876#if 0 /* unimplemented */
e90b62db 6877 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
a9d38797
JM
6878 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
6879#endif
a3f97cbb
JW
6880}
6881
6882/* Generate a DIE for a string type. */
6883static void
6884gen_string_type_die (type, context_die)
6885 register tree type;
6886 register dw_die_ref context_die;
6887{
ab72d377
JM
6888 register dw_die_ref type_die = new_die
6889 (DW_TAG_string_type, scope_die_for (type, context_die));
bdb669cb 6890 equate_type_number_to_die (type, type_die);
a3f97cbb
JW
6891
6892 /* Fudge the string length attribute for now. */
6893
6894 /* TODO: add string length info.
6895 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6896 bound_representation (upper_bound, 0, 'u'); */
6897}
6898
61b32c02
JM
6899/* Generate the DIE for a base class. */
6900static void
6901gen_inheritance_die (binfo, context_die)
6902 register tree binfo;
6903 register dw_die_ref context_die;
6904{
6905 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
6906 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
6907 add_data_member_location_attribute (die, binfo);
6908 if (TREE_VIA_VIRTUAL (binfo))
6909 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
6910 if (TREE_VIA_PUBLIC (binfo))
6911 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
6912 else if (TREE_VIA_PROTECTED (binfo))
6913 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
6914}
6915
a3f97cbb
JW
6916/* Genearate a DIE for a class member. */
6917static void
6918gen_member_die (type, context_die)
6919 register tree type;
6920 register dw_die_ref context_die;
6921{
61b32c02 6922 register tree member;
a3f97cbb
JW
6923 /* If this is not an incomplete type, output descriptions of each of its
6924 members. Note that as we output the DIEs necessary to represent the
6925 members of this record or union type, we will also be trying to output
6926 DIEs to represent the *types* of those members. However the `type'
6927 function (above) will specifically avoid generating type DIEs for member
6928 types *within* the list of member DIEs for this (containing) type execpt
6929 for those types (of members) which are explicitly marked as also being
6930 members of this (containing) type themselves. The g++ front- end can
6931 force any given type to be treated as a member of some other
6932 (containing) type by setting the TYPE_CONTEXT of the given (member) type
6933 to point to the TREE node representing the appropriate (containing)
6934 type. */
6935
61b32c02
JM
6936 /* First output info about the base classes. */
6937 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
a3f97cbb 6938 {
61b32c02
JM
6939 register tree bases = TYPE_BINFO_BASETYPES (type);
6940 register int n_bases = TREE_VEC_LENGTH (bases);
6941 register int i;
6942
6943 for (i = 0; i < n_bases; i++)
6944 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
a3f97cbb
JW
6945 }
6946
61b32c02
JM
6947 /* Now output info about the data members and type members. */
6948 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
6949 gen_decl_die (member, context_die);
6950
a3f97cbb 6951 /* Now output info about the function members (if any). */
61b32c02
JM
6952 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
6953 gen_decl_die (member, context_die);
a3f97cbb
JW
6954}
6955
6956/* Generate a DIE for a structure or union type. */
6957static void
273dbe67 6958gen_struct_or_union_type_die (type, context_die)
a3f97cbb 6959 register tree type;
a3f97cbb
JW
6960 register dw_die_ref context_die;
6961{
273dbe67 6962 register dw_die_ref type_die = lookup_type_die (type);
a082c85a
JM
6963 register dw_die_ref scope_die = 0;
6964 register int nested = 0;
273dbe67
JM
6965
6966 if (type_die && ! TYPE_SIZE (type))
6967 return;
a082c85a
JM
6968
6969 if (TYPE_CONTEXT (type)
6970 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
6971 nested = 1;
6972
6973 if (! type_die || nested)
6974 scope_die = scope_die_for (type, context_die);
6975
6976 if (! type_die || (nested && scope_die == comp_unit_die))
273dbe67 6977 /* First occurrence of type or toplevel definition of nested class. */
a3f97cbb 6978 {
273dbe67 6979 register dw_die_ref old_die = type_die;
a3f97cbb
JW
6980 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
6981 ? DW_TAG_structure_type : DW_TAG_union_type,
a082c85a 6982 scope_die);
a3f97cbb
JW
6983 equate_type_number_to_die (type, type_die);
6984 add_name_attribute (type_die, type_tag (type));
273dbe67
JM
6985 if (old_die)
6986 add_AT_die_ref (type_die, DW_AT_specification, old_die);
a3f97cbb 6987 }
4b674448 6988 else
273dbe67 6989 remove_AT (type_die, DW_AT_declaration);
a3f97cbb
JW
6990
6991 /* If this type has been completed, then give it a byte_size attribute and
6992 then give a list of members. */
a082c85a
JM
6993 if (TYPE_SIZE (type)
6994 /* If we're getting a reference to one nested class from another
6995 nested class, don't recurse. */
6996 && ! (nested && scope_die != context_die
6997 && scope_die == lookup_type_die (TYPE_CONTEXT (type))))
a3f97cbb
JW
6998 {
6999 /* Prevent infinite recursion in cases where the type of some member of
7000 this type is expressed in terms of this type itself. */
7001 TREE_ASM_WRITTEN (type) = 1;
273dbe67
JM
7002 add_byte_size_attribute (type_die, type);
7003 push_decl_scope (type);
7004 gen_member_die (type, type_die);
7005 pop_decl_scope ();
a3f97cbb 7006 }
4b674448
JM
7007 else
7008 add_AT_flag (type_die, DW_AT_declaration, 1);
a3f97cbb
JW
7009}
7010
7011/* Generate a DIE for a subroutine _type_. */
7012static void
7013gen_subroutine_type_die (type, context_die)
7014 register tree type;
7015 register dw_die_ref context_die;
7016{
7017 register tree return_type = TREE_TYPE (type);
273dbe67
JM
7018 register dw_die_ref subr_die = new_die
7019 (DW_TAG_subroutine_type, scope_die_for (type, context_die));
a3f97cbb
JW
7020 equate_type_number_to_die (type, subr_die);
7021 add_prototyped_attribute (subr_die, type);
a3f97cbb
JW
7022 add_type_attribute (subr_die, return_type, 0, 0, context_die);
7023 gen_formal_types_die (type, context_die);
7024}
7025
7026/* Generate a DIE for a type definition */
7027static void
7028gen_typedef_die (decl, context_die)
7029 register tree decl;
7030 register dw_die_ref context_die;
7031{
7032 register tree origin = decl_ultimate_origin (decl);
7033 register dw_die_ref type_die;
ab72d377 7034 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
a3f97cbb
JW
7035 if (origin != NULL)
7036 {
7037 add_abstract_origin_attribute (type_die, origin);
7038 }
7039 else
7040 {
7041 add_name_and_src_coords_attributes (type_die, decl);
a3f97cbb
JW
7042 add_type_attribute (type_die, TREE_TYPE (decl),
7043 TREE_READONLY (decl),
7044 TREE_THIS_VOLATILE (decl),
7045 context_die);
7046 }
7047 if (DECL_ABSTRACT (decl))
7048 {
7049 equate_decl_number_to_die (decl, type_die);
7050 }
7051}
7052
7053/* Generate a type description DIE. */
7054static void
7055gen_type_die (type, context_die)
7056 register tree type;
7057 register dw_die_ref context_die;
7058{
a3f97cbb
JW
7059 if (type == 0 || type == error_mark_node)
7060 {
7061 return;
7062 }
7063
7064 /* We are going to output a DIE to represent the unqualified version of of
7065 this type (i.e. without any const or volatile qualifiers) so get the
7066 main variant (i.e. the unqualified version) of this type now. */
7067 type = type_main_variant (type);
7068
7069 if (TREE_ASM_WRITTEN (type))
7070 {
7071 return;
7072 }
7073
7074 switch (TREE_CODE (type))
7075 {
7076 case ERROR_MARK:
7077 break;
7078
7079 case POINTER_TYPE:
7080 case REFERENCE_TYPE:
7081 /* For these types, all that is required is that we output a DIE (or a
7082 set of DIEs) to represent the "basis" type. */
7083 gen_type_die (TREE_TYPE (type), context_die);
7084 break;
7085
7086 case OFFSET_TYPE:
7087 /* This code is used for C++ pointer-to-data-member types. */
7088 /* Output a description of the relevant class type. */
7089 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
7090 /* Output a description of the type of the object pointed to. */
7091 gen_type_die (TREE_TYPE (type), context_die);
7092 /* Now output a DIE to represent this pointer-to-data-member type
7093 itself. */
7094 gen_ptr_to_mbr_type_die (type, context_die);
7095 break;
7096
7097 case SET_TYPE:
7098 gen_type_die (TYPE_DOMAIN (type), context_die);
7099 gen_set_type_die (type, context_die);
7100 break;
7101
7102 case FILE_TYPE:
7103 gen_type_die (TREE_TYPE (type), context_die);
7104 abort (); /* No way to represent these in Dwarf yet! */
7105 break;
7106
7107 case FUNCTION_TYPE:
7108 /* Force out return type (in case it wasn't forced out already). */
7109 gen_type_die (TREE_TYPE (type), context_die);
7110 gen_subroutine_type_die (type, context_die);
7111 break;
7112
7113 case METHOD_TYPE:
7114 /* Force out return type (in case it wasn't forced out already). */
7115 gen_type_die (TREE_TYPE (type), context_die);
7116 gen_subroutine_type_die (type, context_die);
7117 break;
7118
7119 case ARRAY_TYPE:
7120 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
7121 {
7122 gen_type_die (TREE_TYPE (type), context_die);
7123 gen_string_type_die (type, context_die);
7124 }
7125 else
7126 {
7127 gen_array_type_die (type, context_die);
7128 }
7129 break;
7130
7131 case ENUMERAL_TYPE:
7132 case RECORD_TYPE:
7133 case UNION_TYPE:
7134 case QUAL_UNION_TYPE:
a082c85a
JM
7135 /* If this is a nested type whose containing class hasn't been
7136 written out yet, writing it out will cover this one, too. */
7137 if (TYPE_CONTEXT (type)
7138 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
7139 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
7140 gen_type_die (TYPE_CONTEXT (type), context_die);
7141 else if (TREE_CODE (type) == ENUMERAL_TYPE)
273dbe67 7142 gen_enumeration_type_die (type, context_die);
a3f97cbb 7143 else
273dbe67 7144 gen_struct_or_union_type_die (type, context_die);
4b674448
JM
7145
7146 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
a082c85a
JM
7147 it up if it is ever completed. gen_*_type_die will set it for us
7148 when appropriate. */
7149 return;
a3f97cbb
JW
7150
7151 case VOID_TYPE:
7152 case INTEGER_TYPE:
7153 case REAL_TYPE:
7154 case COMPLEX_TYPE:
7155 case BOOLEAN_TYPE:
7156 case CHAR_TYPE:
7157 /* No DIEs needed for fundamental types. */
7158 break;
7159
7160 case LANG_TYPE:
7161 /* No Dwarf representation currently defined. */
7162 break;
7163
7164 default:
7165 abort ();
7166 }
7167
7168 TREE_ASM_WRITTEN (type) = 1;
7169}
7170
7171/* Generate a DIE for a tagged type instantiation. */
7172static void
7173gen_tagged_type_instantiation_die (type, context_die)
7174 register tree type;
7175 register dw_die_ref context_die;
7176{
7177 if (type == 0 || type == error_mark_node)
7178 {
7179 return;
7180 }
7181
7182 /* We are going to output a DIE to represent the unqualified version of of
7183 this type (i.e. without any const or volatile qualifiers) so make sure
7184 that we have the main variant (i.e. the unqualified version) of this
7185 type now. */
7186 assert (type == type_main_variant (type));
7187 assert (TREE_ASM_WRITTEN (type));
7188
7189 switch (TREE_CODE (type))
7190 {
7191 case ERROR_MARK:
7192 break;
7193
7194 case ENUMERAL_TYPE:
7195 gen_inlined_enumeration_type_die (type, context_die);
7196 break;
7197
7198 case RECORD_TYPE:
7199 gen_inlined_structure_type_die (type, context_die);
7200 break;
7201
7202 case UNION_TYPE:
7203 case QUAL_UNION_TYPE:
7204 gen_inlined_union_type_die (type, context_die);
7205 break;
7206
7207 default:
7208 abort (); /* Should never happen. */
7209 }
7210}
7211
7212/* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
7213 things which are local to the given block. */
7214static void
d7248bff 7215gen_block_die (stmt, context_die, depth)
a3f97cbb
JW
7216 register tree stmt;
7217 register dw_die_ref context_die;
d7248bff 7218 int depth;
a3f97cbb
JW
7219{
7220 register int must_output_die = 0;
7221 register tree origin;
7222 register tree decl;
7223 register enum tree_code origin_code;
7224
7225 /* Ignore blocks never really used to make RTL. */
7226
7227 if (!stmt || !TREE_USED (stmt))
7228 {
7229 return;
7230 }
7231
7232 /* Determine the "ultimate origin" of this block. This block may be an
7233 inlined instance of an inlined instance of inline function, so we have
7234 to trace all of the way back through the origin chain to find out what
7235 sort of node actually served as the original seed for the creation of
7236 the current block. */
7237 origin = block_ultimate_origin (stmt);
7238 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
7239
7240 /* Determine if we need to output any Dwarf DIEs at all to represent this
7241 block. */
7242 if (origin_code == FUNCTION_DECL)
7243 {
7244 /* The outer scopes for inlinings *must* always be represented. We
7245 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
7246 must_output_die = 1;
7247 }
7248 else
7249 {
7250 /* In the case where the current block represents an inlining of the
7251 "body block" of an inline function, we must *NOT* output any DIE for
7252 this block because we have already output a DIE to represent the
7253 whole inlined function scope and the "body block" of any function
7254 doesn't really represent a different scope according to ANSI C
7255 rules. So we check here to make sure that this block does not
7256 represent a "body block inlining" before trying to set the
7257 `must_output_die' flag. */
d7248bff 7258 if (! is_body_block (origin ? origin : stmt))
a3f97cbb
JW
7259 {
7260 /* Determine if this block directly contains any "significant"
7261 local declarations which we will need to output DIEs for. */
7262 if (debug_info_level > DINFO_LEVEL_TERSE)
7263 {
7264 /* We are not in terse mode so *any* local declaration counts
7265 as being a "significant" one. */
7266 must_output_die = (BLOCK_VARS (stmt) != NULL);
7267 }
7268 else
7269 {
7270 /* We are in terse mode, so only local (nested) function
7271 definitions count as "significant" local declarations. */
7272 for (decl = BLOCK_VARS (stmt);
7273 decl != NULL; decl = TREE_CHAIN (decl))
7274 {
7275 if (TREE_CODE (decl) == FUNCTION_DECL
7276 && DECL_INITIAL (decl))
7277 {
7278 must_output_die = 1;
7279 break;
7280 }
7281 }
7282 }
7283 }
7284 }
7285
7286 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
7287 DIE for any block which contains no significant local declarations at
7288 all. Rather, in such cases we just call `decls_for_scope' so that any
7289 needed Dwarf info for any sub-blocks will get properly generated. Note
7290 that in terse mode, our definition of what constitutes a "significant"
7291 local declaration gets restricted to include only inlined function
7292 instances and local (nested) function definitions. */
7293 if (must_output_die)
7294 {
7295 if (origin_code == FUNCTION_DECL)
7296 {
d7248bff 7297 gen_inlined_subroutine_die (stmt, context_die, depth);
a3f97cbb
JW
7298 }
7299 else
7300 {
d7248bff 7301 gen_lexical_block_die (stmt, context_die, depth);
a3f97cbb
JW
7302 }
7303 }
7304 else
d7248bff 7305 decls_for_scope (stmt, context_die, depth);
a3f97cbb
JW
7306}
7307
7308/* Generate all of the decls declared within a given scope and (recursively)
7309 all of it's sub-blocks. */
7310static void
d7248bff 7311decls_for_scope (stmt, context_die, depth)
a3f97cbb
JW
7312 register tree stmt;
7313 register dw_die_ref context_die;
d7248bff 7314 int depth;
a3f97cbb
JW
7315{
7316 register tree decl;
7317 register tree subblocks;
7318 /* Ignore blocks never really used to make RTL. */
7319 if (!stmt || !TREE_USED (stmt))
7320 {
7321 return;
7322 }
d7248bff 7323 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
a3f97cbb
JW
7324 {
7325 next_block_number++;
7326 }
7327
7328 /* Output the DIEs to represent all of the data objects, functions,
7329 typedefs, and tagged types declared directly within this block but not
7330 within any nested sub-blocks. */
7331 for (decl = BLOCK_VARS (stmt);
7332 decl != NULL; decl = TREE_CHAIN (decl))
7333 {
7334 gen_decl_die (decl, context_die);
7335 }
7336
7337 /* Output the DIEs to represent all sub-blocks (and the items declared
7338 therein) of this block. */
7339 for (subblocks = BLOCK_SUBBLOCKS (stmt);
7340 subblocks != NULL;
7341 subblocks = BLOCK_CHAIN (subblocks))
7342 {
d7248bff 7343 gen_block_die (subblocks, context_die, depth + 1);
a3f97cbb
JW
7344 }
7345}
7346
7347/* Generate Dwarf debug information for a decl described by DECL. */
7348static void
7349gen_decl_die (decl, context_die)
7350 register tree decl;
7351 register dw_die_ref context_die;
7352{
7353 register tree origin;
7354 /* Make a note of the decl node we are going to be working on. We may need
7355 to give the user the source coordinates of where it appeared in case we
7356 notice (later on) that something about it looks screwy. */
7357 dwarf_last_decl = decl;
7358
7359 if (TREE_CODE (decl) == ERROR_MARK)
7360 {
7361 return;
7362 }
7363
7364 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
7365 ignore a function definition, since that would screw up our count of
7366 blocks, and that it turn will completely screw up the the labels we will
7367 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7368 subsequent blocks). */
7369 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
7370 {
7371 return;
7372 }
7373
a3f97cbb
JW
7374 switch (TREE_CODE (decl))
7375 {
7376 case CONST_DECL:
7377 /* The individual enumerators of an enum type get output when we output
7378 the Dwarf representation of the relevant enum type itself. */
7379 break;
7380
7381 case FUNCTION_DECL:
7382 /* If we are in terse mode, don't output any DIEs to represent mere
bdb669cb
JM
7383 function declarations, unless they are class members. */
7384 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE)
a3f97cbb
JW
7385 {
7386 break;
7387 }
bdb669cb 7388
a3f97cbb
JW
7389 /* Before we describe the FUNCTION_DECL itself, make sure that we have
7390 described its return type. */
4927276d
JM
7391 if (debug_info_level > DINFO_LEVEL_TERSE)
7392 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
a3f97cbb
JW
7393
7394 /* Now output a DIE to represent the function itself. */
7395 gen_subprogram_die (decl, context_die);
7396 break;
7397
7398 case TYPE_DECL:
7399 /* If we are in terse mode, don't generate any DIEs to represent any
4927276d 7400 actual typedefs. */
a3f97cbb 7401 if (debug_info_level <= DINFO_LEVEL_TERSE)
4927276d 7402 break;
a3f97cbb 7403
5c90448c
JM
7404 /* In the special case of a TYPE_DECL node representing the
7405 declaration of some type tag, if the given TYPE_DECL is marked as
a3f97cbb
JW
7406 having been instantiated from some other (original) TYPE_DECL node
7407 (e.g. one which was generated within the original definition of an
7408 inline function) we have to generate a special (abbreviated)
7409 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type
7410 DIE here. */
5c90448c 7411 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
a3f97cbb
JW
7412 {
7413 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
7414 break;
7415 }
7416 gen_type_die (TREE_TYPE (decl), context_die);
7417
5c90448c 7418 if (! TYPE_DECL_IS_STUB (decl))
a3f97cbb
JW
7419 {
7420 /* Output a DIE to represent the typedef itself. */
7421 gen_typedef_die (decl, context_die);
7422 }
7423 break;
7424
7425 case LABEL_DECL:
7426 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7427 {
7428 gen_label_die (decl, context_die);
7429 }
7430 break;
7431
7432 case VAR_DECL:
7433 /* If we are in terse mode, don't generate any DIEs to represent any
7434 variable declarations or definitions. */
7435 if (debug_info_level <= DINFO_LEVEL_TERSE)
7436 {
7437 break;
7438 }
7439
7440 /* Output any DIEs that are needed to specify the type of this data
7441 object. */
7442 gen_type_die (TREE_TYPE (decl), context_die);
7443
7444 /* Now output the DIE to represent the data object itself. This gets
7445 complicated because of the possibility that the VAR_DECL really
7446 represents an inlined instance of a formal parameter for an inline
7447 function. */
7448 origin = decl_ultimate_origin (decl);
7449 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
7450 {
7451 gen_formal_parameter_die (decl, context_die);
7452 }
7453 else
7454 {
7455 gen_variable_die (decl, context_die);
7456 }
7457 break;
7458
7459 case FIELD_DECL:
7460 /* Ignore the nameless fields that are used to skip bits. */
7461 if (DECL_NAME (decl) != 0)
7462 {
7463 gen_type_die (member_declared_type (decl), context_die);
7464 gen_field_die (decl, context_die);
7465 }
7466 break;
7467
7468 case PARM_DECL:
7469 gen_type_die (TREE_TYPE (decl), context_die);
7470 gen_formal_parameter_die (decl, context_die);
7471 break;
7472
7473 default:
7474 abort ();
7475 }
a3f97cbb
JW
7476}
7477\f
7478/***************** Debug Information Generation Hooks ***********************/
7479void
9a666dda 7480dwarf2out_file_scope_decl (decl, set_finalizing)
a3f97cbb
JW
7481 register tree decl;
7482 register int set_finalizing;
7483{
7484 if (TREE_CODE (decl) == ERROR_MARK)
7485 {
7486 return;
7487 }
7488
7489 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
7490 hope that the node in question doesn't represent a function definition.
7491 If it does, then totally ignoring it is bound to screw up our count of
7492 blocks, and that it turn will completely screw up the the labels we will
7493 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7494 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
7495 own sequence numbers with them!) */
7496 if (DECL_IGNORED_P (decl))
7497 {
7498 if (TREE_CODE (decl) == FUNCTION_DECL
7499 && DECL_INITIAL (decl) != NULL)
7500 {
7501 abort ();
7502 }
7503 return;
7504 }
7505
7506 switch (TREE_CODE (decl))
7507 {
7508 case FUNCTION_DECL:
7509 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
7510 builtin function. Explicit programmer-supplied declarations of
7511 these same functions should NOT be ignored however. */
7512 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
7513 {
7514 return;
7515 }
7516
7517 /* What we would really like to do here is to filter out all mere
7518 file-scope declarations of file-scope functions which are never
7519 referenced later within this translation unit (and keep all of ones
7520 that *are* referenced later on) but we aren't clarvoiant, so we have
7521 no idea which functions will be referenced in the future (i.e. later
7522 on within the current translation unit). So here we just ignore all
7523 file-scope function declarations which are not also definitions. If
7524 and when the debugger needs to know something about these funcstion,
7525 it wil have to hunt around and find the DWARF information associated
7526 with the definition of the function. Note that we can't just check
7527 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
7528 definitions and which ones represent mere declarations. We have to
7529 check `DECL_INITIAL' instead. That's because the C front-end
7530 supports some weird semantics for "extern inline" function
7531 definitions. These can get inlined within the current translation
7532 unit (an thus, we need to generate DWARF info for their abstract
7533 instances so that the DWARF info for the concrete inlined instances
7534 can have something to refer to) but the compiler never generates any
7535 out-of-lines instances of such things (despite the fact that they
7536 *are* definitions). The important point is that the C front-end
7537 marks these "extern inline" functions as DECL_EXTERNAL, but we need
273dbe67 7538 to generate DWARF for them anyway. Note that the C++ front-end also
a3f97cbb
JW
7539 plays some similar games for inline function definitions appearing
7540 within include files which also contain
7541 `#pragma interface' pragmas. */
7542 if (DECL_INITIAL (decl) == NULL_TREE)
7543 {
7544 return;
7545 }
7546 break;
7547
7548 case VAR_DECL:
7549 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
7550 declaration and if the declaration was never even referenced from
7551 within this entire compilation unit. We suppress these DIEs in
7552 order to save space in the .debug section (by eliminating entries
7553 which are probably useless). Note that we must not suppress
7554 block-local extern declarations (whether used or not) because that
7555 would screw-up the debugger's name lookup mechanism and cause it to
7556 miss things which really ought to be in scope at a given point. */
7557 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
7558 {
7559 return;
7560 }
7561
7562 /* If we are in terse mode, don't generate any DIEs to represent any
7563 variable declarations or definitions. */
7564 if (debug_info_level <= DINFO_LEVEL_TERSE)
7565 {
7566 return;
7567 }
7568 break;
7569
7570 case TYPE_DECL:
7571 /* Don't bother trying to generate any DIEs to represent any of the
a9d38797
JM
7572 normal built-in types for the language we are compiling. */
7573 if (DECL_SOURCE_LINE (decl) == 0)
7574 return;
a3f97cbb
JW
7575
7576 /* If we are in terse mode, don't generate any DIEs to represent any
4927276d 7577 actual typedefs. */
a3f97cbb 7578 if (debug_info_level <= DINFO_LEVEL_TERSE)
4927276d 7579 return;
a3f97cbb
JW
7580 break;
7581
7582 default:
7583 return;
7584 }
7585
a3f97cbb
JW
7586 gen_decl_die (decl, comp_unit_die);
7587
7588 if (TREE_CODE (decl) == FUNCTION_DECL
7589 && DECL_INITIAL (decl) != NULL)
7590 {
7591 current_funcdef_number++;
7592 }
7593
7594}
7595
7596/* Output a marker (i.e. a label) for the beginning of the generated code for
7597 a lexical block. */
7598void
9a666dda 7599dwarf2out_begin_block (blocknum)
a3f97cbb
JW
7600 register unsigned blocknum;
7601{
a3f97cbb 7602 function_section (current_function_decl);
5c90448c 7603 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
a3f97cbb
JW
7604}
7605
7606/* Output a marker (i.e. a label) for the end of the generated code for a
7607 lexical block. */
7608void
9a666dda 7609dwarf2out_end_block (blocknum)
a3f97cbb
JW
7610 register unsigned blocknum;
7611{
a3f97cbb 7612 function_section (current_function_decl);
5c90448c 7613 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
a3f97cbb
JW
7614}
7615
7616/* Output a marker (i.e. a label) at a point in the assembly code which
7617 corresponds to a given source level label. */
7618void
9a666dda 7619dwarf2out_label (insn)
a3f97cbb
JW
7620 register rtx insn;
7621{
7622 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7623 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7624 {
7625 function_section (current_function_decl);
5c90448c
JM
7626 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
7627 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
7628 (unsigned) INSN_UID (insn));
a3f97cbb
JW
7629 }
7630}
7631
d291dd49
JM
7632/* Output a marker (i.e. a label) for the beginning of a function, before
7633 the prologue. */
a3f97cbb 7634void
9a666dda 7635dwarf2out_begin_prologue ()
a3f97cbb
JW
7636{
7637 char label[MAX_ARTIFICIAL_LABEL_BYTES];
a3f97cbb 7638 register dw_fde_ref fde;
a3f97cbb
JW
7639
7640 function_section (current_function_decl);
5c90448c
JM
7641 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
7642 current_funcdef_number);
a3f97cbb
JW
7643 ASM_OUTPUT_LABEL (asm_out_file, label);
7644
7645 /* Expand the fde table if necessary. */
7646 if (fde_table_in_use == fde_table_allocated)
7647 {
7648 fde_table_allocated += FDE_TABLE_INCREMENT;
7649 fde_table = (dw_fde_ref) xrealloc (fde_table,
7650 fde_table_allocated * sizeof (dw_fde_node));
7651 }
7652
7653 /* Record the FDE associated with this function. */
7654 current_funcdef_fde = fde_table_in_use;
7655
7656 /* Add the new FDE at the end of the fde_table. */
7657 fde = &fde_table[fde_table_in_use++];
7d4440be 7658 fde->dw_fde_begin = xstrdup (label);
d291dd49 7659 fde->dw_fde_end_prolog = NULL;
a3f97cbb
JW
7660 fde->dw_fde_begin_epilogue = NULL;
7661 fde->dw_fde_end = NULL;
7662 fde->dw_fde_cfi = NULL;
d291dd49
JM
7663}
7664
7665/* Output a marker (i.e. a label) for the point in the generated code where
7666 the real body of the function begins (after parameters have been moved to
7667 their home locations). */
7668void
9a666dda 7669dwarf2out_begin_function ()
d291dd49
JM
7670{
7671 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7672 register long int offset;
7673 register dw_fde_ref fde;
7674 register dw_cfi_ref cfi;
7675
7676 function_section (current_function_decl);
5c90448c
JM
7677 ASM_GENERATE_INTERNAL_LABEL (label, BODY_BEGIN_LABEL,
7678 current_funcdef_number);
d291dd49
JM
7679 ASM_OUTPUT_LABEL (asm_out_file, label);
7680
7681 /* Record the end-of-prolog location in the FDE. */
7682 fde = &fde_table[fde_table_in_use - 1];
7683 fde->dw_fde_end_prolog = xstrdup (label);
a3f97cbb
JW
7684
7685#ifdef MIPS_DEBUGGING_INFO
7686
a3f97cbb
JW
7687 /* Set the location counter to the end of the function prolog. */
7688 cfi = new_cfi ();
7689 cfi->dw_cfi_opc = DW_CFA_advance_loc4;
7690 cfi->dw_cfi_oprnd1.dw_cfi_addr = xstrdup (label);
7691 add_cfi (&fde->dw_fde_cfi, cfi);
7692
c8cc5c4a
JM
7693 /* Define the CFA as an offset from either the frame pointer
7694 or the stack pointer. */
a3f97cbb
JW
7695 cfi = new_cfi ();
7696 cfi->dw_cfi_opc = DW_CFA_def_cfa;
810429b7 7697 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
c8cc5c4a
JM
7698 = DWARF_FRAME_REGNUM (frame_pointer_needed ? FRAME_POINTER_REGNUM
7699 : STACK_POINTER_REGNUM);
a3f97cbb
JW
7700 offset = current_frame_info.total_size;
7701 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7702 add_cfi (&fde->dw_fde_cfi, cfi);
7703
7704 /* record the frame size for later definition of the DW_AT_frame_base
7705 attribute. */
7706 current_funcdef_frame_size = offset;
7707
7708 /* Define the rule for restoring the stack pointer. */
7709 if (frame_pointer_needed)
7710 {
7711 /* Restore the stack register from the frame pointer. */
7712 cfi = new_cfi ();
7713 cfi->dw_cfi_opc = DW_CFA_register;
810429b7 7714 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
c8cc5c4a 7715 = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
810429b7 7716 cfi->dw_cfi_oprnd2.dw_cfi_reg_num
c8cc5c4a 7717 = DWARF_FRAME_REGNUM (FRAME_POINTER_REGNUM);
a3f97cbb
JW
7718 add_cfi (&fde->dw_fde_cfi, cfi);
7719 }
7720
7721 /* If RA is saved on the stack, define it here. */
7722 if (regs_ever_live[31])
7723 {
7724 offset = current_frame_info.gp_save_offset / DWARF_CIE_DATA_ALIGNMENT;
7725 assert (offset >= 0);
7726 cfi = new_cfi ();
7727 cfi->dw_cfi_opc = DW_CFA_offset_extended;
c8cc5c4a 7728 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_RETURN_COLUMN;
a3f97cbb
JW
7729 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7730 add_cfi (&fde->dw_fde_cfi, cfi);
7731 }
7732
7733 /* If FP is saved on the stack, define it here. */
7734 if (current_frame_info.mask & (1 << 30))
7735 {
7736 offset = (current_frame_info.gp_save_offset
ba7b35df 7737 - (((current_frame_info.mask >> 31) & 1) * UNITS_PER_WORD))
a3f97cbb
JW
7738 / DWARF_CIE_DATA_ALIGNMENT;
7739 assert (offset >= 0);
7740 cfi = new_cfi ();
7741 cfi->dw_cfi_opc = DW_CFA_offset;
810429b7 7742 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
c8cc5c4a 7743 = DWARF_FRAME_REGNUM (FRAME_POINTER_REGNUM);
a3f97cbb
JW
7744 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7745 add_cfi (&fde->dw_fde_cfi, cfi);
7746 }
7747
7748#endif
7749
7750}
7751
7752/* Output a marker (i.e. a label) for the point in the generated code where
7753 the real body of the function ends (just before the epilogue code). */
7754void
9a666dda 7755dwarf2out_end_function ()
a3f97cbb
JW
7756{
7757 dw_fde_ref fde;
7758 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7759 function_section (current_function_decl);
5c90448c 7760 ASM_GENERATE_INTERNAL_LABEL (label, BODY_END_LABEL, current_funcdef_number);
a3f97cbb
JW
7761 ASM_OUTPUT_LABEL (asm_out_file, label);
7762 /* Record the ending code location in the FDE. */
7763 fde = &fde_table[fde_table_in_use - 1];
7764 fde->dw_fde_begin_epilogue = xstrdup(label);
7765}
7766
7767/* Output a marker (i.e. a label) for the absolute end of the generated code
7768 for a function definition. This gets called *after* the epilogue code has
7769 been generated. */
7770void
9a666dda 7771dwarf2out_end_epilogue ()
a3f97cbb
JW
7772{
7773 dw_fde_ref fde;
7774 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7775 /* Output a label to mark the endpoint of the code generated for this
7776 function. */
5c90448c 7777 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
a3f97cbb
JW
7778 ASM_OUTPUT_LABEL (asm_out_file, label);
7779 fde = &fde_table[fde_table_in_use - 1];
7780 fde->dw_fde_end = xstrdup (label);
7781}
7782
7783/* Lookup a filename (in the list of filenames that we know about here in
9a666dda 7784 dwarf2out.c) and return its "index". The index of each (known) filename is
a3f97cbb
JW
7785 just a unique number which is associated with only that one filename.
7786 We need such numbers for the sake of generating labels
7787 (in the .debug_sfnames section) and references to those
7788 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
7789 If the filename given as an argument is not found in our current list,
7790 add it to the list and assign it the next available unique index number.
7791 In order to speed up searches, we remember the index of the filename
7792 was looked up last. This handles the majority of all searches. */
7793static unsigned
7794lookup_filename (file_name)
7795 char *file_name;
7796{
7797 static unsigned last_file_lookup_index = 0;
7798 register char *fn;
7799 register unsigned i;
7800
7801 /* Check to see if the file name that was searched on the previous call
7802 matches this file name. If so, return the index. */
7803 if (last_file_lookup_index != 0)
7804 {
7805 fn = file_table[last_file_lookup_index];
7806 if (strcmp (file_name, fn) == 0)
7807 {
7808 return last_file_lookup_index;
7809 }
7810 }
7811
7812 /* Didn't match the previous lookup, search the table */
7813 for (i = 1; i < file_table_in_use; ++i)
7814 {
7815 fn = file_table[i];
7816 if (strcmp (file_name, fn) == 0)
7817 {
7818 last_file_lookup_index = i;
7819 return i;
7820 }
7821 }
7822
7823 /* Prepare to add a new table entry by making sure there is enough space in
7824 the table to do so. If not, expand the current table. */
7825 if (file_table_in_use == file_table_allocated)
7826 {
7827 file_table_allocated += FILE_TABLE_INCREMENT;
7828 file_table
7829 = (char **)
7830 xrealloc (file_table, file_table_allocated * sizeof (char *));
7831 }
7832
7833 /* add the new entry to the end of the filename table. */
7834 file_table[file_table_in_use] = xstrdup (file_name);
7835 last_file_lookup_index = file_table_in_use++;
7836 return last_file_lookup_index;
7837}
7838
7839/* Output a label to mark the beginning of a source code line entry
7840 and record information relating to this source line, in
7841 'line_info_table' for later output of the .debug_line section. */
7842void
9a666dda 7843dwarf2out_line (filename, line)
a3f97cbb
JW
7844 register char *filename;
7845 register unsigned line;
7846{
a3f97cbb
JW
7847 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7848 {
7849 function_section (current_function_decl);
a3f97cbb 7850
e90b62db 7851 if (DECL_SECTION_NAME (current_function_decl))
a3f97cbb 7852 {
e90b62db 7853 register dw_separate_line_info_ref line_info;
5c90448c
JM
7854 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
7855 separate_line_info_table_in_use);
e90b62db
JM
7856 fputc ('\n', asm_out_file);
7857
7858 /* expand the line info table if necessary */
7859 if (separate_line_info_table_in_use
7860 == separate_line_info_table_allocated)
7861 {
7862 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
7863 separate_line_info_table
7864 = (dw_separate_line_info_ref) xrealloc
7865 (separate_line_info_table,
7866 separate_line_info_table_allocated
7867 * sizeof (dw_separate_line_info_entry));
7868 }
7869 /* add the new entry at the end of the line_info_table. */
7870 line_info
7871 = &separate_line_info_table[separate_line_info_table_in_use++];
7872 line_info->dw_file_num = lookup_filename (filename);
7873 line_info->dw_line_num = line;
7874 line_info->function = current_funcdef_number;
7875 }
7876 else
7877 {
7878 register dw_line_info_ref line_info;
5c90448c
JM
7879 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
7880 line_info_table_in_use);
e90b62db
JM
7881 fputc ('\n', asm_out_file);
7882
7883 /* expand the line info table if necessary */
7884 if (line_info_table_in_use == line_info_table_allocated)
7885 {
7886 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
7887 line_info_table
7888 = (dw_line_info_ref) xrealloc
7889 (line_info_table,
7890 line_info_table_allocated * sizeof (dw_line_info_entry));
7891 }
7892 /* add the new entry at the end of the line_info_table. */
7893 line_info = &line_info_table[line_info_table_in_use++];
7894 line_info->dw_file_num = lookup_filename (filename);
7895 line_info->dw_line_num = line;
a3f97cbb 7896 }
a3f97cbb
JW
7897 }
7898}
7899
7900/* Record the beginning of a new source file, for later output
7901 of the .debug_macinfo section. At present, unimplemented. */
7902void
9a666dda 7903dwarf2out_start_source_file (filename)
a3f97cbb
JW
7904 register char *filename;
7905{
7906}
7907
9a666dda 7908/* Record the end of a source file, for later output
a3f97cbb
JW
7909 of the .debug_macinfo section. At present, unimplemented. */
7910void
9a666dda 7911dwarf2out_end_source_file ()
a3f97cbb
JW
7912{
7913}
7914
7915/* Called from check_newline in c-parse.y. The `buffer' parameter contains
7916 the tail part of the directive line, i.e. the part which is past the
7917 initial whitespace, #, whitespace, directive-name, whitespace part. */
7918void
9a666dda 7919dwarf2out_define (lineno, buffer)
a3f97cbb
JW
7920 register unsigned lineno;
7921 register char *buffer;
7922{
7923 static int initialized = 0;
7924 if (!initialized)
7925 {
9a666dda 7926 dwarf2out_start_source_file (primary_filename);
a3f97cbb
JW
7927 initialized = 1;
7928 }
7929}
7930
7931/* Called from check_newline in c-parse.y. The `buffer' parameter contains
7932 the tail part of the directive line, i.e. the part which is past the
7933 initial whitespace, #, whitespace, directive-name, whitespace part. */
7934void
9a666dda 7935dwarf2out_undef (lineno, buffer)
a3f97cbb
JW
7936 register unsigned lineno;
7937 register char *buffer;
7938{
7939}
7940
7941/* Set up for Dwarf output at the start of compilation. */
7942void
9a666dda 7943dwarf2out_init (asm_out_file, main_input_filename)
a3f97cbb
JW
7944 register FILE *asm_out_file;
7945 register char *main_input_filename;
7946{
a3f97cbb
JW
7947 /* Remember the name of the primary input file. */
7948 primary_filename = main_input_filename;
7949
7950 /* Allocate the initial hunk of the file_table. */
7951 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
7952 bzero (file_table, FILE_TABLE_INCREMENT * sizeof (char *));
7953 file_table_allocated = FILE_TABLE_INCREMENT;
7954 /* skip the first entry - file numbers begin at 1 */
7955 file_table_in_use = 1;
7956
7957 /* Allocate the initial hunk of the type_die_table. */
7958 type_die_table
7959 = (dw_die_ref *) xmalloc (TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7960 bzero (type_die_table, TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7961 type_die_table_allocated = TYPE_DIE_TABLE_INCREMENT;
7962 type_die_table_in_use = 0;
7963
7964 /* Allocate the initial hunk of the decl_die_table. */
7965 decl_die_table
7966 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7967 bzero (decl_die_table, DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7968 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
7969 decl_die_table_in_use = 0;
7970
7971 /* Allocate the initial hunk of the decl_scope_table. */
7972 decl_scope_table
7973 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
7974 bzero (decl_scope_table, DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
7975 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
7976 decl_scope_depth = 0;
7977
7978 /* Allocate the initial hunk of the abbrev_die_table. */
7979 abbrev_die_table
7980 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
7981 * sizeof (dw_die_ref));
7982 bzero (abbrev_die_table, ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7983 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
7984 /* zero-th entry is allocated, but unused */
7985 abbrev_die_table_in_use = 1;
7986
7987 /* Allocate the initial hunk of the line_info_table. */
7988 line_info_table
7989 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
7990 * sizeof (dw_line_info_entry));
7991 bzero (line_info_table, LINE_INFO_TABLE_INCREMENT
7992 * sizeof (dw_line_info_entry));
7993 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
7994 /* zero-th entry is allocated, but unused */
7995 line_info_table_in_use = 1;
7996
7997 /* Allocate the initial hunk of the fde_table. */
7998 fde_table = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
7999 bzero (fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
8000 fde_table_allocated = FDE_TABLE_INCREMENT;
8001 fde_table_in_use = 0;
8002
a3f97cbb
JW
8003 /* Generate the initial DIE for the .debug section. Note that the (string)
8004 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
8005 will (typically) be a relative pathname and that this pathname should be
8006 taken as being relative to the directory from which the compiler was
8007 invoked when the given (base) source file was compiled. */
8008 gen_compile_unit_die (main_input_filename);
8009
5c90448c 8010 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
a3f97cbb
JW
8011}
8012
8013/* Output stuff that dwarf requires at the end of every file,
8014 and generate the DWARF-2 debugging info. */
8015void
9a666dda 8016dwarf2out_finish ()
a3f97cbb 8017{
a3f97cbb
JW
8018 /* Traverse the DIE tree and add sibling attributes to those DIE's
8019 that have children. */
8020 add_sibling_attributes (comp_unit_die);
8021
8022 /* Output a terminator label for the .text section. */
8023 fputc ('\n', asm_out_file);
8024 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
5c90448c 8025 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
a3f97cbb 8026
bdb669cb 8027#if 0
a3f97cbb
JW
8028 /* Output a terminator label for the .data section. */
8029 fputc ('\n', asm_out_file);
8030 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
5c90448c 8031 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
a3f97cbb
JW
8032
8033 /* Output a terminator label for the .bss section. */
8034 fputc ('\n', asm_out_file);
8035 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
5c90448c 8036 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
bdb669cb 8037#endif
a3f97cbb 8038
e90b62db
JM
8039 /* Output the source line correspondence table. */
8040 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
8041 {
8042 fputc ('\n', asm_out_file);
8043 ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION);
8044 output_line_info ();
8045
8046 /* We can only use the low/high_pc attributes if all of the code
8047 was in .text. */
8048 if (separate_line_info_table_in_use == 0)
8049 {
8050 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
5c90448c 8051 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
e90b62db
JM
8052 }
8053 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION);
8054 }
8055
a3f97cbb
JW
8056 /* Output the abbreviation table. */
8057 fputc ('\n', asm_out_file);
8058 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
8059 build_abbrev_table (comp_unit_die);
8060 output_abbrev_section ();
8061
a3f97cbb
JW
8062 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8063 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8064 calc_die_sizes (comp_unit_die);
8065
8066 /* Initialize the beginning FDE offset - and calculate sizes/offsets. */
8067 next_fde_offset = DWARF_CIE_SIZE;
8068 calc_fde_sizes ();
8069
8070 /* Output debugging information. */
8071 fputc ('\n', asm_out_file);
8072 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_SECTION);
8073 output_compilation_unit_header ();
8074 output_die (comp_unit_die);
8075
d291dd49
JM
8076 if (pubname_table_in_use)
8077 {
8078 /* Output public names table. */
8079 fputc ('\n', asm_out_file);
8080 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
8081 output_pubnames ();
8082 }
8083
a3f97cbb
JW
8084 if (fde_table_in_use)
8085 {
8086 /* Output call frame information. */
8087 fputc ('\n', asm_out_file);
8088 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
8089 output_call_frame_info ();
8090
a3f97cbb
JW
8091 /* Output the address range information. */
8092 fputc ('\n', asm_out_file);
8093 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
8094 output_aranges ();
8095 }
8096}
9a666dda 8097#endif /* DWARF2_DEBUGGING_INFO */