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