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