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