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