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