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