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