]> gcc.gnu.org Git - gcc.git/blame - gcc/dwarf2out.c
Don't use TARGET_RELOCATABLE, not defined under AIX.
[gcc.git] / gcc / dwarf2out.c
CommitLineData
a3f97cbb
JW
1/* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com). Derived from the
4 DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com).
5
6This file is part of GNU CC.
7
8GNU CC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
13GNU CC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU CC; see the file COPYING. If not, write to
20the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22#include "config.h"
23
6ba95bc9
RK
24#ifndef DWARF_VERSION
25#define DWARF_VERSION 1
26#endif
27#if defined (DWARF_DEBUGGING_INFO) && (DWARF_VERSION == 2)
a3f97cbb
JW
28#include <stdio.h>
29#include "dwarf2.h"
30#include "tree.h"
31#include "flags.h"
32#include "rtl.h"
33#include "hard-reg-set.h"
34#include "regs.h"
35#include "insn-config.h"
36#include "reload.h"
37#include "output.h"
38#include "defaults.h"
39
40/* #define NDEBUG 1 */
41#include "assert.h"
42#if defined(DWARF_TIMESTAMPS)
43#if defined(POSIX)
44#include <time.h>
45#else /* !defined(POSIX) */
46#include <sys/types.h>
47#if defined(__STDC__)
48extern time_t time (time_t *);
49#else /* !defined(__STDC__) */
50extern time_t time ();
51#endif /* !defined(__STDC__) */
52#endif /* !defined(POSIX) */
53#endif /* defined(DWARF_TIMESTAMPS) */
54
55extern char *getpwd ();
56extern char *index ();
57extern char *rindex ();
58
59/* IMPORTANT NOTE: Please see the file README.DWARF for important details
60 regarding the GNU implementation of DWARF. */
61
62/* NOTE: In the comments in this file, many references are made to
63 "Debugging Information Entries". This term is abbreviated as `DIE'
64 throughout the remainder of this file. */
65
66/* NOTE: The implementation of C++ support is unfinished. */
67
68#if defined(__GNUC__) && (NDEBUG == 1)
69#define inline static inline
70#else
71#define inline static
72#endif
73
74
75/* An internal representation of the DWARF output is built, and then
76 walked to generate the DWARF debugging info. The walk of the internal
77 representation is done after the entire program has been compiled.
78 The types below are used to describe the internal representation. */
79
80/* Each DIE may have a series of attribute/value pairs. Values
81 can take on several forms. The forms that are used in this
82 impelementation are listed below. */
83typedef enum
84 {
85 dw_val_class_addr,
86 dw_val_class_loc,
87 dw_val_class_const,
88 dw_val_class_unsigned_const,
89 dw_val_class_double_const,
90 dw_val_class_flag,
91 dw_val_class_die_ref,
92 dw_val_class_fde_ref,
93 dw_val_class_lbl_id,
94 dw_val_class_section_offset,
95 dw_val_class_str
96 }
97dw_val_class;
98
99/* Various DIE's use offsets relative to the beginning of the
100 .debug_info section to refer to each other. */
101typedef long int dw_offset;
102
103/* Define typedefs here to avoid circular dependencies. */
104typedef struct die_struct *dw_die_ref;
105typedef struct dw_attr_struct *dw_attr_ref;
106typedef struct dw_val_struct *dw_val_ref;
107typedef struct dw_line_info_struct *dw_line_info_ref;
e90b62db 108typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
a3f97cbb
JW
109typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
110typedef struct dw_cfi_struct *dw_cfi_ref;
111typedef struct dw_fde_struct *dw_fde_ref;
112typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
d291dd49
JM
113typedef struct pubname_struct *pubname_ref;
114typedef dw_die_ref *arange_ref;
a3f97cbb
JW
115
116/* Describe a double word constant value. */
117typedef struct dw_double_const_struct
118 {
119 unsigned long dw_dbl_hi;
120 unsigned long dw_dbl_low;
121 }
122dw_dbl_const;
123
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. */
128typedef struct dw_line_info_struct
129 {
130 unsigned long dw_file_num;
131 unsigned long dw_line_num;
132 }
133dw_line_info_entry;
134
e90b62db
JM
135/* Line information for functions in separate sections; each one gets its
136 own sequence. */
137typedef struct dw_separate_line_info_struct
138 {
139 unsigned long dw_file_num;
140 unsigned long dw_line_num;
141 unsigned long function;
142 }
143dw_separate_line_info_entry;
144
a3f97cbb
JW
145/* The dw_val_node describes an attibute's value, as it is
146 represnted internally. */
147typedef struct dw_val_struct
148 {
149 dw_val_class val_class;
150 union
151 {
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;
163 }
164 v;
165 }
166dw_val_node;
167
168/* Locations in memory are described using a sequence of stack machine
169 operations. */
170typedef struct dw_loc_descr_struct
171 {
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;
176 }
177dw_loc_descr_node;
178
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. */
182typedef struct dw_attr_struct
183 {
184 enum dwarf_attribute dw_attr;
185 dw_attr_ref dw_attr_next;
186 dw_val_node dw_attr_val;
187 }
188dw_attr_node;
189
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. */
194typedef union dw_cfi_oprnd_struct
195 {
196 unsigned long dw_cfi_reg_num;
197 long int dw_cfi_offset;
198 char *dw_cfi_addr;
199 }
200dw_cfi_oprnd;
201
202typedef struct dw_cfi_struct
203 {
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;
208 }
209dw_cfi_node;
210
211/* All call frame descriptions (FDE's) in the GCC generated DWARF
4b674448 212 refer to a single Common Information Entry (CIE), defined at
a3f97cbb
JW
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. */
216typedef struct dw_fde_struct
217 {
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;
224 }
225dw_fde_node;
226
227/* The Debugging Information Entry (DIE) structure */
228typedef struct die_struct
229 {
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;
239 }
240die_node;
241
d291dd49
JM
242/* The pubname structure */
243typedef struct pubname_struct
244{
245 dw_die_ref die;
246 char * name;
247}
248pubname_entry;
249
a3f97cbb
JW
250/* How to start an assembler comment. */
251#ifndef ASM_COMMENT_START
252#define ASM_COMMENT_START ";#"
253#endif
254
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)
267
268/* Information concerning the compilation unit's programming
269 language, and compiler version. */
270extern int flag_traditional;
271extern char *version_string;
272extern char *language_string;
273
274/* Maximum size (in bytes) of an artificially generated label. */
275#define MAX_ARTIFICIAL_LABEL_BYTES 30
276
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
314
7e23cb16
JM
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
321
a3f97cbb 322/* Fixed size portion of the DWARF compilation unit header. */
7e23cb16 323#define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
a3f97cbb
JW
324
325/* Fixed size portion of debugging line information prolog. */
326#define DWARF_LINE_PROLOG_HEADER_SIZE 5
327
328/* Fixed size portion of public names info. */
7e23cb16
JM
329#define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
330
331/* Round SIZE up to the nearest BOUNDARY. */
332#define DWARF_ROUND(SIZE,BOUNDARY) \
333 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
a3f97cbb
JW
334
335/* Fixed size portion of the address range info. */
7e23cb16
JM
336#define DWARF_ARANGES_HEADER_SIZE \
337 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
a3f97cbb
JW
338
339/* Fixed size portion of the Common Information Entry (including
340 the length field). */
7e23cb16 341#define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 8)
a3f97cbb
JW
342
343/* Fixed size of the Common Information Entry in the call frame
7e23cb16
JM
344 information (.debug_frame) section rounded up to a word boundary. */
345#define DWARF_CIE_SIZE DWARF_ROUND (DWARF_CIE_HEADER_SIZE, PTR_SIZE)
a3f97cbb
JW
346
347/* Offsets recorded in opcodes are a multiple of this alignment factor. */
348#define DWARF_CIE_DATA_ALIGNMENT -4
349
350/* Fixed size portion of the FDE. */
7e23cb16 351#define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
a3f97cbb
JW
352
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
362
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
366
367/* First special line opcde - leave room for the standard opcodes. */
368#define DWARF_LINE_OPCODE_BASE 10
369
370/* Range of line offsets in a special line info. opcode. */
371#define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
372
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
378
379/* This location is used by calc_die_sizes() to keep track
380 the offset of each DIE within the .debug_info section. */
381static unsigned long next_die_offset;
382
383/* This location is used by calc_fde_sizes() to keep track
384 the offset of each FDE within the .debug_frame section. */
385static unsigned long next_fde_offset;
386
387/* Record the root of the DIE's built for the current compilation unit. */
388dw_die_ref comp_unit_die;
389
390/* Pointer to an array of filenames referenced by this compilation unit. */
391static char **file_table;
392
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. */
396static unsigned file_table_allocated;
397
398/* Number of entries in the file_table which are actually in use. */
399static unsigned file_table_in_use;
400
401/* Size (in elements) of increments by which we may expand the filename
402 table. */
403#define FILE_TABLE_INCREMENT 64
404
405/* Local pointer to the name of the main input file. Initialized in
406 dwarfout_init. */
407static char *primary_filename;
408
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. */
414static unsigned next_block_number = 2;
415
a3f97cbb
JW
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. */
419static dw_die_ref *type_die_table;
420
421/* Number of elements currently allocated for type_die_table. */
422static unsigned type_die_table_allocated;
423
424/* Number of elements in type_die_table currently in use. */
425static unsigned type_die_table_in_use;
426
427/* Size (in elements) of increments by which we may expand the
428 type_die_table. */
429#define TYPE_DIE_TABLE_INCREMENT 4096
430
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. */
434static dw_die_ref *decl_die_table;
435
436/* Number of elements currently allocated for the decl_die_table. */
437static unsigned decl_die_table_allocated;
438
439/* Number of elements in decl_die_table currently in use. */
440static unsigned decl_die_table_in_use;
441
442/* Size (in elements) of increments by which we may expand the
443 decl_die_table. */
444#define DECL_DIE_TABLE_INCREMENT 256
445
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. */
451static tree *decl_scope_table;
452
453/* Number of elements currently allocated for the decl_scope_table. */
454static unsigned decl_scope_table_allocated;
455
456/* Current level of nesting of declataion scopes. */
457static unsigned decl_scope_depth;
458
459/* Size (in elements) of increments by which we may expand the
460 decl_scope_table. */
461#define DECL_SCOPE_TABLE_INCREMENT 64
462
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. */
466static dw_die_ref *abbrev_die_table;
467
468/* Number of elements currently allocated for abbrev_die_table. */
469static unsigned abbrev_die_table_allocated;
470
471/* Number of elements in type_die_table currently in use. */
472static unsigned abbrev_die_table_in_use;
473
474/* Size (in elements) of increments by which we may expand the
475 abbrev_die_table. */
476#define ABBREV_DIE_TABLE_INCREMENT 256
477
478/* A pointer to the base of a table that contains line information
e90b62db 479 for each source code line in .text in the compilation unit. */
a3f97cbb
JW
480static dw_line_info_ref line_info_table;
481
482/* Number of elements currently allocated for line_info_table. */
483static unsigned line_info_table_allocated;
484
e90b62db
JM
485/* Number of elements in separate_line_info_table currently in use. */
486static unsigned separate_line_info_table_in_use;
487
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. */
490static dw_separate_line_info_ref separate_line_info_table;
491
492/* Number of elements currently allocated for separate_line_info_table. */
493static unsigned separate_line_info_table_allocated;
494
a3f97cbb
JW
495/* Number of elements in line_info_table currently in use. */
496static unsigned line_info_table_in_use;
497
498/* Size (in elements) of increments by which we may expand the
499 line_info_table. */
500#define LINE_INFO_TABLE_INCREMENT 1024
501
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. */
505static unsigned prev_file_entry_num = (unsigned) -1;
506
507/* A pointer to the base of a table that contains frame description
508 information for each routine. */
509static dw_fde_ref fde_table;
510
511/* Number of elements currently allocated for fde_table. */
512static unsigned fde_table_allocated;
513
514/* Number of elements in fde_table currently in use. */
515static unsigned fde_table_in_use;
516
517/* Size (in elements) of increments by which we may expand the
518 fde_table. */
519#define FDE_TABLE_INCREMENT 256
520
d291dd49
JM
521/* A pointer to the base of a table that contains a list of publicly
522 accessible names. */
523static pubname_ref pubname_table;
524
525/* Number of elements currently allocated for pubname_table. */
526static unsigned pubname_table_allocated;
527
528/* Number of elements in pubname_table currently in use. */
529static unsigned pubname_table_in_use;
530
531/* Size (in elements) of increments by which we may expand the
532 pubname_table. */
533#define PUBNAME_TABLE_INCREMENT 64
534
535/* A pointer to the base of a table that contains a list of publicly
536 accessible names. */
537static arange_ref arange_table;
538
539/* Number of elements currently allocated for arange_table. */
540static unsigned arange_table_allocated;
541
542/* Number of elements in arange_table currently in use. */
543static unsigned arange_table_in_use;
544
545/* Size (in elements) of increments by which we may expand the
546 arange_table. */
547#define ARANGE_TABLE_INCREMENT 64
548
a3f97cbb
JW
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. */
554static unsigned current_funcdef_number = 1;
555
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. */
560static unsigned current_funcdef_fde;
561
562/* Record the size of the frame, so that the DW_AT_frame_base
563 attribute can be set properly in gen_subprogram_die. */
564static long int current_funcdef_frame_size = 0;
565
7e23cb16
JM
566/* Record whether the function being analyzed contains inlined functions. */
567static int current_function_has_inlines;
568static int comp_unit_has_inlines;
569
a3f97cbb
JW
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. */
577typedef struct base_type_struct *base_type_ref;
578typedef struct base_type_struct
579 {
580 char *bt_name;
581 enum dwarf_type bt_type;
582 int bt_is_signed;
583 int bt_size;
584 }
585base_type_info;
586
587/* Characteristics of base types used by the compiler. */
588static base_type_info base_type_table[] =
589{
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}
611};
612#define NUM_BASE_TYPES (sizeof(base_type_table)/sizeof(base_type_info))
613
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. */
617static dw_die_ref base_type_die_table[NUM_BASE_TYPES];
618
619/* This predefined base type is used to create certain anonymous types */
620static dw_die_ref int_base_type_die;
621
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. */
626static tree dwarf_last_decl;
627
a3f97cbb
JW
628/* Forward declarations for functions defined in this file. */
629static void gen_type_die ();
630static void add_type_attribute ();
631static void decls_for_scope ();
632static void gen_decl_die ();
633static unsigned lookup_filename ();
7e23cb16 634static int constant_size PROTO((long unsigned));
f37230f0 635static enum dwarf_form value_format PROTO((dw_val_ref));
a3f97cbb
JW
636
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
7e23cb16
JM
647#ifndef UNALIGNED_DOUBLE_INT_ASM_OP
648#define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
649#endif
a3f97cbb
JW
650#ifndef ASM_BYTE_OP
651#define ASM_BYTE_OP ".byte"
652#endif
653
7e23cb16
JM
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
658
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
663
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)
667
a3f97cbb
JW
668/* Pseudo-op for defining a new section. */
669#ifndef SECTION_ASM_OP
670#define SECTION_ASM_OP ".section"
671#endif
672
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
680
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
709
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
729
730
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
d291dd49
JM
788#ifndef FUNC_BEGIN_LABEL_FMT
789#define FUNC_BEGIN_LABEL_FMT ".L_f%u"
790#endif
a3f97cbb
JW
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
e90b62db
JM
797#ifndef SEPARATE_LINE_CODE_LABEL_FMT
798#define SEPARATE_LINE_CODE_LABEL_FMT ".L_SLC%u"
799#endif
a3f97cbb
JW
800#ifndef SFNAMES_ENTRY_LABEL_FMT
801#define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
802#endif
803
a3f97cbb
JW
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
811
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
820
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
829
7e23cb16
JM
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
838
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
847
a3f97cbb
JW
848#ifndef ASM_OUTPUT_DWARF_ADDR
849#define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
7e23cb16 850 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
a3f97cbb
JW
851 assemble_name (FILE, LABEL); \
852 } while (0)
853#endif
854
855#ifndef ASM_OUTPUT_DWARF_ADDR_CONST
856#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
7e23cb16
JM
857 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
858#endif
859
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)
a3f97cbb
JW
865#endif
866
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
871
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
876
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
881
7e23cb16
JM
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
887
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
893
a3f97cbb
JW
894#ifndef ASM_OUTPUT_DWARF_DATA8
895#define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
896 do { \
897 if (WORDS_BIG_ENDIAN) \
898 { \
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);\
901 } \
902 else \
903 { \
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); \
906 } \
907 } while (0)
908#endif
909
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++) \
921 { \
922 register int c = p[i]; \
923 if (c == '\"' || c == '\\') \
924 putc ('\\', FILE); \
925 if (c >= ' ' && c < 0177) \
926 putc (c, FILE); \
927 else \
928 { \
929 fprintf (FILE, "\\%o", c); \
930 } \
931 } \
932 fprintf (FILE, "\\0\""); \
933 } \
934 while (0)
935#endif
936
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); \
947 } \
948 while (0)
949#endif
950
951\f
952/************************ general utility functions **************************/
953
954/* Return a pointer to a copy of the section string name 's' with all
955 attributes stripped off. */
956inline char *
957stripattributes (s)
958 register char *s;
959{
960 register char *stripped, *p;
961 stripped = xstrdup (s);
962 p = stripped;
963 while (*p && *p != ',')
964 p++;
965 *p = '\0';
966 return stripped;
967}
968
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. */
975static void
976addr_const_to_string (str, x)
977 char *str;
978 rtx x;
979{
980 char buf1[256];
981 char buf2[256];
982
983restart:
984 str[0] = '\0';
985 switch (GET_CODE (x))
986 {
987 case PC:
988 if (flag_pic)
989 strcat (str, ",");
990 else
991 abort ();
992 break;
993
994 case SYMBOL_REF:
995 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
996 strcat (str, buf1);
997 break;
998
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;
1004
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;
1010
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;
1021
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;
1028
1029 case CONST_DOUBLE:
1030 if (GET_MODE (x) == VOIDmode)
1031 {
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);
1066 }
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;
1072
1073 case PLUS:
1074 /* Some assemblers need integer constants to appear last (eg masm). */
1075 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
1076 {
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);
1083 }
1084 else
1085 {
1086 addr_const_to_string (buf1, XEXP (x, 0));
1087 strcat (str, buf1);
bdb669cb 1088 if (INTVAL (XEXP (x, 1)) >= 0)
a3f97cbb
JW
1089 strcat (str, "+");
1090 addr_const_to_string (buf1, XEXP (x, 1));
bdb669cb 1091 strcat (str, buf1);
a3f97cbb
JW
1092 }
1093 break;
1094
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;
1101
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)
1107 {
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);
1112 }
1113 else
1114 {
1115 addr_const_to_string (buf1, XEXP (x, 1));
1116 strcat (str, buf1);
1117 }
1118 break;
1119
1120 case ZERO_EXTEND:
1121 case SIGN_EXTEND:
1122 addr_const_to_string (buf1, XEXP (x, 0));
1123 strcat (str, buf1);
1124 break;
1125
1126 default:
1127 output_operand_lossage ("invalid expression as operand");
1128 }
1129}
1130
1131/* Convert an address constant to a string, and return a pointer to
1132 a copy of the result, located on the heap. */
1133static char *
1134addr_to_string (x)
1135 rtx x;
1136{
1137 char buf[1024];
1138 addr_const_to_string (buf, x);
1139 return xstrdup (buf);
1140}
1141
1142/* Test if rtl node points to a psuedo register. */
1143inline int
1144is_pseudo_reg (rtl)
1145 register rtx rtl;
1146{
1147 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1148 || ((GET_CODE (rtl) == SUBREG)
1149 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1150}
1151
1152
1153/* Return a reference to a type, with its const and volatile qualifiers
1154 removed. */
1155inline tree
1156type_main_variant (type)
1157 register tree type;
1158{
1159 type = TYPE_MAIN_VARIANT (type);
1160
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)
1166 {
1167 while (type != TYPE_MAIN_VARIANT (type))
1168 type = TYPE_MAIN_VARIANT (type);
1169 }
1170 return type;
1171}
1172
1173/* Return non-zero if the given type node represents a tagged type. */
1174inline int
1175is_tagged_type (type)
1176 register tree type;
1177{
1178 register enum tree_code code = TREE_CODE (type);
1179
1180 return (code == RECORD_TYPE || code == UNION_TYPE
1181 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1182}
1183
1184/* Convert a DIE tag into its string name. */
1185static char *
1186dwarf_tag_name (tag)
1187 register unsigned tag;
1188{
1189 switch (tag)
1190 {
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>";
1297 }
1298}
1299
1300/* Convert a DWARF attribute code into its string name. */
1301static char *
1302dwarf_attr_name (attr)
1303 register unsigned attr;
1304{
1305 switch (attr)
1306 {
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";
1431
a3f97cbb
JW
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";
7e23cb16
JM
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";
a3f97cbb
JW
1454
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>";
1469 }
1470}
1471
1472/* Convert a DWARF value form code into its string name. */
1473static char *
1474dwarf_form_name (form)
1475 register unsigned form;
1476{
1477 switch (form)
1478 {
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>";
1523 }
1524}
1525
1526/* Convert a DWARF stack opcode into its string name. */
1527static char *
1528dwarf_stack_op_name (op)
1529 register unsigned op;
1530{
1531 switch (op)
1532 {
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>";
1825 }
1826}
1827
1828/* Convert a DWARF type code into its string name. */
1829static char *
1830dwarf_type_encoding_name (enc)
1831 register unsigned enc;
1832{
1833 switch (enc)
1834 {
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>";
1853 }
1854}
1855
1856/* Convert a DWARF call frame info. operation to its string name */
1857static char *
1858dwarf_cfi_name (cfi_opc)
1859 register unsigned cfi_opc;
1860{
1861 switch (cfi_opc)
1862 {
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>";
1904 }
1905}
1906\f
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. */
1912static tree
1913decl_ultimate_origin (decl)
1914 register tree decl;
1915{
1916 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1917
1918 if (immediate_origin == NULL)
1919 return NULL;
1920 else
1921 {
1922 register tree ret_val;
1923 register tree lookahead = immediate_origin;
1924
1925 do
1926 {
1927 ret_val = lookahead;
1928 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1929 }
1930 while (lookahead != NULL && lookahead != ret_val);
1931 return ret_val;
1932 }
1933}
1934
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. */
1940static tree
1941block_ultimate_origin (block)
1942 register tree block;
1943{
1944 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1945
1946 if (immediate_origin == NULL)
1947 return NULL;
1948 else
1949 {
1950 register tree ret_val;
1951 register tree lookahead = immediate_origin;
1952
1953 do
1954 {
1955 ret_val = lookahead;
1956 lookahead = (TREE_CODE (ret_val) == BLOCK)
1957 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1958 : NULL;
1959 }
1960 while (lookahead != NULL && lookahead != ret_val);
1961 return ret_val;
1962 }
1963}
bdb669cb
JM
1964
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. */
1968
1969tree
1970decl_class_context (decl)
1971 tree decl;
1972{
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)))));
1980
1981 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1982 context = NULL_TREE;
1983
1984 return context;
1985}
a3f97cbb
JW
1986\f
1987/**************** DIE internal representation constturction *******************/
1988
1989/* Add an attribute/value pair to a DIE */
1990inline void
1991add_dwarf_attr (die, attr)
1992 register dw_die_ref die;
1993 register dw_attr_ref attr;
1994{
1995 if (die != NULL && attr != NULL)
1996 {
1997 if (die->die_attr == NULL)
1998 {
1999 die->die_attr = attr;
2000 die->die_attr_last = attr;
2001 }
2002 else
2003 {
2004 die->die_attr_last->dw_attr_next = attr;
2005 die->die_attr_last = attr;
2006 }
2007 }
2008}
2009
2010/* Add a flag value attribute to a DIE. */
2011inline void
2012add_AT_flag (die, attr_kind, flag)
2013 register dw_die_ref die;
2014 register enum dwarf_attribute attr_kind;
2015 register unsigned flag;
2016{
2017 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2018 if (attr != NULL)
2019 {
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);
2025 }
2026}
2027
2028/* Add a signed integer attribute value to a DIE. */
2029inline void
2030add_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;
2034{
2035 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2036 if (attr != NULL)
2037 {
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);
2043 }
2044}
2045
2046/* Add an unsigned integer attribute value to a DIE. */
2047inline void
2048add_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;
2052{
2053 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2054 if (attr != NULL)
2055 {
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);
2061 }
2062}
2063
2064/* Add an unsigned double integer attribute value to a DIE. */
2065inline void
2066add_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;
2071{
2072 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2073 if (attr != NULL)
2074 {
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);
2081 }
2082}
2083
2084/* Add a string attribute value to a DIE. */
2085inline void
2086add_AT_string (die, attr_kind, str)
2087 register dw_die_ref die;
2088 register enum dwarf_attribute attr_kind;
2089 register char *str;
2090{
2091 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2092 if (attr != NULL)
2093 {
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);
2099 }
2100}
2101
2102/* Add a DIE reference attribute value to a DIE. */
2103inline void
2104add_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;
2108{
2109 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2110 if (attr != NULL)
2111 {
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);
2117 }
2118}
2119
2120/* Add an FDE reference attribute value to a DIE. */
2121inline void
2122add_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;
2126{
2127 register dw_attr_ref attr;
2128
2129 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2130 if (attr != NULL)
2131 {
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);
2137 }
2138}
2139
2140/* Add a location description attribute value to a DIE. */
2141inline void
2142add_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;
2146{
2147 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2148 if (attr != NULL)
2149 {
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);
2155 }
2156}
2157
2158/* Add an address constant attribute value to a DIE. */
2159inline void
2160add_AT_addr (die, attr_kind, addr)
2161 register dw_die_ref die;
2162 register enum dwarf_attribute attr_kind;
2163 char *addr;
2164{
2165 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2166 if (attr != NULL)
2167 {
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);
2173 }
2174}
2175
2176/* Add a label identifier attribute value to a DIE. */
2177inline void
2178add_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;
2182{
2183 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2184 if (attr != NULL)
2185 {
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);
2191 }
2192}
2193
2194/* Add a section offset attribute value to a DIE. */
2195inline void
2196add_AT_section_offset (die, attr_kind, section)
2197 register dw_die_ref die;
2198 register enum dwarf_attribute attr_kind;
2199 register char *section;
2200{
2201 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2202 if (attr != NULL)
2203 {
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);
2209 }
2210}
2211
a3f97cbb
JW
2212/* Test if die refers to an external subroutine. */
2213inline int
2214is_extern_subr_die (die)
2215 register dw_die_ref die;
2216{
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)
2221 {
2222 is_subr = TRUE;
2223 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2224 {
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)
2228 {
2229 is_extern = TRUE;
2230 break;
2231 }
2232 }
2233 }
2234 return is_subr && is_extern;
2235}
2236
d291dd49
JM
2237/* Get the attribute of type attr_kind. */
2238inline dw_attr_ref
2239get_AT (die, attr_kind)
a3f97cbb 2240 register dw_die_ref die;
d291dd49 2241 register enum dwarf_attribute attr_kind;
a3f97cbb
JW
2242{
2243 register dw_attr_ref a;
7e23cb16 2244 register dw_die_ref spec = NULL;
d291dd49 2245
a3f97cbb
JW
2246 if (die != NULL)
2247 {
2248 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2249 {
d291dd49
JM
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;
a3f97cbb 2255 }
d291dd49
JM
2256 if (spec)
2257 return get_AT (spec, attr_kind);
a3f97cbb 2258 }
d291dd49
JM
2259 return NULL;
2260}
2261
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. */
2266inline char *
2267get_AT_low_pc (die)
2268 register dw_die_ref die;
2269{
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;
2274}
2275
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. */
2280inline char *
2281get_AT_hi_pc (die)
2282 register dw_die_ref die;
2283{
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;
2288}
2289
2290/* Return the value of the string attribute designated by ATTR_KIND, or
2291 NULL if it is not present. */
2292inline char *
2293get_AT_string (die, attr_kind)
2294 register dw_die_ref die;
2295 register enum dwarf_attribute attr_kind;
2296{
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;
a3f97cbb
JW
2301}
2302
bdb669cb
JM
2303/* Return the value of the flag attribute designated by ATTR_KIND, or -1
2304 if it is not present. */
2305inline int
2306get_AT_flag (die, attr_kind)
2307 register dw_die_ref die;
2308 register enum dwarf_attribute attr_kind;
2309{
d291dd49
JM
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;
bdb669cb
JM
2313 return -1;
2314}
2315
2316/* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
2317 if it is not present. */
2318inline unsigned
2319get_AT_unsigned (die, attr_kind)
2320 register dw_die_ref die;
2321 register enum dwarf_attribute attr_kind;
2322{
d291dd49
JM
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;
bdb669cb
JM
2326 return 0;
2327}
a3f97cbb 2328
4b674448
JM
2329/* Remove the specified attribute if present. */
2330inline void
2331remove_AT (die, attr_kind)
2332 register dw_die_ref die;
2333 register enum dwarf_attribute attr_kind;
2334{
2335 register dw_attr_ref a;
2336 register dw_attr_ref removed = NULL;;
2337 if (die != NULL)
2338 {
2339 if (die->die_attr->dw_attr == attr_kind)
2340 {
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;
2345 }
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)
2349 {
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;
e90b62db 2354 break;
4b674448
JM
2355 }
2356 if (removed)
2357 free (removed);
2358 }
2359}
2360
2361/* Discard the children of this DIE. */
2362inline void
2363remove_children (die)
2364 register dw_die_ref die;
2365{
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)
2370 {
2371 register dw_die_ref tmp_die = child_die;
2372 register dw_attr_ref a;
2373 child_die = child_die->die_sib;
2374
2375 for (a = tmp_die->die_attr; a != NULL; )
2376 {
2377 register dw_attr_ref tmp_a = a;
2378 a = a->dw_attr_next;
2379 free (tmp_a);
2380 }
2381 free (tmp_die);
2382 }
2383}
2384
a3f97cbb
JW
2385/* Add a child DIE below its parent. */
2386inline void
2387add_child_die (die, child_die)
2388 register dw_die_ref die;
2389 register dw_die_ref child_die;
2390{
2391 if (die != NULL && child_die != NULL)
2392 {
2393 assert (die != child_die);
2394 child_die->die_parent = die;
2395 child_die->die_sib = NULL;
2396 if (die->die_child == NULL)
2397 {
2398 die->die_child = child_die;
2399 die->die_child_last = child_die;
2400 }
2401 else
2402 {
2403 die->die_child_last->die_sib = child_die;
2404 die->die_child_last = child_die;
2405 }
2406 }
2407}
2408
2409/* Return a pointer to a newly created DIE node. */
2410inline dw_die_ref
2411new_die (tag_value, parent_die)
2412 register enum dwarf_tag tag_value;
2413 register dw_die_ref parent_die;
2414{
2415 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
2416 if (die != NULL)
2417 {
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)
2428 {
2429 add_child_die (parent_die, die);
2430 }
2431 }
2432 return die;
2433}
2434
2435/* Return the DIE associated with the given type specifier. */
2436inline dw_die_ref
2437lookup_type_die (type)
2438 register tree type;
2439{
2440 register unsigned type_id = TYPE_UID (type);
2441 return (type_id < type_die_table_in_use)
2442 ? type_die_table[type_id] : NULL;
2443}
2444
2445/* Equate a DIE to a given type specifier. */
2446static void
2447equate_type_number_to_die (type, type_die)
2448 register tree type;
2449 register dw_die_ref type_die;
2450{
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)
2455 {
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;
2465 }
2466 if (type_id >= type_die_table_in_use)
2467 {
2468 type_die_table_in_use = (type_id + 1);
2469 }
2470 type_die_table[type_id] = type_die;
2471}
2472
2473/* Return the DIE associated with a given declaration. */
2474inline dw_die_ref
2475lookup_decl_die (decl)
2476 register tree decl;
2477{
2478 register unsigned decl_id = DECL_UID (decl);
2479 return (decl_id < decl_die_table_in_use)
2480 ? decl_die_table[decl_id] : NULL;
2481}
2482
2483/* Equate a DIE to a particular declaration. */
2484static void
2485equate_decl_number_to_die (decl, decl_die)
2486 register tree decl;
2487 register dw_die_ref decl_die;
2488{
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)
2493 {
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;
2503 }
2504 if (decl_id >= decl_die_table_in_use)
2505 {
2506 decl_die_table_in_use = (decl_id + 1);
2507 }
2508 decl_die_table[decl_id] = decl_die;
2509}
2510
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. */
2514inline dw_loc_descr_ref
2515new_loc_descr (op, oprnd1, oprnd2)
2516 register enum dwarf_location_atom op;
2517 register unsigned long oprnd1;
2518 register unsigned long oprnd2;
2519{
2520 register dw_loc_descr_ref descr =
2521 (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2522 if (descr != NULL)
2523 {
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;
2530 }
2531 return descr;
2532}
2533
2534/* Add a location description term to a location description expression. */
2535inline void
2536add_loc_descr (list_head, descr)
2537 register dw_loc_descr_ref *list_head;
2538 register dw_loc_descr_ref descr;
2539{
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)
2543 {
2544 /* nothing */ ;
2545 }
2546 *d = descr;
2547}
2548
2549/* Return a pointer to a newly allocated Call Frame Instruction. */
2550inline dw_cfi_ref
2551new_cfi ()
2552{
2553 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
2554 if (cfi != NULL)
2555 {
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;
2559 }
2560 return cfi;
2561}
2562
2563/* Add a Call Frame Instruction to list of instructions. */
2564inline void
2565add_cfi (list_head, cfi)
2566 register dw_cfi_ref *list_head;
2567 register dw_cfi_ref cfi;
2568{
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)
2572 {
2573 /* nothing */ ;
2574 }
2575 *p = cfi;
2576}
2577\f
2578/********* Print DWARF Internal Representation (debugging aids) ***************/
2579
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. */
2583static int print_indent;
2584
2585/* Indent the line the number of spaces given by print_indent. */
2586inline void
2587print_spaces (outfile)
2588 FILE *outfile;
2589{
2590 fprintf (outfile, "%*s", print_indent, "");
2591}
2592
2593/* Print the information assoaciated with a given DIE, and its children.
2594 This routine is a debugging aid only. */
2595static void
2596print_die (die, outfile)
2597 dw_die_ref die;
2598 FILE *outfile;
2599{
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)
2609 {
2610 print_spaces (outfile);
2611 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
2612 switch (a->dw_attr_val.val_class)
2613 {
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)
2636 {
2637 fprintf (outfile, "die -> %u",
2638 a->dw_attr_val.v.val_die_ref->die_offset);
2639 }
2640 else
2641 {
2642 fprintf (outfile, "die -> <null>");
2643 }
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)
2653 {
2654 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
2655 }
2656 else
2657 {
2658 fprintf (outfile, "<null>");
2659 }
2660 break;
2661 }
2662 fprintf (outfile, "\n");
2663 }
2664 if (die->die_child != NULL)
2665 {
2666 print_indent += 4;
2667 for (c = die->die_child; c != NULL; c = c->die_sib)
2668 {
2669 print_die (c, outfile);
2670 }
2671 print_indent -= 4;
2672 }
2673}
2674
2675/* Print the contents of the source code line number correspondence table.
2676 This routine is a debugging aid only. */
2677static void
2678print_dwarf_line_table (outfile)
2679 FILE *outfile;
2680{
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)
2685 {
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");
2691 }
2692 fprintf (outfile, "\n\n");
2693}
2694
2695/* Print the information collected for a given DIE. */
2696void
2697debug_dwarf_die (die)
2698 dw_die_ref die;
2699{
2700 print_die (die, stderr);
2701}
2702
2703/* Print all DWARF informaiton collected for the compilation unit.
2704 This routine is a debugging aid only. */
2705void
2706debug_dwarf ()
2707{
2708 print_indent = 0;
2709 print_die (comp_unit_die, stderr);
2710 print_dwarf_line_table (stderr);
2711}
2712
2713\f
2714/***************** DWARF Information Construction Support *********************/
2715
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. */
2719static void
2720add_sibling_attributes(die)
2721 register dw_die_ref die;
2722{
2723 register dw_die_ref c;
2724 register dw_attr_ref attr;
2725 if (die != comp_unit_die && die->die_child != NULL)
2726 {
2727 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2728 if (attr != NULL)
2729 {
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;
2734 }
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)
2738 {
2739 die->die_attr_last = attr;
2740 }
2741 die->die_attr = attr;
2742 }
2743 for (c = die->die_child; c != NULL; c = c->die_sib)
2744 {
2745 add_sibling_attributes (c);
2746 }
2747}
2748
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. */
2754static void
2755build_abbrev_table (die)
2756 register dw_die_ref die;
2757{
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)
2763 {
2764 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
2765 if (abbrev->die_tag == die->die_tag)
2766 {
2767 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
2768 {
2769 a_attr = abbrev->die_attr;
2770 d_attr = die->die_attr;
2771 while (a_attr != NULL && d_attr != NULL)
2772 {
2773 if ((a_attr->dw_attr != d_attr->dw_attr)
f37230f0
JM
2774 || (value_format (&a_attr->dw_attr_val)
2775 != value_format (&d_attr->dw_attr_val)))
a3f97cbb
JW
2776 {
2777 break;
2778 }
2779 a_attr = a_attr->dw_attr_next;
2780 d_attr = d_attr->dw_attr_next;
2781 }
2782 if (a_attr == NULL && d_attr == NULL)
2783 {
2784 break;
2785 }
2786 }
2787 }
2788 }
2789 if (abbrev_id >= abbrev_die_table_in_use)
2790 {
2791 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
2792 {
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;
2800 }
2801 ++abbrev_die_table_in_use;
2802 abbrev_die_table[abbrev_id] = die;
2803 }
2804 die->die_abbrev = abbrev_id;
2805 for (c = die->die_child; c != NULL; c = c->die_sib)
2806 {
2807 build_abbrev_table (c);
2808 }
2809}
2810
2811\f
2812/********************** DWARF Information Sizing *****************************/
2813
2814/* Return the size of an unsigned LEB128 quantity. */
2815inline unsigned long
2816size_of_uleb128 (value)
2817 register unsigned long value;
2818{
2819 register unsigned long size = 0;
2820 register unsigned byte;
2821 do
2822 {
2823 byte = (value & 0x7f);
2824 value >>= 7;
2825 size += 1;
2826 }
2827 while (value != 0);
2828 return size;
2829}
2830
2831/* Return the size of a signed LEB128 quantity. */
2832inline unsigned long
2833size_of_sleb128 (value)
2834 register long value;
2835{
2836 register unsigned long size = 0;
2837 register unsigned byte;
2838 do
2839 {
2840 byte = (value & 0x7f);
2841 value >>= 7;
2842 size += 1;
2843 }
2844 while (!(((value == 0) && ((byte & 0x40) == 0))
2845 || ((value == -1) && ((byte & 0x40) != 0))));
2846 return size;
2847}
2848
2849/* Return the size of a string, including the null byte. */
2850static unsigned long
2851size_of_string (str)
2852 register char *str;
2853{
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)
2859 {
2860 c = str[i];
2861 if (c == '\\')
2862 {
2863 ++i;
2864 }
2865 size += 1;
2866 }
2867 /* Null terminator. */
2868 size += 1;
2869 return size;
2870}
2871
2872/* Return the size of a location descriptor. */
2873static unsigned long
2874size_of_loc_descr (loc)
2875 register dw_loc_descr_ref loc;
2876{
2877 register unsigned long size = 1;
2878 switch (loc->dw_loc_opc)
2879 {
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;
2968 }
2969 return size;
2970}
2971
f37230f0
JM
2972/* Return the size of a series of location descriptors. */
2973static unsigned long
2974size_of_locs (loc)
2975 register dw_loc_descr_ref loc;
2976{
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;
2981}
2982
7e23cb16
JM
2983/* Return the power-of-two number of bytes necessary to represent VALUE. */
2984static int
2985constant_size (value)
2986 long unsigned value;
2987{
2988 int log;
2989
2990 if (value == 0)
2991 log = 0;
2992 else
2993 log = floor_log2 (value);
2994
2995 log = log / 8;
2996 log = 1 << (floor_log2 (log) + 1);
2997
2998 return log;
2999}
3000
a3f97cbb
JW
3001/* Return the size of a DIE, as it is represented in the
3002 .debug_info section. */
3003static unsigned long
3004size_of_die (die)
3005 register dw_die_ref die;
3006{
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)
3012 {
3013 switch (a->dw_attr_val.val_class)
3014 {
3015 case dw_val_class_addr:
7e23cb16 3016 size += PTR_SIZE;
a3f97cbb
JW
3017 break;
3018 case dw_val_class_loc:
f37230f0
JM
3019 {
3020 register unsigned long lsize
3021 = size_of_locs (a->dw_attr_val.v.val_loc);
3022
3023 /* Block length. */
3024 size += constant_size (lsize);
3025 size += lsize;
3026 }
a3f97cbb
JW
3027 break;
3028 case dw_val_class_const:
3029 size += 4;
3030 break;
3031 case dw_val_class_unsigned_const:
7e23cb16 3032 size += constant_size (a->dw_attr_val.v.val_unsigned);
a3f97cbb
JW
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:
7e23cb16 3041 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
3042 break;
3043 case dw_val_class_fde_ref:
7e23cb16 3044 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
3045 break;
3046 case dw_val_class_lbl_id:
7e23cb16 3047 size += PTR_SIZE;
a3f97cbb
JW
3048 break;
3049 case dw_val_class_section_offset:
7e23cb16 3050 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
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 ();
3057 }
3058 }
3059 return size;
3060}
3061
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. */
3067static void
3068calc_die_sizes (die)
3069 dw_die_ref die;
3070{
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)
3076 {
3077 calc_die_sizes (c);
3078 }
3079 if (die->die_child != NULL)
3080 {
3081 /* Count the null byte used to terminate sibling lists. */
3082 next_die_offset += 1;
3083 }
3084}
3085
3086/* Return the size of the line information prolog generated for the
3087 compilation unit. */
3088static unsigned long
3089size_of_line_prolog ()
3090{
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)
3103 {
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);
3112 }
3113 /* Count the file table terminator. */
3114 size += 1;
3115 return size;
3116}
3117
3118/* Return the size of the line information generated for this
3119 compilation unit. */
3120static unsigned long
3121size_of_line_info ()
3122{
3123 register unsigned long size;
a3f97cbb
JW
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;
e90b62db 3129 register unsigned long function;
a3f97cbb
JW
3130 /* Version number. */
3131 size = 2;
3132 /* Prolog length specifier. */
7e23cb16 3133 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
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)
3142 {
e90b62db 3143 register dw_line_info_ref line_info;
a3f97cbb
JW
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)
3148 {
3149 /* Set file number instruction. */
3150 size += 1;
3151 current_file = line_info->dw_file_num;
3152 size += size_of_uleb128 (current_file);
3153 }
3154 if (line_info->dw_line_num != current_line)
3155 {
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))
3160 {
3161 /* 1-byte special line number instruction. */
3162 size += 1;
3163 }
3164 else
3165 {
3166 /* Advance line instruction. */
3167 size += 1;
3168 size += size_of_sleb128 (line_offset);
3169 /* Generate line entry instruction. */
3170 size += 1;
3171 }
3172 }
3173 }
bdb669cb
JM
3174 /* Advance pc instruction. */
3175 size += 1 + 2;
a3f97cbb
JW
3176 /* End of line number info. marker. */
3177 size += 1 + size_of_uleb128 (1) + 1;
e90b62db
JM
3178 function = 0;
3179 current_file = 1;
3180 current_line = 1;
3181 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
3182 {
3183 register dw_separate_line_info_ref line_info
3184 = &separate_line_info_table[lt_index];
3185 if (function != line_info->function)
3186 {
3187 function = line_info->function;
3188 /* Set address register instruction. */
3189 size += 1 + size_of_uleb128 (1 + PTR_SIZE)
3190 + 1 + PTR_SIZE;
3191 }
3192 else
3193 {
3194 /* Advance pc instruction. */
3195 size += 1 + 2;
3196 }
3197 if (line_info->dw_file_num != current_file)
3198 {
3199 /* Set file number instruction. */
3200 size += 1;
3201 current_file = line_info->dw_file_num;
3202 size += size_of_uleb128 (current_file);
3203 }
3204 if (line_info->dw_line_num != current_line)
3205 {
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))
3210 {
3211 /* 1-byte special line number instruction. */
3212 size += 1;
3213 }
3214 else
3215 {
3216 /* Advance line instruction. */
3217 size += 1;
3218 size += size_of_sleb128 (line_offset);
3219 /* Generate line entry instruction. */
3220 size += 1;
3221 }
3222 }
3223 ++lt_index;
3224
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)
3228 {
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;
3235 }
3236 }
a3f97cbb
JW
3237 return size;
3238}
3239
3240/* Return the size of the .debug_pubnames table generated for the
3241 compilation unit. */
3242static unsigned long
3243size_of_pubnames ()
3244{
a3f97cbb 3245 register unsigned long size;
d291dd49
JM
3246 register unsigned i;
3247
a3f97cbb 3248 size = DWARF_PUBNAMES_HEADER_SIZE;
d291dd49 3249 for (i = 0; i < pubname_table_in_use; ++i)
a3f97cbb 3250 {
d291dd49 3251 register pubname_ref p = &pubname_table[i];
7e23cb16 3252 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
a3f97cbb 3253 }
7e23cb16 3254 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
3255 return size;
3256}
3257
3258/* Return the size of the information in the .debug_aranges seciton. */
3259static unsigned long
3260size_of_aranges ()
3261{
3262 register unsigned long size;
3263 size = DWARF_ARANGES_HEADER_SIZE;
3264 /* Count the address/length pair for this compilation unit. */
7e23cb16
JM
3265 size += 2 * PTR_SIZE;
3266 size += 2 * PTR_SIZE * arange_table_in_use;
a3f97cbb 3267 /* Count the two zero words used to terminated the address range table. */
7e23cb16 3268 size += 2 * PTR_SIZE;
a3f97cbb
JW
3269 return size;
3270}
3271\f
3272/**************** DWARF Debug Information Output *****************************/
3273
3274/* Output an unsigned LEB128 quantity. */
3275static void
3276output_uleb128 (value)
3277 register unsigned long value;
3278{
3279 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3280 do
3281 {
3282 register unsigned byte = (value & 0x7f);
3283 value >>= 7;
3284 if (value != 0)
3285 {
3286 /* More bytes to follow. */
3287 byte |= 0x80;
3288 }
3289 fprintf (asm_out_file, "0x%x", byte);
3290 if (value != 0)
3291 {
3292 fprintf (asm_out_file, ",");
3293 }
3294 }
3295 while (value != 0);
3296}
3297
3298/* Output an signed LEB128 quantity. */
3299static void
3300output_sleb128 (value)
3301 register long value;
3302{
3303 register int more;
3304 register unsigned byte;
3305 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3306 do
3307 {
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)
3314 {
3315 byte |= 0x80;
3316 }
3317 fprintf (asm_out_file, "0x%x", byte);
3318 if (more)
3319 {
3320 fprintf (asm_out_file, ",");
3321 }
3322 }
3323 while (more);
3324}
3325
f37230f0
JM
3326/* Select the encoding of an attribute value. */
3327static enum dwarf_form
3328value_format (v)
a3f97cbb
JW
3329 dw_val_ref v;
3330{
a3f97cbb
JW
3331 switch (v->val_class)
3332 {
3333 case dw_val_class_addr:
f37230f0 3334 return DW_FORM_addr;
a3f97cbb 3335 case dw_val_class_loc:
f37230f0
JM
3336 switch (constant_size (size_of_locs (v->v.val_loc)))
3337 {
3338 case 1:
3339 return DW_FORM_block1;
3340 case 2:
3341 return DW_FORM_block2;
3342 default:
3343 abort ();
3344 }
a3f97cbb 3345 case dw_val_class_const:
f37230f0 3346 return DW_FORM_data4;
a3f97cbb 3347 case dw_val_class_unsigned_const:
7e23cb16
JM
3348 switch (constant_size (v->v.val_unsigned))
3349 {
3350 case 1:
f37230f0 3351 return DW_FORM_data1;
7e23cb16 3352 case 2:
f37230f0 3353 return DW_FORM_data2;
7e23cb16 3354 case 4:
f37230f0 3355 return DW_FORM_data4;
7e23cb16
JM
3356 default:
3357 abort ();
3358 }
a3f97cbb 3359 case dw_val_class_double_const:
f37230f0 3360 return DW_FORM_data8;
a3f97cbb 3361 case dw_val_class_flag:
f37230f0 3362 return DW_FORM_flag;
a3f97cbb 3363 case dw_val_class_die_ref:
f37230f0 3364 return DW_FORM_ref;
a3f97cbb 3365 case dw_val_class_fde_ref:
f37230f0 3366 return DW_FORM_data;
a3f97cbb 3367 case dw_val_class_lbl_id:
f37230f0 3368 return DW_FORM_addr;
a3f97cbb 3369 case dw_val_class_section_offset:
f37230f0 3370 return DW_FORM_data;
a3f97cbb 3371 case dw_val_class_str:
f37230f0 3372 return DW_FORM_string;
a3f97cbb
JW
3373 default:
3374 abort ();
3375 }
f37230f0
JM
3376}
3377
3378/* Output the encoding of an attribute value. */
3379static void
3380output_value_format (v)
3381 dw_val_ref v;
3382{
3383 enum dwarf_form form = value_format (v);
a3f97cbb
JW
3384 output_uleb128 (form);
3385 if (flag_verbose_asm)
3386 {
3387 fprintf (asm_out_file, "\t%s %s",
3388 ASM_COMMENT_START, dwarf_form_name (form));
3389 }
3390 fputc ('\n', asm_out_file);
3391}
3392
3393/* Output the .debug_abbrev section which defines the DIE abbreviation
3394 table. */
3395static void
3396output_abbrev_section ()
3397{
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)
3401 {
3402 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3403 output_uleb128 (abbrev_id);
3404 if (flag_verbose_asm)
3405 {
3406 fprintf (asm_out_file, "\t%s abbrev code = %u",
3407 ASM_COMMENT_START, abbrev_id);
3408 }
3409 fputc ('\n', asm_out_file);
3410 output_uleb128 (abbrev->die_tag);
3411 if (flag_verbose_asm)
3412 {
3413 fprintf (asm_out_file, "\t%s TAG: %s",
3414 ASM_COMMENT_START, dwarf_tag_name (abbrev->die_tag));
3415 }
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)
3421 {
3422 fprintf (asm_out_file, "\t%s %s",
3423 ASM_COMMENT_START,
3424 (abbrev->die_child != NULL)
3425 ? "DW_children_yes" : "DW_children_no");
3426 }
3427 fputc ('\n', asm_out_file);
3428 for (a_attr = abbrev->die_attr; a_attr != NULL;
3429 a_attr = a_attr->dw_attr_next)
3430 {
3431 output_uleb128 (a_attr->dw_attr);
3432 if (flag_verbose_asm)
3433 {
3434 fprintf (asm_out_file, "\t%s %s",
3435 ASM_COMMENT_START,
3436 dwarf_attr_name (a_attr->dw_attr));
3437 }
3438 fputc ('\n', asm_out_file);
3439 output_value_format (&a_attr->dw_attr_val);
3440 }
3441 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
3442 }
3443}
3444
3445/* Output location description stack opcode's operands (if any). */
3446static void
3447output_loc_operands (loc)
3448 register dw_loc_descr_ref loc;
3449{
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)
3453 {
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;
3561 }
3562}
3563
3564/* Compute the offset of a sibling. */
3565static unsigned long
3566sibling_offset (die)
3567 dw_die_ref die;
3568{
3569 unsigned long offset;
3570 if (die->die_child_last == NULL)
3571 {
3572 offset = die->die_offset + size_of_die (die);
3573 }
3574 else
3575 {
3576 offset = sibling_offset (die->die_child_last) + 1;
3577 }
3578 return offset;
3579}
3580
3581/* Output the DIE and its attributes. Called recursively to generate
3582 the definitions of each child DIE. */
3583static void
3584output_die (die)
3585 register dw_die_ref die;
3586{
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)
3594 {
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));
3599 }
3600 fputc ('\n', asm_out_file);
3601 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3602 {
3603 switch (a->dw_attr_val.val_class)
3604 {
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:
f37230f0
JM
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))
a3f97cbb 3613 {
f37230f0
JM
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 ();
a3f97cbb 3622 }
a3f97cbb
JW
3623 if (flag_verbose_asm)
3624 {
3625 fprintf (asm_out_file, "\t%s %s",
3626 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3627 }
3628 fputc ('\n', asm_out_file);
3629 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3630 loc = loc->dw_loc_next)
3631 {
3632 /* Output the opcode. */
3633 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3634 if (flag_verbose_asm)
3635 {
3636 fprintf (asm_out_file, "\t%s %s",
3637 ASM_COMMENT_START,
3638 dwarf_stack_op_name (loc->dw_loc_opc));
3639 }
3640 fputc ('\n', asm_out_file);
3641 /* Output the operand(s) (if any). */
3642 output_loc_operands (loc);
3643 }
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:
7e23cb16
JM
3649 switch (constant_size (a->dw_attr_val.v.val_unsigned))
3650 {
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 ();
3665 }
a3f97cbb
JW
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)
3677 {
3678 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
3679 }
3680 else if (a->dw_attr == DW_AT_sibling)
3681 {
3682 ref_offset = sibling_offset(die);
3683 }
3684 else
3685 {
3686 abort ();
3687 }
7e23cb16 3688 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
a3f97cbb
JW
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;
7e23cb16 3692 fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_OFFSET_ASM_OP,
a3f97cbb
JW
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:
7e23cb16
JM
3699 ASM_OUTPUT_DWARF_OFFSET
3700 (asm_out_file, stripattributes (a->dw_attr_val.v.val_section));
a3f97cbb
JW
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 ();
3707 }
3708 if (a->dw_attr_val.val_class != dw_val_class_loc)
3709 {
3710 if (flag_verbose_asm)
3711 {
3712 fprintf (asm_out_file, "\t%s %s",
3713 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3714 }
3715 fputc ('\n', asm_out_file);
3716 }
3717 }
3718 for (c = die->die_child; c != NULL; c = c->die_sib)
3719 {
3720 output_die (c);
3721 }
3722 if (die->die_child != NULL)
3723 {
3724 /* Add null byte to terminate sibling list. */
3725 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3726 fputc ('\n', asm_out_file);
3727 }
3728}
3729
3730/* Output the compilation unit that appears at the beginning of the
3731 .debug_info section, and precedes the DIE descriptions. */
3732static void
3733output_compilation_unit_header ()
3734{
7e23cb16 3735 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
a3f97cbb
JW
3736 if (flag_verbose_asm)
3737 {
3738 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
3739 ASM_COMMENT_START);
3740 }
3741 fputc ('\n', asm_out_file);
7e23cb16 3742 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
a3f97cbb
JW
3743 if (flag_verbose_asm)
3744 {
3745 fprintf (asm_out_file, "\t%s DWARF version number",
3746 ASM_COMMENT_START);
3747 }
3748 fputc ('\n', asm_out_file);
7e23cb16 3749 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
a3f97cbb
JW
3750 if (flag_verbose_asm)
3751 {
3752 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
3753 ASM_COMMENT_START);
3754 }
3755 fputc ('\n', asm_out_file);
7e23cb16 3756 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
a3f97cbb
JW
3757 if (flag_verbose_asm)
3758 {
3759 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)",
3760 ASM_COMMENT_START);
3761 }
3762 fputc ('\n', asm_out_file);
3763}
3764
3765/* Return the size of a Call Frame Instruction. */
3766static unsigned long
3767size_of_cfi (cfi)
3768 dw_cfi_ref cfi;
3769{
3770 register unsigned long size;
3771 /* count the 1-byte opcode */
3772 size = 1;
3773 switch (cfi->dw_cfi_opc)
3774 {
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;
3817 }
3818 return size;
3819}
3820
3821/* Return the size of an FDE sans the length word. */
3822inline unsigned long
3823size_of_fde (fde, npad)
3824 dw_fde_ref fde;
3825 unsigned long *npad;
3826{
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)
3832 {
3833 size += size_of_cfi(cfi);
3834 }
7e23cb16
JM
3835 /* Round the size up to a word boundary. */
3836 aligned_size = DWARF_ROUND (size, PTR_SIZE);
a3f97cbb
JW
3837 *npad = aligned_size - size;
3838 return aligned_size;
3839}
3840
3841/* Calculate the size of the FDE table, and establish the offset
3842 of each FDE in the .debug_frame section. */
3843static void
3844calc_fde_sizes ()
3845{
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)
3851 {
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;
3856 }
3857}
3858
3859/* Output a Call Frame Information opcode and its operand(s). */
3860static void
3861output_cfi (cfi, fde)
3862 register dw_cfi_ref cfi;
3863 register dw_fde_ref fde;
3864{
3865 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3866 {
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)
3871 {
3872 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc", ASM_COMMENT_START);
3873 }
3874 fputc ('\n', asm_out_file);
3875 }
3876 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3877 {
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)
3882 {
3883 fprintf (asm_out_file, "\t%s DW_CFA_offset", ASM_COMMENT_START);
3884 }
3885 fputc ('\n', asm_out_file);
3886 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3887 fputc ('\n', asm_out_file);
3888 }
3889 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3890 {
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)
3895 {
3896 fprintf (asm_out_file, "\t%s DW_CFA_restore", ASM_COMMENT_START);
3897 }
3898 fputc ('\n', asm_out_file);
3899 }
3900 else
3901 {
3902 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
3903 if (flag_verbose_asm)
3904 {
3905 fprintf (asm_out_file, "\t%s %s",
3906 ASM_COMMENT_START,
3907 dwarf_cfi_name (cfi->dw_cfi_opc));
3908 }
3909 fputc ('\n', asm_out_file);
3910 switch (cfi->dw_cfi_opc)
3911 {
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;
3968 }
3969 }
3970}
3971
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. */
3975static void
3976output_call_frame_info ()
3977{
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;
3984
3985 /* Output the CIE. */
7e23cb16 3986 ASM_OUTPUT_DWARF_DATA (asm_out_file, DWARF_CIE_SIZE - DWARF_OFFSET_SIZE);
a3f97cbb
JW
3987 if (flag_verbose_asm)
3988 {
3989 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
3990 ASM_COMMENT_START);
3991 }
3992 fputc ('\n', asm_out_file);
3993 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
3994 if (flag_verbose_asm)
3995 {
3996 fprintf (asm_out_file, "\t%s CIE Identifier Tag",
3997 ASM_COMMENT_START);
3998 }
3999 fputc ('\n', asm_out_file);
7e23cb16
JM
4000 if (DWARF_OFFSET_SIZE == 8)
4001 {
4002 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
4003 fputc ('\n', asm_out_file);
4004 }
a3f97cbb
JW
4005 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
4006 if (flag_verbose_asm)
4007 {
4008 fprintf (asm_out_file, "\t%s CIE Version",
4009 ASM_COMMENT_START);
4010 }
4011 fputc ('\n', asm_out_file);
4012 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4013 if (flag_verbose_asm)
4014 {
4015 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
4016 ASM_COMMENT_START);
4017 }
4018 fputc ('\n', asm_out_file);
4019 output_uleb128 (1);
4020 if (flag_verbose_asm)
4021 {
4022 fprintf (asm_out_file, "\t%s CIE Code Alignment Factor",
4023 ASM_COMMENT_START);
4024 }
4025 fputc ('\n', asm_out_file);
4026 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
4027 if (flag_verbose_asm)
4028 {
4029 fprintf (asm_out_file, "\t%s CIE Data Alignment Factor",
4030 ASM_COMMENT_START);
4031 }
4032 fputc ('\n', asm_out_file);
4033 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_FRAME_RA_COL);
4034 if (flag_verbose_asm)
4035 {
4036 fprintf (asm_out_file, "\t%s CIE RA Column",
4037 ASM_COMMENT_START);
4038 }
4039 fputc ('\n', asm_out_file);
4040
4041 /* Output the CFA instructions common to all FDE's. */
4042
4043#ifdef MIPS_DEBUGGING_INFO
4044
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);
4052
4053#endif
4054
4055 /* Pad the CIE out to an address sized boundary. */
4056 for (i = DWARF_CIE_HEADER_SIZE; i < DWARF_CIE_SIZE; ++i)
4057 {
4058 /* Pad out to a pointer size boundary */
4059 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4060 if (flag_verbose_asm)
4061 {
4062 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4063 ASM_COMMENT_START);
4064 }
4065 fputc ('\n', asm_out_file);
4066 }
4067
4068 /* Loop through all of the FDE's. */
4069 for (i = 0; i < fde_table_in_use; ++i)
4070 {
4071 fde = &fde_table[i];
4072 fde_size = size_of_fde (fde, &fde_pad);
7e23cb16 4073 ASM_OUTPUT_DWARF_DATA (asm_out_file, fde_size - DWARF_OFFSET_SIZE);
a3f97cbb
JW
4074 if (flag_verbose_asm)
4075 {
4076 fprintf (asm_out_file, "\t%s FDE Length",
4077 ASM_COMMENT_START);
4078 }
4079 fputc ('\n', asm_out_file);
7e23cb16 4080 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
a3f97cbb
JW
4081 if (flag_verbose_asm)
4082 {
4083 fprintf (asm_out_file, "\t%s FDE CIE offset",
4084 ASM_COMMENT_START);
4085 }
4086 fputc ('\n', asm_out_file);
4087 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
4088 if (flag_verbose_asm)
4089 {
4090 fprintf (asm_out_file, "\t%s FDE initial location",
4091 ASM_COMMENT_START);
4092 }
4093 fputc ('\n', asm_out_file);
7e23cb16
JM
4094 ASM_OUTPUT_DWARF_ADDR_DELTA
4095 (asm_out_file, fde->dw_fde_end, fde->dw_fde_begin);
a3f97cbb
JW
4096 if (flag_verbose_asm)
4097 {
4098 fprintf (asm_out_file, "\t%s FDE address range",
4099 ASM_COMMENT_START);
4100 }
4101 fputc ('\n', asm_out_file);
4102
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)
4106 {
4107 output_cfi (cfi, fde);
4108 }
4109
4110 /* Pad to a double word boundary. */
4111 for (j = 0; j < fde_pad; ++j)
4112 {
4113 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4114 if (flag_verbose_asm)
4115 {
4116 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4117 ASM_COMMENT_START);
4118 }
4119 fputc ('\n', asm_out_file);
4120 }
4121 }
4122}
4123
d291dd49
JM
4124/* Add a new entry to .debug_pubnames if appropriate. */
4125static void
4126add_pubname (decl, die)
4127 tree decl;
4128 dw_die_ref die;
4129{
4130 pubname_ref p;
4131
4132 if (! TREE_PUBLIC (decl))
4133 return;
4134
4135 if (pubname_table_in_use == pubname_table_allocated)
4136 {
4137 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
4138 pubname_table = (pubname_ref) xrealloc
4139 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
4140 }
4141 p = &pubname_table[pubname_table_in_use++];
4142 p->die = die;
4143 p->name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4144}
4145
a3f97cbb
JW
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. */
4149static void
4150output_pubnames ()
4151{
d291dd49
JM
4152 register unsigned i;
4153 {
4154 register unsigned long pubnames_length = size_of_pubnames ();
7e23cb16 4155 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
d291dd49 4156 }
a3f97cbb
JW
4157 if (flag_verbose_asm)
4158 {
4159 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
4160 ASM_COMMENT_START);
4161 }
4162 fputc ('\n', asm_out_file);
4163 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4164 if (flag_verbose_asm)
4165 {
4166 fprintf (asm_out_file, "\t%s DWARF Version",
4167 ASM_COMMENT_START);
4168 }
4169 fputc ('\n', asm_out_file);
7e23cb16 4170 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
a3f97cbb
JW
4171 if (flag_verbose_asm)
4172 {
4173 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4174 ASM_COMMENT_START);
4175 }
4176 fputc ('\n', asm_out_file);
7e23cb16 4177 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
a3f97cbb
JW
4178 if (flag_verbose_asm)
4179 {
4180 fprintf (asm_out_file, "\t%s Compilation Unit Length",
4181 ASM_COMMENT_START);
4182 }
4183 fputc ('\n', asm_out_file);
d291dd49 4184 for (i = 0; i < pubname_table_in_use; ++i)
a3f97cbb 4185 {
d291dd49 4186 register pubname_ref pub = &pubname_table[i];
7e23cb16 4187 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
d291dd49 4188 if (flag_verbose_asm)
a3f97cbb 4189 {
d291dd49
JM
4190 fprintf (asm_out_file, "\t%s DIE offset",
4191 ASM_COMMENT_START);
a3f97cbb 4192 }
d291dd49
JM
4193 fputc ('\n', asm_out_file);
4194
4195 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
4196 if (flag_verbose_asm)
4197 {
4198 fprintf (asm_out_file, "%s external name",
4199 ASM_COMMENT_START);
4200 }
4201 fputc ('\n', asm_out_file);
a3f97cbb 4202 }
7e23cb16 4203 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
a3f97cbb
JW
4204 fputc ('\n', asm_out_file);
4205}
4206
d291dd49
JM
4207/* Add a new entry to .debug_aranges if appropriate. */
4208static void
4209add_arange (decl, die)
4210 tree decl;
4211 dw_die_ref die;
4212{
4213 if (! DECL_SECTION_NAME (decl))
4214 return;
4215
4216 if (arange_table_in_use == arange_table_allocated)
4217 {
4218 arange_table_allocated += ARANGE_TABLE_INCREMENT;
4219 arange_table = (arange_ref) xrealloc
4220 (arange_table, arange_table_allocated * sizeof (dw_die_ref));
4221 }
4222 arange_table[arange_table_in_use++] = die;
4223}
4224
a3f97cbb
JW
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. */
4228static void
4229output_aranges ()
4230{
d291dd49
JM
4231 register unsigned i;
4232 {
4233 register unsigned long aranges_length = size_of_aranges ();
7e23cb16 4234 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
d291dd49 4235 }
a3f97cbb
JW
4236 if (flag_verbose_asm)
4237 {
4238 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
4239 ASM_COMMENT_START);
4240 }
4241 fputc ('\n', asm_out_file);
4242 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4243 if (flag_verbose_asm)
4244 {
4245 fprintf (asm_out_file, "\t%s DWARF Version",
4246 ASM_COMMENT_START);
4247 }
4248 fputc ('\n', asm_out_file);
7e23cb16 4249 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
a3f97cbb
JW
4250 if (flag_verbose_asm)
4251 {
4252 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4253 ASM_COMMENT_START);
4254 }
4255 fputc ('\n', asm_out_file);
4256 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
4257 if (flag_verbose_asm)
4258 {
4259 fprintf (asm_out_file, "\t%s Size of Address",
4260 ASM_COMMENT_START);
4261 }
4262 fputc ('\n', asm_out_file);
4263 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4264 if (flag_verbose_asm)
4265 {
4266 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
4267 ASM_COMMENT_START);
4268 }
4269 fputc ('\n', asm_out_file);
4270 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
7e23cb16
JM
4271 if (PTR_SIZE == 8)
4272 fprintf (asm_out_file, ",0,0");
a3f97cbb
JW
4273 if (flag_verbose_asm)
4274 {
7e23cb16
JM
4275 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
4276 ASM_COMMENT_START, 2 * PTR_SIZE);
a3f97cbb
JW
4277 }
4278 fputc ('\n', asm_out_file);
bdb669cb 4279 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
a3f97cbb
JW
4280 if (flag_verbose_asm)
4281 {
4282 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4283 }
4284 fputc ('\n', asm_out_file);
7e23cb16 4285 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, TEXT_END_LABEL, TEXT_SECTION);
a3f97cbb
JW
4286 if (flag_verbose_asm)
4287 {
4288 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4289 }
4290 fputc ('\n', asm_out_file);
d291dd49
JM
4291 for (i = 0; i < arange_table_in_use; ++i)
4292 {
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)
4299 {
4300 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4301 }
4302 fputc ('\n', asm_out_file);
4303 if (a->die_tag == DW_TAG_subprogram)
7e23cb16
JM
4304 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
4305 get_AT_low_pc (a));
d291dd49 4306 else
7e23cb16
JM
4307 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
4308 get_AT_unsigned (a, DW_AT_byte_size));
d291dd49
JM
4309 if (flag_verbose_asm)
4310 {
4311 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4312 }
4313 fputc ('\n', asm_out_file);
4314 }
a3f97cbb 4315 /* Output the terminator words. */
7e23cb16 4316 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
a3f97cbb 4317 fputc ('\n', asm_out_file);
7e23cb16 4318 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
a3f97cbb
JW
4319 fputc ('\n', asm_out_file);
4320}
4321
4322/* Output the source line number correspondence information. This
4323 information goes into the .debug_line section. */
4324static void
4325output_line_info ()
4326{
a3f97cbb
JW
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;
a3f97cbb
JW
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;
e90b62db 4337 register unsigned long function;
7e23cb16 4338 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
a3f97cbb
JW
4339 if (flag_verbose_asm)
4340 {
4341 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
4342 ASM_COMMENT_START);
4343 }
4344 fputc ('\n', asm_out_file);
4345 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4346 if (flag_verbose_asm)
4347 {
4348 fprintf (asm_out_file, "\t%s DWARF Version",
4349 ASM_COMMENT_START);
4350 }
4351 fputc ('\n', asm_out_file);
7e23cb16 4352 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
a3f97cbb
JW
4353 if (flag_verbose_asm)
4354 {
4355 fprintf (asm_out_file, "\t%s Prolog Length",
4356 ASM_COMMENT_START);
4357 }
4358 fputc ('\n', asm_out_file);
4359 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
4360 if (flag_verbose_asm)
4361 {
4362 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
4363 ASM_COMMENT_START);
4364 }
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)
4368 {
4369 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
4370 ASM_COMMENT_START);
4371 }
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)
4375 {
4376 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
4377 ASM_COMMENT_START);
4378 }
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)
4382 {
4383 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
4384 ASM_COMMENT_START);
4385 }
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)
4389 {
4390 fprintf (asm_out_file, "\t%s Special Opcode Base",
4391 ASM_COMMENT_START);
4392 }
4393 fputc ('\n', asm_out_file);
4394 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
4395 {
4396 switch (opc)
4397 {
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;
4408 }
4409 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
4410 if (flag_verbose_asm)
4411 {
4412 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
4413 ASM_COMMENT_START, opc, n_op_args);
4414 }
4415 fputc ('\n', asm_out_file);
4416 }
4417 if (flag_verbose_asm)
4418 {
4419 fprintf (asm_out_file, "%s Include Directory Table\n",
4420 ASM_COMMENT_START);
4421 }
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)
4426 {
4427 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
4428 }
4429 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4430 {
4431 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
4432 if (flag_verbose_asm)
4433 {
4434 fprintf (asm_out_file, "%s File Entry: 0x%x",
4435 ASM_COMMENT_START, ft_index);
4436 }
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);
4447 }
4448 /* Terminate the file name table */
4449 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4450 fputc ('\n', asm_out_file);
4451
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)
4455 {
4456 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
4457 }
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);
bdb669cb 4463 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
a3f97cbb
JW
4464 fputc ('\n', asm_out_file);
4465
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;
bdb669cb 4470 strcpy (prev_line_label, TEXT_SECTION);
a3f97cbb
JW
4471 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4472 {
e90b62db 4473 register dw_line_info_ref line_info;
a3f97cbb
JW
4474 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4475 if (flag_verbose_asm)
4476 {
4477 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4478 ASM_COMMENT_START);
4479 }
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)
4486 {
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)
4490 {
4491 fprintf (asm_out_file,
4492 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4493 }
4494 fputc ('\n', asm_out_file);
4495 output_uleb128 (current_file);
4496 if (flag_verbose_asm)
4497 {
4498 fprintf (asm_out_file, "\t%s \"%s\"",
4499 ASM_COMMENT_START, file_table[current_file]);
4500 }
4501 fputc ('\n', asm_out_file);
4502 }
4503 if (line_info->dw_line_num != current_line)
4504 {
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))
4509 {
4510 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4511 DWARF_LINE_OPCODE_BASE + line_delta);
4512 if (flag_verbose_asm)
4513 {
4514 fprintf (asm_out_file,
4515 "\t%s line %d", ASM_COMMENT_START, current_line);
4516 }
4517 fputc ('\n', asm_out_file);
4518 }
4519 else
4520 {
4521 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4522 if (flag_verbose_asm)
4523 {
4524 fprintf (asm_out_file,
4525 "\t%s advance to line %d",
4526 ASM_COMMENT_START, current_line);
4527 }
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);
4533 }
4534 }
4535 strcpy (prev_line_label, line_label);
4536 }
4537
bdb669cb 4538 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
a3f97cbb
JW
4539 if (flag_verbose_asm)
4540 {
bdb669cb
JM
4541 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4542 ASM_COMMENT_START);
a3f97cbb
JW
4543 }
4544 fputc ('\n', asm_out_file);
bdb669cb 4545 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, TEXT_END_LABEL, prev_line_label);
a3f97cbb 4546 fputc ('\n', asm_out_file);
bdb669cb 4547
a3f97cbb
JW
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)
4551 {
4552 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
4553 }
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);
e90b62db
JM
4559
4560 function = 0;
4561 current_file = 1;
4562 current_line = 1;
4563 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4564 {
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)
4569 {
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);
4583 }
4584 else
4585 {
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);
4593 }
4594 if (line_info->dw_file_num != current_file)
4595 {
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)
4599 {
4600 fprintf (asm_out_file,
4601 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4602 }
4603 fputc ('\n', asm_out_file);
4604 output_uleb128 (current_file);
4605 if (flag_verbose_asm)
4606 {
4607 fprintf (asm_out_file, "\t%s \"%s\"",
4608 ASM_COMMENT_START, file_table[current_file]);
4609 }
4610 fputc ('\n', asm_out_file);
4611 }
4612 if (line_info->dw_line_num != current_line)
4613 {
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))
4618 {
4619 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4620 DWARF_LINE_OPCODE_BASE + line_delta);
4621 if (flag_verbose_asm)
4622 {
4623 fprintf (asm_out_file,
4624 "\t%s line %d", ASM_COMMENT_START, current_line);
4625 }
4626 fputc ('\n', asm_out_file);
4627 }
4628 else
4629 {
4630 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4631 if (flag_verbose_asm)
4632 {
4633 fprintf (asm_out_file,
4634 "\t%s advance to line %d",
4635 ASM_COMMENT_START, current_line);
4636 }
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);
4642 }
4643 }
4644 ++lt_index;
4645 strcpy (prev_line_label, line_label);
4646
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)
4650 {
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);
4661
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);
4672 }
4673 }
a3f97cbb
JW
4674}
4675\f
4676/**************** attribute support utilities ********************************/
4677
4678/*
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.
4682 *
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.
4688 */
4689inline int
4690is_body_block (stmt)
4691 register tree stmt;
4692{
4693 if (TREE_CODE (stmt) == BLOCK)
4694 {
4695 register tree parent = BLOCK_SUPERCONTEXT (stmt);
4696
4697 if (TREE_CODE (parent) == BLOCK)
4698 {
4699 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
4700
4701 if (TREE_CODE (grandparent) == FUNCTION_DECL)
4702 return 1;
4703 }
4704 }
4705 return 0;
4706}
4707
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. */
4713inline void
4714init_base_type_table ()
4715{
4716 register int i;
4717 register base_type_ref bt;
4718 for (i = 0; i < NUM_BASE_TYPES; ++i)
4719 {
4720 base_type_die_table[i] = NULL;
4721 }
4722 assert (comp_unit_die != 0);
4723 for (i = 0; i < NUM_BASE_TYPES; ++i)
4724 {
4725 bt = &base_type_table[i];
4726 if (strcmp (bt->bt_name, "int") == 0)
4727 {
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;
4735 }
4736 }
4737}
4738
4739/* Given a pointer to a tree node for some base type, return a pointer to
4740 a DIE that describes the given type.
4741
4742 This routine must only be called for GCC type nodes that correspond to
4743 Dwarf base (fundamental) types. */
4744static dw_die_ref
4745base_type_die (type)
4746 register tree type;
4747{
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;
4753
4754 if (TREE_CODE (type) == ERROR_MARK)
4755 return 0;
4756
4757 switch (TREE_CODE (type))
4758 {
4759 case VOID_TYPE:
4760 case ERROR_MARK:
4761 break;
4762
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)
4772 {
4773 type_name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
4774 for (i = 0; i < NUM_BASE_TYPES; ++i)
4775 {
4776 bt = &base_type_table[i];
4777 if (strcmp (type_name, bt->bt_name) == 0)
4778 {
4779 type_index = i;
4780 break;
4781 }
4782 }
4783 }
4784
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)
4789 {
4790 for (i = 0; i < NUM_BASE_TYPES; ++i)
4791 {
4792 bt = &base_type_table[i];
4793 if (bt->bt_size == TYPE_PRECISION (type)
4794 && (TREE_UNSIGNED (type) == 0) == bt->bt_is_signed)
4795 {
4796 type_index = i;
4797 break;
4798 }
4799 }
4800 }
4801 break;
4802
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)
4807 {
4808 bt = &base_type_table[i];
4809 if ((bt->bt_type == DW_ATE_float)
4810 && (bt->bt_size == TYPE_PRECISION (type)))
4811 {
4812 type_index = i;
4813 break;
4814 }
4815 }
4816 break;
4817
4818 case COMPLEX_TYPE:
4819 for (i = 0; i < NUM_BASE_TYPES; ++i)
4820 {
4821 bt = &base_type_table[i];
4822 if ((bt->bt_type == DW_ATE_complex_float)
4823 && (bt->bt_size == TYPE_PRECISION (type)))
4824 {
4825 type_index = i;
4826 break;
4827 }
4828 }
4829 break;
4830
4831 case CHAR_TYPE:
4832 /* GNU Pascal/Ada CHAR type. Not used in C. */
4833 for (i = 0; i < NUM_BASE_TYPES; ++i)
4834 {
4835 bt = &base_type_table[i];
4836 if (bt->bt_type == DW_ATE_signed_char
4837 || bt->bt_type == DW_ATE_unsigned_char)
4838 {
4839 if (bt->bt_size == TYPE_PRECISION (type)
4840 && ((TREE_UNSIGNED (type) == 0) == bt->bt_is_signed))
4841 {
4842 type_index = i;
4843 break;
4844 }
4845 }
4846 }
4847 break;
4848
4849 case BOOLEAN_TYPE:
4850 /* GNU FORTRAN/Ada BOOLEAN type. */
4851 for (i = 0; i < NUM_BASE_TYPES; ++i)
4852 {
4853 bt = &base_type_table[i];
4854 if (bt->bt_type == DW_ATE_boolean
4855 && bt->bt_size == TYPE_PRECISION (type))
4856 {
4857 type_index = i;
4858 break;
4859 }
4860 }
4861 break;
4862
4863 default:
4864 abort (); /* No other TREE_CODEs are Dwarf fundamental
4865 types. */
4866 }
4867
4868 if (type_index == 0)
4869 {
4870 base_type_result = NULL;
4871 }
4872 else
4873 {
4874 base_type_result = base_type_die_table[type_index];
4875 if (base_type_result == NULL)
4876 {
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);
4883 }
4884
4885 }
4886
4887 return base_type_result;
4888}
4889
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. */
4898static tree
4899root_type (type)
4900 register tree type;
4901{
4902 if (TREE_CODE (type) == ERROR_MARK)
4903 return error_mark_node;
4904
4905 switch (TREE_CODE (type))
4906 {
4907 case ERROR_MARK:
4908 return error_mark_node;
4909
4910 case POINTER_TYPE:
4911 case REFERENCE_TYPE:
4912 return type_main_variant (root_type (TREE_TYPE (type)));
4913
4914 default:
4915 return type_main_variant (type);
4916 }
4917}
4918
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. */
4921inline int
4922is_base_type (type)
4923 register tree type;
4924{
4925 switch (TREE_CODE (type))
4926 {
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;
4935
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;
4950
4951 default:
4952 abort ();
4953 }
4954 return 0;
4955}
4956
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. */
4959static dw_die_ref
4960modified_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;
4965{
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;
4970
4971 if (code != ERROR_MARK)
4972 {
bdb669cb
JM
4973 type = build_type_variant (type, is_const_type, is_volatile_type);
4974
4975 mod_type_die = lookup_type_die (type);
4976 if (mod_type_die)
4977 return mod_type_die;
4978
a3f97cbb
JW
4979 if (is_const_type)
4980 {
ab72d377 4981 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
bdb669cb
JM
4982 sub_die = modified_type_die
4983 (build_type_variant (type, 0, is_volatile_type),
4984 0, is_volatile_type, context_die);
a3f97cbb
JW
4985 }
4986 else if (is_volatile_type)
4987 {
ab72d377 4988 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
bdb669cb
JM
4989 sub_die = modified_type_die
4990 (TYPE_MAIN_VARIANT (type), 0, 0, context_die);
a3f97cbb
JW
4991 }
4992 else if (code == POINTER_TYPE)
4993 {
ab72d377 4994 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
a3f97cbb 4995 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
61b32c02 4996#if 0
a3f97cbb 4997 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
61b32c02 4998#endif
a3f97cbb
JW
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);
5004 }
5005 else if (code == REFERENCE_TYPE)
5006 {
ab72d377 5007 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
a3f97cbb 5008 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
61b32c02 5009#if 0
a3f97cbb 5010 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
61b32c02 5011#endif
a3f97cbb
JW
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);
5017 }
5018 else if (is_base_type (type))
5019 {
5020 mod_type_die = base_type_die (type);
5021 }
5022 else
5023 {
4b674448
JM
5024 gen_type_die (type, context_die);
5025
a3f97cbb
JW
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));
a3f97cbb 5036 if (mod_type_die == NULL)
4b674448 5037 abort ();
a3f97cbb
JW
5038 }
5039 }
5040 if (sub_die != NULL)
5041 {
5042 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
5043 }
bdb669cb 5044 equate_type_number_to_die (type, mod_type_die);
a3f97cbb
JW
5045 return mod_type_die;
5046}
5047
a3f97cbb
JW
5048/* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
5049 an enumerated type. */
5050inline int
5051type_is_enum (type)
5052 register tree type;
5053{
5054 return TREE_CODE (type) == ENUMERAL_TYPE;
5055}
5056
5057/* Return the register number described by a given RTL node. */
5058static unsigned
5059reg_number (rtl)
5060 register rtx rtl;
5061{
5062 register unsigned regno = REGNO (rtl);
5063
5064 if (regno >= FIRST_PSEUDO_REGISTER)
5065 {
5066 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
5067 regno);
5068 regno = 0;
5069 }
5070 regno = DBX_REGISTER_NUMBER (regno);
5071 return regno;
5072}
5073
5074/* Return a location descriptor that designates a machine register. */
5075static dw_loc_descr_ref
5076reg_loc_descriptor (rtl)
5077 register rtx rtl;
5078{
5079 register dw_loc_descr_ref loc_result = NULL;
5080 register unsigned reg = reg_number (rtl);
5081 if (reg >= 0 && reg <= 31)
5082 {
5083 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0);
5084 }
5085 else
5086 {
5087 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
5088 }
5089 return loc_result;
5090}
5091
5092/* Return a location descriptor that designates a base+offset location. */
5093static dw_loc_descr_ref
5094based_loc_descr (reg, offset)
5095 unsigned reg;
5096 long int offset;
5097{
5098 register dw_loc_descr_ref loc_result;
810429b7
JM
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);
a3f97cbb
JW
5105 if (reg == fp_reg)
5106 {
810429b7 5107 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
a3f97cbb
JW
5108 }
5109 else if (reg >= 0 && reg <= 31)
5110 {
5111 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset);
5112 }
5113 else
5114 {
5115 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
5116 }
5117 return loc_result;
5118}
5119
5120/* Return true if this RTL expression describes a base+offset calculation. */
5121inline int
5122is_based_loc (rtl)
5123 register rtx rtl;
5124{
5125 return GET_CODE (rtl) == PLUS
5126 && ((GET_CODE (XEXP (rtl, 0)) == REG
5127 && GET_CODE (XEXP (rtl, 1)) == CONST_INT));
5128}
5129
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. */
5138static dw_loc_descr_ref
5139mem_loc_descriptor (rtl)
5140 register rtx rtl;
5141{
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))
5148 {
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. */
5157
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;
5174
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;
5179
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;
5186
5187 case PLUS:
5188 if (is_based_loc (rtl))
5189 {
5190 mem_loc_result = based_loc_descr (
5191 reg_number (XEXP (rtl, 0)),
5192 INTVAL (XEXP (rtl, 1)));
5193 }
5194 else
5195 {
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));
5199 }
5200 break;
5201
5202 case CONST_INT:
5203 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
5204 break;
5205
5206 default:
5207 abort ();
5208 }
5209 return mem_loc_result;
5210}
5211
5212/* Output a proper Dwarf location descriptor for a variable or parameter
5213 which is either allocated in a register or in a memory location. For a
5214 register, we just generate an OP_REG and the register number. For a
5215 memory location we provide a Dwarf postfix expression describing how to
5216 generate the (dynamic) address of the object onto the address stack. */
5217static dw_loc_descr_ref
5218loc_descriptor (rtl)
5219 register rtx rtl;
5220{
5221 dw_loc_descr_ref loc_result = NULL;
5222 switch (GET_CODE (rtl))
5223 {
5224 case SUBREG:
5225
5226 /* The case of a subreg may arise when we have a local (register)
5227 variable or a formal (register) parameter which doesn't quite fill
5228 up an entire register. For now, just assume that it is
5229 legitimate to make the Dwarf info refer to the whole register which
5230 contains the given subreg. */
5231
5232 rtl = XEXP (rtl, 0);
5233 loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0);
5234 break;
5235
5236 case REG:
5237 loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0);
5238 break;
5239
5240 case MEM:
5241 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5242 break;
5243
5244 default:
5245 abort (); /* Should never happen */
5246 }
5247 return loc_result;
5248}
5249
5250/* Given an unsigned value, round it up to the lowest multiple of `boundary'
5251 which is not less than the value itself. */
5252inline unsigned
5253ceiling (value, boundary)
5254 register unsigned value;
5255 register unsigned boundary;
5256{
5257 return (((value + boundary - 1) / boundary) * boundary);
5258}
5259
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. */
5264inline tree
5265field_type (decl)
5266 register tree decl;
5267{
5268 register tree type;
5269
5270 if (TREE_CODE (decl) == ERROR_MARK)
5271 return integer_type_node;
5272
5273 type = DECL_BIT_FIELD_TYPE (decl);
5274 if (type == NULL)
5275 type = TREE_TYPE (decl);
5276
5277 return type;
5278}
5279
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. */
5284inline unsigned
5285simple_type_align_in_bits (type)
5286 register tree type;
5287{
5288 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
5289}
5290
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. */
5296inline unsigned
5297simple_type_size_in_bits (type)
5298 register tree type;
5299{
5300 if (TREE_CODE (type) == ERROR_MARK)
5301 return BITS_PER_WORD;
5302 else
5303 {
5304 register tree type_size_tree = TYPE_SIZE (type);
5305
5306 if (TREE_CODE (type_size_tree) != INTEGER_CST)
5307 return TYPE_ALIGN (type);
5308
5309 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
5310 }
5311}
5312
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). */
5319static unsigned
5320field_byte_offset (decl)
5321 register tree decl;
5322{
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;
5335
5336 if (TREE_CODE (decl) == ERROR_MARK)
5337 return 0;
5338
5339 if (TREE_CODE (decl) != FIELD_DECL)
5340 abort ();
5341
5342 type = field_type (decl);
5343
5344 bitpos_tree = DECL_FIELD_BITPOS (decl);
5345 field_size_tree = DECL_SIZE (decl);
5346
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);
5353
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);
5357
5358 type_size_in_bits = simple_type_size_in_bits (type);
5359
5360 type_align_in_bits = simple_type_align_in_bits (type);
5361 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
5362
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:
5372
5373 struct S { int field1; long long field2:31; };
5374
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). */
5401
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;
5405
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;
5410
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;
5413
5414 /* Compute the offset of the containing object in bytes. */
5415 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
5416
5417 return object_offset_in_bytes;
5418}
5419
5420
5421\f
5422/****************************** attributes *********************************/
5423
5424/* The following routines define various Dwarf attributes
5425 (and any data associated with them). */
5426
5427
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. */
5431static void
5432add_location_attribute (die, rtl)
5433 dw_die_ref die;
5434 register rtx rtl;
5435{
5436 dw_loc_descr_ref loc_descr = NULL;
5437
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))))
5456 {
5457 loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
5458 }
5459
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)
5465 {
5466 loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0));
5467 }
5468#endif
5469
5470 add_AT_loc (die, DW_AT_location, loc_descr);
5471}
5472
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). */
5491static void
5492add_data_member_location_attribute (die, decl)
5493 register dw_die_ref die;
5494 register tree decl;
5495{
61b32c02 5496 register unsigned long offset;
a3f97cbb
JW
5497 register dw_loc_descr_ref loc_descr;
5498 register enum dwarf_location_atom op;
5499
61b32c02
JM
5500 if (TREE_CODE (decl) == TREE_VEC)
5501 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
5502 else
5503 offset = field_byte_offset (decl);
5504
a3f97cbb
JW
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);
5517}
5518
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". */
5524static void
5525add_const_value_attribute (die, rtl)
5526 register dw_die_ref die;
5527 register rtx rtl;
5528{
5529 switch (GET_CODE (rtl))
5530 {
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;
5539
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;
5551
5552 case CONST_STRING:
5553 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
5554 break;
5555
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;
5561
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;
5577
5578 default:
5579 /* No other kinds of rtx should be possible here. */
5580 abort ();
5581 }
5582
5583}
5584
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. */
5595static void
5596add_location_or_const_value_attribute (die, decl)
5597 register dw_die_ref die;
5598 register tree decl;
5599{
5600 register rtx rtl;
5601 register tree declared_type;
5602 register tree passed_type;
5603
5604 if (TREE_CODE (decl) == ERROR_MARK)
5605 {
5606 return;
5607 }
5608 if ((TREE_CODE (decl) != VAR_DECL)
5609 && (TREE_CODE (decl) != PARM_DECL))
5610 {
5611 /* Should never happen. */
5612 abort ();
5613 return;
5614 }
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). */
5680
5681 /* Use DECL_RTL as the "location" unless we find something better. */
5682 rtl = DECL_RTL (decl);
5683
5684 if (TREE_CODE (decl) == PARM_DECL)
5685 {
5686 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
5687 {
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.
5692
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)
5696 {
5697 rtl = DECL_INCOMING_RTL (decl);
5698 }
5699 else if (!BYTES_BIG_ENDIAN)
5700 {
5701 if (TREE_CODE (declared_type) == INTEGER_TYPE)
5702 {
5703 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
5704 {
5705 rtl = DECL_INCOMING_RTL (decl);
5706 }
5707 }
5708 }
a3f97cbb
JW
5709 }
5710 }
61b32c02
JM
5711 if (rtl == NULL_RTX)
5712 return;
5713
a3f97cbb
JW
5714 switch (GET_CODE (rtl))
5715 {
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;
5726
5727 case MEM:
5728 case REG:
5729 case SUBREG:
5730 add_location_attribute (die, rtl);
5731 break;
5732
5733 default:
5734 abort (); /* Should never happen. */
5735 }
5736}
5737
5738/* Generate an DW_AT_name attribute given some string value to be included as
5739 the value of the attribute. */
5740inline void
5741add_name_attribute (die, name_string)
5742 register dw_die_ref die;
5743 register char *name_string;
5744{
5745 if (name_string && *name_string)
5746 {
5747 add_AT_string (die, DW_AT_name, name_string);
5748 }
5749}
5750
5751/* Given a tree node describing an array bound (either lower or upper) output
5752 a representation for that bound. */
5753static void
5754add_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;
5758{
5759 register dw_loc_descr_ref bound_loc = NULL;
5760 register unsigned bound_value = 0;
5761 switch (TREE_CODE (bound))
5762 {
5763 case ERROR_MARK:
5764 return;
5765
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))
5772 {
5773 add_AT_unsigned (subrange_die, bound_attr, bound_value);
5774 }
5775 break;
5776
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... */
5782
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)
5802 {
5803 bound_loc = mem_loc_descriptor (
5804 eliminate_regs (SAVE_EXPR_RTL (bound),
5805 0, NULL_RTX));
5806 }
5807 else
5808 {
5809 bound_loc = NULL;
5810 }
5811 add_AT_loc (subrange_die, bound_attr, bound_loc);
5812 break;
5813
5814 default:
5815 abort ();
5816 }
5817}
5818
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. */
5821static void
5822add_subscript_info (type_die, type)
5823 register dw_die_ref type_die;
5824 register tree type;
5825{
5826 register unsigned dimension_number;
5827 register tree lower, upper;
5828 register dw_die_ref subrange_die;
5829
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++)
5846 {
5847#endif
5848 register tree domain = TYPE_DOMAIN (type);
5849
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)
5855 {
5856 /* We have an array type with specified bounds. */
5857 lower = TYPE_MIN_VALUE (domain);
5858 upper = TYPE_MAX_VALUE (domain);
5859
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);
5864 }
5865 else
5866 {
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. */
5872
5873 /* define the (assumed) index type. */
5874 add_AT_die_ref (subrange_die, DW_AT_type, int_base_type_die);
5875
5876 /* Add the (assumed) lower bound (constant) value. */
5877 add_AT_unsigned (subrange_die, DW_AT_lower_bound, 0);
5878
5879 /* Add the (empty) location description for the upper bound. */
5880 add_AT_loc (subrange_die, DW_AT_upper_bound, NULL);
5881 }
5882#ifndef MIPS_DEBUGGING_INFO
5883 }
5884#endif
5885}
5886
5887static void
5888add_byte_size_attribute (die, tree_node)
5889 dw_die_ref die;
5890 register tree tree_node;
5891{
5892 register unsigned size;
5893
5894 switch (TREE_CODE (tree_node))
5895 {
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 ();
5914 }
5915
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. */
5920
5921 add_AT_unsigned (die, DW_AT_byte_size, size);
5922}
5923
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.
5928
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).
5936
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). */
5940inline void
5941add_bit_offset_attribute (die, decl)
5942 register dw_die_ref die;
5943 register tree decl;
5944{
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;
5952
5953 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
5954 assert (type); /* Must be a bit field. */
5955
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)
5960 {
5961 return;
5962 }
5963 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5964
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;
5972
5973 if (!BYTES_BIG_ENDIAN)
5974 {
5975 highest_order_field_bit_offset
5976 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
5977
5978 highest_order_object_bit_offset += simple_type_size_in_bits (type);
5979 }
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);
5984
5985 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
5986}
5987
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. */
5990inline void
5991add_bit_size_attribute (die, decl)
5992 register dw_die_ref die;
5993 register tree decl;
5994{
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)));
5999}
6000
a3f97cbb
JW
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. */
6003inline void
6004add_prototyped_attribute (die, func_type)
6005 register dw_die_ref die;
6006 register tree func_type;
6007{
6008 if ((strcmp (language_string, "GNU C") == 0)
6009 && (TYPE_ARG_TYPES (func_type) != NULL))
6010 {
6011 add_AT_flag (die, DW_AT_prototyped, 0);
6012 }
6013}
6014
6015
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. */
6019inline void
6020add_abstract_origin_attribute (die, origin)
6021 register dw_die_ref die;
6022 register tree origin;
6023{
6024 dw_die_ref origin_die = NULL;
6025 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
6026 {
6027 origin_die = lookup_decl_die (origin);
6028 }
6029 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
6030 {
6031 origin_die = lookup_type_die (origin);
6032 }
6033 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
6034}
6035
bdb669cb
JM
6036/* We do not currently support the pure_virtual attribute. */
6037
a3f97cbb
JW
6038inline void
6039add_pure_or_virtual_attribute (die, func_decl)
6040 register dw_die_ref die;
6041 register tree func_decl;
6042{
6043 if (DECL_VIRTUAL_P (func_decl))
6044 {
bdb669cb 6045 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
61b32c02
JM
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))));
a3f97cbb
JW
6048 }
6049}
6050\f
6051/********************* utility routines for DIEs *************************/
6052
6053/* Add an DW_AT_name attribute and source coordinate attribute for the
6054 given decl, but only if it actually has a name. */
6055static void
6056add_name_and_src_coords_attributes (die, decl)
6057 register dw_die_ref die;
6058 register tree decl;
6059{
61b32c02 6060 register tree decl_name;
a3f97cbb 6061 register unsigned file_index;
273dbe67 6062 if (TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
61b32c02
JM
6063 decl_name = DECL_ASSEMBLER_NAME (decl);
6064 else
6065 decl_name = DECL_NAME (decl);
6066
a3f97cbb
JW
6067 if (decl_name && IDENTIFIER_POINTER (decl_name))
6068 {
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));
6073 }
6074}
6075
6076/* Push a new declaration scope. */
6077static void
6078push_decl_scope (scope)
6079 tree scope;
6080{
6081 /* Make room in the decl_scope_table, if necessary. */
6082 if (decl_scope_table_allocated == decl_scope_depth)
6083 {
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));
6087 }
6088 decl_scope_table[decl_scope_depth++] = scope;
6089}
6090
6091/* Return the DIE for the scope the immediately contains this declaration. */
6092static dw_die_ref
ab72d377
JM
6093scope_die_for (t, context_die)
6094 register tree t;
a3f97cbb
JW
6095 register dw_die_ref context_die;
6096{
6097 register dw_die_ref scope_die = NULL;
6098 register tree containing_scope;
6099 register unsigned long i;
6100
6101 /* Walk back up the declaration tree looking for a place to define
6102 this type. */
ab72d377
JM
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);
6109
a3f97cbb
JW
6110 if (containing_scope == NULL)
6111 {
6112 scope_die = comp_unit_die;
6113 }
6114 else
6115 {
ab72d377
JM
6116 for (i = decl_scope_depth, scope_die = context_die;
6117 i > 0 && decl_scope_table[i - 1] != containing_scope;
7d4440be
JM
6118 scope_die = scope_die->die_parent, --i)
6119 /* nothing */ ;
ab72d377 6120 if (i == 0)
a3f97cbb 6121 {
ab72d377
JM
6122 assert (scope_die == comp_unit_die);
6123 assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't');
6124 assert (TREE_ASM_WRITTEN (containing_scope));
a3f97cbb
JW
6125 }
6126 }
6127 return scope_die;
6128}
6129
6130/* Pop a declaration scope. */
6131inline void
6132pop_decl_scope ()
6133{
6134 assert (decl_scope_depth > 0);
6135 --decl_scope_depth;
6136}
6137
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. */
6141static void
6142add_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;
6148{
6149 register enum tree_code code = TREE_CODE (type);
a3f97cbb
JW
6150 register dw_die_ref type_die = NULL;
6151
6152 if (code == ERROR_MARK)
6153 {
6154 return;
6155 }
6156
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)
6161 {
6162 return;
6163 }
6164
a3f97cbb
JW
6165 type_die = modified_type_die (type,
6166 decl_const || TYPE_READONLY (type),
6167 decl_volatile || TYPE_VOLATILE (type),
ab72d377 6168 context_die);
a3f97cbb
JW
6169 if (type_die != NULL)
6170 {
6171 add_AT_die_ref (object_die, DW_AT_type, type_die);
6172 }
6173}
6174
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. */
6178static char *
6179type_tag (type)
6180 register tree type;
6181{
6182 register char *name = 0;
6183
6184 if (TYPE_NAME (type) != 0)
6185 {
6186 register tree t = 0;
6187
6188 /* Find the IDENTIFIER_NODE for the type name. */
6189 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
6190 t = TYPE_NAME (type);
bdb669cb 6191
a3f97cbb
JW
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
bdb669cb 6194 involved. */
a3f97cbb
JW
6195 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
6196 t = DECL_NAME (TYPE_NAME (type));
bdb669cb 6197
a3f97cbb
JW
6198 /* Now get the name as a string, or invent one. */
6199 if (t != 0)
6200 {
6201 name = IDENTIFIER_POINTER (t);
6202 }
6203 }
6204 return (name == 0 || *name == '\0') ? 0 : name;
6205}
6206
6207/* Return the type associated with a data member, make a special check
6208 for bit field types. */
6209inline tree
6210member_declared_type (member)
6211 register tree member;
6212{
6213 return (DECL_BIT_FIELD_TYPE (member))
6214 ? DECL_BIT_FIELD_TYPE (member)
6215 : TREE_TYPE (member);
6216}
6217
d291dd49 6218/* Get the decl's label, as described by its RTL. This may be different
a3f97cbb
JW
6219 from the DECL_NAME name used in the source file. */
6220static char *
d291dd49 6221decl_start_label (decl)
a3f97cbb
JW
6222 register tree decl;
6223{
6224 rtx x;
6225 char *fnname;
6226 x = DECL_RTL (decl);
6227 if (GET_CODE (x) != MEM)
6228 {
6229 abort ();
6230 }
6231 x = XEXP (x, 0);
6232 if (GET_CODE (x) != SYMBOL_REF)
6233 {
6234 abort ();
6235 }
6236 fnname = XSTR (x, 0);
6237 return fnname;
6238}
6239\f
6240/******************************* DIE Generation *************************/
6241
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(). */
6245
6246static void
6247gen_array_type_die (type, context_die)
6248 register tree type;
6249 register dw_die_ref context_die;
6250{
ab72d377
JM
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);
a3f97cbb 6253 register tree element_type;
bdb669cb 6254
a3f97cbb
JW
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
6265
6266 add_subscript_info (array_die, type);
6267
6268 equate_type_number_to_die (type, array_die);
6269
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)
6278 {
6279 element_type = TREE_TYPE (element_type);
6280 }
6281#endif
6282 gen_type_die (element_type, context_die);
6283
6284 add_type_attribute (array_die, element_type, 0, 0, context_die);
6285}
6286
6287static void
6288gen_set_type_die (type, context_die)
6289 register tree type;
6290 register dw_die_ref context_die;
6291{
ab72d377
JM
6292 register dw_die_ref type_die = new_die
6293 (DW_TAG_set_type, scope_die_for (type, context_die));
a3f97cbb 6294 equate_type_number_to_die (type, type_die);
a3f97cbb
JW
6295 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
6296}
6297
6298static void
6299gen_entry_point_die (decl, context_die)
6300 register tree decl;
6301 register dw_die_ref context_die;
6302{
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)
6306 {
6307 add_abstract_origin_attribute (decl_die, origin);
6308 }
6309 else
6310 {
6311 add_name_and_src_coords_attributes (decl_die, decl);
a3f97cbb
JW
6312 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
6313 0, 0, context_die);
6314 }
6315 if (DECL_ABSTRACT (decl))
6316 {
6317 equate_decl_number_to_die (decl, decl_die);
6318 }
6319 else
6320 {
d291dd49 6321 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
a3f97cbb
JW
6322 }
6323}
6324
6325/* Generate a DIE to represent an inlined instance of an enumeration type. */
6326static void
6327gen_inlined_enumeration_type_die (type, context_die)
6328 register tree type;
6329 register dw_die_ref context_die;
6330{
6331 register dw_die_ref type_die;
6332 type_die = new_die (DW_TAG_enumeration_type,
ab72d377 6333 scope_die_for (type, context_die));
a3f97cbb
JW
6334 assert (TREE_ASM_WRITTEN (type));
6335 add_abstract_origin_attribute (type_die, type);
6336}
6337
6338/* Generate a DIE to represent an inlined instance of a structure type. */
6339static void
6340gen_inlined_structure_type_die (type, context_die)
6341 register tree type;
6342 register dw_die_ref context_die;
6343{
6344 register dw_die_ref type_die;
6345 type_die = new_die (DW_TAG_structure_type,
ab72d377 6346 scope_die_for (type, context_die));
a3f97cbb
JW
6347 assert (TREE_ASM_WRITTEN (type));
6348 add_abstract_origin_attribute (type_die, type);
6349}
6350
6351/* Generate a DIE to represent an inlined instance of a union type. */
6352static void
6353gen_inlined_union_type_die (type, context_die)
6354 register tree type;
6355 register dw_die_ref context_die;
6356{
6357 register dw_die_ref type_die;
6358 type_die = new_die (DW_TAG_union_type,
ab72d377 6359 scope_die_for (type, context_die));
a3f97cbb
JW
6360 assert (TREE_ASM_WRITTEN (type));
6361 add_abstract_origin_attribute (type_die, type);
6362}
6363
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
273dbe67
JM
6366 enumerated type name/value is listed as a child of the enumerated type
6367 DIE. */
a3f97cbb 6368static void
273dbe67 6369gen_enumeration_type_die (type, context_die)
a3f97cbb 6370 register tree type;
a3f97cbb
JW
6371 register dw_die_ref context_die;
6372{
273dbe67
JM
6373 register dw_die_ref type_die = lookup_type_die (type);
6374
a3f97cbb
JW
6375 if (type_die == NULL)
6376 {
6377 type_die = new_die (DW_TAG_enumeration_type,
ab72d377 6378 scope_die_for (type, context_die));
a3f97cbb
JW
6379 equate_type_number_to_die (type, type_die);
6380 add_name_attribute (type_die, type_tag (type));
a3f97cbb 6381 }
273dbe67
JM
6382 else if (! TYPE_SIZE (type))
6383 return;
6384 else
6385 remove_AT (type_die, DW_AT_declaration);
6386
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))
a3f97cbb 6391 {
273dbe67
JM
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))
a3f97cbb 6396 {
273dbe67
JM
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,
a3f97cbb 6401 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
a3f97cbb
JW
6402 }
6403 }
273dbe67
JM
6404 else
6405 add_AT_flag (type_die, DW_AT_declaration, 1);
a3f97cbb
JW
6406}
6407
6408
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. */
6420static void
6421gen_formal_parameter_die (node, context_die)
6422 register tree node;
6423 register dw_die_ref context_die;
6424{
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)))
6429 {
6430 /* We were called with some kind of a ..._DECL node. */
6431 case 'd':
6432 origin = decl_ultimate_origin (node);
6433 if (origin != NULL)
6434 {
6435 add_abstract_origin_attribute (parm_die, origin);
6436 }
6437 else
6438 {
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);
bdb669cb
JM
6444 if (DECL_ARTIFICIAL (node))
6445 add_AT_flag (parm_die, DW_AT_artificial, 1);
a3f97cbb
JW
6446 }
6447 if (DECL_ABSTRACT (node))
6448 {
6449 equate_decl_number_to_die (node, parm_die);
6450 }
6451 else
6452 {
6453 add_location_or_const_value_attribute (parm_die, node);
6454 }
6455 break;
6456
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;
6461
6462 /* Should never happen. */
6463 default:
6464 abort ();
6465 }
6466}
6467
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. */
6470static void
6471gen_unspecified_parameters_die (decl_or_type, context_die)
6472 register tree decl_or_type;
6473 register dw_die_ref context_die;
6474{
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))
6488 {
6489 add_name_attribute (parm_die, "...");
6490 add_AT_die_ref (parm_die, DW_AT_type, int_base_type_die);
6491 }
6492}
6493
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. */
6502static void
6503gen_formal_types_die (function_or_method_type, context_die)
6504 register tree function_or_method_type;
6505 register dw_die_ref context_die;
6506{
6507 register tree link;
6508 register tree formal_type = NULL;
6509 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
6510
bdb669cb 6511#if 0
a3f97cbb
JW
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);
bdb669cb 6522#endif
a3f97cbb
JW
6523
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))
6527 {
6528 formal_type = TREE_VALUE (link);
6529 if (formal_type == void_type_node)
6530 break;
6531
6532 /* Output a (nameless) DIE to represent the formal parameter itself. */
6533 gen_formal_parameter_die (formal_type, context_die);
6534 }
6535
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);
6540
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))
6546 {
6547 formal_type = TREE_VALUE (link);
6548 if (formal_type == void_type_node)
6549 break;
6550
b50c02f9 6551 gen_type_die (formal_type, context_die);
a3f97cbb
JW
6552 }
6553}
6554
6555/* Generate a DIE to represent a declared function (either file-scope or
6556 block-local). */
6557static void
6558gen_subprogram_die (decl, context_die)
6559 register tree decl;
6560 register dw_die_ref context_die;
6561{
6562 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
6563 register tree origin = decl_ultimate_origin (decl);
4b674448 6564 register dw_die_ref subr_die;
a3f97cbb
JW
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;
bdb669cb 6571 dw_die_ref old_die = lookup_decl_die (decl);
a3f97cbb 6572
a3f97cbb
JW
6573 if (origin != NULL)
6574 {
4b674448 6575 subr_die = new_die (DW_TAG_subprogram, context_die);
a3f97cbb
JW
6576 add_abstract_origin_attribute (subr_die, origin);
6577 }
bdb669cb
JM
6578 else if (old_die)
6579 {
4b674448
JM
6580 register unsigned file_index
6581 = lookup_filename (DECL_SOURCE_FILE (decl));
bdb669cb
JM
6582 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
6583 abort ();
4b674448
JM
6584
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)))
bdb669cb 6590 {
4b674448
JM
6591 subr_die = old_die;
6592
6593 /* Clear out the declaration attribute and the parm types. */
6594 remove_AT (subr_die, DW_AT_declaration);
6595 remove_children (subr_die);
6596 }
6597 else
6598 {
6599 subr_die = new_die (DW_TAG_subprogram, context_die);
6600 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
bdb669cb
JM
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));
6607 }
6608 }
a3f97cbb
JW
6609 else
6610 {
ab72d377
JM
6611 subr_die = new_die (DW_TAG_subprogram,
6612 scope_die_for (decl, context_die));
273dbe67
JM
6613 if (TREE_PUBLIC (decl))
6614 add_AT_flag (subr_die, DW_AT_external, 1);
a3f97cbb 6615 add_name_and_src_coords_attributes (subr_die, decl);
ba7b35df 6616 type = TREE_TYPE (decl);
a3f97cbb 6617 add_prototyped_attribute (subr_die, type);
a3f97cbb
JW
6618 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
6619 add_pure_or_virtual_attribute (subr_die, decl);
273dbe67
JM
6620 if (DECL_ARTIFICIAL (decl))
6621 add_AT_flag (subr_die, DW_AT_artificial, 1);
bdb669cb
JM
6622
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);
a3f97cbb 6629 }
61b32c02 6630 if (DECL_ABSTRACT (decl))
a3f97cbb 6631 {
61b32c02
JM
6632 if (DECL_DEFER_OUTPUT (decl))
6633 {
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);
6639 }
6640 else if (DECL_INLINE (decl))
6641 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
6642 else
6643 abort ();
6644
a3f97cbb
JW
6645 equate_decl_number_to_die (decl, subr_die);
6646 }
61b32c02
JM
6647 else if (!DECL_INITIAL (decl))
6648 equate_decl_number_to_die (decl, subr_die);
a3f97cbb
JW
6649 else if (!DECL_EXTERNAL (decl))
6650 {
ba7b35df
JW
6651 if (origin == NULL)
6652 equate_decl_number_to_die (decl, subr_die);
7d4440be
JM
6653 sprintf (label_id, FUNC_BEGIN_LABEL_FMT, current_funcdef_number);
6654 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
a3f97cbb
JW
6655 sprintf (label_id, FUNC_END_LABEL_FMT, current_funcdef_number);
6656 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
6657
d291dd49
JM
6658 add_pubname (decl, subr_die);
6659 add_arange (decl, subr_die);
6660
a3f97cbb
JW
6661#ifdef MIPS_DEBUGGING_INFO
6662
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
6666
810429b7
JM
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);
a3f97cbb 6673 assert (fp_reg >= 0 && fp_reg <= 31);
810429b7 6674 fp_loc = new_loc_descr (DW_OP_reg0 + fp_reg);
a3f97cbb
JW
6675 add_AT_loc (subr_die, DW_AT_frame_base, fp_loc);
6676
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
6683
6684 }
6685
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. */
6695
ab72d377 6696 push_decl_scope (decl);
a3f97cbb
JW
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)
6701 {
6702 gen_formal_types_die (TREE_TYPE (decl), subr_die);
6703 }
6704 else
6705 {
6706 /* Generate DIEs to represent all known formal parameters */
6707 register tree arg_decls = DECL_ARGUMENTS (decl);
6708 register tree parm;
6709
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))
6713 {
6714 if (TREE_CODE (parm) == PARM_DECL)
6715 {
6716 if (DECL_NAME (parm) &&
6717 !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
6718 "__builtin_va_alist"))
6719 {
6720 gen_unspecified_parameters_die (parm, subr_die);
6721 }
6722 else
6723 {
6724 gen_decl_die (parm, subr_die);
6725 }
6726 }
6727 }
6728
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)
6737 {
6738 /* this is the prototyped case, check for ... */
6739 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
6740 {
6741 gen_unspecified_parameters_die (decl, subr_die);
6742 }
6743 }
6744 else
6745 {
6746 /* this is unprotoyped, check for undefined (just declaration) */
6747 if (!DECL_INITIAL (decl))
6748 {
6749 gen_unspecified_parameters_die (decl, subr_die);
6750 }
6751 }
6752 }
6753
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);
6757
d7248bff
JM
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. */
a3f97cbb 6772 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
7e23cb16
JM
6773 {
6774 current_function_has_inlines = 0;
6775 decls_for_scope (outer_scope, subr_die, 0);
ce61cc73 6776#if 0 && defined (MIPS_DEBUGGING_INFO)
7e23cb16
JM
6777 if (current_function_has_inlines)
6778 {
6779 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
6780 if (! comp_unit_has_inlines)
6781 {
6782 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
6783 comp_unit_has_inlines = 1;
6784 }
6785 }
6786#endif
6787 }
ab72d377 6788 pop_decl_scope ();
a3f97cbb
JW
6789}
6790
6791/* Generate a DIE to represent a declared data object. */
6792static void
6793gen_variable_die (decl, context_die)
6794 register tree decl;
6795 register dw_die_ref context_die;
6796{
6797 register tree origin = decl_ultimate_origin (decl);
6798 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
bdb669cb
JM
6799 dw_die_ref old_die = lookup_decl_die (decl);
6800
a3f97cbb
JW
6801 if (origin != NULL)
6802 {
6803 add_abstract_origin_attribute (var_die, origin);
6804 }
bdb669cb
JM
6805 else if (old_die)
6806 {
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))
6811 {
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));
6820 }
6821 }
a3f97cbb
JW
6822 else
6823 {
6824 add_name_and_src_coords_attributes (var_die, decl);
a3f97cbb
JW
6825 add_type_attribute (var_die, TREE_TYPE (decl),
6826 TREE_READONLY (decl),
6827 TREE_THIS_VOLATILE (decl), context_die);
273dbe67
JM
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);
a3f97cbb
JW
6832 }
6833 if (DECL_ABSTRACT (decl))
6834 {
6835 equate_decl_number_to_die (decl, var_die);
6836 }
6837 else if (!DECL_EXTERNAL (decl))
6838 {
7e23cb16
JM
6839 if (TREE_STATIC (decl))
6840 equate_decl_number_to_die (decl, var_die);
a3f97cbb 6841 add_location_or_const_value_attribute (var_die, decl);
d291dd49 6842 add_pubname (decl, var_die);
a3f97cbb 6843 }
bdb669cb
JM
6844 else if (decl_class_context (decl))
6845 {
6846 equate_decl_number_to_die (decl, var_die);
6847 add_AT_flag (var_die, DW_AT_declaration, 1);
6848 }
a3f97cbb
JW
6849}
6850
6851/* Generate a DIE to represent a label identifier. */
6852static void
6853gen_label_die (decl, context_die)
6854 register tree decl;
6855 register dw_die_ref context_die;
6856{
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)
6862 {
6863 add_abstract_origin_attribute (lbl_die, origin);
6864 }
6865 else
6866 {
6867 add_name_and_src_coords_attributes (lbl_die, decl);
6868 }
6869 if (DECL_ABSTRACT (decl))
6870 {
6871 equate_decl_number_to_die (decl, lbl_die);
6872 }
6873 else
6874 {
6875 insn = DECL_RTL (decl);
6876 if (GET_CODE (insn) == CODE_LABEL)
6877 {
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))
6884 {
6885 abort (); /* Should never happen. */
6886 }
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);
6890 }
6891 }
6892}
6893
6894/* Generate a DIE for a lexical block. */
6895static void
d7248bff 6896gen_lexical_block_die (stmt, context_die, depth)
a3f97cbb
JW
6897 register tree stmt;
6898 register dw_die_ref context_die;
d7248bff 6899 int depth;
a3f97cbb
JW
6900{
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))
6904 {
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);
6909 }
7d4440be 6910 push_decl_scope (stmt);
d7248bff 6911 decls_for_scope (stmt, stmt_die, depth);
7d4440be 6912 pop_decl_scope ();
a3f97cbb
JW
6913}
6914
6915/* Generate a DIE for an inlined subprogram. */
6916static void
d7248bff 6917gen_inlined_subroutine_die (stmt, context_die, depth)
a3f97cbb
JW
6918 register tree stmt;
6919 register dw_die_ref context_die;
d7248bff 6920 int depth;
a3f97cbb 6921{
a3f97cbb
JW
6922 if (!BLOCK_ABSTRACT (stmt))
6923 {
d7248bff 6924 register dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine,
7e23cb16 6925 context_die);
ab72d377 6926 register tree decl = block_ultimate_origin (stmt);
d7248bff 6927 char label[MAX_ARTIFICIAL_LABEL_BYTES];
ab72d377 6928 add_abstract_origin_attribute (subr_die, decl);
a3f97cbb
JW
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);
ab72d377 6933 push_decl_scope (decl);
d7248bff 6934 decls_for_scope (stmt, subr_die, depth);
ab72d377 6935 pop_decl_scope ();
7e23cb16 6936 current_function_has_inlines = 1;
a3f97cbb 6937 }
a3f97cbb
JW
6938}
6939
6940/* Generate a DIE for a field in a record, or structure. */
6941static void
6942gen_field_die (decl, context_die)
6943 register tree decl;
6944 register dw_die_ref context_die;
6945{
6946 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
6947 add_name_and_src_coords_attributes (decl_die, decl);
a3f97cbb
JW
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))
6953 {
6954 add_byte_size_attribute (decl_die, decl);
6955 add_bit_size_attribute (decl_die, decl);
6956 add_bit_offset_attribute (decl_die, decl);
6957 }
6958 add_data_member_location_attribute (decl_die, decl);
273dbe67
JM
6959 if (DECL_ARTIFICIAL (decl))
6960 add_AT_flag (decl_die, DW_AT_artificial, 1);
a3f97cbb
JW
6961}
6962
ab72d377
JM
6963#if 0
6964/* Don't generate either pointer_type DIEs or reference_type DIEs here.
6965 Use modified_type_die instead.
a3f97cbb
JW
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. */
6968static void
6969gen_pointer_type_die (type, context_die)
6970 register tree type;
6971 register dw_die_ref context_die;
6972{
273dbe67
JM
6973 register dw_die_ref ptr_die = new_die
6974 (DW_TAG_pointer_type, scope_die_for (type, context_die));
a3f97cbb 6975 equate_type_number_to_die (type, ptr_die);
a3f97cbb 6976 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
ab72d377 6977 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
a3f97cbb
JW
6978}
6979
ab72d377
JM
6980/* Don't generate either pointer_type DIEs or reference_type DIEs here.
6981 Use modified_type_die instead.
a3f97cbb
JW
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. */
6984static void
6985gen_reference_type_die (type, context_die)
6986 register tree type;
6987 register dw_die_ref context_die;
6988{
273dbe67
JM
6989 register dw_die_ref ref_die = new_die
6990 (DW_TAG_reference_type, scope_die_for (type, context_die));
a3f97cbb 6991 equate_type_number_to_die (type, ref_die);
a3f97cbb 6992 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
ab72d377 6993 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
a3f97cbb 6994}
ab72d377 6995#endif
a3f97cbb
JW
6996
6997/* Generate a DIE for a pointer to a member type. */
6998static void
6999gen_ptr_to_mbr_type_die (type, context_die)
7000 register tree type;
7001 register dw_die_ref context_die;
7002{
ab72d377 7003 register dw_die_ref ptr_die = new_die
273dbe67 7004 (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
a3f97cbb 7005 equate_type_number_to_die (type, ptr_die);
a3f97cbb 7006 add_AT_die_ref (ptr_die, DW_AT_containing_type,
bdb669cb 7007 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
a3f97cbb
JW
7008 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7009}
7010
7011/* Generate the DIE for the compilation unit. */
7012static void
7013gen_compile_unit_die (main_input_filename)
7014 register char *main_input_filename;
7015{
7016 char producer[250];
a3f97cbb
JW
7017 char *wd = getpwd ();
7018
7019 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
7020
bdb669cb
JM
7021 add_name_attribute (comp_unit_die, main_input_filename);
7022
7023 if (wd)
a3f97cbb 7024 {
bdb669cb 7025 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
a3f97cbb
JW
7026 }
7027
7028 sprintf (producer, "%s %s", language_string, version_string);
7029
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)
7038 {
bdb669cb 7039 strcat (producer, " -g");
a3f97cbb
JW
7040 }
7041
7042#endif
7043
7044 add_AT_string (comp_unit_die, DW_AT_producer, producer);
7045 if (strcmp (language_string, "GNU C++") == 0)
7046 {
7047 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
7048 }
7049 else if (strcmp (language_string, "GNU Ada") == 0)
7050 {
7051 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
7052 }
7053 else if (flag_traditional)
7054 {
7055 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
7056 }
7057 else
7058 {
7059 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
7060 }
e90b62db 7061 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
a3f97cbb 7062 {
e90b62db 7063 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
a3f97cbb
JW
7064 }
7065}
7066
7067/* Generate a DIE for a string type. */
7068static void
7069gen_string_type_die (type, context_die)
7070 register tree type;
7071 register dw_die_ref context_die;
7072{
ab72d377
JM
7073 register dw_die_ref type_die = new_die
7074 (DW_TAG_string_type, scope_die_for (type, context_die));
bdb669cb 7075 equate_type_number_to_die (type, type_die);
a3f97cbb
JW
7076
7077 /* Fudge the string length attribute for now. */
7078
7079 /* TODO: add string length info.
7080 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
7081 bound_representation (upper_bound, 0, 'u'); */
7082}
7083
61b32c02
JM
7084/* Generate the DIE for a base class. */
7085static void
7086gen_inheritance_die (binfo, context_die)
7087 register tree binfo;
7088 register dw_die_ref context_die;
7089{
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);
7099}
7100
a3f97cbb
JW
7101/* Genearate a DIE for a class member. */
7102static void
7103gen_member_die (type, context_die)
7104 register tree type;
7105 register dw_die_ref context_die;
7106{
61b32c02 7107 register tree member;
a3f97cbb
JW
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. */
7120
61b32c02
JM
7121 /* First output info about the base classes. */
7122 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
a3f97cbb 7123 {
61b32c02
JM
7124 register tree bases = TYPE_BINFO_BASETYPES (type);
7125 register int n_bases = TREE_VEC_LENGTH (bases);
7126 register int i;
7127
7128 for (i = 0; i < n_bases; i++)
7129 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
a3f97cbb
JW
7130 }
7131
61b32c02
JM
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);
7135
a3f97cbb 7136 /* Now output info about the function members (if any). */
61b32c02
JM
7137 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
7138 gen_decl_die (member, context_die);
a3f97cbb
JW
7139}
7140
7141/* Generate a DIE for a structure or union type. */
7142static void
273dbe67 7143gen_struct_or_union_type_die (type, context_die)
a3f97cbb 7144 register tree type;
a3f97cbb
JW
7145 register dw_die_ref context_die;
7146{
273dbe67
JM
7147 register dw_die_ref type_die = lookup_type_die (type);
7148
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. */
a3f97cbb 7155 {
273dbe67 7156 register dw_die_ref old_die = type_die;
a3f97cbb
JW
7157 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
7158 ? DW_TAG_structure_type : DW_TAG_union_type,
ab72d377 7159 scope_die_for (type, context_die));
a3f97cbb
JW
7160 equate_type_number_to_die (type, type_die);
7161 add_name_attribute (type_die, type_tag (type));
273dbe67
JM
7162 if (old_die)
7163 add_AT_die_ref (type_die, DW_AT_specification, old_die);
a3f97cbb 7164 }
4b674448 7165 else
273dbe67 7166 remove_AT (type_die, DW_AT_declaration);
a3f97cbb
JW
7167
7168 /* If this type has been completed, then give it a byte_size attribute and
7169 then give a list of members. */
273dbe67 7170 if (TYPE_SIZE (type))
a3f97cbb
JW
7171 {
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;
273dbe67
JM
7175 add_byte_size_attribute (type_die, type);
7176 push_decl_scope (type);
7177 gen_member_die (type, type_die);
7178 pop_decl_scope ();
a3f97cbb 7179 }
4b674448
JM
7180 else
7181 add_AT_flag (type_die, DW_AT_declaration, 1);
a3f97cbb
JW
7182}
7183
7184/* Generate a DIE for a subroutine _type_. */
7185static void
7186gen_subroutine_type_die (type, context_die)
7187 register tree type;
7188 register dw_die_ref context_die;
7189{
7190 register tree return_type = TREE_TYPE (type);
273dbe67
JM
7191 register dw_die_ref subr_die = new_die
7192 (DW_TAG_subroutine_type, scope_die_for (type, context_die));
a3f97cbb
JW
7193 equate_type_number_to_die (type, subr_die);
7194 add_prototyped_attribute (subr_die, type);
a3f97cbb
JW
7195 add_type_attribute (subr_die, return_type, 0, 0, context_die);
7196 gen_formal_types_die (type, context_die);
7197}
7198
7199/* Generate a DIE for a type definition */
7200static void
7201gen_typedef_die (decl, context_die)
7202 register tree decl;
7203 register dw_die_ref context_die;
7204{
7205 register tree origin = decl_ultimate_origin (decl);
7206 register dw_die_ref type_die;
ab72d377 7207 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
a3f97cbb
JW
7208 if (origin != NULL)
7209 {
7210 add_abstract_origin_attribute (type_die, origin);
7211 }
7212 else
7213 {
7214 add_name_and_src_coords_attributes (type_die, decl);
a3f97cbb
JW
7215 add_type_attribute (type_die, TREE_TYPE (decl),
7216 TREE_READONLY (decl),
7217 TREE_THIS_VOLATILE (decl),
7218 context_die);
7219 }
7220 if (DECL_ABSTRACT (decl))
7221 {
7222 equate_decl_number_to_die (decl, type_die);
7223 }
7224}
7225
7226/* Generate a type description DIE. */
7227static void
7228gen_type_die (type, context_die)
7229 register tree type;
7230 register dw_die_ref context_die;
7231{
a3f97cbb
JW
7232 if (type == 0 || type == error_mark_node)
7233 {
7234 return;
7235 }
7236
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);
7241
7242 if (TREE_ASM_WRITTEN (type))
7243 {
7244 return;
7245 }
7246
7247 switch (TREE_CODE (type))
7248 {
7249 case ERROR_MARK:
7250 break;
7251
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;
7258
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;
7269
7270 case SET_TYPE:
7271 gen_type_die (TYPE_DOMAIN (type), context_die);
7272 gen_set_type_die (type, context_die);
7273 break;
7274
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;
7279
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;
7285
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;
7291
7292 case ARRAY_TYPE:
7293 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
7294 {
7295 gen_type_die (TREE_TYPE (type), context_die);
7296 gen_string_type_die (type, context_die);
7297 }
7298 else
7299 {
7300 gen_array_type_die (type, context_die);
7301 }
7302 break;
7303
7304 case ENUMERAL_TYPE:
7305 case RECORD_TYPE:
7306 case UNION_TYPE:
7307 case QUAL_UNION_TYPE:
a3f97cbb 7308 if (TREE_CODE (type) == ENUMERAL_TYPE)
273dbe67 7309 gen_enumeration_type_die (type, context_die);
a3f97cbb 7310 else
273dbe67 7311 gen_struct_or_union_type_die (type, context_die);
4b674448
JM
7312
7313 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
7314 it up if it is ever completed. */
273dbe67 7315 if (TYPE_SIZE (type) == NULL_TREE)
4b674448 7316 return;
a3f97cbb
JW
7317 break;
7318
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;
7327
7328 case LANG_TYPE:
7329 /* No Dwarf representation currently defined. */
7330 break;
7331
7332 default:
7333 abort ();
7334 }
7335
7336 TREE_ASM_WRITTEN (type) = 1;
7337}
7338
7339/* Generate a DIE for a tagged type instantiation. */
7340static void
7341gen_tagged_type_instantiation_die (type, context_die)
7342 register tree type;
7343 register dw_die_ref context_die;
7344{
7345 if (type == 0 || type == error_mark_node)
7346 {
7347 return;
7348 }
7349
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));
7356
7357 switch (TREE_CODE (type))
7358 {
7359 case ERROR_MARK:
7360 break;
7361
7362 case ENUMERAL_TYPE:
7363 gen_inlined_enumeration_type_die (type, context_die);
7364 break;
7365
7366 case RECORD_TYPE:
7367 gen_inlined_structure_type_die (type, context_die);
7368 break;
7369
7370 case UNION_TYPE:
7371 case QUAL_UNION_TYPE:
7372 gen_inlined_union_type_die (type, context_die);
7373 break;
7374
7375 default:
7376 abort (); /* Should never happen. */
7377 }
7378}
7379
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. */
7382static void
d7248bff 7383gen_block_die (stmt, context_die, depth)
a3f97cbb
JW
7384 register tree stmt;
7385 register dw_die_ref context_die;
d7248bff 7386 int depth;
a3f97cbb
JW
7387{
7388 register int must_output_die = 0;
7389 register tree origin;
7390 register tree decl;
7391 register enum tree_code origin_code;
7392
7393 /* Ignore blocks never really used to make RTL. */
7394
7395 if (!stmt || !TREE_USED (stmt))
7396 {
7397 return;
7398 }
7399
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;
7407
7408 /* Determine if we need to output any Dwarf DIEs at all to represent this
7409 block. */
7410 if (origin_code == FUNCTION_DECL)
7411 {
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;
7415 }
7416 else
7417 {
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. */
d7248bff 7426 if (! is_body_block (origin ? origin : stmt))
a3f97cbb
JW
7427 {
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)
7431 {
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);
7435 }
7436 else
7437 {
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))
7442 {
7443 if (TREE_CODE (decl) == FUNCTION_DECL
7444 && DECL_INITIAL (decl))
7445 {
7446 must_output_die = 1;
7447 break;
7448 }
7449 }
7450 }
7451 }
7452 }
7453
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)
7462 {
7463 if (origin_code == FUNCTION_DECL)
7464 {
d7248bff 7465 gen_inlined_subroutine_die (stmt, context_die, depth);
a3f97cbb
JW
7466 }
7467 else
7468 {
d7248bff 7469 gen_lexical_block_die (stmt, context_die, depth);
a3f97cbb
JW
7470 }
7471 }
7472 else
d7248bff 7473 decls_for_scope (stmt, context_die, depth);
a3f97cbb
JW
7474}
7475
7476/* Generate all of the decls declared within a given scope and (recursively)
7477 all of it's sub-blocks. */
7478static void
d7248bff 7479decls_for_scope (stmt, context_die, depth)
a3f97cbb
JW
7480 register tree stmt;
7481 register dw_die_ref context_die;
d7248bff 7482 int depth;
a3f97cbb
JW
7483{
7484 register tree decl;
7485 register tree subblocks;
7486 /* Ignore blocks never really used to make RTL. */
7487 if (!stmt || !TREE_USED (stmt))
7488 {
7489 return;
7490 }
d7248bff 7491 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
a3f97cbb
JW
7492 {
7493 next_block_number++;
7494 }
7495
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))
7501 {
7502 gen_decl_die (decl, context_die);
7503 }
7504
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))
7510 {
d7248bff 7511 gen_block_die (subblocks, context_die, depth + 1);
a3f97cbb
JW
7512 }
7513}
7514
7515/* Generate Dwarf debug information for a decl described by DECL. */
7516static void
7517gen_decl_die (decl, context_die)
7518 register tree decl;
7519 register dw_die_ref context_die;
7520{
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;
7526
7527 if (TREE_CODE (decl) == ERROR_MARK)
7528 {
7529 return;
7530 }
7531
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)
7538 {
7539 return;
7540 }
7541
a3f97cbb
JW
7542 switch (TREE_CODE (decl))
7543 {
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;
7548
7549 case FUNCTION_DECL:
7550 /* If we are in terse mode, don't output any DIEs to represent mere
bdb669cb
JM
7551 function declarations, unless they are class members. */
7552 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE)
a3f97cbb
JW
7553 {
7554 break;
7555 }
bdb669cb 7556
a3f97cbb
JW
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);
7560
7561 /* Now output a DIE to represent the function itself. */
7562 gen_subprogram_die (decl, context_die);
7563 break;
7564
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)
7572 {
29b396f7
JM
7573 if ((DECL_NAME (decl) != NULL
7574 || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
7575 && ! DECL_ARTIFICIAL (decl))
a3f97cbb
JW
7576 {
7577 break;
7578 }
7579 }
7580
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))
7589 {
7590 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
7591 break;
7592 }
7593 gen_type_die (TREE_TYPE (decl), context_die);
7594
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.
bdb669cb
JM
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))
a3f97cbb
JW
7602 {
7603 /* Output a DIE to represent the typedef itself. */
7604 gen_typedef_die (decl, context_die);
7605 }
7606 break;
7607
7608 case LABEL_DECL:
7609 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7610 {
7611 gen_label_die (decl, context_die);
7612 }
7613 break;
7614
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)
7619 {
7620 break;
7621 }
7622
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);
7626
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)
7633 {
7634 gen_formal_parameter_die (decl, context_die);
7635 }
7636 else
7637 {
7638 gen_variable_die (decl, context_die);
7639 }
7640 break;
7641
7642 case FIELD_DECL:
7643 /* Ignore the nameless fields that are used to skip bits. */
7644 if (DECL_NAME (decl) != 0)
7645 {
7646 gen_type_die (member_declared_type (decl), context_die);
7647 gen_field_die (decl, context_die);
7648 }
7649 break;
7650
7651 case PARM_DECL:
7652 gen_type_die (TREE_TYPE (decl), context_die);
7653 gen_formal_parameter_die (decl, context_die);
7654 break;
7655
7656 default:
7657 abort ();
7658 }
a3f97cbb
JW
7659}
7660\f
7661/***************** Debug Information Generation Hooks ***********************/
7662void
7663dwarfout_file_scope_decl (decl, set_finalizing)
7664 register tree decl;
7665 register int set_finalizing;
7666{
7667 if (TREE_CODE (decl) == ERROR_MARK)
7668 {
7669 return;
7670 }
7671
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))
7680 {
7681 if (TREE_CODE (decl) == FUNCTION_DECL
7682 && DECL_INITIAL (decl) != NULL)
7683 {
7684 abort ();
7685 }
7686 return;
7687 }
7688
7689 switch (TREE_CODE (decl))
7690 {
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))
7696 {
7697 return;
7698 }
7699
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
273dbe67 7721 to generate DWARF for them anyway. Note that the C++ front-end also
a3f97cbb
JW
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)
7726 {
7727 return;
7728 }
7729 break;
7730
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))
7741 {
7742 return;
7743 }
7744
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)
7748 {
7749 return;
7750 }
7751 break;
7752
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)))
7765 {
7766 return;
7767 }
7768
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)
7775 {
29b396f7
JM
7776 if ((DECL_NAME (decl) != NULL
7777 || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
7778 && ! DECL_ARTIFICIAL (decl))
a3f97cbb
JW
7779 {
7780 return;
7781 }
7782 }
7783 break;
7784
7785 default:
7786 return;
7787 }
7788
a3f97cbb
JW
7789 gen_decl_die (decl, comp_unit_die);
7790
7791 if (TREE_CODE (decl) == FUNCTION_DECL
7792 && DECL_INITIAL (decl) != NULL)
7793 {
7794 current_funcdef_number++;
7795 }
7796
7797}
7798
7799/* Output a marker (i.e. a label) for the beginning of the generated code for
7800 a lexical block. */
7801void
7802dwarfout_begin_block (blocknum)
7803 register unsigned blocknum;
7804{
7805 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7806
7807 function_section (current_function_decl);
7808 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
7809 ASM_OUTPUT_LABEL (asm_out_file, label);
7810}
7811
7812/* Output a marker (i.e. a label) for the end of the generated code for a
7813 lexical block. */
7814void
7815dwarfout_end_block (blocknum)
7816 register unsigned blocknum;
7817{
7818 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7819
7820 function_section (current_function_decl);
7821 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
7822 ASM_OUTPUT_LABEL (asm_out_file, label);
7823}
7824
7825/* Output a marker (i.e. a label) at a point in the assembly code which
7826 corresponds to a given source level label. */
7827void
7828dwarfout_label (insn)
7829 register rtx insn;
7830{
7831 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7832 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7833 {
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);
7838 }
7839}
7840
d291dd49
JM
7841/* Output a marker (i.e. a label) for the beginning of a function, before
7842 the prologue. */
a3f97cbb 7843void
d291dd49 7844dwarfout_begin_prologue ()
a3f97cbb
JW
7845{
7846 char label[MAX_ARTIFICIAL_LABEL_BYTES];
a3f97cbb
JW
7847 register dw_fde_ref fde;
7848 register dw_cfi_ref cfi;
7849
7850 function_section (current_function_decl);
d291dd49 7851 sprintf (label, FUNC_BEGIN_LABEL_FMT, current_funcdef_number);
a3f97cbb
JW
7852 ASM_OUTPUT_LABEL (asm_out_file, label);
7853
7854 /* Expand the fde table if necessary. */
7855 if (fde_table_in_use == fde_table_allocated)
7856 {
7857 fde_table_allocated += FDE_TABLE_INCREMENT;
7858 fde_table = (dw_fde_ref) xrealloc (fde_table,
7859 fde_table_allocated * sizeof (dw_fde_node));
7860 }
7861
7862 /* Record the FDE associated with this function. */
7863 current_funcdef_fde = fde_table_in_use;
7864
7865 /* Add the new FDE at the end of the fde_table. */
7866 fde = &fde_table[fde_table_in_use++];
7d4440be 7867 fde->dw_fde_begin = xstrdup (label);
d291dd49 7868 fde->dw_fde_end_prolog = NULL;
a3f97cbb
JW
7869 fde->dw_fde_begin_epilogue = NULL;
7870 fde->dw_fde_end = NULL;
7871 fde->dw_fde_cfi = NULL;
d291dd49
JM
7872}
7873
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). */
7877void
7878dwarfout_begin_function ()
7879{
7880 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7881 register long int offset;
7882 register dw_fde_ref fde;
7883 register dw_cfi_ref cfi;
7884
7885 function_section (current_function_decl);
7886 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
7887 ASM_OUTPUT_LABEL (asm_out_file, label);
7888
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);
a3f97cbb
JW
7892
7893#ifdef MIPS_DEBUGGING_INFO
7894
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;
810429b7
JM
7898 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
7899 = DBX_REGISTER_NUMBER (STACK_POINTER_REGNUM);
a3f97cbb
JW
7900 cfi->dw_cfi_oprnd2.dw_cfi_offset = 0;
7901 add_cfi (&fde->dw_fde_cfi, cfi);
7902
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);
7908
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;
810429b7
JM
7913 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
7914 = DBX_REGISTER_NUMBER (frame_pointer_needed ? FRAME_POINTER_REGNUM
7915 : STACK_POINTER_REGNUM);
a3f97cbb
JW
7916 offset = current_frame_info.total_size;
7917 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7918 add_cfi (&fde->dw_fde_cfi, cfi);
7919
7920 /* record the frame size for later definition of the DW_AT_frame_base
7921 attribute. */
7922 current_funcdef_frame_size = offset;
7923
7924 /* Define the rule for restoring the stack pointer. */
7925 if (frame_pointer_needed)
7926 {
7927 /* Restore the stack register from the frame pointer. */
7928 cfi = new_cfi ();
7929 cfi->dw_cfi_opc = DW_CFA_register;
810429b7
JM
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);
a3f97cbb
JW
7934 add_cfi (&fde->dw_fde_cfi, cfi);
7935 }
7936
7937 /* If RA is saved on the stack, define it here. */
7938 if (regs_ever_live[31])
7939 {
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);
7947 }
7948
7949 /* If FP is saved on the stack, define it here. */
7950 if (current_frame_info.mask & (1 << 30))
7951 {
7952 offset = (current_frame_info.gp_save_offset
ba7b35df 7953 - (((current_frame_info.mask >> 31) & 1) * UNITS_PER_WORD))
a3f97cbb
JW
7954 / DWARF_CIE_DATA_ALIGNMENT;
7955 assert (offset >= 0);
7956 cfi = new_cfi ();
7957 cfi->dw_cfi_opc = DW_CFA_offset;
810429b7
JM
7958 cfi->dw_cfi_oprnd1.dw_cfi_reg_num
7959 = DBX_REGISTER_NUMBER (FRAME_POINTER_REGNUM);
a3f97cbb
JW
7960 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7961 add_cfi (&fde->dw_fde_cfi, cfi);
7962 }
7963
7964#endif
7965
7966}
7967
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). */
7970void
7971dwarfout_end_function ()
7972{
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);
7981}
7982
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. */
7986void
7987dwarfout_end_epilogue ()
7988{
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);
7997}
7998
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. */
8009static unsigned
8010lookup_filename (file_name)
8011 char *file_name;
8012{
8013 static unsigned last_file_lookup_index = 0;
8014 register char *fn;
8015 register unsigned i;
8016
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)
8020 {
8021 fn = file_table[last_file_lookup_index];
8022 if (strcmp (file_name, fn) == 0)
8023 {
8024 return last_file_lookup_index;
8025 }
8026 }
8027
8028 /* Didn't match the previous lookup, search the table */
8029 for (i = 1; i < file_table_in_use; ++i)
8030 {
8031 fn = file_table[i];
8032 if (strcmp (file_name, fn) == 0)
8033 {
8034 last_file_lookup_index = i;
8035 return i;
8036 }
8037 }
8038
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)
8042 {
8043 file_table_allocated += FILE_TABLE_INCREMENT;
8044 file_table
8045 = (char **)
8046 xrealloc (file_table, file_table_allocated * sizeof (char *));
8047 }
8048
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;
8053}
8054
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. */
8058void
8059dwarfout_line (filename, line)
8060 register char *filename;
8061 register unsigned line;
8062{
8063 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8064 register unsigned this_file_entry_num = lookup_filename (filename);
a3f97cbb
JW
8065 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8066 {
8067 function_section (current_function_decl);
a3f97cbb 8068
e90b62db 8069 if (DECL_SECTION_NAME (current_function_decl))
a3f97cbb 8070 {
e90b62db
JM
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);
8076
8077 /* expand the line info table if necessary */
8078 if (separate_line_info_table_in_use
8079 == separate_line_info_table_allocated)
8080 {
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));
8087 }
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;
8094 }
8095 else
8096 {
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);
8101
8102 /* expand the line info table if necessary */
8103 if (line_info_table_in_use == line_info_table_allocated)
8104 {
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));
8110 }
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;
a3f97cbb 8115 }
a3f97cbb
JW
8116 }
8117}
8118
8119/* Record the beginning of a new source file, for later output
8120 of the .debug_macinfo section. At present, unimplemented. */
8121void
8122dwarfout_start_new_source_file (filename)
8123 register char *filename;
8124{
8125}
8126
8127/* Record the resumption of a source file, for later output
8128 of the .debug_macinfo section. At present, unimplemented. */
8129void
8130dwarfout_resume_previous_source_file (lineno)
8131 register unsigned lineno;
8132{
8133}
8134
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. */
8138void
8139dwarfout_define (lineno, buffer)
8140 register unsigned lineno;
8141 register char *buffer;
8142{
8143 static int initialized = 0;
8144 if (!initialized)
8145 {
8146 dwarfout_start_new_source_file (primary_filename);
8147 initialized = 1;
8148 }
8149}
8150
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. */
8154void
8155dwarfout_undef (lineno, buffer)
8156 register unsigned lineno;
8157 register char *buffer;
8158{
8159}
8160
8161/* Set up for Dwarf output at the start of compilation. */
8162void
8163dwarfout_init (asm_out_file, main_input_filename)
8164 register FILE *asm_out_file;
8165 register char *main_input_filename;
8166{
8167
8168 /* Remember the name of the primary input file. */
8169 primary_filename = main_input_filename;
8170
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;
8177
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;
8184
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;
8191
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;
8198
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;
8207
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;
8217
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;
8223
bdb669cb 8224#if 0
a3f97cbb
JW
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);
8229
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);
8234
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);
8239
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);
bdb669cb 8244#endif
a3f97cbb
JW
8245
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);
8252
8253 /* clear the association between base types and their DIE's */
8254 init_base_type_table ();
a3f97cbb
JW
8255}
8256
8257/* Output stuff that dwarf requires at the end of every file,
8258 and generate the DWARF-2 debugging info. */
8259void
8260dwarfout_finish ()
8261{
a3f97cbb
JW
8262 /* Traverse the DIE tree and add sibling attributes to those DIE's
8263 that have children. */
8264 add_sibling_attributes (comp_unit_die);
8265
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);
8270
bdb669cb 8271#if 0
a3f97cbb
JW
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);
8276
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);
8281
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);
bdb669cb 8286#endif
a3f97cbb 8287
e90b62db
JM
8288 /* Output the source line correspondence table. */
8289 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
8290 {
8291 fputc ('\n', asm_out_file);
8292 ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION);
8293 output_line_info ();
8294
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)
8298 {
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);
8301 }
8302 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION);
8303 }
8304
a3f97cbb
JW
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 ();
8310
a3f97cbb
JW
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);
8314
8315 /* Initialize the beginning FDE offset - and calculate sizes/offsets. */
8316 next_fde_offset = DWARF_CIE_SIZE;
8317 calc_fde_sizes ();
8318
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);
8324
d291dd49
JM
8325 if (pubname_table_in_use)
8326 {
8327 /* Output public names table. */
8328 fputc ('\n', asm_out_file);
8329 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
8330 output_pubnames ();
8331 }
8332
a3f97cbb
JW
8333 if (fde_table_in_use)
8334 {
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 ();
8339
a3f97cbb
JW
8340 /* Output the address range information. */
8341 fputc ('\n', asm_out_file);
8342 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
8343 output_aranges ();
8344 }
8345}
8346#endif /* DWARF_DEBUGGING_INFO && DWARF_VERSION == 2 */
This page took 0.854739 seconds and 5 git commands to generate.