x
[official-gcc.git] / gcc / dwarf2out.c
blobb122e0bfed5184f200dc9ba5ccd5ba9569593ad7
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).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "config.h"
24 #ifndef DWARF_VERSION
25 #define DWARF_VERSION 1
26 #endif
27 #if defined (DWARF_DEBUGGING_INFO) && (DWARF_VERSION == 2)
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"
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__)
48 extern time_t time (time_t *);
49 #else /* !defined(__STDC__) */
50 extern time_t time ();
51 #endif /* !defined(__STDC__) */
52 #endif /* !defined(POSIX) */
53 #endif /* defined(DWARF_TIMESTAMPS) */
55 extern char *getpwd ();
56 extern char *index ();
57 extern char *rindex ();
59 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
60 regarding the GNU implementation of DWARF. */
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. */
66 /* NOTE: The implementation of C++ support is unfinished. */
68 #if defined(__GNUC__) && (NDEBUG == 1)
69 #define inline static inline
70 #else
71 #define inline static
72 #endif
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. */
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. */
83 typedef enum
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
97 dw_val_class;
99 /* Various DIE's use offsets relative to the beginning of the
100 .debug_info section to refer to each other. */
101 typedef long int dw_offset;
103 /* Define typedefs here to avoid circular dependencies. */
104 typedef struct die_struct *dw_die_ref;
105 typedef struct dw_attr_struct *dw_attr_ref;
106 typedef struct dw_val_struct *dw_val_ref;
107 typedef struct dw_line_info_struct *dw_line_info_ref;
108 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
109 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
110 typedef struct dw_cfi_struct *dw_cfi_ref;
111 typedef struct dw_fde_struct *dw_fde_ref;
112 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
113 typedef struct pubname_struct *pubname_ref;
114 typedef dw_die_ref *arange_ref;
116 /* Describe a double word constant value. */
117 typedef struct dw_double_const_struct
119 unsigned long dw_dbl_hi;
120 unsigned long dw_dbl_low;
122 dw_dbl_const;
124 /* Each entry in the line_info_table maintains the file and
125 line nuber associated with the label generated for that
126 entry. The label gives the PC value associated with
127 the line number entry. */
128 typedef struct dw_line_info_struct
130 unsigned long dw_file_num;
131 unsigned long dw_line_num;
133 dw_line_info_entry;
135 /* Line information for functions in separate sections; each one gets its
136 own sequence. */
137 typedef struct dw_separate_line_info_struct
139 unsigned long dw_file_num;
140 unsigned long dw_line_num;
141 unsigned long function;
143 dw_separate_line_info_entry;
145 /* The dw_val_node describes an attibute's value, as it is
146 represnted internally. */
147 typedef struct dw_val_struct
149 dw_val_class val_class;
150 union
152 char *val_addr;
153 dw_loc_descr_ref val_loc;
154 long int val_int;
155 long unsigned val_unsigned;
156 dw_dbl_const val_dbl_const;
157 dw_die_ref val_die_ref;
158 unsigned val_fde_index;
159 char *val_str;
160 char *val_lbl_id;
161 char *val_section;
162 unsigned char val_flag;
166 dw_val_node;
168 /* Locations in memory are described using a sequence of stack machine
169 operations. */
170 typedef struct dw_loc_descr_struct
172 dw_loc_descr_ref dw_loc_next;
173 enum dwarf_location_atom dw_loc_opc;
174 dw_val_node dw_loc_oprnd1;
175 dw_val_node dw_loc_oprnd2;
177 dw_loc_descr_node;
179 /* Each DIE attribute has a field specifying the attribute kind,
180 a link to the next attribute in the chain, and an attribute value.
181 Attributes are typically linked below the DIE they modify. */
182 typedef struct dw_attr_struct
184 enum dwarf_attribute dw_attr;
185 dw_attr_ref dw_attr_next;
186 dw_val_node dw_attr_val;
188 dw_attr_node;
190 /* Call frames are described using a sequence of Call Frame
191 Information instructions. The register number, offset
192 and address fields are provided as possible operands;
193 their use is selected by the opcode field. */
194 typedef union dw_cfi_oprnd_struct
196 unsigned long dw_cfi_reg_num;
197 long int dw_cfi_offset;
198 char *dw_cfi_addr;
200 dw_cfi_oprnd;
202 typedef struct dw_cfi_struct
204 dw_cfi_ref dw_cfi_next;
205 enum dwarf_call_frame_info dw_cfi_opc;
206 dw_cfi_oprnd dw_cfi_oprnd1;
207 dw_cfi_oprnd dw_cfi_oprnd2;
209 dw_cfi_node;
211 /* All call frame descriptions (FDE's) in the GCC generated DWARF
212 refer to a single Common Information Entry (CIE), defined at
213 the beginning of the .debug_frame section. This used of a single
214 CIE obviates the need to keep track of multiple CIE's
215 in the DWARF generation routines below. */
216 typedef struct dw_fde_struct
218 unsigned long dw_fde_offset;
219 char *dw_fde_begin;
220 char *dw_fde_end_prolog;
221 char *dw_fde_begin_epilogue;
222 char *dw_fde_end;
223 dw_cfi_ref dw_fde_cfi;
225 dw_fde_node;
227 /* The Debugging Information Entry (DIE) structure */
228 typedef struct die_struct
230 enum dwarf_tag die_tag;
231 dw_attr_ref die_attr;
232 dw_attr_ref die_attr_last;
233 dw_die_ref die_parent;
234 dw_die_ref die_child;
235 dw_die_ref die_child_last;
236 dw_die_ref die_sib;
237 dw_offset die_offset;
238 unsigned long die_abbrev;
240 die_node;
242 /* The pubname structure */
243 typedef struct pubname_struct
245 dw_die_ref die;
246 char * name;
248 pubname_entry;
250 /* How to start an assembler comment. */
251 #ifndef ASM_COMMENT_START
252 #define ASM_COMMENT_START ";#"
253 #endif
255 /* Define a macro which returns non-zero for any tagged type which is used
256 (directly or indirectly) in the specification of either some function's
257 return type or some formal parameter of some function. We use this macro
258 when we are operating in "terse" mode to help us know what tagged types
259 have to be represented in Dwarf (even in terse mode) and which ones don't.
260 A flag bit with this meaning really should be a part of the normal GCC
261 ..._TYPE nodes, but at the moment, there is no such bit defined for these
262 nodes. For now, we have to just fake it. It it safe for us to simply
263 return zero for all complete tagged types (which will get forced out
264 anyway if they were used in the specification of some formal or return
265 type) and non-zero for all incomplete tagged types. */
266 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
268 /* Information concerning the compilation unit's programming
269 language, and compiler version. */
270 extern int flag_traditional;
271 extern char *version_string;
272 extern char *language_string;
274 /* Maximum size (in bytes) of an artificially generated label. */
275 #define MAX_ARTIFICIAL_LABEL_BYTES 30
277 /* Make sure we know the sizes of the various types dwarf can describe. These
278 are only defaults. If the sizes are different for your target, you should
279 override these values by defining the appropriate symbols in your tm.h
280 file. */
281 #ifndef CHAR_TYPE_SIZE
282 #define CHAR_TYPE_SIZE BITS_PER_UNIT
283 #endif
284 #ifndef SHORT_TYPE_SIZE
285 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
286 #endif
287 #ifndef INT_TYPE_SIZE
288 #define INT_TYPE_SIZE BITS_PER_WORD
289 #endif
290 #ifndef LONG_TYPE_SIZE
291 #define LONG_TYPE_SIZE BITS_PER_WORD
292 #endif
293 #ifndef LONG_LONG_TYPE_SIZE
294 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
295 #endif
296 #ifndef WCHAR_TYPE_SIZE
297 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
298 #endif
299 #ifndef WCHAR_UNSIGNED
300 #define WCHAR_UNSIGNED 0
301 #endif
302 #ifndef FLOAT_TYPE_SIZE
303 #define FLOAT_TYPE_SIZE BITS_PER_WORD
304 #endif
305 #ifndef DOUBLE_TYPE_SIZE
306 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
307 #endif
308 #ifndef LONG_DOUBLE_TYPE_SIZE
309 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
310 #endif
311 #ifndef PTR_SIZE
312 #define PTR_SIZE (POINTER_SIZE / 8)
313 #endif
315 /* The size in bytes of a DWARF field indicating an offset or length
316 relative to a debug info section, specified to be 4 bytes in the DWARF-2
317 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
318 #ifndef DWARF_OFFSET_SIZE
319 #define DWARF_OFFSET_SIZE 4
320 #endif
322 /* Fixed size portion of the DWARF compilation unit header. */
323 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
325 /* Fixed size portion of debugging line information prolog. */
326 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
328 /* Fixed size portion of public names info. */
329 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
331 /* Round SIZE up to the nearest BOUNDARY. */
332 #define DWARF_ROUND(SIZE,BOUNDARY) \
333 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
335 /* Fixed size portion of the address range info. */
336 #define DWARF_ARANGES_HEADER_SIZE \
337 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
339 /* Fixed size portion of the Common Information Entry (including
340 the length field). */
341 #define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 8)
343 /* Fixed size of the Common Information Entry in the call frame
344 information (.debug_frame) section rounded up to a word boundary. */
345 #define DWARF_CIE_SIZE DWARF_ROUND (DWARF_CIE_HEADER_SIZE, PTR_SIZE)
347 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
348 #define DWARF_CIE_DATA_ALIGNMENT -4
350 /* Fixed size portion of the FDE. */
351 #define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
353 /* Define the architecture-dependent minimum instruction length (in bytes).
354 In this implementation of DWARF, this field is used for information
355 purposes only. Since GCC generates assembly language, we have
356 no a priori knowledge of how many instruction bytes are generated
357 for each source line, and therefore can use only the DW_LNE_set_address
358 and DW_LNS_fixed_advance_pc line information commands. */
359 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
360 #define DWARF_LINE_MIN_INSTR_LENGTH 4
361 #endif
363 /* Minimum line offset in a special line info. opcode.
364 This value was chosen to give a reasonable range of values. */
365 #define DWARF_LINE_BASE -10
367 /* First special line opcde - leave room for the standard opcodes. */
368 #define DWARF_LINE_OPCODE_BASE 10
370 /* Range of line offsets in a special line info. opcode. */
371 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
373 /* Flag that indicates the initial value of the is_stmt_start flag.
374 In the present implementation, we do not mark any lines as
375 the beginning of a source statement, because that information
376 is not made available by the GCC front-end. */
377 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
379 /* This location is used by calc_die_sizes() to keep track
380 the offset of each DIE within the .debug_info section. */
381 static unsigned long next_die_offset;
383 /* This location is used by calc_fde_sizes() to keep track
384 the offset of each FDE within the .debug_frame section. */
385 static unsigned long next_fde_offset;
387 /* Record the root of the DIE's built for the current compilation unit. */
388 dw_die_ref comp_unit_die;
390 /* Pointer to an array of filenames referenced by this compilation unit. */
391 static char **file_table;
393 /* Total number of entries in the table (i.e. array) pointed to by
394 `file_table'. This is the *total* and includes both used and unused
395 slots. */
396 static unsigned file_table_allocated;
398 /* Number of entries in the file_table which are actually in use. */
399 static unsigned file_table_in_use;
401 /* Size (in elements) of increments by which we may expand the filename
402 table. */
403 #define FILE_TABLE_INCREMENT 64
405 /* Local pointer to the name of the main input file. Initialized in
406 dwarfout_init. */
407 static char *primary_filename;
409 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
410 which their beginnings are encountered. We output Dwarf debugging info
411 that refers to the beginnings and ends of the ranges of code for each
412 lexical block. The labels themselves are generated in final.c, which
413 assigns numbers to the blocks in the same way. */
414 static unsigned next_block_number = 2;
416 /* A pointer to the base of a list of references to DIE's that describe
417 types. The table is indexed by TYPE_UID() which is a unique number,
418 indentifying each type. */
419 static dw_die_ref *type_die_table;
421 /* Number of elements currently allocated for type_die_table. */
422 static unsigned type_die_table_allocated;
424 /* Number of elements in type_die_table currently in use. */
425 static unsigned type_die_table_in_use;
427 /* Size (in elements) of increments by which we may expand the
428 type_die_table. */
429 #define TYPE_DIE_TABLE_INCREMENT 4096
431 /* A pointer to the base of a table of references to DIE's that describe
432 declarations. The table is indexed by DECL_UID() which is a unique
433 number, indentifying each decl. */
434 static dw_die_ref *decl_die_table;
436 /* Number of elements currently allocated for the decl_die_table. */
437 static unsigned decl_die_table_allocated;
439 /* Number of elements in decl_die_table currently in use. */
440 static unsigned decl_die_table_in_use;
442 /* Size (in elements) of increments by which we may expand the
443 decl_die_table. */
444 #define DECL_DIE_TABLE_INCREMENT 256
446 /* A pointer to the base of a table of references to declaration
447 scopes. This table is a display which tracks the nesting
448 of declaration scopes at the current scope and containing
449 scopes. This table is used to find the proper place to
450 define type declaration DIE's. */
451 static tree *decl_scope_table;
453 /* Number of elements currently allocated for the decl_scope_table. */
454 static unsigned decl_scope_table_allocated;
456 /* Current level of nesting of declataion scopes. */
457 static unsigned decl_scope_depth;
459 /* Size (in elements) of increments by which we may expand the
460 decl_scope_table. */
461 #define DECL_SCOPE_TABLE_INCREMENT 64
463 /* A pointer to the base of a list of references to DIE's that
464 are uniquely identified by their tag, presence/absence of
465 children DIE's, and list of attribute/value pairs. */
466 static dw_die_ref *abbrev_die_table;
468 /* Number of elements currently allocated for abbrev_die_table. */
469 static unsigned abbrev_die_table_allocated;
471 /* Number of elements in type_die_table currently in use. */
472 static unsigned abbrev_die_table_in_use;
474 /* Size (in elements) of increments by which we may expand the
475 abbrev_die_table. */
476 #define ABBREV_DIE_TABLE_INCREMENT 256
478 /* A pointer to the base of a table that contains line information
479 for each source code line in .text in the compilation unit. */
480 static dw_line_info_ref line_info_table;
482 /* Number of elements currently allocated for line_info_table. */
483 static unsigned line_info_table_allocated;
485 /* Number of elements in separate_line_info_table currently in use. */
486 static unsigned separate_line_info_table_in_use;
488 /* A pointer to the base of a table that contains line information
489 for each source code line outside of .text in the compilation unit. */
490 static dw_separate_line_info_ref separate_line_info_table;
492 /* Number of elements currently allocated for separate_line_info_table. */
493 static unsigned separate_line_info_table_allocated;
495 /* Number of elements in line_info_table currently in use. */
496 static unsigned line_info_table_in_use;
498 /* Size (in elements) of increments by which we may expand the
499 line_info_table. */
500 #define LINE_INFO_TABLE_INCREMENT 1024
502 /* Keep track of the last line_info_table entry number, returned
503 by the prior call to lookup_filename(). This serves as a
504 cache used to speed up file name look ups. */
505 static unsigned prev_file_entry_num = (unsigned) -1;
507 /* A pointer to the base of a table that contains frame description
508 information for each routine. */
509 static dw_fde_ref fde_table;
511 /* Number of elements currently allocated for fde_table. */
512 static unsigned fde_table_allocated;
514 /* Number of elements in fde_table currently in use. */
515 static unsigned fde_table_in_use;
517 /* Size (in elements) of increments by which we may expand the
518 fde_table. */
519 #define FDE_TABLE_INCREMENT 256
521 /* A pointer to the base of a table that contains a list of publicly
522 accessible names. */
523 static pubname_ref pubname_table;
525 /* Number of elements currently allocated for pubname_table. */
526 static unsigned pubname_table_allocated;
528 /* Number of elements in pubname_table currently in use. */
529 static unsigned pubname_table_in_use;
531 /* Size (in elements) of increments by which we may expand the
532 pubname_table. */
533 #define PUBNAME_TABLE_INCREMENT 64
535 /* A pointer to the base of a table that contains a list of publicly
536 accessible names. */
537 static arange_ref arange_table;
539 /* Number of elements currently allocated for arange_table. */
540 static unsigned arange_table_allocated;
542 /* Number of elements in arange_table currently in use. */
543 static unsigned arange_table_in_use;
545 /* Size (in elements) of increments by which we may expand the
546 arange_table. */
547 #define ARANGE_TABLE_INCREMENT 64
549 /* The number of the current function definition for which debugging
550 information is being generated. These numbers range from 1 up to the
551 maximum number of function definitions contained within the current
552 compilation unit. These numbers are used to create unique label id's
553 unique to each function definition. */
554 static unsigned current_funcdef_number = 1;
556 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
557 attribute that accelerates the lookup of the FDE associated
558 with the subprogram. This variable holds the table index of the FDE
559 associated with the current function (body) definition. */
560 static unsigned current_funcdef_fde;
562 /* Record the size of the frame, so that the DW_AT_frame_base
563 attribute can be set properly in gen_subprogram_die. */
564 static long int current_funcdef_frame_size = 0;
566 /* Record whether the function being analyzed contains inlined functions. */
567 static int current_function_has_inlines;
568 static int comp_unit_has_inlines;
570 /* DWARF requires that the compiler's primary datatypes
571 are mapped into a reference to a DIE that defines that
572 primary (base) type. The base_type_info structure is used
573 to track the correspondence between the name of a
574 base type used by GCC, and its corresponding type
575 characteristics. Note, that the bt_size field below
576 is the size in bits. */
577 typedef struct base_type_struct *base_type_ref;
578 typedef struct base_type_struct
580 char *bt_name;
581 enum dwarf_type bt_type;
582 int bt_is_signed;
583 int bt_size;
585 base_type_info;
587 /* Characteristics of base types used by the compiler. */
588 static base_type_info base_type_table[] =
590 {"void", DW_ATE_unsigned, 0, 0},
591 /* TODO: on some architectures, "char" may be signed. */
592 {"char", DW_ATE_unsigned_char, 0, CHAR_TYPE_SIZE},
593 {"unsigned char", DW_ATE_unsigned_char, 0, CHAR_TYPE_SIZE},
594 {"signed char", DW_ATE_signed_char, 1, CHAR_TYPE_SIZE},
595 {"int", DW_ATE_signed, 1, /* INT_TYPE_SIZE */ 4*8},
596 {"unsigned int", DW_ATE_unsigned, 0, /* INT_TYPE_SIZE */ 4*8},
597 {"short", DW_ATE_signed, 1, SHORT_TYPE_SIZE},
598 {"short int", DW_ATE_signed, 1, SHORT_TYPE_SIZE},
599 {"short unsigned int", DW_ATE_unsigned, 0, SHORT_TYPE_SIZE},
600 {"long", DW_ATE_signed, 1, /* LONG_TYPE_SIZE */ 4*8},
601 {"long int", DW_ATE_signed, 1, /* LONG_TYPE_SIZE */ 4*8},
602 {"long unsigned int", DW_ATE_unsigned, 0, /* LONG_TYPE_SIZE */ 4*8},
603 {"long long int", DW_ATE_signed, 1, LONG_LONG_TYPE_SIZE},
604 {"long long unsigned int", DW_ATE_unsigned, 0, LONG_LONG_TYPE_SIZE},
605 {"float", DW_ATE_float, 1, /* FLOAT_TYPE_SIZE */ 4*8},
606 {"double", DW_ATE_float, 1, DOUBLE_TYPE_SIZE},
607 {"long double", DW_ATE_float, 1, LONG_DOUBLE_TYPE_SIZE},
608 {"complex", DW_ATE_complex_float, 1, 2 * /* FLOAT_TYPE_SIZE */ 4*8},
609 {"double complex", DW_ATE_complex_float, 1, 2 * DOUBLE_TYPE_SIZE},
610 {"long double complex", DW_ATE_complex_float, 1, 2 * LONG_DOUBLE_TYPE_SIZE}
612 #define NUM_BASE_TYPES (sizeof(base_type_table)/sizeof(base_type_info))
614 /* Record the DIE associated with a given base type This table is
615 parallel to the base_type_table, and records the DIE genereated
616 to describe base type that has been previously referenced. */
617 static dw_die_ref base_type_die_table[NUM_BASE_TYPES];
619 /* This predefined base type is used to create certain anonymous types */
620 static dw_die_ref int_base_type_die;
622 /* A pointer to the ..._DECL node which we have most recently been working
623 on. We keep this around just in case something about it looks screwy and
624 we want to tell the user what the source coordinates for the actual
625 declaration are. */
626 static tree dwarf_last_decl;
628 /* Forward declarations for functions defined in this file. */
629 static void gen_type_die ();
630 static void add_type_attribute ();
631 static void decls_for_scope ();
632 static void gen_decl_die ();
633 static unsigned lookup_filename ();
634 static int constant_size PROTO((long unsigned));
635 static enum dwarf_form value_format PROTO((dw_val_ref));
637 /* Definitions of defaults for assembler-dependent names of various
638 pseudo-ops and section names.
639 Theses may be overridden in the tm.h file (if necessary) for a particular
640 assembler. */
641 #ifndef UNALIGNED_SHORT_ASM_OP
642 #define UNALIGNED_SHORT_ASM_OP ".2byte"
643 #endif
644 #ifndef UNALIGNED_INT_ASM_OP
645 #define UNALIGNED_INT_ASM_OP ".4byte"
646 #endif
647 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
648 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
649 #endif
650 #ifndef ASM_BYTE_OP
651 #define ASM_BYTE_OP ".byte"
652 #endif
654 #ifndef UNALIGNED_OFFSET_ASM_OP
655 #define UNALIGNED_OFFSET_ASM_OP \
656 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
657 #endif
659 #ifndef UNALIGNED_WORD_ASM_OP
660 #define UNALIGNED_WORD_ASM_OP \
661 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
662 #endif
664 /* Data and reference forms for relocatable data. */
665 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
666 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
668 /* Pseudo-op for defining a new section. */
669 #ifndef SECTION_ASM_OP
670 #define SECTION_ASM_OP ".section"
671 #endif
673 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
674 print the SECTION_ASM_OP and the section name. The default here works for
675 almost all svr4 assemblers, except for the sparc, where the section name
676 must be enclosed in double quotes. (See sparcv4.h). */
677 #ifndef SECTION_FORMAT
678 #define SECTION_FORMAT "\t%s\t%s\n"
679 #endif
681 /* Section names used to hold DWARF debugging information. */
682 #ifndef DEBUG_SECTION
683 #define DEBUG_SECTION ".debug_info"
684 #endif
685 #ifndef ABBREV_SECTION
686 #define ABBREV_SECTION ".debug_abbrev"
687 #endif
688 #ifndef ARANGES_SECTION
689 #define ARANGES_SECTION ".debug_aranges"
690 #endif
691 #ifndef DW_MACINFO_SECTION
692 #define DW_MACINFO_SECTION ".debug_macinfo"
693 #endif
694 #ifndef FRAME_SECTION
695 #define FRAME_SECTION ".debug_frame"
696 #endif
697 #ifndef LINE_SECTION
698 #define LINE_SECTION ".debug_line"
699 #endif
700 #ifndef LOC_SECTION
701 #define LOC_SECTION ".debug_loc"
702 #endif
703 #ifndef PUBNAMES_SECTION
704 #define PUBNAMES_SECTION ".debug_pubnames"
705 #endif
706 #ifndef STR_SECTION
707 #define STR_SECTION ".debug_str"
708 #endif
710 /* Standerd ELF section names for compiled code and data. */
711 #ifndef TEXT_SECTION
712 #define TEXT_SECTION ".text"
713 #endif
714 #ifndef DATA_SECTION
715 #define DATA_SECTION ".data"
716 #endif
717 #ifndef DATA1_SECTION
718 #define DATA1_SECTION ".data1"
719 #endif
720 #ifndef RODATA_SECTION
721 #define RODATA_SECTION ".rodata"
722 #endif
723 #ifndef RODATA1_SECTION
724 #define RODATA1_SECTION ".rodata1"
725 #endif
726 #ifndef BSS_SECTION
727 #define BSS_SECTION ".bss"
728 #endif
731 /* Definitions of defaults for formats and names of various special
732 (artificial) labels which may be generated within this file (when the -g
733 options is used and DWARF_DEBUGGING_INFO is in effect.
734 If necessary, these may be overridden from within the tm.h file, but
735 typically, overriding these defaults is unnecessary.
736 These labels have been hacked so that they all begin with a
737 `.L' sequence to appease the stock sparc/svr4 assembler and the
738 stock m88k/svr4 assembler, both of which need to see .L at the start of a
739 label in order to prevent that label from going into the linker symbol
740 table). Eventually, the ASM_GENERATE_INTERNAL_LABEL and
741 ASM_OUTPUT_INTERNAL_LABEL should be used, but that will require
742 a major rework. */
743 #ifndef TEXT_BEGIN_LABEL
744 #define TEXT_BEGIN_LABEL ".L_text_b"
745 #endif
746 #ifndef TEXT_END_LABEL
747 #define TEXT_END_LABEL ".L_text_e"
748 #endif
749 #ifndef DATA_BEGIN_LABEL
750 #define DATA_BEGIN_LABEL ".L_data_b"
751 #endif
752 #ifndef DATA_END_LABEL
753 #define DATA_END_LABEL ".L_data_e"
754 #endif
755 #ifndef RODATA_BEGIN_LABEL
756 #define RODATA_BEGIN_LABEL ".L_rodata_b"
757 #endif
758 #ifndef RODATA_END_LABEL
759 #define RODATA_END_LABEL ".L_rodata_e"
760 #endif
761 #ifndef BSS_BEGIN_LABEL
762 #define BSS_BEGIN_LABEL ".L_bss_b"
763 #endif
764 #ifndef BSS_END_LABEL
765 #define BSS_END_LABEL ".L_bss_e"
766 #endif
767 #ifndef LINE_BEGIN_LABEL
768 #define LINE_BEGIN_LABEL ".L_line_b"
769 #endif
770 #ifndef LINE_END_LABEL
771 #define LINE_END_LABEL ".L_line_e"
772 #endif
773 #ifndef INSN_LABEL_FMT
774 #define INSN_LABEL_FMT ".L_I%u_%u"
775 #endif
776 #ifndef BLOCK_BEGIN_LABEL_FMT
777 #define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
778 #endif
779 #ifndef BLOCK_END_LABEL_FMT
780 #define BLOCK_END_LABEL_FMT ".L_B%u_e"
781 #endif
782 #ifndef BODY_BEGIN_LABEL_FMT
783 #define BODY_BEGIN_LABEL_FMT ".L_b%u"
784 #endif
785 #ifndef BODY_END_LABEL_FMT
786 #define BODY_END_LABEL_FMT ".L_b%u_e"
787 #endif
788 #ifndef FUNC_BEGIN_LABEL_FMT
789 #define FUNC_BEGIN_LABEL_FMT ".L_f%u"
790 #endif
791 #ifndef FUNC_END_LABEL_FMT
792 #define FUNC_END_LABEL_FMT ".L_f%u_e"
793 #endif
794 #ifndef LINE_CODE_LABEL_FMT
795 #define LINE_CODE_LABEL_FMT ".L_LC%u"
796 #endif
797 #ifndef SEPARATE_LINE_CODE_LABEL_FMT
798 #define SEPARATE_LINE_CODE_LABEL_FMT ".L_SLC%u"
799 #endif
800 #ifndef SFNAMES_ENTRY_LABEL_FMT
801 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
802 #endif
804 /* Definitions of defaults for various types of primitive assembly language
805 output operations. These may be overridden from within the tm.h file,
806 but typically, that is unecessary. */
807 #ifndef ASM_OUTPUT_SECTION
808 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
809 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
810 #endif
812 #ifndef ASM_OUTPUT_DWARF_DELTA2
813 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
814 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
815 assemble_name (FILE, LABEL1); \
816 fprintf (FILE, "-"); \
817 assemble_name (FILE, LABEL2); \
818 } while (0)
819 #endif
821 #ifndef ASM_OUTPUT_DWARF_DELTA4
822 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
823 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
824 assemble_name (FILE, LABEL1); \
825 fprintf (FILE, "-"); \
826 assemble_name (FILE, LABEL2); \
827 } while (0)
828 #endif
830 #ifndef ASM_OUTPUT_DWARF_DELTA
831 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
832 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
833 assemble_name (FILE, LABEL1); \
834 fprintf (FILE, "-"); \
835 assemble_name (FILE, LABEL2); \
836 } while (0)
837 #endif
839 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
840 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
841 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
842 assemble_name (FILE, LABEL1); \
843 fprintf (FILE, "-"); \
844 assemble_name (FILE, LABEL2); \
845 } while (0)
846 #endif
848 #ifndef ASM_OUTPUT_DWARF_ADDR
849 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
850 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
851 assemble_name (FILE, LABEL); \
852 } while (0)
853 #endif
855 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
856 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
857 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
858 #endif
860 #ifndef ASM_OUTPUT_DWARF_OFFSET
861 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
862 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
863 assemble_name (FILE, LABEL); \
864 } while (0)
865 #endif
867 #ifndef ASM_OUTPUT_DWARF_DATA1
868 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
869 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
870 #endif
872 #ifndef ASM_OUTPUT_DWARF_DATA2
873 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
874 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
875 #endif
877 #ifndef ASM_OUTPUT_DWARF_DATA4
878 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
879 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
880 #endif
882 #ifndef ASM_OUTPUT_DWARF_DATA
883 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
884 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
885 (unsigned long) VALUE)
886 #endif
888 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
889 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
890 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
891 (unsigned long) VALUE)
892 #endif
894 #ifndef ASM_OUTPUT_DWARF_DATA8
895 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
896 do { \
897 if (WORDS_BIG_ENDIAN) \
899 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
900 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
902 else \
904 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
905 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
907 } while (0)
908 #endif
910 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
911 newline is produced. When flag_verbose_asm is asserted, we add commnetary
912 at the end of the line, so we must avoid output of a newline here. */
913 #ifndef ASM_OUTPUT_DWARF_STRING
914 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
915 do { \
916 register int slen = strlen(P); \
917 register char *p = (P); \
918 register int i; \
919 fprintf (FILE, "\t.ascii \""); \
920 for (i = 0; i < slen; i++) \
922 register int c = p[i]; \
923 if (c == '\"' || c == '\\') \
924 putc ('\\', FILE); \
925 if (c >= ' ' && c < 0177) \
926 putc (c, FILE); \
927 else \
929 fprintf (FILE, "\\%o", c); \
932 fprintf (FILE, "\\0\""); \
934 while (0)
935 #endif
937 /* Convert a reference to the assembler name of a C-level name. This
938 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
939 a string rather than writing to a file. */
940 #ifndef ASM_NAME_TO_STRING
941 #define ASM_NAME_TO_STRING(STR, NAME) \
942 do { \
943 if ((NAME)[0] == '*') \
944 strcpy (STR, NAME+1); \
945 else \
946 strcpy (STR, NAME); \
948 while (0)
949 #endif
952 /************************ general utility functions **************************/
954 /* Return a pointer to a copy of the section string name 's' with all
955 attributes stripped off. */
956 inline char *
957 stripattributes (s)
958 register char *s;
960 register char *stripped, *p;
961 stripped = xstrdup (s);
962 p = stripped;
963 while (*p && *p != ',')
964 p++;
965 *p = '\0';
966 return stripped;
969 /* Convert an integer constant expression into assembler syntax.
970 Addition and subtraction are the only arithmetic
971 that may appear in these expressions. This is an adaptation
972 of output_addr_const() in final.c. Here, the target of the
973 conversion is a string buffer. We can't use output_addr_const
974 directly, because it writes to a file. */
975 static void
976 addr_const_to_string (str, x)
977 char *str;
978 rtx x;
980 char buf1[256];
981 char buf2[256];
983 restart:
984 str[0] = '\0';
985 switch (GET_CODE (x))
987 case PC:
988 if (flag_pic)
989 strcat (str, ",");
990 else
991 abort ();
992 break;
994 case SYMBOL_REF:
995 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
996 strcat (str, buf1);
997 break;
999 case LABEL_REF:
1000 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
1001 ASM_NAME_TO_STRING (buf2, buf1);
1002 strcat (str, buf2);
1003 break;
1005 case CODE_LABEL:
1006 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
1007 ASM_NAME_TO_STRING (buf2, buf1);
1008 strcat (str, buf2);
1009 break;
1011 case CONST_INT:
1012 sprintf (buf1,
1013 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1014 "%d",
1015 #else
1016 "%ld",
1017 #endif
1018 INTVAL (x));
1019 strcat (str, buf1);
1020 break;
1022 case CONST:
1023 /* This used to output parentheses around the expression, but that does
1024 not work on the 386 (either ATT or BSD assembler). */
1025 addr_const_to_string (buf1, XEXP (x, 0));
1026 strcat (str, buf1);
1027 break;
1029 case CONST_DOUBLE:
1030 if (GET_MODE (x) == VOIDmode)
1032 /* We can use %d if the number is one word and positive. */
1033 if (CONST_DOUBLE_HIGH (x))
1034 sprintf (buf1,
1035 #if HOST_BITS_PER_WIDE_INT == 64
1036 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
1037 "0x%lx%016lx",
1038 #else
1039 "0x%x%016x",
1040 #endif
1041 #else
1042 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
1043 "0x%lx%08lx",
1044 #else
1045 "0x%x%08x",
1046 #endif
1047 #endif
1048 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
1049 else if (CONST_DOUBLE_LOW (x) < 0)
1050 sprintf (buf1,
1051 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1052 "0x%x",
1053 #else
1054 "0x%lx",
1055 #endif
1056 CONST_DOUBLE_LOW (x));
1057 else
1058 sprintf (buf1,
1059 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1060 "%d",
1061 #else
1062 "%ld",
1063 #endif
1064 CONST_DOUBLE_LOW (x));
1065 strcat (str, buf1);
1067 else
1068 /* We can't handle floating point constants; PRINT_OPERAND must
1069 handle them. */
1070 output_operand_lossage ("floating constant misused");
1071 break;
1073 case PLUS:
1074 /* Some assemblers need integer constants to appear last (eg masm). */
1075 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
1077 addr_const_to_string (buf1, XEXP (x, 1));
1078 strcat (str, buf1);
1079 if (INTVAL (XEXP (x, 0)) >= 0)
1080 strcat (str, "+");
1081 addr_const_to_string (buf1, XEXP (x, 0));
1082 strcat (str, buf1);
1084 else
1086 addr_const_to_string (buf1, XEXP (x, 0));
1087 strcat (str, buf1);
1088 if (INTVAL (XEXP (x, 1)) >= 0)
1089 strcat (str, "+");
1090 addr_const_to_string (buf1, XEXP (x, 1));
1091 strcat (str, buf1);
1093 break;
1095 case MINUS:
1096 /* Avoid outputting things like x-x or x+5-x, since some assemblers
1097 can't handle that. */
1098 x = simplify_subtraction (x);
1099 if (GET_CODE (x) != MINUS)
1100 goto restart;
1102 addr_const_to_string (buf1, XEXP (x, 0));
1103 strcat (str, buf1);
1104 strcat (str, "-");
1105 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1106 && INTVAL (XEXP (x, 1)) < 0)
1108 strcat (str, ASM_OPEN_PAREN);
1109 addr_const_to_string (buf1, XEXP (x, 1));
1110 strcat (str, buf1);
1111 strcat (str, ASM_CLOSE_PAREN);
1113 else
1115 addr_const_to_string (buf1, XEXP (x, 1));
1116 strcat (str, buf1);
1118 break;
1120 case ZERO_EXTEND:
1121 case SIGN_EXTEND:
1122 addr_const_to_string (buf1, XEXP (x, 0));
1123 strcat (str, buf1);
1124 break;
1126 default:
1127 output_operand_lossage ("invalid expression as operand");
1131 /* Convert an address constant to a string, and return a pointer to
1132 a copy of the result, located on the heap. */
1133 static char *
1134 addr_to_string (x)
1135 rtx x;
1137 char buf[1024];
1138 addr_const_to_string (buf, x);
1139 return xstrdup (buf);
1142 /* Test if rtl node points to a psuedo register. */
1143 inline int
1144 is_pseudo_reg (rtl)
1145 register rtx rtl;
1147 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1148 || ((GET_CODE (rtl) == SUBREG)
1149 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1153 /* Return a reference to a type, with its const and volatile qualifiers
1154 removed. */
1155 inline tree
1156 type_main_variant (type)
1157 register tree type;
1159 type = TYPE_MAIN_VARIANT (type);
1161 /* There really should be only one main variant among any group of variants
1162 of a given type (and all of the MAIN_VARIANT values for all members of
1163 the group should point to that one type) but sometimes the C front-end
1164 messes this up for array types, so we work around that bug here. */
1165 if (TREE_CODE (type) == ARRAY_TYPE)
1167 while (type != TYPE_MAIN_VARIANT (type))
1168 type = TYPE_MAIN_VARIANT (type);
1170 return type;
1173 /* Return non-zero if the given type node represents a tagged type. */
1174 inline int
1175 is_tagged_type (type)
1176 register tree type;
1178 register enum tree_code code = TREE_CODE (type);
1180 return (code == RECORD_TYPE || code == UNION_TYPE
1181 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1184 /* Convert a DIE tag into its string name. */
1185 static char *
1186 dwarf_tag_name (tag)
1187 register unsigned tag;
1189 switch (tag)
1191 case DW_TAG_padding:
1192 return "DW_TAG_padding";
1193 case DW_TAG_array_type:
1194 return "DW_TAG_array_type";
1195 case DW_TAG_class_type:
1196 return "DW_TAG_class_type";
1197 case DW_TAG_entry_point:
1198 return "DW_TAG_entry_point";
1199 case DW_TAG_enumeration_type:
1200 return "DW_TAG_enumeration_type";
1201 case DW_TAG_formal_parameter:
1202 return "DW_TAG_formal_parameter";
1203 case DW_TAG_imported_declaration:
1204 return "DW_TAG_imported_declaration";
1205 case DW_TAG_label:
1206 return "DW_TAG_label";
1207 case DW_TAG_lexical_block:
1208 return "DW_TAG_lexical_block";
1209 case DW_TAG_member:
1210 return "DW_TAG_member";
1211 case DW_TAG_pointer_type:
1212 return "DW_TAG_pointer_type";
1213 case DW_TAG_reference_type:
1214 return "DW_TAG_reference_type";
1215 case DW_TAG_compile_unit:
1216 return "DW_TAG_compile_unit";
1217 case DW_TAG_string_type:
1218 return "DW_TAG_string_type";
1219 case DW_TAG_structure_type:
1220 return "DW_TAG_structure_type";
1221 case DW_TAG_subroutine_type:
1222 return "DW_TAG_subroutine_type";
1223 case DW_TAG_typedef:
1224 return "DW_TAG_typedef";
1225 case DW_TAG_union_type:
1226 return "DW_TAG_union_type";
1227 case DW_TAG_unspecified_parameters:
1228 return "DW_TAG_unspecified_parameters";
1229 case DW_TAG_variant:
1230 return "DW_TAG_variant";
1231 case DW_TAG_common_block:
1232 return "DW_TAG_common_block";
1233 case DW_TAG_common_inclusion:
1234 return "DW_TAG_common_inclusion";
1235 case DW_TAG_inheritance:
1236 return "DW_TAG_inheritance";
1237 case DW_TAG_inlined_subroutine:
1238 return "DW_TAG_inlined_subroutine";
1239 case DW_TAG_module:
1240 return "DW_TAG_module";
1241 case DW_TAG_ptr_to_member_type:
1242 return "DW_TAG_ptr_to_member_type";
1243 case DW_TAG_set_type:
1244 return "DW_TAG_set_type";
1245 case DW_TAG_subrange_type:
1246 return "DW_TAG_subrange_type";
1247 case DW_TAG_with_stmt:
1248 return "DW_TAG_with_stmt";
1249 case DW_TAG_access_declaration:
1250 return "DW_TAG_access_declaration";
1251 case DW_TAG_base_type:
1252 return "DW_TAG_base_type";
1253 case DW_TAG_catch_block:
1254 return "DW_TAG_catch_block";
1255 case DW_TAG_const_type:
1256 return "DW_TAG_const_type";
1257 case DW_TAG_constant:
1258 return "DW_TAG_constant";
1259 case DW_TAG_enumerator:
1260 return "DW_TAG_enumerator";
1261 case DW_TAG_file_type:
1262 return "DW_TAG_file_type";
1263 case DW_TAG_friend:
1264 return "DW_TAG_friend";
1265 case DW_TAG_namelist:
1266 return "DW_TAG_namelist";
1267 case DW_TAG_namelist_item:
1268 return "DW_TAG_namelist_item";
1269 case DW_TAG_packed_type:
1270 return "DW_TAG_packed_type";
1271 case DW_TAG_subprogram:
1272 return "DW_TAG_subprogram";
1273 case DW_TAG_template_type_param:
1274 return "DW_TAG_template_type_param";
1275 case DW_TAG_template_value_param:
1276 return "DW_TAG_template_value_param";
1277 case DW_TAG_thrown_type:
1278 return "DW_TAG_thrown_type";
1279 case DW_TAG_try_block:
1280 return "DW_TAG_try_block";
1281 case DW_TAG_variant_part:
1282 return "DW_TAG_variant_part";
1283 case DW_TAG_variable:
1284 return "DW_TAG_variable";
1285 case DW_TAG_volatile_type:
1286 return "DW_TAG_volatile_type";
1287 case DW_TAG_MIPS_loop:
1288 return "DW_TAG_MIPS_loop";
1289 case DW_TAG_format_label:
1290 return "DW_TAG_format_label";
1291 case DW_TAG_function_template:
1292 return "DW_TAG_function_template";
1293 case DW_TAG_class_template:
1294 return "DW_TAG_class_template";
1295 default:
1296 return "DW_TAG_<unknown>";
1300 /* Convert a DWARF attribute code into its string name. */
1301 static char *
1302 dwarf_attr_name (attr)
1303 register unsigned attr;
1305 switch (attr)
1307 case DW_AT_sibling:
1308 return "DW_AT_sibling";
1309 case DW_AT_location:
1310 return "DW_AT_location";
1311 case DW_AT_name:
1312 return "DW_AT_name";
1313 case DW_AT_ordering:
1314 return "DW_AT_ordering";
1315 case DW_AT_subscr_data:
1316 return "DW_AT_subscr_data";
1317 case DW_AT_byte_size:
1318 return "DW_AT_byte_size";
1319 case DW_AT_bit_offset:
1320 return "DW_AT_bit_offset";
1321 case DW_AT_bit_size:
1322 return "DW_AT_bit_size";
1323 case DW_AT_element_list:
1324 return "DW_AT_element_list";
1325 case DW_AT_stmt_list:
1326 return "DW_AT_stmt_list";
1327 case DW_AT_low_pc:
1328 return "DW_AT_low_pc";
1329 case DW_AT_high_pc:
1330 return "DW_AT_high_pc";
1331 case DW_AT_language:
1332 return "DW_AT_language";
1333 case DW_AT_member:
1334 return "DW_AT_member";
1335 case DW_AT_discr:
1336 return "DW_AT_discr";
1337 case DW_AT_discr_value:
1338 return "DW_AT_discr_value";
1339 case DW_AT_visibility:
1340 return "DW_AT_visibility";
1341 case DW_AT_import:
1342 return "DW_AT_import";
1343 case DW_AT_string_length:
1344 return "DW_AT_string_length";
1345 case DW_AT_common_reference:
1346 return "DW_AT_common_reference";
1347 case DW_AT_comp_dir:
1348 return "DW_AT_comp_dir";
1349 case DW_AT_const_value:
1350 return "DW_AT_const_value";
1351 case DW_AT_containing_type:
1352 return "DW_AT_containing_type";
1353 case DW_AT_default_value:
1354 return "DW_AT_default_value";
1355 case DW_AT_inline:
1356 return "DW_AT_inline";
1357 case DW_AT_is_optional:
1358 return "DW_AT_is_optional";
1359 case DW_AT_lower_bound:
1360 return "DW_AT_lower_bound";
1361 case DW_AT_producer:
1362 return "DW_AT_producer";
1363 case DW_AT_prototyped:
1364 return "DW_AT_prototyped";
1365 case DW_AT_return_addr:
1366 return "DW_AT_return_addr";
1367 case DW_AT_start_scope:
1368 return "DW_AT_start_scope";
1369 case DW_AT_stride_size:
1370 return "DW_AT_stride_size";
1371 case DW_AT_upper_bound:
1372 return "DW_AT_upper_bound";
1373 case DW_AT_abstract_origin:
1374 return "DW_AT_abstract_origin";
1375 case DW_AT_accessibility:
1376 return "DW_AT_accessibility";
1377 case DW_AT_address_class:
1378 return "DW_AT_address_class";
1379 case DW_AT_artificial:
1380 return "DW_AT_artificial";
1381 case DW_AT_base_types:
1382 return "DW_AT_base_types";
1383 case DW_AT_calling_convention:
1384 return "DW_AT_calling_convention";
1385 case DW_AT_count:
1386 return "DW_AT_count";
1387 case DW_AT_data_member_location:
1388 return "DW_AT_data_member_location";
1389 case DW_AT_decl_column:
1390 return "DW_AT_decl_column";
1391 case DW_AT_decl_file:
1392 return "DW_AT_decl_file";
1393 case DW_AT_decl_line:
1394 return "DW_AT_decl_line";
1395 case DW_AT_declaration:
1396 return "DW_AT_declaration";
1397 case DW_AT_discr_list:
1398 return "DW_AT_discr_list";
1399 case DW_AT_encoding:
1400 return "DW_AT_encoding";
1401 case DW_AT_external:
1402 return "DW_AT_external";
1403 case DW_AT_frame_base:
1404 return "DW_AT_frame_base";
1405 case DW_AT_friend:
1406 return "DW_AT_friend";
1407 case DW_AT_identifier_case:
1408 return "DW_AT_identifier_case";
1409 case DW_AT_macro_info:
1410 return "DW_AT_macro_info";
1411 case DW_AT_namelist_items:
1412 return "DW_AT_namelist_items";
1413 case DW_AT_priority:
1414 return "DW_AT_priority";
1415 case DW_AT_segment:
1416 return "DW_AT_segment";
1417 case DW_AT_specification:
1418 return "DW_AT_specification";
1419 case DW_AT_static_link:
1420 return "DW_AT_static_link";
1421 case DW_AT_type:
1422 return "DW_AT_type";
1423 case DW_AT_use_location:
1424 return "DW_AT_use_location";
1425 case DW_AT_variable_parameter:
1426 return "DW_AT_variable_parameter";
1427 case DW_AT_virtuality:
1428 return "DW_AT_virtuality";
1429 case DW_AT_vtable_elem_location:
1430 return "DW_AT_vtable_elem_location";
1432 case DW_AT_MIPS_fde:
1433 return "DW_AT_MIPS_fde";
1434 case DW_AT_MIPS_loop_begin:
1435 return "DW_AT_MIPS_loop_begin";
1436 case DW_AT_MIPS_tail_loop_begin:
1437 return "DW_AT_MIPS_tail_loop_begin";
1438 case DW_AT_MIPS_epilog_begin:
1439 return "DW_AT_MIPS_epilog_begin";
1440 case DW_AT_MIPS_loop_unroll_factor:
1441 return "DW_AT_MIPS_loop_unroll_factor";
1442 case DW_AT_MIPS_software_pipeline_depth:
1443 return "DW_AT_MIPS_software_pipeline_depth";
1444 case DW_AT_MIPS_linkage_name:
1445 return "DW_AT_MIPS_linkage_name";
1446 case DW_AT_MIPS_stride:
1447 return "DW_AT_MIPS_stride";
1448 case DW_AT_MIPS_abstract_name:
1449 return "DW_AT_MIPS_abstract_name";
1450 case DW_AT_MIPS_clone_origin:
1451 return "DW_AT_MIPS_clone_origin";
1452 case DW_AT_MIPS_has_inlines:
1453 return "DW_AT_MIPS_has_inlines";
1455 case DW_AT_sf_names:
1456 return "DW_AT_sf_names";
1457 case DW_AT_src_info:
1458 return "DW_AT_src_info";
1459 case DW_AT_mac_info:
1460 return "DW_AT_mac_info";
1461 case DW_AT_src_coords:
1462 return "DW_AT_src_coords";
1463 case DW_AT_body_begin:
1464 return "DW_AT_body_begin";
1465 case DW_AT_body_end:
1466 return "DW_AT_body_end";
1467 default:
1468 return "DW_AT_<unknown>";
1472 /* Convert a DWARF value form code into its string name. */
1473 static char *
1474 dwarf_form_name (form)
1475 register unsigned form;
1477 switch (form)
1479 case DW_FORM_addr:
1480 return "DW_FORM_addr";
1481 case DW_FORM_block2:
1482 return "DW_FORM_block2";
1483 case DW_FORM_block4:
1484 return "DW_FORM_block4";
1485 case DW_FORM_data2:
1486 return "DW_FORM_data2";
1487 case DW_FORM_data4:
1488 return "DW_FORM_data4";
1489 case DW_FORM_data8:
1490 return "DW_FORM_data8";
1491 case DW_FORM_string:
1492 return "DW_FORM_string";
1493 case DW_FORM_block:
1494 return "DW_FORM_block";
1495 case DW_FORM_block1:
1496 return "DW_FORM_block1";
1497 case DW_FORM_data1:
1498 return "DW_FORM_data1";
1499 case DW_FORM_flag:
1500 return "DW_FORM_flag";
1501 case DW_FORM_sdata:
1502 return "DW_FORM_sdata";
1503 case DW_FORM_strp:
1504 return "DW_FORM_strp";
1505 case DW_FORM_udata:
1506 return "DW_FORM_udata";
1507 case DW_FORM_ref_addr:
1508 return "DW_FORM_ref_addr";
1509 case DW_FORM_ref1:
1510 return "DW_FORM_ref1";
1511 case DW_FORM_ref2:
1512 return "DW_FORM_ref2";
1513 case DW_FORM_ref4:
1514 return "DW_FORM_ref4";
1515 case DW_FORM_ref8:
1516 return "DW_FORM_ref8";
1517 case DW_FORM_ref_udata:
1518 return "DW_FORM_ref_udata";
1519 case DW_FORM_indirect:
1520 return "DW_FORM_indirect";
1521 default:
1522 return "DW_FORM_<unknown>";
1526 /* Convert a DWARF stack opcode into its string name. */
1527 static char *
1528 dwarf_stack_op_name (op)
1529 register unsigned op;
1531 switch (op)
1533 case DW_OP_addr:
1534 return "DW_OP_addr";
1535 case DW_OP_deref:
1536 return "DW_OP_deref";
1537 case DW_OP_const1u:
1538 return "DW_OP_const1u";
1539 case DW_OP_const1s:
1540 return "DW_OP_const1s";
1541 case DW_OP_const2u:
1542 return "DW_OP_const2u";
1543 case DW_OP_const2s:
1544 return "DW_OP_const2s";
1545 case DW_OP_const4u:
1546 return "DW_OP_const4u";
1547 case DW_OP_const4s:
1548 return "DW_OP_const4s";
1549 case DW_OP_const8u:
1550 return "DW_OP_const8u";
1551 case DW_OP_const8s:
1552 return "DW_OP_const8s";
1553 case DW_OP_constu:
1554 return "DW_OP_constu";
1555 case DW_OP_consts:
1556 return "DW_OP_consts";
1557 case DW_OP_dup:
1558 return "DW_OP_dup";
1559 case DW_OP_drop:
1560 return "DW_OP_drop";
1561 case DW_OP_over:
1562 return "DW_OP_over";
1563 case DW_OP_pick:
1564 return "DW_OP_pick";
1565 case DW_OP_swap:
1566 return "DW_OP_swap";
1567 case DW_OP_rot:
1568 return "DW_OP_rot";
1569 case DW_OP_xderef:
1570 return "DW_OP_xderef";
1571 case DW_OP_abs:
1572 return "DW_OP_abs";
1573 case DW_OP_and:
1574 return "DW_OP_and";
1575 case DW_OP_div:
1576 return "DW_OP_div";
1577 case DW_OP_minus:
1578 return "DW_OP_minus";
1579 case DW_OP_mod:
1580 return "DW_OP_mod";
1581 case DW_OP_mul:
1582 return "DW_OP_mul";
1583 case DW_OP_neg:
1584 return "DW_OP_neg";
1585 case DW_OP_not:
1586 return "DW_OP_not";
1587 case DW_OP_or:
1588 return "DW_OP_or";
1589 case DW_OP_plus:
1590 return "DW_OP_plus";
1591 case DW_OP_plus_uconst:
1592 return "DW_OP_plus_uconst";
1593 case DW_OP_shl:
1594 return "DW_OP_shl";
1595 case DW_OP_shr:
1596 return "DW_OP_shr";
1597 case DW_OP_shra:
1598 return "DW_OP_shra";
1599 case DW_OP_xor:
1600 return "DW_OP_xor";
1601 case DW_OP_bra:
1602 return "DW_OP_bra";
1603 case DW_OP_eq:
1604 return "DW_OP_eq";
1605 case DW_OP_ge:
1606 return "DW_OP_ge";
1607 case DW_OP_gt:
1608 return "DW_OP_gt";
1609 case DW_OP_le:
1610 return "DW_OP_le";
1611 case DW_OP_lt:
1612 return "DW_OP_lt";
1613 case DW_OP_ne:
1614 return "DW_OP_ne";
1615 case DW_OP_skip:
1616 return "DW_OP_skip";
1617 case DW_OP_lit0:
1618 return "DW_OP_lit0";
1619 case DW_OP_lit1:
1620 return "DW_OP_lit1";
1621 case DW_OP_lit2:
1622 return "DW_OP_lit2";
1623 case DW_OP_lit3:
1624 return "DW_OP_lit3";
1625 case DW_OP_lit4:
1626 return "DW_OP_lit4";
1627 case DW_OP_lit5:
1628 return "DW_OP_lit5";
1629 case DW_OP_lit6:
1630 return "DW_OP_lit6";
1631 case DW_OP_lit7:
1632 return "DW_OP_lit7";
1633 case DW_OP_lit8:
1634 return "DW_OP_lit8";
1635 case DW_OP_lit9:
1636 return "DW_OP_lit9";
1637 case DW_OP_lit10:
1638 return "DW_OP_lit10";
1639 case DW_OP_lit11:
1640 return "DW_OP_lit11";
1641 case DW_OP_lit12:
1642 return "DW_OP_lit12";
1643 case DW_OP_lit13:
1644 return "DW_OP_lit13";
1645 case DW_OP_lit14:
1646 return "DW_OP_lit14";
1647 case DW_OP_lit15:
1648 return "DW_OP_lit15";
1649 case DW_OP_lit16:
1650 return "DW_OP_lit16";
1651 case DW_OP_lit17:
1652 return "DW_OP_lit17";
1653 case DW_OP_lit18:
1654 return "DW_OP_lit18";
1655 case DW_OP_lit19:
1656 return "DW_OP_lit19";
1657 case DW_OP_lit20:
1658 return "DW_OP_lit20";
1659 case DW_OP_lit21:
1660 return "DW_OP_lit21";
1661 case DW_OP_lit22:
1662 return "DW_OP_lit22";
1663 case DW_OP_lit23:
1664 return "DW_OP_lit23";
1665 case DW_OP_lit24:
1666 return "DW_OP_lit24";
1667 case DW_OP_lit25:
1668 return "DW_OP_lit25";
1669 case DW_OP_lit26:
1670 return "DW_OP_lit26";
1671 case DW_OP_lit27:
1672 return "DW_OP_lit27";
1673 case DW_OP_lit28:
1674 return "DW_OP_lit28";
1675 case DW_OP_lit29:
1676 return "DW_OP_lit29";
1677 case DW_OP_lit30:
1678 return "DW_OP_lit30";
1679 case DW_OP_lit31:
1680 return "DW_OP_lit31";
1681 case DW_OP_reg0:
1682 return "DW_OP_reg0";
1683 case DW_OP_reg1:
1684 return "DW_OP_reg1";
1685 case DW_OP_reg2:
1686 return "DW_OP_reg2";
1687 case DW_OP_reg3:
1688 return "DW_OP_reg3";
1689 case DW_OP_reg4:
1690 return "DW_OP_reg4";
1691 case DW_OP_reg5:
1692 return "DW_OP_reg5";
1693 case DW_OP_reg6:
1694 return "DW_OP_reg6";
1695 case DW_OP_reg7:
1696 return "DW_OP_reg7";
1697 case DW_OP_reg8:
1698 return "DW_OP_reg8";
1699 case DW_OP_reg9:
1700 return "DW_OP_reg9";
1701 case DW_OP_reg10:
1702 return "DW_OP_reg10";
1703 case DW_OP_reg11:
1704 return "DW_OP_reg11";
1705 case DW_OP_reg12:
1706 return "DW_OP_reg12";
1707 case DW_OP_reg13:
1708 return "DW_OP_reg13";
1709 case DW_OP_reg14:
1710 return "DW_OP_reg14";
1711 case DW_OP_reg15:
1712 return "DW_OP_reg15";
1713 case DW_OP_reg16:
1714 return "DW_OP_reg16";
1715 case DW_OP_reg17:
1716 return "DW_OP_reg17";
1717 case DW_OP_reg18:
1718 return "DW_OP_reg18";
1719 case DW_OP_reg19:
1720 return "DW_OP_reg19";
1721 case DW_OP_reg20:
1722 return "DW_OP_reg20";
1723 case DW_OP_reg21:
1724 return "DW_OP_reg21";
1725 case DW_OP_reg22:
1726 return "DW_OP_reg22";
1727 case DW_OP_reg23:
1728 return "DW_OP_reg23";
1729 case DW_OP_reg24:
1730 return "DW_OP_reg24";
1731 case DW_OP_reg25:
1732 return "DW_OP_reg25";
1733 case DW_OP_reg26:
1734 return "DW_OP_reg26";
1735 case DW_OP_reg27:
1736 return "DW_OP_reg27";
1737 case DW_OP_reg28:
1738 return "DW_OP_reg28";
1739 case DW_OP_reg29:
1740 return "DW_OP_reg29";
1741 case DW_OP_reg30:
1742 return "DW_OP_reg30";
1743 case DW_OP_reg31:
1744 return "DW_OP_reg31";
1745 case DW_OP_breg0:
1746 return "DW_OP_breg0";
1747 case DW_OP_breg1:
1748 return "DW_OP_breg1";
1749 case DW_OP_breg2:
1750 return "DW_OP_breg2";
1751 case DW_OP_breg3:
1752 return "DW_OP_breg3";
1753 case DW_OP_breg4:
1754 return "DW_OP_breg4";
1755 case DW_OP_breg5:
1756 return "DW_OP_breg5";
1757 case DW_OP_breg6:
1758 return "DW_OP_breg6";
1759 case DW_OP_breg7:
1760 return "DW_OP_breg7";
1761 case DW_OP_breg8:
1762 return "DW_OP_breg8";
1763 case DW_OP_breg9:
1764 return "DW_OP_breg9";
1765 case DW_OP_breg10:
1766 return "DW_OP_breg10";
1767 case DW_OP_breg11:
1768 return "DW_OP_breg11";
1769 case DW_OP_breg12:
1770 return "DW_OP_breg12";
1771 case DW_OP_breg13:
1772 return "DW_OP_breg13";
1773 case DW_OP_breg14:
1774 return "DW_OP_breg14";
1775 case DW_OP_breg15:
1776 return "DW_OP_breg15";
1777 case DW_OP_breg16:
1778 return "DW_OP_breg16";
1779 case DW_OP_breg17:
1780 return "DW_OP_breg17";
1781 case DW_OP_breg18:
1782 return "DW_OP_breg18";
1783 case DW_OP_breg19:
1784 return "DW_OP_breg19";
1785 case DW_OP_breg20:
1786 return "DW_OP_breg20";
1787 case DW_OP_breg21:
1788 return "DW_OP_breg21";
1789 case DW_OP_breg22:
1790 return "DW_OP_breg22";
1791 case DW_OP_breg23:
1792 return "DW_OP_breg23";
1793 case DW_OP_breg24:
1794 return "DW_OP_breg24";
1795 case DW_OP_breg25:
1796 return "DW_OP_breg25";
1797 case DW_OP_breg26:
1798 return "DW_OP_breg26";
1799 case DW_OP_breg27:
1800 return "DW_OP_breg27";
1801 case DW_OP_breg28:
1802 return "DW_OP_breg28";
1803 case DW_OP_breg29:
1804 return "DW_OP_breg29";
1805 case DW_OP_breg30:
1806 return "DW_OP_breg30";
1807 case DW_OP_breg31:
1808 return "DW_OP_breg31";
1809 case DW_OP_regx:
1810 return "DW_OP_regx";
1811 case DW_OP_fbreg:
1812 return "DW_OP_fbreg";
1813 case DW_OP_bregx:
1814 return "DW_OP_bregx";
1815 case DW_OP_piece:
1816 return "DW_OP_piece";
1817 case DW_OP_deref_size:
1818 return "DW_OP_deref_size";
1819 case DW_OP_xderef_size:
1820 return "DW_OP_xderef_size";
1821 case DW_OP_nop:
1822 return "DW_OP_nop";
1823 default:
1824 return "OP_<unknown>";
1828 /* Convert a DWARF type code into its string name. */
1829 static char *
1830 dwarf_type_encoding_name (enc)
1831 register unsigned enc;
1833 switch (enc)
1835 case DW_ATE_address:
1836 return "DW_ATE_address";
1837 case DW_ATE_boolean:
1838 return "DW_ATE_boolean";
1839 case DW_ATE_complex_float:
1840 return "DW_ATE_complex_float";
1841 case DW_ATE_float:
1842 return "DW_ATE_float";
1843 case DW_ATE_signed:
1844 return "DW_ATE_signed";
1845 case DW_ATE_signed_char:
1846 return "DW_ATE_signed_char";
1847 case DW_ATE_unsigned:
1848 return "DW_ATE_unsigned";
1849 case DW_ATE_unsigned_char:
1850 return "DW_ATE_unsigned_char";
1851 default:
1852 return "DW_ATE_<unknown>";
1856 /* Convert a DWARF call frame info. operation to its string name */
1857 static char *
1858 dwarf_cfi_name (cfi_opc)
1859 register unsigned cfi_opc;
1861 switch (cfi_opc)
1863 case DW_CFA_advance_loc:
1864 return "DW_CFA_advance_loc";
1865 case DW_CFA_offset:
1866 return "DW_CFA_offset";
1867 case DW_CFA_restore:
1868 return "DW_CFA_restore";
1869 case DW_CFA_nop:
1870 return "DW_CFA_nop";
1871 case DW_CFA_set_loc:
1872 return "DW_CFA_set_loc";
1873 case DW_CFA_advance_loc1:
1874 return "DW_CFA_advance_loc1";
1875 case DW_CFA_advance_loc2:
1876 return "DW_CFA_advance_loc2";
1877 case DW_CFA_advance_loc4:
1878 return "DW_CFA_advance_loc4";
1879 case DW_CFA_offset_extended:
1880 return "DW_CFA_offset_extended";
1881 case DW_CFA_restore_extended:
1882 return "DW_CFA_restore_extended";
1883 case DW_CFA_undefined:
1884 return "DW_CFA_undefined";
1885 case DW_CFA_same_value:
1886 return "DW_CFA_same_value";
1887 case DW_CFA_register:
1888 return "DW_CFA_register";
1889 case DW_CFA_remember_state:
1890 return "DW_CFA_remember_state";
1891 case DW_CFA_restore_state:
1892 return "DW_CFA_restore_state";
1893 case DW_CFA_def_cfa:
1894 return "DW_CFA_def_cfa";
1895 case DW_CFA_def_cfa_register:
1896 return "DW_CFA_def_cfa_register";
1897 case DW_CFA_def_cfa_offset:
1898 return "DW_CFA_def_cfa_offset";
1899 /* SGI/MIPS specific */
1900 case DW_CFA_MIPS_advance_loc8:
1901 return "DW_CFA_MIPS_advance_loc8";
1902 default:
1903 return "DW_CFA_<unknown>";
1907 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
1908 instance of an inlined instance of a decl which is local to an inline
1909 function, so we have to trace all of the way back through the origin chain
1910 to find out what sort of node actually served as the original seed for the
1911 given block. */
1912 static tree
1913 decl_ultimate_origin (decl)
1914 register tree decl;
1916 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1918 if (immediate_origin == NULL)
1919 return NULL;
1920 else
1922 register tree ret_val;
1923 register tree lookahead = immediate_origin;
1927 ret_val = lookahead;
1928 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1930 while (lookahead != NULL && lookahead != ret_val);
1931 return ret_val;
1935 /* Determine the "ultimate origin" of a block. The block may be an inlined
1936 instance of an inlined instance of a block which is local to an inline
1937 function, so we have to trace all of the way back through the origin chain
1938 to find out what sort of node actually served as the original seed for the
1939 given block. */
1940 static tree
1941 block_ultimate_origin (block)
1942 register tree block;
1944 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1946 if (immediate_origin == NULL)
1947 return NULL;
1948 else
1950 register tree ret_val;
1951 register tree lookahead = immediate_origin;
1955 ret_val = lookahead;
1956 lookahead = (TREE_CODE (ret_val) == BLOCK)
1957 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1958 : NULL;
1960 while (lookahead != NULL && lookahead != ret_val);
1961 return ret_val;
1965 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1966 of a virtual function may refer to a base class, so we check the 'this'
1967 parameter. */
1969 tree
1970 decl_class_context (decl)
1971 tree decl;
1973 tree context = NULL_TREE;
1974 if (TREE_CODE (decl) != FUNCTION_DECL
1975 || ! DECL_VIRTUAL_P (decl))
1976 context = DECL_CONTEXT (decl);
1977 else
1978 context = TYPE_MAIN_VARIANT
1979 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1981 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1982 context = NULL_TREE;
1984 return context;
1987 /**************** DIE internal representation constturction *******************/
1989 /* Add an attribute/value pair to a DIE */
1990 inline void
1991 add_dwarf_attr (die, attr)
1992 register dw_die_ref die;
1993 register dw_attr_ref attr;
1995 if (die != NULL && attr != NULL)
1997 if (die->die_attr == NULL)
1999 die->die_attr = attr;
2000 die->die_attr_last = attr;
2002 else
2004 die->die_attr_last->dw_attr_next = attr;
2005 die->die_attr_last = attr;
2010 /* Add a flag value attribute to a DIE. */
2011 inline void
2012 add_AT_flag (die, attr_kind, flag)
2013 register dw_die_ref die;
2014 register enum dwarf_attribute attr_kind;
2015 register unsigned flag;
2017 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2018 if (attr != NULL)
2020 attr->dw_attr_next = NULL;
2021 attr->dw_attr = attr_kind;
2022 attr->dw_attr_val.val_class = dw_val_class_flag;
2023 attr->dw_attr_val.v.val_flag = flag;
2024 add_dwarf_attr (die, attr);
2028 /* Add a signed integer attribute value to a DIE. */
2029 inline void
2030 add_AT_int (die, attr_kind, int_val)
2031 register dw_die_ref die;
2032 register enum dwarf_attribute attr_kind;
2033 register long int int_val;
2035 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2036 if (attr != NULL)
2038 attr->dw_attr_next = NULL;
2039 attr->dw_attr = attr_kind;
2040 attr->dw_attr_val.val_class = dw_val_class_const;
2041 attr->dw_attr_val.v.val_int = int_val;
2042 add_dwarf_attr (die, attr);
2046 /* Add an unsigned integer attribute value to a DIE. */
2047 inline void
2048 add_AT_unsigned (die, attr_kind, unsigned_val)
2049 register dw_die_ref die;
2050 register enum dwarf_attribute attr_kind;
2051 register unsigned long unsigned_val;
2053 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2054 if (attr != NULL)
2056 attr->dw_attr_next = NULL;
2057 attr->dw_attr = attr_kind;
2058 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
2059 attr->dw_attr_val.v.val_unsigned = unsigned_val;
2060 add_dwarf_attr (die, attr);
2064 /* Add an unsigned double integer attribute value to a DIE. */
2065 inline void
2066 add_AT_double (die, attr_kind, val_hi, val_low)
2067 register dw_die_ref die;
2068 register enum dwarf_attribute attr_kind;
2069 register unsigned long val_hi;
2070 register unsigned long val_low;
2072 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2073 if (attr != NULL)
2075 attr->dw_attr_next = NULL;
2076 attr->dw_attr = attr_kind;
2077 attr->dw_attr_val.val_class = dw_val_class_double_const;
2078 attr->dw_attr_val.v.val_dbl_const.dw_dbl_hi = val_hi;
2079 attr->dw_attr_val.v.val_dbl_const.dw_dbl_low = val_low;
2080 add_dwarf_attr (die, attr);
2084 /* Add a string attribute value to a DIE. */
2085 inline void
2086 add_AT_string (die, attr_kind, str)
2087 register dw_die_ref die;
2088 register enum dwarf_attribute attr_kind;
2089 register char *str;
2091 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2092 if (attr != NULL)
2094 attr->dw_attr_next = NULL;
2095 attr->dw_attr = attr_kind;
2096 attr->dw_attr_val.val_class = dw_val_class_str;
2097 attr->dw_attr_val.v.val_str = xstrdup (str);
2098 add_dwarf_attr (die, attr);
2102 /* Add a DIE reference attribute value to a DIE. */
2103 inline void
2104 add_AT_die_ref (die, attr_kind, targ_die)
2105 register dw_die_ref die;
2106 register enum dwarf_attribute attr_kind;
2107 register dw_die_ref targ_die;
2109 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2110 if (attr != NULL)
2112 attr->dw_attr_next = NULL;
2113 attr->dw_attr = attr_kind;
2114 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2115 attr->dw_attr_val.v.val_die_ref = targ_die;
2116 add_dwarf_attr (die, attr);
2120 /* Add an FDE reference attribute value to a DIE. */
2121 inline void
2122 add_AT_fde_ref (die, attr_kind, targ_fde)
2123 register dw_die_ref die;
2124 register enum dwarf_attribute attr_kind;
2125 register unsigned targ_fde;
2127 register dw_attr_ref attr;
2129 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2130 if (attr != NULL)
2132 attr->dw_attr_next = NULL;
2133 attr->dw_attr = attr_kind;
2134 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
2135 attr->dw_attr_val.v.val_fde_index = targ_fde;
2136 add_dwarf_attr (die, attr);
2140 /* Add a location description attribute value to a DIE. */
2141 inline void
2142 add_AT_loc (die, attr_kind, loc)
2143 register dw_die_ref die;
2144 register enum dwarf_attribute attr_kind;
2145 register dw_loc_descr_ref loc;
2147 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2148 if (attr != NULL)
2150 attr->dw_attr_next = NULL;
2151 attr->dw_attr = attr_kind;
2152 attr->dw_attr_val.val_class = dw_val_class_loc;
2153 attr->dw_attr_val.v.val_loc = loc;
2154 add_dwarf_attr (die, attr);
2158 /* Add an address constant attribute value to a DIE. */
2159 inline void
2160 add_AT_addr (die, attr_kind, addr)
2161 register dw_die_ref die;
2162 register enum dwarf_attribute attr_kind;
2163 char *addr;
2165 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2166 if (attr != NULL)
2168 attr->dw_attr_next = NULL;
2169 attr->dw_attr = attr_kind;
2170 attr->dw_attr_val.val_class = dw_val_class_addr;
2171 attr->dw_attr_val.v.val_addr = addr;
2172 add_dwarf_attr (die, attr);
2176 /* Add a label identifier attribute value to a DIE. */
2177 inline void
2178 add_AT_lbl_id (die, attr_kind, lbl_id)
2179 register dw_die_ref die;
2180 register enum dwarf_attribute attr_kind;
2181 register char *lbl_id;
2183 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2184 if (attr != NULL)
2186 attr->dw_attr_next = NULL;
2187 attr->dw_attr = attr_kind;
2188 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
2189 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
2190 add_dwarf_attr (die, attr);
2194 /* Add a section offset attribute value to a DIE. */
2195 inline void
2196 add_AT_section_offset (die, attr_kind, section)
2197 register dw_die_ref die;
2198 register enum dwarf_attribute attr_kind;
2199 register char *section;
2201 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2202 if (attr != NULL)
2204 attr->dw_attr_next = NULL;
2205 attr->dw_attr = attr_kind;
2206 attr->dw_attr_val.val_class = dw_val_class_section_offset;
2207 attr->dw_attr_val.v.val_section = section;
2208 add_dwarf_attr (die, attr);
2212 /* Test if die refers to an external subroutine. */
2213 inline int
2214 is_extern_subr_die (die)
2215 register dw_die_ref die;
2217 register dw_attr_ref a;
2218 register int is_subr = FALSE;
2219 register int is_extern = FALSE;
2220 if (die != NULL && die->die_tag == DW_TAG_subprogram)
2222 is_subr = TRUE;
2223 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2225 if (a->dw_attr == DW_AT_external
2226 && a->dw_attr_val.val_class == dw_val_class_flag
2227 && a->dw_attr_val.v.val_flag != 0)
2229 is_extern = TRUE;
2230 break;
2234 return is_subr && is_extern;
2237 /* Get the attribute of type attr_kind. */
2238 inline dw_attr_ref
2239 get_AT (die, attr_kind)
2240 register dw_die_ref die;
2241 register enum dwarf_attribute attr_kind;
2243 register dw_attr_ref a;
2244 register dw_die_ref spec = NULL;
2246 if (die != NULL)
2248 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2250 if (a->dw_attr == attr_kind)
2251 return a;
2252 if (a->dw_attr == DW_AT_specification
2253 || a->dw_attr == DW_AT_abstract_origin)
2254 spec = a->dw_attr_val.v.val_die_ref;
2256 if (spec)
2257 return get_AT (spec, attr_kind);
2259 return NULL;
2262 /* Return the "low pc" attribute value, typically associated with
2263 a subprogram DIE. Return null if the "low pc" attribute is
2264 either not prsent, or if it cannot be represented as an
2265 assembler label identifier. */
2266 inline char *
2267 get_AT_low_pc (die)
2268 register dw_die_ref die;
2270 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
2271 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2272 return a->dw_attr_val.v.val_lbl_id;
2273 return NULL;
2276 /* Return the "high pc" attribute value, typically associated with
2277 a subprogram DIE. Return null if the "high pc" attribute is
2278 either not prsent, or if it cannot be represented as an
2279 assembler label identifier. */
2280 inline char *
2281 get_AT_hi_pc (die)
2282 register dw_die_ref die;
2284 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
2285 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2286 return a->dw_attr_val.v.val_lbl_id;
2287 return NULL;
2290 /* Return the value of the string attribute designated by ATTR_KIND, or
2291 NULL if it is not present. */
2292 inline char *
2293 get_AT_string (die, attr_kind)
2294 register dw_die_ref die;
2295 register enum dwarf_attribute attr_kind;
2297 register dw_attr_ref a = get_AT (die, attr_kind);
2298 if (a && a->dw_attr_val.val_class == dw_val_class_str)
2299 return a->dw_attr_val.v.val_str;
2300 return NULL;
2303 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
2304 if it is not present. */
2305 inline int
2306 get_AT_flag (die, attr_kind)
2307 register dw_die_ref die;
2308 register enum dwarf_attribute attr_kind;
2310 register dw_attr_ref a = get_AT (die, attr_kind);
2311 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
2312 return a->dw_attr_val.v.val_flag;
2313 return -1;
2316 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
2317 if it is not present. */
2318 inline unsigned
2319 get_AT_unsigned (die, attr_kind)
2320 register dw_die_ref die;
2321 register enum dwarf_attribute attr_kind;
2323 register dw_attr_ref a = get_AT (die, attr_kind);
2324 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
2325 return a->dw_attr_val.v.val_unsigned;
2326 return 0;
2329 /* Remove the specified attribute if present. */
2330 inline void
2331 remove_AT (die, attr_kind)
2332 register dw_die_ref die;
2333 register enum dwarf_attribute attr_kind;
2335 register dw_attr_ref a;
2336 register dw_attr_ref removed = NULL;;
2337 if (die != NULL)
2339 if (die->die_attr->dw_attr == attr_kind)
2341 removed = die->die_attr;
2342 if (die->die_attr_last == die->die_attr)
2343 die->die_attr_last = NULL;
2344 die->die_attr = die->die_attr->dw_attr_next;
2346 else for (a = die->die_attr; a->dw_attr_next != NULL;
2347 a = a->dw_attr_next)
2348 if (a->dw_attr_next->dw_attr == attr_kind)
2350 removed = a->dw_attr_next;
2351 if (die->die_attr_last == a->dw_attr_next)
2352 die->die_attr_last = a;
2353 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
2354 break;
2356 if (removed)
2357 free (removed);
2361 /* Discard the children of this DIE. */
2362 inline void
2363 remove_children (die)
2364 register dw_die_ref die;
2366 register dw_die_ref child_die = die->die_child;
2367 die->die_child = NULL;
2368 die->die_child_last = NULL;
2369 while (child_die != NULL)
2371 register dw_die_ref tmp_die = child_die;
2372 register dw_attr_ref a;
2373 child_die = child_die->die_sib;
2375 for (a = tmp_die->die_attr; a != NULL; )
2377 register dw_attr_ref tmp_a = a;
2378 a = a->dw_attr_next;
2379 free (tmp_a);
2381 free (tmp_die);
2385 /* Add a child DIE below its parent. */
2386 inline void
2387 add_child_die (die, child_die)
2388 register dw_die_ref die;
2389 register dw_die_ref child_die;
2391 if (die != NULL && child_die != NULL)
2393 assert (die != child_die);
2394 child_die->die_parent = die;
2395 child_die->die_sib = NULL;
2396 if (die->die_child == NULL)
2398 die->die_child = child_die;
2399 die->die_child_last = child_die;
2401 else
2403 die->die_child_last->die_sib = child_die;
2404 die->die_child_last = child_die;
2409 /* Return a pointer to a newly created DIE node. */
2410 inline dw_die_ref
2411 new_die (tag_value, parent_die)
2412 register enum dwarf_tag tag_value;
2413 register dw_die_ref parent_die;
2415 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
2416 if (die != NULL)
2418 die->die_tag = tag_value;
2419 die->die_abbrev = 0;
2420 die->die_offset = 0;
2421 die->die_child = NULL;
2422 die->die_parent = NULL;
2423 die->die_sib = NULL;
2424 die->die_child_last = NULL;
2425 die->die_attr = NULL;
2426 die->die_attr_last = NULL;
2427 if (parent_die != NULL)
2429 add_child_die (parent_die, die);
2432 return die;
2435 /* Return the DIE associated with the given type specifier. */
2436 inline dw_die_ref
2437 lookup_type_die (type)
2438 register tree type;
2440 register unsigned type_id = TYPE_UID (type);
2441 return (type_id < type_die_table_in_use)
2442 ? type_die_table[type_id] : NULL;
2445 /* Equate a DIE to a given type specifier. */
2446 static void
2447 equate_type_number_to_die (type, type_die)
2448 register tree type;
2449 register dw_die_ref type_die;
2451 register unsigned type_id = TYPE_UID (type);
2452 register unsigned i;
2453 register unsigned num_allocated;
2454 if (type_id >= type_die_table_allocated)
2456 num_allocated = (((type_id + 1)
2457 + TYPE_DIE_TABLE_INCREMENT - 1)
2458 / TYPE_DIE_TABLE_INCREMENT)
2459 * TYPE_DIE_TABLE_INCREMENT;
2460 type_die_table = (dw_die_ref *) xrealloc (type_die_table,
2461 sizeof (dw_die_ref) * num_allocated);
2462 bzero (&type_die_table[type_die_table_allocated],
2463 (num_allocated - type_die_table_allocated) * sizeof (dw_die_ref));
2464 type_die_table_allocated = num_allocated;
2466 if (type_id >= type_die_table_in_use)
2468 type_die_table_in_use = (type_id + 1);
2470 type_die_table[type_id] = type_die;
2473 /* Return the DIE associated with a given declaration. */
2474 inline dw_die_ref
2475 lookup_decl_die (decl)
2476 register tree decl;
2478 register unsigned decl_id = DECL_UID (decl);
2479 return (decl_id < decl_die_table_in_use)
2480 ? decl_die_table[decl_id] : NULL;
2483 /* Equate a DIE to a particular declaration. */
2484 static void
2485 equate_decl_number_to_die (decl, decl_die)
2486 register tree decl;
2487 register dw_die_ref decl_die;
2489 register unsigned decl_id = DECL_UID (decl);
2490 register unsigned i;
2491 register unsigned num_allocated;
2492 if (decl_id >= decl_die_table_allocated)
2494 num_allocated = (((decl_id + 1)
2495 + DECL_DIE_TABLE_INCREMENT - 1)
2496 / DECL_DIE_TABLE_INCREMENT)
2497 * DECL_DIE_TABLE_INCREMENT;
2498 decl_die_table = (dw_die_ref *) xrealloc (decl_die_table,
2499 sizeof (dw_die_ref) * num_allocated);
2500 bzero (&decl_die_table[decl_die_table_allocated],
2501 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
2502 decl_die_table_allocated = num_allocated;
2504 if (decl_id >= decl_die_table_in_use)
2506 decl_die_table_in_use = (decl_id + 1);
2508 decl_die_table[decl_id] = decl_die;
2511 /* Return a pointer to a newly allocated location description. Location
2512 descriptions are simple expression terms that can be strung
2513 together to form more complicated location (address) descriptions. */
2514 inline dw_loc_descr_ref
2515 new_loc_descr (op, oprnd1, oprnd2)
2516 register enum dwarf_location_atom op;
2517 register unsigned long oprnd1;
2518 register unsigned long oprnd2;
2520 register dw_loc_descr_ref descr =
2521 (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2522 if (descr != NULL)
2524 descr->dw_loc_next = NULL;
2525 descr->dw_loc_opc = op;
2526 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2527 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2528 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2529 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2531 return descr;
2534 /* Add a location description term to a location description expression. */
2535 inline void
2536 add_loc_descr (list_head, descr)
2537 register dw_loc_descr_ref *list_head;
2538 register dw_loc_descr_ref descr;
2540 register dw_loc_descr_ref *d;
2541 /* find the end of the chain. */
2542 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2544 /* nothing */ ;
2546 *d = descr;
2549 /* Return a pointer to a newly allocated Call Frame Instruction. */
2550 inline dw_cfi_ref
2551 new_cfi ()
2553 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
2554 if (cfi != NULL)
2556 cfi->dw_cfi_next = NULL;
2557 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
2558 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
2560 return cfi;
2563 /* Add a Call Frame Instruction to list of instructions. */
2564 inline void
2565 add_cfi (list_head, cfi)
2566 register dw_cfi_ref *list_head;
2567 register dw_cfi_ref cfi;
2569 register dw_cfi_ref *p;
2570 /* find the end of the chain. */
2571 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
2573 /* nothing */ ;
2575 *p = cfi;
2578 /********* Print DWARF Internal Representation (debugging aids) ***************/
2580 /* Keep track of the number of spaces used to indent the
2581 output of the debugging routines that print the structure of
2582 the DIE internal representation. */
2583 static int print_indent;
2585 /* Indent the line the number of spaces given by print_indent. */
2586 inline void
2587 print_spaces (outfile)
2588 FILE *outfile;
2590 fprintf (outfile, "%*s", print_indent, "");
2593 /* Print the information assoaciated with a given DIE, and its children.
2594 This routine is a debugging aid only. */
2595 static void
2596 print_die (die, outfile)
2597 dw_die_ref die;
2598 FILE *outfile;
2600 register dw_attr_ref a;
2601 register dw_die_ref c;
2602 print_spaces (outfile);
2603 fprintf (outfile, "DIE %4u: %s\n",
2604 die->die_offset, dwarf_tag_name (die->die_tag));
2605 print_spaces (outfile);
2606 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
2607 fprintf (outfile, " offset: %u\n", die->die_offset);
2608 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2610 print_spaces (outfile);
2611 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
2612 switch (a->dw_attr_val.val_class)
2614 case dw_val_class_addr:
2615 fprintf (outfile, "address");
2616 break;
2617 case dw_val_class_loc:
2618 fprintf (outfile, "location descriptor");
2619 break;
2620 case dw_val_class_const:
2621 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
2622 break;
2623 case dw_val_class_unsigned_const:
2624 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
2625 break;
2626 case dw_val_class_double_const:
2627 fprintf (outfile, "constant (%u,%u)",
2628 a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
2629 a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
2630 break;
2631 case dw_val_class_flag:
2632 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
2633 break;
2634 case dw_val_class_die_ref:
2635 if (a->dw_attr_val.v.val_die_ref != NULL)
2637 fprintf (outfile, "die -> %u",
2638 a->dw_attr_val.v.val_die_ref->die_offset);
2640 else
2642 fprintf (outfile, "die -> <null>");
2644 break;
2645 case dw_val_class_lbl_id:
2646 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
2647 break;
2648 case dw_val_class_section_offset:
2649 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
2650 break;
2651 case dw_val_class_str:
2652 if (a->dw_attr_val.v.val_str != NULL)
2654 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
2656 else
2658 fprintf (outfile, "<null>");
2660 break;
2662 fprintf (outfile, "\n");
2664 if (die->die_child != NULL)
2666 print_indent += 4;
2667 for (c = die->die_child; c != NULL; c = c->die_sib)
2669 print_die (c, outfile);
2671 print_indent -= 4;
2675 /* Print the contents of the source code line number correspondence table.
2676 This routine is a debugging aid only. */
2677 static void
2678 print_dwarf_line_table (outfile)
2679 FILE *outfile;
2681 register unsigned i;
2682 register dw_line_info_ref line_info;
2683 fprintf (outfile, "\n\nDWARF source line information\n");
2684 for (i = 1; i < line_info_table_in_use; ++i)
2686 line_info = &line_info_table[i];
2687 fprintf (outfile, "%5d: ", i);
2688 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
2689 fprintf (outfile, "%6d", line_info->dw_line_num);
2690 fprintf (outfile, "\n");
2692 fprintf (outfile, "\n\n");
2695 /* Print the information collected for a given DIE. */
2696 void
2697 debug_dwarf_die (die)
2698 dw_die_ref die;
2700 print_die (die, stderr);
2703 /* Print all DWARF informaiton collected for the compilation unit.
2704 This routine is a debugging aid only. */
2705 void
2706 debug_dwarf ()
2708 print_indent = 0;
2709 print_die (comp_unit_die, stderr);
2710 print_dwarf_line_table (stderr);
2714 /***************** DWARF Information Construction Support *********************/
2716 /* Traverse the DIE, and add a sibling attribute if it may have the
2717 effect of speeding up access to siblings. To save some space,
2718 avoid generating sibling attributes for DIE's without children. */
2719 static void
2720 add_sibling_attributes(die)
2721 register dw_die_ref die;
2723 register dw_die_ref c;
2724 register dw_attr_ref attr;
2725 if (die != comp_unit_die && die->die_child != NULL)
2727 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2728 if (attr != NULL)
2730 attr->dw_attr_next = NULL;
2731 attr->dw_attr = DW_AT_sibling;
2732 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2733 attr->dw_attr_val.v.val_die_ref = die->die_sib;
2735 /* add the sibling link to the front of the attribute list. */
2736 attr->dw_attr_next = die->die_attr;
2737 if (die->die_attr == NULL)
2739 die->die_attr_last = attr;
2741 die->die_attr = attr;
2743 for (c = die->die_child; c != NULL; c = c->die_sib)
2745 add_sibling_attributes (c);
2749 /* The format of each DIE (and its attribute value pairs)
2750 is encoded in an abbreviation table. This routine builds the
2751 abbreviation table and assigns a unique abbreviation id for
2752 each abbreviation entry. The children of each die are visited
2753 recursively. */
2754 static void
2755 build_abbrev_table (die)
2756 register dw_die_ref die;
2758 register unsigned long abbrev_id;
2759 register unsigned long n_alloc;
2760 register dw_die_ref c;
2761 register dw_attr_ref d_attr, a_attr;
2762 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
2764 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
2765 if (abbrev->die_tag == die->die_tag)
2767 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
2769 a_attr = abbrev->die_attr;
2770 d_attr = die->die_attr;
2771 while (a_attr != NULL && d_attr != NULL)
2773 if ((a_attr->dw_attr != d_attr->dw_attr)
2774 || (value_format (&a_attr->dw_attr_val)
2775 != value_format (&d_attr->dw_attr_val)))
2777 break;
2779 a_attr = a_attr->dw_attr_next;
2780 d_attr = d_attr->dw_attr_next;
2782 if (a_attr == NULL && d_attr == NULL)
2784 break;
2789 if (abbrev_id >= abbrev_die_table_in_use)
2791 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
2793 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
2794 abbrev_die_table = (dw_die_ref *)
2795 xmalloc (abbrev_die_table,
2796 sizeof (dw_die_ref) * n_alloc);
2797 bzero (&abbrev_die_table[abbrev_die_table_allocated],
2798 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
2799 abbrev_die_table_allocated = n_alloc;
2801 ++abbrev_die_table_in_use;
2802 abbrev_die_table[abbrev_id] = die;
2804 die->die_abbrev = abbrev_id;
2805 for (c = die->die_child; c != NULL; c = c->die_sib)
2807 build_abbrev_table (c);
2812 /********************** DWARF Information Sizing *****************************/
2814 /* Return the size of an unsigned LEB128 quantity. */
2815 inline unsigned long
2816 size_of_uleb128 (value)
2817 register unsigned long value;
2819 register unsigned long size = 0;
2820 register unsigned byte;
2823 byte = (value & 0x7f);
2824 value >>= 7;
2825 size += 1;
2827 while (value != 0);
2828 return size;
2831 /* Return the size of a signed LEB128 quantity. */
2832 inline unsigned long
2833 size_of_sleb128 (value)
2834 register long value;
2836 register unsigned long size = 0;
2837 register unsigned byte;
2840 byte = (value & 0x7f);
2841 value >>= 7;
2842 size += 1;
2844 while (!(((value == 0) && ((byte & 0x40) == 0))
2845 || ((value == -1) && ((byte & 0x40) != 0))));
2846 return size;
2849 /* Return the size of a string, including the null byte. */
2850 static unsigned long
2851 size_of_string (str)
2852 register char *str;
2854 register unsigned long size = 0;
2855 register unsigned long slen = strlen (str);
2856 register unsigned long i;
2857 register unsigned c;
2858 for (i = 0; i < slen; ++i)
2860 c = str[i];
2861 if (c == '\\')
2863 ++i;
2865 size += 1;
2867 /* Null terminator. */
2868 size += 1;
2869 return size;
2872 /* Return the size of a location descriptor. */
2873 static unsigned long
2874 size_of_loc_descr (loc)
2875 register dw_loc_descr_ref loc;
2877 register unsigned long size = 1;
2878 switch (loc->dw_loc_opc)
2880 case DW_OP_addr:
2881 size += PTR_SIZE;
2882 break;
2883 case DW_OP_const1u:
2884 case DW_OP_const1s:
2885 size += 1;
2886 break;
2887 case DW_OP_const2u:
2888 case DW_OP_const2s:
2889 size += 2;
2890 break;
2891 case DW_OP_const4u:
2892 case DW_OP_const4s:
2893 size += 4;
2894 break;
2895 case DW_OP_const8u:
2896 case DW_OP_const8s:
2897 size += 8;
2898 break;
2899 case DW_OP_constu:
2900 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2901 break;
2902 case DW_OP_consts:
2903 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2904 break;
2905 case DW_OP_pick:
2906 size += 1;
2907 break;
2908 case DW_OP_plus_uconst:
2909 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2910 break;
2911 case DW_OP_skip:
2912 case DW_OP_bra:
2913 size += 2;
2914 break;
2915 case DW_OP_breg0:
2916 case DW_OP_breg1:
2917 case DW_OP_breg2:
2918 case DW_OP_breg3:
2919 case DW_OP_breg4:
2920 case DW_OP_breg5:
2921 case DW_OP_breg6:
2922 case DW_OP_breg7:
2923 case DW_OP_breg8:
2924 case DW_OP_breg9:
2925 case DW_OP_breg10:
2926 case DW_OP_breg11:
2927 case DW_OP_breg12:
2928 case DW_OP_breg13:
2929 case DW_OP_breg14:
2930 case DW_OP_breg15:
2931 case DW_OP_breg16:
2932 case DW_OP_breg17:
2933 case DW_OP_breg18:
2934 case DW_OP_breg19:
2935 case DW_OP_breg20:
2936 case DW_OP_breg21:
2937 case DW_OP_breg22:
2938 case DW_OP_breg23:
2939 case DW_OP_breg24:
2940 case DW_OP_breg25:
2941 case DW_OP_breg26:
2942 case DW_OP_breg27:
2943 case DW_OP_breg28:
2944 case DW_OP_breg29:
2945 case DW_OP_breg30:
2946 case DW_OP_breg31:
2947 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2948 break;
2949 case DW_OP_regx:
2950 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2951 break;
2952 case DW_OP_fbreg:
2953 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2954 break;
2955 case DW_OP_bregx:
2956 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2957 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2958 break;
2959 case DW_OP_piece:
2960 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2961 break;
2962 case DW_OP_deref_size:
2963 case DW_OP_xderef_size:
2964 size += 1;
2965 break;
2966 default:
2967 break;
2969 return size;
2972 /* Return the size of a series of location descriptors. */
2973 static unsigned long
2974 size_of_locs (loc)
2975 register dw_loc_descr_ref loc;
2977 register unsigned long size = 0;
2978 for (; loc != NULL; loc = loc->dw_loc_next)
2979 size += size_of_loc_descr (loc);
2980 return size;
2983 /* Return the power-of-two number of bytes necessary to represent VALUE. */
2984 static int
2985 constant_size (value)
2986 long unsigned value;
2988 int log;
2990 if (value == 0)
2991 log = 0;
2992 else
2993 log = floor_log2 (value);
2995 log = log / 8;
2996 log = 1 << (floor_log2 (log) + 1);
2998 return log;
3001 /* Return the size of a DIE, as it is represented in the
3002 .debug_info section. */
3003 static unsigned long
3004 size_of_die (die)
3005 register dw_die_ref die;
3007 register unsigned long size = 0;
3008 register dw_attr_ref a;
3009 register dw_loc_descr_ref loc;
3010 size += size_of_uleb128 (die->die_abbrev);
3011 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3013 switch (a->dw_attr_val.val_class)
3015 case dw_val_class_addr:
3016 size += PTR_SIZE;
3017 break;
3018 case dw_val_class_loc:
3020 register unsigned long lsize
3021 = size_of_locs (a->dw_attr_val.v.val_loc);
3023 /* Block length. */
3024 size += constant_size (lsize);
3025 size += lsize;
3027 break;
3028 case dw_val_class_const:
3029 size += 4;
3030 break;
3031 case dw_val_class_unsigned_const:
3032 size += constant_size (a->dw_attr_val.v.val_unsigned);
3033 break;
3034 case dw_val_class_double_const:
3035 size += 8;
3036 break;
3037 case dw_val_class_flag:
3038 size += 1;
3039 break;
3040 case dw_val_class_die_ref:
3041 size += DWARF_OFFSET_SIZE;
3042 break;
3043 case dw_val_class_fde_ref:
3044 size += DWARF_OFFSET_SIZE;
3045 break;
3046 case dw_val_class_lbl_id:
3047 size += PTR_SIZE;
3048 break;
3049 case dw_val_class_section_offset:
3050 size += DWARF_OFFSET_SIZE;
3051 break;
3052 case dw_val_class_str:
3053 size += size_of_string (a->dw_attr_val.v.val_str);
3054 break;
3055 default:
3056 abort ();
3059 return size;
3062 /* Size the debgging information associted with a given DIE.
3063 Visits the DIE's children recursively. Updates the global
3064 variable next_die_offset, on each time through. Uses the
3065 current value of next_die_offset to updete the die_offset
3066 field in each DIE. */
3067 static void
3068 calc_die_sizes (die)
3069 dw_die_ref die;
3071 register dw_die_ref c;
3072 register unsigned long die_size;
3073 die->die_offset = next_die_offset;
3074 next_die_offset += size_of_die (die);
3075 for (c = die->die_child; c != NULL; c = c->die_sib)
3077 calc_die_sizes (c);
3079 if (die->die_child != NULL)
3081 /* Count the null byte used to terminate sibling lists. */
3082 next_die_offset += 1;
3086 /* Return the size of the line information prolog generated for the
3087 compilation unit. */
3088 static unsigned long
3089 size_of_line_prolog ()
3091 register unsigned long size;
3092 register unsigned opc;
3093 register unsigned n_op_args;
3094 register unsigned long ft_index;
3095 size = DWARF_LINE_PROLOG_HEADER_SIZE;
3096 /* Count the size of the table giving number of args for each
3097 standard opcode. */
3098 size += DWARF_LINE_OPCODE_BASE - 1;
3099 /* Include directory table is empty (at present). Count only the
3100 the null byte used to terminate the table. */
3101 size += 1;
3102 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
3104 /* File name entry. */
3105 size += size_of_string (file_table[ft_index]);
3106 /* Include directory index. */
3107 size += size_of_uleb128 (0);
3108 /* Modification time. */
3109 size += size_of_uleb128 (0);
3110 /* File length in bytes. */
3111 size += size_of_uleb128 (0);
3113 /* Count the file table terminator. */
3114 size += 1;
3115 return size;
3118 /* Return the size of the line information generated for this
3119 compilation unit. */
3120 static unsigned long
3121 size_of_line_info ()
3123 register unsigned long size;
3124 register unsigned long lt_index;
3125 register unsigned long current_line;
3126 register long line_offset;
3127 register long line_delta;
3128 register unsigned long current_file;
3129 register unsigned long function;
3130 /* Version number. */
3131 size = 2;
3132 /* Prolog length specifier. */
3133 size += DWARF_OFFSET_SIZE;
3134 /* Prolog. */
3135 size += size_of_line_prolog ();
3136 /* Set address register instruction. */
3137 size += 1 + size_of_uleb128 (1 + PTR_SIZE)
3138 + 1 + PTR_SIZE;
3139 current_file = 1;
3140 current_line = 1;
3141 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
3143 register dw_line_info_ref line_info;
3144 /* Advance pc instruction. */
3145 size += 1 + 2;
3146 line_info = &line_info_table[lt_index];
3147 if (line_info->dw_file_num != current_file)
3149 /* Set file number instruction. */
3150 size += 1;
3151 current_file = line_info->dw_file_num;
3152 size += size_of_uleb128 (current_file);
3154 if (line_info->dw_line_num != current_line)
3156 line_offset = line_info->dw_line_num - current_line;
3157 line_delta = line_offset - DWARF_LINE_BASE;
3158 current_line = line_info->dw_line_num;
3159 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3161 /* 1-byte special line number instruction. */
3162 size += 1;
3164 else
3166 /* Advance line instruction. */
3167 size += 1;
3168 size += size_of_sleb128 (line_offset);
3169 /* Generate line entry instruction. */
3170 size += 1;
3174 /* Advance pc instruction. */
3175 size += 1 + 2;
3176 /* End of line number info. marker. */
3177 size += 1 + size_of_uleb128 (1) + 1;
3178 function = 0;
3179 current_file = 1;
3180 current_line = 1;
3181 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
3183 register dw_separate_line_info_ref line_info
3184 = &separate_line_info_table[lt_index];
3185 if (function != line_info->function)
3187 function = line_info->function;
3188 /* Set address register instruction. */
3189 size += 1 + size_of_uleb128 (1 + PTR_SIZE)
3190 + 1 + PTR_SIZE;
3192 else
3194 /* Advance pc instruction. */
3195 size += 1 + 2;
3197 if (line_info->dw_file_num != current_file)
3199 /* Set file number instruction. */
3200 size += 1;
3201 current_file = line_info->dw_file_num;
3202 size += size_of_uleb128 (current_file);
3204 if (line_info->dw_line_num != current_line)
3206 line_offset = line_info->dw_line_num - current_line;
3207 line_delta = line_offset - DWARF_LINE_BASE;
3208 current_line = line_info->dw_line_num;
3209 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3211 /* 1-byte special line number instruction. */
3212 size += 1;
3214 else
3216 /* Advance line instruction. */
3217 size += 1;
3218 size += size_of_sleb128 (line_offset);
3219 /* Generate line entry instruction. */
3220 size += 1;
3223 ++lt_index;
3225 /* If we're done with a function, end its sequence. */
3226 if (lt_index == separate_line_info_table_in_use
3227 || separate_line_info_table[lt_index].function != function)
3229 current_file = 1;
3230 current_line = 1;
3231 /* Advance pc instruction. */
3232 size += 1 + 2;
3233 /* End of line number info. marker. */
3234 size += 1 + size_of_uleb128 (1) + 1;
3237 return size;
3240 /* Return the size of the .debug_pubnames table generated for the
3241 compilation unit. */
3242 static unsigned long
3243 size_of_pubnames ()
3245 register unsigned long size;
3246 register unsigned i;
3248 size = DWARF_PUBNAMES_HEADER_SIZE;
3249 for (i = 0; i < pubname_table_in_use; ++i)
3251 register pubname_ref p = &pubname_table[i];
3252 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
3254 size += DWARF_OFFSET_SIZE;
3255 return size;
3258 /* Return the size of the information in the .debug_aranges seciton. */
3259 static unsigned long
3260 size_of_aranges ()
3262 register unsigned long size;
3263 size = DWARF_ARANGES_HEADER_SIZE;
3264 /* Count the address/length pair for this compilation unit. */
3265 size += 2 * PTR_SIZE;
3266 size += 2 * PTR_SIZE * arange_table_in_use;
3267 /* Count the two zero words used to terminated the address range table. */
3268 size += 2 * PTR_SIZE;
3269 return size;
3272 /**************** DWARF Debug Information Output *****************************/
3274 /* Output an unsigned LEB128 quantity. */
3275 static void
3276 output_uleb128 (value)
3277 register unsigned long value;
3279 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3282 register unsigned byte = (value & 0x7f);
3283 value >>= 7;
3284 if (value != 0)
3286 /* More bytes to follow. */
3287 byte |= 0x80;
3289 fprintf (asm_out_file, "0x%x", byte);
3290 if (value != 0)
3292 fprintf (asm_out_file, ",");
3295 while (value != 0);
3298 /* Output an signed LEB128 quantity. */
3299 static void
3300 output_sleb128 (value)
3301 register long value;
3303 register int more;
3304 register unsigned byte;
3305 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3308 byte = (value & 0x7f);
3309 /* arithmetic shift */
3310 value >>= 7;
3311 more = !((((value == 0) && ((byte & 0x40) == 0))
3312 || ((value == -1) && ((byte & 0x40) != 0))));
3313 if (more)
3315 byte |= 0x80;
3317 fprintf (asm_out_file, "0x%x", byte);
3318 if (more)
3320 fprintf (asm_out_file, ",");
3323 while (more);
3326 /* Select the encoding of an attribute value. */
3327 static enum dwarf_form
3328 value_format (v)
3329 dw_val_ref v;
3331 switch (v->val_class)
3333 case dw_val_class_addr:
3334 return DW_FORM_addr;
3335 case dw_val_class_loc:
3336 switch (constant_size (size_of_locs (v->v.val_loc)))
3338 case 1:
3339 return DW_FORM_block1;
3340 case 2:
3341 return DW_FORM_block2;
3342 default:
3343 abort ();
3345 case dw_val_class_const:
3346 return DW_FORM_data4;
3347 case dw_val_class_unsigned_const:
3348 switch (constant_size (v->v.val_unsigned))
3350 case 1:
3351 return DW_FORM_data1;
3352 case 2:
3353 return DW_FORM_data2;
3354 case 4:
3355 return DW_FORM_data4;
3356 default:
3357 abort ();
3359 case dw_val_class_double_const:
3360 return DW_FORM_data8;
3361 case dw_val_class_flag:
3362 return DW_FORM_flag;
3363 case dw_val_class_die_ref:
3364 return DW_FORM_ref;
3365 case dw_val_class_fde_ref:
3366 return DW_FORM_data;
3367 case dw_val_class_lbl_id:
3368 return DW_FORM_addr;
3369 case dw_val_class_section_offset:
3370 return DW_FORM_data;
3371 case dw_val_class_str:
3372 return DW_FORM_string;
3373 default:
3374 abort ();
3378 /* Output the encoding of an attribute value. */
3379 static void
3380 output_value_format (v)
3381 dw_val_ref v;
3383 enum dwarf_form form = value_format (v);
3384 output_uleb128 (form);
3385 if (flag_verbose_asm)
3387 fprintf (asm_out_file, "\t%s %s",
3388 ASM_COMMENT_START, dwarf_form_name (form));
3390 fputc ('\n', asm_out_file);
3393 /* Output the .debug_abbrev section which defines the DIE abbreviation
3394 table. */
3395 static void
3396 output_abbrev_section ()
3398 unsigned long abbrev_id;
3399 dw_attr_ref a_attr;
3400 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3402 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3403 output_uleb128 (abbrev_id);
3404 if (flag_verbose_asm)
3406 fprintf (asm_out_file, "\t%s abbrev code = %u",
3407 ASM_COMMENT_START, abbrev_id);
3409 fputc ('\n', asm_out_file);
3410 output_uleb128 (abbrev->die_tag);
3411 if (flag_verbose_asm)
3413 fprintf (asm_out_file, "\t%s TAG: %s",
3414 ASM_COMMENT_START, dwarf_tag_name (abbrev->die_tag));
3416 fputc ('\n', asm_out_file);
3417 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
3418 (abbrev->die_child != NULL)
3419 ? DW_children_yes : DW_children_no);
3420 if (flag_verbose_asm)
3422 fprintf (asm_out_file, "\t%s %s",
3423 ASM_COMMENT_START,
3424 (abbrev->die_child != NULL)
3425 ? "DW_children_yes" : "DW_children_no");
3427 fputc ('\n', asm_out_file);
3428 for (a_attr = abbrev->die_attr; a_attr != NULL;
3429 a_attr = a_attr->dw_attr_next)
3431 output_uleb128 (a_attr->dw_attr);
3432 if (flag_verbose_asm)
3434 fprintf (asm_out_file, "\t%s %s",
3435 ASM_COMMENT_START,
3436 dwarf_attr_name (a_attr->dw_attr));
3438 fputc ('\n', asm_out_file);
3439 output_value_format (&a_attr->dw_attr_val);
3441 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
3445 /* Output location description stack opcode's operands (if any). */
3446 static void
3447 output_loc_operands (loc)
3448 register dw_loc_descr_ref loc;
3450 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
3451 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
3452 switch (loc->dw_loc_opc)
3454 case DW_OP_addr:
3455 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
3456 fputc ('\n', asm_out_file);
3457 break;
3458 case DW_OP_const1u:
3459 case DW_OP_const1s:
3460 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3461 fputc ('\n', asm_out_file);
3462 break;
3463 case DW_OP_const2u:
3464 case DW_OP_const2s:
3465 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3466 fputc ('\n', asm_out_file);
3467 break;
3468 case DW_OP_const4u:
3469 case DW_OP_const4s:
3470 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
3471 fputc ('\n', asm_out_file);
3472 break;
3473 case DW_OP_const8u:
3474 case DW_OP_const8s:
3475 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3476 val1->v.val_dbl_const.dw_dbl_hi,
3477 val2->v.val_dbl_const.dw_dbl_low);
3478 fputc ('\n', asm_out_file);
3479 break;
3480 case DW_OP_constu:
3481 output_uleb128 (val1->v.val_unsigned);
3482 fputc ('\n', asm_out_file);
3483 break;
3484 case DW_OP_consts:
3485 output_sleb128 (val1->v.val_unsigned);
3486 fputc ('\n', asm_out_file);
3487 break;
3488 case DW_OP_pick:
3489 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
3490 fputc ('\n', asm_out_file);
3491 break;
3492 case DW_OP_plus_uconst:
3493 output_uleb128 (val1->v.val_unsigned);
3494 fputc ('\n', asm_out_file);
3495 break;
3496 case DW_OP_skip:
3497 case DW_OP_bra:
3498 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3499 fputc ('\n', asm_out_file);
3500 break;
3501 case DW_OP_breg0:
3502 case DW_OP_breg1:
3503 case DW_OP_breg2:
3504 case DW_OP_breg3:
3505 case DW_OP_breg4:
3506 case DW_OP_breg5:
3507 case DW_OP_breg6:
3508 case DW_OP_breg7:
3509 case DW_OP_breg8:
3510 case DW_OP_breg9:
3511 case DW_OP_breg10:
3512 case DW_OP_breg11:
3513 case DW_OP_breg12:
3514 case DW_OP_breg13:
3515 case DW_OP_breg14:
3516 case DW_OP_breg15:
3517 case DW_OP_breg16:
3518 case DW_OP_breg17:
3519 case DW_OP_breg18:
3520 case DW_OP_breg19:
3521 case DW_OP_breg20:
3522 case DW_OP_breg21:
3523 case DW_OP_breg22:
3524 case DW_OP_breg23:
3525 case DW_OP_breg24:
3526 case DW_OP_breg25:
3527 case DW_OP_breg26:
3528 case DW_OP_breg27:
3529 case DW_OP_breg28:
3530 case DW_OP_breg29:
3531 case DW_OP_breg30:
3532 case DW_OP_breg31:
3533 output_sleb128 (val1->v.val_int);
3534 fputc ('\n', asm_out_file);
3535 break;
3536 case DW_OP_regx:
3537 output_uleb128 (val1->v.val_unsigned);
3538 fputc ('\n', asm_out_file);
3539 break;
3540 case DW_OP_fbreg:
3541 output_sleb128 (val1->v.val_unsigned);
3542 fputc ('\n', asm_out_file);
3543 break;
3544 case DW_OP_bregx:
3545 output_uleb128 (val1->v.val_unsigned);
3546 fputc ('\n', asm_out_file);
3547 output_sleb128 (val2->v.val_unsigned);
3548 fputc ('\n', asm_out_file);
3549 break;
3550 case DW_OP_piece:
3551 output_uleb128 (val1->v.val_unsigned);
3552 fputc ('\n', asm_out_file);
3553 break;
3554 case DW_OP_deref_size:
3555 case DW_OP_xderef_size:
3556 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3557 fputc ('\n', asm_out_file);
3558 break;
3559 default:
3560 break;
3564 /* Compute the offset of a sibling. */
3565 static unsigned long
3566 sibling_offset (die)
3567 dw_die_ref die;
3569 unsigned long offset;
3570 if (die->die_child_last == NULL)
3572 offset = die->die_offset + size_of_die (die);
3574 else
3576 offset = sibling_offset (die->die_child_last) + 1;
3578 return offset;
3581 /* Output the DIE and its attributes. Called recursively to generate
3582 the definitions of each child DIE. */
3583 static void
3584 output_die (die)
3585 register dw_die_ref die;
3587 register dw_attr_ref a;
3588 register dw_die_ref c;
3589 register unsigned long ref_offset;
3590 register unsigned long size;
3591 register dw_loc_descr_ref loc;
3592 output_uleb128 (die->die_abbrev);
3593 if (flag_verbose_asm)
3595 fprintf (asm_out_file, "\t%s DIE (0x%x) %s",
3596 ASM_COMMENT_START,
3597 die->die_offset,
3598 dwarf_tag_name (die->die_tag));
3600 fputc ('\n', asm_out_file);
3601 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3603 switch (a->dw_attr_val.val_class)
3605 case dw_val_class_addr:
3606 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
3607 a->dw_attr_val.v.val_addr);
3608 break;
3609 case dw_val_class_loc:
3610 size = size_of_locs (a->dw_attr_val.v.val_loc);
3611 /* Output the block length for this list of location operations. */
3612 switch (constant_size (size))
3614 case 1:
3615 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
3616 break;
3617 case 2:
3618 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
3619 break;
3620 default:
3621 abort ();
3623 if (flag_verbose_asm)
3625 fprintf (asm_out_file, "\t%s %s",
3626 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3628 fputc ('\n', asm_out_file);
3629 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3630 loc = loc->dw_loc_next)
3632 /* Output the opcode. */
3633 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3634 if (flag_verbose_asm)
3636 fprintf (asm_out_file, "\t%s %s",
3637 ASM_COMMENT_START,
3638 dwarf_stack_op_name (loc->dw_loc_opc));
3640 fputc ('\n', asm_out_file);
3641 /* Output the operand(s) (if any). */
3642 output_loc_operands (loc);
3644 break;
3645 case dw_val_class_const:
3646 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
3647 break;
3648 case dw_val_class_unsigned_const:
3649 switch (constant_size (a->dw_attr_val.v.val_unsigned))
3651 case 1:
3652 ASM_OUTPUT_DWARF_DATA1
3653 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3654 break;
3655 case 2:
3656 ASM_OUTPUT_DWARF_DATA2
3657 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3658 break;
3659 case 4:
3660 ASM_OUTPUT_DWARF_DATA4
3661 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3662 break;
3663 default:
3664 abort ();
3666 break;
3667 case dw_val_class_double_const:
3668 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3669 a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
3670 a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
3671 break;
3672 case dw_val_class_flag:
3673 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
3674 break;
3675 case dw_val_class_die_ref:
3676 if (a->dw_attr_val.v.val_die_ref != NULL)
3678 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
3680 else if (a->dw_attr == DW_AT_sibling)
3682 ref_offset = sibling_offset(die);
3684 else
3686 abort ();
3688 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
3689 break;
3690 case dw_val_class_fde_ref:
3691 ref_offset = fde_table[a->dw_attr_val.v.val_fde_index].dw_fde_offset;
3692 fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_OFFSET_ASM_OP,
3693 stripattributes (FRAME_SECTION), ref_offset);
3694 break;
3695 case dw_val_class_lbl_id:
3696 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
3697 break;
3698 case dw_val_class_section_offset:
3699 ASM_OUTPUT_DWARF_OFFSET
3700 (asm_out_file, stripattributes (a->dw_attr_val.v.val_section));
3701 break;
3702 case dw_val_class_str:
3703 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
3704 break;
3705 default:
3706 abort ();
3708 if (a->dw_attr_val.val_class != dw_val_class_loc)
3710 if (flag_verbose_asm)
3712 fprintf (asm_out_file, "\t%s %s",
3713 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3715 fputc ('\n', asm_out_file);
3718 for (c = die->die_child; c != NULL; c = c->die_sib)
3720 output_die (c);
3722 if (die->die_child != NULL)
3724 /* Add null byte to terminate sibling list. */
3725 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3726 fputc ('\n', asm_out_file);
3730 /* Output the compilation unit that appears at the beginning of the
3731 .debug_info section, and precedes the DIE descriptions. */
3732 static void
3733 output_compilation_unit_header ()
3735 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
3736 if (flag_verbose_asm)
3738 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
3739 ASM_COMMENT_START);
3741 fputc ('\n', asm_out_file);
3742 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
3743 if (flag_verbose_asm)
3745 fprintf (asm_out_file, "\t%s DWARF version number",
3746 ASM_COMMENT_START);
3748 fputc ('\n', asm_out_file);
3749 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
3750 if (flag_verbose_asm)
3752 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
3753 ASM_COMMENT_START);
3755 fputc ('\n', asm_out_file);
3756 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
3757 if (flag_verbose_asm)
3759 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)",
3760 ASM_COMMENT_START);
3762 fputc ('\n', asm_out_file);
3765 /* Return the size of a Call Frame Instruction. */
3766 static unsigned long
3767 size_of_cfi (cfi)
3768 dw_cfi_ref cfi;
3770 register unsigned long size;
3771 /* count the 1-byte opcode */
3772 size = 1;
3773 switch (cfi->dw_cfi_opc)
3775 case DW_CFA_offset:
3776 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3777 break;
3778 case DW_CFA_set_loc:
3779 size += PTR_SIZE;
3780 break;
3781 case DW_CFA_advance_loc1:
3782 size += 1;
3783 break;
3784 case DW_CFA_advance_loc2:
3785 size += 2;
3786 break;
3787 case DW_CFA_advance_loc4:
3788 size += 4;
3789 break;
3790 #ifdef MIPS_DEBUGGING_INFO
3791 case DW_CFA_MIPS_advance_loc8:
3792 size += 8;
3793 break;
3794 #endif
3795 case DW_CFA_offset_extended:
3796 case DW_CFA_def_cfa:
3797 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3798 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3799 break;
3800 case DW_CFA_restore_extended:
3801 case DW_CFA_undefined:
3802 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3803 break;
3804 case DW_CFA_same_value:
3805 case DW_CFA_def_cfa_register:
3806 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3807 break;
3808 case DW_CFA_register:
3809 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3810 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3811 break;
3812 case DW_CFA_def_cfa_offset:
3813 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
3814 break;
3815 default:
3816 break;
3818 return size;
3821 /* Return the size of an FDE sans the length word. */
3822 inline unsigned long
3823 size_of_fde (fde, npad)
3824 dw_fde_ref fde;
3825 unsigned long *npad;
3827 register dw_cfi_ref cfi;
3828 register unsigned long aligned_size;
3829 register unsigned long size;
3830 size = DWARF_FDE_HEADER_SIZE;
3831 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3833 size += size_of_cfi(cfi);
3835 /* Round the size up to a word boundary. */
3836 aligned_size = DWARF_ROUND (size, PTR_SIZE);
3837 *npad = aligned_size - size;
3838 return aligned_size;
3841 /* Calculate the size of the FDE table, and establish the offset
3842 of each FDE in the .debug_frame section. */
3843 static void
3844 calc_fde_sizes ()
3846 register unsigned long i;
3847 register dw_fde_ref fde;
3848 register unsigned long fde_size;
3849 unsigned long fde_pad;
3850 for (i = 0; i < fde_table_in_use; ++i)
3852 fde = &fde_table[i];
3853 fde->dw_fde_offset = next_fde_offset;
3854 fde_size = size_of_fde (fde, &fde_pad);
3855 next_fde_offset += fde_size;
3859 /* Output a Call Frame Information opcode and its operand(s). */
3860 static void
3861 output_cfi (cfi, fde)
3862 register dw_cfi_ref cfi;
3863 register dw_fde_ref fde;
3865 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3867 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3868 cfi->dw_cfi_opc
3869 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
3870 if (flag_verbose_asm)
3872 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc", ASM_COMMENT_START);
3874 fputc ('\n', asm_out_file);
3876 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3878 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3879 cfi->dw_cfi_opc
3880 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3881 if (flag_verbose_asm)
3883 fprintf (asm_out_file, "\t%s DW_CFA_offset", ASM_COMMENT_START);
3885 fputc ('\n', asm_out_file);
3886 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3887 fputc ('\n', asm_out_file);
3889 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3891 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3892 cfi->dw_cfi_opc
3893 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3894 if (flag_verbose_asm)
3896 fprintf (asm_out_file, "\t%s DW_CFA_restore", ASM_COMMENT_START);
3898 fputc ('\n', asm_out_file);
3900 else
3902 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
3903 if (flag_verbose_asm)
3905 fprintf (asm_out_file, "\t%s %s",
3906 ASM_COMMENT_START,
3907 dwarf_cfi_name (cfi->dw_cfi_opc));
3909 fputc ('\n', asm_out_file);
3910 switch (cfi->dw_cfi_opc)
3912 case DW_CFA_set_loc:
3913 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
3914 cfi->dw_cfi_oprnd1.dw_cfi_addr);
3915 fputc ('\n', asm_out_file);
3916 break;
3917 case DW_CFA_advance_loc1:
3918 /* TODO: not currently implemented. */
3919 abort ();
3920 break;
3921 case DW_CFA_advance_loc2:
3922 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
3923 cfi->dw_cfi_oprnd1.dw_cfi_addr,
3924 fde->dw_fde_begin);
3925 fputc ('\n', asm_out_file);
3926 break;
3927 case DW_CFA_advance_loc4:
3928 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
3929 cfi->dw_cfi_oprnd1.dw_cfi_addr,
3930 fde->dw_fde_begin);
3931 fputc ('\n', asm_out_file);
3932 break;
3933 #ifdef MIPS_DEBUGGING_INFO
3934 case DW_CFA_MIPS_advance_loc8:
3935 /* TODO: not currently implemented. */
3936 abort ();
3937 break;
3938 #endif
3939 case DW_CFA_offset_extended:
3940 case DW_CFA_def_cfa:
3941 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3942 fputc ('\n', asm_out_file);
3943 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3944 fputc ('\n', asm_out_file);
3945 break;
3946 case DW_CFA_restore_extended:
3947 case DW_CFA_undefined:
3948 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3949 fputc ('\n', asm_out_file);
3950 break;
3951 case DW_CFA_same_value:
3952 case DW_CFA_def_cfa_register:
3953 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3954 fputc ('\n', asm_out_file);
3955 break;
3956 case DW_CFA_register:
3957 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3958 fputc ('\n', asm_out_file);
3959 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3960 fputc ('\n', asm_out_file);
3961 break;
3962 case DW_CFA_def_cfa_offset:
3963 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
3964 fputc ('\n', asm_out_file);
3965 break;
3966 default:
3967 break;
3972 /* Output the call frame information used to used to record information
3973 that relates to calculating the frame pointer, and records the
3974 location of saved registers. */
3975 static void
3976 output_call_frame_info ()
3978 register unsigned long i, j;
3979 register dw_fde_ref fde;
3980 register unsigned long fde_size;
3981 dw_cfi_node cfi_node;
3982 register dw_cfi_ref cfi;
3983 unsigned long fde_pad;
3985 /* Output the CIE. */
3986 ASM_OUTPUT_DWARF_DATA (asm_out_file, DWARF_CIE_SIZE - DWARF_OFFSET_SIZE);
3987 if (flag_verbose_asm)
3989 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
3990 ASM_COMMENT_START);
3992 fputc ('\n', asm_out_file);
3993 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
3994 if (flag_verbose_asm)
3996 fprintf (asm_out_file, "\t%s CIE Identifier Tag",
3997 ASM_COMMENT_START);
3999 fputc ('\n', asm_out_file);
4000 if (DWARF_OFFSET_SIZE == 8)
4002 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
4003 fputc ('\n', asm_out_file);
4005 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
4006 if (flag_verbose_asm)
4008 fprintf (asm_out_file, "\t%s CIE Version",
4009 ASM_COMMENT_START);
4011 fputc ('\n', asm_out_file);
4012 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4013 if (flag_verbose_asm)
4015 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
4016 ASM_COMMENT_START);
4018 fputc ('\n', asm_out_file);
4019 output_uleb128 (1);
4020 if (flag_verbose_asm)
4022 fprintf (asm_out_file, "\t%s CIE Code Alignment Factor",
4023 ASM_COMMENT_START);
4025 fputc ('\n', asm_out_file);
4026 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
4027 if (flag_verbose_asm)
4029 fprintf (asm_out_file, "\t%s CIE Data Alignment Factor",
4030 ASM_COMMENT_START);
4032 fputc ('\n', asm_out_file);
4033 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_FRAME_RA_COL);
4034 if (flag_verbose_asm)
4036 fprintf (asm_out_file, "\t%s CIE RA Column",
4037 ASM_COMMENT_START);
4039 fputc ('\n', asm_out_file);
4041 /* Output the CFA instructions common to all FDE's. */
4043 #ifdef MIPS_DEBUGGING_INFO
4045 /* Set the RA on entry to be the contents of r31. */
4046 bzero (&cfi_node, sizeof (dw_cfi_node));
4047 cfi = &cfi_node;
4048 cfi->dw_cfi_opc = DW_CFA_register;
4049 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DW_FRAME_RA_COL;
4050 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = DW_FRAME_REG31;
4051 output_cfi (cfi);
4053 #endif
4055 /* Pad the CIE out to an address sized boundary. */
4056 for (i = DWARF_CIE_HEADER_SIZE; i < DWARF_CIE_SIZE; ++i)
4058 /* Pad out to a pointer size boundary */
4059 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4060 if (flag_verbose_asm)
4062 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4063 ASM_COMMENT_START);
4065 fputc ('\n', asm_out_file);
4068 /* Loop through all of the FDE's. */
4069 for (i = 0; i < fde_table_in_use; ++i)
4071 fde = &fde_table[i];
4072 fde_size = size_of_fde (fde, &fde_pad);
4073 ASM_OUTPUT_DWARF_DATA (asm_out_file, fde_size - DWARF_OFFSET_SIZE);
4074 if (flag_verbose_asm)
4076 fprintf (asm_out_file, "\t%s FDE Length",
4077 ASM_COMMENT_START);
4079 fputc ('\n', asm_out_file);
4080 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
4081 if (flag_verbose_asm)
4083 fprintf (asm_out_file, "\t%s FDE CIE offset",
4084 ASM_COMMENT_START);
4086 fputc ('\n', asm_out_file);
4087 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
4088 if (flag_verbose_asm)
4090 fprintf (asm_out_file, "\t%s FDE initial location",
4091 ASM_COMMENT_START);
4093 fputc ('\n', asm_out_file);
4094 ASM_OUTPUT_DWARF_ADDR_DELTA
4095 (asm_out_file, fde->dw_fde_end, fde->dw_fde_begin);
4096 if (flag_verbose_asm)
4098 fprintf (asm_out_file, "\t%s FDE address range",
4099 ASM_COMMENT_START);
4101 fputc ('\n', asm_out_file);
4103 /* Loop through the Call Frame Instructions associated with
4104 this FDE. */
4105 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
4107 output_cfi (cfi, fde);
4110 /* Pad to a double word boundary. */
4111 for (j = 0; j < fde_pad; ++j)
4113 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4114 if (flag_verbose_asm)
4116 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4117 ASM_COMMENT_START);
4119 fputc ('\n', asm_out_file);
4124 /* Add a new entry to .debug_pubnames if appropriate. */
4125 static void
4126 add_pubname (decl, die)
4127 tree decl;
4128 dw_die_ref die;
4130 pubname_ref p;
4132 if (! TREE_PUBLIC (decl))
4133 return;
4135 if (pubname_table_in_use == pubname_table_allocated)
4137 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
4138 pubname_table = (pubname_ref) xrealloc
4139 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
4141 p = &pubname_table[pubname_table_in_use++];
4142 p->die = die;
4143 p->name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4146 /* Output the public names table used to speed up access to externally
4147 visible names. For now, only generate entries for externally
4148 visible procedures. */
4149 static void
4150 output_pubnames ()
4152 register unsigned i;
4154 register unsigned long pubnames_length = size_of_pubnames ();
4155 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
4157 if (flag_verbose_asm)
4159 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
4160 ASM_COMMENT_START);
4162 fputc ('\n', asm_out_file);
4163 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4164 if (flag_verbose_asm)
4166 fprintf (asm_out_file, "\t%s DWARF Version",
4167 ASM_COMMENT_START);
4169 fputc ('\n', asm_out_file);
4170 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4171 if (flag_verbose_asm)
4173 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4174 ASM_COMMENT_START);
4176 fputc ('\n', asm_out_file);
4177 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
4178 if (flag_verbose_asm)
4180 fprintf (asm_out_file, "\t%s Compilation Unit Length",
4181 ASM_COMMENT_START);
4183 fputc ('\n', asm_out_file);
4184 for (i = 0; i < pubname_table_in_use; ++i)
4186 register pubname_ref pub = &pubname_table[i];
4187 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
4188 if (flag_verbose_asm)
4190 fprintf (asm_out_file, "\t%s DIE offset",
4191 ASM_COMMENT_START);
4193 fputc ('\n', asm_out_file);
4195 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
4196 if (flag_verbose_asm)
4198 fprintf (asm_out_file, "%s external name",
4199 ASM_COMMENT_START);
4201 fputc ('\n', asm_out_file);
4203 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
4204 fputc ('\n', asm_out_file);
4207 /* Add a new entry to .debug_aranges if appropriate. */
4208 static void
4209 add_arange (decl, die)
4210 tree decl;
4211 dw_die_ref die;
4213 if (! DECL_SECTION_NAME (decl))
4214 return;
4216 if (arange_table_in_use == arange_table_allocated)
4218 arange_table_allocated += ARANGE_TABLE_INCREMENT;
4219 arange_table = (arange_ref) xrealloc
4220 (arange_table, arange_table_allocated * sizeof (dw_die_ref));
4222 arange_table[arange_table_in_use++] = die;
4225 /* Output the information that goes into the .debug_aranges table.
4226 Namely, define the beginning and ending address range of the
4227 text section generated for this compilation unit. */
4228 static void
4229 output_aranges ()
4231 register unsigned i;
4233 register unsigned long aranges_length = size_of_aranges ();
4234 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
4236 if (flag_verbose_asm)
4238 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
4239 ASM_COMMENT_START);
4241 fputc ('\n', asm_out_file);
4242 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4243 if (flag_verbose_asm)
4245 fprintf (asm_out_file, "\t%s DWARF Version",
4246 ASM_COMMENT_START);
4248 fputc ('\n', asm_out_file);
4249 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4250 if (flag_verbose_asm)
4252 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4253 ASM_COMMENT_START);
4255 fputc ('\n', asm_out_file);
4256 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
4257 if (flag_verbose_asm)
4259 fprintf (asm_out_file, "\t%s Size of Address",
4260 ASM_COMMENT_START);
4262 fputc ('\n', asm_out_file);
4263 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4264 if (flag_verbose_asm)
4266 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
4267 ASM_COMMENT_START);
4269 fputc ('\n', asm_out_file);
4270 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4271 if (PTR_SIZE == 8)
4272 fprintf (asm_out_file, ",0,0");
4273 if (flag_verbose_asm)
4275 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
4276 ASM_COMMENT_START, 2 * PTR_SIZE);
4278 fputc ('\n', asm_out_file);
4279 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
4280 if (flag_verbose_asm)
4282 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4284 fputc ('\n', asm_out_file);
4285 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, TEXT_END_LABEL, TEXT_SECTION);
4286 if (flag_verbose_asm)
4288 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4290 fputc ('\n', asm_out_file);
4291 for (i = 0; i < arange_table_in_use; ++i)
4293 dw_die_ref a = arange_table[i];
4294 if (a->die_tag == DW_TAG_subprogram)
4295 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
4296 else
4297 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_string (a, DW_AT_name));
4298 if (flag_verbose_asm)
4300 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4302 fputc ('\n', asm_out_file);
4303 if (a->die_tag == DW_TAG_subprogram)
4304 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
4305 get_AT_low_pc (a));
4306 else
4307 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
4308 get_AT_unsigned (a, DW_AT_byte_size));
4309 if (flag_verbose_asm)
4311 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4313 fputc ('\n', asm_out_file);
4315 /* Output the terminator words. */
4316 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
4317 fputc ('\n', asm_out_file);
4318 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
4319 fputc ('\n', asm_out_file);
4322 /* Output the source line number correspondence information. This
4323 information goes into the .debug_line section. */
4324 static void
4325 output_line_info ()
4327 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4328 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4329 register unsigned opc;
4330 register unsigned n_op_args;
4331 register unsigned long ft_index;
4332 register unsigned long lt_index;
4333 register unsigned long current_line;
4334 register long line_offset;
4335 register long line_delta;
4336 register unsigned long current_file;
4337 register unsigned long function;
4338 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
4339 if (flag_verbose_asm)
4341 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
4342 ASM_COMMENT_START);
4344 fputc ('\n', asm_out_file);
4345 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4346 if (flag_verbose_asm)
4348 fprintf (asm_out_file, "\t%s DWARF Version",
4349 ASM_COMMENT_START);
4351 fputc ('\n', asm_out_file);
4352 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
4353 if (flag_verbose_asm)
4355 fprintf (asm_out_file, "\t%s Prolog Length",
4356 ASM_COMMENT_START);
4358 fputc ('\n', asm_out_file);
4359 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
4360 if (flag_verbose_asm)
4362 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
4363 ASM_COMMENT_START);
4365 fputc ('\n', asm_out_file);
4366 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
4367 if (flag_verbose_asm)
4369 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
4370 ASM_COMMENT_START);
4372 fputc ('\n', asm_out_file);
4373 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
4374 if (flag_verbose_asm)
4376 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
4377 ASM_COMMENT_START);
4379 fputc ('\n', asm_out_file);
4380 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
4381 if (flag_verbose_asm)
4383 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
4384 ASM_COMMENT_START);
4386 fputc ('\n', asm_out_file);
4387 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
4388 if (flag_verbose_asm)
4390 fprintf (asm_out_file, "\t%s Special Opcode Base",
4391 ASM_COMMENT_START);
4393 fputc ('\n', asm_out_file);
4394 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
4396 switch (opc)
4398 case DW_LNS_advance_pc:
4399 case DW_LNS_advance_line:
4400 case DW_LNS_set_file:
4401 case DW_LNS_set_column:
4402 case DW_LNS_fixed_advance_pc:
4403 n_op_args = 1;
4404 break;
4405 default:
4406 n_op_args = 0;
4407 break;
4409 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
4410 if (flag_verbose_asm)
4412 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
4413 ASM_COMMENT_START, opc, n_op_args);
4415 fputc ('\n', asm_out_file);
4417 if (flag_verbose_asm)
4419 fprintf (asm_out_file, "%s Include Directory Table\n",
4420 ASM_COMMENT_START);
4422 /* Include directory table is empty, at present */
4423 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4424 fputc ('\n', asm_out_file);
4425 if (flag_verbose_asm)
4427 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
4429 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4431 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
4432 if (flag_verbose_asm)
4434 fprintf (asm_out_file, "%s File Entry: 0x%x",
4435 ASM_COMMENT_START, ft_index);
4437 fputc ('\n', asm_out_file);
4438 /* Include directory index */
4439 output_uleb128 (0);
4440 fputc ('\n', asm_out_file);
4441 /* Modification time */
4442 output_uleb128 (0);
4443 fputc ('\n', asm_out_file);
4444 /* File length in bytes */
4445 output_uleb128 (0);
4446 fputc ('\n', asm_out_file);
4448 /* Terminate the file name table */
4449 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4450 fputc ('\n', asm_out_file);
4452 /* Set the address register to the first location in the text section */
4453 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4454 if (flag_verbose_asm)
4456 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
4458 fputc ('\n', asm_out_file);
4459 output_uleb128 (1 + PTR_SIZE);
4460 fputc ('\n', asm_out_file);
4461 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4462 fputc ('\n', asm_out_file);
4463 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
4464 fputc ('\n', asm_out_file);
4466 /* Generate the line number to PC correspondence table, encoded as
4467 a series of state machine operations. */
4468 current_file = 1;
4469 current_line = 1;
4470 strcpy (prev_line_label, TEXT_SECTION);
4471 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4473 register dw_line_info_ref line_info;
4474 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4475 if (flag_verbose_asm)
4477 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4478 ASM_COMMENT_START);
4480 fputc ('\n', asm_out_file);
4481 sprintf (line_label, LINE_CODE_LABEL_FMT, lt_index);
4482 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4483 fputc ('\n', asm_out_file);
4484 line_info = &line_info_table[lt_index];
4485 if (line_info->dw_file_num != current_file)
4487 current_file = line_info->dw_file_num;
4488 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
4489 if (flag_verbose_asm)
4491 fprintf (asm_out_file,
4492 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4494 fputc ('\n', asm_out_file);
4495 output_uleb128 (current_file);
4496 if (flag_verbose_asm)
4498 fprintf (asm_out_file, "\t%s \"%s\"",
4499 ASM_COMMENT_START, file_table[current_file]);
4501 fputc ('\n', asm_out_file);
4503 if (line_info->dw_line_num != current_line)
4505 line_offset = line_info->dw_line_num - current_line;
4506 line_delta = line_offset - DWARF_LINE_BASE;
4507 current_line = line_info->dw_line_num;
4508 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4510 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4511 DWARF_LINE_OPCODE_BASE + line_delta);
4512 if (flag_verbose_asm)
4514 fprintf (asm_out_file,
4515 "\t%s line %d", ASM_COMMENT_START, current_line);
4517 fputc ('\n', asm_out_file);
4519 else
4521 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4522 if (flag_verbose_asm)
4524 fprintf (asm_out_file,
4525 "\t%s advance to line %d",
4526 ASM_COMMENT_START, current_line);
4528 fputc ('\n', asm_out_file);
4529 output_sleb128 (line_offset);
4530 fputc ('\n', asm_out_file);
4531 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
4532 fputc ('\n', asm_out_file);
4535 strcpy (prev_line_label, line_label);
4538 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4539 if (flag_verbose_asm)
4541 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4542 ASM_COMMENT_START);
4544 fputc ('\n', asm_out_file);
4545 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, TEXT_END_LABEL, prev_line_label);
4546 fputc ('\n', asm_out_file);
4548 /* Output the marker for the end of the line number info. */
4549 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4550 if (flag_verbose_asm)
4552 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
4554 fputc ('\n', asm_out_file);
4555 output_uleb128 (1);
4556 fputc ('\n', asm_out_file);
4557 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
4558 fputc ('\n', asm_out_file);
4560 function = 0;
4561 current_file = 1;
4562 current_line = 1;
4563 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4565 register dw_separate_line_info_ref line_info
4566 = &separate_line_info_table[lt_index];
4567 sprintf (line_label, SEPARATE_LINE_CODE_LABEL_FMT, lt_index);
4568 if (function != line_info->function)
4570 function = line_info->function;
4571 /* Set the address register to the first line in the function */
4572 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4573 if (flag_verbose_asm)
4574 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
4575 ASM_COMMENT_START);
4576 fputc ('\n', asm_out_file);
4577 output_uleb128 (1 + PTR_SIZE);
4578 fputc ('\n', asm_out_file);
4579 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4580 fputc ('\n', asm_out_file);
4581 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
4582 fputc ('\n', asm_out_file);
4584 else
4586 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4587 if (flag_verbose_asm)
4588 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4589 ASM_COMMENT_START);
4590 fputc ('\n', asm_out_file);
4591 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4592 fputc ('\n', asm_out_file);
4594 if (line_info->dw_file_num != current_file)
4596 current_file = line_info->dw_file_num;
4597 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
4598 if (flag_verbose_asm)
4600 fprintf (asm_out_file,
4601 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4603 fputc ('\n', asm_out_file);
4604 output_uleb128 (current_file);
4605 if (flag_verbose_asm)
4607 fprintf (asm_out_file, "\t%s \"%s\"",
4608 ASM_COMMENT_START, file_table[current_file]);
4610 fputc ('\n', asm_out_file);
4612 if (line_info->dw_line_num != current_line)
4614 line_offset = line_info->dw_line_num - current_line;
4615 line_delta = line_offset - DWARF_LINE_BASE;
4616 current_line = line_info->dw_line_num;
4617 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4619 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4620 DWARF_LINE_OPCODE_BASE + line_delta);
4621 if (flag_verbose_asm)
4623 fprintf (asm_out_file,
4624 "\t%s line %d", ASM_COMMENT_START, current_line);
4626 fputc ('\n', asm_out_file);
4628 else
4630 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4631 if (flag_verbose_asm)
4633 fprintf (asm_out_file,
4634 "\t%s advance to line %d",
4635 ASM_COMMENT_START, current_line);
4637 fputc ('\n', asm_out_file);
4638 output_sleb128 (line_offset);
4639 fputc ('\n', asm_out_file);
4640 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
4641 fputc ('\n', asm_out_file);
4644 ++lt_index;
4645 strcpy (prev_line_label, line_label);
4647 /* If we're done with a function, end its sequence. */
4648 if (lt_index == separate_line_info_table_in_use
4649 || separate_line_info_table[lt_index].function != function)
4651 current_file = 1;
4652 current_line = 1;
4653 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4654 if (flag_verbose_asm)
4655 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4656 ASM_COMMENT_START);
4657 fputc ('\n', asm_out_file);
4658 sprintf (line_label, FUNC_END_LABEL_FMT, function);
4659 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4660 fputc ('\n', asm_out_file);
4662 /* Output the marker for the end of this sequence. */
4663 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4664 if (flag_verbose_asm)
4665 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
4666 ASM_COMMENT_START);
4667 fputc ('\n', asm_out_file);
4668 output_uleb128 (1);
4669 fputc ('\n', asm_out_file);
4670 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
4671 fputc ('\n', asm_out_file);
4676 /**************** attribute support utilities ********************************/
4679 * Given a pointer to a BLOCK node return non-zero if (and only if) the node
4680 * in question represents the outermost pair of curly braces (i.e. the "body
4681 * block") of a function or method.
4683 * For any BLOCK node representing a "body block" of a function or method, the
4684 * BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
4685 * represents the outermost (function) scope for the function or method (i.e.
4686 * the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
4687 * *that* node in turn will point to the relevant FUNCTION_DECL node.
4689 inline int
4690 is_body_block (stmt)
4691 register tree stmt;
4693 if (TREE_CODE (stmt) == BLOCK)
4695 register tree parent = BLOCK_SUPERCONTEXT (stmt);
4697 if (TREE_CODE (parent) == BLOCK)
4699 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
4701 if (TREE_CODE (grandparent) == FUNCTION_DECL)
4702 return 1;
4705 return 0;
4708 /* Reset the base type to DIE table, and build a special predefined
4709 base type entry for the "int" signed integer base type. The
4710 "int" base type is used to construct subscript index range
4711 definitions, in situations where an anonymous integer type
4712 is required. */
4713 inline void
4714 init_base_type_table ()
4716 register int i;
4717 register base_type_ref bt;
4718 for (i = 0; i < NUM_BASE_TYPES; ++i)
4720 base_type_die_table[i] = NULL;
4722 assert (comp_unit_die != 0);
4723 for (i = 0; i < NUM_BASE_TYPES; ++i)
4725 bt = &base_type_table[i];
4726 if (strcmp (bt->bt_name, "int") == 0)
4728 int_base_type_die = new_die (DW_TAG_base_type, comp_unit_die);
4729 base_type_die_table[i] = int_base_type_die;
4730 add_AT_string (int_base_type_die, DW_AT_name, bt->bt_name);
4731 add_AT_unsigned (int_base_type_die,
4732 DW_AT_byte_size, bt->bt_size / 8);
4733 add_AT_unsigned (int_base_type_die, DW_AT_encoding, bt->bt_type);
4734 break;
4739 /* Given a pointer to a tree node for some base type, return a pointer to
4740 a DIE that describes the given type.
4742 This routine must only be called for GCC type nodes that correspond to
4743 Dwarf base (fundamental) types. */
4744 static dw_die_ref
4745 base_type_die (type)
4746 register tree type;
4748 register dw_die_ref base_type_result = NULL;
4749 register char *type_name = NULL;
4750 register int type_index = 0;
4751 register base_type_ref bt;
4752 register int i;
4754 if (TREE_CODE (type) == ERROR_MARK)
4755 return 0;
4757 switch (TREE_CODE (type))
4759 case VOID_TYPE:
4760 case ERROR_MARK:
4761 break;
4763 case INTEGER_TYPE:
4764 /* Carefully distinguish all the standard types of C, without messing
4765 up if the language is not C. Note that we check only for the names
4766 that contain spaces; other names might occur by coincidence in other
4767 languages. */
4768 if (TYPE_NAME (type) != 0
4769 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
4770 && DECL_NAME (TYPE_NAME (type)) != 0
4771 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
4773 type_name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
4774 for (i = 0; i < NUM_BASE_TYPES; ++i)
4776 bt = &base_type_table[i];
4777 if (strcmp (type_name, bt->bt_name) == 0)
4779 type_index = i;
4780 break;
4785 /* Most integer types will be sorted out above, however, for the sake
4786 of special `array index' integer types, the following code is also
4787 provided. */
4788 if (type_index == 0)
4790 for (i = 0; i < NUM_BASE_TYPES; ++i)
4792 bt = &base_type_table[i];
4793 if (bt->bt_size == TYPE_PRECISION (type)
4794 && (TREE_UNSIGNED (type) == 0) == bt->bt_is_signed)
4796 type_index = i;
4797 break;
4801 break;
4803 case REAL_TYPE:
4804 /* Carefully distinguish all the standard types of C, without messing
4805 up if the language is not C. */
4806 for (i = 0; i < NUM_BASE_TYPES; ++i)
4808 bt = &base_type_table[i];
4809 if ((bt->bt_type == DW_ATE_float)
4810 && (bt->bt_size == TYPE_PRECISION (type)))
4812 type_index = i;
4813 break;
4816 break;
4818 case COMPLEX_TYPE:
4819 for (i = 0; i < NUM_BASE_TYPES; ++i)
4821 bt = &base_type_table[i];
4822 if ((bt->bt_type == DW_ATE_complex_float)
4823 && (bt->bt_size == TYPE_PRECISION (type)))
4825 type_index = i;
4826 break;
4829 break;
4831 case CHAR_TYPE:
4832 /* GNU Pascal/Ada CHAR type. Not used in C. */
4833 for (i = 0; i < NUM_BASE_TYPES; ++i)
4835 bt = &base_type_table[i];
4836 if (bt->bt_type == DW_ATE_signed_char
4837 || bt->bt_type == DW_ATE_unsigned_char)
4839 if (bt->bt_size == TYPE_PRECISION (type)
4840 && ((TREE_UNSIGNED (type) == 0) == bt->bt_is_signed))
4842 type_index = i;
4843 break;
4847 break;
4849 case BOOLEAN_TYPE:
4850 /* GNU FORTRAN/Ada BOOLEAN type. */
4851 for (i = 0; i < NUM_BASE_TYPES; ++i)
4853 bt = &base_type_table[i];
4854 if (bt->bt_type == DW_ATE_boolean
4855 && bt->bt_size == TYPE_PRECISION (type))
4857 type_index = i;
4858 break;
4861 break;
4863 default:
4864 abort (); /* No other TREE_CODEs are Dwarf fundamental
4865 types. */
4868 if (type_index == 0)
4870 base_type_result = NULL;
4872 else
4874 base_type_result = base_type_die_table[type_index];
4875 if (base_type_result == NULL)
4877 bt = &base_type_table[type_index];
4878 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
4879 base_type_die_table[type_index] = base_type_result;
4880 add_AT_string (base_type_result, DW_AT_name, bt->bt_name);
4881 add_AT_unsigned (base_type_result, DW_AT_byte_size, bt->bt_size / 8);
4882 add_AT_unsigned (base_type_result, DW_AT_encoding, bt->bt_type);
4887 return base_type_result;
4890 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
4891 the Dwarf "root" type for the given input type. The Dwarf "root" type of
4892 a given type is generally the same as the given type, except that if the
4893 given type is a pointer or reference type, then the root type of the given
4894 type is the root type of the "basis" type for the pointer or reference
4895 type. (This definition of the "root" type is recursive.) Also, the root
4896 type of a `const' qualified type or a `volatile' qualified type is the
4897 root type of the given type without the qualifiers. */
4898 static tree
4899 root_type (type)
4900 register tree type;
4902 if (TREE_CODE (type) == ERROR_MARK)
4903 return error_mark_node;
4905 switch (TREE_CODE (type))
4907 case ERROR_MARK:
4908 return error_mark_node;
4910 case POINTER_TYPE:
4911 case REFERENCE_TYPE:
4912 return type_main_variant (root_type (TREE_TYPE (type)));
4914 default:
4915 return type_main_variant (type);
4919 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
4920 given input type is a Dwarf "fundamental" type. Otherwise return null. */
4921 inline int
4922 is_base_type (type)
4923 register tree type;
4925 switch (TREE_CODE (type))
4927 case ERROR_MARK:
4928 case VOID_TYPE:
4929 case INTEGER_TYPE:
4930 case REAL_TYPE:
4931 case COMPLEX_TYPE:
4932 case BOOLEAN_TYPE:
4933 case CHAR_TYPE:
4934 return 1;
4936 case SET_TYPE:
4937 case ARRAY_TYPE:
4938 case RECORD_TYPE:
4939 case UNION_TYPE:
4940 case QUAL_UNION_TYPE:
4941 case ENUMERAL_TYPE:
4942 case FUNCTION_TYPE:
4943 case METHOD_TYPE:
4944 case POINTER_TYPE:
4945 case REFERENCE_TYPE:
4946 case FILE_TYPE:
4947 case OFFSET_TYPE:
4948 case LANG_TYPE:
4949 return 0;
4951 default:
4952 abort ();
4954 return 0;
4957 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
4958 entry that chains various modifiers in front of the given type. */
4959 static dw_die_ref
4960 modified_type_die (type, is_const_type, is_volatile_type, context_die)
4961 register tree type;
4962 register int is_const_type;
4963 register int is_volatile_type;
4964 register dw_die_ref context_die;
4966 register enum tree_code code = TREE_CODE (type);
4967 register dw_die_ref mod_type_die = NULL;
4968 register dw_die_ref sub_die = NULL;
4969 register tree item_type;
4971 if (code != ERROR_MARK)
4973 type = build_type_variant (type, is_const_type, is_volatile_type);
4975 mod_type_die = lookup_type_die (type);
4976 if (mod_type_die)
4977 return mod_type_die;
4979 if (is_const_type)
4981 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
4982 sub_die = modified_type_die
4983 (build_type_variant (type, 0, is_volatile_type),
4984 0, is_volatile_type, context_die);
4986 else if (is_volatile_type)
4988 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
4989 sub_die = modified_type_die
4990 (TYPE_MAIN_VARIANT (type), 0, 0, context_die);
4992 else if (code == POINTER_TYPE)
4994 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
4995 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
4996 #if 0
4997 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
4998 #endif
4999 item_type = TREE_TYPE (type);
5000 sub_die = modified_type_die (item_type,
5001 TYPE_READONLY (item_type),
5002 TYPE_VOLATILE (item_type),
5003 context_die);
5005 else if (code == REFERENCE_TYPE)
5007 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
5008 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5009 #if 0
5010 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5011 #endif
5012 item_type = TREE_TYPE (type);
5013 sub_die = modified_type_die (item_type,
5014 TYPE_READONLY (item_type),
5015 TYPE_VOLATILE (item_type),
5016 context_die);
5018 else if (is_base_type (type))
5020 mod_type_die = base_type_die (type);
5022 else
5024 gen_type_die (type, context_die);
5026 /* We have to get the type_main_variant here (and pass that to the
5027 `lookup_type_die' routine) because the ..._TYPE node we have
5028 might simply be a *copy* of some original type node (where the
5029 copy was created to help us keep track of typedef names) and
5030 that copy might have a different TYPE_UID from the original
5031 ..._TYPE node. (Note that when `equate_type_number_to_die' is
5032 labeling a given type DIE for future reference, it always only
5033 handles DIEs representing *main variants*, and it never even
5034 knows about non-main-variants.). */
5035 mod_type_die = lookup_type_die (type_main_variant (type));
5036 if (mod_type_die == NULL)
5037 abort ();
5040 if (sub_die != NULL)
5042 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
5044 equate_type_number_to_die (type, mod_type_die);
5045 return mod_type_die;
5048 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
5049 an enumerated type. */
5050 inline int
5051 type_is_enum (type)
5052 register tree type;
5054 return TREE_CODE (type) == ENUMERAL_TYPE;
5057 /* Return the register number described by a given RTL node. */
5058 static unsigned
5059 reg_number (rtl)
5060 register rtx rtl;
5062 register unsigned regno = REGNO (rtl);
5064 if (regno >= FIRST_PSEUDO_REGISTER)
5066 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
5067 regno);
5068 regno = 0;
5070 regno = DBX_REGISTER_NUMBER (regno);
5071 return regno;
5074 /* Return a location descriptor that designates a machine register. */
5075 static dw_loc_descr_ref
5076 reg_loc_descriptor (rtl)
5077 register rtx rtl;
5079 register dw_loc_descr_ref loc_result = NULL;
5080 register unsigned reg = reg_number (rtl);
5081 if (reg >= 0 && reg <= 31)
5083 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0);
5085 else
5087 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
5089 return loc_result;
5092 /* Return a location descriptor that designates a base+offset location. */
5093 static dw_loc_descr_ref
5094 based_loc_descr (reg, offset)
5095 unsigned reg;
5096 long int offset;
5098 register dw_loc_descr_ref loc_result;
5099 /* For the "frame base", we use the frame pointer or stack pointer
5100 registers, since the RTL for local variables is relative to one of
5101 them. */
5102 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
5103 ? FRAME_POINTER_REGNUM
5104 : STACK_POINTER_REGNUM);
5105 if (reg == fp_reg)
5107 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
5109 else if (reg >= 0 && reg <= 31)
5111 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset);
5113 else
5115 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
5117 return loc_result;
5120 /* Return true if this RTL expression describes a base+offset calculation. */
5121 inline int
5122 is_based_loc (rtl)
5123 register rtx rtl;
5125 return GET_CODE (rtl) == PLUS
5126 && ((GET_CODE (XEXP (rtl, 0)) == REG
5127 && GET_CODE (XEXP (rtl, 1)) == CONST_INT));
5130 /* The following routine converts the RTL for a variable or parameter
5131 (resident in memory) into an equivalent Dwarf representation of a
5132 mechanism for getting the address of that same variable onto the top of a
5133 hypothetical "address evaluation" stack.
5134 When creating memory location descriptors, we are effectively transforming
5135 the RTL for a memory-resident object into its Dwarf postfix expression
5136 equivalent. This routine recursively descends an RTL tree, turning
5137 it into Dwarf postfix code as it goes. */
5138 static dw_loc_descr_ref
5139 mem_loc_descriptor (rtl)
5140 register rtx rtl;
5142 dw_loc_descr_ref mem_loc_result = NULL;
5143 /* Note that for a dynamically sized array, the location we will generate a
5144 description of here will be the lowest numbered location which is
5145 actually within the array. That's *not* necessarily the same as the
5146 zeroth element of the array. */
5147 switch (GET_CODE (rtl))
5149 case SUBREG:
5150 /* The case of a subreg may arise when we have a local (register)
5151 variable or a formal (register) parameter which doesn't quite fill
5152 up an entire register. For now, just assume that it is
5153 legitimate to make the Dwarf info refer to the whole register which
5154 contains the given subreg. */
5155 rtl = XEXP (rtl, 0);
5156 /* Drop thru. */
5158 case REG:
5159 /* Whenever a register number forms a part of the description of the
5160 method for calculating the (dynamic) address of a memory resident
5161 object, DWARF rules require the register number be referred to as
5162 a "base register". This distinction is not based in any way upon
5163 what category of register the hardware believes the given register
5164 belongs to. This is strictly DWARF terminology we're dealing with
5165 here. Note that in cases where the location of a memory-resident
5166 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
5167 OP_CONST (0)) the actual DWARF location descriptor that we generate
5168 may just be OP_BASEREG (basereg). This may look deceptively like
5169 the object in question was allocated to a register (rather than in
5170 memory) so DWARF consumers need to be aware of the subtle
5171 distinction between OP_REG and OP_BASEREG. */
5172 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
5173 break;
5175 case MEM:
5176 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5177 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
5178 break;
5180 case CONST:
5181 case SYMBOL_REF:
5182 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
5183 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
5184 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
5185 break;
5187 case PLUS:
5188 if (is_based_loc (rtl))
5190 mem_loc_result = based_loc_descr (
5191 reg_number (XEXP (rtl, 0)),
5192 INTVAL (XEXP (rtl, 1)));
5194 else
5196 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5197 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5198 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
5200 break;
5202 case CONST_INT:
5203 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
5204 break;
5206 default:
5207 abort ();
5209 return mem_loc_result;
5212 /* Output a proper Dwarf location descriptor for a variable or parameter
5213 which is either allocated in a register or in a memory location. For a
5214 register, we just generate an OP_REG and the register number. For a
5215 memory location we provide a Dwarf postfix expression describing how to
5216 generate the (dynamic) address of the object onto the address stack. */
5217 static dw_loc_descr_ref
5218 loc_descriptor (rtl)
5219 register rtx rtl;
5221 dw_loc_descr_ref loc_result = NULL;
5222 switch (GET_CODE (rtl))
5224 case SUBREG:
5226 /* The case of a subreg may arise when we have a local (register)
5227 variable or a formal (register) parameter which doesn't quite fill
5228 up an entire register. For now, just assume that it is
5229 legitimate to make the Dwarf info refer to the whole register which
5230 contains the given subreg. */
5232 rtl = XEXP (rtl, 0);
5233 loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0);
5234 break;
5236 case REG:
5237 loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0);
5238 break;
5240 case MEM:
5241 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5242 break;
5244 default:
5245 abort (); /* Should never happen */
5247 return loc_result;
5250 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
5251 which is not less than the value itself. */
5252 inline unsigned
5253 ceiling (value, boundary)
5254 register unsigned value;
5255 register unsigned boundary;
5257 return (((value + boundary - 1) / boundary) * boundary);
5260 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
5261 pointer to the declared type for the relevant field variable, or return
5262 `integer_type_node' if the given node turns out to be an
5263 ERROR_MARK node. */
5264 inline tree
5265 field_type (decl)
5266 register tree decl;
5268 register tree type;
5270 if (TREE_CODE (decl) == ERROR_MARK)
5271 return integer_type_node;
5273 type = DECL_BIT_FIELD_TYPE (decl);
5274 if (type == NULL)
5275 type = TREE_TYPE (decl);
5277 return type;
5280 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5281 node, return the alignment in bits for the type, or else return
5282 BITS_PER_WORD if the node actually turns out to be an
5283 ERROR_MARK node. */
5284 inline unsigned
5285 simple_type_align_in_bits (type)
5286 register tree type;
5288 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
5291 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5292 node, return the size in bits for the type if it is a constant, or else
5293 return the alignment for the type if the type's size is not constant, or
5294 else return BITS_PER_WORD if the type actually turns out to be an
5295 ERROR_MARK node. */
5296 inline unsigned
5297 simple_type_size_in_bits (type)
5298 register tree type;
5300 if (TREE_CODE (type) == ERROR_MARK)
5301 return BITS_PER_WORD;
5302 else
5304 register tree type_size_tree = TYPE_SIZE (type);
5306 if (TREE_CODE (type_size_tree) != INTEGER_CST)
5307 return TYPE_ALIGN (type);
5309 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
5313 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
5314 return the byte offset of the lowest addressed byte of the "containing
5315 object" for the given FIELD_DECL, or return 0 if we are unable to
5316 determine what that offset is, either because the argument turns out to
5317 be a pointer to an ERROR_MARK node, or because the offset is actually
5318 variable. (We can't handle the latter case just yet). */
5319 static unsigned
5320 field_byte_offset (decl)
5321 register tree decl;
5323 register unsigned type_align_in_bytes;
5324 register unsigned type_align_in_bits;
5325 register unsigned type_size_in_bits;
5326 register unsigned object_offset_in_align_units;
5327 register unsigned object_offset_in_bits;
5328 register unsigned object_offset_in_bytes;
5329 register tree type;
5330 register tree bitpos_tree;
5331 register tree field_size_tree;
5332 register unsigned bitpos_int;
5333 register unsigned deepest_bitpos;
5334 register unsigned field_size_in_bits;
5336 if (TREE_CODE (decl) == ERROR_MARK)
5337 return 0;
5339 if (TREE_CODE (decl) != FIELD_DECL)
5340 abort ();
5342 type = field_type (decl);
5344 bitpos_tree = DECL_FIELD_BITPOS (decl);
5345 field_size_tree = DECL_SIZE (decl);
5347 /* We cannot yet cope with fields whose positions or sizes are variable, so
5348 for now, when we see such things, we simply return 0. Someday, we may
5349 be able to handle such cases, but it will be damn difficult. */
5350 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5351 return 0;
5352 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5354 if (TREE_CODE (field_size_tree) != INTEGER_CST)
5355 return 0;
5356 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
5358 type_size_in_bits = simple_type_size_in_bits (type);
5360 type_align_in_bits = simple_type_align_in_bits (type);
5361 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
5363 /* Note that the GCC front-end doesn't make any attempt to keep track of
5364 the starting bit offset (relative to the start of the containing
5365 structure type) of the hypothetical "containing object" for a bit-
5366 field. Thus, when computing the byte offset value for the start of the
5367 "containing object" of a bit-field, we must deduce this information on
5368 our own. This can be rather tricky to do in some cases. For example,
5369 handling the following structure type definition when compiling for an
5370 i386/i486 target (which only aligns long long's to 32-bit boundaries)
5371 can be very tricky:
5373 struct S { int field1; long long field2:31; };
5375 Fortunately, there is a simple rule-of-thumb which can be
5376 used in such cases. When compiling for an i386/i486, GCC will allocate
5377 8 bytes for the structure shown above. It decides to do this based upon
5378 one simple rule for bit-field allocation. Quite simply, GCC allocates
5379 each "containing object" for each bit-field at the first (i.e. lowest
5380 addressed) legitimate alignment boundary (based upon the required
5381 minimum alignment for the declared type of the field) which it can
5382 possibly use, subject to the condition that there is still enough
5383 available space remaining in the containing object (when allocated at
5384 the selected point) to fully accommodate all of the bits of the
5385 bit-field itself. This simple rule makes it obvious why GCC allocates
5386 8 bytes for each object of the structure type shown above. When looking
5387 for a place to allocate the "containing object" for `field2', the
5388 compiler simply tries to allocate a 64-bit "containing object" at each
5389 successive 32-bit boundary (starting at zero) until it finds a place to
5390 allocate that 64- bit field such that at least 31 contiguous (and
5391 previously unallocated) bits remain within that selected 64 bit field.
5392 (As it turns out, for the example above, the compiler finds that it is
5393 OK to allocate the "containing object" 64-bit field at bit-offset zero
5394 within the structure type.) Here we attempt to work backwards from the
5395 limited set of facts we're given, and we try to deduce from those facts,
5396 where GCC must have believed that the containing object started (within
5397 the structure type). The value we deduce is then used (by the callers of
5398 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
5399 for fields (both bit-fields and, in the case of DW_AT_location, regular
5400 fields as well). */
5402 /* Figure out the bit-distance from the start of the structure to the
5403 "deepest" bit of the bit-field. */
5404 deepest_bitpos = bitpos_int + field_size_in_bits;
5406 /* This is the tricky part. Use some fancy footwork to deduce where the
5407 lowest addressed bit of the containing object must be. */
5408 object_offset_in_bits
5409 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
5411 /* Compute the offset of the containing object in "alignment units". */
5412 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
5414 /* Compute the offset of the containing object in bytes. */
5415 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
5417 return object_offset_in_bytes;
5422 /****************************** attributes *********************************/
5424 /* The following routines define various Dwarf attributes
5425 (and any data associated with them). */
5428 /* Output the form of location attributes suitable for whole variables and
5429 whole parameters. Note that the location attributes for struct fields are
5430 generated by the routine `data_member_location_attribute' below. */
5431 static void
5432 add_location_attribute (die, rtl)
5433 dw_die_ref die;
5434 register rtx rtl;
5436 dw_loc_descr_ref loc_descr = NULL;
5438 /* Handle a special case. If we are about to output a location descriptor
5439 for a variable or parameter which has been optimized out of existence,
5440 don't do that. Instead we output a null location descriptor value as
5441 part of the location attribute. A variable which has been optimized out
5442 of existence will have a DECL_RTL value which denotes a pseudo-reg.
5443 Currently, in some rare cases, variables can have DECL_RTL values which
5444 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
5445 elsewhere in the compiler. We treat such cases as if the variable(s) in
5446 question had been optimized out of existence. Note that in all cases
5447 where we wish to express the fact that a variable has been optimized out
5448 of existence, we do not simply suppress the generation of the entire
5449 location attribute because the absence of a location attribute in
5450 certain kinds of DIEs is used to indicate something else entirely...
5451 i.e. that the DIE represents an object declaration, but not a
5452 definition. So sayeth the PLSIG. */
5453 if (!is_pseudo_reg (rtl)
5454 && (GET_CODE (rtl) != MEM
5455 || !is_pseudo_reg (XEXP (rtl, 0))))
5457 loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
5460 #ifdef MIPS_DEBUGGING_INFO
5461 /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
5462 location descriptor. Lets just use r0 for now to represent a
5463 variable that has been optimized away. */
5464 if (loc_descr == NULL)
5466 loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0));
5468 #endif
5470 add_AT_loc (die, DW_AT_location, loc_descr);
5473 /* Attach the specialized form of location attribute used for data
5474 members of struct and union types. In the special case of a
5475 FIELD_DECL node which represents a bit-field, the "offset" part
5476 of this special location descriptor must indicate the distance
5477 in bytes from the lowest-addressed byte of the containing struct
5478 or union type to the lowest-addressed byte of the "containing
5479 object" for the bit-field. (See the `field_byte_offset' function
5480 above).. For any given bit-field, the "containing object" is a
5481 hypothetical object (of some integral or enum type) within which
5482 the given bit-field lives. The type of this hypothetical
5483 "containing object" is always the same as the declared type of
5484 the individual bit-field itself (for GCC anyway... the DWARF
5485 spec doesn't actually mandate this). Note that it is the size
5486 (in bytes) of the hypothetical "containing object" which will
5487 be given in the DW_AT_byte_size attribute for this bit-field.
5488 (See the `byte_size_attribute' function below.) It is also used
5489 when calculating the value of the DW_AT_bit_offset attribute.
5490 (See the `bit_offset_attribute' function below). */
5491 static void
5492 add_data_member_location_attribute (die, decl)
5493 register dw_die_ref die;
5494 register tree decl;
5496 register unsigned long offset;
5497 register dw_loc_descr_ref loc_descr;
5498 register enum dwarf_location_atom op;
5500 if (TREE_CODE (decl) == TREE_VEC)
5501 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
5502 else
5503 offset = field_byte_offset (decl);
5505 /* The DWARF2 standard says that we should assume that the structure address
5506 is already on the stack, so we can specify a structure field address
5507 by using DW_OP_plus_uconst. */
5508 #ifdef MIPS_DEBUGGING_INFO
5509 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
5510 correctly. It works only if we leave the offset on the stack. */
5511 op = DW_OP_constu;
5512 #else
5513 op = DW_OP_plus_uconst;
5514 #endif
5515 loc_descr = new_loc_descr (op, offset, 0);
5516 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
5519 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
5520 does not have a "location" either in memory or in a register. These
5521 things can arise in GNU C when a constant is passed as an actual parameter
5522 to an inlined function. They can also arise in C++ where declared
5523 constants do not necessarily get memory "homes". */
5524 static void
5525 add_const_value_attribute (die, rtl)
5526 register dw_die_ref die;
5527 register rtx rtl;
5529 switch (GET_CODE (rtl))
5531 case CONST_INT:
5532 /* Note that a CONST_INT rtx could represent either an integer or a
5533 floating-point constant. A CONST_INT is used whenever the constant
5534 will fit into a single word. In all such cases, the original mode
5535 of the constant value is wiped out, and the CONST_INT rtx is
5536 assigned VOIDmode. */
5537 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
5538 break;
5540 case CONST_DOUBLE:
5541 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
5542 floating-point constant. A CONST_DOUBLE is used whenever the
5543 constant requires more than one word in order to be adequately
5544 represented. In all such cases, the original mode of the constant
5545 value is preserved as the mode of the CONST_DOUBLE rtx, but for
5546 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
5547 add_AT_double (die, DW_AT_const_value,
5548 (unsigned) CONST_DOUBLE_HIGH (rtl),
5549 (unsigned) CONST_DOUBLE_LOW (rtl));
5550 break;
5552 case CONST_STRING:
5553 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
5554 break;
5556 case SYMBOL_REF:
5557 case LABEL_REF:
5558 case CONST:
5559 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
5560 break;
5562 case PLUS:
5563 /* In cases where an inlined instance of an inline function is passed
5564 the address of an `auto' variable (which is local to the caller) we
5565 can get a situation where the DECL_RTL of the artificial local
5566 variable (for the inlining) which acts as a stand-in for the
5567 corresponding formal parameter (of the inline function) will look
5568 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
5569 exactly a compile-time constant expression, but it isn't the address
5570 of the (artificial) local variable either. Rather, it represents the
5571 *value* which the artificial local variable always has during its
5572 lifetime. We currently have no way to represent such quasi-constant
5573 values in Dwarf, so for now we just punt and generate an
5574 DW_AT_const_value attribute with null address. */
5575 add_AT_addr (die, DW_AT_const_value, addr_to_string (const0_rtx));
5576 break;
5578 default:
5579 /* No other kinds of rtx should be possible here. */
5580 abort ();
5585 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
5586 data attribute for a variable or a parameter. We generate the
5587 DW_AT_const_value attribute only in those cases where the given variable
5588 or parameter does not have a true "location" either in memory or in a
5589 register. This can happen (for example) when a constant is passed as an
5590 actual argument in a call to an inline function. (It's possible that
5591 these things can crop up in other ways also.) Note that one type of
5592 constant value which can be passed into an inlined function is a constant
5593 pointer. This can happen for example if an actual argument in an inlined
5594 function call evaluates to a compile-time constant address. */
5595 static void
5596 add_location_or_const_value_attribute (die, decl)
5597 register dw_die_ref die;
5598 register tree decl;
5600 register rtx rtl;
5601 register tree declared_type;
5602 register tree passed_type;
5604 if (TREE_CODE (decl) == ERROR_MARK)
5606 return;
5608 if ((TREE_CODE (decl) != VAR_DECL)
5609 && (TREE_CODE (decl) != PARM_DECL))
5611 /* Should never happen. */
5612 abort ();
5613 return;
5615 /* Here we have to decide where we are going to say the parameter "lives"
5616 (as far as the debugger is concerned). We only have a couple of
5617 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
5618 DECL_RTL normally indicates where the parameter lives during most of the
5619 activa- tion of the function. If optimization is enabled however, this
5620 could be either NULL or else a pseudo-reg. Both of those cases indicate
5621 that the parameter doesn't really live anywhere (as far as the code
5622 generation parts of GCC are concerned) during most of the function's
5623 activation. That will happen (for example) if the parameter is never
5624 referenced within the function. We could just generate a location
5625 descriptor here for all non-NULL non-pseudo values of DECL_RTL and
5626 ignore all of the rest, but we can be a little nicer than that if we
5627 also consider DECL_INCOMING_RTL in cases where DECL_RTL is NULL or is a
5628 pseudo-reg. Note however that we can only get away with using
5629 DECL_INCOMING_RTL as a backup substitute for DECL_RTL in certain limited
5630 cases. In cases where DECL_ARG_TYPE(decl) indicates the same type as
5631 TREE_TYPE(decl) we can be sure that the parameter was passed using the
5632 same type as it is declared to have within the function, and that its
5633 DECL_INCOMING_RTL points us to a place where a value of that type is
5634 passed. In cases where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are
5635 different types however, we cannot (in general) use DECL_INCOMING_RTL as
5636 a backup substitute for DECL_RTL because in these cases,
5637 DECL_INCOMING_RTL points us to a value of some type which is *different*
5638 from the type of the parameter itself. Thus, if we tried to use
5639 DECL_INCOMING_RTL to generate a location attribute in such cases, the
5640 debugger would end up (for example) trying to fetch a `float' from a
5641 place which actually contains the first part of a `double'. That would
5642 lead to really incorrect and confusing output at debug-time, and we
5643 don't want that now do we? So in general, we DO NOT use
5644 DECL_INCOMING_RTL as a backup for DECL_RTL in cases where
5645 DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a couple of cute
5646 exceptions however. On little-endian machines we can get away with
5647 using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is not the same as
5648 TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is an integral type
5649 which is smaller than TREE_TYPE(decl). These cases arise when (on a
5650 little-endian machine) a non-prototyped function has a parameter
5651 declared to be of type `short' or `char'. In such cases,
5652 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
5653 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
5654 passed `int' value. If the debugger then uses that address to fetch a
5655 `short' or a `char' (on a little-endian machine) the result will be the
5656 correct data, so we allow for such exceptional cases below. Note that
5657 our goal here is to describe the place where the given formal parameter
5658 lives during most of the function's activation (i.e. between the end of
5659 the prologue and the start of the epilogue). We'll do that as best as
5660 we can. Note however that if the given formal parameter is modified
5661 sometime during the execution of the function, then a stack backtrace
5662 (at debug-time) will show the function as having been called with the
5663 *new* value rather than the value which was originally passed in. This
5664 happens rarely enough that it is not a major problem, but it *is* a
5665 problem, and I'd like to fix it. A future version of dwarfout.c may
5666 generate two additional attributes for any given DW_TAG_formal_parameter
5667 DIE which will describe the "passed type" and the "passed location" for
5668 the given formal parameter in addition to the attributes we now generate
5669 to indicate the "declared type" and the "active location" for each
5670 parameter. This additional set of attributes could be used by debuggers
5671 for stack backtraces. Separately, note that sometimes DECL_RTL can be
5672 NULL and DECL_INCOMING_RTL can be NULL also. This happens (for example)
5673 for inlined-instances of inline function formal parameters which are
5674 never referenced. This really shouldn't be happening. All PARM_DECL
5675 nodes should get valid non-NULL DECL_INCOMING_RTL values, but
5676 integrate.c doesn't currently generate these values for inlined
5677 instances of inline function parameters, so when we see such cases, we
5678 are just SOL (shit-out-of-luck) for the time being (until integrate.c
5679 gets fixed). */
5681 /* Use DECL_RTL as the "location" unless we find something better. */
5682 rtl = DECL_RTL (decl);
5684 if (TREE_CODE (decl) == PARM_DECL)
5686 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
5688 declared_type = type_main_variant (TREE_TYPE (decl));
5689 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
5690 /* This decl represents a formal parameter which was
5691 optimized out.
5693 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
5694 all* cases where (rtl == NULL_RTX) just below. */
5695 if (declared_type == passed_type)
5697 rtl = DECL_INCOMING_RTL (decl);
5699 else if (!BYTES_BIG_ENDIAN)
5701 if (TREE_CODE (declared_type) == INTEGER_TYPE)
5703 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
5705 rtl = DECL_INCOMING_RTL (decl);
5711 if (rtl == NULL_RTX)
5712 return;
5714 switch (GET_CODE (rtl))
5716 case CONST_INT:
5717 case CONST_DOUBLE:
5718 case CONST_STRING:
5719 case SYMBOL_REF:
5720 case LABEL_REF:
5721 case CONST:
5722 case PLUS:
5723 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
5724 add_const_value_attribute (die, rtl);
5725 break;
5727 case MEM:
5728 case REG:
5729 case SUBREG:
5730 add_location_attribute (die, rtl);
5731 break;
5733 default:
5734 abort (); /* Should never happen. */
5738 /* Generate an DW_AT_name attribute given some string value to be included as
5739 the value of the attribute. */
5740 inline void
5741 add_name_attribute (die, name_string)
5742 register dw_die_ref die;
5743 register char *name_string;
5745 if (name_string && *name_string)
5747 add_AT_string (die, DW_AT_name, name_string);
5751 /* Given a tree node describing an array bound (either lower or upper) output
5752 a representation for that bound. */
5753 static void
5754 add_bound_info (subrange_die, bound_attr, bound)
5755 register dw_die_ref subrange_die;
5756 register enum dwarf_attribute bound_attr;
5757 register tree bound;
5759 register dw_loc_descr_ref bound_loc = NULL;
5760 register unsigned bound_value = 0;
5761 switch (TREE_CODE (bound))
5763 case ERROR_MARK:
5764 return;
5766 /* All fixed-bounds are represented by INTEGER_CST nodes. */
5767 case INTEGER_CST:
5768 bound_value = TREE_INT_CST_LOW (bound);
5769 /* TODO: we need to check for C language below, or some flag
5770 derived from the language. C implies a lower bound of 0. */
5771 if (!(bound_attr == DW_AT_lower_bound && bound_value == 0))
5773 add_AT_unsigned (subrange_die, bound_attr, bound_value);
5775 break;
5777 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
5778 SAVE_EXPR nodes. */
5779 case NOP_EXPR:
5780 bound = TREE_OPERAND (bound, 0);
5781 /* ... fall thru... */
5783 case SAVE_EXPR:
5784 /* If optimization is turned on, the SAVE_EXPRs that describe how to
5785 access the upper bound values are essentially bogus. They only
5786 describe (at best) how to get at these values at the points in the
5787 generated code right after they have just been computed. Worse yet,
5788 in the typical case, the upper bound values will not even *be*
5789 computed in the optimized code, so these SAVE_EXPRs are entirely
5790 bogus. In order to compensate for this fact, we check here to see if
5791 optimization is enabled, and if so, we effectively create an empty
5792 location description for the (unknown and unknowable) upper bound.
5793 This should not cause too much trouble for existing (stupid?)
5794 debuggers because they have to deal with empty upper bounds location
5795 descriptions anyway in order to be able to deal with incomplete array
5796 types. Of course an intelligent debugger (GDB?) should be able to
5797 comprehend that a missing upper bound specification in a array type
5798 used for a storage class `auto' local array variable indicates that
5799 the upper bound is both unknown (at compile- time) and unknowable (at
5800 run-time) due to optimization. */
5801 if (!optimize)
5803 bound_loc = mem_loc_descriptor (
5804 eliminate_regs (SAVE_EXPR_RTL (bound),
5805 0, NULL_RTX));
5807 else
5809 bound_loc = NULL;
5811 add_AT_loc (subrange_die, bound_attr, bound_loc);
5812 break;
5814 default:
5815 abort ();
5819 /* Note that the block of subscript information for an array type also
5820 includes information about the element type of type given array type. */
5821 static void
5822 add_subscript_info (type_die, type)
5823 register dw_die_ref type_die;
5824 register tree type;
5826 register unsigned dimension_number;
5827 register tree lower, upper;
5828 register dw_die_ref subrange_die;
5830 /* The GNU compilers represent multidimensional array types as sequences of
5831 one dimensional array types whose element types are themselves array
5832 types. Here we squish that down, so that each multidimensional array
5833 type gets only one array_type DIE in the Dwarf debugging info. The draft
5834 Dwarf specification say that we are allowed to do this kind of
5835 compression in C (because there is no difference between an array or
5836 arrays and a multidimensional array in C) but for other source languages
5837 (e.g. Ada) we probably shouldn't do this. */
5838 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
5839 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
5840 We work around this by disabling this feature. See also
5841 gen_array_type_die. */
5842 #ifndef MIPS_DEBUGGING_INFO
5843 for (dimension_number = 0;
5844 TREE_CODE (type) == ARRAY_TYPE;
5845 type = TREE_TYPE (type), dimension_number++)
5847 #endif
5848 register tree domain = TYPE_DOMAIN (type);
5850 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
5851 and (in GNU C only) variable bounds. Handle all three forms
5852 here. */
5853 subrange_die = new_die (DW_TAG_subrange_type, type_die);
5854 if (domain)
5856 /* We have an array type with specified bounds. */
5857 lower = TYPE_MIN_VALUE (domain);
5858 upper = TYPE_MAX_VALUE (domain);
5860 /* TODO: establish DW_AT_type for the basis type a byte_size
5861 attribute if the byte size is non-standard */
5862 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
5863 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
5865 else
5867 /* We have an array type with an unspecified length. For C and C++
5868 we can assume that this really means that (a) the index type is
5869 an integral type, and (b) the lower bound is zero. Note that
5870 Dwarf defines the representation of an unspecified (upper) bound
5871 as being a zero-length location description. */
5873 /* define the (assumed) index type. */
5874 add_AT_die_ref (subrange_die, DW_AT_type, int_base_type_die);
5876 /* Add the (assumed) lower bound (constant) value. */
5877 add_AT_unsigned (subrange_die, DW_AT_lower_bound, 0);
5879 /* Add the (empty) location description for the upper bound. */
5880 add_AT_loc (subrange_die, DW_AT_upper_bound, NULL);
5882 #ifndef MIPS_DEBUGGING_INFO
5884 #endif
5887 static void
5888 add_byte_size_attribute (die, tree_node)
5889 dw_die_ref die;
5890 register tree tree_node;
5892 register unsigned size;
5894 switch (TREE_CODE (tree_node))
5896 case ERROR_MARK:
5897 size = 0;
5898 break;
5899 case ENUMERAL_TYPE:
5900 case RECORD_TYPE:
5901 case UNION_TYPE:
5902 case QUAL_UNION_TYPE:
5903 size = int_size_in_bytes (tree_node);
5904 break;
5905 case FIELD_DECL:
5906 /* For a data member of a struct or union, the DW_AT_byte_size is
5907 generally given as the number of bytes normally allocated for an
5908 object of the *declared* type of the member itself. This is true
5909 even for bit-fields. */
5910 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
5911 break;
5912 default:
5913 abort ();
5916 /* Note that `size' might be -1 when we get to this point. If it is, that
5917 indicates that the byte size of the entity in question is variable. We
5918 have no good way of expressing this fact in Dwarf at the present time,
5919 so just let the -1 pass on through. */
5921 add_AT_unsigned (die, DW_AT_byte_size, size);
5924 /* For a FIELD_DECL node which represents a bit-field, output an attribute
5925 which specifies the distance in bits from the highest order bit of the
5926 "containing object" for the bit-field to the highest order bit of the
5927 bit-field itself.
5929 For any given bit-field, the "containing object" is a hypothetical object (of
5930 some integral or enum type) within which the given bit-field lives. The
5931 type of this hypothetical "containing object" is always the same as the
5932 declared type of the individual bit-field itself.
5933 The determination of the exact location of the "containing object" for a
5934 bit-field is rather complicated. It's handled by the `field_byte_offset'
5935 function (above).
5937 Note that it is the size (in bytes) of the hypothetical "containing object"
5938 which will be given in the DW_AT_byte_size attribute for this bit-field.
5939 (See `byte_size_attribute' above). */
5940 inline void
5941 add_bit_offset_attribute (die, decl)
5942 register dw_die_ref die;
5943 register tree decl;
5945 register unsigned object_offset_in_bytes = field_byte_offset (decl);
5946 register tree type = DECL_BIT_FIELD_TYPE (decl);
5947 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
5948 register unsigned bitpos_int;
5949 register unsigned highest_order_object_bit_offset;
5950 register unsigned highest_order_field_bit_offset;
5951 register unsigned bit_offset;
5953 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
5954 assert (type); /* Must be a bit field. */
5956 /* We can't yet handle bit-fields whose offsets are variable, so if we
5957 encounter such things, just return without generating any attribute
5958 whatsoever. */
5959 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5961 return;
5963 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5965 /* Note that the bit offset is always the distance (in bits) from the
5966 highest-order bit of the "containing object" to the highest-order bit of
5967 the bit-field itself. Since the "high-order end" of any object or field
5968 is different on big-endian and little-endian machines, the computation
5969 below must take account of these differences. */
5970 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
5971 highest_order_field_bit_offset = bitpos_int;
5973 if (!BYTES_BIG_ENDIAN)
5975 highest_order_field_bit_offset
5976 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
5978 highest_order_object_bit_offset += simple_type_size_in_bits (type);
5980 bit_offset =
5981 (!BYTES_BIG_ENDIAN
5982 ? highest_order_object_bit_offset - highest_order_field_bit_offset
5983 : highest_order_field_bit_offset - highest_order_object_bit_offset);
5985 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
5988 /* For a FIELD_DECL node which represents a bit field, output an attribute
5989 which specifies the length in bits of the given field. */
5990 inline void
5991 add_bit_size_attribute (die, decl)
5992 register dw_die_ref die;
5993 register tree decl;
5995 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
5996 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
5997 add_AT_unsigned (die, DW_AT_bit_size,
5998 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
6001 /* If the compiled language is GNU C, then add a 'prototyped'
6002 attribute, if arg types are given for the parameters of a function. */
6003 inline void
6004 add_prototyped_attribute (die, func_type)
6005 register dw_die_ref die;
6006 register tree func_type;
6008 if ((strcmp (language_string, "GNU C") == 0)
6009 && (TYPE_ARG_TYPES (func_type) != NULL))
6011 add_AT_flag (die, DW_AT_prototyped, 0);
6016 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
6017 by looking in either the type declaration or object declaration
6018 equate table. */
6019 inline void
6020 add_abstract_origin_attribute (die, origin)
6021 register dw_die_ref die;
6022 register tree origin;
6024 dw_die_ref origin_die = NULL;
6025 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
6027 origin_die = lookup_decl_die (origin);
6029 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
6031 origin_die = lookup_type_die (origin);
6033 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
6036 /* We do not currently support the pure_virtual attribute. */
6038 inline void
6039 add_pure_or_virtual_attribute (die, func_decl)
6040 register dw_die_ref die;
6041 register tree func_decl;
6043 if (DECL_VIRTUAL_P (func_decl))
6045 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
6046 add_AT_loc (die, DW_AT_vtable_elem_location, new_loc_descr
6047 (DW_OP_constu, TREE_INT_CST_LOW (DECL_VINDEX (func_decl))));
6051 /********************* utility routines for DIEs *************************/
6053 /* Add an DW_AT_name attribute and source coordinate attribute for the
6054 given decl, but only if it actually has a name. */
6055 static void
6056 add_name_and_src_coords_attributes (die, decl)
6057 register dw_die_ref die;
6058 register tree decl;
6060 register tree decl_name;
6061 register unsigned file_index;
6062 if (TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
6063 decl_name = DECL_ASSEMBLER_NAME (decl);
6064 else
6065 decl_name = DECL_NAME (decl);
6067 if (decl_name && IDENTIFIER_POINTER (decl_name))
6069 add_name_attribute (die, IDENTIFIER_POINTER (decl_name));
6070 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
6071 add_AT_unsigned (die, DW_AT_decl_file, file_index);
6072 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6076 /* Push a new declaration scope. */
6077 static void
6078 push_decl_scope (scope)
6079 tree scope;
6081 /* Make room in the decl_scope_table, if necessary. */
6082 if (decl_scope_table_allocated == decl_scope_depth)
6084 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
6085 decl_scope_table = (tree *) xrealloc (decl_scope_table,
6086 decl_scope_table_allocated * sizeof (tree));
6088 decl_scope_table[decl_scope_depth++] = scope;
6091 /* Return the DIE for the scope the immediately contains this declaration. */
6092 static dw_die_ref
6093 scope_die_for (t, context_die)
6094 register tree t;
6095 register dw_die_ref context_die;
6097 register dw_die_ref scope_die = NULL;
6098 register tree containing_scope;
6099 register unsigned long i;
6101 /* Walk back up the declaration tree looking for a place to define
6102 this type. */
6103 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
6104 containing_scope = TYPE_CONTEXT (t);
6105 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VIRTUAL_P (t))
6106 containing_scope = decl_class_context (t);
6107 else
6108 containing_scope = DECL_CONTEXT (t);
6110 if (containing_scope == NULL)
6112 scope_die = comp_unit_die;
6114 else
6116 for (i = decl_scope_depth, scope_die = context_die;
6117 i > 0 && decl_scope_table[i - 1] != containing_scope;
6118 scope_die = scope_die->die_parent, --i)
6119 /* nothing */ ;
6120 if (i == 0)
6122 assert (scope_die == comp_unit_die);
6123 assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't');
6124 assert (TREE_ASM_WRITTEN (containing_scope));
6127 return scope_die;
6130 /* Pop a declaration scope. */
6131 inline void
6132 pop_decl_scope ()
6134 assert (decl_scope_depth > 0);
6135 --decl_scope_depth;
6138 /* Many forms of DIEs require a "type description" attribute. This
6139 routine locates the proper "type descriptor" die for the type given
6140 by 'type', and adds an DW_AT_type attribute below the given die. */
6141 static void
6142 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
6143 register dw_die_ref object_die;
6144 register tree type;
6145 register int decl_const;
6146 register int decl_volatile;
6147 register dw_die_ref context_die;
6149 register enum tree_code code = TREE_CODE (type);
6150 register dw_die_ref type_die = NULL;
6152 if (code == ERROR_MARK)
6154 return;
6157 /* Handle a special case. For functions whose return type is void, we
6158 generate *no* type attribute. (Note that no object may have type
6159 `void', so this only applies to function return types). */
6160 if (code == VOID_TYPE)
6162 return;
6165 type_die = modified_type_die (type,
6166 decl_const || TYPE_READONLY (type),
6167 decl_volatile || TYPE_VOLATILE (type),
6168 context_die);
6169 if (type_die != NULL)
6171 add_AT_die_ref (object_die, DW_AT_type, type_die);
6175 /* Given a tree pointer to a struct, class, union, or enum type node, return
6176 a pointer to the (string) tag name for the given type, or zero if the type
6177 was declared without a tag. */
6178 static char *
6179 type_tag (type)
6180 register tree type;
6182 register char *name = 0;
6184 if (TYPE_NAME (type) != 0)
6186 register tree t = 0;
6188 /* Find the IDENTIFIER_NODE for the type name. */
6189 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
6190 t = TYPE_NAME (type);
6192 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
6193 a TYPE_DECL node, regardless of whether or not a `typedef' was
6194 involved. */
6195 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
6196 t = DECL_NAME (TYPE_NAME (type));
6198 /* Now get the name as a string, or invent one. */
6199 if (t != 0)
6201 name = IDENTIFIER_POINTER (t);
6204 return (name == 0 || *name == '\0') ? 0 : name;
6207 /* Return the type associated with a data member, make a special check
6208 for bit field types. */
6209 inline tree
6210 member_declared_type (member)
6211 register tree member;
6213 return (DECL_BIT_FIELD_TYPE (member))
6214 ? DECL_BIT_FIELD_TYPE (member)
6215 : TREE_TYPE (member);
6218 /* Get the decl's label, as described by its RTL. This may be different
6219 from the DECL_NAME name used in the source file. */
6220 static char *
6221 decl_start_label (decl)
6222 register tree decl;
6224 rtx x;
6225 char *fnname;
6226 x = DECL_RTL (decl);
6227 if (GET_CODE (x) != MEM)
6229 abort ();
6231 x = XEXP (x, 0);
6232 if (GET_CODE (x) != SYMBOL_REF)
6234 abort ();
6236 fnname = XSTR (x, 0);
6237 return fnname;
6240 /******************************* DIE Generation *************************/
6242 /* These routines generate the internnal representation of the DIE's for
6243 the compilation unit. Debugging information is collected by walking
6244 the declaration trees passed in from dwarfout_file_scope_decl(). */
6246 static void
6247 gen_array_type_die (type, context_die)
6248 register tree type;
6249 register dw_die_ref context_die;
6251 register dw_die_ref scope_die = scope_die_for (type, context_die);
6252 register dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die);
6253 register tree element_type;
6255 #if 0
6256 /* We default the array ordering. SDB will probably do
6257 the right things even if DW_AT_ordering is not present. It's not even
6258 an issue until we start to get into multidimensional arrays anyway. If
6259 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
6260 then we'll have to put the DW_AT_ordering attribute back in. (But if
6261 and when we find out that we need to put these in, we will only do so
6262 for multidimensional arrays. */
6263 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
6264 #endif
6266 add_subscript_info (array_die, type);
6268 equate_type_number_to_die (type, array_die);
6270 /* Add representation of the type of the elements of this array type. */
6271 element_type = TREE_TYPE (type);
6272 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6273 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
6274 We work around this by disabling this feature. See also
6275 add_subscript_info. */
6276 #ifndef MIPS_DEBUGGING_INFO
6277 while (TREE_CODE (element_type) == ARRAY_TYPE)
6279 element_type = TREE_TYPE (element_type);
6281 #endif
6282 gen_type_die (element_type, context_die);
6284 add_type_attribute (array_die, element_type, 0, 0, context_die);
6287 static void
6288 gen_set_type_die (type, context_die)
6289 register tree type;
6290 register dw_die_ref context_die;
6292 register dw_die_ref type_die = new_die
6293 (DW_TAG_set_type, scope_die_for (type, context_die));
6294 equate_type_number_to_die (type, type_die);
6295 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
6298 static void
6299 gen_entry_point_die (decl, context_die)
6300 register tree decl;
6301 register dw_die_ref context_die;
6303 register tree origin = decl_ultimate_origin (decl);
6304 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
6305 if (origin != NULL)
6307 add_abstract_origin_attribute (decl_die, origin);
6309 else
6311 add_name_and_src_coords_attributes (decl_die, decl);
6312 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
6313 0, 0, context_die);
6315 if (DECL_ABSTRACT (decl))
6317 equate_decl_number_to_die (decl, decl_die);
6319 else
6321 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
6325 /* Generate a DIE to represent an inlined instance of an enumeration type. */
6326 static void
6327 gen_inlined_enumeration_type_die (type, context_die)
6328 register tree type;
6329 register dw_die_ref context_die;
6331 register dw_die_ref type_die;
6332 type_die = new_die (DW_TAG_enumeration_type,
6333 scope_die_for (type, context_die));
6334 assert (TREE_ASM_WRITTEN (type));
6335 add_abstract_origin_attribute (type_die, type);
6338 /* Generate a DIE to represent an inlined instance of a structure type. */
6339 static void
6340 gen_inlined_structure_type_die (type, context_die)
6341 register tree type;
6342 register dw_die_ref context_die;
6344 register dw_die_ref type_die;
6345 type_die = new_die (DW_TAG_structure_type,
6346 scope_die_for (type, context_die));
6347 assert (TREE_ASM_WRITTEN (type));
6348 add_abstract_origin_attribute (type_die, type);
6351 /* Generate a DIE to represent an inlined instance of a union type. */
6352 static void
6353 gen_inlined_union_type_die (type, context_die)
6354 register tree type;
6355 register dw_die_ref context_die;
6357 register dw_die_ref type_die;
6358 type_die = new_die (DW_TAG_union_type,
6359 scope_die_for (type, context_die));
6360 assert (TREE_ASM_WRITTEN (type));
6361 add_abstract_origin_attribute (type_die, type);
6364 /* Generate a DIE to represent an enumeration type. Note that these DIEs
6365 include all of the information about the enumeration values also. Each
6366 enumerated type name/value is listed as a child of the enumerated type
6367 DIE. */
6368 static void
6369 gen_enumeration_type_die (type, context_die)
6370 register tree type;
6371 register dw_die_ref context_die;
6373 register dw_die_ref type_die = lookup_type_die (type);
6375 if (type_die == NULL)
6377 type_die = new_die (DW_TAG_enumeration_type,
6378 scope_die_for (type, context_die));
6379 equate_type_number_to_die (type, type_die);
6380 add_name_attribute (type_die, type_tag (type));
6382 else if (! TYPE_SIZE (type))
6383 return;
6384 else
6385 remove_AT (type_die, DW_AT_declaration);
6387 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
6388 given enum type is incomplete, do not generate the DW_AT_byte_size
6389 attribute or the DW_AT_element_list attribute. */
6390 if (TYPE_SIZE (type))
6392 register tree link;
6393 add_byte_size_attribute (type_die, type);
6394 for (link = TYPE_FIELDS (type);
6395 link != NULL; link = TREE_CHAIN (link))
6397 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
6398 add_name_attribute (enum_die,
6399 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
6400 add_AT_unsigned (enum_die, DW_AT_const_value,
6401 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
6404 else
6405 add_AT_flag (type_die, DW_AT_declaration, 1);
6409 /* Generate a DIE to represent either a real live formal parameter decl or to
6410 represent just the type of some formal parameter position in some function
6411 type.
6412 Note that this routine is a bit unusual because its argument may be a
6413 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
6414 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
6415 node. If it's the former then this function is being called to output a
6416 DIE to represent a formal parameter object (or some inlining thereof). If
6417 it's the latter, then this function is only being called to output a
6418 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
6419 argument type of some subprogram type. */
6420 static void
6421 gen_formal_parameter_die (node, context_die)
6422 register tree node;
6423 register dw_die_ref context_die;
6425 register dw_die_ref parm_die = new_die (DW_TAG_formal_parameter,
6426 context_die);
6427 register tree origin;
6428 switch (TREE_CODE_CLASS (TREE_CODE (node)))
6430 /* We were called with some kind of a ..._DECL node. */
6431 case 'd':
6432 origin = decl_ultimate_origin (node);
6433 if (origin != NULL)
6435 add_abstract_origin_attribute (parm_die, origin);
6437 else
6439 add_name_and_src_coords_attributes (parm_die, node);
6440 add_type_attribute (parm_die, TREE_TYPE (node),
6441 TREE_READONLY (node),
6442 TREE_THIS_VOLATILE (node),
6443 context_die);
6444 if (DECL_ARTIFICIAL (node))
6445 add_AT_flag (parm_die, DW_AT_artificial, 1);
6447 if (DECL_ABSTRACT (node))
6449 equate_decl_number_to_die (node, parm_die);
6451 else
6453 add_location_or_const_value_attribute (parm_die, node);
6455 break;
6457 /* We were called with some kind of a ..._TYPE node. */
6458 case 't':
6459 add_type_attribute (parm_die, node, 0, 0, context_die);
6460 break;
6462 /* Should never happen. */
6463 default:
6464 abort ();
6468 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
6469 at the end of an (ANSI prototyped) formal parameters list. */
6470 static void
6471 gen_unspecified_parameters_die (decl_or_type, context_die)
6472 register tree decl_or_type;
6473 register dw_die_ref context_die;
6475 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
6476 context_die);
6477 /* This kludge is here only for the sake of being compatible with what the
6478 USL CI5 C compiler does. The specification of Dwarf Version 1 doesn't
6479 say that DW_TAG_unspecified_parameters DIEs should contain any
6480 attributes other than the DW_AT_sibling attribute, but they are
6481 certainly allowed to contain additional attributes, and the CI5 compiler
6482 generates DW_AT_name, DW_AT_base_type, and DW_AT_location attributes
6483 within DW_TAG_unspecified_parameters DIEs which appear in the child
6484 lists for DIEs representing function definitions, so we do likewise
6485 here. */
6486 if (TREE_CODE (decl_or_type) == FUNCTION_DECL
6487 && DECL_INITIAL (decl_or_type))
6489 add_name_attribute (parm_die, "...");
6490 add_AT_die_ref (parm_die, DW_AT_type, int_base_type_die);
6494 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
6495 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
6496 parameters as specified in some function type specification (except for
6497 those which appear as part of a function *definition*).
6498 Note that we must be careful here to output all of the parameter DIEs before*
6499 we output any DIEs needed to represent the types of the formal parameters.
6500 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
6501 non-parameter DIE it sees ends the formal parameter list. */
6502 static void
6503 gen_formal_types_die (function_or_method_type, context_die)
6504 register tree function_or_method_type;
6505 register dw_die_ref context_die;
6507 register tree link;
6508 register tree formal_type = NULL;
6509 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
6511 #if 0
6512 /* In the case where we are generating a formal types list for a C++
6513 non-static member function type, skip over the first thing on the
6514 TYPE_ARG_TYPES list because it only represents the type of the hidden
6515 `this pointer'. The debugger should be able to figure out (without
6516 being explicitly told) that this non-static member function type takes a
6517 `this pointer' and should be able to figure what the type of that hidden
6518 parameter is from the DW_AT_member attribute of the parent
6519 DW_TAG_subroutine_type DIE. */
6520 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
6521 first_parm_type = TREE_CHAIN (first_parm_type);
6522 #endif
6524 /* Make our first pass over the list of formal parameter types and output a
6525 DW_TAG_formal_parameter DIE for each one. */
6526 for (link = first_parm_type; link; link = TREE_CHAIN (link))
6528 formal_type = TREE_VALUE (link);
6529 if (formal_type == void_type_node)
6530 break;
6532 /* Output a (nameless) DIE to represent the formal parameter itself. */
6533 gen_formal_parameter_die (formal_type, context_die);
6536 /* If this function type has an ellipsis, add a
6537 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
6538 if (formal_type != void_type_node)
6539 gen_unspecified_parameters_die (function_or_method_type, context_die);
6541 /* Make our second (and final) pass over the list of formal parameter types
6542 and output DIEs to represent those types (as necessary). */
6543 for (link = TYPE_ARG_TYPES (function_or_method_type);
6544 link;
6545 link = TREE_CHAIN (link))
6547 formal_type = TREE_VALUE (link);
6548 if (formal_type == void_type_node)
6549 break;
6551 gen_type_die (formal_type, context_die);
6555 /* Generate a DIE to represent a declared function (either file-scope or
6556 block-local). */
6557 static void
6558 gen_subprogram_die (decl, context_die)
6559 register tree decl;
6560 register dw_die_ref context_die;
6562 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
6563 register tree origin = decl_ultimate_origin (decl);
6564 register dw_die_ref subr_die;
6565 register dw_loc_descr_ref fp_loc = NULL;
6566 register unsigned fp_reg;
6567 register tree type;
6568 register tree fn_arg_types;
6569 register tree outer_scope;
6570 register tree label;
6571 dw_die_ref old_die = lookup_decl_die (decl);
6573 if (origin != NULL)
6575 subr_die = new_die (DW_TAG_subprogram, context_die);
6576 add_abstract_origin_attribute (subr_die, origin);
6578 else if (old_die)
6580 register unsigned file_index
6581 = lookup_filename (DECL_SOURCE_FILE (decl));
6582 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
6583 abort ();
6585 /* If the definition comes from the same place as the declaration,
6586 use the old DIE. */
6587 if (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
6588 && (get_AT_unsigned (old_die, DW_AT_decl_line)
6589 == DECL_SOURCE_LINE (decl)))
6591 subr_die = old_die;
6593 /* Clear out the declaration attribute and the parm types. */
6594 remove_AT (subr_die, DW_AT_declaration);
6595 remove_children (subr_die);
6597 else
6599 subr_die = new_die (DW_TAG_subprogram, context_die);
6600 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
6601 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
6602 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
6603 if (get_AT_unsigned (old_die, DW_AT_decl_line)
6604 != DECL_SOURCE_LINE (decl))
6605 add_AT_unsigned
6606 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6609 else
6611 subr_die = new_die (DW_TAG_subprogram,
6612 scope_die_for (decl, context_die));
6613 if (TREE_PUBLIC (decl))
6614 add_AT_flag (subr_die, DW_AT_external, 1);
6615 add_name_and_src_coords_attributes (subr_die, decl);
6616 type = TREE_TYPE (decl);
6617 add_prototyped_attribute (subr_die, type);
6618 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
6619 add_pure_or_virtual_attribute (subr_die, decl);
6620 if (DECL_ARTIFICIAL (decl))
6621 add_AT_flag (subr_die, DW_AT_artificial, 1);
6623 /* The first time we see a member function, it is in the context of
6624 the class to which it belongs. We make sure of this by emitting
6625 the class first. The next time is the definition, which is
6626 handled above. The two may come from the same source text. */
6627 if (! DECL_INITIAL (decl))
6628 add_AT_flag (subr_die, DW_AT_declaration, 1);
6630 if (DECL_ABSTRACT (decl))
6632 if (DECL_DEFER_OUTPUT (decl))
6634 if (DECL_INLINE (decl))
6635 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
6636 else
6637 add_AT_unsigned (subr_die, DW_AT_inline,
6638 DW_INL_declared_not_inlined);
6640 else if (DECL_INLINE (decl))
6641 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
6642 else
6643 abort ();
6645 equate_decl_number_to_die (decl, subr_die);
6647 else if (!DECL_INITIAL (decl))
6648 equate_decl_number_to_die (decl, subr_die);
6649 else if (!DECL_EXTERNAL (decl))
6651 if (origin == NULL)
6652 equate_decl_number_to_die (decl, subr_die);
6653 sprintf (label_id, FUNC_BEGIN_LABEL_FMT, current_funcdef_number);
6654 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
6655 sprintf (label_id, FUNC_END_LABEL_FMT, current_funcdef_number);
6656 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
6658 add_pubname (decl, subr_die);
6659 add_arange (decl, subr_die);
6661 #ifdef MIPS_DEBUGGING_INFO
6663 /* Add a reference to the FDE for this routine. */
6664 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
6665 #endif
6667 /* Define the "frame base" location for this routine. We use the
6668 frame pointer or stack pointer registers, since the RTL for local
6669 variables is relative to one of them. */
6670 fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6671 ? FRAME_POINTER_REGNUM
6672 : STACK_POINTER_REGNUM);
6673 assert (fp_reg >= 0 && fp_reg <= 31);
6674 fp_loc = new_loc_descr (DW_OP_reg0 + fp_reg);
6675 add_AT_loc (subr_die, DW_AT_frame_base, fp_loc);
6677 #ifdef DWARF_GNU_EXTENSIONS
6678 sprintf (label_id, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
6679 add_AT_lbl_id (subr_die, DW_AT_body_begin, label_id);
6680 sprintf (label_id, BODY_END_LABEL_FMT, current_funcdef_number);
6681 add_AT_lbl_id (subr_die, DW_AT_body_end, label_id);
6682 #endif
6686 /* Now output descriptions of the arguments for this function. This gets
6687 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
6688 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
6689 `...' at the end of the formal parameter list. In order to find out if
6690 there was a trailing ellipsis or not, we must instead look at the type
6691 associated with the FUNCTION_DECL. This will be a node of type
6692 FUNCTION_TYPE. If the chain of type nodes hanging off of this
6693 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
6694 an ellipsis at the end. */
6696 push_decl_scope (decl);
6697 /* In the case where we are describing a mere function declaration, all we
6698 need to do here (and all we *can* do here) is to describe the *types* of
6699 its formal parameters. */
6700 if (DECL_INITIAL (decl) == NULL_TREE)
6702 gen_formal_types_die (TREE_TYPE (decl), subr_die);
6704 else
6706 /* Generate DIEs to represent all known formal parameters */
6707 register tree arg_decls = DECL_ARGUMENTS (decl);
6708 register tree parm;
6710 /* When generating DIEs, generate the unspecified_parameters DIE
6711 instead if we come across the arg "__builtin_va_alist" */
6712 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
6714 if (TREE_CODE (parm) == PARM_DECL)
6716 if (DECL_NAME (parm) &&
6717 !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
6718 "__builtin_va_alist"))
6720 gen_unspecified_parameters_die (parm, subr_die);
6722 else
6724 gen_decl_die (parm, subr_die);
6729 /* Decide whether we need a unspecified_parameters DIE at the end.
6730 There are 2 more cases to do this for: 1) the ansi ... declaration -
6731 this is detectable when the end of the arg list is not a
6732 void_type_node 2) an unprototyped function declaration (not a
6733 definition). This just means that we have no info about the
6734 parameters at all. */
6735 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
6736 if (fn_arg_types)
6738 /* this is the prototyped case, check for ... */
6739 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
6741 gen_unspecified_parameters_die (decl, subr_die);
6744 else
6746 /* this is unprotoyped, check for undefined (just declaration) */
6747 if (!DECL_INITIAL (decl))
6749 gen_unspecified_parameters_die (decl, subr_die);
6754 /* Output Dwarf info for all of the stuff within the body of the function
6755 (if it has one - it may be just a declaration). */
6756 outer_scope = DECL_INITIAL (decl);
6758 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
6759 node created to represent a function. This outermost BLOCK actually
6760 represents the outermost binding contour for the function, i.e. the
6761 contour in which the function's formal parameters and labels get
6762 declared. Curiously, it appears that the front end doesn't actually
6763 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
6764 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
6765 list for the function instead.) The BLOCK_VARS list for the
6766 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
6767 the function however, and we output DWARF info for those in
6768 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
6769 node representing the function's outermost pair of curly braces, and
6770 any blocks used for the base and member initializers of a C++
6771 constructor function. */
6772 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
6774 current_function_has_inlines = 0;
6775 decls_for_scope (outer_scope, subr_die, 0);
6776 #if 0 && defined (MIPS_DEBUGGING_INFO)
6777 if (current_function_has_inlines)
6779 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
6780 if (! comp_unit_has_inlines)
6782 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
6783 comp_unit_has_inlines = 1;
6786 #endif
6788 pop_decl_scope ();
6791 /* Generate a DIE to represent a declared data object. */
6792 static void
6793 gen_variable_die (decl, context_die)
6794 register tree decl;
6795 register dw_die_ref context_die;
6797 register tree origin = decl_ultimate_origin (decl);
6798 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
6799 dw_die_ref old_die = lookup_decl_die (decl);
6801 if (origin != NULL)
6803 add_abstract_origin_attribute (var_die, origin);
6805 else if (old_die)
6807 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
6808 abort ();
6809 add_AT_die_ref (var_die, DW_AT_specification, old_die);
6810 if (DECL_NAME (decl))
6812 register unsigned file_index
6813 = lookup_filename (DECL_SOURCE_FILE (decl));
6814 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
6815 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
6816 if (get_AT_unsigned (old_die, DW_AT_decl_line)
6817 != DECL_SOURCE_LINE (decl))
6818 add_AT_unsigned
6819 (var_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6822 else
6824 add_name_and_src_coords_attributes (var_die, decl);
6825 add_type_attribute (var_die, TREE_TYPE (decl),
6826 TREE_READONLY (decl),
6827 TREE_THIS_VOLATILE (decl), context_die);
6828 if (TREE_PUBLIC (decl))
6829 add_AT_flag (var_die, DW_AT_external, 1);
6830 if (DECL_ARTIFICIAL (decl))
6831 add_AT_flag (var_die, DW_AT_artificial, 1);
6833 if (DECL_ABSTRACT (decl))
6835 equate_decl_number_to_die (decl, var_die);
6837 else if (!DECL_EXTERNAL (decl))
6839 if (TREE_STATIC (decl))
6840 equate_decl_number_to_die (decl, var_die);
6841 add_location_or_const_value_attribute (var_die, decl);
6842 add_pubname (decl, var_die);
6844 else if (decl_class_context (decl))
6846 equate_decl_number_to_die (decl, var_die);
6847 add_AT_flag (var_die, DW_AT_declaration, 1);
6851 /* Generate a DIE to represent a label identifier. */
6852 static void
6853 gen_label_die (decl, context_die)
6854 register tree decl;
6855 register dw_die_ref context_die;
6857 register tree origin = decl_ultimate_origin (decl);
6858 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
6859 register rtx insn;
6860 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6861 if (origin != NULL)
6863 add_abstract_origin_attribute (lbl_die, origin);
6865 else
6867 add_name_and_src_coords_attributes (lbl_die, decl);
6869 if (DECL_ABSTRACT (decl))
6871 equate_decl_number_to_die (decl, lbl_die);
6873 else
6875 insn = DECL_RTL (decl);
6876 if (GET_CODE (insn) == CODE_LABEL)
6878 /* When optimization is enabled (via -O) some parts of the compiler
6879 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
6880 represent source-level labels which were explicitly declared by
6881 the user. This really shouldn't be happening though, so catch
6882 it if it ever does happen. */
6883 if (INSN_DELETED_P (insn))
6885 abort (); /* Should never happen. */
6887 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
6888 (unsigned) INSN_UID (insn));
6889 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
6894 /* Generate a DIE for a lexical block. */
6895 static void
6896 gen_lexical_block_die (stmt, context_die, depth)
6897 register tree stmt;
6898 register dw_die_ref context_die;
6899 int depth;
6901 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
6902 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6903 if (!BLOCK_ABSTRACT (stmt))
6905 sprintf (label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
6906 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
6907 sprintf (label, BLOCK_END_LABEL_FMT, next_block_number);
6908 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
6910 push_decl_scope (stmt);
6911 decls_for_scope (stmt, stmt_die, depth);
6912 pop_decl_scope ();
6915 /* Generate a DIE for an inlined subprogram. */
6916 static void
6917 gen_inlined_subroutine_die (stmt, context_die, depth)
6918 register tree stmt;
6919 register dw_die_ref context_die;
6920 int depth;
6922 if (!BLOCK_ABSTRACT (stmt))
6924 register dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine,
6925 context_die);
6926 register tree decl = block_ultimate_origin (stmt);
6927 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6928 add_abstract_origin_attribute (subr_die, decl);
6929 sprintf (label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
6930 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
6931 sprintf (label, BLOCK_END_LABEL_FMT, next_block_number);
6932 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
6933 push_decl_scope (decl);
6934 decls_for_scope (stmt, subr_die, depth);
6935 pop_decl_scope ();
6936 current_function_has_inlines = 1;
6940 /* Generate a DIE for a field in a record, or structure. */
6941 static void
6942 gen_field_die (decl, context_die)
6943 register tree decl;
6944 register dw_die_ref context_die;
6946 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
6947 add_name_and_src_coords_attributes (decl_die, decl);
6948 add_type_attribute (decl_die, member_declared_type (decl),
6949 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
6950 context_die);
6951 /* If this is a bit field... */
6952 if (DECL_BIT_FIELD_TYPE (decl))
6954 add_byte_size_attribute (decl_die, decl);
6955 add_bit_size_attribute (decl_die, decl);
6956 add_bit_offset_attribute (decl_die, decl);
6958 add_data_member_location_attribute (decl_die, decl);
6959 if (DECL_ARTIFICIAL (decl))
6960 add_AT_flag (decl_die, DW_AT_artificial, 1);
6963 #if 0
6964 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
6965 Use modified_type_die instead.
6966 We keep this code here just in case these types of DIEs may be needed to
6967 represent certain things in other languages (e.g. Pascal) someday. */
6968 static void
6969 gen_pointer_type_die (type, context_die)
6970 register tree type;
6971 register dw_die_ref context_die;
6973 register dw_die_ref ptr_die = new_die
6974 (DW_TAG_pointer_type, scope_die_for (type, context_die));
6975 equate_type_number_to_die (type, ptr_die);
6976 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
6977 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6980 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
6981 Use modified_type_die instead.
6982 We keep this code here just in case these types of DIEs may be needed to
6983 represent certain things in other languages (e.g. Pascal) someday. */
6984 static void
6985 gen_reference_type_die (type, context_die)
6986 register tree type;
6987 register dw_die_ref context_die;
6989 register dw_die_ref ref_die = new_die
6990 (DW_TAG_reference_type, scope_die_for (type, context_die));
6991 equate_type_number_to_die (type, ref_die);
6992 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
6993 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6995 #endif
6997 /* Generate a DIE for a pointer to a member type. */
6998 static void
6999 gen_ptr_to_mbr_type_die (type, context_die)
7000 register tree type;
7001 register dw_die_ref context_die;
7003 register dw_die_ref ptr_die = new_die
7004 (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
7005 equate_type_number_to_die (type, ptr_die);
7006 add_AT_die_ref (ptr_die, DW_AT_containing_type,
7007 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
7008 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7011 /* Generate the DIE for the compilation unit. */
7012 static void
7013 gen_compile_unit_die (main_input_filename)
7014 register char *main_input_filename;
7016 char producer[250];
7017 char *wd = getpwd ();
7019 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
7021 add_name_attribute (comp_unit_die, main_input_filename);
7023 if (wd)
7025 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
7028 sprintf (producer, "%s %s", language_string, version_string);
7030 #ifdef MIPS_DEBUGGING_INFO
7031 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
7032 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
7033 not appear in the producer string, the debugger reaches the conclusion
7034 that the object file is stripped and has no debugging information.
7035 To get the MIPS/SGI debugger to believe that there is debugging
7036 information in the object file, we add a -g to the producer string. */
7037 if (write_symbols != NO_DEBUG)
7039 strcat (producer, " -g");
7042 #endif
7044 add_AT_string (comp_unit_die, DW_AT_producer, producer);
7045 if (strcmp (language_string, "GNU C++") == 0)
7047 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
7049 else if (strcmp (language_string, "GNU Ada") == 0)
7051 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
7053 else if (flag_traditional)
7055 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
7057 else
7059 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
7061 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
7063 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
7067 /* Generate a DIE for a string type. */
7068 static void
7069 gen_string_type_die (type, context_die)
7070 register tree type;
7071 register dw_die_ref context_die;
7073 register dw_die_ref type_die = new_die
7074 (DW_TAG_string_type, scope_die_for (type, context_die));
7075 equate_type_number_to_die (type, type_die);
7077 /* Fudge the string length attribute for now. */
7079 /* TODO: add string length info.
7080 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
7081 bound_representation (upper_bound, 0, 'u'); */
7084 /* Generate the DIE for a base class. */
7085 static void
7086 gen_inheritance_die (binfo, context_die)
7087 register tree binfo;
7088 register dw_die_ref context_die;
7090 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
7091 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
7092 add_data_member_location_attribute (die, binfo);
7093 if (TREE_VIA_VIRTUAL (binfo))
7094 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7095 if (TREE_VIA_PUBLIC (binfo))
7096 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
7097 else if (TREE_VIA_PROTECTED (binfo))
7098 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
7101 /* Genearate a DIE for a class member. */
7102 static void
7103 gen_member_die (type, context_die)
7104 register tree type;
7105 register dw_die_ref context_die;
7107 register tree member;
7108 /* If this is not an incomplete type, output descriptions of each of its
7109 members. Note that as we output the DIEs necessary to represent the
7110 members of this record or union type, we will also be trying to output
7111 DIEs to represent the *types* of those members. However the `type'
7112 function (above) will specifically avoid generating type DIEs for member
7113 types *within* the list of member DIEs for this (containing) type execpt
7114 for those types (of members) which are explicitly marked as also being
7115 members of this (containing) type themselves. The g++ front- end can
7116 force any given type to be treated as a member of some other
7117 (containing) type by setting the TYPE_CONTEXT of the given (member) type
7118 to point to the TREE node representing the appropriate (containing)
7119 type. */
7121 /* First output info about the base classes. */
7122 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
7124 register tree bases = TYPE_BINFO_BASETYPES (type);
7125 register int n_bases = TREE_VEC_LENGTH (bases);
7126 register int i;
7128 for (i = 0; i < n_bases; i++)
7129 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
7132 /* Now output info about the data members and type members. */
7133 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
7134 gen_decl_die (member, context_die);
7136 /* Now output info about the function members (if any). */
7137 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
7138 gen_decl_die (member, context_die);
7141 /* Generate a DIE for a structure or union type. */
7142 static void
7143 gen_struct_or_union_type_die (type, context_die)
7144 register tree type;
7145 register dw_die_ref context_die;
7147 register dw_die_ref type_die = lookup_type_die (type);
7149 if (type_die && ! TYPE_SIZE (type))
7150 return;
7151 else if (! type_die
7152 || (TYPE_CONTEXT (type)
7153 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'))
7154 /* First occurrence of type or toplevel definition of nested class. */
7156 register dw_die_ref old_die = type_die;
7157 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
7158 ? DW_TAG_structure_type : DW_TAG_union_type,
7159 scope_die_for (type, context_die));
7160 equate_type_number_to_die (type, type_die);
7161 add_name_attribute (type_die, type_tag (type));
7162 if (old_die)
7163 add_AT_die_ref (type_die, DW_AT_specification, old_die);
7165 else
7166 remove_AT (type_die, DW_AT_declaration);
7168 /* If this type has been completed, then give it a byte_size attribute and
7169 then give a list of members. */
7170 if (TYPE_SIZE (type))
7172 /* Prevent infinite recursion in cases where the type of some member of
7173 this type is expressed in terms of this type itself. */
7174 TREE_ASM_WRITTEN (type) = 1;
7175 add_byte_size_attribute (type_die, type);
7176 push_decl_scope (type);
7177 gen_member_die (type, type_die);
7178 pop_decl_scope ();
7180 else
7181 add_AT_flag (type_die, DW_AT_declaration, 1);
7184 /* Generate a DIE for a subroutine _type_. */
7185 static void
7186 gen_subroutine_type_die (type, context_die)
7187 register tree type;
7188 register dw_die_ref context_die;
7190 register tree return_type = TREE_TYPE (type);
7191 register dw_die_ref subr_die = new_die
7192 (DW_TAG_subroutine_type, scope_die_for (type, context_die));
7193 equate_type_number_to_die (type, subr_die);
7194 add_prototyped_attribute (subr_die, type);
7195 add_type_attribute (subr_die, return_type, 0, 0, context_die);
7196 gen_formal_types_die (type, context_die);
7199 /* Generate a DIE for a type definition */
7200 static void
7201 gen_typedef_die (decl, context_die)
7202 register tree decl;
7203 register dw_die_ref context_die;
7205 register tree origin = decl_ultimate_origin (decl);
7206 register dw_die_ref type_die;
7207 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
7208 if (origin != NULL)
7210 add_abstract_origin_attribute (type_die, origin);
7212 else
7214 add_name_and_src_coords_attributes (type_die, decl);
7215 add_type_attribute (type_die, TREE_TYPE (decl),
7216 TREE_READONLY (decl),
7217 TREE_THIS_VOLATILE (decl),
7218 context_die);
7220 if (DECL_ABSTRACT (decl))
7222 equate_decl_number_to_die (decl, type_die);
7226 /* Generate a type description DIE. */
7227 static void
7228 gen_type_die (type, context_die)
7229 register tree type;
7230 register dw_die_ref context_die;
7232 if (type == 0 || type == error_mark_node)
7234 return;
7237 /* We are going to output a DIE to represent the unqualified version of of
7238 this type (i.e. without any const or volatile qualifiers) so get the
7239 main variant (i.e. the unqualified version) of this type now. */
7240 type = type_main_variant (type);
7242 if (TREE_ASM_WRITTEN (type))
7244 return;
7247 switch (TREE_CODE (type))
7249 case ERROR_MARK:
7250 break;
7252 case POINTER_TYPE:
7253 case REFERENCE_TYPE:
7254 /* For these types, all that is required is that we output a DIE (or a
7255 set of DIEs) to represent the "basis" type. */
7256 gen_type_die (TREE_TYPE (type), context_die);
7257 break;
7259 case OFFSET_TYPE:
7260 /* This code is used for C++ pointer-to-data-member types. */
7261 /* Output a description of the relevant class type. */
7262 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
7263 /* Output a description of the type of the object pointed to. */
7264 gen_type_die (TREE_TYPE (type), context_die);
7265 /* Now output a DIE to represent this pointer-to-data-member type
7266 itself. */
7267 gen_ptr_to_mbr_type_die (type, context_die);
7268 break;
7270 case SET_TYPE:
7271 gen_type_die (TYPE_DOMAIN (type), context_die);
7272 gen_set_type_die (type, context_die);
7273 break;
7275 case FILE_TYPE:
7276 gen_type_die (TREE_TYPE (type), context_die);
7277 abort (); /* No way to represent these in Dwarf yet! */
7278 break;
7280 case FUNCTION_TYPE:
7281 /* Force out return type (in case it wasn't forced out already). */
7282 gen_type_die (TREE_TYPE (type), context_die);
7283 gen_subroutine_type_die (type, context_die);
7284 break;
7286 case METHOD_TYPE:
7287 /* Force out return type (in case it wasn't forced out already). */
7288 gen_type_die (TREE_TYPE (type), context_die);
7289 gen_subroutine_type_die (type, context_die);
7290 break;
7292 case ARRAY_TYPE:
7293 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
7295 gen_type_die (TREE_TYPE (type), context_die);
7296 gen_string_type_die (type, context_die);
7298 else
7300 gen_array_type_die (type, context_die);
7302 break;
7304 case ENUMERAL_TYPE:
7305 case RECORD_TYPE:
7306 case UNION_TYPE:
7307 case QUAL_UNION_TYPE:
7308 if (TREE_CODE (type) == ENUMERAL_TYPE)
7309 gen_enumeration_type_die (type, context_die);
7310 else
7311 gen_struct_or_union_type_die (type, context_die);
7313 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
7314 it up if it is ever completed. */
7315 if (TYPE_SIZE (type) == NULL_TREE)
7316 return;
7317 break;
7319 case VOID_TYPE:
7320 case INTEGER_TYPE:
7321 case REAL_TYPE:
7322 case COMPLEX_TYPE:
7323 case BOOLEAN_TYPE:
7324 case CHAR_TYPE:
7325 /* No DIEs needed for fundamental types. */
7326 break;
7328 case LANG_TYPE:
7329 /* No Dwarf representation currently defined. */
7330 break;
7332 default:
7333 abort ();
7336 TREE_ASM_WRITTEN (type) = 1;
7339 /* Generate a DIE for a tagged type instantiation. */
7340 static void
7341 gen_tagged_type_instantiation_die (type, context_die)
7342 register tree type;
7343 register dw_die_ref context_die;
7345 if (type == 0 || type == error_mark_node)
7347 return;
7350 /* We are going to output a DIE to represent the unqualified version of of
7351 this type (i.e. without any const or volatile qualifiers) so make sure
7352 that we have the main variant (i.e. the unqualified version) of this
7353 type now. */
7354 assert (type == type_main_variant (type));
7355 assert (TREE_ASM_WRITTEN (type));
7357 switch (TREE_CODE (type))
7359 case ERROR_MARK:
7360 break;
7362 case ENUMERAL_TYPE:
7363 gen_inlined_enumeration_type_die (type, context_die);
7364 break;
7366 case RECORD_TYPE:
7367 gen_inlined_structure_type_die (type, context_die);
7368 break;
7370 case UNION_TYPE:
7371 case QUAL_UNION_TYPE:
7372 gen_inlined_union_type_die (type, context_die);
7373 break;
7375 default:
7376 abort (); /* Should never happen. */
7380 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
7381 things which are local to the given block. */
7382 static void
7383 gen_block_die (stmt, context_die, depth)
7384 register tree stmt;
7385 register dw_die_ref context_die;
7386 int depth;
7388 register int must_output_die = 0;
7389 register tree origin;
7390 register tree decl;
7391 register enum tree_code origin_code;
7393 /* Ignore blocks never really used to make RTL. */
7395 if (!stmt || !TREE_USED (stmt))
7397 return;
7400 /* Determine the "ultimate origin" of this block. This block may be an
7401 inlined instance of an inlined instance of inline function, so we have
7402 to trace all of the way back through the origin chain to find out what
7403 sort of node actually served as the original seed for the creation of
7404 the current block. */
7405 origin = block_ultimate_origin (stmt);
7406 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
7408 /* Determine if we need to output any Dwarf DIEs at all to represent this
7409 block. */
7410 if (origin_code == FUNCTION_DECL)
7412 /* The outer scopes for inlinings *must* always be represented. We
7413 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
7414 must_output_die = 1;
7416 else
7418 /* In the case where the current block represents an inlining of the
7419 "body block" of an inline function, we must *NOT* output any DIE for
7420 this block because we have already output a DIE to represent the
7421 whole inlined function scope and the "body block" of any function
7422 doesn't really represent a different scope according to ANSI C
7423 rules. So we check here to make sure that this block does not
7424 represent a "body block inlining" before trying to set the
7425 `must_output_die' flag. */
7426 if (! is_body_block (origin ? origin : stmt))
7428 /* Determine if this block directly contains any "significant"
7429 local declarations which we will need to output DIEs for. */
7430 if (debug_info_level > DINFO_LEVEL_TERSE)
7432 /* We are not in terse mode so *any* local declaration counts
7433 as being a "significant" one. */
7434 must_output_die = (BLOCK_VARS (stmt) != NULL);
7436 else
7438 /* We are in terse mode, so only local (nested) function
7439 definitions count as "significant" local declarations. */
7440 for (decl = BLOCK_VARS (stmt);
7441 decl != NULL; decl = TREE_CHAIN (decl))
7443 if (TREE_CODE (decl) == FUNCTION_DECL
7444 && DECL_INITIAL (decl))
7446 must_output_die = 1;
7447 break;
7454 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
7455 DIE for any block which contains no significant local declarations at
7456 all. Rather, in such cases we just call `decls_for_scope' so that any
7457 needed Dwarf info for any sub-blocks will get properly generated. Note
7458 that in terse mode, our definition of what constitutes a "significant"
7459 local declaration gets restricted to include only inlined function
7460 instances and local (nested) function definitions. */
7461 if (must_output_die)
7463 if (origin_code == FUNCTION_DECL)
7465 gen_inlined_subroutine_die (stmt, context_die, depth);
7467 else
7469 gen_lexical_block_die (stmt, context_die, depth);
7472 else
7473 decls_for_scope (stmt, context_die, depth);
7476 /* Generate all of the decls declared within a given scope and (recursively)
7477 all of it's sub-blocks. */
7478 static void
7479 decls_for_scope (stmt, context_die, depth)
7480 register tree stmt;
7481 register dw_die_ref context_die;
7482 int depth;
7484 register tree decl;
7485 register tree subblocks;
7486 /* Ignore blocks never really used to make RTL. */
7487 if (!stmt || !TREE_USED (stmt))
7489 return;
7491 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
7493 next_block_number++;
7496 /* Output the DIEs to represent all of the data objects, functions,
7497 typedefs, and tagged types declared directly within this block but not
7498 within any nested sub-blocks. */
7499 for (decl = BLOCK_VARS (stmt);
7500 decl != NULL; decl = TREE_CHAIN (decl))
7502 gen_decl_die (decl, context_die);
7505 /* Output the DIEs to represent all sub-blocks (and the items declared
7506 therein) of this block. */
7507 for (subblocks = BLOCK_SUBBLOCKS (stmt);
7508 subblocks != NULL;
7509 subblocks = BLOCK_CHAIN (subblocks))
7511 gen_block_die (subblocks, context_die, depth + 1);
7515 /* Generate Dwarf debug information for a decl described by DECL. */
7516 static void
7517 gen_decl_die (decl, context_die)
7518 register tree decl;
7519 register dw_die_ref context_die;
7521 register tree origin;
7522 /* Make a note of the decl node we are going to be working on. We may need
7523 to give the user the source coordinates of where it appeared in case we
7524 notice (later on) that something about it looks screwy. */
7525 dwarf_last_decl = decl;
7527 if (TREE_CODE (decl) == ERROR_MARK)
7529 return;
7532 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
7533 ignore a function definition, since that would screw up our count of
7534 blocks, and that it turn will completely screw up the the labels we will
7535 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7536 subsequent blocks). */
7537 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
7539 return;
7542 switch (TREE_CODE (decl))
7544 case CONST_DECL:
7545 /* The individual enumerators of an enum type get output when we output
7546 the Dwarf representation of the relevant enum type itself. */
7547 break;
7549 case FUNCTION_DECL:
7550 /* If we are in terse mode, don't output any DIEs to represent mere
7551 function declarations, unless they are class members. */
7552 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE)
7554 break;
7557 /* Before we describe the FUNCTION_DECL itself, make sure that we have
7558 described its return type. */
7559 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
7561 /* Now output a DIE to represent the function itself. */
7562 gen_subprogram_die (decl, context_die);
7563 break;
7565 case TYPE_DECL:
7566 /* If we are in terse mode, don't generate any DIEs to represent any
7567 actual typedefs. Note that even when we are in terse mode, we must
7568 still output DIEs to represent those tagged types which are used
7569 (directly or indirectly) in the specification of either a return
7570 type or a formal parameter type of some function. */
7571 if (debug_info_level <= DINFO_LEVEL_TERSE)
7573 if ((DECL_NAME (decl) != NULL
7574 || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
7575 && ! DECL_ARTIFICIAL (decl))
7577 break;
7581 /* In the special case of a null-named TYPE_DECL node (representing the
7582 declaration of some type tag), if the given TYPE_DECL is marked as
7583 having been instantiated from some other (original) TYPE_DECL node
7584 (e.g. one which was generated within the original definition of an
7585 inline function) we have to generate a special (abbreviated)
7586 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type
7587 DIE here. */
7588 if (!DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl))
7590 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
7591 break;
7593 gen_type_die (TREE_TYPE (decl), context_die);
7595 /* Note that unlike the gcc front end (which generates a NULL named
7596 TYPE_DECL node for each complete tagged type, each array type, and
7597 each function type node created) the g++ front end generates a
7598 _named_ TYPE_DECL node for each tagged type node created.
7599 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
7600 generate a DW_TAG_typedef DIE for them. */
7601 if (DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
7603 /* Output a DIE to represent the typedef itself. */
7604 gen_typedef_die (decl, context_die);
7606 break;
7608 case LABEL_DECL:
7609 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7611 gen_label_die (decl, context_die);
7613 break;
7615 case VAR_DECL:
7616 /* If we are in terse mode, don't generate any DIEs to represent any
7617 variable declarations or definitions. */
7618 if (debug_info_level <= DINFO_LEVEL_TERSE)
7620 break;
7623 /* Output any DIEs that are needed to specify the type of this data
7624 object. */
7625 gen_type_die (TREE_TYPE (decl), context_die);
7627 /* Now output the DIE to represent the data object itself. This gets
7628 complicated because of the possibility that the VAR_DECL really
7629 represents an inlined instance of a formal parameter for an inline
7630 function. */
7631 origin = decl_ultimate_origin (decl);
7632 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
7634 gen_formal_parameter_die (decl, context_die);
7636 else
7638 gen_variable_die (decl, context_die);
7640 break;
7642 case FIELD_DECL:
7643 /* Ignore the nameless fields that are used to skip bits. */
7644 if (DECL_NAME (decl) != 0)
7646 gen_type_die (member_declared_type (decl), context_die);
7647 gen_field_die (decl, context_die);
7649 break;
7651 case PARM_DECL:
7652 gen_type_die (TREE_TYPE (decl), context_die);
7653 gen_formal_parameter_die (decl, context_die);
7654 break;
7656 default:
7657 abort ();
7661 /***************** Debug Information Generation Hooks ***********************/
7662 void
7663 dwarfout_file_scope_decl (decl, set_finalizing)
7664 register tree decl;
7665 register int set_finalizing;
7667 if (TREE_CODE (decl) == ERROR_MARK)
7669 return;
7672 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
7673 hope that the node in question doesn't represent a function definition.
7674 If it does, then totally ignoring it is bound to screw up our count of
7675 blocks, and that it turn will completely screw up the the labels we will
7676 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7677 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
7678 own sequence numbers with them!) */
7679 if (DECL_IGNORED_P (decl))
7681 if (TREE_CODE (decl) == FUNCTION_DECL
7682 && DECL_INITIAL (decl) != NULL)
7684 abort ();
7686 return;
7689 switch (TREE_CODE (decl))
7691 case FUNCTION_DECL:
7692 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
7693 builtin function. Explicit programmer-supplied declarations of
7694 these same functions should NOT be ignored however. */
7695 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
7697 return;
7700 /* What we would really like to do here is to filter out all mere
7701 file-scope declarations of file-scope functions which are never
7702 referenced later within this translation unit (and keep all of ones
7703 that *are* referenced later on) but we aren't clarvoiant, so we have
7704 no idea which functions will be referenced in the future (i.e. later
7705 on within the current translation unit). So here we just ignore all
7706 file-scope function declarations which are not also definitions. If
7707 and when the debugger needs to know something about these funcstion,
7708 it wil have to hunt around and find the DWARF information associated
7709 with the definition of the function. Note that we can't just check
7710 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
7711 definitions and which ones represent mere declarations. We have to
7712 check `DECL_INITIAL' instead. That's because the C front-end
7713 supports some weird semantics for "extern inline" function
7714 definitions. These can get inlined within the current translation
7715 unit (an thus, we need to generate DWARF info for their abstract
7716 instances so that the DWARF info for the concrete inlined instances
7717 can have something to refer to) but the compiler never generates any
7718 out-of-lines instances of such things (despite the fact that they
7719 *are* definitions). The important point is that the C front-end
7720 marks these "extern inline" functions as DECL_EXTERNAL, but we need
7721 to generate DWARF for them anyway. Note that the C++ front-end also
7722 plays some similar games for inline function definitions appearing
7723 within include files which also contain
7724 `#pragma interface' pragmas. */
7725 if (DECL_INITIAL (decl) == NULL_TREE)
7727 return;
7729 break;
7731 case VAR_DECL:
7732 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
7733 declaration and if the declaration was never even referenced from
7734 within this entire compilation unit. We suppress these DIEs in
7735 order to save space in the .debug section (by eliminating entries
7736 which are probably useless). Note that we must not suppress
7737 block-local extern declarations (whether used or not) because that
7738 would screw-up the debugger's name lookup mechanism and cause it to
7739 miss things which really ought to be in scope at a given point. */
7740 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
7742 return;
7745 /* If we are in terse mode, don't generate any DIEs to represent any
7746 variable declarations or definitions. */
7747 if (debug_info_level <= DINFO_LEVEL_TERSE)
7749 return;
7751 break;
7753 case TYPE_DECL:
7754 /* Don't bother trying to generate any DIEs to represent any of the
7755 normal built-in types for the language we are compiling, except in
7756 cases where the types in question are *not* DWARF fundamental types.
7757 We make an exception in the case of non-fundamental types for the
7758 sake of objective C (and perhaps C++) because the GNU front-ends for
7759 these languages may in fact create certain "built-in" types which
7760 are (for example) RECORD_TYPEs. In such cases, we really need to
7761 output these (non-fundamental) types because other DIEs may contain
7762 references to them. */
7763 if (DECL_SOURCE_LINE (decl) == 0
7764 && is_base_type (TREE_TYPE (decl)))
7766 return;
7769 /* If we are in terse mode, don't generate any DIEs to represent any
7770 actual typedefs. Note that even when we are in terse mode, we must
7771 still output DIEs to represent those tagged types which are used
7772 (directly or indirectly) in the specification of either a return
7773 type or a formal parameter type of some function. */
7774 if (debug_info_level <= DINFO_LEVEL_TERSE)
7776 if ((DECL_NAME (decl) != NULL
7777 || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
7778 && ! DECL_ARTIFICIAL (decl))
7780 return;
7783 break;
7785 default:
7786 return;
7789 gen_decl_die (decl, comp_unit_die);
7791 if (TREE_CODE (decl) == FUNCTION_DECL
7792 && DECL_INITIAL (decl) != NULL)
7794 current_funcdef_number++;
7799 /* Output a marker (i.e. a label) for the beginning of the generated code for
7800 a lexical block. */
7801 void
7802 dwarfout_begin_block (blocknum)
7803 register unsigned blocknum;
7805 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7807 function_section (current_function_decl);
7808 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
7809 ASM_OUTPUT_LABEL (asm_out_file, label);
7812 /* Output a marker (i.e. a label) for the end of the generated code for a
7813 lexical block. */
7814 void
7815 dwarfout_end_block (blocknum)
7816 register unsigned blocknum;
7818 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7820 function_section (current_function_decl);
7821 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
7822 ASM_OUTPUT_LABEL (asm_out_file, label);
7825 /* Output a marker (i.e. a label) at a point in the assembly code which
7826 corresponds to a given source level label. */
7827 void
7828 dwarfout_label (insn)
7829 register rtx insn;
7831 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7832 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7834 function_section (current_function_decl);
7835 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
7836 (unsigned) INSN_UID (insn));
7837 ASM_OUTPUT_LABEL (asm_out_file, label);
7841 /* Output a marker (i.e. a label) for the beginning of a function, before
7842 the prologue. */
7843 void
7844 dwarfout_begin_prologue ()
7846 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7847 register dw_fde_ref fde;
7848 register dw_cfi_ref cfi;
7850 function_section (current_function_decl);
7851 sprintf (label, FUNC_BEGIN_LABEL_FMT, current_funcdef_number);
7852 ASM_OUTPUT_LABEL (asm_out_file, label);
7854 /* Expand the fde table if necessary. */
7855 if (fde_table_in_use == fde_table_allocated)
7857 fde_table_allocated += FDE_TABLE_INCREMENT;
7858 fde_table = (dw_fde_ref) xrealloc (fde_table,
7859 fde_table_allocated * sizeof (dw_fde_node));
7862 /* Record the FDE associated with this function. */
7863 current_funcdef_fde = fde_table_in_use;
7865 /* Add the new FDE at the end of the fde_table. */
7866 fde = &fde_table[fde_table_in_use++];
7867 fde->dw_fde_begin = xstrdup (label);
7868 fde->dw_fde_end_prolog = NULL;
7869 fde->dw_fde_begin_epilogue = NULL;
7870 fde->dw_fde_end = NULL;
7871 fde->dw_fde_cfi = NULL;
7874 /* Output a marker (i.e. a label) for the point in the generated code where
7875 the real body of the function begins (after parameters have been moved to
7876 their home locations). */
7877 void
7878 dwarfout_begin_function ()
7880 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7881 register long int offset;
7882 register dw_fde_ref fde;
7883 register dw_cfi_ref cfi;
7885 function_section (current_function_decl);
7886 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
7887 ASM_OUTPUT_LABEL (asm_out_file, label);
7889 /* Record the end-of-prolog location in the FDE. */
7890 fde = &fde_table[fde_table_in_use - 1];
7891 fde->dw_fde_end_prolog = xstrdup (label);
7893 #ifdef MIPS_DEBUGGING_INFO
7895 /* On entry, the Call Frame Address is in the stack pointer register. */
7896 cfi = new_cfi ();
7897 cfi->dw_cfi_opc = DW_CFA_def_cfa;
7898 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
7899 = DBX_REGISTER_NUMBER (STACK_POINTER_REGNUM);
7900 cfi->dw_cfi_oprnd2.dw_cfi_offset = 0;
7901 add_cfi (&fde->dw_fde_cfi, cfi);
7903 /* Set the location counter to the end of the function prolog. */
7904 cfi = new_cfi ();
7905 cfi->dw_cfi_opc = DW_CFA_advance_loc4;
7906 cfi->dw_cfi_oprnd1.dw_cfi_addr = xstrdup (label);
7907 add_cfi (&fde->dw_fde_cfi, cfi);
7909 /* Define the CFA as either an explicit frame pointer register,
7910 or an offset from the stack pointer. */
7911 cfi = new_cfi ();
7912 cfi->dw_cfi_opc = DW_CFA_def_cfa;
7913 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
7914 = DBX_REGISTER_NUMBER (frame_pointer_needed ? FRAME_POINTER_REGNUM
7915 : STACK_POINTER_REGNUM);
7916 offset = current_frame_info.total_size;
7917 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7918 add_cfi (&fde->dw_fde_cfi, cfi);
7920 /* record the frame size for later definition of the DW_AT_frame_base
7921 attribute. */
7922 current_funcdef_frame_size = offset;
7924 /* Define the rule for restoring the stack pointer. */
7925 if (frame_pointer_needed)
7927 /* Restore the stack register from the frame pointer. */
7928 cfi = new_cfi ();
7929 cfi->dw_cfi_opc = DW_CFA_register;
7930 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
7931 = DBX_REGISTER_NUMBER (STACK_POINTER_REGNUM);
7932 cfi->dw_cfi_oprnd2.dw_cfi_reg_num
7933 = DBX_REGISTER_NUMBER (FRAME_POINTER_REGNUM);
7934 add_cfi (&fde->dw_fde_cfi, cfi);
7937 /* If RA is saved on the stack, define it here. */
7938 if (regs_ever_live[31])
7940 offset = current_frame_info.gp_save_offset / DWARF_CIE_DATA_ALIGNMENT;
7941 assert (offset >= 0);
7942 cfi = new_cfi ();
7943 cfi->dw_cfi_opc = DW_CFA_offset_extended;
7944 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DW_FRAME_RA_COL;
7945 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7946 add_cfi (&fde->dw_fde_cfi, cfi);
7949 /* If FP is saved on the stack, define it here. */
7950 if (current_frame_info.mask & (1 << 30))
7952 offset = (current_frame_info.gp_save_offset
7953 - (((current_frame_info.mask >> 31) & 1) * UNITS_PER_WORD))
7954 / DWARF_CIE_DATA_ALIGNMENT;
7955 assert (offset >= 0);
7956 cfi = new_cfi ();
7957 cfi->dw_cfi_opc = DW_CFA_offset;
7958 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
7959 = DBX_REGISTER_NUMBER (FRAME_POINTER_REGNUM);
7960 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7961 add_cfi (&fde->dw_fde_cfi, cfi);
7964 #endif
7968 /* Output a marker (i.e. a label) for the point in the generated code where
7969 the real body of the function ends (just before the epilogue code). */
7970 void
7971 dwarfout_end_function ()
7973 dw_fde_ref fde;
7974 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7975 function_section (current_function_decl);
7976 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
7977 ASM_OUTPUT_LABEL (asm_out_file, label);
7978 /* Record the ending code location in the FDE. */
7979 fde = &fde_table[fde_table_in_use - 1];
7980 fde->dw_fde_begin_epilogue = xstrdup(label);
7983 /* Output a marker (i.e. a label) for the absolute end of the generated code
7984 for a function definition. This gets called *after* the epilogue code has
7985 been generated. */
7986 void
7987 dwarfout_end_epilogue ()
7989 dw_fde_ref fde;
7990 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7991 /* Output a label to mark the endpoint of the code generated for this
7992 function. */
7993 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
7994 ASM_OUTPUT_LABEL (asm_out_file, label);
7995 fde = &fde_table[fde_table_in_use - 1];
7996 fde->dw_fde_end = xstrdup (label);
7999 /* Lookup a filename (in the list of filenames that we know about here in
8000 dwarfout.c) and return its "index". The index of each (known) filename is
8001 just a unique number which is associated with only that one filename.
8002 We need such numbers for the sake of generating labels
8003 (in the .debug_sfnames section) and references to those
8004 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
8005 If the filename given as an argument is not found in our current list,
8006 add it to the list and assign it the next available unique index number.
8007 In order to speed up searches, we remember the index of the filename
8008 was looked up last. This handles the majority of all searches. */
8009 static unsigned
8010 lookup_filename (file_name)
8011 char *file_name;
8013 static unsigned last_file_lookup_index = 0;
8014 register char *fn;
8015 register unsigned i;
8017 /* Check to see if the file name that was searched on the previous call
8018 matches this file name. If so, return the index. */
8019 if (last_file_lookup_index != 0)
8021 fn = file_table[last_file_lookup_index];
8022 if (strcmp (file_name, fn) == 0)
8024 return last_file_lookup_index;
8028 /* Didn't match the previous lookup, search the table */
8029 for (i = 1; i < file_table_in_use; ++i)
8031 fn = file_table[i];
8032 if (strcmp (file_name, fn) == 0)
8034 last_file_lookup_index = i;
8035 return i;
8039 /* Prepare to add a new table entry by making sure there is enough space in
8040 the table to do so. If not, expand the current table. */
8041 if (file_table_in_use == file_table_allocated)
8043 file_table_allocated += FILE_TABLE_INCREMENT;
8044 file_table
8045 = (char **)
8046 xrealloc (file_table, file_table_allocated * sizeof (char *));
8049 /* add the new entry to the end of the filename table. */
8050 file_table[file_table_in_use] = xstrdup (file_name);
8051 last_file_lookup_index = file_table_in_use++;
8052 return last_file_lookup_index;
8055 /* Output a label to mark the beginning of a source code line entry
8056 and record information relating to this source line, in
8057 'line_info_table' for later output of the .debug_line section. */
8058 void
8059 dwarfout_line (filename, line)
8060 register char *filename;
8061 register unsigned line;
8063 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8064 register unsigned this_file_entry_num = lookup_filename (filename);
8065 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8067 function_section (current_function_decl);
8069 if (DECL_SECTION_NAME (current_function_decl))
8071 register dw_separate_line_info_ref line_info;
8072 sprintf (label, SEPARATE_LINE_CODE_LABEL_FMT,
8073 separate_line_info_table_in_use);
8074 ASM_OUTPUT_LABEL (asm_out_file, label);
8075 fputc ('\n', asm_out_file);
8077 /* expand the line info table if necessary */
8078 if (separate_line_info_table_in_use
8079 == separate_line_info_table_allocated)
8081 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8082 separate_line_info_table
8083 = (dw_separate_line_info_ref) xrealloc
8084 (separate_line_info_table,
8085 separate_line_info_table_allocated
8086 * sizeof (dw_separate_line_info_entry));
8088 /* add the new entry at the end of the line_info_table. */
8089 line_info
8090 = &separate_line_info_table[separate_line_info_table_in_use++];
8091 line_info->dw_file_num = lookup_filename (filename);
8092 line_info->dw_line_num = line;
8093 line_info->function = current_funcdef_number;
8095 else
8097 register dw_line_info_ref line_info;
8098 sprintf (label, LINE_CODE_LABEL_FMT, line_info_table_in_use);
8099 ASM_OUTPUT_LABEL (asm_out_file, label);
8100 fputc ('\n', asm_out_file);
8102 /* expand the line info table if necessary */
8103 if (line_info_table_in_use == line_info_table_allocated)
8105 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8106 line_info_table
8107 = (dw_line_info_ref) xrealloc
8108 (line_info_table,
8109 line_info_table_allocated * sizeof (dw_line_info_entry));
8111 /* add the new entry at the end of the line_info_table. */
8112 line_info = &line_info_table[line_info_table_in_use++];
8113 line_info->dw_file_num = lookup_filename (filename);
8114 line_info->dw_line_num = line;
8119 /* Record the beginning of a new source file, for later output
8120 of the .debug_macinfo section. At present, unimplemented. */
8121 void
8122 dwarfout_start_new_source_file (filename)
8123 register char *filename;
8127 /* Record the resumption of a source file, for later output
8128 of the .debug_macinfo section. At present, unimplemented. */
8129 void
8130 dwarfout_resume_previous_source_file (lineno)
8131 register unsigned lineno;
8135 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8136 the tail part of the directive line, i.e. the part which is past the
8137 initial whitespace, #, whitespace, directive-name, whitespace part. */
8138 void
8139 dwarfout_define (lineno, buffer)
8140 register unsigned lineno;
8141 register char *buffer;
8143 static int initialized = 0;
8144 if (!initialized)
8146 dwarfout_start_new_source_file (primary_filename);
8147 initialized = 1;
8151 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8152 the tail part of the directive line, i.e. the part which is past the
8153 initial whitespace, #, whitespace, directive-name, whitespace part. */
8154 void
8155 dwarfout_undef (lineno, buffer)
8156 register unsigned lineno;
8157 register char *buffer;
8161 /* Set up for Dwarf output at the start of compilation. */
8162 void
8163 dwarfout_init (asm_out_file, main_input_filename)
8164 register FILE *asm_out_file;
8165 register char *main_input_filename;
8168 /* Remember the name of the primary input file. */
8169 primary_filename = main_input_filename;
8171 /* Allocate the initial hunk of the file_table. */
8172 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
8173 bzero (file_table, FILE_TABLE_INCREMENT * sizeof (char *));
8174 file_table_allocated = FILE_TABLE_INCREMENT;
8175 /* skip the first entry - file numbers begin at 1 */
8176 file_table_in_use = 1;
8178 /* Allocate the initial hunk of the type_die_table. */
8179 type_die_table
8180 = (dw_die_ref *) xmalloc (TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8181 bzero (type_die_table, TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8182 type_die_table_allocated = TYPE_DIE_TABLE_INCREMENT;
8183 type_die_table_in_use = 0;
8185 /* Allocate the initial hunk of the decl_die_table. */
8186 decl_die_table
8187 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8188 bzero (decl_die_table, DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8189 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
8190 decl_die_table_in_use = 0;
8192 /* Allocate the initial hunk of the decl_scope_table. */
8193 decl_scope_table
8194 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8195 bzero (decl_scope_table, DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8196 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
8197 decl_scope_depth = 0;
8199 /* Allocate the initial hunk of the abbrev_die_table. */
8200 abbrev_die_table
8201 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
8202 * sizeof (dw_die_ref));
8203 bzero (abbrev_die_table, ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8204 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
8205 /* zero-th entry is allocated, but unused */
8206 abbrev_die_table_in_use = 1;
8208 /* Allocate the initial hunk of the line_info_table. */
8209 line_info_table
8210 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
8211 * sizeof (dw_line_info_entry));
8212 bzero (line_info_table, LINE_INFO_TABLE_INCREMENT
8213 * sizeof (dw_line_info_entry));
8214 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
8215 /* zero-th entry is allocated, but unused */
8216 line_info_table_in_use = 1;
8218 /* Allocate the initial hunk of the fde_table. */
8219 fde_table = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
8220 bzero (fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
8221 fde_table_allocated = FDE_TABLE_INCREMENT;
8222 fde_table_in_use = 0;
8224 #if 0
8225 /* Output a starting label for the .text section. */
8226 fputc ('\n', asm_out_file);
8227 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
8228 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
8230 /* Output a starting label for the .data section. */
8231 fputc ('\n', asm_out_file);
8232 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
8233 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
8235 /* Output a starting label for the .rodata section. */
8236 fputc ('\n', asm_out_file);
8237 ASM_OUTPUT_SECTION (asm_out_file, RODATA_SECTION);
8238 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
8240 /* Output a starting label for the .bss section. */
8241 fputc ('\n', asm_out_file);
8242 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
8243 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
8244 #endif
8246 /* Generate the initial DIE for the .debug section. Note that the (string)
8247 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
8248 will (typically) be a relative pathname and that this pathname should be
8249 taken as being relative to the directory from which the compiler was
8250 invoked when the given (base) source file was compiled. */
8251 gen_compile_unit_die (main_input_filename);
8253 /* clear the association between base types and their DIE's */
8254 init_base_type_table ();
8257 /* Output stuff that dwarf requires at the end of every file,
8258 and generate the DWARF-2 debugging info. */
8259 void
8260 dwarfout_finish ()
8262 /* Traverse the DIE tree and add sibling attributes to those DIE's
8263 that have children. */
8264 add_sibling_attributes (comp_unit_die);
8266 /* Output a terminator label for the .text section. */
8267 fputc ('\n', asm_out_file);
8268 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
8269 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
8271 #if 0
8272 /* Output a terminator label for the .data section. */
8273 fputc ('\n', asm_out_file);
8274 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
8275 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
8277 /* Output a terminator label for the .rodata section. */
8278 fputc ('\n', asm_out_file);
8279 ASM_OUTPUT_SECTION (asm_out_file, RODATA_SECTION);
8280 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
8282 /* Output a terminator label for the .bss section. */
8283 fputc ('\n', asm_out_file);
8284 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
8285 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
8286 #endif
8288 /* Output the source line correspondence table. */
8289 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
8291 fputc ('\n', asm_out_file);
8292 ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION);
8293 output_line_info ();
8295 /* We can only use the low/high_pc attributes if all of the code
8296 was in .text. */
8297 if (separate_line_info_table_in_use == 0)
8299 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
8300 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, TEXT_END_LABEL);
8302 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION);
8305 /* Output the abbreviation table. */
8306 fputc ('\n', asm_out_file);
8307 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
8308 build_abbrev_table (comp_unit_die);
8309 output_abbrev_section ();
8311 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8312 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8313 calc_die_sizes (comp_unit_die);
8315 /* Initialize the beginning FDE offset - and calculate sizes/offsets. */
8316 next_fde_offset = DWARF_CIE_SIZE;
8317 calc_fde_sizes ();
8319 /* Output debugging information. */
8320 fputc ('\n', asm_out_file);
8321 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_SECTION);
8322 output_compilation_unit_header ();
8323 output_die (comp_unit_die);
8325 if (pubname_table_in_use)
8327 /* Output public names table. */
8328 fputc ('\n', asm_out_file);
8329 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
8330 output_pubnames ();
8333 if (fde_table_in_use)
8335 /* Output call frame information. */
8336 fputc ('\n', asm_out_file);
8337 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
8338 output_call_frame_info ();
8340 /* Output the address range information. */
8341 fputc ('\n', asm_out_file);
8342 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
8343 output_aranges ();
8346 #endif /* DWARF_DEBUGGING_INFO && DWARF_VERSION == 2 */