]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/dwarf2out.c
dbxout.c: Follow spelling conventions.
[thirdparty/gcc.git] / gcc / dwarf2out.c
CommitLineData
a3f97cbb 1/* Output Dwarf2 format symbol table information from the GNU C compiler.
54ba1f0d 2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
06ceef4e 3 Free Software Foundation, Inc.
e9a25f70
JL
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
469ac993 6 Extensively modified by Jason Merrill (jason@cygnus.com).
a3f97cbb 7
1322177d 8This file is part of GCC.
a3f97cbb 9
1322177d
LB
10GCC is free software; you can redistribute it and/or modify it under
11the terms of the GNU General Public License as published by the Free
12Software Foundation; either version 2, or (at your option) any later
13version.
a3f97cbb 14
1322177d
LB
15GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18for more details.
a3f97cbb
JW
19
20You should have received a copy of the GNU General Public License
1322177d
LB
21along with GCC; see the file COPYING. If not, write to the Free
22Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2302111-1307, USA. */
a3f97cbb 24
9eb4015a 25/* TODO: Emit .debug_line header even when there are no functions, since
348bb3c7
JM
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
30
3f76745e
JM
31/* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 information. */
36
0021b564 37#include "config.h"
670ee920 38#include "system.h"
a3f97cbb
JW
39#include "tree.h"
40#include "flags.h"
11ad4784 41#include "real.h"
a3f97cbb
JW
42#include "rtl.h"
43#include "hard-reg-set.h"
44#include "regs.h"
45#include "insn-config.h"
46#include "reload.h"
52a11cbf 47#include "function.h"
a3f97cbb 48#include "output.h"
71dfc51f 49#include "expr.h"
e78d8e51 50#include "libfuncs.h"
3f76745e 51#include "except.h"
a7cc7f29 52#include "dwarf2.h"
76ead72b 53#include "dwarf2out.h"
2e4b9b8c 54#include "dwarf2asm.h"
10f0ad3d 55#include "toplev.h"
1865dbb5 56#include "varray.h"
951a525f 57#include "ggc.h"
881c6935 58#include "md5.h"
57bed152 59#include "tm_p.h"
2a2b2d43 60#include "diagnostic.h"
a51d908e 61#include "debug.h"
07c9d2eb 62#include "target.h"
3ac88239 63#include "langhooks.h"
9eb4015a 64#include "hashtable.h"
a3f97cbb 65
653e276c
NB
66#ifdef DWARF2_DEBUGGING_INFO
67static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
68#endif
69
770ca8c6
JO
70/* DWARF2 Abbreviation Glossary:
71 CFA = Canonical Frame Address
00a42e21
JM
72 a fixed address on the stack which identifies a call frame.
73 We define it to be the value of SP just before the call insn.
74 The CFA register and offset, which may change during the course
75 of the function, are used to calculate its value at runtime.
a401107d
JO
76 CFI = Call Frame Instruction
77 an instruction for the DWARF2 abstract machine
770ca8c6
JO
78 CIE = Common Information Entry
79 information describing information common to one or more FDEs
80 DIE = Debugging Information Entry
81 FDE = Frame Description Entry
82 information describing the stack call frame, in particular,
83 how to restore registers
84
85 DW_CFA_... = DWARF2 CFA call frame instruction
86 DW_TAG_... = DWARF2 DIE tag */
87
0021b564
JM
88/* Decide whether we want to emit frame unwind information for the current
89 translation unit. */
90
91int
92dwarf2out_do_frame ()
93{
94 return (write_symbols == DWARF2_DEBUG
7a0c8d71 95 || write_symbols == VMS_AND_DWARF2_DEBUG
9ec36da5 96#ifdef DWARF2_FRAME_INFO
556273e0 97 || DWARF2_FRAME_INFO
9ec36da5 98#endif
0021b564 99#ifdef DWARF2_UNWIND_INFO
14a774a9 100 || flag_unwind_tables
531073e7 101 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
0021b564
JM
102#endif
103 );
104}
105
f3a8e4f5
KG
106/* The size of the target's pointer type. */
107#ifndef PTR_SIZE
108#define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
109#endif
110
111/* Default version of targetm.eh_frame_section. Note this must appear
112 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
113 guards. */
114
115void
116default_eh_frame_section ()
117{
118#ifdef EH_FRAME_SECTION_NAME
119 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
120#else
121 tree label = get_file_function_name ('F');
122
123 data_section ();
124 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
5eb99654 125 (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label));
f3a8e4f5
KG
126 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
127#endif
128}
129
e2500fed
GK
130/* Array of RTXes referenced by the debugging information, which therefore
131 must be kept around forever. */
132static GTY(()) varray_type used_rtx_varray;
133
134/* A pointer to the base of a list of incomplete types which might be
135 completed at some later time. incomplete_types_list needs to be a VARRAY
136 because we want to tell the garbage collector about it. */
137static GTY(()) varray_type incomplete_types;
138
139/* A pointer to the base of a table of references to declaration
140 scopes. This table is a display which tracks the nesting
141 of declaration scopes at the current scope and containing
142 scopes. This table is used to find the proper place to
143 define type declaration DIE's. */
144static GTY(()) varray_type decl_scope_table;
145
0021b564
JM
146#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
147
eaf95893
RK
148/* How to start an assembler comment. */
149#ifndef ASM_COMMENT_START
150#define ASM_COMMENT_START ";#"
151#endif
152
a3f97cbb
JW
153typedef struct dw_cfi_struct *dw_cfi_ref;
154typedef struct dw_fde_struct *dw_fde_ref;
155typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
a3f97cbb
JW
156
157/* Call frames are described using a sequence of Call Frame
158 Information instructions. The register number, offset
159 and address fields are provided as possible operands;
160 their use is selected by the opcode field. */
71dfc51f 161
a3f97cbb 162typedef union dw_cfi_oprnd_struct
71dfc51f
RK
163{
164 unsigned long dw_cfi_reg_num;
165 long int dw_cfi_offset;
d3e3972c 166 const char *dw_cfi_addr;
7d9d8943 167 struct dw_loc_descr_struct *dw_cfi_loc;
71dfc51f 168}
a3f97cbb
JW
169dw_cfi_oprnd;
170
171typedef struct dw_cfi_struct
71dfc51f
RK
172{
173 dw_cfi_ref dw_cfi_next;
174 enum dwarf_call_frame_info dw_cfi_opc;
175 dw_cfi_oprnd dw_cfi_oprnd1;
176 dw_cfi_oprnd dw_cfi_oprnd2;
177}
a3f97cbb
JW
178dw_cfi_node;
179
7d9d8943
AM
180/* This is how we define the location of the CFA. We use to handle it
181 as REG + OFFSET all the time, but now it can be more complex.
182 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
556273e0 183 Instead of passing around REG and OFFSET, we pass a copy
7d9d8943
AM
184 of this structure. */
185typedef struct cfa_loc
186{
556273e0 187 unsigned long reg;
7d9d8943
AM
188 long offset;
189 long base_offset;
190 int indirect; /* 1 if CFA is accessed via a dereference. */
191} dw_cfa_location;
192
a3f97cbb 193/* All call frame descriptions (FDE's) in the GCC generated DWARF
4b674448 194 refer to a single Common Information Entry (CIE), defined at
fb530c07 195 the beginning of the .debug_frame section. This use of a single
a3f97cbb
JW
196 CIE obviates the need to keep track of multiple CIE's
197 in the DWARF generation routines below. */
71dfc51f 198
a3f97cbb 199typedef struct dw_fde_struct
71dfc51f 200{
d3e3972c
KG
201 const char *dw_fde_begin;
202 const char *dw_fde_current_label;
203 const char *dw_fde_end;
71dfc51f 204 dw_cfi_ref dw_fde_cfi;
52a11cbf 205 unsigned funcdef_number;
b6128b8c 206 unsigned all_throwers_are_sibcalls : 1;
52a11cbf
RH
207 unsigned nothrow : 1;
208 unsigned uses_eh_lsda : 1;
71dfc51f 209}
a3f97cbb
JW
210dw_fde_node;
211
6d2f8887 212/* Maximum size (in bytes) of an artificially generated label. */
a3f97cbb
JW
213#define MAX_ARTIFICIAL_LABEL_BYTES 30
214
a1a4189d
JB
215/* The size of addresses as they appear in the Dwarf 2 data.
216 Some architectures use word addresses to refer to code locations,
217 but Dwarf 2 info always uses byte addresses. On such machines,
218 Dwarf 2 addresses need to be larger than the architecture's
219 pointers. */
220#ifndef DWARF2_ADDR_SIZE
221#define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
222#endif
223
7e23cb16 224/* The size in bytes of a DWARF field indicating an offset or length
a1a4189d
JB
225 relative to a debug info section, specified to be 4 bytes in the
226 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
b13fe8bf 227 as PTR_SIZE. */
71dfc51f 228
7e23cb16
JM
229#ifndef DWARF_OFFSET_SIZE
230#define DWARF_OFFSET_SIZE 4
231#endif
232
9a666dda
JM
233#define DWARF_VERSION 2
234
7e23cb16
JM
235/* Round SIZE up to the nearest BOUNDARY. */
236#define DWARF_ROUND(SIZE,BOUNDARY) \
262b6384 237 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
a3f97cbb 238
a3f97cbb 239/* Offsets recorded in opcodes are a multiple of this alignment factor. */
27c35f4b 240#ifndef DWARF_CIE_DATA_ALIGNMENT
469ac993 241#ifdef STACK_GROWS_DOWNWARD
08cb3d38 242#define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
469ac993 243#else
08cb3d38 244#define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
469ac993 245#endif
2ad9852d 246#endif
a3f97cbb 247
3f76745e
JM
248/* A pointer to the base of a table that contains frame description
249 information for each routine. */
250static dw_fde_ref fde_table;
a3f97cbb 251
3f76745e
JM
252/* Number of elements currently allocated for fde_table. */
253static unsigned fde_table_allocated;
a94dbf2c 254
3f76745e
JM
255/* Number of elements in fde_table currently in use. */
256static unsigned fde_table_in_use;
a3f97cbb 257
3f76745e
JM
258/* Size (in elements) of increments by which we may expand the
259 fde_table. */
260#define FDE_TABLE_INCREMENT 256
a3f97cbb 261
a94dbf2c
JM
262/* A list of call frame insns for the CIE. */
263static dw_cfi_ref cie_cfi_head;
264
a3f97cbb
JW
265/* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
266 attribute that accelerates the lookup of the FDE associated
556273e0 267 with the subprogram. This variable holds the table index of the FDE
a3f97cbb
JW
268 associated with the current function (body) definition. */
269static unsigned current_funcdef_fde;
270
9eb4015a
JJ
271struct ht *debug_str_hash;
272
273struct indirect_string_node
274{
275 struct ht_identifier id;
276 unsigned int refcount;
277 unsigned int form;
278 char *label;
279};
280
a3f97cbb 281/* Forward declarations for functions defined in this file. */
71dfc51f 282
83d2b3b9
KG
283static char *stripattributes PARAMS ((const char *));
284static const char *dwarf_cfi_name PARAMS ((unsigned));
285static dw_cfi_ref new_cfi PARAMS ((void));
286static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
d3e3972c 287static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
2ad9852d
RK
288static void lookup_cfa_1 PARAMS ((dw_cfi_ref,
289 dw_cfa_location *));
7d9d8943 290static void lookup_cfa PARAMS ((dw_cfa_location *));
d3e3972c
KG
291static void reg_save PARAMS ((const char *, unsigned,
292 unsigned, long));
83d2b3b9 293static void initial_return_save PARAMS ((rtx));
5e640c56 294static long stack_adjust_offset PARAMS ((rtx));
12f0b96b 295static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
83d2b3b9 296static void output_call_frame_info PARAMS ((int));
83d2b3b9 297static void dwarf2out_stack_adjust PARAMS ((rtx));
fbfa55b0
RH
298static void queue_reg_save PARAMS ((const char *, rtx, long));
299static void flush_queued_reg_saves PARAMS ((void));
300static bool clobbers_queued_reg_save PARAMS ((rtx));
d3e3972c 301static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
a3f97cbb 302
7d9d8943
AM
303/* Support for complex CFA locations. */
304static void output_cfa_loc PARAMS ((dw_cfi_ref));
556273e0 305static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
7d9d8943
AM
306 struct dw_loc_descr_struct *));
307static struct dw_loc_descr_struct *build_cfa_loc
308 PARAMS ((dw_cfa_location *));
2ad9852d
RK
309static void def_cfa_1 PARAMS ((const char *,
310 dw_cfa_location *));
7d9d8943 311
2e4b9b8c
RH
312/* How to start an assembler comment. */
313#ifndef ASM_COMMENT_START
314#define ASM_COMMENT_START ";#"
a3f97cbb
JW
315#endif
316
7e23cb16
JM
317/* Data and reference forms for relocatable data. */
318#define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
319#define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
320
cf2fe500
RH
321#ifndef DEBUG_FRAME_SECTION
322#define DEBUG_FRAME_SECTION ".debug_frame"
a3f97cbb 323#endif
a3f97cbb 324
5c90448c
JM
325#ifndef FUNC_BEGIN_LABEL
326#define FUNC_BEGIN_LABEL "LFB"
a3f97cbb 327#endif
2ad9852d 328
5c90448c
JM
329#ifndef FUNC_END_LABEL
330#define FUNC_END_LABEL "LFE"
a3f97cbb 331#endif
2ad9852d 332
27d95cbe 333#define FRAME_BEGIN_LABEL "Lframe"
a6ab3aad
JM
334#define CIE_AFTER_SIZE_LABEL "LSCIE"
335#define CIE_END_LABEL "LECIE"
2e4b9b8c
RH
336#define FDE_LABEL "LSFDE"
337#define FDE_AFTER_SIZE_LABEL "LASFDE"
a6ab3aad 338#define FDE_END_LABEL "LEFDE"
981975b6
RH
339#define LINE_NUMBER_BEGIN_LABEL "LSLT"
340#define LINE_NUMBER_END_LABEL "LELT"
341#define LN_PROLOG_AS_LABEL "LASLTP"
342#define LN_PROLOG_END_LABEL "LELTP"
881c6935 343#define DIE_LABEL_PREFIX "DW"
a3f97cbb 344
c8cc5c4a 345/* The DWARF 2 CFA column which tracks the return address. Normally this
a94dbf2c
JM
346 is the column for PC, or the first column after all of the hard
347 registers. */
c8cc5c4a 348#ifndef DWARF_FRAME_RETURN_COLUMN
a94dbf2c
JM
349#ifdef PC_REGNUM
350#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
351#else
3073d01c 352#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
a94dbf2c 353#endif
c8cc5c4a
JM
354#endif
355
356/* The mapping from gcc register number to DWARF 2 CFA column number. By
469ac993 357 default, we just provide columns for all registers. */
c8cc5c4a 358#ifndef DWARF_FRAME_REGNUM
469ac993 359#define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
c8cc5c4a 360#endif
3f76745e 361
2ad9852d
RK
362/* The offset from the incoming value of %sp to the top of the stack frame
363 for the current function. */
364#ifndef INCOMING_FRAME_SP_OFFSET
365#define INCOMING_FRAME_SP_OFFSET 0
366#endif
367\f
0021b564
JM
368/* Hook used by __throw. */
369
370rtx
371expand_builtin_dwarf_fp_regnum ()
372{
373 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
374}
375
71dfc51f 376/* Return a pointer to a copy of the section string name S with all
bf20f341 377 attributes stripped off, and an asterisk prepended (for assemble_name). */
71dfc51f
RK
378
379static inline char *
a3f97cbb 380stripattributes (s)
d560ee52 381 const char *s;
a3f97cbb 382{
bf20f341 383 char *stripped = xmalloc (strlen (s) + 2);
71dfc51f
RK
384 char *p = stripped;
385
bf20f341
JW
386 *p++ = '*';
387
388 while (*s && *s != ',')
389 *p++ = *s++;
71dfc51f 390
a3f97cbb
JW
391 *p = '\0';
392 return stripped;
393}
394
d9d5c9de 395/* Generate code to initialize the register size table. */
2f3ca9e7 396
d9d5c9de
BS
397void
398expand_builtin_init_dwarf_reg_sizes (address)
399 tree address;
2f3ca9e7 400{
d9d5c9de
BS
401 int i;
402 enum machine_mode mode = TYPE_MODE (char_type_node);
403 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
2ad9852d 404 rtx mem = gen_rtx_MEM (BLKmode, addr);
2f3ca9e7 405
91ea38f9
JH
406 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
407 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
408 {
409 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
410 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
2f3ca9e7 411
91ea38f9
JH
412 if (offset < 0)
413 continue;
c699cee9 414
91ea38f9
JH
415 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
416 }
2f3ca9e7
JM
417}
418
3f76745e 419/* Convert a DWARF call frame info. operation to its string name */
a3f97cbb 420
d560ee52 421static const char *
3f76745e 422dwarf_cfi_name (cfi_opc)
b3694847 423 unsigned cfi_opc;
3f76745e
JM
424{
425 switch (cfi_opc)
426 {
427 case DW_CFA_advance_loc:
428 return "DW_CFA_advance_loc";
429 case DW_CFA_offset:
430 return "DW_CFA_offset";
431 case DW_CFA_restore:
432 return "DW_CFA_restore";
433 case DW_CFA_nop:
434 return "DW_CFA_nop";
435 case DW_CFA_set_loc:
436 return "DW_CFA_set_loc";
437 case DW_CFA_advance_loc1:
438 return "DW_CFA_advance_loc1";
439 case DW_CFA_advance_loc2:
440 return "DW_CFA_advance_loc2";
441 case DW_CFA_advance_loc4:
442 return "DW_CFA_advance_loc4";
443 case DW_CFA_offset_extended:
444 return "DW_CFA_offset_extended";
445 case DW_CFA_restore_extended:
446 return "DW_CFA_restore_extended";
447 case DW_CFA_undefined:
448 return "DW_CFA_undefined";
449 case DW_CFA_same_value:
450 return "DW_CFA_same_value";
451 case DW_CFA_register:
452 return "DW_CFA_register";
453 case DW_CFA_remember_state:
454 return "DW_CFA_remember_state";
455 case DW_CFA_restore_state:
456 return "DW_CFA_restore_state";
457 case DW_CFA_def_cfa:
458 return "DW_CFA_def_cfa";
459 case DW_CFA_def_cfa_register:
460 return "DW_CFA_def_cfa_register";
461 case DW_CFA_def_cfa_offset:
462 return "DW_CFA_def_cfa_offset";
6bb28965
JM
463
464 /* DWARF 3 */
7d9d8943
AM
465 case DW_CFA_def_cfa_expression:
466 return "DW_CFA_def_cfa_expression";
6bb28965
JM
467 case DW_CFA_expression:
468 return "DW_CFA_expression";
469 case DW_CFA_offset_extended_sf:
470 return "DW_CFA_offset_extended_sf";
471 case DW_CFA_def_cfa_sf:
472 return "DW_CFA_def_cfa_sf";
473 case DW_CFA_def_cfa_offset_sf:
474 return "DW_CFA_def_cfa_offset_sf";
c53aa195 475
3f76745e
JM
476 /* SGI/MIPS specific */
477 case DW_CFA_MIPS_advance_loc8:
478 return "DW_CFA_MIPS_advance_loc8";
c53aa195
JM
479
480 /* GNU extensions */
481 case DW_CFA_GNU_window_save:
482 return "DW_CFA_GNU_window_save";
0021b564
JM
483 case DW_CFA_GNU_args_size:
484 return "DW_CFA_GNU_args_size";
3f388b42
GK
485 case DW_CFA_GNU_negative_offset_extended:
486 return "DW_CFA_GNU_negative_offset_extended";
c53aa195 487
3f76745e
JM
488 default:
489 return "DW_CFA_<unknown>";
490 }
491}
a3f97cbb 492
3f76745e 493/* Return a pointer to a newly allocated Call Frame Instruction. */
71dfc51f 494
3f76745e
JM
495static inline dw_cfi_ref
496new_cfi ()
497{
b3694847 498 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
71dfc51f 499
3f76745e
JM
500 cfi->dw_cfi_next = NULL;
501 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
502 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
a3f97cbb 503
3f76745e
JM
504 return cfi;
505}
a3f97cbb 506
3f76745e 507/* Add a Call Frame Instruction to list of instructions. */
a3f97cbb 508
3f76745e
JM
509static inline void
510add_cfi (list_head, cfi)
b3694847
SS
511 dw_cfi_ref *list_head;
512 dw_cfi_ref cfi;
3f76745e 513{
b3694847 514 dw_cfi_ref *p;
a3f97cbb 515
3f76745e
JM
516 /* Find the end of the chain. */
517 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
518 ;
519
520 *p = cfi;
a3f97cbb
JW
521}
522
3f76745e 523/* Generate a new label for the CFI info to refer to. */
71dfc51f 524
c53aa195 525char *
3f76745e 526dwarf2out_cfi_label ()
a3f97cbb 527{
3f76745e
JM
528 static char label[20];
529 static unsigned long label_num = 0;
556273e0 530
3f76745e
JM
531 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
532 ASM_OUTPUT_LABEL (asm_out_file, label);
3f76745e 533 return label;
a3f97cbb
JW
534}
535
3f76745e
JM
536/* Add CFI to the current fde at the PC value indicated by LABEL if specified,
537 or to the CIE if LABEL is NULL. */
71dfc51f 538
3f76745e
JM
539static void
540add_fde_cfi (label, cfi)
b3694847
SS
541 const char *label;
542 dw_cfi_ref cfi;
a3f97cbb 543{
3f76745e
JM
544 if (label)
545 {
b3694847 546 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
a3f97cbb 547
3f76745e
JM
548 if (*label == 0)
549 label = dwarf2out_cfi_label ();
71dfc51f 550
3f76745e
JM
551 if (fde->dw_fde_current_label == NULL
552 || strcmp (label, fde->dw_fde_current_label) != 0)
553 {
b3694847 554 dw_cfi_ref xcfi;
a3f97cbb 555
3f76745e 556 fde->dw_fde_current_label = label = xstrdup (label);
71dfc51f 557
3f76745e
JM
558 /* Set the location counter to the new label. */
559 xcfi = new_cfi ();
560 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
561 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
562 add_cfi (&fde->dw_fde_cfi, xcfi);
563 }
71dfc51f 564
3f76745e
JM
565 add_cfi (&fde->dw_fde_cfi, cfi);
566 }
567
568 else
569 add_cfi (&cie_cfi_head, cfi);
a3f97cbb
JW
570}
571
3f76745e 572/* Subroutine of lookup_cfa. */
71dfc51f 573
3f76745e 574static inline void
7d9d8943 575lookup_cfa_1 (cfi, loc)
b3694847
SS
576 dw_cfi_ref cfi;
577 dw_cfa_location *loc;
a3f97cbb 578{
3f76745e
JM
579 switch (cfi->dw_cfi_opc)
580 {
581 case DW_CFA_def_cfa_offset:
7d9d8943 582 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
3f76745e
JM
583 break;
584 case DW_CFA_def_cfa_register:
7d9d8943 585 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
3f76745e
JM
586 break;
587 case DW_CFA_def_cfa:
7d9d8943
AM
588 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
589 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
590 break;
591 case DW_CFA_def_cfa_expression:
592 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
3f76745e 593 break;
e9a25f70
JL
594 default:
595 break;
3f76745e 596 }
a3f97cbb
JW
597}
598
3f76745e 599/* Find the previous value for the CFA. */
71dfc51f 600
3f76745e 601static void
7d9d8943 602lookup_cfa (loc)
b3694847 603 dw_cfa_location *loc;
a3f97cbb 604{
b3694847 605 dw_cfi_ref cfi;
3f76745e 606
7d9d8943
AM
607 loc->reg = (unsigned long) -1;
608 loc->offset = 0;
609 loc->indirect = 0;
610 loc->base_offset = 0;
3f76745e
JM
611
612 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
7d9d8943 613 lookup_cfa_1 (cfi, loc);
3f76745e
JM
614
615 if (fde_table_in_use)
a3f97cbb 616 {
b3694847 617 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
3f76745e 618 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
7d9d8943 619 lookup_cfa_1 (cfi, loc);
a3f97cbb
JW
620 }
621}
622
3f76745e 623/* The current rule for calculating the DWARF2 canonical frame address. */
fbfa55b0 624static dw_cfa_location cfa;
71dfc51f 625
3f76745e
JM
626/* The register used for saving registers to the stack, and its offset
627 from the CFA. */
fbfa55b0 628static dw_cfa_location cfa_store;
3f76745e 629
0021b564
JM
630/* The running total of the size of arguments pushed onto the stack. */
631static long args_size;
632
b57d9225
JM
633/* The last args_size we actually output. */
634static long old_args_size;
635
3f76745e
JM
636/* Entry point to update the canonical frame address (CFA).
637 LABEL is passed to add_fde_cfi. The value of CFA is now to be
638 calculated from REG+OFFSET. */
639
640void
641dwarf2out_def_cfa (label, reg, offset)
b3694847 642 const char *label;
7d9d8943
AM
643 unsigned reg;
644 long offset;
645{
646 dw_cfa_location loc;
647 loc.indirect = 0;
648 loc.base_offset = 0;
649 loc.reg = reg;
650 loc.offset = offset;
651 def_cfa_1 (label, &loc);
652}
653
770ca8c6 654/* This routine does the actual work. The CFA is now calculated from
7d9d8943 655 the dw_cfa_location structure. */
2ad9852d 656
7d9d8943
AM
657static void
658def_cfa_1 (label, loc_p)
b3694847 659 const char *label;
7d9d8943 660 dw_cfa_location *loc_p;
a3f97cbb 661{
b3694847 662 dw_cfi_ref cfi;
7d9d8943 663 dw_cfa_location old_cfa, loc;
3f76745e 664
7d9d8943
AM
665 cfa = *loc_p;
666 loc = *loc_p;
5bef9b1f 667
7d9d8943
AM
668 if (cfa_store.reg == loc.reg && loc.indirect == 0)
669 cfa_store.offset = loc.offset;
3f76745e 670
7d9d8943
AM
671 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
672 lookup_cfa (&old_cfa);
673
2ad9852d
RK
674 /* If nothing changed, no need to issue any call frame instructions. */
675 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
676 && loc.indirect == old_cfa.indirect
677 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
678 return;
3f76745e
JM
679
680 cfi = new_cfi ();
681
e09bbb25 682 if (loc.reg == old_cfa.reg && !loc.indirect)
a3f97cbb 683 {
770ca8c6
JO
684 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
685 indicating the CFA register did not change but the offset
686 did. */
3f76745e 687 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
7d9d8943 688 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
3f76745e 689 }
a3f97cbb 690
3f76745e 691#ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
7d9d8943 692 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
e09bbb25 693 && !loc.indirect)
3f76745e 694 {
770ca8c6
JO
695 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
696 indicating the CFA register has changed to <register> but the
697 offset has not changed. */
3f76745e 698 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
7d9d8943 699 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
3f76745e
JM
700 }
701#endif
a3f97cbb 702
7d9d8943 703 else if (loc.indirect == 0)
3f76745e 704 {
770ca8c6
JO
705 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
706 indicating the CFA register has changed to <register> with
707 the specified offset. */
3f76745e 708 cfi->dw_cfi_opc = DW_CFA_def_cfa;
7d9d8943
AM
709 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
710 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
711 }
712 else
713 {
770ca8c6
JO
714 /* Construct a DW_CFA_def_cfa_expression instruction to
715 calculate the CFA using a full location expression since no
716 register-offset pair is available. */
556273e0 717 struct dw_loc_descr_struct *loc_list;
2ad9852d 718
7d9d8943
AM
719 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
720 loc_list = build_cfa_loc (&loc);
721 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
a3f97cbb 722 }
3f76745e
JM
723
724 add_fde_cfi (label, cfi);
a3f97cbb
JW
725}
726
3f76745e
JM
727/* Add the CFI for saving a register. REG is the CFA column number.
728 LABEL is passed to add_fde_cfi.
729 If SREG is -1, the register is saved at OFFSET from the CFA;
730 otherwise it is saved in SREG. */
71dfc51f 731
3f76745e
JM
732static void
733reg_save (label, reg, sreg, offset)
b3694847
SS
734 const char *label;
735 unsigned reg;
736 unsigned sreg;
737 long offset;
a3f97cbb 738{
b3694847 739 dw_cfi_ref cfi = new_cfi ();
3f76745e
JM
740
741 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
742
85066503
MH
743 /* The following comparison is correct. -1 is used to indicate that
744 the value isn't a register number. */
745 if (sreg == (unsigned int) -1)
a3f97cbb 746 {
3f76745e
JM
747 if (reg & ~0x3f)
748 /* The register number won't fit in 6 bits, so we have to use
749 the long form. */
750 cfi->dw_cfi_opc = DW_CFA_offset_extended;
751 else
752 cfi->dw_cfi_opc = DW_CFA_offset;
753
27c35f4b
HPN
754#ifdef ENABLE_CHECKING
755 {
756 /* If we get an offset that is not a multiple of
757 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
758 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
759 description. */
760 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
761
762 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
763 abort ();
764 }
765#endif
3f76745e 766 offset /= DWARF_CIE_DATA_ALIGNMENT;
3a88cbd1 767 if (offset < 0)
6bb28965 768 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
2ad9852d 769
3f76745e
JM
770 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
771 }
2c849145
JM
772 else if (sreg == reg)
773 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
774 return;
3f76745e
JM
775 else
776 {
777 cfi->dw_cfi_opc = DW_CFA_register;
778 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
779 }
780
781 add_fde_cfi (label, cfi);
782}
783
c53aa195
JM
784/* Add the CFI for saving a register window. LABEL is passed to reg_save.
785 This CFI tells the unwinder that it needs to restore the window registers
786 from the previous frame's window save area.
556273e0 787
c53aa195
JM
788 ??? Perhaps we should note in the CIE where windows are saved (instead of
789 assuming 0(cfa)) and what registers are in the window. */
790
791void
792dwarf2out_window_save (label)
b3694847 793 const char *label;
c53aa195 794{
b3694847 795 dw_cfi_ref cfi = new_cfi ();
2ad9852d 796
c53aa195
JM
797 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
798 add_fde_cfi (label, cfi);
799}
800
0021b564
JM
801/* Add a CFI to update the running total of the size of arguments
802 pushed onto the stack. */
803
804void
805dwarf2out_args_size (label, size)
d3e3972c 806 const char *label;
0021b564
JM
807 long size;
808{
b3694847 809 dw_cfi_ref cfi;
b57d9225
JM
810
811 if (size == old_args_size)
812 return;
2ad9852d 813
b57d9225
JM
814 old_args_size = size;
815
816 cfi = new_cfi ();
0021b564
JM
817 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
818 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
819 add_fde_cfi (label, cfi);
820}
821
c53aa195
JM
822/* Entry point for saving a register to the stack. REG is the GCC register
823 number. LABEL and OFFSET are passed to reg_save. */
3f76745e
JM
824
825void
826dwarf2out_reg_save (label, reg, offset)
b3694847
SS
827 const char *label;
828 unsigned reg;
829 long offset;
3f76745e
JM
830{
831 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
832}
833
c53aa195
JM
834/* Entry point for saving the return address in the stack.
835 LABEL and OFFSET are passed to reg_save. */
836
837void
838dwarf2out_return_save (label, offset)
b3694847
SS
839 const char *label;
840 long offset;
c53aa195
JM
841{
842 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
843}
844
845/* Entry point for saving the return address in a register.
846 LABEL and SREG are passed to reg_save. */
847
848void
849dwarf2out_return_reg (label, sreg)
b3694847
SS
850 const char *label;
851 unsigned sreg;
c53aa195
JM
852{
853 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
854}
855
3f76745e
JM
856/* Record the initial position of the return address. RTL is
857 INCOMING_RETURN_ADDR_RTX. */
858
859static void
860initial_return_save (rtl)
b3694847 861 rtx rtl;
3f76745e 862{
973838fd 863 unsigned int reg = (unsigned int) -1;
2ad9852d 864 HOST_WIDE_INT offset = 0;
3f76745e
JM
865
866 switch (GET_CODE (rtl))
867 {
868 case REG:
869 /* RA is in a register. */
2c849145 870 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
3f76745e 871 break;
2ad9852d 872
3f76745e
JM
873 case MEM:
874 /* RA is on the stack. */
875 rtl = XEXP (rtl, 0);
876 switch (GET_CODE (rtl))
877 {
878 case REG:
3a88cbd1
JL
879 if (REGNO (rtl) != STACK_POINTER_REGNUM)
880 abort ();
3f76745e
JM
881 offset = 0;
882 break;
2ad9852d 883
3f76745e 884 case PLUS:
3a88cbd1
JL
885 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
886 abort ();
3f76745e
JM
887 offset = INTVAL (XEXP (rtl, 1));
888 break;
2ad9852d 889
3f76745e 890 case MINUS:
3a88cbd1
JL
891 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
892 abort ();
3f76745e
JM
893 offset = -INTVAL (XEXP (rtl, 1));
894 break;
2ad9852d 895
3f76745e
JM
896 default:
897 abort ();
898 }
2ad9852d 899
3f76745e 900 break;
2ad9852d 901
c53aa195
JM
902 case PLUS:
903 /* The return address is at some offset from any value we can
904 actually load. For instance, on the SPARC it is in %i7+8. Just
905 ignore the offset for now; it doesn't matter for unwinding frames. */
3a88cbd1
JL
906 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
907 abort ();
c53aa195
JM
908 initial_return_save (XEXP (rtl, 0));
909 return;
2ad9852d 910
a3f97cbb 911 default:
3f76745e 912 abort ();
a3f97cbb 913 }
3f76745e 914
7d9d8943 915 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
a3f97cbb
JW
916}
917
1ba5ae8f 918/* Given a SET, calculate the amount of stack adjustment it
30f7a378 919 contains. */
1ba5ae8f 920
5e640c56
AH
921static long
922stack_adjust_offset (pattern)
173bf5be 923 rtx pattern;
1ba5ae8f
AH
924{
925 rtx src = SET_SRC (pattern);
926 rtx dest = SET_DEST (pattern);
2ad9852d 927 HOST_WIDE_INT offset = 0;
1ba5ae8f
AH
928 enum rtx_code code;
929
930 if (dest == stack_pointer_rtx)
931 {
932 /* (set (reg sp) (plus (reg sp) (const_int))) */
933 code = GET_CODE (src);
934 if (! (code == PLUS || code == MINUS)
935 || XEXP (src, 0) != stack_pointer_rtx
936 || GET_CODE (XEXP (src, 1)) != CONST_INT)
937 return 0;
938
939 offset = INTVAL (XEXP (src, 1));
f472fa29
AM
940 if (code == PLUS)
941 offset = -offset;
1ba5ae8f
AH
942 }
943 else if (GET_CODE (dest) == MEM)
944 {
945 /* (set (mem (pre_dec (reg sp))) (foo)) */
946 src = XEXP (dest, 0);
947 code = GET_CODE (src);
948
c26fbbca
KH
949 switch (code)
950 {
f472fa29
AM
951 case PRE_MODIFY:
952 case POST_MODIFY:
953 if (XEXP (src, 0) == stack_pointer_rtx)
954 {
955 rtx val = XEXP (XEXP (src, 1), 1);
956 /* We handle only adjustments by constant amount. */
957 if (GET_CODE (XEXP (src, 1)) != PLUS ||
958 GET_CODE (val) != CONST_INT)
c26fbbca 959 abort ();
f472fa29
AM
960 offset = -INTVAL (val);
961 break;
962 }
963 return 0;
964
965 case PRE_DEC:
966 case POST_DEC:
967 if (XEXP (src, 0) == stack_pointer_rtx)
968 {
969 offset = GET_MODE_SIZE (GET_MODE (dest));
970 break;
971 }
972 return 0;
973
974 case PRE_INC:
975 case POST_INC:
976 if (XEXP (src, 0) == stack_pointer_rtx)
977 {
978 offset = -GET_MODE_SIZE (GET_MODE (dest));
979 break;
980 }
981 return 0;
2ad9852d 982
f472fa29
AM
983 default:
984 return 0;
e2134eea 985 }
1ba5ae8f
AH
986 }
987 else
988 return 0;
989
1ba5ae8f
AH
990 return offset;
991}
992
0021b564
JM
993/* Check INSN to see if it looks like a push or a stack adjustment, and
994 make a note of it if it does. EH uses this information to find out how
995 much extra space it needs to pop off the stack. */
996
997static void
998dwarf2out_stack_adjust (insn)
999 rtx insn;
1000{
2ad9852d 1001 HOST_WIDE_INT offset;
d3e3972c 1002 const char *label;
2ad9852d 1003 int i;
0021b564 1004
2ad9852d 1005 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
b57d9225
JM
1006 {
1007 /* Extract the size of the args from the CALL rtx itself. */
b57d9225
JM
1008 insn = PATTERN (insn);
1009 if (GET_CODE (insn) == PARALLEL)
1010 insn = XVECEXP (insn, 0, 0);
1011 if (GET_CODE (insn) == SET)
1012 insn = SET_SRC (insn);
3db35af4
MM
1013 if (GET_CODE (insn) != CALL)
1014 abort ();
2ad9852d 1015
b57d9225
JM
1016 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1017 return;
1018 }
1019
1020 /* If only calls can throw, and we have a frame pointer,
1021 save up adjustments until we see the CALL_INSN. */
2ad9852d 1022 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
b57d9225
JM
1023 return;
1024
6020d360 1025 if (GET_CODE (insn) == BARRIER)
0021b564 1026 {
6020d360
JM
1027 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1028 the compiler will have already emitted a stack adjustment, but
1029 doesn't bother for calls to noreturn functions. */
1030#ifdef STACK_GROWS_DOWNWARD
1031 offset = -args_size;
1032#else
1033 offset = args_size;
1034#endif
0021b564 1035 }
6020d360 1036 else if (GET_CODE (PATTERN (insn)) == SET)
2ad9852d 1037 offset = stack_adjust_offset (PATTERN (insn));
1ba5ae8f
AH
1038 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1039 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1040 {
1041 /* There may be stack adjustments inside compound insns. Search
2ad9852d
RK
1042 for them. */
1043 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1044 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1045 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
0021b564
JM
1046 }
1047 else
1048 return;
0b34cf1e 1049
6020d360
JM
1050 if (offset == 0)
1051 return;
1052
7d9d8943
AM
1053 if (cfa.reg == STACK_POINTER_REGNUM)
1054 cfa.offset += offset;
0021b564
JM
1055
1056#ifndef STACK_GROWS_DOWNWARD
1057 offset = -offset;
1058#endif
2ad9852d 1059
0021b564
JM
1060 args_size += offset;
1061 if (args_size < 0)
1062 args_size = 0;
1063
1064 label = dwarf2out_cfi_label ();
7d9d8943 1065 def_cfa_1 (label, &cfa);
0021b564
JM
1066 dwarf2out_args_size (label, args_size);
1067}
1068
fbfa55b0
RH
1069/* We delay emitting a register save until either (a) we reach the end
1070 of the prologue or (b) the register is clobbered. This clusters
1071 register saves so that there are fewer pc advances. */
1072
1073struct queued_reg_save
1074{
1075 struct queued_reg_save *next;
1076 rtx reg;
1077 long cfa_offset;
1078};
1079
1080static struct queued_reg_save *queued_reg_saves;
1081static const char *last_reg_save_label;
1082
1083static void
1084queue_reg_save (label, reg, offset)
1085 const char *label;
1086 rtx reg;
1087 long offset;
1088{
1089 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1090
1091 q->next = queued_reg_saves;
1092 q->reg = reg;
1093 q->cfa_offset = offset;
1094 queued_reg_saves = q;
1095
1096 last_reg_save_label = label;
1097}
1098
1099static void
1100flush_queued_reg_saves ()
1101{
1102 struct queued_reg_save *q, *next;
1103
c26fbbca 1104 for (q = queued_reg_saves; q; q = next)
fbfa55b0
RH
1105 {
1106 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1107 next = q->next;
1108 free (q);
1109 }
1110
1111 queued_reg_saves = NULL;
1112 last_reg_save_label = NULL;
1113}
1114
1115static bool
1116clobbers_queued_reg_save (insn)
1117 rtx insn;
1118{
1119 struct queued_reg_save *q;
1120
c26fbbca 1121 for (q = queued_reg_saves; q; q = q->next)
fbfa55b0
RH
1122 if (modified_in_p (q->reg, insn))
1123 return true;
1124
1125 return false;
1126}
c26fbbca 1127
fbfa55b0 1128
770ca8c6
JO
1129/* A temporary register holding an integral value used in adjusting SP
1130 or setting up the store_reg. The "offset" field holds the integer
1131 value, not an offset. */
fbfa55b0 1132static dw_cfa_location cfa_temp;
770ca8c6
JO
1133
1134/* Record call frame debugging information for an expression EXPR,
1135 which either sets SP or FP (adjusting how we calculate the frame
1136 address) or saves a register to the stack. LABEL indicates the
1137 address of EXPR.
1138
1139 This function encodes a state machine mapping rtxes to actions on
1140 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1141 users need not read the source code.
1142
a401107d
JO
1143 The High-Level Picture
1144
1145 Changes in the register we use to calculate the CFA: Currently we
1146 assume that if you copy the CFA register into another register, we
1147 should take the other one as the new CFA register; this seems to
1148 work pretty well. If it's wrong for some target, it's simple
1149 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1150
1151 Changes in the register we use for saving registers to the stack:
1152 This is usually SP, but not always. Again, we deduce that if you
1153 copy SP into another register (and SP is not the CFA register),
1154 then the new register is the one we will be using for register
1155 saves. This also seems to work.
1156
1157 Register saves: There's not much guesswork about this one; if
1158 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1159 register save, and the register used to calculate the destination
1160 had better be the one we think we're using for this purpose.
1161
1162 Except: If the register being saved is the CFA register, and the
cc2902df 1163 offset is nonzero, we are saving the CFA, so we assume we have to
a401107d
JO
1164 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1165 the intent is to save the value of SP from the previous frame.
1166
770ca8c6
JO
1167 Invariants / Summaries of Rules
1168
a401107d
JO
1169 cfa current rule for calculating the CFA. It usually
1170 consists of a register and an offset.
770ca8c6
JO
1171 cfa_store register used by prologue code to save things to the stack
1172 cfa_store.offset is the offset from the value of
1173 cfa_store.reg to the actual CFA
1174 cfa_temp register holding an integral value. cfa_temp.offset
1175 stores the value, which will be used to adjust the
19ec6a36
AM
1176 stack pointer. cfa_temp is also used like cfa_store,
1177 to track stores to the stack via fp or a temp reg.
c26fbbca 1178
770ca8c6
JO
1179 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1180 with cfa.reg as the first operand changes the cfa.reg and its
19ec6a36
AM
1181 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1182 cfa_temp.offset.
770ca8c6
JO
1183
1184 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1185 expression yielding a constant. This sets cfa_temp.reg
1186 and cfa_temp.offset.
1187
1188 Rule 5: Create a new register cfa_store used to save items to the
1189 stack.
1190
19ec6a36 1191 Rules 10-14: Save a register to the stack. Define offset as the
a401107d 1192 difference of the original location and cfa_store's
19ec6a36 1193 location (or cfa_temp's location if cfa_temp is used).
770ca8c6
JO
1194
1195 The Rules
1196
1197 "{a,b}" indicates a choice of a xor b.
1198 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1199
1200 Rule 1:
1201 (set <reg1> <reg2>:cfa.reg)
19ec6a36 1202 effects: cfa.reg = <reg1>
770ca8c6 1203 cfa.offset unchanged
19ec6a36
AM
1204 cfa_temp.reg = <reg1>
1205 cfa_temp.offset = cfa.offset
770ca8c6
JO
1206
1207 Rule 2:
2ad9852d
RK
1208 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1209 {<const_int>,<reg>:cfa_temp.reg}))
770ca8c6
JO
1210 effects: cfa.reg = sp if fp used
1211 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1212 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1213 if cfa_store.reg==sp
1214
1215 Rule 3:
19ec6a36 1216 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
770ca8c6
JO
1217 effects: cfa.reg = fp
1218 cfa_offset += +/- <const_int>
1219
1220 Rule 4:
19ec6a36 1221 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
770ca8c6
JO
1222 constraints: <reg1> != fp
1223 <reg1> != sp
1224 effects: cfa.reg = <reg1>
19ec6a36
AM
1225 cfa_temp.reg = <reg1>
1226 cfa_temp.offset = cfa.offset
770ca8c6
JO
1227
1228 Rule 5:
1229 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1230 constraints: <reg1> != fp
1231 <reg1> != sp
1232 effects: cfa_store.reg = <reg1>
1233 cfa_store.offset = cfa.offset - cfa_temp.offset
1234
1235 Rule 6:
1236 (set <reg> <const_int>)
1237 effects: cfa_temp.reg = <reg>
1238 cfa_temp.offset = <const_int>
1239
1240 Rule 7:
1241 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1242 effects: cfa_temp.reg = <reg1>
1243 cfa_temp.offset |= <const_int>
1244
1245 Rule 8:
1246 (set <reg> (high <exp>))
1247 effects: none
1248
1249 Rule 9:
1250 (set <reg> (lo_sum <exp> <const_int>))
1251 effects: cfa_temp.reg = <reg>
1252 cfa_temp.offset = <const_int>
1253
1254 Rule 10:
1255 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1256 effects: cfa_store.offset -= <const_int>
1257 cfa.offset = cfa_store.offset if cfa.reg == sp
770ca8c6 1258 cfa.reg = sp
19ec6a36 1259 cfa.base_offset = -cfa_store.offset
770ca8c6
JO
1260
1261 Rule 11:
1262 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1263 effects: cfa_store.offset += -/+ mode_size(mem)
1264 cfa.offset = cfa_store.offset if cfa.reg == sp
770ca8c6 1265 cfa.reg = sp
19ec6a36 1266 cfa.base_offset = -cfa_store.offset
770ca8c6
JO
1267
1268 Rule 12:
2ad9852d
RK
1269 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1270
1271 <reg2>)
19ec6a36
AM
1272 effects: cfa.reg = <reg1>
1273 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
770ca8c6
JO
1274
1275 Rule 13:
19ec6a36
AM
1276 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1277 effects: cfa.reg = <reg1>
1278 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1279
1280 Rule 14:
1281 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1282 effects: cfa.reg = <reg1>
1283 cfa.base_offset = -cfa_temp.offset
1284 cfa_temp.offset -= mode_size(mem) */
b664de3a
AM
1285
1286static void
1287dwarf2out_frame_debug_expr (expr, label)
1288 rtx expr;
d3e3972c 1289 const char *label;
b664de3a
AM
1290{
1291 rtx src, dest;
2ad9852d 1292 HOST_WIDE_INT offset;
556273e0
KH
1293
1294 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1295 the PARALLEL independently. The first element is always processed if
770ca8c6 1296 it is a SET. This is for backward compatibility. Other elements
556273e0
KH
1297 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1298 flag is set in them. */
2ad9852d 1299 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
556273e0 1300 {
b664de3a
AM
1301 int par_index;
1302 int limit = XVECLEN (expr, 0);
1303
1304 for (par_index = 0; par_index < limit; par_index++)
2ad9852d
RK
1305 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1306 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1307 || par_index == 0))
1308 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
556273e0 1309
b664de3a
AM
1310 return;
1311 }
556273e0 1312
b664de3a
AM
1313 if (GET_CODE (expr) != SET)
1314 abort ();
1315
1316 src = SET_SRC (expr);
1317 dest = SET_DEST (expr);
1318
1319 switch (GET_CODE (dest))
1320 {
1321 case REG:
770ca8c6 1322 /* Rule 1 */
b664de3a
AM
1323 /* Update the CFA rule wrt SP or FP. Make sure src is
1324 relative to the current CFA register. */
1325 switch (GET_CODE (src))
556273e0
KH
1326 {
1327 /* Setting FP from SP. */
1328 case REG:
1329 if (cfa.reg == (unsigned) REGNO (src))
1330 /* OK. */
1331 ;
626d1efd 1332 else
556273e0 1333 abort ();
2c849145
JM
1334
1335 /* We used to require that dest be either SP or FP, but the
1336 ARM copies SP to a temporary register, and from there to
1337 FP. So we just rely on the backends to only set
1338 RTX_FRAME_RELATED_P on appropriate insns. */
556273e0 1339 cfa.reg = REGNO (dest);
19ec6a36
AM
1340 cfa_temp.reg = cfa.reg;
1341 cfa_temp.offset = cfa.offset;
556273e0 1342 break;
b664de3a 1343
556273e0
KH
1344 case PLUS:
1345 case MINUS:
19ec6a36 1346 case LO_SUM:
556273e0
KH
1347 if (dest == stack_pointer_rtx)
1348 {
770ca8c6 1349 /* Rule 2 */
2618f955
MM
1350 /* Adjusting SP. */
1351 switch (GET_CODE (XEXP (src, 1)))
1352 {
1353 case CONST_INT:
1354 offset = INTVAL (XEXP (src, 1));
1355 break;
1356 case REG:
770ca8c6 1357 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
2618f955 1358 abort ();
770ca8c6 1359 offset = cfa_temp.offset;
2618f955
MM
1360 break;
1361 default:
1362 abort ();
1363 }
1364
1365 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1366 {
1367 /* Restoring SP from FP in the epilogue. */
7d9d8943 1368 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
2618f955 1369 abort ();
7d9d8943 1370 cfa.reg = STACK_POINTER_REGNUM;
2618f955 1371 }
19ec6a36
AM
1372 else if (GET_CODE (src) == LO_SUM)
1373 /* Assume we've set the source reg of the LO_SUM from sp. */
1374 ;
2618f955
MM
1375 else if (XEXP (src, 0) != stack_pointer_rtx)
1376 abort ();
1377
19ec6a36 1378 if (GET_CODE (src) != MINUS)
2618f955 1379 offset = -offset;
7d9d8943
AM
1380 if (cfa.reg == STACK_POINTER_REGNUM)
1381 cfa.offset += offset;
1382 if (cfa_store.reg == STACK_POINTER_REGNUM)
1383 cfa_store.offset += offset;
556273e0
KH
1384 }
1385 else if (dest == hard_frame_pointer_rtx)
1386 {
770ca8c6 1387 /* Rule 3 */
2618f955
MM
1388 /* Either setting the FP from an offset of the SP,
1389 or adjusting the FP */
2c849145 1390 if (! frame_pointer_needed)
2618f955
MM
1391 abort ();
1392
2c849145 1393 if (GET_CODE (XEXP (src, 0)) == REG
7d9d8943 1394 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2618f955
MM
1395 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1396 {
2618f955 1397 offset = INTVAL (XEXP (src, 1));
19ec6a36 1398 if (GET_CODE (src) != MINUS)
2618f955 1399 offset = -offset;
7d9d8943
AM
1400 cfa.offset += offset;
1401 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2618f955 1402 }
556273e0
KH
1403 else
1404 abort ();
1405 }
1406 else
1407 {
19ec6a36 1408 if (GET_CODE (src) == MINUS)
2618f955 1409 abort ();
b53ef1a2 1410
770ca8c6 1411 /* Rule 4 */
b53ef1a2
NC
1412 if (GET_CODE (XEXP (src, 0)) == REG
1413 && REGNO (XEXP (src, 0)) == cfa.reg
1414 && GET_CODE (XEXP (src, 1)) == CONST_INT)
34ce3d7b
JM
1415 {
1416 /* Setting a temporary CFA register that will be copied
1417 into the FP later on. */
19ec6a36 1418 offset = - INTVAL (XEXP (src, 1));
34ce3d7b
JM
1419 cfa.offset += offset;
1420 cfa.reg = REGNO (dest);
19ec6a36
AM
1421 /* Or used to save regs to the stack. */
1422 cfa_temp.reg = cfa.reg;
1423 cfa_temp.offset = cfa.offset;
34ce3d7b 1424 }
2ad9852d 1425
770ca8c6 1426 /* Rule 5 */
19ec6a36
AM
1427 else if (GET_CODE (XEXP (src, 0)) == REG
1428 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1429 && XEXP (src, 1) == stack_pointer_rtx)
b53ef1a2 1430 {
00a42e21
JM
1431 /* Setting a scratch register that we will use instead
1432 of SP for saving registers to the stack. */
b53ef1a2
NC
1433 if (cfa.reg != STACK_POINTER_REGNUM)
1434 abort ();
1435 cfa_store.reg = REGNO (dest);
770ca8c6 1436 cfa_store.offset = cfa.offset - cfa_temp.offset;
b53ef1a2 1437 }
2ad9852d 1438
19ec6a36
AM
1439 /* Rule 9 */
1440 else if (GET_CODE (src) == LO_SUM
1441 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1442 {
1443 cfa_temp.reg = REGNO (dest);
1444 cfa_temp.offset = INTVAL (XEXP (src, 1));
1445 }
1446 else
1447 abort ();
556273e0
KH
1448 }
1449 break;
b664de3a 1450
770ca8c6 1451 /* Rule 6 */
556273e0 1452 case CONST_INT:
770ca8c6
JO
1453 cfa_temp.reg = REGNO (dest);
1454 cfa_temp.offset = INTVAL (src);
556273e0 1455 break;
b664de3a 1456
770ca8c6 1457 /* Rule 7 */
556273e0
KH
1458 case IOR:
1459 if (GET_CODE (XEXP (src, 0)) != REG
770ca8c6 1460 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
2618f955 1461 || GET_CODE (XEXP (src, 1)) != CONST_INT)
556273e0 1462 abort ();
2ad9852d 1463
770ca8c6
JO
1464 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1465 cfa_temp.reg = REGNO (dest);
1466 cfa_temp.offset |= INTVAL (XEXP (src, 1));
556273e0 1467 break;
b664de3a 1468
9ae21d2a
AM
1469 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1470 which will fill in all of the bits. */
1471 /* Rule 8 */
1472 case HIGH:
1473 break;
1474
556273e0
KH
1475 default:
1476 abort ();
1477 }
2ad9852d 1478
7d9d8943 1479 def_cfa_1 (label, &cfa);
2618f955 1480 break;
b664de3a 1481
2618f955 1482 case MEM:
2618f955
MM
1483 if (GET_CODE (src) != REG)
1484 abort ();
7d9d8943 1485
7d9d8943
AM
1486 /* Saving a register to the stack. Make sure dest is relative to the
1487 CFA register. */
2618f955
MM
1488 switch (GET_CODE (XEXP (dest, 0)))
1489 {
770ca8c6 1490 /* Rule 10 */
2618f955 1491 /* With a push. */
e2134eea
JH
1492 case PRE_MODIFY:
1493 /* We can't handle variable size modifications. */
1494 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
173bf5be 1495 abort ();
e2134eea
JH
1496 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1497
1498 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1499 || cfa_store.reg != STACK_POINTER_REGNUM)
1500 abort ();
2ad9852d 1501
e2134eea
JH
1502 cfa_store.offset += offset;
1503 if (cfa.reg == STACK_POINTER_REGNUM)
1504 cfa.offset = cfa_store.offset;
1505
1506 offset = -cfa_store.offset;
1507 break;
2ad9852d 1508
770ca8c6 1509 /* Rule 11 */
2618f955
MM
1510 case PRE_INC:
1511 case PRE_DEC:
1512 offset = GET_MODE_SIZE (GET_MODE (dest));
1513 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1514 offset = -offset;
b664de3a 1515
2618f955 1516 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
7d9d8943 1517 || cfa_store.reg != STACK_POINTER_REGNUM)
2618f955 1518 abort ();
2ad9852d 1519
7d9d8943
AM
1520 cfa_store.offset += offset;
1521 if (cfa.reg == STACK_POINTER_REGNUM)
1522 cfa.offset = cfa_store.offset;
b664de3a 1523
7d9d8943 1524 offset = -cfa_store.offset;
2618f955 1525 break;
b664de3a 1526
770ca8c6 1527 /* Rule 12 */
2618f955
MM
1528 /* With an offset. */
1529 case PLUS:
1530 case MINUS:
19ec6a36 1531 case LO_SUM:
770ca8c6
JO
1532 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1533 abort ();
2618f955
MM
1534 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1535 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1536 offset = -offset;
b664de3a 1537
19ec6a36
AM
1538 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1539 offset -= cfa_store.offset;
1540 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1541 offset -= cfa_temp.offset;
1542 else
2618f955 1543 abort ();
2618f955
MM
1544 break;
1545
770ca8c6 1546 /* Rule 13 */
2618f955
MM
1547 /* Without an offset. */
1548 case REG:
19ec6a36
AM
1549 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1550 offset = -cfa_store.offset;
1551 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1552 offset = -cfa_temp.offset;
1553 else
556273e0 1554 abort ();
19ec6a36
AM
1555 break;
1556
1557 /* Rule 14 */
1558 case POST_INC:
1559 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1560 abort ();
1561 offset = -cfa_temp.offset;
1562 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2618f955
MM
1563 break;
1564
1565 default:
1566 abort ();
1567 }
e09bbb25 1568
556273e0 1569 if (REGNO (src) != STACK_POINTER_REGNUM
e09bbb25
JM
1570 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1571 && (unsigned) REGNO (src) == cfa.reg)
1572 {
1573 /* We're storing the current CFA reg into the stack. */
1574
1575 if (cfa.offset == 0)
1576 {
1577 /* If the source register is exactly the CFA, assume
1578 we're saving SP like any other register; this happens
1579 on the ARM. */
e09bbb25 1580 def_cfa_1 (label, &cfa);
fbfa55b0 1581 queue_reg_save (label, stack_pointer_rtx, offset);
e09bbb25
JM
1582 break;
1583 }
1584 else
1585 {
1586 /* Otherwise, we'll need to look in the stack to
1587 calculate the CFA. */
e09bbb25 1588 rtx x = XEXP (dest, 0);
2ad9852d 1589
e09bbb25
JM
1590 if (GET_CODE (x) != REG)
1591 x = XEXP (x, 0);
1592 if (GET_CODE (x) != REG)
1593 abort ();
2ad9852d
RK
1594
1595 cfa.reg = REGNO (x);
e09bbb25
JM
1596 cfa.base_offset = offset;
1597 cfa.indirect = 1;
1598 def_cfa_1 (label, &cfa);
1599 break;
1600 }
1601 }
1602
7d9d8943 1603 def_cfa_1 (label, &cfa);
fbfa55b0 1604 queue_reg_save (label, src, offset);
2618f955
MM
1605 break;
1606
1607 default:
1608 abort ();
1609 }
b664de3a
AM
1610}
1611
3f76745e
JM
1612/* Record call frame debugging information for INSN, which either
1613 sets SP or FP (adjusting how we calculate the frame address) or saves a
1614 register to the stack. If INSN is NULL_RTX, initialize our state. */
71dfc51f 1615
3f76745e
JM
1616void
1617dwarf2out_frame_debug (insn)
1618 rtx insn;
a3f97cbb 1619{
d3e3972c 1620 const char *label;
b664de3a 1621 rtx src;
3f76745e
JM
1622
1623 if (insn == NULL_RTX)
a3f97cbb 1624 {
fbfa55b0
RH
1625 /* Flush any queued register saves. */
1626 flush_queued_reg_saves ();
1627
3f76745e 1628 /* Set up state for generating call frame debug info. */
7d9d8943
AM
1629 lookup_cfa (&cfa);
1630 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
3a88cbd1 1631 abort ();
2ad9852d 1632
7d9d8943
AM
1633 cfa.reg = STACK_POINTER_REGNUM;
1634 cfa_store = cfa;
770ca8c6
JO
1635 cfa_temp.reg = -1;
1636 cfa_temp.offset = 0;
3f76745e
JM
1637 return;
1638 }
1639
fbfa55b0
RH
1640 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1641 flush_queued_reg_saves ();
1642
0021b564
JM
1643 if (! RTX_FRAME_RELATED_P (insn))
1644 {
fbfa55b0 1645 if (!ACCUMULATE_OUTGOING_ARGS)
c26fbbca 1646 dwarf2out_stack_adjust (insn);
2ad9852d 1647
0021b564
JM
1648 return;
1649 }
1650
3f76745e 1651 label = dwarf2out_cfi_label ();
07ebc930
RH
1652 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1653 if (src)
1654 insn = XEXP (src, 0);
556273e0 1655 else
07ebc930
RH
1656 insn = PATTERN (insn);
1657
b664de3a 1658 dwarf2out_frame_debug_expr (insn, label);
3f76745e
JM
1659}
1660
3f76745e
JM
1661/* Output a Call Frame Information opcode and its operand(s). */
1662
1663static void
12f0b96b 1664output_cfi (cfi, fde, for_eh)
b3694847
SS
1665 dw_cfi_ref cfi;
1666 dw_fde_ref fde;
12f0b96b 1667 int for_eh;
3f76745e
JM
1668{
1669 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2ad9852d
RK
1670 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1671 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1672 "DW_CFA_advance_loc 0x%lx",
1673 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3f76745e
JM
1674 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1675 {
2e4b9b8c
RH
1676 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1677 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1678 "DW_CFA_offset, column 0x%lx",
1679 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1680 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3f76745e
JM
1681 }
1682 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2ad9852d
RK
1683 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1684 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1685 "DW_CFA_restore, column 0x%lx",
1686 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3f76745e
JM
1687 else
1688 {
2e4b9b8c
RH
1689 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1690 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3f76745e 1691
3f76745e
JM
1692 switch (cfi->dw_cfi_opc)
1693 {
1694 case DW_CFA_set_loc:
e1f9550a
RH
1695 if (for_eh)
1696 dw2_asm_output_encoded_addr_rtx (
1697 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1698 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1699 NULL);
1700 else
1701 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1702 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3f76745e 1703 break;
2ad9852d 1704
3f76745e 1705 case DW_CFA_advance_loc1:
2e4b9b8c
RH
1706 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1707 fde->dw_fde_current_label, NULL);
bb727b5a 1708 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3f76745e 1709 break;
2ad9852d 1710
3f76745e 1711 case DW_CFA_advance_loc2:
2e4b9b8c
RH
1712 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1713 fde->dw_fde_current_label, NULL);
3f76745e
JM
1714 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1715 break;
2ad9852d 1716
3f76745e 1717 case DW_CFA_advance_loc4:
2e4b9b8c
RH
1718 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1719 fde->dw_fde_current_label, NULL);
3f76745e
JM
1720 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1721 break;
2ad9852d 1722
3f76745e 1723 case DW_CFA_MIPS_advance_loc8:
2e4b9b8c
RH
1724 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1725 fde->dw_fde_current_label, NULL);
1726 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3f76745e 1727 break;
2ad9852d 1728
3f76745e
JM
1729 case DW_CFA_offset_extended:
1730 case DW_CFA_def_cfa:
2ad9852d
RK
1731 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1732 NULL);
2e4b9b8c 1733 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3f76745e 1734 break;
2ad9852d 1735
6bb28965
JM
1736 case DW_CFA_offset_extended_sf:
1737 case DW_CFA_def_cfa_sf:
1738 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1739 NULL);
1740 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1741 break;
1742
3f76745e
JM
1743 case DW_CFA_restore_extended:
1744 case DW_CFA_undefined:
3f76745e
JM
1745 case DW_CFA_same_value:
1746 case DW_CFA_def_cfa_register:
2ad9852d
RK
1747 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1748 NULL);
3f76745e 1749 break;
2ad9852d 1750
3f76745e 1751 case DW_CFA_register:
2ad9852d
RK
1752 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1753 NULL);
1754 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1755 NULL);
3f76745e 1756 break;
2ad9852d 1757
3f76745e 1758 case DW_CFA_def_cfa_offset:
2e4b9b8c
RH
1759 case DW_CFA_GNU_args_size:
1760 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3f76745e 1761 break;
2ad9852d 1762
6bb28965
JM
1763 case DW_CFA_def_cfa_offset_sf:
1764 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1765 break;
1766
c53aa195
JM
1767 case DW_CFA_GNU_window_save:
1768 break;
2ad9852d 1769
7d9d8943 1770 case DW_CFA_def_cfa_expression:
6bb28965 1771 case DW_CFA_expression:
7d9d8943
AM
1772 output_cfa_loc (cfi);
1773 break;
2ad9852d 1774
6bb28965
JM
1775 case DW_CFA_GNU_negative_offset_extended:
1776 /* Obsoleted by DW_CFA_offset_extended_sf. */
1777 abort ();
1778
3f76745e
JM
1779 default:
1780 break;
1781 }
556273e0 1782 }
3f76745e
JM
1783}
1784
1785/* Output the call frame information used to used to record information
1786 that relates to calculating the frame pointer, and records the
1787 location of saved registers. */
1788
1789static void
1790output_call_frame_info (for_eh)
1791 int for_eh;
1792{
b3694847
SS
1793 unsigned int i;
1794 dw_fde_ref fde;
1795 dw_cfi_ref cfi;
27d95cbe 1796 char l1[20], l2[20], section_start_label[20];
52a11cbf
RH
1797 int any_lsda_needed = 0;
1798 char augmentation[6];
e1f9550a
RH
1799 int augmentation_size;
1800 int fde_encoding = DW_EH_PE_absptr;
1801 int per_encoding = DW_EH_PE_absptr;
1802 int lsda_encoding = DW_EH_PE_absptr;
3f76745e 1803
29b91443
JM
1804 /* Don't emit a CIE if there won't be any FDEs. */
1805 if (fde_table_in_use == 0)
1806 return;
1807
2ad9852d
RK
1808 /* If we don't have any functions we'll want to unwind out of, don't emit any
1809 EH unwind information. */
737faf14
JM
1810 if (for_eh)
1811 {
b932f770 1812 int any_eh_needed = flag_asynchronous_unwind_tables;
2ad9852d
RK
1813
1814 for (i = 0; i < fde_table_in_use; i++)
52a11cbf
RH
1815 if (fde_table[i].uses_eh_lsda)
1816 any_eh_needed = any_lsda_needed = 1;
1817 else if (! fde_table[i].nothrow)
1818 any_eh_needed = 1;
1819
1820 if (! any_eh_needed)
1821 return;
737faf14
JM
1822 }
1823
aa0c1401
JL
1824 /* We're going to be generating comments, so turn on app. */
1825 if (flag_debug_asm)
1826 app_enable ();
956d6950 1827
3f76745e 1828 if (for_eh)
07c9d2eb 1829 (*targetm.asm_out.eh_frame_section) ();
3f76745e 1830 else
715bdd29 1831 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
3f76745e 1832
27d95cbe
RH
1833 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1834 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1835
556273e0 1836 /* Output the CIE. */
a6ab3aad
JM
1837 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1838 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2e4b9b8c
RH
1839 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1840 "Length of Common Information Entry");
a6ab3aad
JM
1841 ASM_OUTPUT_LABEL (asm_out_file, l1);
1842
2e4b9b8c
RH
1843 /* Now that the CIE pointer is PC-relative for EH,
1844 use 0 to identify the CIE. */
1845 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1846 (for_eh ? 0 : DW_CIE_ID),
1847 "CIE Identifier Tag");
3f76745e 1848
2e4b9b8c 1849 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
3f76745e 1850
52a11cbf 1851 augmentation[0] = 0;
e1f9550a 1852 augmentation_size = 0;
52a11cbf 1853 if (for_eh)
a6ab3aad 1854 {
e1f9550a
RH
1855 char *p;
1856
52a11cbf
RH
1857 /* Augmentation:
1858 z Indicates that a uleb128 is present to size the
1859 augmentation section.
e1f9550a
RH
1860 L Indicates the encoding (and thus presence) of
1861 an LSDA pointer in the FDE augmentation.
1862 R Indicates a non-default pointer encoding for
1863 FDE code pointers.
1864 P Indicates the presence of an encoding + language
1865 personality routine in the CIE augmentation. */
1866
1867 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1868 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1869 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1870
1871 p = augmentation + 1;
1872 if (eh_personality_libfunc)
1873 {
1874 *p++ = 'P';
1875 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1876 }
52a11cbf 1877 if (any_lsda_needed)
e1f9550a
RH
1878 {
1879 *p++ = 'L';
1880 augmentation_size += 1;
1881 }
1882 if (fde_encoding != DW_EH_PE_absptr)
1883 {
1884 *p++ = 'R';
1885 augmentation_size += 1;
1886 }
1887 if (p > augmentation + 1)
1888 {
1889 augmentation[0] = 'z';
c26fbbca 1890 *p = '\0';
e1f9550a 1891 }
099c8b17
RH
1892
1893 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1894 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1895 {
1896 int offset = ( 4 /* Length */
1897 + 4 /* CIE Id */
1898 + 1 /* CIE version */
1899 + strlen (augmentation) + 1 /* Augmentation */
1900 + size_of_uleb128 (1) /* Code alignment */
1901 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1902 + 1 /* RA column */
1903 + 1 /* Augmentation size */
1904 + 1 /* Personality encoding */ );
1905 int pad = -offset & (PTR_SIZE - 1);
1906
1907 augmentation_size += pad;
1908
1909 /* Augmentations should be small, so there's scarce need to
1910 iterate for a solution. Die if we exceed one uleb128 byte. */
1911 if (size_of_uleb128 (augmentation_size) != 1)
1912 abort ();
1913 }
a6ab3aad 1914 }
3f76745e 1915
2ad9852d 1916 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2e4b9b8c 1917 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2e4b9b8c
RH
1918 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1919 "CIE Data Alignment Factor");
2e4b9b8c 1920 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
3f76745e 1921
52a11cbf
RH
1922 if (augmentation[0])
1923 {
e1f9550a 1924 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
52a11cbf 1925 if (eh_personality_libfunc)
e1f9550a
RH
1926 {
1927 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1928 eh_data_format_name (per_encoding));
1929 dw2_asm_output_encoded_addr_rtx (per_encoding,
1930 eh_personality_libfunc, NULL);
1931 }
2ad9852d 1932
e1f9550a
RH
1933 if (any_lsda_needed)
1934 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1935 eh_data_format_name (lsda_encoding));
2ad9852d 1936
e1f9550a
RH
1937 if (fde_encoding != DW_EH_PE_absptr)
1938 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1939 eh_data_format_name (fde_encoding));
52a11cbf
RH
1940 }
1941
3f76745e 1942 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
12f0b96b 1943 output_cfi (cfi, NULL, for_eh);
3f76745e
JM
1944
1945 /* Pad the CIE out to an address sized boundary. */
c26fbbca 1946 ASM_OUTPUT_ALIGN (asm_out_file,
12f0b96b 1947 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
a6ab3aad 1948 ASM_OUTPUT_LABEL (asm_out_file, l2);
3f76745e
JM
1949
1950 /* Loop through all of the FDE's. */
2ad9852d 1951 for (i = 0; i < fde_table_in_use; i++)
3f76745e
JM
1952 {
1953 fde = &fde_table[i];
3f76745e 1954
52a11cbf 1955 /* Don't emit EH unwind info for leaf functions that don't need it. */
b6128b8c
SH
1956 if (!flag_asynchronous_unwind_tables && for_eh
1957 && (fde->nothrow || fde->all_throwers_are_sibcalls)
1958 && !fde->uses_eh_lsda)
737faf14
JM
1959 continue;
1960
2e4b9b8c 1961 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
556273e0
KH
1962 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1963 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2e4b9b8c
RH
1964 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1965 "FDE Length");
a6ab3aad
JM
1966 ASM_OUTPUT_LABEL (asm_out_file, l1);
1967
3f76745e 1968 if (for_eh)
27d95cbe 1969 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3f76745e 1970 else
27d95cbe 1971 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2e4b9b8c 1972 "FDE CIE offset");
3f76745e 1973
e1f9550a
RH
1974 if (for_eh)
1975 {
1976 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1977 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1978 "FDE initial location");
1979 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
c26fbbca 1980 fde->dw_fde_end, fde->dw_fde_begin,
e1f9550a
RH
1981 "FDE address range");
1982 }
1983 else
1984 {
1985 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1986 "FDE initial location");
c26fbbca
KH
1987 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1988 fde->dw_fde_end, fde->dw_fde_begin,
e1f9550a
RH
1989 "FDE address range");
1990 }
3f76745e 1991
52a11cbf
RH
1992 if (augmentation[0])
1993 {
e1f9550a 1994 if (any_lsda_needed)
52a11cbf 1995 {
099c8b17
RH
1996 int size = size_of_encoded_value (lsda_encoding);
1997
1998 if (lsda_encoding == DW_EH_PE_aligned)
1999 {
2000 int offset = ( 4 /* Length */
2001 + 4 /* CIE offset */
2002 + 2 * size_of_encoded_value (fde_encoding)
2003 + 1 /* Augmentation size */ );
2004 int pad = -offset & (PTR_SIZE - 1);
2005
2006 size += pad;
2007 if (size_of_uleb128 (size) != 1)
2008 abort ();
2009 }
2010
2011 dw2_asm_output_data_uleb128 (size, "Augmentation size");
e1f9550a
RH
2012
2013 if (fde->uses_eh_lsda)
2014 {
2015 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2016 fde->funcdef_number);
2017 dw2_asm_output_encoded_addr_rtx (
2018 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2019 "Language Specific Data Area");
2020 }
2021 else
099c8b17
RH
2022 {
2023 if (lsda_encoding == DW_EH_PE_aligned)
2024 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2ad9852d
RK
2025 dw2_asm_output_data
2026 (size_of_encoded_value (lsda_encoding), 0,
2027 "Language Specific Data Area (none)");
099c8b17 2028 }
52a11cbf
RH
2029 }
2030 else
e1f9550a 2031 dw2_asm_output_data_uleb128 (0, "Augmentation size");
52a11cbf
RH
2032 }
2033
3f76745e
JM
2034 /* Loop through the Call Frame Instructions associated with
2035 this FDE. */
2036 fde->dw_fde_current_label = fde->dw_fde_begin;
2037 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
12f0b96b 2038 output_cfi (cfi, fde, for_eh);
3f76745e 2039
a6ab3aad 2040 /* Pad the FDE out to an address sized boundary. */
c26fbbca 2041 ASM_OUTPUT_ALIGN (asm_out_file,
e1f9550a 2042 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
a6ab3aad 2043 ASM_OUTPUT_LABEL (asm_out_file, l2);
3f76745e 2044 }
2e4b9b8c 2045
7606e68f 2046 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2e4b9b8c 2047 dw2_asm_output_data (4, 0, "End of Table");
a6ab3aad
JM
2048#ifdef MIPS_DEBUGGING_INFO
2049 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2050 get a value of 0. Putting .align 0 after the label fixes it. */
2051 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2052#endif
aa0c1401
JL
2053
2054 /* Turn off app to make assembly quicker. */
2055 if (flag_debug_asm)
2056 app_disable ();
a6ab3aad
JM
2057}
2058
3f76745e
JM
2059/* Output a marker (i.e. a label) for the beginning of a function, before
2060 the prologue. */
2061
2062void
653e276c
NB
2063dwarf2out_begin_prologue (line, file)
2064 unsigned int line ATTRIBUTE_UNUSED;
2065 const char *file ATTRIBUTE_UNUSED;
3f76745e
JM
2066{
2067 char label[MAX_ARTIFICIAL_LABEL_BYTES];
b3694847 2068 dw_fde_ref fde;
3f76745e 2069
2a1ee410
RH
2070 current_function_func_begin_label = 0;
2071
2072#ifdef IA64_UNWIND_INFO
2073 /* ??? current_function_func_begin_label is also used by except.c
2074 for call-site information. We must emit this label if it might
2075 be used. */
2076 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2077 && ! dwarf2out_do_frame ())
2078 return;
2079#else
2080 if (! dwarf2out_do_frame ())
2081 return;
2082#endif
2083
3f76745e
JM
2084 function_section (current_function_decl);
2085 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
df696a75 2086 current_function_funcdef_no);
2a1ee410 2087 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
df696a75 2088 current_function_funcdef_no);
00262c8a 2089 current_function_func_begin_label = get_identifier (label);
3f76745e 2090
2a1ee410
RH
2091#ifdef IA64_UNWIND_INFO
2092 /* We can elide the fde allocation if we're not emitting debug info. */
2093 if (! dwarf2out_do_frame ())
2094 return;
2095#endif
2096
3f76745e
JM
2097 /* Expand the fde table if necessary. */
2098 if (fde_table_in_use == fde_table_allocated)
2099 {
2100 fde_table_allocated += FDE_TABLE_INCREMENT;
2101 fde_table
2102 = (dw_fde_ref) xrealloc (fde_table,
2103 fde_table_allocated * sizeof (dw_fde_node));
a3f97cbb 2104 }
3f76745e
JM
2105
2106 /* Record the FDE associated with this function. */
2107 current_funcdef_fde = fde_table_in_use;
2108
2109 /* Add the new FDE at the end of the fde_table. */
2110 fde = &fde_table[fde_table_in_use++];
2111 fde->dw_fde_begin = xstrdup (label);
2112 fde->dw_fde_current_label = NULL;
2113 fde->dw_fde_end = NULL;
2114 fde->dw_fde_cfi = NULL;
df696a75 2115 fde->funcdef_number = current_function_funcdef_no;
fb13d4d0 2116 fde->nothrow = current_function_nothrow;
52a11cbf 2117 fde->uses_eh_lsda = cfun->uses_eh_lsda;
b6128b8c 2118 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
737faf14 2119
b57d9225 2120 args_size = old_args_size = 0;
653e276c 2121
2ad9852d
RK
2122 /* We only want to output line number information for the genuine dwarf2
2123 prologue case, not the eh frame case. */
653e276c
NB
2124#ifdef DWARF2_DEBUGGING_INFO
2125 if (file)
2126 dwarf2out_source_line (line, file);
2127#endif
3f76745e
JM
2128}
2129
2130/* Output a marker (i.e. a label) for the absolute end of the generated code
2131 for a function definition. This gets called *after* the epilogue code has
2132 been generated. */
2133
2134void
702ada3d
DR
2135dwarf2out_end_epilogue (line, file)
2136 unsigned int line ATTRIBUTE_UNUSED;
2137 const char *file ATTRIBUTE_UNUSED;
3f76745e
JM
2138{
2139 dw_fde_ref fde;
2140 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2141
2142 /* Output a label to mark the endpoint of the code generated for this
3ef42a0c 2143 function. */
df696a75
RH
2144 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2145 current_function_funcdef_no);
3f76745e
JM
2146 ASM_OUTPUT_LABEL (asm_out_file, label);
2147 fde = &fde_table[fde_table_in_use - 1];
2148 fde->dw_fde_end = xstrdup (label);
3f76745e
JM
2149}
2150
2151void
2152dwarf2out_frame_init ()
2153{
2154 /* Allocate the initial hunk of the fde_table. */
3de90026 2155 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
3f76745e
JM
2156 fde_table_allocated = FDE_TABLE_INCREMENT;
2157 fde_table_in_use = 0;
2158
2159 /* Generate the CFA instructions common to all FDE's. Do it now for the
2160 sake of lookup_cfa. */
2161
a6ab3aad 2162#ifdef DWARF2_UNWIND_INFO
91193900
AS
2163 /* On entry, the Canonical Frame Address is at SP. */
2164 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2165 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3f76745e
JM
2166#endif
2167}
2168
2169void
2170dwarf2out_frame_finish ()
2171{
3f76745e 2172 /* Output call frame information. */
7a0c8d71 2173 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
3f76745e 2174 output_call_frame_info (0);
2ad9852d 2175
ddee9e8d 2176 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
3f76745e 2177 output_call_frame_info (1);
556273e0 2178}
7d9d8943
AM
2179\f
2180/* And now, the subset of the debugging information support code necessary
2181 for emitting location expressions. */
3f76745e 2182
b9203463
RH
2183/* We need some way to distinguish DW_OP_addr with a direct symbol
2184 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2185#define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2186
2187
7d9d8943
AM
2188typedef struct dw_val_struct *dw_val_ref;
2189typedef struct die_struct *dw_die_ref;
2190typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
63e46568 2191typedef struct dw_loc_list_struct *dw_loc_list_ref;
3f76745e
JM
2192
2193/* Each DIE may have a series of attribute/value pairs. Values
2194 can take on several forms. The forms that are used in this
2195 implementation are listed below. */
2196
2197typedef enum
2198{
2199 dw_val_class_addr,
a20612aa 2200 dw_val_class_offset,
3f76745e 2201 dw_val_class_loc,
63e46568 2202 dw_val_class_loc_list,
2bee6045 2203 dw_val_class_range_list,
3f76745e
JM
2204 dw_val_class_const,
2205 dw_val_class_unsigned_const,
2206 dw_val_class_long_long,
2207 dw_val_class_float,
2208 dw_val_class_flag,
2209 dw_val_class_die_ref,
2210 dw_val_class_fde_ref,
2211 dw_val_class_lbl_id,
8b790721 2212 dw_val_class_lbl_offset,
3f76745e 2213 dw_val_class_str
a3f97cbb 2214}
3f76745e 2215dw_val_class;
a3f97cbb 2216
3f76745e 2217/* Describe a double word constant value. */
21217bd0 2218/* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3f76745e
JM
2219
2220typedef struct dw_long_long_struct
a3f97cbb 2221{
3f76745e
JM
2222 unsigned long hi;
2223 unsigned long low;
2224}
2225dw_long_long_const;
2226
2227/* Describe a floating point constant value. */
2228
2229typedef struct dw_fp_struct
2230{
2231 long *array;
2232 unsigned length;
2233}
2234dw_float_const;
2235
956d6950 2236/* The dw_val_node describes an attribute's value, as it is
3f76745e
JM
2237 represented internally. */
2238
2239typedef struct dw_val_struct
2240{
2241 dw_val_class val_class;
2242 union
a3f97cbb 2243 {
1865dbb5 2244 rtx val_addr;
a20612aa 2245 long unsigned val_offset;
63e46568 2246 dw_loc_list_ref val_loc_list;
3f76745e
JM
2247 dw_loc_descr_ref val_loc;
2248 long int val_int;
2249 long unsigned val_unsigned;
2250 dw_long_long_const val_long_long;
2251 dw_float_const val_float;
2ad9852d
RK
2252 struct
2253 {
2254 dw_die_ref die;
2255 int external;
2256 } val_die_ref;
3f76745e 2257 unsigned val_fde_index;
9eb4015a 2258 struct indirect_string_node *val_str;
3f76745e 2259 char *val_lbl_id;
3f76745e 2260 unsigned char val_flag;
a3f97cbb 2261 }
3f76745e
JM
2262 v;
2263}
2264dw_val_node;
2265
2266/* Locations in memory are described using a sequence of stack machine
2267 operations. */
2268
2269typedef struct dw_loc_descr_struct
2270{
2271 dw_loc_descr_ref dw_loc_next;
2272 enum dwarf_location_atom dw_loc_opc;
2273 dw_val_node dw_loc_oprnd1;
2274 dw_val_node dw_loc_oprnd2;
d8041cc8 2275 int dw_loc_addr;
3f76745e
JM
2276}
2277dw_loc_descr_node;
2278
63e46568
DB
2279/* Location lists are ranges + location descriptions for that range,
2280 so you can track variables that are in different places over
30f7a378 2281 their entire life. */
63e46568
DB
2282typedef struct dw_loc_list_struct
2283{
2284 dw_loc_list_ref dw_loc_next;
2285 const char *begin; /* Label for begin address of range */
2286 const char *end; /* Label for end address of range */
2ad9852d
RK
2287 char *ll_symbol; /* Label for beginning of location list.
2288 Only on head of list */
63e46568
DB
2289 const char *section; /* Section this loclist is relative to */
2290 dw_loc_descr_ref expr;
2291} dw_loc_list_node;
2292
7d9d8943
AM
2293static const char *dwarf_stack_op_name PARAMS ((unsigned));
2294static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2295 unsigned long,
2296 unsigned long));
2297static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2298 dw_loc_descr_ref));
2299static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2300static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2301static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2302static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
3f76745e 2303
7d9d8943 2304/* Convert a DWARF stack opcode into its string name. */
3f76745e 2305
7d9d8943
AM
2306static const char *
2307dwarf_stack_op_name (op)
b3694847 2308 unsigned op;
ef76d03b 2309{
7d9d8943
AM
2310 switch (op)
2311 {
2312 case DW_OP_addr:
b9203463 2313 case INTERNAL_DW_OP_tls_addr:
7d9d8943
AM
2314 return "DW_OP_addr";
2315 case DW_OP_deref:
2316 return "DW_OP_deref";
2317 case DW_OP_const1u:
2318 return "DW_OP_const1u";
2319 case DW_OP_const1s:
2320 return "DW_OP_const1s";
2321 case DW_OP_const2u:
2322 return "DW_OP_const2u";
2323 case DW_OP_const2s:
2324 return "DW_OP_const2s";
2325 case DW_OP_const4u:
2326 return "DW_OP_const4u";
2327 case DW_OP_const4s:
2328 return "DW_OP_const4s";
2329 case DW_OP_const8u:
2330 return "DW_OP_const8u";
2331 case DW_OP_const8s:
2332 return "DW_OP_const8s";
2333 case DW_OP_constu:
2334 return "DW_OP_constu";
2335 case DW_OP_consts:
2336 return "DW_OP_consts";
2337 case DW_OP_dup:
2338 return "DW_OP_dup";
2339 case DW_OP_drop:
2340 return "DW_OP_drop";
2341 case DW_OP_over:
2342 return "DW_OP_over";
2343 case DW_OP_pick:
2344 return "DW_OP_pick";
2345 case DW_OP_swap:
2346 return "DW_OP_swap";
2347 case DW_OP_rot:
2348 return "DW_OP_rot";
2349 case DW_OP_xderef:
2350 return "DW_OP_xderef";
2351 case DW_OP_abs:
2352 return "DW_OP_abs";
2353 case DW_OP_and:
2354 return "DW_OP_and";
2355 case DW_OP_div:
2356 return "DW_OP_div";
2357 case DW_OP_minus:
2358 return "DW_OP_minus";
2359 case DW_OP_mod:
2360 return "DW_OP_mod";
2361 case DW_OP_mul:
2362 return "DW_OP_mul";
2363 case DW_OP_neg:
2364 return "DW_OP_neg";
2365 case DW_OP_not:
2366 return "DW_OP_not";
2367 case DW_OP_or:
2368 return "DW_OP_or";
2369 case DW_OP_plus:
2370 return "DW_OP_plus";
2371 case DW_OP_plus_uconst:
2372 return "DW_OP_plus_uconst";
2373 case DW_OP_shl:
2374 return "DW_OP_shl";
2375 case DW_OP_shr:
2376 return "DW_OP_shr";
2377 case DW_OP_shra:
2378 return "DW_OP_shra";
2379 case DW_OP_xor:
2380 return "DW_OP_xor";
2381 case DW_OP_bra:
2382 return "DW_OP_bra";
2383 case DW_OP_eq:
2384 return "DW_OP_eq";
2385 case DW_OP_ge:
2386 return "DW_OP_ge";
2387 case DW_OP_gt:
2388 return "DW_OP_gt";
2389 case DW_OP_le:
2390 return "DW_OP_le";
2391 case DW_OP_lt:
2392 return "DW_OP_lt";
2393 case DW_OP_ne:
2394 return "DW_OP_ne";
2395 case DW_OP_skip:
2396 return "DW_OP_skip";
2397 case DW_OP_lit0:
2398 return "DW_OP_lit0";
2399 case DW_OP_lit1:
2400 return "DW_OP_lit1";
2401 case DW_OP_lit2:
2402 return "DW_OP_lit2";
2403 case DW_OP_lit3:
2404 return "DW_OP_lit3";
2405 case DW_OP_lit4:
2406 return "DW_OP_lit4";
2407 case DW_OP_lit5:
2408 return "DW_OP_lit5";
2409 case DW_OP_lit6:
2410 return "DW_OP_lit6";
2411 case DW_OP_lit7:
2412 return "DW_OP_lit7";
2413 case DW_OP_lit8:
2414 return "DW_OP_lit8";
2415 case DW_OP_lit9:
2416 return "DW_OP_lit9";
2417 case DW_OP_lit10:
2418 return "DW_OP_lit10";
2419 case DW_OP_lit11:
2420 return "DW_OP_lit11";
2421 case DW_OP_lit12:
2422 return "DW_OP_lit12";
2423 case DW_OP_lit13:
2424 return "DW_OP_lit13";
2425 case DW_OP_lit14:
2426 return "DW_OP_lit14";
2427 case DW_OP_lit15:
2428 return "DW_OP_lit15";
2429 case DW_OP_lit16:
2430 return "DW_OP_lit16";
2431 case DW_OP_lit17:
2432 return "DW_OP_lit17";
2433 case DW_OP_lit18:
2434 return "DW_OP_lit18";
2435 case DW_OP_lit19:
2436 return "DW_OP_lit19";
2437 case DW_OP_lit20:
2438 return "DW_OP_lit20";
2439 case DW_OP_lit21:
2440 return "DW_OP_lit21";
2441 case DW_OP_lit22:
2442 return "DW_OP_lit22";
2443 case DW_OP_lit23:
2444 return "DW_OP_lit23";
2445 case DW_OP_lit24:
2446 return "DW_OP_lit24";
2447 case DW_OP_lit25:
2448 return "DW_OP_lit25";
2449 case DW_OP_lit26:
2450 return "DW_OP_lit26";
2451 case DW_OP_lit27:
2452 return "DW_OP_lit27";
2453 case DW_OP_lit28:
2454 return "DW_OP_lit28";
2455 case DW_OP_lit29:
2456 return "DW_OP_lit29";
2457 case DW_OP_lit30:
2458 return "DW_OP_lit30";
2459 case DW_OP_lit31:
2460 return "DW_OP_lit31";
2461 case DW_OP_reg0:
2462 return "DW_OP_reg0";
2463 case DW_OP_reg1:
2464 return "DW_OP_reg1";
2465 case DW_OP_reg2:
2466 return "DW_OP_reg2";
2467 case DW_OP_reg3:
2468 return "DW_OP_reg3";
2469 case DW_OP_reg4:
2470 return "DW_OP_reg4";
2471 case DW_OP_reg5:
2472 return "DW_OP_reg5";
2473 case DW_OP_reg6:
2474 return "DW_OP_reg6";
2475 case DW_OP_reg7:
2476 return "DW_OP_reg7";
2477 case DW_OP_reg8:
2478 return "DW_OP_reg8";
2479 case DW_OP_reg9:
2480 return "DW_OP_reg9";
2481 case DW_OP_reg10:
2482 return "DW_OP_reg10";
2483 case DW_OP_reg11:
2484 return "DW_OP_reg11";
2485 case DW_OP_reg12:
2486 return "DW_OP_reg12";
2487 case DW_OP_reg13:
2488 return "DW_OP_reg13";
2489 case DW_OP_reg14:
2490 return "DW_OP_reg14";
2491 case DW_OP_reg15:
2492 return "DW_OP_reg15";
2493 case DW_OP_reg16:
2494 return "DW_OP_reg16";
2495 case DW_OP_reg17:
2496 return "DW_OP_reg17";
2497 case DW_OP_reg18:
2498 return "DW_OP_reg18";
2499 case DW_OP_reg19:
2500 return "DW_OP_reg19";
2501 case DW_OP_reg20:
2502 return "DW_OP_reg20";
2503 case DW_OP_reg21:
2504 return "DW_OP_reg21";
2505 case DW_OP_reg22:
2506 return "DW_OP_reg22";
2507 case DW_OP_reg23:
2508 return "DW_OP_reg23";
2509 case DW_OP_reg24:
2510 return "DW_OP_reg24";
2511 case DW_OP_reg25:
2512 return "DW_OP_reg25";
2513 case DW_OP_reg26:
2514 return "DW_OP_reg26";
2515 case DW_OP_reg27:
2516 return "DW_OP_reg27";
2517 case DW_OP_reg28:
2518 return "DW_OP_reg28";
2519 case DW_OP_reg29:
2520 return "DW_OP_reg29";
2521 case DW_OP_reg30:
2522 return "DW_OP_reg30";
2523 case DW_OP_reg31:
2524 return "DW_OP_reg31";
2525 case DW_OP_breg0:
2526 return "DW_OP_breg0";
2527 case DW_OP_breg1:
2528 return "DW_OP_breg1";
2529 case DW_OP_breg2:
2530 return "DW_OP_breg2";
2531 case DW_OP_breg3:
2532 return "DW_OP_breg3";
2533 case DW_OP_breg4:
2534 return "DW_OP_breg4";
2535 case DW_OP_breg5:
2536 return "DW_OP_breg5";
2537 case DW_OP_breg6:
2538 return "DW_OP_breg6";
2539 case DW_OP_breg7:
2540 return "DW_OP_breg7";
2541 case DW_OP_breg8:
2542 return "DW_OP_breg8";
2543 case DW_OP_breg9:
2544 return "DW_OP_breg9";
2545 case DW_OP_breg10:
2546 return "DW_OP_breg10";
2547 case DW_OP_breg11:
2548 return "DW_OP_breg11";
2549 case DW_OP_breg12:
2550 return "DW_OP_breg12";
2551 case DW_OP_breg13:
2552 return "DW_OP_breg13";
2553 case DW_OP_breg14:
2554 return "DW_OP_breg14";
2555 case DW_OP_breg15:
2556 return "DW_OP_breg15";
2557 case DW_OP_breg16:
2558 return "DW_OP_breg16";
2559 case DW_OP_breg17:
2560 return "DW_OP_breg17";
2561 case DW_OP_breg18:
2562 return "DW_OP_breg18";
2563 case DW_OP_breg19:
2564 return "DW_OP_breg19";
2565 case DW_OP_breg20:
2566 return "DW_OP_breg20";
2567 case DW_OP_breg21:
2568 return "DW_OP_breg21";
2569 case DW_OP_breg22:
2570 return "DW_OP_breg22";
2571 case DW_OP_breg23:
2572 return "DW_OP_breg23";
2573 case DW_OP_breg24:
2574 return "DW_OP_breg24";
2575 case DW_OP_breg25:
2576 return "DW_OP_breg25";
2577 case DW_OP_breg26:
2578 return "DW_OP_breg26";
2579 case DW_OP_breg27:
2580 return "DW_OP_breg27";
2581 case DW_OP_breg28:
2582 return "DW_OP_breg28";
2583 case DW_OP_breg29:
2584 return "DW_OP_breg29";
2585 case DW_OP_breg30:
2586 return "DW_OP_breg30";
2587 case DW_OP_breg31:
2588 return "DW_OP_breg31";
2589 case DW_OP_regx:
2590 return "DW_OP_regx";
2591 case DW_OP_fbreg:
2592 return "DW_OP_fbreg";
2593 case DW_OP_bregx:
2594 return "DW_OP_bregx";
2595 case DW_OP_piece:
2596 return "DW_OP_piece";
2597 case DW_OP_deref_size:
2598 return "DW_OP_deref_size";
2599 case DW_OP_xderef_size:
2600 return "DW_OP_xderef_size";
2601 case DW_OP_nop:
2602 return "DW_OP_nop";
b9203463
RH
2603 case DW_OP_push_object_address:
2604 return "DW_OP_push_object_address";
2605 case DW_OP_call2:
2606 return "DW_OP_call2";
2607 case DW_OP_call4:
2608 return "DW_OP_call4";
2609 case DW_OP_call_ref:
2610 return "DW_OP_call_ref";
2611 case DW_OP_GNU_push_tls_address:
2612 return "DW_OP_GNU_push_tls_address";
3f76745e 2613 default:
7d9d8943 2614 return "OP_<unknown>";
3f76745e 2615 }
bdb669cb 2616}
a3f97cbb 2617
7d9d8943
AM
2618/* Return a pointer to a newly allocated location description. Location
2619 descriptions are simple expression terms that can be strung
2620 together to form more complicated location (address) descriptions. */
2621
2622static inline dw_loc_descr_ref
2623new_loc_descr (op, oprnd1, oprnd2)
b3694847
SS
2624 enum dwarf_location_atom op;
2625 unsigned long oprnd1;
2626 unsigned long oprnd2;
4b674448 2627{
5de0e8d4
JM
2628 /* Use xcalloc here so we clear out all of the long_long constant in
2629 the union. */
b3694847 2630 dw_loc_descr_ref descr
5de0e8d4 2631 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
71dfc51f 2632
7d9d8943
AM
2633 descr->dw_loc_opc = op;
2634 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2635 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2636 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2637 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
71dfc51f 2638
7d9d8943
AM
2639 return descr;
2640}
2641
63e46568 2642
7d9d8943
AM
2643/* Add a location description term to a location description expression. */
2644
2645static inline void
2646add_loc_descr (list_head, descr)
b3694847
SS
2647 dw_loc_descr_ref *list_head;
2648 dw_loc_descr_ref descr;
7d9d8943 2649{
b3694847 2650 dw_loc_descr_ref *d;
7d9d8943
AM
2651
2652 /* Find the end of the chain. */
2653 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2654 ;
2655
2656 *d = descr;
2657}
2658
2659/* Return the size of a location descriptor. */
2660
2661static unsigned long
2662size_of_loc_descr (loc)
b3694847 2663 dw_loc_descr_ref loc;
7d9d8943 2664{
b3694847 2665 unsigned long size = 1;
7d9d8943
AM
2666
2667 switch (loc->dw_loc_opc)
2668 {
2669 case DW_OP_addr:
b9203463 2670 case INTERNAL_DW_OP_tls_addr:
7d9d8943
AM
2671 size += DWARF2_ADDR_SIZE;
2672 break;
2673 case DW_OP_const1u:
2674 case DW_OP_const1s:
2675 size += 1;
2676 break;
2677 case DW_OP_const2u:
2678 case DW_OP_const2s:
2679 size += 2;
2680 break;
2681 case DW_OP_const4u:
2682 case DW_OP_const4s:
2683 size += 4;
2684 break;
2685 case DW_OP_const8u:
2686 case DW_OP_const8s:
2687 size += 8;
2688 break;
2689 case DW_OP_constu:
2690 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2691 break;
2692 case DW_OP_consts:
2693 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2694 break;
2695 case DW_OP_pick:
2696 size += 1;
2697 break;
2698 case DW_OP_plus_uconst:
2699 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2700 break;
2701 case DW_OP_skip:
2702 case DW_OP_bra:
2703 size += 2;
2704 break;
2705 case DW_OP_breg0:
2706 case DW_OP_breg1:
2707 case DW_OP_breg2:
2708 case DW_OP_breg3:
2709 case DW_OP_breg4:
2710 case DW_OP_breg5:
2711 case DW_OP_breg6:
2712 case DW_OP_breg7:
2713 case DW_OP_breg8:
2714 case DW_OP_breg9:
2715 case DW_OP_breg10:
2716 case DW_OP_breg11:
2717 case DW_OP_breg12:
2718 case DW_OP_breg13:
2719 case DW_OP_breg14:
2720 case DW_OP_breg15:
2721 case DW_OP_breg16:
2722 case DW_OP_breg17:
2723 case DW_OP_breg18:
2724 case DW_OP_breg19:
2725 case DW_OP_breg20:
2726 case DW_OP_breg21:
2727 case DW_OP_breg22:
2728 case DW_OP_breg23:
2729 case DW_OP_breg24:
2730 case DW_OP_breg25:
2731 case DW_OP_breg26:
2732 case DW_OP_breg27:
2733 case DW_OP_breg28:
2734 case DW_OP_breg29:
2735 case DW_OP_breg30:
2736 case DW_OP_breg31:
2737 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2738 break;
2739 case DW_OP_regx:
2740 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2741 break;
2742 case DW_OP_fbreg:
2743 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2744 break;
2745 case DW_OP_bregx:
2746 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2747 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2748 break;
2749 case DW_OP_piece:
2750 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2751 break;
2752 case DW_OP_deref_size:
2753 case DW_OP_xderef_size:
2754 size += 1;
2755 break;
b9203463
RH
2756 case DW_OP_call2:
2757 size += 2;
2758 break;
2759 case DW_OP_call4:
2760 size += 4;
2761 break;
2762 case DW_OP_call_ref:
2763 size += DWARF2_ADDR_SIZE;
2764 break;
3f76745e 2765 default:
7d9d8943 2766 break;
4b674448 2767 }
7d9d8943
AM
2768
2769 return size;
4b674448
JM
2770}
2771
7d9d8943 2772/* Return the size of a series of location descriptors. */
71dfc51f 2773
7d9d8943
AM
2774static unsigned long
2775size_of_locs (loc)
b3694847 2776 dw_loc_descr_ref loc;
4b674448 2777{
2ad9852d 2778 unsigned long size;
7d9d8943 2779
2ad9852d 2780 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
d8041cc8
RH
2781 {
2782 loc->dw_loc_addr = size;
2783 size += size_of_loc_descr (loc);
2784 }
7d9d8943
AM
2785
2786 return size;
4b674448
JM
2787}
2788
7d9d8943 2789/* Output location description stack opcode's operands (if any). */
71dfc51f 2790
7d9d8943
AM
2791static void
2792output_loc_operands (loc)
b3694847 2793 dw_loc_descr_ref loc;
a3f97cbb 2794{
b3694847
SS
2795 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2796 dw_val_ref val2 = &loc->dw_loc_oprnd2;
7d9d8943
AM
2797
2798 switch (loc->dw_loc_opc)
a3f97cbb 2799 {
0517872a 2800#ifdef DWARF2_DEBUGGING_INFO
3f76745e 2801 case DW_OP_addr:
2e4b9b8c 2802 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
7d9d8943 2803 break;
3f76745e 2804 case DW_OP_const2u:
3f76745e 2805 case DW_OP_const2s:
2e4b9b8c 2806 dw2_asm_output_data (2, val1->v.val_int, NULL);
7d9d8943 2807 break;
3f76745e 2808 case DW_OP_const4u:
3f76745e 2809 case DW_OP_const4s:
2e4b9b8c 2810 dw2_asm_output_data (4, val1->v.val_int, NULL);
7d9d8943 2811 break;
3f76745e 2812 case DW_OP_const8u:
3f76745e 2813 case DW_OP_const8s:
2e4b9b8c
RH
2814 if (HOST_BITS_PER_LONG < 64)
2815 abort ();
2816 dw2_asm_output_data (8, val1->v.val_int, NULL);
7d9d8943 2817 break;
0517872a
JM
2818 case DW_OP_skip:
2819 case DW_OP_bra:
d8041cc8
RH
2820 {
2821 int offset;
2822
2823 if (val1->val_class == dw_val_class_loc)
2824 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2825 else
2826 abort ();
2827
2e4b9b8c 2828 dw2_asm_output_data (2, offset, NULL);
d8041cc8 2829 }
0517872a 2830 break;
3139472f
JM
2831#else
2832 case DW_OP_addr:
2833 case DW_OP_const2u:
2834 case DW_OP_const2s:
2835 case DW_OP_const4u:
2836 case DW_OP_const4s:
2837 case DW_OP_const8u:
2838 case DW_OP_const8s:
2839 case DW_OP_skip:
2840 case DW_OP_bra:
2841 /* We currently don't make any attempt to make sure these are
2842 aligned properly like we do for the main unwind info, so
2843 don't support emitting things larger than a byte if we're
2844 only doing unwinding. */
2845 abort ();
0517872a
JM
2846#endif
2847 case DW_OP_const1u:
2848 case DW_OP_const1s:
2e4b9b8c 2849 dw2_asm_output_data (1, val1->v.val_int, NULL);
0517872a 2850 break;
3f76745e 2851 case DW_OP_constu:
2e4b9b8c 2852 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
7d9d8943 2853 break;
3f76745e 2854 case DW_OP_consts:
2e4b9b8c 2855 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
7d9d8943
AM
2856 break;
2857 case DW_OP_pick:
2e4b9b8c 2858 dw2_asm_output_data (1, val1->v.val_int, NULL);
7d9d8943
AM
2859 break;
2860 case DW_OP_plus_uconst:
2e4b9b8c 2861 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
7d9d8943 2862 break;
3f76745e 2863 case DW_OP_breg0:
3f76745e 2864 case DW_OP_breg1:
3f76745e 2865 case DW_OP_breg2:
3f76745e 2866 case DW_OP_breg3:
3f76745e 2867 case DW_OP_breg4:
3f76745e 2868 case DW_OP_breg5:
3f76745e 2869 case DW_OP_breg6:
3f76745e 2870 case DW_OP_breg7:
3f76745e 2871 case DW_OP_breg8:
3f76745e 2872 case DW_OP_breg9:
3f76745e 2873 case DW_OP_breg10:
3f76745e 2874 case DW_OP_breg11:
3f76745e 2875 case DW_OP_breg12:
3f76745e 2876 case DW_OP_breg13:
3f76745e 2877 case DW_OP_breg14:
3f76745e 2878 case DW_OP_breg15:
3f76745e 2879 case DW_OP_breg16:
3f76745e 2880 case DW_OP_breg17:
3f76745e 2881 case DW_OP_breg18:
3f76745e 2882 case DW_OP_breg19:
3f76745e 2883 case DW_OP_breg20:
3f76745e 2884 case DW_OP_breg21:
3f76745e 2885 case DW_OP_breg22:
3f76745e 2886 case DW_OP_breg23:
3f76745e 2887 case DW_OP_breg24:
3f76745e 2888 case DW_OP_breg25:
3f76745e 2889 case DW_OP_breg26:
3f76745e 2890 case DW_OP_breg27:
3f76745e 2891 case DW_OP_breg28:
3f76745e 2892 case DW_OP_breg29:
3f76745e 2893 case DW_OP_breg30:
3f76745e 2894 case DW_OP_breg31:
2e4b9b8c 2895 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
7d9d8943 2896 break;
3f76745e 2897 case DW_OP_regx:
2e4b9b8c 2898 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
7d9d8943 2899 break;
3f76745e 2900 case DW_OP_fbreg:
2e4b9b8c 2901 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
7d9d8943 2902 break;
3f76745e 2903 case DW_OP_bregx:
2e4b9b8c
RH
2904 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2905 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
7d9d8943 2906 break;
3f76745e 2907 case DW_OP_piece:
2e4b9b8c 2908 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
7d9d8943 2909 break;
3f76745e 2910 case DW_OP_deref_size:
3f76745e 2911 case DW_OP_xderef_size:
2e4b9b8c 2912 dw2_asm_output_data (1, val1->v.val_int, NULL);
7d9d8943 2913 break;
b9203463
RH
2914
2915 case INTERNAL_DW_OP_tls_addr:
2916#ifdef ASM_OUTPUT_DWARF_DTPREL
2917 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
2918 val1->v.val_addr);
2919 fputc ('\n', asm_out_file);
2920#else
2921 abort ();
2922#endif
2923 break;
2924
7d9d8943 2925 default:
3139472f
JM
2926 /* Other codes have no operands. */
2927 break;
7d9d8943
AM
2928 }
2929}
2930
2931/* Output a sequence of location operations. */
2932
2933static void
2934output_loc_sequence (loc)
2935 dw_loc_descr_ref loc;
2936{
2937 for (; loc != NULL; loc = loc->dw_loc_next)
2938 {
2939 /* Output the opcode. */
2e4b9b8c
RH
2940 dw2_asm_output_data (1, loc->dw_loc_opc,
2941 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
7d9d8943
AM
2942
2943 /* Output the operand(s) (if any). */
2944 output_loc_operands (loc);
2945 }
2946}
2947
2948/* This routine will generate the correct assembly data for a location
2949 description based on a cfi entry with a complex address. */
2950
2951static void
2952output_cfa_loc (cfi)
2953 dw_cfi_ref cfi;
2954{
2955 dw_loc_descr_ref loc;
2956 unsigned long size;
2957
2958 /* Output the size of the block. */
2959 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2960 size = size_of_locs (loc);
2e4b9b8c 2961 dw2_asm_output_data_uleb128 (size, NULL);
7d9d8943
AM
2962
2963 /* Now output the operations themselves. */
2964 output_loc_sequence (loc);
2965}
2966
dd49a9ec 2967/* This function builds a dwarf location descriptor sequence from
556273e0 2968 a dw_cfa_location. */
7d9d8943
AM
2969
2970static struct dw_loc_descr_struct *
2971build_cfa_loc (cfa)
2972 dw_cfa_location *cfa;
2973{
2974 struct dw_loc_descr_struct *head, *tmp;
2975
2976 if (cfa->indirect == 0)
2977 abort ();
2978
2979 if (cfa->base_offset)
f299afab
HPN
2980 {
2981 if (cfa->reg <= 31)
2982 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2983 else
2984 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2985 }
2986 else if (cfa->reg <= 31)
7d9d8943 2987 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
f299afab
HPN
2988 else
2989 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2ad9852d 2990
7d9d8943
AM
2991 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2992 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2993 add_loc_descr (&head, tmp);
2994 if (cfa->offset != 0)
2995 {
2996 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2997 add_loc_descr (&head, tmp);
2998 }
2ad9852d 2999
7d9d8943
AM
3000 return head;
3001}
3002
2ad9852d
RK
3003/* This function fills in aa dw_cfa_location structure from a dwarf location
3004 descriptor sequence. */
7d9d8943
AM
3005
3006static void
3007get_cfa_from_loc_descr (cfa, loc)
3008 dw_cfa_location *cfa;
556273e0 3009 struct dw_loc_descr_struct *loc;
7d9d8943 3010{
556273e0 3011 struct dw_loc_descr_struct *ptr;
7d9d8943
AM
3012 cfa->offset = 0;
3013 cfa->base_offset = 0;
3014 cfa->indirect = 0;
3015 cfa->reg = -1;
3016
3017 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3018 {
3019 enum dwarf_location_atom op = ptr->dw_loc_opc;
2ad9852d 3020
7d9d8943 3021 switch (op)
556273e0 3022 {
7d9d8943
AM
3023 case DW_OP_reg0:
3024 case DW_OP_reg1:
3025 case DW_OP_reg2:
3026 case DW_OP_reg3:
3027 case DW_OP_reg4:
3028 case DW_OP_reg5:
3029 case DW_OP_reg6:
3030 case DW_OP_reg7:
3031 case DW_OP_reg8:
3032 case DW_OP_reg9:
3033 case DW_OP_reg10:
3034 case DW_OP_reg11:
3035 case DW_OP_reg12:
3036 case DW_OP_reg13:
3037 case DW_OP_reg14:
3038 case DW_OP_reg15:
3039 case DW_OP_reg16:
3040 case DW_OP_reg17:
3041 case DW_OP_reg18:
3042 case DW_OP_reg19:
3043 case DW_OP_reg20:
3044 case DW_OP_reg21:
3045 case DW_OP_reg22:
3046 case DW_OP_reg23:
3047 case DW_OP_reg24:
3048 case DW_OP_reg25:
3049 case DW_OP_reg26:
3050 case DW_OP_reg27:
3051 case DW_OP_reg28:
3052 case DW_OP_reg29:
3053 case DW_OP_reg30:
3054 case DW_OP_reg31:
3055 cfa->reg = op - DW_OP_reg0;
3056 break;
3057 case DW_OP_regx:
3058 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
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 cfa->reg = op - DW_OP_breg0;
3093 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3094 break;
3095 case DW_OP_bregx:
3096 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3097 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3098 break;
3099 case DW_OP_deref:
3100 cfa->indirect = 1;
3101 break;
3102 case DW_OP_plus_uconst:
556273e0 3103 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
7d9d8943
AM
3104 break;
3105 default:
a1f300c0 3106 internal_error ("DW_LOC_OP %s not implemented\n",
400500c4 3107 dwarf_stack_op_name (ptr->dw_loc_opc));
7d9d8943
AM
3108 }
3109 }
3110}
3111#endif /* .debug_frame support */
3112\f
3113/* And now, the support for symbolic debugging information. */
3114#ifdef DWARF2_DEBUGGING_INFO
3115
117f9d28
GS
3116/* .debug_str support. */
3117static hashnode indirect_string_alloc PARAMS ((hash_table *));
3118static int output_indirect_string PARAMS ((struct cpp_reader *,
3119 hashnode, const PTR));
3120
3121
e2a12aca
NB
3122static void dwarf2out_init PARAMS ((const char *));
3123static void dwarf2out_finish PARAMS ((const char *));
7f905405
NB
3124static void dwarf2out_define PARAMS ((unsigned int, const char *));
3125static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3126static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3127static void dwarf2out_end_source_file PARAMS ((unsigned));
e2a12aca
NB
3128static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3129static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
e1772ac0 3130static bool dwarf2out_ignore_block PARAMS ((tree));
2b85879e 3131static void dwarf2out_global_decl PARAMS ((tree));
e1772ac0 3132static void dwarf2out_abstract_function PARAMS ((tree));
7f905405
NB
3133
3134/* The debug hooks structure. */
3135
54b6670a 3136const struct gcc_debug_hooks dwarf2_debug_hooks =
7f905405
NB
3137{
3138 dwarf2out_init,
3139 dwarf2out_finish,
3140 dwarf2out_define,
3141 dwarf2out_undef,
3142 dwarf2out_start_source_file,
a5a42b92
NB
3143 dwarf2out_end_source_file,
3144 dwarf2out_begin_block,
e2a12aca 3145 dwarf2out_end_block,
e1772ac0 3146 dwarf2out_ignore_block,
e2a12aca 3147 dwarf2out_source_line,
653e276c 3148 dwarf2out_begin_prologue,
702ada3d 3149 debug_nothing_int_charstar, /* end_prologue */
e2a12aca 3150 dwarf2out_end_epilogue,
653e276c 3151 debug_nothing_tree, /* begin_function */
2b85879e
NB
3152 debug_nothing_int, /* end_function */
3153 dwarf2out_decl, /* function_decl */
3154 dwarf2out_global_decl,
e1772ac0
NB
3155 debug_nothing_tree, /* deferred_inline_function */
3156 /* The DWARF 2 backend tries to reduce debugging bloat by not
3157 emitting the abstract description of inline functions until
3158 something tries to reference them. */
3159 dwarf2out_abstract_function, /* outlining_inline_function */
3160 debug_nothing_rtx /* label */
7f905405
NB
3161};
3162\f
7d9d8943
AM
3163/* NOTE: In the comments in this file, many references are made to
3164 "Debugging Information Entries". This term is abbreviated as `DIE'
3165 throughout the remainder of this file. */
3166
3167/* An internal representation of the DWARF output is built, and then
3168 walked to generate the DWARF debugging info. The walk of the internal
3169 representation is done after the entire program has been compiled.
3170 The types below are used to describe the internal representation. */
3171
3172/* Various DIE's use offsets relative to the beginning of the
3173 .debug_info section to refer to each other. */
3174
3175typedef long int dw_offset;
3176
3177/* Define typedefs here to avoid circular dependencies. */
3178
3179typedef struct dw_attr_struct *dw_attr_ref;
3180typedef struct dw_line_info_struct *dw_line_info_ref;
3181typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3182typedef struct pubname_struct *pubname_ref;
a20612aa 3183typedef struct dw_ranges_struct *dw_ranges_ref;
7d9d8943
AM
3184
3185/* Each entry in the line_info_table maintains the file and
3186 line number associated with the label generated for that
3187 entry. The label gives the PC value associated with
3188 the line number entry. */
3189
3190typedef struct dw_line_info_struct
3191{
3192 unsigned long dw_file_num;
3193 unsigned long dw_line_num;
3194}
3195dw_line_info_entry;
3196
3197/* Line information for functions in separate sections; each one gets its
3198 own sequence. */
3199typedef struct dw_separate_line_info_struct
3200{
3201 unsigned long dw_file_num;
3202 unsigned long dw_line_num;
3203 unsigned long function;
3204}
3205dw_separate_line_info_entry;
3206
3207/* Each DIE attribute has a field specifying the attribute kind,
3208 a link to the next attribute in the chain, and an attribute value.
3209 Attributes are typically linked below the DIE they modify. */
3210
3211typedef struct dw_attr_struct
3212{
3213 enum dwarf_attribute dw_attr;
3214 dw_attr_ref dw_attr_next;
3215 dw_val_node dw_attr_val;
3216}
3217dw_attr_node;
3218
3219/* The Debugging Information Entry (DIE) structure */
3220
3221typedef struct die_struct
3222{
3223 enum dwarf_tag die_tag;
881c6935 3224 char *die_symbol;
7d9d8943
AM
3225 dw_attr_ref die_attr;
3226 dw_die_ref die_parent;
3227 dw_die_ref die_child;
3228 dw_die_ref die_sib;
3229 dw_offset die_offset;
3230 unsigned long die_abbrev;
1bfb5f8f 3231 int die_mark;
7d9d8943
AM
3232}
3233die_node;
3234
3235/* The pubname structure */
3236
3237typedef struct pubname_struct
3238{
3239 dw_die_ref die;
556273e0 3240 char *name;
7d9d8943
AM
3241}
3242pubname_entry;
3243
a20612aa
RH
3244struct dw_ranges_struct
3245{
3246 int block_num;
3247};
3248
7d9d8943
AM
3249/* The limbo die list structure. */
3250typedef struct limbo_die_struct
3251{
3252 dw_die_ref die;
54ba1f0d 3253 tree created_for;
7d9d8943
AM
3254 struct limbo_die_struct *next;
3255}
3256limbo_die_node;
3257
3258/* How to start an assembler comment. */
3259#ifndef ASM_COMMENT_START
3260#define ASM_COMMENT_START ";#"
3261#endif
3262
cc2902df 3263/* Define a macro which returns nonzero for a TYPE_DECL which was
7d9d8943
AM
3264 implicitly generated for a tagged type.
3265
3266 Note that unlike the gcc front end (which generates a NULL named
3267 TYPE_DECL node for each complete tagged type, each array type, and
3268 each function type node created) the g++ front end generates a
3269 _named_ TYPE_DECL node for each tagged type node created.
3270 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3271 generate a DW_TAG_typedef DIE for them. */
3272
3273#define TYPE_DECL_IS_STUB(decl) \
3274 (DECL_NAME (decl) == NULL_TREE \
3275 || (DECL_ARTIFICIAL (decl) \
3276 && is_tagged_type (TREE_TYPE (decl)) \
3277 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3278 /* This is necessary for stub decls that \
3279 appear in nested inline functions. */ \
3280 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3281 && (decl_ultimate_origin (decl) \
3282 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3283
3284/* Information concerning the compilation unit's programming
3285 language, and compiler version. */
3286
7d9d8943
AM
3287/* Fixed size portion of the DWARF compilation unit header. */
3288#define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3289
7d9d8943
AM
3290/* Fixed size portion of public names info. */
3291#define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3292
3293/* Fixed size portion of the address range info. */
3294#define DWARF_ARANGES_HEADER_SIZE \
3295 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3296 - DWARF_OFFSET_SIZE)
3297
3298/* Size of padding portion in the address range info. It must be
3299 aligned to twice the pointer size. */
3300#define DWARF_ARANGES_PAD_SIZE \
3301 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3302 - (2 * DWARF_OFFSET_SIZE + 4))
3303
9d147085 3304/* Use assembler line directives if available. */
7d9d8943 3305#ifndef DWARF2_ASM_LINE_DEBUG_INFO
9d147085
RH
3306#ifdef HAVE_AS_DWARF2_DEBUG_LINE
3307#define DWARF2_ASM_LINE_DEBUG_INFO 1
3308#else
7d9d8943
AM
3309#define DWARF2_ASM_LINE_DEBUG_INFO 0
3310#endif
9d147085 3311#endif
7d9d8943 3312
7d9d8943
AM
3313/* Minimum line offset in a special line info. opcode.
3314 This value was chosen to give a reasonable range of values. */
3315#define DWARF_LINE_BASE -10
3316
a1f300c0 3317/* First special line opcode - leave room for the standard opcodes. */
7d9d8943
AM
3318#define DWARF_LINE_OPCODE_BASE 10
3319
3320/* Range of line offsets in a special line info. opcode. */
3321#define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3322
3323/* Flag that indicates the initial value of the is_stmt_start flag.
3324 In the present implementation, we do not mark any lines as
3325 the beginning of a source statement, because that information
3326 is not made available by the GCC front-end. */
3327#define DWARF_LINE_DEFAULT_IS_STMT_START 1
3328
3329/* This location is used by calc_die_sizes() to keep track
3330 the offset of each DIE within the .debug_info section. */
3331static unsigned long next_die_offset;
3332
3333/* Record the root of the DIE's built for the current compilation unit. */
3334static dw_die_ref comp_unit_die;
3335
3336/* A list of DIEs with a NULL parent waiting to be relocated. */
3337static limbo_die_node *limbo_die_list = 0;
3338
2e18bbae
RH
3339/* Structure used by lookup_filename to manage sets of filenames. */
3340struct file_table
3341{
3342 char **table;
3343 unsigned allocated;
3344 unsigned in_use;
3345 unsigned last_lookup_index;
3346};
7d9d8943
AM
3347
3348/* Size (in elements) of increments by which we may expand the filename
3349 table. */
3350#define FILE_TABLE_INCREMENT 64
3351
981975b6
RH
3352/* Filenames referenced by this compilation unit. */
3353static struct file_table file_table;
2e18bbae 3354
7d9d8943
AM
3355/* Local pointer to the name of the main input file. Initialized in
3356 dwarf2out_init. */
3357static const char *primary_filename;
3358
3359/* A pointer to the base of a table of references to DIE's that describe
3360 declarations. The table is indexed by DECL_UID() which is a unique
3361 number identifying each decl. */
3362static dw_die_ref *decl_die_table;
3363
3364/* Number of elements currently allocated for the decl_die_table. */
3365static unsigned decl_die_table_allocated;
3366
3367/* Number of elements in decl_die_table currently in use. */
3368static unsigned decl_die_table_in_use;
3369
3370/* Size (in elements) of increments by which we may expand the
3371 decl_die_table. */
3372#define DECL_DIE_TABLE_INCREMENT 256
3373
7d9d8943
AM
3374/* A pointer to the base of a list of references to DIE's that
3375 are uniquely identified by their tag, presence/absence of
3376 children DIE's, and list of attribute/value pairs. */
3377static dw_die_ref *abbrev_die_table;
3378
3379/* Number of elements currently allocated for abbrev_die_table. */
3380static unsigned abbrev_die_table_allocated;
3381
3382/* Number of elements in type_die_table currently in use. */
3383static unsigned abbrev_die_table_in_use;
3384
3385/* Size (in elements) of increments by which we may expand the
3386 abbrev_die_table. */
3387#define ABBREV_DIE_TABLE_INCREMENT 256
3388
3389/* A pointer to the base of a table that contains line information
3390 for each source code line in .text in the compilation unit. */
3391static dw_line_info_ref line_info_table;
3392
3393/* Number of elements currently allocated for line_info_table. */
3394static unsigned line_info_table_allocated;
3395
3396/* Number of elements in separate_line_info_table currently in use. */
3397static unsigned separate_line_info_table_in_use;
3398
3399/* A pointer to the base of a table that contains line information
3400 for each source code line outside of .text in the compilation unit. */
3401static dw_separate_line_info_ref separate_line_info_table;
3402
3403/* Number of elements currently allocated for separate_line_info_table. */
3404static unsigned separate_line_info_table_allocated;
3405
3406/* Number of elements in line_info_table currently in use. */
3407static unsigned line_info_table_in_use;
3408
3409/* Size (in elements) of increments by which we may expand the
3410 line_info_table. */
3411#define LINE_INFO_TABLE_INCREMENT 1024
3412
3413/* A pointer to the base of a table that contains a list of publicly
3414 accessible names. */
3415static pubname_ref pubname_table;
3416
3417/* Number of elements currently allocated for pubname_table. */
3418static unsigned pubname_table_allocated;
3419
3420/* Number of elements in pubname_table currently in use. */
3421static unsigned pubname_table_in_use;
3422
3423/* Size (in elements) of increments by which we may expand the
3424 pubname_table. */
3425#define PUBNAME_TABLE_INCREMENT 64
3426
a20612aa
RH
3427/* Array of dies for which we should generate .debug_arange info. */
3428static dw_die_ref *arange_table;
7d9d8943
AM
3429
3430/* Number of elements currently allocated for arange_table. */
3431static unsigned arange_table_allocated;
3432
3433/* Number of elements in arange_table currently in use. */
3434static unsigned arange_table_in_use;
3435
3436/* Size (in elements) of increments by which we may expand the
3437 arange_table. */
3438#define ARANGE_TABLE_INCREMENT 64
3439
a20612aa
RH
3440/* Array of dies for which we should generate .debug_ranges info. */
3441static dw_ranges_ref ranges_table;
3442
3443/* Number of elements currently allocated for ranges_table. */
3444static unsigned ranges_table_allocated;
3445
3446/* Number of elements in ranges_table currently in use. */
3447static unsigned ranges_table_in_use;
3448
3449/* Size (in elements) of increments by which we may expand the
3450 ranges_table. */
3451#define RANGES_TABLE_INCREMENT 64
3452
63e46568
DB
3453/* Whether we have location lists that need outputting */
3454static unsigned have_location_lists;
3455
7d9d8943
AM
3456/* Record whether the function being analyzed contains inlined functions. */
3457static int current_function_has_inlines;
3458#if 0 && defined (MIPS_DEBUGGING_INFO)
3459static int comp_unit_has_inlines;
3460#endif
3461
7d9d8943
AM
3462/* Forward declarations for functions defined in this file. */
3463
3464static int is_pseudo_reg PARAMS ((rtx));
3465static tree type_main_variant PARAMS ((tree));
3466static int is_tagged_type PARAMS ((tree));
3467static const char *dwarf_tag_name PARAMS ((unsigned));
3468static const char *dwarf_attr_name PARAMS ((unsigned));
3469static const char *dwarf_form_name PARAMS ((unsigned));
3470#if 0
3471static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3472#endif
3473static tree decl_ultimate_origin PARAMS ((tree));
3474static tree block_ultimate_origin PARAMS ((tree));
3475static tree decl_class_context PARAMS ((tree));
3476static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
2ad9852d 3477static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
7d9d8943
AM
3478static void add_AT_flag PARAMS ((dw_die_ref,
3479 enum dwarf_attribute,
3480 unsigned));
2ad9852d 3481static inline unsigned AT_flag PARAMS ((dw_attr_ref));
7d9d8943
AM
3482static void add_AT_int PARAMS ((dw_die_ref,
3483 enum dwarf_attribute, long));
2ad9852d 3484static inline long int AT_int PARAMS ((dw_attr_ref));
7d9d8943
AM
3485static void add_AT_unsigned PARAMS ((dw_die_ref,
3486 enum dwarf_attribute,
3487 unsigned long));
2ad9852d 3488static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
7d9d8943
AM
3489static void add_AT_long_long PARAMS ((dw_die_ref,
3490 enum dwarf_attribute,
3491 unsigned long,
3492 unsigned long));
3493static void add_AT_float PARAMS ((dw_die_ref,
3494 enum dwarf_attribute,
3495 unsigned, long *));
3496static void add_AT_string PARAMS ((dw_die_ref,
3497 enum dwarf_attribute,
3498 const char *));
2ad9852d
RK
3499static inline const char *AT_string PARAMS ((dw_attr_ref));
3500static int AT_string_form PARAMS ((dw_attr_ref));
7d9d8943
AM
3501static void add_AT_die_ref PARAMS ((dw_die_ref,
3502 enum dwarf_attribute,
3503 dw_die_ref));
2ad9852d
RK
3504static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3505static inline int AT_ref_external PARAMS ((dw_attr_ref));
3506static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
7d9d8943
AM
3507static void add_AT_fde_ref PARAMS ((dw_die_ref,
3508 enum dwarf_attribute,
3509 unsigned));
3510static void add_AT_loc PARAMS ((dw_die_ref,
3511 enum dwarf_attribute,
3512 dw_loc_descr_ref));
2ad9852d 3513static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
63e46568
DB
3514static void add_AT_loc_list PARAMS ((dw_die_ref,
3515 enum dwarf_attribute,
3516 dw_loc_list_ref));
2ad9852d 3517static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
7d9d8943
AM
3518static void add_AT_addr PARAMS ((dw_die_ref,
3519 enum dwarf_attribute,
3520 rtx));
2ad9852d 3521static inline rtx AT_addr PARAMS ((dw_attr_ref));
7d9d8943
AM
3522static void add_AT_lbl_id PARAMS ((dw_die_ref,
3523 enum dwarf_attribute,
3524 const char *));
3525static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3526 enum dwarf_attribute,
3527 const char *));
a20612aa
RH
3528static void add_AT_offset PARAMS ((dw_die_ref,
3529 enum dwarf_attribute,
3530 unsigned long));
2bee6045
JJ
3531static void add_AT_range_list PARAMS ((dw_die_ref,
3532 enum dwarf_attribute,
3533 unsigned long));
2ad9852d 3534static inline const char *AT_lbl PARAMS ((dw_attr_ref));
7d9d8943
AM
3535static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3536 enum dwarf_attribute));
3537static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3538static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3539static const char *get_AT_string PARAMS ((dw_die_ref,
3540 enum dwarf_attribute));
3541static int get_AT_flag PARAMS ((dw_die_ref,
3542 enum dwarf_attribute));
3543static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3544 enum dwarf_attribute));
3545static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3546 enum dwarf_attribute));
3547static int is_c_family PARAMS ((void));
710af899 3548static int is_cxx PARAMS ((void));
28985b81 3549static int is_java PARAMS ((void));
7d9d8943
AM
3550static int is_fortran PARAMS ((void));
3551static void remove_AT PARAMS ((dw_die_ref,
3552 enum dwarf_attribute));
2ad9852d 3553static inline void free_die PARAMS ((dw_die_ref));
7d9d8943
AM
3554static void remove_children PARAMS ((dw_die_ref));
3555static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
54ba1f0d
RH
3556static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3557 tree));
7d9d8943
AM
3558static dw_die_ref lookup_type_die PARAMS ((tree));
3559static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3560static dw_die_ref lookup_decl_die PARAMS ((tree));
3561static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3562static void print_spaces PARAMS ((FILE *));
3563static void print_die PARAMS ((dw_die_ref, FILE *));
3564static void print_dwarf_line_table PARAMS ((FILE *));
881c6935
JM
3565static void reverse_die_lists PARAMS ((dw_die_ref));
3566static void reverse_all_dies PARAMS ((dw_die_ref));
3567static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3568static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
2ad9852d
RK
3569static void loc_checksum PARAMS ((dw_loc_descr_ref,
3570 struct md5_ctx *));
3571static void attr_checksum PARAMS ((dw_attr_ref,
3572 struct md5_ctx *));
3573static void die_checksum PARAMS ((dw_die_ref,
3574 struct md5_ctx *));
881c6935
JM
3575static void compute_section_prefix PARAMS ((dw_die_ref));
3576static int is_type_die PARAMS ((dw_die_ref));
3577static int is_comdat_die PARAMS ((dw_die_ref));
3578static int is_symbol_die PARAMS ((dw_die_ref));
881c6935
JM
3579static void assign_symbol_names PARAMS ((dw_die_ref));
3580static void break_out_includes PARAMS ((dw_die_ref));
7d9d8943
AM
3581static void add_sibling_attributes PARAMS ((dw_die_ref));
3582static void build_abbrev_table PARAMS ((dw_die_ref));
63e46568 3583static void output_location_lists PARAMS ((dw_die_ref));
7d9d8943
AM
3584static int constant_size PARAMS ((long unsigned));
3585static unsigned long size_of_die PARAMS ((dw_die_ref));
3586static void calc_die_sizes PARAMS ((dw_die_ref));
1bfb5f8f
JM
3587static void mark_dies PARAMS ((dw_die_ref));
3588static void unmark_dies PARAMS ((dw_die_ref));
7d9d8943
AM
3589static unsigned long size_of_pubnames PARAMS ((void));
3590static unsigned long size_of_aranges PARAMS ((void));
3591static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3592static void output_value_format PARAMS ((dw_attr_ref));
3593static void output_abbrev_section PARAMS ((void));
881c6935 3594static void output_die_symbol PARAMS ((dw_die_ref));
7d9d8943
AM
3595static void output_die PARAMS ((dw_die_ref));
3596static void output_compilation_unit_header PARAMS ((void));
881c6935 3597static void output_comp_unit PARAMS ((dw_die_ref));
7d9d8943
AM
3598static const char *dwarf2_name PARAMS ((tree, int));
3599static void add_pubname PARAMS ((tree, dw_die_ref));
3600static void output_pubnames PARAMS ((void));
3601static void add_arange PARAMS ((tree, dw_die_ref));
3602static void output_aranges PARAMS ((void));
a20612aa
RH
3603static unsigned int add_ranges PARAMS ((tree));
3604static void output_ranges PARAMS ((void));
7d9d8943 3605static void output_line_info PARAMS ((void));
0b34cf1e 3606static void output_file_names PARAMS ((void));
7d9d8943
AM
3607static dw_die_ref base_type_die PARAMS ((tree));
3608static tree root_type PARAMS ((tree));
3609static int is_base_type PARAMS ((tree));
3610static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3611static int type_is_enum PARAMS ((tree));
3612static unsigned int reg_number PARAMS ((rtx));
3613static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
d8041cc8 3614static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
7d9d8943
AM
3615static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3616static int is_based_loc PARAMS ((rtx));
3617static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3618static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3619static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
d8041cc8 3620static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
7d9d8943
AM
3621static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3622static tree field_type PARAMS ((tree));
3623static unsigned int simple_type_align_in_bits PARAMS ((tree));
5f446d21 3624static unsigned int simple_decl_align_in_bits PARAMS ((tree));
7d9d8943
AM
3625static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3626static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3627static void add_AT_location_description PARAMS ((dw_die_ref,
b9203463
RH
3628 enum dwarf_attribute,
3629 dw_loc_descr_ref));
7d9d8943
AM
3630static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3631static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
d8041cc8 3632static rtx rtl_for_decl_location PARAMS ((tree));
7d9d8943 3633static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
1bfb5f8f 3634static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
7d9d8943
AM
3635static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3636static void add_bound_info PARAMS ((dw_die_ref,
3637 enum dwarf_attribute, tree));
3638static void add_subscript_info PARAMS ((dw_die_ref, tree));
3639static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3640static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3641static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3642static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3643static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3644static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3645static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3646static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3647static void push_decl_scope PARAMS ((tree));
7d9d8943 3648static void pop_decl_scope PARAMS ((void));
2ad9852d
RK
3649static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3650static inline int local_scope_p PARAMS ((dw_die_ref));
3651static inline int class_scope_p PARAMS ((dw_die_ref));
7d9d8943
AM
3652static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3653 dw_die_ref));
3654static const char *type_tag PARAMS ((tree));
3655static tree member_declared_type PARAMS ((tree));
3656#if 0
3657static const char *decl_start_label PARAMS ((tree));
3658#endif
3659static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3660static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3661#if 0
3662static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3663#endif
3664static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3665static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3666static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3667static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3668static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3669static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3670static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3671static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3672static void gen_variable_die PARAMS ((tree, dw_die_ref));
3673static void gen_label_die PARAMS ((tree, dw_die_ref));
3674static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3675static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3676static void gen_field_die PARAMS ((tree, dw_die_ref));
3677static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3678static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3679static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3680static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3681static void gen_member_die PARAMS ((tree, dw_die_ref));
3682static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3683static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3684static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3685static void gen_type_die PARAMS ((tree, dw_die_ref));
3686static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3687static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3688static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3689static int is_redundant_typedef PARAMS ((tree));
3690static void gen_decl_die PARAMS ((tree, dw_die_ref));
981975b6
RH
3691static unsigned lookup_filename PARAMS ((const char *));
3692static void init_file_table PARAMS ((void));
7d9d8943
AM
3693static void retry_incomplete_types PARAMS ((void));
3694static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
7d9d8943 3695static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
fc608b03 3696static int file_info_cmp PARAMS ((const void *, const void *));
c26fbbca 3697static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
84a5b4f8
DB
3698 const char *, const char *,
3699 const char *, unsigned));
3700static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3701 dw_loc_descr_ref,
3702 const char *, const char *, const char *));
3703static void output_loc_list PARAMS ((dw_loc_list_ref));
3704static char *gen_internal_sym PARAMS ((const char *));
54ba1f0d 3705static void mark_limbo_die_list PARAMS ((void *));
7d9d8943
AM
3706
3707/* Section names used to hold DWARF debugging information. */
3708#ifndef DEBUG_INFO_SECTION
3709#define DEBUG_INFO_SECTION ".debug_info"
3710#endif
9d2f2c45
RH
3711#ifndef DEBUG_ABBREV_SECTION
3712#define DEBUG_ABBREV_SECTION ".debug_abbrev"
7d9d8943 3713#endif
9d2f2c45
RH
3714#ifndef DEBUG_ARANGES_SECTION
3715#define DEBUG_ARANGES_SECTION ".debug_aranges"
7d9d8943 3716#endif
9d2f2c45
RH
3717#ifndef DEBUG_MACINFO_SECTION
3718#define DEBUG_MACINFO_SECTION ".debug_macinfo"
7d9d8943
AM
3719#endif
3720#ifndef DEBUG_LINE_SECTION
3721#define DEBUG_LINE_SECTION ".debug_line"
3722#endif
9d2f2c45
RH
3723#ifndef DEBUG_LOC_SECTION
3724#define DEBUG_LOC_SECTION ".debug_loc"
7d9d8943 3725#endif
9d2f2c45
RH
3726#ifndef DEBUG_PUBNAMES_SECTION
3727#define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
7d9d8943 3728#endif
9d2f2c45
RH
3729#ifndef DEBUG_STR_SECTION
3730#define DEBUG_STR_SECTION ".debug_str"
7d9d8943 3731#endif
a20612aa
RH
3732#ifndef DEBUG_RANGES_SECTION
3733#define DEBUG_RANGES_SECTION ".debug_ranges"
3734#endif
7d9d8943
AM
3735
3736/* Standard ELF section names for compiled code and data. */
f99ffb60
RH
3737#ifndef TEXT_SECTION_NAME
3738#define TEXT_SECTION_NAME ".text"
7d9d8943
AM
3739#endif
3740
9eb4015a
JJ
3741/* Section flags for .debug_str section. */
3742#ifdef HAVE_GAS_SHF_MERGE
3743#define DEBUG_STR_SECTION_FLAGS \
3744 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3745#else
3746#define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3747#endif
3748
7d9d8943 3749/* Labels we insert at beginning sections we can reference instead of
556273e0 3750 the section names themselves. */
7d9d8943
AM
3751
3752#ifndef TEXT_SECTION_LABEL
9d2f2c45 3753#define TEXT_SECTION_LABEL "Ltext"
7d9d8943
AM
3754#endif
3755#ifndef DEBUG_LINE_SECTION_LABEL
9d2f2c45 3756#define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
7d9d8943
AM
3757#endif
3758#ifndef DEBUG_INFO_SECTION_LABEL
9d2f2c45 3759#define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
7d9d8943 3760#endif
9d2f2c45
RH
3761#ifndef DEBUG_ABBREV_SECTION_LABEL
3762#define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
7d9d8943 3763#endif
9d2f2c45
RH
3764#ifndef DEBUG_LOC_SECTION_LABEL
3765#define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
63e46568 3766#endif
2bee6045
JJ
3767#ifndef DEBUG_RANGES_SECTION_LABEL
3768#define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3769#endif
84a5b4f8
DB
3770#ifndef DEBUG_MACINFO_SECTION_LABEL
3771#define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3772#endif
a20612aa 3773
7d9d8943
AM
3774/* Definitions of defaults for formats and names of various special
3775 (artificial) labels which may be generated within this file (when the -g
3776 options is used and DWARF_DEBUGGING_INFO is in effect.
3777 If necessary, these may be overridden from within the tm.h file, but
3778 typically, overriding these defaults is unnecessary. */
3779
3780static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3781static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3782static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3783static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3784static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
84a5b4f8 3785static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
63e46568 3786static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2bee6045 3787static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
2ad9852d 3788
7d9d8943
AM
3789#ifndef TEXT_END_LABEL
3790#define TEXT_END_LABEL "Letext"
3791#endif
7d9d8943
AM
3792#ifndef BLOCK_BEGIN_LABEL
3793#define BLOCK_BEGIN_LABEL "LBB"
3794#endif
3795#ifndef BLOCK_END_LABEL
3796#define BLOCK_END_LABEL "LBE"
3797#endif
7d9d8943
AM
3798#ifndef LINE_CODE_LABEL
3799#define LINE_CODE_LABEL "LM"
3800#endif
3801#ifndef SEPARATE_LINE_CODE_LABEL
3802#define SEPARATE_LINE_CODE_LABEL "LSM"
3803#endif
3804\f
3805/* We allow a language front-end to designate a function that is to be
3806 called to "demangle" any name before it it put into a DIE. */
3807
3808static const char *(*demangle_name_func) PARAMS ((const char *));
3809
3810void
3811dwarf2out_set_demangle_name_func (func)
3812 const char *(*func) PARAMS ((const char *));
3813{
3814 demangle_name_func = func;
3815}
7d9d8943
AM
3816
3817/* Test if rtl node points to a pseudo register. */
3818
3819static inline int
3820is_pseudo_reg (rtl)
b3694847 3821 rtx rtl;
7d9d8943
AM
3822{
3823 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3824 || (GET_CODE (rtl) == SUBREG
ddef6bc7 3825 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
7d9d8943
AM
3826}
3827
3828/* Return a reference to a type, with its const and volatile qualifiers
3829 removed. */
3830
3831static inline tree
3832type_main_variant (type)
b3694847 3833 tree type;
7d9d8943
AM
3834{
3835 type = TYPE_MAIN_VARIANT (type);
3836
2ad9852d
RK
3837 /* ??? There really should be only one main variant among any group of
3838 variants of a given type (and all of the MAIN_VARIANT values for all
3839 members of the group should point to that one type) but sometimes the C
3840 front-end messes this up for array types, so we work around that bug
3841 here. */
7d9d8943
AM
3842 if (TREE_CODE (type) == ARRAY_TYPE)
3843 while (type != TYPE_MAIN_VARIANT (type))
3844 type = TYPE_MAIN_VARIANT (type);
3845
3846 return type;
3847}
3848
cc2902df 3849/* Return nonzero if the given type node represents a tagged type. */
7d9d8943
AM
3850
3851static inline int
3852is_tagged_type (type)
b3694847 3853 tree type;
7d9d8943 3854{
b3694847 3855 enum tree_code code = TREE_CODE (type);
7d9d8943
AM
3856
3857 return (code == RECORD_TYPE || code == UNION_TYPE
3858 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3859}
3860
3861/* Convert a DIE tag into its string name. */
3862
3863static const char *
3864dwarf_tag_name (tag)
b3694847 3865 unsigned tag;
7d9d8943
AM
3866{
3867 switch (tag)
3868 {
3869 case DW_TAG_padding:
3870 return "DW_TAG_padding";
3871 case DW_TAG_array_type:
3872 return "DW_TAG_array_type";
3873 case DW_TAG_class_type:
3874 return "DW_TAG_class_type";
3875 case DW_TAG_entry_point:
3876 return "DW_TAG_entry_point";
3877 case DW_TAG_enumeration_type:
3878 return "DW_TAG_enumeration_type";
3879 case DW_TAG_formal_parameter:
3880 return "DW_TAG_formal_parameter";
3881 case DW_TAG_imported_declaration:
3882 return "DW_TAG_imported_declaration";
3883 case DW_TAG_label:
3884 return "DW_TAG_label";
3885 case DW_TAG_lexical_block:
3886 return "DW_TAG_lexical_block";
3887 case DW_TAG_member:
3888 return "DW_TAG_member";
3889 case DW_TAG_pointer_type:
3890 return "DW_TAG_pointer_type";
3891 case DW_TAG_reference_type:
3892 return "DW_TAG_reference_type";
3893 case DW_TAG_compile_unit:
3894 return "DW_TAG_compile_unit";
3895 case DW_TAG_string_type:
3896 return "DW_TAG_string_type";
3897 case DW_TAG_structure_type:
3898 return "DW_TAG_structure_type";
3899 case DW_TAG_subroutine_type:
3900 return "DW_TAG_subroutine_type";
3901 case DW_TAG_typedef:
3902 return "DW_TAG_typedef";
3903 case DW_TAG_union_type:
3904 return "DW_TAG_union_type";
3905 case DW_TAG_unspecified_parameters:
3906 return "DW_TAG_unspecified_parameters";
3907 case DW_TAG_variant:
3908 return "DW_TAG_variant";
3909 case DW_TAG_common_block:
3910 return "DW_TAG_common_block";
3911 case DW_TAG_common_inclusion:
3912 return "DW_TAG_common_inclusion";
3913 case DW_TAG_inheritance:
3914 return "DW_TAG_inheritance";
3915 case DW_TAG_inlined_subroutine:
3916 return "DW_TAG_inlined_subroutine";
3917 case DW_TAG_module:
3918 return "DW_TAG_module";
3919 case DW_TAG_ptr_to_member_type:
3920 return "DW_TAG_ptr_to_member_type";
3921 case DW_TAG_set_type:
3922 return "DW_TAG_set_type";
3923 case DW_TAG_subrange_type:
3924 return "DW_TAG_subrange_type";
3925 case DW_TAG_with_stmt:
3926 return "DW_TAG_with_stmt";
3927 case DW_TAG_access_declaration:
3928 return "DW_TAG_access_declaration";
3929 case DW_TAG_base_type:
3930 return "DW_TAG_base_type";
3931 case DW_TAG_catch_block:
3932 return "DW_TAG_catch_block";
3933 case DW_TAG_const_type:
3934 return "DW_TAG_const_type";
3935 case DW_TAG_constant:
3936 return "DW_TAG_constant";
3937 case DW_TAG_enumerator:
3938 return "DW_TAG_enumerator";
3939 case DW_TAG_file_type:
3940 return "DW_TAG_file_type";
3941 case DW_TAG_friend:
3942 return "DW_TAG_friend";
3943 case DW_TAG_namelist:
3944 return "DW_TAG_namelist";
3945 case DW_TAG_namelist_item:
3946 return "DW_TAG_namelist_item";
3947 case DW_TAG_packed_type:
3948 return "DW_TAG_packed_type";
3949 case DW_TAG_subprogram:
3950 return "DW_TAG_subprogram";
3951 case DW_TAG_template_type_param:
3952 return "DW_TAG_template_type_param";
3953 case DW_TAG_template_value_param:
3954 return "DW_TAG_template_value_param";
3955 case DW_TAG_thrown_type:
3956 return "DW_TAG_thrown_type";
3957 case DW_TAG_try_block:
3958 return "DW_TAG_try_block";
3959 case DW_TAG_variant_part:
3960 return "DW_TAG_variant_part";
3961 case DW_TAG_variable:
3962 return "DW_TAG_variable";
3963 case DW_TAG_volatile_type:
3964 return "DW_TAG_volatile_type";
3965 case DW_TAG_MIPS_loop:
3966 return "DW_TAG_MIPS_loop";
3967 case DW_TAG_format_label:
3968 return "DW_TAG_format_label";
3969 case DW_TAG_function_template:
3970 return "DW_TAG_function_template";
3971 case DW_TAG_class_template:
3972 return "DW_TAG_class_template";
881c6935
JM
3973 case DW_TAG_GNU_BINCL:
3974 return "DW_TAG_GNU_BINCL";
3975 case DW_TAG_GNU_EINCL:
3976 return "DW_TAG_GNU_EINCL";
7d9d8943
AM
3977 default:
3978 return "DW_TAG_<unknown>";
3979 }
3980}
3981
3982/* Convert a DWARF attribute code into its string name. */
3983
3984static const char *
3985dwarf_attr_name (attr)
b3694847 3986 unsigned attr;
7d9d8943
AM
3987{
3988 switch (attr)
3989 {
3990 case DW_AT_sibling:
3991 return "DW_AT_sibling";
3992 case DW_AT_location:
3993 return "DW_AT_location";
3994 case DW_AT_name:
3995 return "DW_AT_name";
3996 case DW_AT_ordering:
3997 return "DW_AT_ordering";
3998 case DW_AT_subscr_data:
3999 return "DW_AT_subscr_data";
4000 case DW_AT_byte_size:
4001 return "DW_AT_byte_size";
4002 case DW_AT_bit_offset:
4003 return "DW_AT_bit_offset";
4004 case DW_AT_bit_size:
4005 return "DW_AT_bit_size";
4006 case DW_AT_element_list:
4007 return "DW_AT_element_list";
4008 case DW_AT_stmt_list:
4009 return "DW_AT_stmt_list";
4010 case DW_AT_low_pc:
4011 return "DW_AT_low_pc";
4012 case DW_AT_high_pc:
4013 return "DW_AT_high_pc";
4014 case DW_AT_language:
4015 return "DW_AT_language";
4016 case DW_AT_member:
4017 return "DW_AT_member";
4018 case DW_AT_discr:
4019 return "DW_AT_discr";
4020 case DW_AT_discr_value:
4021 return "DW_AT_discr_value";
4022 case DW_AT_visibility:
4023 return "DW_AT_visibility";
4024 case DW_AT_import:
4025 return "DW_AT_import";
4026 case DW_AT_string_length:
4027 return "DW_AT_string_length";
4028 case DW_AT_common_reference:
4029 return "DW_AT_common_reference";
4030 case DW_AT_comp_dir:
4031 return "DW_AT_comp_dir";
4032 case DW_AT_const_value:
4033 return "DW_AT_const_value";
4034 case DW_AT_containing_type:
4035 return "DW_AT_containing_type";
4036 case DW_AT_default_value:
4037 return "DW_AT_default_value";
4038 case DW_AT_inline:
4039 return "DW_AT_inline";
4040 case DW_AT_is_optional:
4041 return "DW_AT_is_optional";
4042 case DW_AT_lower_bound:
4043 return "DW_AT_lower_bound";
4044 case DW_AT_producer:
4045 return "DW_AT_producer";
4046 case DW_AT_prototyped:
4047 return "DW_AT_prototyped";
4048 case DW_AT_return_addr:
4049 return "DW_AT_return_addr";
4050 case DW_AT_start_scope:
4051 return "DW_AT_start_scope";
4052 case DW_AT_stride_size:
4053 return "DW_AT_stride_size";
4054 case DW_AT_upper_bound:
4055 return "DW_AT_upper_bound";
4056 case DW_AT_abstract_origin:
4057 return "DW_AT_abstract_origin";
4058 case DW_AT_accessibility:
4059 return "DW_AT_accessibility";
4060 case DW_AT_address_class:
4061 return "DW_AT_address_class";
4062 case DW_AT_artificial:
4063 return "DW_AT_artificial";
4064 case DW_AT_base_types:
4065 return "DW_AT_base_types";
4066 case DW_AT_calling_convention:
4067 return "DW_AT_calling_convention";
4068 case DW_AT_count:
4069 return "DW_AT_count";
4070 case DW_AT_data_member_location:
4071 return "DW_AT_data_member_location";
4072 case DW_AT_decl_column:
4073 return "DW_AT_decl_column";
4074 case DW_AT_decl_file:
4075 return "DW_AT_decl_file";
4076 case DW_AT_decl_line:
4077 return "DW_AT_decl_line";
4078 case DW_AT_declaration:
4079 return "DW_AT_declaration";
4080 case DW_AT_discr_list:
4081 return "DW_AT_discr_list";
4082 case DW_AT_encoding:
4083 return "DW_AT_encoding";
4084 case DW_AT_external:
4085 return "DW_AT_external";
4086 case DW_AT_frame_base:
4087 return "DW_AT_frame_base";
4088 case DW_AT_friend:
4089 return "DW_AT_friend";
4090 case DW_AT_identifier_case:
4091 return "DW_AT_identifier_case";
4092 case DW_AT_macro_info:
4093 return "DW_AT_macro_info";
4094 case DW_AT_namelist_items:
4095 return "DW_AT_namelist_items";
4096 case DW_AT_priority:
4097 return "DW_AT_priority";
4098 case DW_AT_segment:
4099 return "DW_AT_segment";
4100 case DW_AT_specification:
4101 return "DW_AT_specification";
4102 case DW_AT_static_link:
4103 return "DW_AT_static_link";
4104 case DW_AT_type:
4105 return "DW_AT_type";
4106 case DW_AT_use_location:
4107 return "DW_AT_use_location";
4108 case DW_AT_variable_parameter:
4109 return "DW_AT_variable_parameter";
4110 case DW_AT_virtuality:
4111 return "DW_AT_virtuality";
4112 case DW_AT_vtable_elem_location:
4113 return "DW_AT_vtable_elem_location";
4114
a20612aa
RH
4115 case DW_AT_allocated:
4116 return "DW_AT_allocated";
4117 case DW_AT_associated:
4118 return "DW_AT_associated";
4119 case DW_AT_data_location:
4120 return "DW_AT_data_location";
4121 case DW_AT_stride:
4122 return "DW_AT_stride";
4123 case DW_AT_entry_pc:
4124 return "DW_AT_entry_pc";
4125 case DW_AT_use_UTF8:
4126 return "DW_AT_use_UTF8";
4127 case DW_AT_extension:
4128 return "DW_AT_extension";
4129 case DW_AT_ranges:
4130 return "DW_AT_ranges";
4131 case DW_AT_trampoline:
4132 return "DW_AT_trampoline";
4133 case DW_AT_call_column:
4134 return "DW_AT_call_column";
4135 case DW_AT_call_file:
4136 return "DW_AT_call_file";
4137 case DW_AT_call_line:
4138 return "DW_AT_call_line";
4139
7d9d8943
AM
4140 case DW_AT_MIPS_fde:
4141 return "DW_AT_MIPS_fde";
4142 case DW_AT_MIPS_loop_begin:
4143 return "DW_AT_MIPS_loop_begin";
4144 case DW_AT_MIPS_tail_loop_begin:
4145 return "DW_AT_MIPS_tail_loop_begin";
4146 case DW_AT_MIPS_epilog_begin:
4147 return "DW_AT_MIPS_epilog_begin";
4148 case DW_AT_MIPS_loop_unroll_factor:
4149 return "DW_AT_MIPS_loop_unroll_factor";
4150 case DW_AT_MIPS_software_pipeline_depth:
4151 return "DW_AT_MIPS_software_pipeline_depth";
4152 case DW_AT_MIPS_linkage_name:
4153 return "DW_AT_MIPS_linkage_name";
4154 case DW_AT_MIPS_stride:
4155 return "DW_AT_MIPS_stride";
4156 case DW_AT_MIPS_abstract_name:
4157 return "DW_AT_MIPS_abstract_name";
4158 case DW_AT_MIPS_clone_origin:
4159 return "DW_AT_MIPS_clone_origin";
4160 case DW_AT_MIPS_has_inlines:
4161 return "DW_AT_MIPS_has_inlines";
4162
4163 case DW_AT_sf_names:
4164 return "DW_AT_sf_names";
4165 case DW_AT_src_info:
4166 return "DW_AT_src_info";
4167 case DW_AT_mac_info:
4168 return "DW_AT_mac_info";
4169 case DW_AT_src_coords:
4170 return "DW_AT_src_coords";
4171 case DW_AT_body_begin:
4172 return "DW_AT_body_begin";
4173 case DW_AT_body_end:
4174 return "DW_AT_body_end";
84f0ace0
JM
4175 case DW_AT_GNU_vector:
4176 return "DW_AT_GNU_vector";
4177
7a0c8d71
DR
4178 case DW_AT_VMS_rtnbeg_pd_address:
4179 return "DW_AT_VMS_rtnbeg_pd_address";
4180
7d9d8943
AM
4181 default:
4182 return "DW_AT_<unknown>";
4183 }
4184}
4185
4186/* Convert a DWARF value form code into its string name. */
4187
4188static const char *
4189dwarf_form_name (form)
b3694847 4190 unsigned form;
7d9d8943
AM
4191{
4192 switch (form)
4193 {
4194 case DW_FORM_addr:
4195 return "DW_FORM_addr";
4196 case DW_FORM_block2:
4197 return "DW_FORM_block2";
4198 case DW_FORM_block4:
4199 return "DW_FORM_block4";
4200 case DW_FORM_data2:
4201 return "DW_FORM_data2";
4202 case DW_FORM_data4:
4203 return "DW_FORM_data4";
4204 case DW_FORM_data8:
4205 return "DW_FORM_data8";
4206 case DW_FORM_string:
4207 return "DW_FORM_string";
4208 case DW_FORM_block:
4209 return "DW_FORM_block";
4210 case DW_FORM_block1:
4211 return "DW_FORM_block1";
4212 case DW_FORM_data1:
4213 return "DW_FORM_data1";
4214 case DW_FORM_flag:
4215 return "DW_FORM_flag";
4216 case DW_FORM_sdata:
4217 return "DW_FORM_sdata";
4218 case DW_FORM_strp:
4219 return "DW_FORM_strp";
4220 case DW_FORM_udata:
4221 return "DW_FORM_udata";
4222 case DW_FORM_ref_addr:
4223 return "DW_FORM_ref_addr";
4224 case DW_FORM_ref1:
4225 return "DW_FORM_ref1";
4226 case DW_FORM_ref2:
4227 return "DW_FORM_ref2";
4228 case DW_FORM_ref4:
4229 return "DW_FORM_ref4";
4230 case DW_FORM_ref8:
4231 return "DW_FORM_ref8";
4232 case DW_FORM_ref_udata:
4233 return "DW_FORM_ref_udata";
4234 case DW_FORM_indirect:
4235 return "DW_FORM_indirect";
3f76745e 4236 default:
7d9d8943 4237 return "DW_FORM_<unknown>";
a3f97cbb
JW
4238 }
4239}
4240
3f76745e 4241/* Convert a DWARF type code into its string name. */
71dfc51f 4242
487a6e06 4243#if 0
d560ee52 4244static const char *
3f76745e 4245dwarf_type_encoding_name (enc)
b3694847 4246 unsigned enc;
a3f97cbb 4247{
3f76745e 4248 switch (enc)
a3f97cbb 4249 {
3f76745e
JM
4250 case DW_ATE_address:
4251 return "DW_ATE_address";
4252 case DW_ATE_boolean:
4253 return "DW_ATE_boolean";
4254 case DW_ATE_complex_float:
4255 return "DW_ATE_complex_float";
4256 case DW_ATE_float:
4257 return "DW_ATE_float";
4258 case DW_ATE_signed:
4259 return "DW_ATE_signed";
4260 case DW_ATE_signed_char:
4261 return "DW_ATE_signed_char";
4262 case DW_ATE_unsigned:
4263 return "DW_ATE_unsigned";
4264 case DW_ATE_unsigned_char:
4265 return "DW_ATE_unsigned_char";
4266 default:
4267 return "DW_ATE_<unknown>";
4268 }
a3f97cbb 4269}
487a6e06 4270#endif
3f76745e
JM
4271\f
4272/* Determine the "ultimate origin" of a decl. The decl may be an inlined
4273 instance of an inlined instance of a decl which is local to an inline
4274 function, so we have to trace all of the way back through the origin chain
4275 to find out what sort of node actually served as the original seed for the
4276 given block. */
a3f97cbb 4277
3f76745e
JM
4278static tree
4279decl_ultimate_origin (decl)
b3694847 4280 tree decl;
a3f97cbb 4281{
10a11b75
JM
4282 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4283 nodes in the function to point to themselves; ignore that if
4284 we're trying to output the abstract instance of this function. */
4285 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4286 return NULL_TREE;
4287
556273e0 4288#ifdef ENABLE_CHECKING
02e24c7a
MM
4289 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4290 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4291 most distant ancestor, this should never happen. */
4292 abort ();
4293#endif
3f76745e 4294
02e24c7a 4295 return DECL_ABSTRACT_ORIGIN (decl);
a3f97cbb
JW
4296}
4297
3f76745e
JM
4298/* Determine the "ultimate origin" of a block. The block may be an inlined
4299 instance of an inlined instance of a block which is local to an inline
4300 function, so we have to trace all of the way back through the origin chain
4301 to find out what sort of node actually served as the original seed for the
4302 given block. */
71dfc51f 4303
3f76745e
JM
4304static tree
4305block_ultimate_origin (block)
b3694847 4306 tree block;
a3f97cbb 4307{
b3694847 4308 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
71dfc51f 4309
10a11b75
JM
4310 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4311 nodes in the function to point to themselves; ignore that if
4312 we're trying to output the abstract instance of this function. */
4313 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4314 return NULL_TREE;
4315
3f76745e
JM
4316 if (immediate_origin == NULL_TREE)
4317 return NULL_TREE;
4318 else
4319 {
b3694847
SS
4320 tree ret_val;
4321 tree lookahead = immediate_origin;
71dfc51f 4322
3f76745e
JM
4323 do
4324 {
4325 ret_val = lookahead;
2ad9852d
RK
4326 lookahead = (TREE_CODE (ret_val) == BLOCK
4327 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
3f76745e
JM
4328 }
4329 while (lookahead != NULL && lookahead != ret_val);
4330
4331 return ret_val;
4332 }
a3f97cbb
JW
4333}
4334
3f76745e
JM
4335/* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4336 of a virtual function may refer to a base class, so we check the 'this'
4337 parameter. */
71dfc51f 4338
3f76745e
JM
4339static tree
4340decl_class_context (decl)
4341 tree decl;
a3f97cbb 4342{
3f76745e 4343 tree context = NULL_TREE;
71dfc51f 4344
3f76745e
JM
4345 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4346 context = DECL_CONTEXT (decl);
4347 else
4348 context = TYPE_MAIN_VARIANT
4349 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
71dfc51f 4350
2f939d94 4351 if (context && !TYPE_P (context))
3f76745e
JM
4352 context = NULL_TREE;
4353
4354 return context;
a3f97cbb
JW
4355}
4356\f
a96c67ec 4357/* Add an attribute/value pair to a DIE. We build the lists up in reverse
881c6935 4358 addition order, and correct that in reverse_all_dies. */
71dfc51f
RK
4359
4360static inline void
3f76745e 4361add_dwarf_attr (die, attr)
b3694847
SS
4362 dw_die_ref die;
4363 dw_attr_ref attr;
a3f97cbb 4364{
3f76745e 4365 if (die != NULL && attr != NULL)
a3f97cbb 4366 {
a96c67ec
JM
4367 attr->dw_attr_next = die->die_attr;
4368 die->die_attr = attr;
a3f97cbb
JW
4369 }
4370}
4371
a96c67ec
JM
4372static inline dw_val_class
4373AT_class (a)
4374 dw_attr_ref a;
4375{
4376 return a->dw_attr_val.val_class;
4377}
4378
3f76745e 4379/* Add a flag value attribute to a DIE. */
71dfc51f 4380
3f76745e
JM
4381static inline void
4382add_AT_flag (die, attr_kind, flag)
b3694847
SS
4383 dw_die_ref die;
4384 enum dwarf_attribute attr_kind;
4385 unsigned flag;
a3f97cbb 4386{
b3694847 4387 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 4388
3f76745e
JM
4389 attr->dw_attr_next = NULL;
4390 attr->dw_attr = attr_kind;
4391 attr->dw_attr_val.val_class = dw_val_class_flag;
4392 attr->dw_attr_val.v.val_flag = flag;
4393 add_dwarf_attr (die, attr);
a3f97cbb
JW
4394}
4395
a96c67ec
JM
4396static inline unsigned
4397AT_flag (a)
b3694847 4398 dw_attr_ref a;
a96c67ec
JM
4399{
4400 if (a && AT_class (a) == dw_val_class_flag)
4401 return a->dw_attr_val.v.val_flag;
4402
40e8cc95 4403 abort ();
a96c67ec
JM
4404}
4405
3f76745e 4406/* Add a signed integer attribute value to a DIE. */
71dfc51f 4407
3f76745e
JM
4408static inline void
4409add_AT_int (die, attr_kind, int_val)
b3694847
SS
4410 dw_die_ref die;
4411 enum dwarf_attribute attr_kind;
4412 long int int_val;
a3f97cbb 4413{
b3694847 4414 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3f76745e
JM
4415
4416 attr->dw_attr_next = NULL;
4417 attr->dw_attr = attr_kind;
4418 attr->dw_attr_val.val_class = dw_val_class_const;
4419 attr->dw_attr_val.v.val_int = int_val;
4420 add_dwarf_attr (die, attr);
a3f97cbb
JW
4421}
4422
a96c67ec
JM
4423static inline long int
4424AT_int (a)
b3694847 4425 dw_attr_ref a;
a96c67ec
JM
4426{
4427 if (a && AT_class (a) == dw_val_class_const)
4428 return a->dw_attr_val.v.val_int;
4429
40e8cc95 4430 abort ();
a96c67ec
JM
4431}
4432
3f76745e 4433/* Add an unsigned integer attribute value to a DIE. */
71dfc51f 4434
3f76745e
JM
4435static inline void
4436add_AT_unsigned (die, attr_kind, unsigned_val)
b3694847
SS
4437 dw_die_ref die;
4438 enum dwarf_attribute attr_kind;
4439 unsigned long unsigned_val;
a3f97cbb 4440{
b3694847 4441 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3f76745e
JM
4442
4443 attr->dw_attr_next = NULL;
4444 attr->dw_attr = attr_kind;
4445 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4446 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4447 add_dwarf_attr (die, attr);
a3f97cbb 4448}
71dfc51f 4449
a96c67ec
JM
4450static inline unsigned long
4451AT_unsigned (a)
b3694847 4452 dw_attr_ref a;
a96c67ec
JM
4453{
4454 if (a && AT_class (a) == dw_val_class_unsigned_const)
4455 return a->dw_attr_val.v.val_unsigned;
4456
40e8cc95 4457 abort ();
a96c67ec
JM
4458}
4459
3f76745e
JM
4460/* Add an unsigned double integer attribute value to a DIE. */
4461
4462static inline void
4463add_AT_long_long (die, attr_kind, val_hi, val_low)
b3694847
SS
4464 dw_die_ref die;
4465 enum dwarf_attribute attr_kind;
4466 unsigned long val_hi;
4467 unsigned long val_low;
a3f97cbb 4468{
b3694847 4469 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 4470
3f76745e
JM
4471 attr->dw_attr_next = NULL;
4472 attr->dw_attr = attr_kind;
4473 attr->dw_attr_val.val_class = dw_val_class_long_long;
4474 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4475 attr->dw_attr_val.v.val_long_long.low = val_low;
4476 add_dwarf_attr (die, attr);
4477}
71dfc51f 4478
3f76745e 4479/* Add a floating point attribute value to a DIE and return it. */
71dfc51f 4480
3f76745e
JM
4481static inline void
4482add_AT_float (die, attr_kind, length, array)
b3694847
SS
4483 dw_die_ref die;
4484 enum dwarf_attribute attr_kind;
4485 unsigned length;
4486 long *array;
3f76745e 4487{
b3694847 4488 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3f76745e
JM
4489
4490 attr->dw_attr_next = NULL;
4491 attr->dw_attr = attr_kind;
4492 attr->dw_attr_val.val_class = dw_val_class_float;
4493 attr->dw_attr_val.v.val_float.length = length;
4494 attr->dw_attr_val.v.val_float.array = array;
4495 add_dwarf_attr (die, attr);
a3f97cbb
JW
4496}
4497
3f76745e 4498/* Add a string attribute value to a DIE. */
71dfc51f 4499
3f76745e
JM
4500static inline void
4501add_AT_string (die, attr_kind, str)
b3694847
SS
4502 dw_die_ref die;
4503 enum dwarf_attribute attr_kind;
4504 const char *str;
a3f97cbb 4505{
b3694847 4506 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
9eb4015a 4507 struct indirect_string_node *node;
c26fbbca 4508
9eb4015a
JJ
4509 if (! debug_str_hash)
4510 {
4511 debug_str_hash = ht_create (10);
4512 debug_str_hash->alloc_node = indirect_string_alloc;
4513 }
4514
4515 node = (struct indirect_string_node *)
4516 ht_lookup (debug_str_hash, (const unsigned char *) str,
4517 strlen (str), HT_ALLOC);
4518 node->refcount++;
71dfc51f 4519
3f76745e
JM
4520 attr->dw_attr_next = NULL;
4521 attr->dw_attr = attr_kind;
4522 attr->dw_attr_val.val_class = dw_val_class_str;
9eb4015a 4523 attr->dw_attr_val.v.val_str = node;
3f76745e
JM
4524 add_dwarf_attr (die, attr);
4525}
71dfc51f 4526
a96c67ec
JM
4527static inline const char *
4528AT_string (a)
b3694847 4529 dw_attr_ref a;
a96c67ec
JM
4530{
4531 if (a && AT_class (a) == dw_val_class_str)
9eb4015a
JJ
4532 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4533
4534 abort ();
4535}
4536
4537/* Find out whether a string should be output inline in DIE
4538 or out-of-line in .debug_str section. */
4539
9eb4015a
JJ
4540static int
4541AT_string_form (a)
4542 dw_attr_ref a;
4543{
4544 if (a && AT_class (a) == dw_val_class_str)
4545 {
4546 struct indirect_string_node *node;
4547 unsigned int len;
4548 extern int const_labelno;
4549 char label[32];
4550
4551 node = a->dw_attr_val.v.val_str;
4552 if (node->form)
4553 return node->form;
4554
4555 len = HT_LEN (&node->id) + 1;
4556
2ad9852d
RK
4557 /* If the string is shorter or equal to the size of the reference, it is
4558 always better to put it inline. */
9eb4015a
JJ
4559 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4560 return node->form = DW_FORM_string;
4561
2ad9852d
RK
4562 /* If we cannot expect the linker to merge strings in .debug_str
4563 section, only put it into .debug_str if it is worth even in this
4564 single module. */
4565 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4566 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4567 return node->form = DW_FORM_string;
9eb4015a
JJ
4568
4569 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4570 ++const_labelno;
4571 node->label = xstrdup (label);
2ad9852d 4572
9eb4015a
JJ
4573 return node->form = DW_FORM_strp;
4574 }
a96c67ec 4575
40e8cc95 4576 abort ();
a96c67ec
JM
4577}
4578
3f76745e 4579/* Add a DIE reference attribute value to a DIE. */
71dfc51f 4580
3f76745e
JM
4581static inline void
4582add_AT_die_ref (die, attr_kind, targ_die)
b3694847
SS
4583 dw_die_ref die;
4584 enum dwarf_attribute attr_kind;
4585 dw_die_ref targ_die;
3f76745e 4586{
b3694847 4587 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 4588
3f76745e
JM
4589 attr->dw_attr_next = NULL;
4590 attr->dw_attr = attr_kind;
4591 attr->dw_attr_val.val_class = dw_val_class_die_ref;
881c6935
JM
4592 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4593 attr->dw_attr_val.v.val_die_ref.external = 0;
3f76745e
JM
4594 add_dwarf_attr (die, attr);
4595}
b1ccbc24 4596
a96c67ec
JM
4597static inline dw_die_ref
4598AT_ref (a)
b3694847 4599 dw_attr_ref a;
a96c67ec
JM
4600{
4601 if (a && AT_class (a) == dw_val_class_die_ref)
881c6935 4602 return a->dw_attr_val.v.val_die_ref.die;
a96c67ec 4603
40e8cc95 4604 abort ();
a96c67ec
JM
4605}
4606
881c6935
JM
4607static inline int
4608AT_ref_external (a)
b3694847 4609 dw_attr_ref a;
881c6935
JM
4610{
4611 if (a && AT_class (a) == dw_val_class_die_ref)
4612 return a->dw_attr_val.v.val_die_ref.external;
4613
4614 return 0;
4615}
4616
881c6935
JM
4617static inline void
4618set_AT_ref_external (a, i)
b3694847 4619 dw_attr_ref a;
881c6935
JM
4620 int i;
4621{
4622 if (a && AT_class (a) == dw_val_class_die_ref)
4623 a->dw_attr_val.v.val_die_ref.external = i;
4624 else
4625 abort ();
4626}
4627
3f76745e 4628/* Add an FDE reference attribute value to a DIE. */
b1ccbc24 4629
3f76745e
JM
4630static inline void
4631add_AT_fde_ref (die, attr_kind, targ_fde)
b3694847
SS
4632 dw_die_ref die;
4633 enum dwarf_attribute attr_kind;
4634 unsigned targ_fde;
3f76745e 4635{
b3694847 4636 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
b1ccbc24 4637
3f76745e
JM
4638 attr->dw_attr_next = NULL;
4639 attr->dw_attr = attr_kind;
4640 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4641 attr->dw_attr_val.v.val_fde_index = targ_fde;
4642 add_dwarf_attr (die, attr);
a3f97cbb 4643}
71dfc51f 4644
3f76745e 4645/* Add a location description attribute value to a DIE. */
71dfc51f 4646
3f76745e
JM
4647static inline void
4648add_AT_loc (die, attr_kind, loc)
b3694847
SS
4649 dw_die_ref die;
4650 enum dwarf_attribute attr_kind;
4651 dw_loc_descr_ref loc;
3f76745e 4652{
b3694847 4653 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 4654
3f76745e
JM
4655 attr->dw_attr_next = NULL;
4656 attr->dw_attr = attr_kind;
4657 attr->dw_attr_val.val_class = dw_val_class_loc;
4658 attr->dw_attr_val.v.val_loc = loc;
4659 add_dwarf_attr (die, attr);
a3f97cbb
JW
4660}
4661
a96c67ec
JM
4662static inline dw_loc_descr_ref
4663AT_loc (a)
b3694847 4664 dw_attr_ref a;
a96c67ec
JM
4665{
4666 if (a && AT_class (a) == dw_val_class_loc)
4667 return a->dw_attr_val.v.val_loc;
4668
40e8cc95 4669 abort ();
a96c67ec
JM
4670}
4671
63e46568
DB
4672static inline void
4673add_AT_loc_list (die, attr_kind, loc_list)
b3694847
SS
4674 dw_die_ref die;
4675 enum dwarf_attribute attr_kind;
4676 dw_loc_list_ref loc_list;
63e46568 4677{
b3694847 4678 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
63e46568
DB
4679
4680 attr->dw_attr_next = NULL;
4681 attr->dw_attr = attr_kind;
4682 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4683 attr->dw_attr_val.v.val_loc_list = loc_list;
4684 add_dwarf_attr (die, attr);
4685 have_location_lists = 1;
4686}
4687
63e46568
DB
4688static inline dw_loc_list_ref
4689AT_loc_list (a)
b3694847 4690 dw_attr_ref a;
63e46568
DB
4691{
4692 if (a && AT_class (a) == dw_val_class_loc_list)
4693 return a->dw_attr_val.v.val_loc_list;
4694
4695 abort ();
4696}
4697
3f76745e 4698/* Add an address constant attribute value to a DIE. */
71dfc51f 4699
3f76745e
JM
4700static inline void
4701add_AT_addr (die, attr_kind, addr)
b3694847
SS
4702 dw_die_ref die;
4703 enum dwarf_attribute attr_kind;
1865dbb5 4704 rtx addr;
a3f97cbb 4705{
b3694847 4706 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 4707
3f76745e
JM
4708 attr->dw_attr_next = NULL;
4709 attr->dw_attr = attr_kind;
4710 attr->dw_attr_val.val_class = dw_val_class_addr;
4711 attr->dw_attr_val.v.val_addr = addr;
4712 add_dwarf_attr (die, attr);
a3f97cbb
JW
4713}
4714
1865dbb5 4715static inline rtx
a96c67ec 4716AT_addr (a)
b3694847 4717 dw_attr_ref a;
a96c67ec
JM
4718{
4719 if (a && AT_class (a) == dw_val_class_addr)
4720 return a->dw_attr_val.v.val_addr;
4721
40e8cc95 4722 abort ();
a96c67ec
JM
4723}
4724
3f76745e 4725/* Add a label identifier attribute value to a DIE. */
71dfc51f 4726
3f76745e
JM
4727static inline void
4728add_AT_lbl_id (die, attr_kind, lbl_id)
b3694847
SS
4729 dw_die_ref die;
4730 enum dwarf_attribute attr_kind;
4731 const char *lbl_id;
a3f97cbb 4732{
b3694847 4733 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 4734
3f76745e
JM
4735 attr->dw_attr_next = NULL;
4736 attr->dw_attr = attr_kind;
4737 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4738 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4739 add_dwarf_attr (die, attr);
4740}
71dfc51f 4741
3f76745e
JM
4742/* Add a section offset attribute value to a DIE. */
4743
4744static inline void
8b790721 4745add_AT_lbl_offset (die, attr_kind, label)
b3694847
SS
4746 dw_die_ref die;
4747 enum dwarf_attribute attr_kind;
4748 const char *label;
3f76745e 4749{
b3694847 4750 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
71dfc51f 4751
3f76745e
JM
4752 attr->dw_attr_next = NULL;
4753 attr->dw_attr = attr_kind;
8b790721 4754 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
a96c67ec 4755 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
3f76745e 4756 add_dwarf_attr (die, attr);
a3f97cbb
JW
4757}
4758
a20612aa
RH
4759/* Add an offset attribute value to a DIE. */
4760
2bee6045 4761static inline void
a20612aa 4762add_AT_offset (die, attr_kind, offset)
b3694847
SS
4763 dw_die_ref die;
4764 enum dwarf_attribute attr_kind;
4765 unsigned long offset;
a20612aa 4766{
b3694847 4767 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
a20612aa
RH
4768
4769 attr->dw_attr_next = NULL;
4770 attr->dw_attr = attr_kind;
4771 attr->dw_attr_val.val_class = dw_val_class_offset;
4772 attr->dw_attr_val.v.val_offset = offset;
4773 add_dwarf_attr (die, attr);
4774}
4775
2bee6045
JJ
4776/* Add an range_list attribute value to a DIE. */
4777
4778static void
4779add_AT_range_list (die, attr_kind, offset)
4780 dw_die_ref die;
4781 enum dwarf_attribute attr_kind;
4782 unsigned long offset;
4783{
4784 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4785
4786 attr->dw_attr_next = NULL;
4787 attr->dw_attr = attr_kind;
4788 attr->dw_attr_val.val_class = dw_val_class_range_list;
4789 attr->dw_attr_val.v.val_offset = offset;
4790 add_dwarf_attr (die, attr);
4791}
4792
a96c67ec
JM
4793static inline const char *
4794AT_lbl (a)
b3694847 4795 dw_attr_ref a;
a3f97cbb 4796{
a96c67ec
JM
4797 if (a && (AT_class (a) == dw_val_class_lbl_id
4798 || AT_class (a) == dw_val_class_lbl_offset))
4799 return a->dw_attr_val.v.val_lbl_id;
71dfc51f 4800
40e8cc95 4801 abort ();
a3f97cbb
JW
4802}
4803
3f76745e 4804/* Get the attribute of type attr_kind. */
71dfc51f 4805
3f76745e
JM
4806static inline dw_attr_ref
4807get_AT (die, attr_kind)
b3694847
SS
4808 dw_die_ref die;
4809 enum dwarf_attribute attr_kind;
f37230f0 4810{
b3694847
SS
4811 dw_attr_ref a;
4812 dw_die_ref spec = NULL;
556273e0 4813
3f76745e
JM
4814 if (die != NULL)
4815 {
4816 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2ad9852d
RK
4817 if (a->dw_attr == attr_kind)
4818 return a;
4819 else if (a->dw_attr == DW_AT_specification
4820 || a->dw_attr == DW_AT_abstract_origin)
4821 spec = AT_ref (a);
71dfc51f 4822
3f76745e
JM
4823 if (spec)
4824 return get_AT (spec, attr_kind);
4825 }
4826
4827 return NULL;
f37230f0
JM
4828}
4829
2ad9852d
RK
4830/* Return the "low pc" attribute value, typically associated with a subprogram
4831 DIE. Return null if the "low pc" attribute is either not present, or if it
4832 cannot be represented as an assembler label identifier. */
71dfc51f 4833
a96c67ec 4834static inline const char *
3f76745e 4835get_AT_low_pc (die)
b3694847 4836 dw_die_ref die;
7e23cb16 4837{
b3694847 4838 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
2ad9852d 4839
40e8cc95 4840 return a ? AT_lbl (a) : NULL;
7e23cb16
JM
4841}
4842
2ad9852d
RK
4843/* Return the "high pc" attribute value, typically associated with a subprogram
4844 DIE. Return null if the "high pc" attribute is either not present, or if it
4845 cannot be represented as an assembler label identifier. */
71dfc51f 4846
a96c67ec 4847static inline const char *
3f76745e 4848get_AT_hi_pc (die)
b3694847 4849 dw_die_ref die;
a3f97cbb 4850{
b3694847 4851 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
2ad9852d 4852
40e8cc95 4853 return a ? AT_lbl (a) : NULL;
3f76745e
JM
4854}
4855
4856/* Return the value of the string attribute designated by ATTR_KIND, or
4857 NULL if it is not present. */
71dfc51f 4858
a96c67ec 4859static inline const char *
3f76745e 4860get_AT_string (die, attr_kind)
b3694847
SS
4861 dw_die_ref die;
4862 enum dwarf_attribute attr_kind;
3f76745e 4863{
b3694847 4864 dw_attr_ref a = get_AT (die, attr_kind);
2ad9852d 4865
40e8cc95 4866 return a ? AT_string (a) : NULL;
a3f97cbb
JW
4867}
4868
3f76745e
JM
4869/* Return the value of the flag attribute designated by ATTR_KIND, or -1
4870 if it is not present. */
71dfc51f 4871
3f76745e
JM
4872static inline int
4873get_AT_flag (die, attr_kind)
b3694847
SS
4874 dw_die_ref die;
4875 enum dwarf_attribute attr_kind;
a3f97cbb 4876{
b3694847 4877 dw_attr_ref a = get_AT (die, attr_kind);
2ad9852d 4878
40e8cc95 4879 return a ? AT_flag (a) : 0;
a3f97cbb
JW
4880}
4881
3f76745e
JM
4882/* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4883 if it is not present. */
71dfc51f 4884
3f76745e
JM
4885static inline unsigned
4886get_AT_unsigned (die, attr_kind)
b3694847
SS
4887 dw_die_ref die;
4888 enum dwarf_attribute attr_kind;
a3f97cbb 4889{
b3694847 4890 dw_attr_ref a = get_AT (die, attr_kind);
2ad9852d 4891
40e8cc95 4892 return a ? AT_unsigned (a) : 0;
a96c67ec 4893}
71dfc51f 4894
a96c67ec
JM
4895static inline dw_die_ref
4896get_AT_ref (die, attr_kind)
4897 dw_die_ref die;
b3694847 4898 enum dwarf_attribute attr_kind;
a96c67ec 4899{
b3694847 4900 dw_attr_ref a = get_AT (die, attr_kind);
2ad9852d 4901
40e8cc95 4902 return a ? AT_ref (a) : NULL;
3f76745e 4903}
71dfc51f 4904
3f76745e
JM
4905static inline int
4906is_c_family ()
4907{
b3694847 4908 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
71dfc51f 4909
3f76745e
JM
4910 return (lang == DW_LANG_C || lang == DW_LANG_C89
4911 || lang == DW_LANG_C_plus_plus);
556273e0 4912}
71dfc51f 4913
1d3d6b1e
JM
4914static inline int
4915is_cxx ()
4916{
4917 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4918 == DW_LANG_C_plus_plus);
c26fbbca 4919}
1d3d6b1e 4920
3f76745e
JM
4921static inline int
4922is_fortran ()
4923{
b3694847 4924 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
71dfc51f 4925
3f76745e 4926 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
556273e0 4927}
71dfc51f 4928
28985b81
AG
4929static inline int
4930is_java ()
4931{
b3694847 4932 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
28985b81
AG
4933
4934 return (lang == DW_LANG_Java);
4935}
4936
10a11b75 4937/* Free up the memory used by A. */
71dfc51f 4938
c6991660 4939static inline void free_AT PARAMS ((dw_attr_ref));
3f76745e 4940static inline void
10a11b75
JM
4941free_AT (a)
4942 dw_attr_ref a;
4943{
4944 switch (AT_class (a))
4945 {
10a11b75 4946 case dw_val_class_str:
9eb4015a
JJ
4947 if (a->dw_attr_val.v.val_str->refcount)
4948 a->dw_attr_val.v.val_str->refcount--;
4949 break;
4950
10a11b75
JM
4951 case dw_val_class_lbl_id:
4952 case dw_val_class_lbl_offset:
9eb4015a 4953 free (a->dw_attr_val.v.val_lbl_id);
10a11b75
JM
4954 break;
4955
3724ec07
WC
4956 case dw_val_class_float:
4957 free (a->dw_attr_val.v.val_float.array);
4958 break;
0b34cf1e 4959
10a11b75
JM
4960 default:
4961 break;
4962 }
4963
4964 free (a);
556273e0 4965}
10a11b75
JM
4966
4967/* Remove the specified attribute if present. */
4968
4969static void
3f76745e 4970remove_AT (die, attr_kind)
b3694847
SS
4971 dw_die_ref die;
4972 enum dwarf_attribute attr_kind;
3f76745e 4973{
b3694847
SS
4974 dw_attr_ref *p;
4975 dw_attr_ref removed = NULL;
a3f97cbb 4976
3f76745e
JM
4977 if (die != NULL)
4978 {
a96c67ec
JM
4979 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4980 if ((*p)->dw_attr == attr_kind)
4981 {
4982 removed = *p;
4983 *p = (*p)->dw_attr_next;
4984 break;
4985 }
71dfc51f 4986
a96c67ec 4987 if (removed != 0)
10a11b75
JM
4988 free_AT (removed);
4989 }
4990}
71dfc51f 4991
10a11b75 4992/* Free up the memory used by DIE. */
71dfc51f 4993
10a11b75
JM
4994static inline void
4995free_die (die)
4996 dw_die_ref die;
4997{
4998 remove_children (die);
4999 free (die);
3f76745e 5000}
71dfc51f 5001
3f76745e 5002/* Discard the children of this DIE. */
71dfc51f 5003
10a11b75 5004static void
3f76745e 5005remove_children (die)
b3694847 5006 dw_die_ref die;
3f76745e 5007{
b3694847 5008 dw_die_ref child_die = die->die_child;
3f76745e
JM
5009
5010 die->die_child = NULL;
3f76745e
JM
5011
5012 while (child_die != NULL)
a3f97cbb 5013 {
b3694847
SS
5014 dw_die_ref tmp_die = child_die;
5015 dw_attr_ref a;
71dfc51f 5016
3f76745e 5017 child_die = child_die->die_sib;
556273e0
KH
5018
5019 for (a = tmp_die->die_attr; a != NULL;)
a3f97cbb 5020 {
b3694847 5021 dw_attr_ref tmp_a = a;
71dfc51f 5022
3f76745e 5023 a = a->dw_attr_next;
10a11b75 5024 free_AT (tmp_a);
a3f97cbb 5025 }
71dfc51f 5026
10a11b75 5027 free_die (tmp_die);
3f76745e
JM
5028 }
5029}
71dfc51f 5030
a96c67ec 5031/* Add a child DIE below its parent. We build the lists up in reverse
881c6935 5032 addition order, and correct that in reverse_all_dies. */
71dfc51f 5033
3f76745e
JM
5034static inline void
5035add_child_die (die, child_die)
b3694847
SS
5036 dw_die_ref die;
5037 dw_die_ref child_die;
3f76745e
JM
5038{
5039 if (die != NULL && child_die != NULL)
e90b62db 5040 {
3a88cbd1
JL
5041 if (die == child_die)
5042 abort ();
2ad9852d 5043
3f76745e 5044 child_die->die_parent = die;
a96c67ec
JM
5045 child_die->die_sib = die->die_child;
5046 die->die_child = child_die;
3f76745e
JM
5047 }
5048}
5049
2081603c
JM
5050/* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5051 is the specification, to the front of PARENT's list of children. */
10a11b75
JM
5052
5053static void
5054splice_child_die (parent, child)
5055 dw_die_ref parent, child;
5056{
5057 dw_die_ref *p;
5058
5059 /* We want the declaration DIE from inside the class, not the
5060 specification DIE at toplevel. */
5061 if (child->die_parent != parent)
2081603c
JM
5062 {
5063 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
2ad9852d 5064
2081603c
JM
5065 if (tmp)
5066 child = tmp;
5067 }
10a11b75 5068
2081603c
JM
5069 if (child->die_parent != parent
5070 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
10a11b75
JM
5071 abort ();
5072
5de0e8d4 5073 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
10a11b75
JM
5074 if (*p == child)
5075 {
5076 *p = child->die_sib;
5077 break;
5078 }
5079
5080 child->die_sib = parent->die_child;
5081 parent->die_child = child;
5082}
5083
3f76745e
JM
5084/* Return a pointer to a newly created DIE node. */
5085
5086static inline dw_die_ref
54ba1f0d 5087new_die (tag_value, parent_die, t)
b3694847
SS
5088 enum dwarf_tag tag_value;
5089 dw_die_ref parent_die;
54ba1f0d 5090 tree t;
3f76745e 5091{
b3694847 5092 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
3f76745e
JM
5093
5094 die->die_tag = tag_value;
3f76745e
JM
5095
5096 if (parent_die != NULL)
5097 add_child_die (parent_die, die);
5098 else
ef76d03b
JW
5099 {
5100 limbo_die_node *limbo_node;
5101
5102 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5103 limbo_node->die = die;
54ba1f0d 5104 limbo_node->created_for = t;
ef76d03b
JW
5105 limbo_node->next = limbo_die_list;
5106 limbo_die_list = limbo_node;
5107 }
71dfc51f 5108
3f76745e
JM
5109 return die;
5110}
71dfc51f 5111
3f76745e 5112/* Return the DIE associated with the given type specifier. */
71dfc51f 5113
3f76745e
JM
5114static inline dw_die_ref
5115lookup_type_die (type)
b3694847 5116 tree type;
3f76745e 5117{
e2500fed 5118 return TYPE_SYMTAB_DIE (type);
3f76745e 5119}
e90b62db 5120
3f76745e 5121/* Equate a DIE to a given type specifier. */
71dfc51f 5122
10a11b75 5123static inline void
3f76745e 5124equate_type_number_to_die (type, type_die)
b3694847
SS
5125 tree type;
5126 dw_die_ref type_die;
3f76745e 5127{
e2500fed 5128 TYPE_SYMTAB_DIE (type) = type_die;
3f76745e 5129}
71dfc51f 5130
3f76745e 5131/* Return the DIE associated with a given declaration. */
71dfc51f 5132
3f76745e
JM
5133static inline dw_die_ref
5134lookup_decl_die (decl)
b3694847 5135 tree decl;
3f76745e 5136{
b3694847 5137 unsigned decl_id = DECL_UID (decl);
3f76745e 5138
2ad9852d 5139 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
a3f97cbb
JW
5140}
5141
3f76745e 5142/* Equate a DIE to a particular declaration. */
71dfc51f 5143
3f76745e
JM
5144static void
5145equate_decl_number_to_die (decl, decl_die)
b3694847
SS
5146 tree decl;
5147 dw_die_ref decl_die;
a3f97cbb 5148{
aea9695c
RK
5149 unsigned int decl_id = DECL_UID (decl);
5150 unsigned int num_allocated;
d291dd49 5151
3f76745e 5152 if (decl_id >= decl_die_table_allocated)
a3f97cbb 5153 {
3f76745e
JM
5154 num_allocated
5155 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5156 / DECL_DIE_TABLE_INCREMENT)
5157 * DECL_DIE_TABLE_INCREMENT;
5158
5159 decl_die_table
5160 = (dw_die_ref *) xrealloc (decl_die_table,
5161 sizeof (dw_die_ref) * num_allocated);
5162
961192e1 5163 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
3f76745e
JM
5164 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5165 decl_die_table_allocated = num_allocated;
a3f97cbb 5166 }
71dfc51f 5167
3f76745e
JM
5168 if (decl_id >= decl_die_table_in_use)
5169 decl_die_table_in_use = (decl_id + 1);
5170
5171 decl_die_table[decl_id] = decl_die;
a3f97cbb 5172}
3f76745e
JM
5173\f
5174/* Keep track of the number of spaces used to indent the
5175 output of the debugging routines that print the structure of
5176 the DIE internal representation. */
5177static int print_indent;
71dfc51f 5178
3f76745e
JM
5179/* Indent the line the number of spaces given by print_indent. */
5180
5181static inline void
5182print_spaces (outfile)
5183 FILE *outfile;
5184{
5185 fprintf (outfile, "%*s", print_indent, "");
a3f97cbb
JW
5186}
5187
956d6950 5188/* Print the information associated with a given DIE, and its children.
3f76745e 5189 This routine is a debugging aid only. */
71dfc51f 5190
a3f97cbb 5191static void
3f76745e
JM
5192print_die (die, outfile)
5193 dw_die_ref die;
5194 FILE *outfile;
a3f97cbb 5195{
b3694847
SS
5196 dw_attr_ref a;
5197 dw_die_ref c;
71dfc51f 5198
3f76745e 5199 print_spaces (outfile);
2d8b0f3a 5200 fprintf (outfile, "DIE %4lu: %s\n",
3f76745e
JM
5201 die->die_offset, dwarf_tag_name (die->die_tag));
5202 print_spaces (outfile);
2d8b0f3a
JL
5203 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5204 fprintf (outfile, " offset: %lu\n", die->die_offset);
3f76745e
JM
5205
5206 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
a3f97cbb 5207 {
3f76745e
JM
5208 print_spaces (outfile);
5209 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5210
a96c67ec 5211 switch (AT_class (a))
3f76745e
JM
5212 {
5213 case dw_val_class_addr:
5214 fprintf (outfile, "address");
5215 break;
a20612aa
RH
5216 case dw_val_class_offset:
5217 fprintf (outfile, "offset");
5218 break;
3f76745e
JM
5219 case dw_val_class_loc:
5220 fprintf (outfile, "location descriptor");
5221 break;
63e46568 5222 case dw_val_class_loc_list:
a20612aa
RH
5223 fprintf (outfile, "location list -> label:%s",
5224 AT_loc_list (a)->ll_symbol);
63e46568 5225 break;
2bee6045
JJ
5226 case dw_val_class_range_list:
5227 fprintf (outfile, "range list");
5228 break;
3f76745e 5229 case dw_val_class_const:
a96c67ec 5230 fprintf (outfile, "%ld", AT_int (a));
3f76745e
JM
5231 break;
5232 case dw_val_class_unsigned_const:
a96c67ec 5233 fprintf (outfile, "%lu", AT_unsigned (a));
3f76745e
JM
5234 break;
5235 case dw_val_class_long_long:
2d8b0f3a 5236 fprintf (outfile, "constant (%lu,%lu)",
556273e0
KH
5237 a->dw_attr_val.v.val_long_long.hi,
5238 a->dw_attr_val.v.val_long_long.low);
3f76745e
JM
5239 break;
5240 case dw_val_class_float:
5241 fprintf (outfile, "floating-point constant");
5242 break;
5243 case dw_val_class_flag:
a96c67ec 5244 fprintf (outfile, "%u", AT_flag (a));
3f76745e
JM
5245 break;
5246 case dw_val_class_die_ref:
a96c67ec 5247 if (AT_ref (a) != NULL)
881c6935 5248 {
1bfb5f8f 5249 if (AT_ref (a)->die_symbol)
881c6935
JM
5250 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5251 else
5252 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5253 }
3f76745e
JM
5254 else
5255 fprintf (outfile, "die -> <null>");
5256 break;
5257 case dw_val_class_lbl_id:
8b790721 5258 case dw_val_class_lbl_offset:
a96c67ec 5259 fprintf (outfile, "label: %s", AT_lbl (a));
3f76745e 5260 break;
3f76745e 5261 case dw_val_class_str:
a96c67ec
JM
5262 if (AT_string (a) != NULL)
5263 fprintf (outfile, "\"%s\"", AT_string (a));
3f76745e
JM
5264 else
5265 fprintf (outfile, "<null>");
5266 break;
e9a25f70
JL
5267 default:
5268 break;
3f76745e
JM
5269 }
5270
5271 fprintf (outfile, "\n");
5272 }
5273
5274 if (die->die_child != NULL)
5275 {
5276 print_indent += 4;
5277 for (c = die->die_child; c != NULL; c = c->die_sib)
5278 print_die (c, outfile);
71dfc51f 5279
3f76745e 5280 print_indent -= 4;
a3f97cbb 5281 }
881c6935
JM
5282 if (print_indent == 0)
5283 fprintf (outfile, "\n");
a3f97cbb
JW
5284}
5285
3f76745e
JM
5286/* Print the contents of the source code line number correspondence table.
5287 This routine is a debugging aid only. */
71dfc51f 5288
3f76745e
JM
5289static void
5290print_dwarf_line_table (outfile)
5291 FILE *outfile;
a3f97cbb 5292{
b3694847
SS
5293 unsigned i;
5294 dw_line_info_ref line_info;
3f76745e
JM
5295
5296 fprintf (outfile, "\n\nDWARF source line information\n");
2ad9852d 5297 for (i = 1; i < line_info_table_in_use; i++)
a3f97cbb 5298 {
3f76745e
JM
5299 line_info = &line_info_table[i];
5300 fprintf (outfile, "%5d: ", i);
981975b6 5301 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
2d8b0f3a 5302 fprintf (outfile, "%6ld", line_info->dw_line_num);
3f76745e 5303 fprintf (outfile, "\n");
a3f97cbb 5304 }
3f76745e
JM
5305
5306 fprintf (outfile, "\n\n");
f37230f0
JM
5307}
5308
3f76745e
JM
5309/* Print the information collected for a given DIE. */
5310
5311void
5312debug_dwarf_die (die)
5313 dw_die_ref die;
5314{
5315 print_die (die, stderr);
5316}
5317
5318/* Print all DWARF information collected for the compilation unit.
5319 This routine is a debugging aid only. */
5320
5321void
5322debug_dwarf ()
5323{
5324 print_indent = 0;
5325 print_die (comp_unit_die, stderr);
b2244e22
JW
5326 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5327 print_dwarf_line_table (stderr);
3f76745e
JM
5328}
5329\f
a96c67ec
JM
5330/* We build up the lists of children and attributes by pushing new ones
5331 onto the beginning of the list. Reverse the lists for DIE so that
5332 they are in order of addition. */
71dfc51f 5333
f37230f0 5334static void
a96c67ec 5335reverse_die_lists (die)
b3694847 5336 dw_die_ref die;
f37230f0 5337{
b3694847
SS
5338 dw_die_ref c, cp, cn;
5339 dw_attr_ref a, ap, an;
71dfc51f 5340
a96c67ec 5341 for (a = die->die_attr, ap = 0; a; a = an)
7d9d8943
AM
5342 {
5343 an = a->dw_attr_next;
5344 a->dw_attr_next = ap;
5345 ap = a;
a3f97cbb 5346 }
2ad9852d 5347
7d9d8943 5348 die->die_attr = ap;
3f76745e 5349
7d9d8943
AM
5350 for (c = die->die_child, cp = 0; c; c = cn)
5351 {
5352 cn = c->die_sib;
5353 c->die_sib = cp;
5354 cp = c;
5355 }
2ad9852d 5356
7d9d8943 5357 die->die_child = cp;
a3f97cbb
JW
5358}
5359
2ad9852d
RK
5360/* reverse_die_lists only reverses the single die you pass it. Since we used to
5361 reverse all dies in add_sibling_attributes, which runs through all the dies,
5362 it would reverse all the dies. Now, however, since we don't call
5363 reverse_die_lists in add_sibling_attributes, we need a routine to
5364 recursively reverse all the dies. This is that routine. */
71dfc51f 5365
7d9d8943 5366static void
881c6935 5367reverse_all_dies (die)
b3694847 5368 dw_die_ref die;
a3f97cbb 5369{
b3694847 5370 dw_die_ref c;
71dfc51f 5371
7d9d8943 5372 reverse_die_lists (die);
3f76745e 5373
881c6935
JM
5374 for (c = die->die_child; c; c = c->die_sib)
5375 reverse_all_dies (c);
5376}
5377
2ad9852d
RK
5378/* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5379 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5380 DIE that marks the start of the DIEs for this include file. */
881c6935
JM
5381
5382static dw_die_ref
5383push_new_compile_unit (old_unit, bincl_die)
5384 dw_die_ref old_unit, bincl_die;
5385{
5386 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5387 dw_die_ref new_unit = gen_compile_unit_die (filename);
2ad9852d 5388
881c6935
JM
5389 new_unit->die_sib = old_unit;
5390 return new_unit;
5391}
5392
5393/* Close an include-file CU and reopen the enclosing one. */
5394
5395static dw_die_ref
5396pop_compile_unit (old_unit)
5397 dw_die_ref old_unit;
5398{
5399 dw_die_ref new_unit = old_unit->die_sib;
2ad9852d 5400
881c6935
JM
5401 old_unit->die_sib = NULL;
5402 return new_unit;
5403}
5404
2ad9852d
RK
5405#define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5406#define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
881c6935
JM
5407
5408/* Calculate the checksum of a location expression. */
5409
5410static inline void
5411loc_checksum (loc, ctx)
5412 dw_loc_descr_ref loc;
5413 struct md5_ctx *ctx;
5414{
2ad9852d
RK
5415 CHECKSUM (loc->dw_loc_opc);
5416 CHECKSUM (loc->dw_loc_oprnd1);
5417 CHECKSUM (loc->dw_loc_oprnd2);
881c6935
JM
5418}
5419
5420/* Calculate the checksum of an attribute. */
5421
5422static void
5423attr_checksum (at, ctx)
5424 dw_attr_ref at;
5425 struct md5_ctx *ctx;
5426{
5427 dw_loc_descr_ref loc;
5428 rtx r;
5429
2ad9852d 5430 CHECKSUM (at->dw_attr);
881c6935
JM
5431
5432 /* We don't care about differences in file numbering. */
5f632b5e
JM
5433 if (at->dw_attr == DW_AT_decl_file
5434 /* Or that this was compiled with a different compiler snapshot; if
5435 the output is the same, that's what matters. */
5436 || at->dw_attr == DW_AT_producer)
881c6935
JM
5437 return;
5438
5439 switch (AT_class (at))
5440 {
5441 case dw_val_class_const:
2ad9852d 5442 CHECKSUM (at->dw_attr_val.v.val_int);
881c6935
JM
5443 break;
5444 case dw_val_class_unsigned_const:
2ad9852d 5445 CHECKSUM (at->dw_attr_val.v.val_unsigned);
881c6935
JM
5446 break;
5447 case dw_val_class_long_long:
2ad9852d 5448 CHECKSUM (at->dw_attr_val.v.val_long_long);
881c6935
JM
5449 break;
5450 case dw_val_class_float:
2ad9852d 5451 CHECKSUM (at->dw_attr_val.v.val_float);
881c6935
JM
5452 break;
5453 case dw_val_class_flag:
2ad9852d 5454 CHECKSUM (at->dw_attr_val.v.val_flag);
881c6935 5455 break;
881c6935 5456 case dw_val_class_str:
2ad9852d 5457 CHECKSUM_STRING (AT_string (at));
881c6935 5458 break;
a20612aa 5459
881c6935
JM
5460 case dw_val_class_addr:
5461 r = AT_addr (at);
5462 switch (GET_CODE (r))
5463 {
5464 case SYMBOL_REF:
2ad9852d 5465 CHECKSUM_STRING (XSTR (r, 0));
881c6935
JM
5466 break;
5467
5468 default:
5469 abort ();
5470 }
5471 break;
5472
a20612aa 5473 case dw_val_class_offset:
2ad9852d 5474 CHECKSUM (at->dw_attr_val.v.val_offset);
a20612aa
RH
5475 break;
5476
881c6935
JM
5477 case dw_val_class_loc:
5478 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5479 loc_checksum (loc, ctx);
5480 break;
5481
5482 case dw_val_class_die_ref:
5483 if (AT_ref (at)->die_offset)
2ad9852d 5484 CHECKSUM (AT_ref (at)->die_offset);
881c6935
JM
5485 /* FIXME else use target die name or something. */
5486
5487 case dw_val_class_fde_ref:
5488 case dw_val_class_lbl_id:
5489 case dw_val_class_lbl_offset:
a20612aa 5490 break;
881c6935
JM
5491
5492 default:
5493 break;
5494 }
5495}
5496
5497/* Calculate the checksum of a DIE. */
5498
5499static void
5500die_checksum (die, ctx)
5501 dw_die_ref die;
5502 struct md5_ctx *ctx;
5503{
5504 dw_die_ref c;
5505 dw_attr_ref a;
5506
2ad9852d 5507 CHECKSUM (die->die_tag);
881c6935
JM
5508
5509 for (a = die->die_attr; a; a = a->dw_attr_next)
5510 attr_checksum (a, ctx);
5511
5512 for (c = die->die_child; c; c = c->die_sib)
5513 die_checksum (c, ctx);
5514}
5515
2ad9852d
RK
5516#undef CHECKSUM
5517#undef CHECKSUM_STRING
881c6935
JM
5518
5519/* The prefix to attach to symbols on DIEs in the current comdat debug
5520 info section. */
5521static char *comdat_symbol_id;
5522
5523/* The index of the current symbol within the current comdat CU. */
5524static unsigned int comdat_symbol_number;
5525
5526/* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5527 children, and set comdat_symbol_id accordingly. */
5528
5529static void
5530compute_section_prefix (unit_die)
5531 dw_die_ref unit_die;
5532{
f11c3043
RK
5533 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5534 char *name = (char *) alloca (strlen (base) + 64);
5535 char *p;
881c6935
JM
5536 int i;
5537 unsigned char checksum[16];
5538 struct md5_ctx ctx;
5539
f11c3043
RK
5540 /* Compute the checksum of the DIE, then append part of it as hex digits to
5541 the name filename of the unit. */
5542
881c6935
JM
5543 md5_init_ctx (&ctx);
5544 die_checksum (unit_die, &ctx);
5545 md5_finish_ctx (&ctx, checksum);
5546
0023400b 5547 sprintf (name, "%s.", base);
881c6935
JM
5548 clean_symbol_name (name);
5549
2ad9852d
RK
5550 p = name + strlen (name);
5551 for (i = 0; i < 4; i++)
5552 {
5553 sprintf (p, "%.2x", checksum[i]);
5554 p += 2;
5555 }
881c6935
JM
5556
5557 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5558 comdat_symbol_number = 0;
5559}
5560
f11c3043 5561/* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
881c6935
JM
5562
5563static int
5564is_type_die (die)
5565 dw_die_ref die;
5566{
5567 switch (die->die_tag)
5568 {
5569 case DW_TAG_array_type:
5570 case DW_TAG_class_type:
5571 case DW_TAG_enumeration_type:
5572 case DW_TAG_pointer_type:
5573 case DW_TAG_reference_type:
5574 case DW_TAG_string_type:
5575 case DW_TAG_structure_type:
5576 case DW_TAG_subroutine_type:
5577 case DW_TAG_union_type:
5578 case DW_TAG_ptr_to_member_type:
5579 case DW_TAG_set_type:
5580 case DW_TAG_subrange_type:
5581 case DW_TAG_base_type:
5582 case DW_TAG_const_type:
5583 case DW_TAG_file_type:
5584 case DW_TAG_packed_type:
5585 case DW_TAG_volatile_type:
5586 return 1;
5587 default:
5588 return 0;
5589 }
5590}
5591
5592/* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5593 Basically, we want to choose the bits that are likely to be shared between
5594 compilations (types) and leave out the bits that are specific to individual
5595 compilations (functions). */
5596
5597static int
5598is_comdat_die (c)
5599 dw_die_ref c;
5600{
2ad9852d
RK
5601 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5602 we do for stabs. The advantage is a greater likelihood of sharing between
5603 objects that don't include headers in the same order (and therefore would
5604 put the base types in a different comdat). jason 8/28/00 */
5605
881c6935
JM
5606 if (c->die_tag == DW_TAG_base_type)
5607 return 0;
5608
5609 if (c->die_tag == DW_TAG_pointer_type
5610 || c->die_tag == DW_TAG_reference_type
5611 || c->die_tag == DW_TAG_const_type
5612 || c->die_tag == DW_TAG_volatile_type)
5613 {
5614 dw_die_ref t = get_AT_ref (c, DW_AT_type);
2ad9852d 5615
881c6935
JM
5616 return t ? is_comdat_die (t) : 0;
5617 }
881c6935
JM
5618
5619 return is_type_die (c);
5620}
5621
5622/* Returns 1 iff C is the sort of DIE that might be referred to from another
5623 compilation unit. */
5624
5625static int
5626is_symbol_die (c)
5627 dw_die_ref c;
5628{
2ad9852d 5629 return (is_type_die (c)
c26fbbca 5630 || (get_AT (c, DW_AT_declaration)
2ad9852d 5631 && !get_AT (c, DW_AT_specification)));
881c6935
JM
5632}
5633
5634static char *
63e46568 5635gen_internal_sym (prefix)
173bf5be 5636 const char *prefix;
881c6935
JM
5637{
5638 char buf[256];
5639 static int label_num;
2ad9852d 5640
63e46568 5641 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
881c6935
JM
5642 return xstrdup (buf);
5643}
5644
5645/* Assign symbols to all worthy DIEs under DIE. */
5646
5647static void
5648assign_symbol_names (die)
b3694847 5649 dw_die_ref die;
881c6935 5650{
b3694847 5651 dw_die_ref c;
881c6935
JM
5652
5653 if (is_symbol_die (die))
5654 {
5655 if (comdat_symbol_id)
5656 {
5657 char *p = alloca (strlen (comdat_symbol_id) + 64);
2ad9852d 5658
881c6935
JM
5659 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5660 comdat_symbol_id, comdat_symbol_number++);
5661 die->die_symbol = xstrdup (p);
5662 }
5663 else
63e46568 5664 die->die_symbol = gen_internal_sym ("LDIE");
881c6935
JM
5665 }
5666
5667 for (c = die->die_child; c != NULL; c = c->die_sib)
5668 assign_symbol_names (c);
5669}
5670
5671/* Traverse the DIE (which is always comp_unit_die), and set up
5672 additional compilation units for each of the include files we see
5673 bracketed by BINCL/EINCL. */
5674
5675static void
5676break_out_includes (die)
b3694847 5677 dw_die_ref die;
881c6935
JM
5678{
5679 dw_die_ref *ptr;
b3694847 5680 dw_die_ref unit = NULL;
881c6935
JM
5681 limbo_die_node *node;
5682
c26fbbca 5683 for (ptr = &(die->die_child); *ptr;)
881c6935 5684 {
b3694847 5685 dw_die_ref c = *ptr;
881c6935 5686
2ad9852d 5687 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
881c6935
JM
5688 || (unit && is_comdat_die (c)))
5689 {
5690 /* This DIE is for a secondary CU; remove it from the main one. */
5691 *ptr = c->die_sib;
5692
5693 if (c->die_tag == DW_TAG_GNU_BINCL)
5694 {
5695 unit = push_new_compile_unit (unit, c);
5696 free_die (c);
5697 }
5698 else if (c->die_tag == DW_TAG_GNU_EINCL)
5699 {
5700 unit = pop_compile_unit (unit);
5701 free_die (c);
5702 }
5703 else
5704 add_child_die (unit, c);
5705 }
5706 else
5707 {
5708 /* Leave this DIE in the main CU. */
5709 ptr = &(c->die_sib);
5710 continue;
5711 }
5712 }
5713
5714#if 0
5715 /* We can only use this in debugging, since the frontend doesn't check
0b34cf1e 5716 to make sure that we leave every include file we enter. */
881c6935
JM
5717 if (unit != NULL)
5718 abort ();
5719#endif
5720
5721 assign_symbol_names (die);
5722 for (node = limbo_die_list; node; node = node->next)
5723 {
5724 compute_section_prefix (node->die);
5725 assign_symbol_names (node->die);
5726 }
5727}
5728
5729/* Traverse the DIE and add a sibling attribute if it may have the
5730 effect of speeding up access to siblings. To save some space,
5731 avoid generating sibling attributes for DIE's without children. */
5732
5733static void
5734add_sibling_attributes (die)
b3694847 5735 dw_die_ref die;
881c6935 5736{
b3694847 5737 dw_die_ref c;
881c6935
JM
5738
5739 if (die->die_tag != DW_TAG_compile_unit
5740 && die->die_sib && die->die_child != NULL)
7d9d8943
AM
5741 /* Add the sibling link to the front of the attribute list. */
5742 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5743
5744 for (c = die->die_child; c != NULL; c = c->die_sib)
5745 add_sibling_attributes (c);
5746}
5747
2ad9852d
RK
5748/* Output all location lists for the DIE and its children. */
5749
63e46568
DB
5750static void
5751output_location_lists (die)
b3694847 5752 dw_die_ref die;
63e46568
DB
5753{
5754 dw_die_ref c;
5755 dw_attr_ref d_attr;
2ad9852d 5756
63e46568 5757 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
2ad9852d
RK
5758 if (AT_class (d_attr) == dw_val_class_loc_list)
5759 output_loc_list (AT_loc_list (d_attr));
5760
63e46568
DB
5761 for (c = die->die_child; c != NULL; c = c->die_sib)
5762 output_location_lists (c);
5763
5764}
c26fbbca 5765
2ad9852d
RK
5766/* The format of each DIE (and its attribute value pairs) is encoded in an
5767 abbreviation table. This routine builds the abbreviation table and assigns
5768 a unique abbreviation id for each abbreviation entry. The children of each
5769 die are visited recursively. */
7d9d8943
AM
5770
5771static void
5772build_abbrev_table (die)
b3694847 5773 dw_die_ref die;
7d9d8943 5774{
b3694847
SS
5775 unsigned long abbrev_id;
5776 unsigned int n_alloc;
5777 dw_die_ref c;
5778 dw_attr_ref d_attr, a_attr;
881c6935
JM
5779
5780 /* Scan the DIE references, and mark as external any that refer to
1bfb5f8f 5781 DIEs from other CUs (i.e. those which are not marked). */
881c6935 5782 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
2ad9852d
RK
5783 if (AT_class (d_attr) == dw_val_class_die_ref
5784 && AT_ref (d_attr)->die_mark == 0)
5785 {
5786 if (AT_ref (d_attr)->die_symbol == 0)
5787 abort ();
5788
5789 set_AT_ref_external (d_attr, 1);
5790 }
881c6935 5791
7d9d8943
AM
5792 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5793 {
b3694847 5794 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7d9d8943
AM
5795
5796 if (abbrev->die_tag == die->die_tag)
5797 {
5798 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5799 {
5800 a_attr = abbrev->die_attr;
5801 d_attr = die->die_attr;
5802
5803 while (a_attr != NULL && d_attr != NULL)
5804 {
5805 if ((a_attr->dw_attr != d_attr->dw_attr)
5806 || (value_format (a_attr) != value_format (d_attr)))
5807 break;
5808
5809 a_attr = a_attr->dw_attr_next;
5810 d_attr = d_attr->dw_attr_next;
5811 }
5812
5813 if (a_attr == NULL && d_attr == NULL)
5814 break;
5815 }
5816 }
5817 }
5818
5819 if (abbrev_id >= abbrev_die_table_in_use)
5820 {
5821 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5822 {
5823 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
556273e0 5824 abbrev_die_table
7d9d8943
AM
5825 = (dw_die_ref *) xrealloc (abbrev_die_table,
5826 sizeof (dw_die_ref) * n_alloc);
5827
961192e1 5828 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
7d9d8943
AM
5829 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5830 abbrev_die_table_allocated = n_alloc;
5831 }
5832
5833 ++abbrev_die_table_in_use;
5834 abbrev_die_table[abbrev_id] = die;
5835 }
5836
5837 die->die_abbrev = abbrev_id;
5838 for (c = die->die_child; c != NULL; c = c->die_sib)
5839 build_abbrev_table (c);
5840}
5841\f
3f76745e
JM
5842/* Return the power-of-two number of bytes necessary to represent VALUE. */
5843
5844static int
5845constant_size (value)
5846 long unsigned value;
5847{
5848 int log;
5849
5850 if (value == 0)
5851 log = 0;
a3f97cbb 5852 else
3f76745e 5853 log = floor_log2 (value);
71dfc51f 5854
3f76745e
JM
5855 log = log / 8;
5856 log = 1 << (floor_log2 (log) + 1);
5857
5858 return log;
a3f97cbb
JW
5859}
5860
2ad9852d 5861/* Return the size of a DIE as it is represented in the
3f76745e 5862 .debug_info section. */
71dfc51f 5863
3f76745e
JM
5864static unsigned long
5865size_of_die (die)
b3694847 5866 dw_die_ref die;
a3f97cbb 5867{
b3694847
SS
5868 unsigned long size = 0;
5869 dw_attr_ref a;
71dfc51f 5870
3f76745e 5871 size += size_of_uleb128 (die->die_abbrev);
a3f97cbb
JW
5872 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5873 {
a96c67ec 5874 switch (AT_class (a))
a3f97cbb
JW
5875 {
5876 case dw_val_class_addr:
a1a4189d 5877 size += DWARF2_ADDR_SIZE;
a3f97cbb 5878 break;
a20612aa
RH
5879 case dw_val_class_offset:
5880 size += DWARF_OFFSET_SIZE;
5881 break;
a3f97cbb 5882 case dw_val_class_loc:
3f76745e 5883 {
b3694847 5884 unsigned long lsize = size_of_locs (AT_loc (a));
71dfc51f 5885
3f76745e
JM
5886 /* Block length. */
5887 size += constant_size (lsize);
5888 size += lsize;
5889 }
a3f97cbb 5890 break;
63e46568
DB
5891 case dw_val_class_loc_list:
5892 size += DWARF_OFFSET_SIZE;
5893 break;
2bee6045
JJ
5894 case dw_val_class_range_list:
5895 size += DWARF_OFFSET_SIZE;
5896 break;
a3f97cbb 5897 case dw_val_class_const:
25dd13ec 5898 size += size_of_sleb128 (AT_int (a));
a3f97cbb
JW
5899 break;
5900 case dw_val_class_unsigned_const:
a96c67ec 5901 size += constant_size (AT_unsigned (a));
a3f97cbb 5902 break;
469ac993 5903 case dw_val_class_long_long:
2e4b9b8c 5904 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
469ac993
JM
5905 break;
5906 case dw_val_class_float:
3f76745e 5907 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
a3f97cbb
JW
5908 break;
5909 case dw_val_class_flag:
3f76745e 5910 size += 1;
a3f97cbb
JW
5911 break;
5912 case dw_val_class_die_ref:
3f76745e 5913 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
5914 break;
5915 case dw_val_class_fde_ref:
3f76745e 5916 size += DWARF_OFFSET_SIZE;
a3f97cbb
JW
5917 break;
5918 case dw_val_class_lbl_id:
a1a4189d 5919 size += DWARF2_ADDR_SIZE;
3f76745e 5920 break;
8b790721 5921 case dw_val_class_lbl_offset:
3f76745e
JM
5922 size += DWARF_OFFSET_SIZE;
5923 break;
5924 case dw_val_class_str:
9eb4015a
JJ
5925 if (AT_string_form (a) == DW_FORM_strp)
5926 size += DWARF_OFFSET_SIZE;
5927 else
5928 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
3f76745e
JM
5929 break;
5930 default:
5931 abort ();
5932 }
a3f97cbb 5933 }
3f76745e
JM
5934
5935 return size;
a3f97cbb
JW
5936}
5937
2ad9852d
RK
5938/* Size the debugging information associated with a given DIE. Visits the
5939 DIE's children recursively. Updates the global variable next_die_offset, on
5940 each time through. Uses the current value of next_die_offset to update the
5941 die_offset field in each DIE. */
71dfc51f 5942
a3f97cbb 5943static void
3f76745e
JM
5944calc_die_sizes (die)
5945 dw_die_ref die;
a3f97cbb 5946{
b3694847 5947 dw_die_ref c;
2ad9852d 5948
3f76745e
JM
5949 die->die_offset = next_die_offset;
5950 next_die_offset += size_of_die (die);
71dfc51f 5951
3f76745e
JM
5952 for (c = die->die_child; c != NULL; c = c->die_sib)
5953 calc_die_sizes (c);
71dfc51f 5954
3f76745e
JM
5955 if (die->die_child != NULL)
5956 /* Count the null byte used to terminate sibling lists. */
5957 next_die_offset += 1;
a3f97cbb
JW
5958}
5959
1bfb5f8f 5960/* Set the marks for a die and its children. We do this so
881c6935 5961 that we know whether or not a reference needs to use FORM_ref_addr; only
1bfb5f8f
JM
5962 DIEs in the same CU will be marked. We used to clear out the offset
5963 and use that as the flag, but ran into ordering problems. */
881c6935
JM
5964
5965static void
1bfb5f8f 5966mark_dies (die)
881c6935
JM
5967 dw_die_ref die;
5968{
b3694847 5969 dw_die_ref c;
2ad9852d 5970
1bfb5f8f
JM
5971 die->die_mark = 1;
5972 for (c = die->die_child; c; c = c->die_sib)
5973 mark_dies (c);
5974}
5975
5976/* Clear the marks for a die and its children. */
5977
5978static void
5979unmark_dies (die)
5980 dw_die_ref die;
5981{
b3694847 5982 dw_die_ref c;
2ad9852d 5983
1bfb5f8f 5984 die->die_mark = 0;
881c6935 5985 for (c = die->die_child; c; c = c->die_sib)
1bfb5f8f 5986 unmark_dies (c);
881c6935
JM
5987}
5988
3f76745e
JM
5989/* Return the size of the .debug_pubnames table generated for the
5990 compilation unit. */
a94dbf2c 5991
3f76745e
JM
5992static unsigned long
5993size_of_pubnames ()
a94dbf2c 5994{
b3694847
SS
5995 unsigned long size;
5996 unsigned i;
469ac993 5997
3f76745e 5998 size = DWARF_PUBNAMES_HEADER_SIZE;
2ad9852d 5999 for (i = 0; i < pubname_table_in_use; i++)
a94dbf2c 6000 {
b3694847 6001 pubname_ref p = &pubname_table[i];
9eb4015a 6002 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
a94dbf2c
JM
6003 }
6004
3f76745e
JM
6005 size += DWARF_OFFSET_SIZE;
6006 return size;
a94dbf2c
JM
6007}
6008
956d6950 6009/* Return the size of the information in the .debug_aranges section. */
469ac993 6010
3f76745e
JM
6011static unsigned long
6012size_of_aranges ()
469ac993 6013{
b3694847 6014 unsigned long size;
469ac993 6015
3f76745e 6016 size = DWARF_ARANGES_HEADER_SIZE;
469ac993 6017
3f76745e 6018 /* Count the address/length pair for this compilation unit. */
a1a4189d
JB
6019 size += 2 * DWARF2_ADDR_SIZE;
6020 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
469ac993 6021
3f76745e 6022 /* Count the two zero words used to terminated the address range table. */
a1a4189d 6023 size += 2 * DWARF2_ADDR_SIZE;
3f76745e
JM
6024 return size;
6025}
6026\f
6027/* Select the encoding of an attribute value. */
6028
6029static enum dwarf_form
a96c67ec
JM
6030value_format (a)
6031 dw_attr_ref a;
3f76745e 6032{
a96c67ec 6033 switch (a->dw_attr_val.val_class)
469ac993 6034 {
3f76745e
JM
6035 case dw_val_class_addr:
6036 return DW_FORM_addr;
2bee6045 6037 case dw_val_class_range_list:
a20612aa
RH
6038 case dw_val_class_offset:
6039 if (DWARF_OFFSET_SIZE == 4)
6040 return DW_FORM_data4;
6041 if (DWARF_OFFSET_SIZE == 8)
6042 return DW_FORM_data8;
6043 abort ();
63e46568 6044 case dw_val_class_loc_list:
9d2f2c45
RH
6045 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6046 .debug_loc section */
6047 return DW_FORM_data4;
3f76745e 6048 case dw_val_class_loc:
a96c67ec 6049 switch (constant_size (size_of_locs (AT_loc (a))))
469ac993 6050 {
3f76745e
JM
6051 case 1:
6052 return DW_FORM_block1;
6053 case 2:
6054 return DW_FORM_block2;
469ac993
JM
6055 default:
6056 abort ();
6057 }
3f76745e 6058 case dw_val_class_const:
25dd13ec 6059 return DW_FORM_sdata;
3f76745e 6060 case dw_val_class_unsigned_const:
a96c67ec 6061 switch (constant_size (AT_unsigned (a)))
3f76745e
JM
6062 {
6063 case 1:
6064 return DW_FORM_data1;
6065 case 2:
6066 return DW_FORM_data2;
6067 case 4:
6068 return DW_FORM_data4;
6069 case 8:
6070 return DW_FORM_data8;
6071 default:
6072 abort ();
6073 }
6074 case dw_val_class_long_long:
6075 return DW_FORM_block1;
6076 case dw_val_class_float:
6077 return DW_FORM_block1;
6078 case dw_val_class_flag:
6079 return DW_FORM_flag;
6080 case dw_val_class_die_ref:
881c6935
JM
6081 if (AT_ref_external (a))
6082 return DW_FORM_ref_addr;
6083 else
6084 return DW_FORM_ref;
3f76745e
JM
6085 case dw_val_class_fde_ref:
6086 return DW_FORM_data;
6087 case dw_val_class_lbl_id:
6088 return DW_FORM_addr;
8b790721 6089 case dw_val_class_lbl_offset:
3f76745e
JM
6090 return DW_FORM_data;
6091 case dw_val_class_str:
9eb4015a 6092 return AT_string_form (a);
a20612aa 6093
469ac993
JM
6094 default:
6095 abort ();
6096 }
a94dbf2c
JM
6097}
6098
3f76745e 6099/* Output the encoding of an attribute value. */
469ac993 6100
3f76745e 6101static void
a96c67ec
JM
6102output_value_format (a)
6103 dw_attr_ref a;
a94dbf2c 6104{
a96c67ec 6105 enum dwarf_form form = value_format (a);
2ad9852d 6106
2e4b9b8c 6107 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
3f76745e 6108}
469ac993 6109
3f76745e
JM
6110/* Output the .debug_abbrev section which defines the DIE abbreviation
6111 table. */
469ac993 6112
3f76745e
JM
6113static void
6114output_abbrev_section ()
6115{
6116 unsigned long abbrev_id;
71dfc51f 6117
3f76745e 6118 dw_attr_ref a_attr;
2ad9852d 6119
3f76745e
JM
6120 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6121 {
b3694847 6122 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
71dfc51f 6123
2e4b9b8c 6124 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
2e4b9b8c
RH
6125 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6126 dwarf_tag_name (abbrev->die_tag));
71dfc51f 6127
2e4b9b8c
RH
6128 if (abbrev->die_child != NULL)
6129 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6130 else
6131 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
3f76745e
JM
6132
6133 for (a_attr = abbrev->die_attr; a_attr != NULL;
6134 a_attr = a_attr->dw_attr_next)
6135 {
2e4b9b8c
RH
6136 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6137 dwarf_attr_name (a_attr->dw_attr));
a96c67ec 6138 output_value_format (a_attr);
469ac993 6139 }
469ac993 6140
2e4b9b8c
RH
6141 dw2_asm_output_data (1, 0, NULL);
6142 dw2_asm_output_data (1, 0, NULL);
469ac993 6143 }
81f374eb
HPN
6144
6145 /* Terminate the table. */
2e4b9b8c 6146 dw2_asm_output_data (1, 0, NULL);
a94dbf2c
JM
6147}
6148
881c6935
JM
6149/* Output a symbol we can use to refer to this DIE from another CU. */
6150
6151static inline void
6152output_die_symbol (die)
b3694847 6153 dw_die_ref die;
881c6935
JM
6154{
6155 char *sym = die->die_symbol;
6156
6157 if (sym == 0)
6158 return;
6159
6160 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6161 /* We make these global, not weak; if the target doesn't support
6162 .linkonce, it doesn't support combining the sections, so debugging
6163 will break. */
5eb99654 6164 (*targetm.asm_out.globalize_label) (asm_out_file, sym);
2ad9852d 6165
881c6935
JM
6166 ASM_OUTPUT_LABEL (asm_out_file, sym);
6167}
6168
84a5b4f8 6169/* Return a new location list, given the begin and end range, and the
2ad9852d
RK
6170 expression. gensym tells us whether to generate a new internal symbol for
6171 this location list node, which is done for the head of the list only. */
6172
84a5b4f8
DB
6173static inline dw_loc_list_ref
6174new_loc_list (expr, begin, end, section, gensym)
b3694847
SS
6175 dw_loc_descr_ref expr;
6176 const char *begin;
6177 const char *end;
6178 const char *section;
6179 unsigned gensym;
84a5b4f8 6180{
b3694847 6181 dw_loc_list_ref retlist
84a5b4f8 6182 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
2ad9852d 6183
84a5b4f8
DB
6184 retlist->begin = begin;
6185 retlist->end = end;
6186 retlist->expr = expr;
6187 retlist->section = section;
c26fbbca 6188 if (gensym)
84a5b4f8 6189 retlist->ll_symbol = gen_internal_sym ("LLST");
2ad9852d 6190
84a5b4f8
DB
6191 return retlist;
6192}
6193
6194/* Add a location description expression to a location list */
2ad9852d 6195
84a5b4f8
DB
6196static inline void
6197add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
b3694847
SS
6198 dw_loc_list_ref *list_head;
6199 dw_loc_descr_ref descr;
6200 const char *begin;
6201 const char *end;
6202 const char *section;
84a5b4f8 6203{
b3694847 6204 dw_loc_list_ref *d;
c26fbbca 6205
30f7a378 6206 /* Find the end of the chain. */
84a5b4f8
DB
6207 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6208 ;
2ad9852d 6209
84a5b4f8
DB
6210 /* Add a new location list node to the list */
6211 *d = new_loc_list (descr, begin, end, section, 0);
6212}
6213
63e46568 6214/* Output the location list given to us */
2ad9852d 6215
63e46568
DB
6216static void
6217output_loc_list (list_head)
b3694847 6218 dw_loc_list_ref list_head;
63e46568 6219{
2ad9852d
RK
6220 dw_loc_list_ref curr = list_head;
6221
63e46568 6222 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
a20612aa
RH
6223
6224 /* ??? This shouldn't be needed now that we've forced the
6225 compilation unit base address to zero when there is code
6226 in more than one section. */
63e46568
DB
6227 if (strcmp (curr->section, ".text") == 0)
6228 {
aafdcfcd 6229 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
c4f2c499 6230 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
aafdcfcd
NS
6231 "Location list base address specifier fake entry");
6232 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6233 "Location list base address specifier base");
63e46568 6234 }
2ad9852d 6235
c26fbbca 6236 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
63e46568 6237 {
2bee6045 6238 unsigned long size;
2ad9852d 6239
aafdcfcd
NS
6240 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6241 "Location list begin address (%s)",
6242 list_head->ll_symbol);
6243 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6244 "Location list end address (%s)",
6245 list_head->ll_symbol);
63e46568 6246 size = size_of_locs (curr->expr);
c26fbbca 6247
63e46568 6248 /* Output the block length for this list of location operations. */
2bee6045
JJ
6249 if (size > 0xffff)
6250 abort ();
6251 dw2_asm_output_data (2, size, "%s", "Location expression size");
6252
63e46568
DB
6253 output_loc_sequence (curr->expr);
6254 }
2ad9852d 6255
aafdcfcd
NS
6256 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6257 "Location list terminator begin (%s)",
6258 list_head->ll_symbol);
6259 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6260 "Location list terminator end (%s)",
6261 list_head->ll_symbol);
63e46568 6262}
9eb4015a 6263
3f76745e
JM
6264/* Output the DIE and its attributes. Called recursively to generate
6265 the definitions of each child DIE. */
71dfc51f 6266
a3f97cbb 6267static void
3f76745e 6268output_die (die)
b3694847 6269 dw_die_ref die;
a3f97cbb 6270{
b3694847
SS
6271 dw_attr_ref a;
6272 dw_die_ref c;
6273 unsigned long size;
a94dbf2c 6274
881c6935
JM
6275 /* If someone in another CU might refer to us, set up a symbol for
6276 them to point to. */
6277 if (die->die_symbol)
6278 output_die_symbol (die);
6279
2e4b9b8c
RH
6280 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6281 die->die_offset, dwarf_tag_name (die->die_tag));
a94dbf2c 6282
3f76745e 6283 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
a3f97cbb 6284 {
2e4b9b8c
RH
6285 const char *name = dwarf_attr_name (a->dw_attr);
6286
a96c67ec 6287 switch (AT_class (a))
3f76745e
JM
6288 {
6289 case dw_val_class_addr:
2e4b9b8c 6290 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
3f76745e 6291 break;
a3f97cbb 6292
a20612aa
RH
6293 case dw_val_class_offset:
6294 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6295 "%s", name);
6296 break;
6297
2bee6045
JJ
6298 case dw_val_class_range_list:
6299 {
6300 char *p = strchr (ranges_section_label, '\0');
6301
6302 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6303 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6304 "%s", name);
6305 *p = '\0';
6306 }
6307 break;
6308
3f76745e 6309 case dw_val_class_loc:
a96c67ec 6310 size = size_of_locs (AT_loc (a));
71dfc51f 6311
3f76745e 6312 /* Output the block length for this list of location operations. */
2e4b9b8c 6313 dw2_asm_output_data (constant_size (size), size, "%s", name);
71dfc51f 6314
7d9d8943 6315 output_loc_sequence (AT_loc (a));
a3f97cbb 6316 break;
3f76745e
JM
6317
6318 case dw_val_class_const:
25dd13ec
JW
6319 /* ??? It would be slightly more efficient to use a scheme like is
6320 used for unsigned constants below, but gdb 4.x does not sign
6321 extend. Gdb 5.x does sign extend. */
2e4b9b8c 6322 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
a3f97cbb 6323 break;
3f76745e
JM
6324
6325 case dw_val_class_unsigned_const:
2e4b9b8c
RH
6326 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6327 AT_unsigned (a), "%s", name);
a3f97cbb 6328 break;
3f76745e
JM
6329
6330 case dw_val_class_long_long:
2e4b9b8c
RH
6331 {
6332 unsigned HOST_WIDE_INT first, second;
3f76745e 6333
2ad9852d
RK
6334 dw2_asm_output_data (1,
6335 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
c26fbbca 6336 "%s", name);
556273e0 6337
2e4b9b8c
RH
6338 if (WORDS_BIG_ENDIAN)
6339 {
6340 first = a->dw_attr_val.v.val_long_long.hi;
6341 second = a->dw_attr_val.v.val_long_long.low;
6342 }
6343 else
6344 {
6345 first = a->dw_attr_val.v.val_long_long.low;
6346 second = a->dw_attr_val.v.val_long_long.hi;
6347 }
2ad9852d
RK
6348
6349 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
2e4b9b8c 6350 first, "long long constant");
2ad9852d 6351 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
2e4b9b8c
RH
6352 second, NULL);
6353 }
a3f97cbb 6354 break;
3f76745e
JM
6355
6356 case dw_val_class_float:
c84e2712 6357 {
b3694847 6358 unsigned int i;
c84e2712 6359
2e4b9b8c 6360 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
c26fbbca 6361 "%s", name);
c84e2712 6362
2ad9852d 6363 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
2e4b9b8c
RH
6364 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6365 "fp constant word %u", i);
556273e0 6366 break;
c84e2712 6367 }
3f76745e
JM
6368
6369 case dw_val_class_flag:
2e4b9b8c 6370 dw2_asm_output_data (1, AT_flag (a), "%s", name);
a3f97cbb 6371 break;
a20612aa 6372
c26fbbca 6373 case dw_val_class_loc_list:
63e46568
DB
6374 {
6375 char *sym = AT_loc_list (a)->ll_symbol;
2ad9852d 6376
63e46568 6377 if (sym == 0)
173bf5be 6378 abort ();
a20612aa
RH
6379 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6380 loc_section_label, "%s", name);
63e46568
DB
6381 }
6382 break;
a20612aa 6383
3f76745e 6384 case dw_val_class_die_ref:
881c6935 6385 if (AT_ref_external (a))
2e4b9b8c
RH
6386 {
6387 char *sym = AT_ref (a)->die_symbol;
2ad9852d 6388
2e4b9b8c
RH
6389 if (sym == 0)
6390 abort ();
6391 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6392 }
3f4907a6
JM
6393 else if (AT_ref (a)->die_offset == 0)
6394 abort ();
881c6935 6395 else
2e4b9b8c
RH
6396 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6397 "%s", name);
a3f97cbb 6398 break;
3f76745e
JM
6399
6400 case dw_val_class_fde_ref:
a6ab3aad
JM
6401 {
6402 char l1[20];
2ad9852d 6403
2e4b9b8c
RH
6404 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6405 a->dw_attr_val.v.val_fde_index * 2);
6406 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
a6ab3aad 6407 }
a3f97cbb 6408 break;
a3f97cbb 6409
3f76745e 6410 case dw_val_class_lbl_id:
8e7fa2c8 6411 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
3f76745e 6412 break;
71dfc51f 6413
8b790721 6414 case dw_val_class_lbl_offset:
2e4b9b8c 6415 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
3f76745e 6416 break;
a3f97cbb 6417
3f76745e 6418 case dw_val_class_str:
9eb4015a
JJ
6419 if (AT_string_form (a) == DW_FORM_strp)
6420 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6421 a->dw_attr_val.v.val_str->label,
a4cf1d85 6422 "%s: \"%s\"", name, AT_string (a));
9eb4015a
JJ
6423 else
6424 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
3f76745e 6425 break;
b2932ae5 6426
3f76745e
JM
6427 default:
6428 abort ();
6429 }
3f76745e 6430 }
71dfc51f 6431
3f76745e
JM
6432 for (c = die->die_child; c != NULL; c = c->die_sib)
6433 output_die (c);
71dfc51f 6434
2ad9852d 6435 /* Add null byte to terminate sibling list. */
3f76745e 6436 if (die->die_child != NULL)
2ad9852d
RK
6437 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6438 die->die_offset);
3f76745e 6439}
71dfc51f 6440
3f76745e
JM
6441/* Output the compilation unit that appears at the beginning of the
6442 .debug_info section, and precedes the DIE descriptions. */
71dfc51f 6443
3f76745e
JM
6444static void
6445output_compilation_unit_header ()
6446{
2e4b9b8c
RH
6447 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6448 "Length of Compilation Unit Info");
2e4b9b8c 6449 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
2e4b9b8c
RH
6450 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6451 "Offset Into Abbrev. Section");
2e4b9b8c 6452 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
a3f97cbb
JW
6453}
6454
881c6935
JM
6455/* Output the compilation unit DIE and its children. */
6456
6457static void
6458output_comp_unit (die)
6459 dw_die_ref die;
6460{
ce1cc601 6461 const char *secname;
881c6935 6462
2ad9852d
RK
6463 /* Even if there are no children of this DIE, we must output the information
6464 about the compilation unit. Otherwise, on an empty translation unit, we
6465 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6466 will then complain when examining the file. First mark all the DIEs in
6467 this CU so we know which get local refs. */
1bfb5f8f
JM
6468 mark_dies (die);
6469
6470 build_abbrev_table (die);
6471
6d2f8887 6472 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
881c6935
JM
6473 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6474 calc_die_sizes (die);
6475
881c6935
JM
6476 if (die->die_symbol)
6477 {
ce1cc601 6478 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
2ad9852d 6479
ce1cc601
KG
6480 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6481 secname = tmp;
881c6935
JM
6482 die->die_symbol = NULL;
6483 }
6484 else
ce1cc601 6485 secname = (const char *) DEBUG_INFO_SECTION;
881c6935
JM
6486
6487 /* Output debugging information. */
715bdd29 6488 named_section_flags (secname, SECTION_DEBUG);
881c6935
JM
6489 output_compilation_unit_header ();
6490 output_die (die);
6491
1bfb5f8f
JM
6492 /* Leave the marks on the main CU, so we can check them in
6493 output_pubnames. */
881c6935 6494 if (die->die_symbol)
1bfb5f8f 6495 unmark_dies (die);
881c6935
JM
6496}
6497
7afff7cf
NB
6498/* The DWARF2 pubname for a nested thingy looks like "A::f". The
6499 output of lang_hooks.decl_printable_name for C++ looks like
6500 "A::f(int)". Let's drop the argument list, and maybe the scope. */
a1d7ffe3 6501
d560ee52 6502static const char *
a1d7ffe3
JM
6503dwarf2_name (decl, scope)
6504 tree decl;
6505 int scope;
6506{
7afff7cf 6507 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
a1d7ffe3
JM
6508}
6509
d291dd49 6510/* Add a new entry to .debug_pubnames if appropriate. */
71dfc51f 6511
d291dd49
JM
6512static void
6513add_pubname (decl, die)
6514 tree decl;
6515 dw_die_ref die;
6516{
6517 pubname_ref p;
6518
6519 if (! TREE_PUBLIC (decl))
6520 return;
6521
6522 if (pubname_table_in_use == pubname_table_allocated)
6523 {
6524 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
2ad9852d
RK
6525 pubname_table
6526 = (pubname_ref) xrealloc (pubname_table,
6527 (pubname_table_allocated
6528 * sizeof (pubname_entry)));
d291dd49 6529 }
71dfc51f 6530
d291dd49
JM
6531 p = &pubname_table[pubname_table_in_use++];
6532 p->die = die;
a1d7ffe3 6533 p->name = xstrdup (dwarf2_name (decl, 1));
d291dd49
JM
6534}
6535
a3f97cbb
JW
6536/* Output the public names table used to speed up access to externally
6537 visible names. For now, only generate entries for externally
6538 visible procedures. */
71dfc51f 6539
a3f97cbb
JW
6540static void
6541output_pubnames ()
6542{
b3694847
SS
6543 unsigned i;
6544 unsigned long pubnames_length = size_of_pubnames ();
71dfc51f 6545
2e4b9b8c
RH
6546 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6547 "Length of Public Names Info");
2e4b9b8c 6548 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
2e4b9b8c
RH
6549 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6550 "Offset of Compilation Unit Info");
2e4b9b8c
RH
6551 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6552 "Compilation Unit Length");
71dfc51f 6553
2ad9852d 6554 for (i = 0; i < pubname_table_in_use; i++)
a3f97cbb 6555 {
b3694847 6556 pubname_ref pub = &pubname_table[i];
71dfc51f 6557
881c6935 6558 /* We shouldn't see pubnames for DIEs outside of the main CU. */
1bfb5f8f 6559 if (pub->die->die_mark == 0)
881c6935
JM
6560 abort ();
6561
2e4b9b8c
RH
6562 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6563 "DIE offset");
71dfc51f 6564
2e4b9b8c 6565 dw2_asm_output_nstring (pub->name, -1, "external name");
a3f97cbb 6566 }
71dfc51f 6567
2e4b9b8c 6568 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
a3f97cbb
JW
6569}
6570
d291dd49 6571/* Add a new entry to .debug_aranges if appropriate. */
71dfc51f 6572
d291dd49
JM
6573static void
6574add_arange (decl, die)
6575 tree decl;
6576 dw_die_ref die;
6577{
6578 if (! DECL_SECTION_NAME (decl))
6579 return;
6580
6581 if (arange_table_in_use == arange_table_allocated)
6582 {
6583 arange_table_allocated += ARANGE_TABLE_INCREMENT;
a20612aa
RH
6584 arange_table = (dw_die_ref *)
6585 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
d291dd49 6586 }
71dfc51f 6587
d291dd49
JM
6588 arange_table[arange_table_in_use++] = die;
6589}
6590
a3f97cbb
JW
6591/* Output the information that goes into the .debug_aranges table.
6592 Namely, define the beginning and ending address range of the
6593 text section generated for this compilation unit. */
71dfc51f 6594
a3f97cbb
JW
6595static void
6596output_aranges ()
6597{
b3694847
SS
6598 unsigned i;
6599 unsigned long aranges_length = size_of_aranges ();
71dfc51f 6600
2e4b9b8c
RH
6601 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6602 "Length of Address Ranges Info");
2e4b9b8c 6603 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
2e4b9b8c
RH
6604 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6605 "Offset of Compilation Unit Info");
2e4b9b8c 6606 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
2e4b9b8c 6607 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
71dfc51f 6608
262b6384
SC
6609 /* We need to align to twice the pointer size here. */
6610 if (DWARF_ARANGES_PAD_SIZE)
6611 {
2e4b9b8c
RH
6612 /* Pad using a 2 byte words so that padding is correct for any
6613 pointer size. */
6614 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6615 2 * DWARF2_ADDR_SIZE);
770ca8c6 6616 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
2e4b9b8c 6617 dw2_asm_output_data (2, 0, NULL);
262b6384 6618 }
71dfc51f 6619
8e7fa2c8 6620 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
2e4b9b8c
RH
6621 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6622 text_section_label, "Length");
71dfc51f 6623
2ad9852d 6624 for (i = 0; i < arange_table_in_use; i++)
d291dd49 6625 {
e689ae67 6626 dw_die_ref die = arange_table[i];
71dfc51f 6627
881c6935 6628 /* We shouldn't see aranges for DIEs outside of the main CU. */
1bfb5f8f 6629 if (die->die_mark == 0)
881c6935
JM
6630 abort ();
6631
e689ae67 6632 if (die->die_tag == DW_TAG_subprogram)
2e4b9b8c 6633 {
8e7fa2c8 6634 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
173bf5be 6635 "Address");
2e4b9b8c
RH
6636 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6637 get_AT_low_pc (die), "Length");
6638 }
d291dd49 6639 else
a1d7ffe3 6640 {
e689ae67
JM
6641 /* A static variable; extract the symbol from DW_AT_location.
6642 Note that this code isn't currently hit, as we only emit
6643 aranges for functions (jason 9/23/99). */
e689ae67
JM
6644 dw_attr_ref a = get_AT (die, DW_AT_location);
6645 dw_loc_descr_ref loc;
2ad9852d 6646
a96c67ec 6647 if (! a || AT_class (a) != dw_val_class_loc)
e689ae67
JM
6648 abort ();
6649
a96c67ec 6650 loc = AT_loc (a);
e689ae67
JM
6651 if (loc->dw_loc_opc != DW_OP_addr)
6652 abort ();
6653
2e4b9b8c
RH
6654 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6655 loc->dw_loc_oprnd1.v.val_addr, "Address");
6656 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6657 get_AT_unsigned (die, DW_AT_byte_size),
6658 "Length");
a1d7ffe3 6659 }
d291dd49 6660 }
71dfc51f 6661
a3f97cbb 6662 /* Output the terminator words. */
2e4b9b8c
RH
6663 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6664 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
a3f97cbb
JW
6665}
6666
a20612aa
RH
6667/* Add a new entry to .debug_ranges. Return the offset at which it
6668 was placed. */
6669
6670static unsigned int
6671add_ranges (block)
6672 tree block;
6673{
6674 unsigned int in_use = ranges_table_in_use;
6675
6676 if (in_use == ranges_table_allocated)
6677 {
6678 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6679 ranges_table = (dw_ranges_ref)
6680 xrealloc (ranges_table, (ranges_table_allocated
6681 * sizeof (struct dw_ranges_struct)));
6682 }
6683
6684 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6685 ranges_table_in_use = in_use + 1;
6686
6687 return in_use * 2 * DWARF2_ADDR_SIZE;
6688}
6689
6690static void
6691output_ranges ()
6692{
b3694847 6693 unsigned i;
83182544 6694 static const char *const start_fmt = "Offset 0x%x";
a20612aa
RH
6695 const char *fmt = start_fmt;
6696
2ad9852d 6697 for (i = 0; i < ranges_table_in_use; i++)
a20612aa
RH
6698 {
6699 int block_num = ranges_table[i].block_num;
6700
6701 if (block_num)
6702 {
6703 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6704 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6705
6706 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6707 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6708
6709 /* If all code is in the text section, then the compilation
6710 unit base address defaults to DW_AT_low_pc, which is the
6711 base of the text section. */
6712 if (separate_line_info_table_in_use == 0)
6713 {
6714 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6715 text_section_label,
6716 fmt, i * 2 * DWARF2_ADDR_SIZE);
6717 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6718 text_section_label, NULL);
6719 }
2ad9852d 6720
a20612aa
RH
6721 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6722 compilation unit base address to zero, which allows us to
6723 use absolute addresses, and not worry about whether the
6724 target supports cross-section arithmetic. */
6725 else
6726 {
6727 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6728 fmt, i * 2 * DWARF2_ADDR_SIZE);
6729 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6730 }
6731
6732 fmt = NULL;
6733 }
6734 else
6735 {
6736 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6737 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6738 fmt = start_fmt;
6739 }
6740 }
6741}
0b34cf1e
UD
6742
6743/* Data structure containing information about input files. */
6744struct file_info
6745{
6746 char *path; /* Complete file name. */
6747 char *fname; /* File name part. */
6748 int length; /* Length of entire string. */
6749 int file_idx; /* Index in input file table. */
6750 int dir_idx; /* Index in directory table. */
6751};
6752
6753/* Data structure containing information about directories with source
6754 files. */
6755struct dir_info
6756{
6757 char *path; /* Path including directory name. */
6758 int length; /* Path length. */
6759 int prefix; /* Index of directory entry which is a prefix. */
0b34cf1e
UD
6760 int count; /* Number of files in this directory. */
6761 int dir_idx; /* Index of directory used as base. */
6762 int used; /* Used in the end? */
6763};
6764
6765/* Callback function for file_info comparison. We sort by looking at
6766 the directories in the path. */
356b0698 6767
0b34cf1e
UD
6768static int
6769file_info_cmp (p1, p2)
6770 const void *p1;
6771 const void *p2;
6772{
6773 const struct file_info *s1 = p1;
6774 const struct file_info *s2 = p2;
6775 unsigned char *cp1;
6776 unsigned char *cp2;
6777
356b0698
RK
6778 /* Take care of file names without directories. We need to make sure that
6779 we return consistent values to qsort since some will get confused if
6780 we return the same value when identical operands are passed in opposite
6781 orders. So if neither has a directory, return 0 and otherwise return
6782 1 or -1 depending on which one has the directory. */
6783 if ((s1->path == s1->fname || s2->path == s2->fname))
6784 return (s2->path == s2->fname) - (s1->path == s1->fname);
0b34cf1e
UD
6785
6786 cp1 = (unsigned char *) s1->path;
6787 cp2 = (unsigned char *) s2->path;
6788
6789 while (1)
6790 {
6791 ++cp1;
6792 ++cp2;
356b0698
RK
6793 /* Reached the end of the first path? If so, handle like above. */
6794 if ((cp1 == (unsigned char *) s1->fname)
6795 || (cp2 == (unsigned char *) s2->fname))
6796 return ((cp2 == (unsigned char *) s2->fname)
6797 - (cp1 == (unsigned char *) s1->fname));
0b34cf1e
UD
6798
6799 /* Character of current path component the same? */
356b0698 6800 else if (*cp1 != *cp2)
0b34cf1e
UD
6801 return *cp1 - *cp2;
6802 }
6803}
6804
6805/* Output the directory table and the file name table. We try to minimize
6806 the total amount of memory needed. A heuristic is used to avoid large
6807 slowdowns with many input files. */
2ad9852d 6808
0b34cf1e
UD
6809static void
6810output_file_names ()
6811{
6812 struct file_info *files;
6813 struct dir_info *dirs;
6814 int *saved;
6815 int *savehere;
6816 int *backmap;
6817 int ndirs;
6818 int idx_offset;
6819 int i;
6820 int idx;
6821
6822 /* Allocate the various arrays we need. */
981975b6 6823 files = (struct file_info *) alloca (file_table.in_use
0b34cf1e 6824 * sizeof (struct file_info));
981975b6 6825 dirs = (struct dir_info *) alloca (file_table.in_use
0b34cf1e
UD
6826 * sizeof (struct dir_info));
6827
6828 /* Sort the file names. */
2ad9852d 6829 for (i = 1; i < (int) file_table.in_use; i++)
0b34cf1e
UD
6830 {
6831 char *f;
6832
6833 /* Skip all leading "./". */
981975b6 6834 f = file_table.table[i];
0b34cf1e
UD
6835 while (f[0] == '.' && f[1] == '/')
6836 f += 2;
6837
6838 /* Create a new array entry. */
6839 files[i].path = f;
6840 files[i].length = strlen (f);
6841 files[i].file_idx = i;
6842
6843 /* Search for the file name part. */
6844 f = strrchr (f, '/');
6845 files[i].fname = f == NULL ? files[i].path : f + 1;
6846 }
2ad9852d 6847
981975b6 6848 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
0b34cf1e
UD
6849
6850 /* Find all the different directories used. */
6851 dirs[0].path = files[1].path;
6852 dirs[0].length = files[1].fname - files[1].path;
6853 dirs[0].prefix = -1;
0b34cf1e
UD
6854 dirs[0].count = 1;
6855 dirs[0].dir_idx = 0;
6856 dirs[0].used = 0;
6857 files[1].dir_idx = 0;
6858 ndirs = 1;
6859
2ad9852d 6860 for (i = 2; i < (int) file_table.in_use; i++)
0b34cf1e
UD
6861 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6862 && memcmp (dirs[ndirs - 1].path, files[i].path,
6863 dirs[ndirs - 1].length) == 0)
6864 {
6865 /* Same directory as last entry. */
6866 files[i].dir_idx = ndirs - 1;
0b34cf1e
UD
6867 ++dirs[ndirs - 1].count;
6868 }
6869 else
6870 {
6871 int j;
6872
6873 /* This is a new directory. */
6874 dirs[ndirs].path = files[i].path;
6875 dirs[ndirs].length = files[i].fname - files[i].path;
0b34cf1e
UD
6876 dirs[ndirs].count = 1;
6877 dirs[ndirs].dir_idx = ndirs;
6878 dirs[ndirs].used = 0;
6879 files[i].dir_idx = ndirs;
6880
6881 /* Search for a prefix. */
981975b6 6882 dirs[ndirs].prefix = -1;
2ad9852d 6883 for (j = 0; j < ndirs; j++)
981975b6
RH
6884 if (dirs[j].length < dirs[ndirs].length
6885 && dirs[j].length > 1
6886 && (dirs[ndirs].prefix == -1
6887 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6888 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6889 dirs[ndirs].prefix = j;
0b34cf1e
UD
6890
6891 ++ndirs;
6892 }
6893
2ad9852d
RK
6894 /* Now to the actual work. We have to find a subset of the directories which
6895 allow expressing the file name using references to the directory table
6896 with the least amount of characters. We do not do an exhaustive search
6897 where we would have to check out every combination of every single
6898 possible prefix. Instead we use a heuristic which provides nearly optimal
6899 results in most cases and never is much off. */
0b34cf1e
UD
6900 saved = (int *) alloca (ndirs * sizeof (int));
6901 savehere = (int *) alloca (ndirs * sizeof (int));
6902
6903 memset (saved, '\0', ndirs * sizeof (saved[0]));
2ad9852d 6904 for (i = 0; i < ndirs; i++)
0b34cf1e
UD
6905 {
6906 int j;
6907 int total;
6908
2ad9852d
RK
6909 /* We can always save some space for the current directory. But this
6910 does not mean it will be enough to justify adding the directory. */
0b34cf1e
UD
6911 savehere[i] = dirs[i].length;
6912 total = (savehere[i] - saved[i]) * dirs[i].count;
6913
2ad9852d 6914 for (j = i + 1; j < ndirs; j++)
0b34cf1e
UD
6915 {
6916 savehere[j] = 0;
0b34cf1e
UD
6917 if (saved[j] < dirs[i].length)
6918 {
6919 /* Determine whether the dirs[i] path is a prefix of the
6920 dirs[j] path. */
6921 int k;
6922
981975b6
RH
6923 k = dirs[j].prefix;
6924 while (k != -1 && k != i)
6925 k = dirs[k].prefix;
6926
6927 if (k == i)
6928 {
6929 /* Yes it is. We can possibly safe some memory but
6930 writing the filenames in dirs[j] relative to
6931 dirs[i]. */
6932 savehere[j] = dirs[i].length;
6933 total += (savehere[j] - saved[j]) * dirs[j].count;
6934 }
0b34cf1e
UD
6935 }
6936 }
6937
6938 /* Check whether we can safe enough to justify adding the dirs[i]
6939 directory. */
6940 if (total > dirs[i].length + 1)
6941 {
981975b6 6942 /* It's worthwhile adding. */
c26fbbca 6943 for (j = i; j < ndirs; j++)
0b34cf1e
UD
6944 if (savehere[j] > 0)
6945 {
6946 /* Remember how much we saved for this directory so far. */
6947 saved[j] = savehere[j];
6948
6949 /* Remember the prefix directory. */
6950 dirs[j].dir_idx = i;
6951 }
6952 }
6953 }
6954
2ad9852d
RK
6955 /* We have to emit them in the order they appear in the file_table array
6956 since the index is used in the debug info generation. To do this
6957 efficiently we generate a back-mapping of the indices first. */
981975b6 6958 backmap = (int *) alloca (file_table.in_use * sizeof (int));
2ad9852d 6959 for (i = 1; i < (int) file_table.in_use; i++)
0b34cf1e
UD
6960 {
6961 backmap[files[i].file_idx] = i;
2ad9852d 6962
0b34cf1e
UD
6963 /* Mark this directory as used. */
6964 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6965 }
6966
2ad9852d
RK
6967 /* That was it. We are ready to emit the information. First emit the
6968 directory name table. We have to make sure the first actually emitted
6969 directory name has index one; zero is reserved for the current working
6970 directory. Make sure we do not confuse these indices with the one for the
6971 constructed table (even though most of the time they are identical). */
0b34cf1e 6972 idx = 1;
e57cabac 6973 idx_offset = dirs[0].length > 0 ? 1 : 0;
2ad9852d 6974 for (i = 1 - idx_offset; i < ndirs; i++)
0b34cf1e
UD
6975 if (dirs[i].used != 0)
6976 {
6977 dirs[i].used = idx++;
2e4b9b8c
RH
6978 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6979 "Directory Entry: 0x%x", dirs[i].used);
0b34cf1e 6980 }
2ad9852d 6981
2e4b9b8c
RH
6982 dw2_asm_output_data (1, 0, "End directory table");
6983
0b34cf1e
UD
6984 /* Correct the index for the current working directory entry if it
6985 exists. */
6986 if (idx_offset == 0)
6987 dirs[0].used = 0;
0b34cf1e
UD
6988
6989 /* Now write all the file names. */
2ad9852d 6990 for (i = 1; i < (int) file_table.in_use; i++)
0b34cf1e
UD
6991 {
6992 int file_idx = backmap[i];
6993 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6994
2e4b9b8c
RH
6995 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6996 "File Entry: 0x%x", i);
0b34cf1e
UD
6997
6998 /* Include directory index. */
2e4b9b8c 6999 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
0b34cf1e
UD
7000
7001 /* Modification time. */
2e4b9b8c 7002 dw2_asm_output_data_uleb128 (0, NULL);
0b34cf1e
UD
7003
7004 /* File length in bytes. */
2e4b9b8c 7005 dw2_asm_output_data_uleb128 (0, NULL);
0b34cf1e 7006 }
2ad9852d 7007
2e4b9b8c 7008 dw2_asm_output_data (1, 0, "End file name table");
0b34cf1e
UD
7009}
7010
7011
a3f97cbb 7012/* Output the source line number correspondence information. This
14a774a9 7013 information goes into the .debug_line section. */
71dfc51f 7014
a3f97cbb
JW
7015static void
7016output_line_info ()
7017{
981975b6 7018 char l1[20], l2[20], p1[20], p2[20];
a3f97cbb
JW
7019 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7020 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
b3694847
SS
7021 unsigned opc;
7022 unsigned n_op_args;
7023 unsigned long lt_index;
7024 unsigned long current_line;
7025 long line_offset;
7026 long line_delta;
7027 unsigned long current_file;
7028 unsigned long function;
71dfc51f 7029
2e4b9b8c
RH
7030 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7031 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
981975b6
RH
7032 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7033 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
71dfc51f 7034
2e4b9b8c
RH
7035 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7036 "Length of Source Line Info");
7037 ASM_OUTPUT_LABEL (asm_out_file, l1);
71dfc51f 7038
2e4b9b8c 7039 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
981975b6
RH
7040 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7041 ASM_OUTPUT_LABEL (asm_out_file, p1);
71dfc51f 7042
c1a046e5
TT
7043 /* Define the architecture-dependent minimum instruction length (in
7044 bytes). In this implementation of DWARF, this field is used for
7045 information purposes only. Since GCC generates assembly language,
7046 we have no a priori knowledge of how many instruction bytes are
7047 generated for each source line, and therefore can use only the
7048 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7049 commands. Accordingly, we fix this as `1', which is "correct
7050 enough" for all architectures, and don't let the target override. */
7051 dw2_asm_output_data (1, 1,
2e4b9b8c 7052 "Minimum Instruction Length");
c1a046e5 7053
2e4b9b8c
RH
7054 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7055 "Default is_stmt_start flag");
2e4b9b8c
RH
7056 dw2_asm_output_data (1, DWARF_LINE_BASE,
7057 "Line Base Value (Special Opcodes)");
2e4b9b8c
RH
7058 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7059 "Line Range Value (Special Opcodes)");
2e4b9b8c
RH
7060 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7061 "Special Opcode Base");
71dfc51f 7062
2ad9852d 7063 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
a3f97cbb
JW
7064 {
7065 switch (opc)
7066 {
7067 case DW_LNS_advance_pc:
7068 case DW_LNS_advance_line:
7069 case DW_LNS_set_file:
7070 case DW_LNS_set_column:
7071 case DW_LNS_fixed_advance_pc:
7072 n_op_args = 1;
7073 break;
7074 default:
7075 n_op_args = 0;
7076 break;
7077 }
2e4b9b8c
RH
7078
7079 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7080 opc, n_op_args);
a3f97cbb 7081 }
71dfc51f 7082
0b34cf1e
UD
7083 /* Write out the information about the files we use. */
7084 output_file_names ();
981975b6 7085 ASM_OUTPUT_LABEL (asm_out_file, p2);
a3f97cbb 7086
2f22d404
JM
7087 /* We used to set the address register to the first location in the text
7088 section here, but that didn't accomplish anything since we already
7089 have a line note for the opening brace of the first function. */
a3f97cbb
JW
7090
7091 /* Generate the line number to PC correspondence table, encoded as
7092 a series of state machine operations. */
7093 current_file = 1;
7094 current_line = 1;
8b790721 7095 strcpy (prev_line_label, text_section_label);
a3f97cbb
JW
7096 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7097 {
b3694847 7098 dw_line_info_ref line_info = &line_info_table[lt_index];
2f22d404 7099
10a11b75
JM
7100#if 0
7101 /* Disable this optimization for now; GDB wants to see two line notes
7102 at the beginning of a function so it can find the end of the
7103 prologue. */
7104
2f22d404
JM
7105 /* Don't emit anything for redundant notes. Just updating the
7106 address doesn't accomplish anything, because we already assume
7107 that anything after the last address is this line. */
7108 if (line_info->dw_line_num == current_line
7109 && line_info->dw_file_num == current_file)
7110 continue;
10a11b75 7111#endif
71dfc51f 7112
2e4b9b8c
RH
7113 /* Emit debug info for the address of the current line.
7114
7115 Unfortunately, we have little choice here currently, and must always
2ad9852d 7116 use the most general form. GCC does not know the address delta
2e4b9b8c
RH
7117 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7118 attributes which will give an upper bound on the address range. We
7119 could perhaps use length attributes to determine when it is safe to
7120 use DW_LNS_fixed_advance_pc. */
7121
5c90448c 7122 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
f19a6894
JW
7123 if (0)
7124 {
7125 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
2e4b9b8c
RH
7126 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7127 "DW_LNS_fixed_advance_pc");
7128 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
f19a6894
JW
7129 }
7130 else
7131 {
a1a4189d
JB
7132 /* This can handle any delta. This takes
7133 4+DWARF2_ADDR_SIZE bytes. */
2e4b9b8c
RH
7134 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7135 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7136 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8e7fa2c8 7137 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
f19a6894 7138 }
2ad9852d 7139
f19a6894
JW
7140 strcpy (prev_line_label, line_label);
7141
7142 /* Emit debug info for the source file of the current line, if
7143 different from the previous line. */
a3f97cbb
JW
7144 if (line_info->dw_file_num != current_file)
7145 {
7146 current_file = line_info->dw_file_num;
2e4b9b8c
RH
7147 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7148 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
981975b6 7149 file_table.table[current_file]);
a3f97cbb 7150 }
71dfc51f 7151
f19a6894
JW
7152 /* Emit debug info for the current line number, choosing the encoding
7153 that uses the least amount of space. */
2f22d404 7154 if (line_info->dw_line_num != current_line)
a3f97cbb 7155 {
2f22d404
JM
7156 line_offset = line_info->dw_line_num - current_line;
7157 line_delta = line_offset - DWARF_LINE_BASE;
7158 current_line = line_info->dw_line_num;
7159 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
2ad9852d
RK
7160 /* This can handle deltas from -10 to 234, using the current
7161 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7162 takes 1 byte. */
7163 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7164 "line %lu", current_line);
2f22d404
JM
7165 else
7166 {
7167 /* This can handle any delta. This takes at least 4 bytes,
7168 depending on the value being encoded. */
2e4b9b8c
RH
7169 dw2_asm_output_data (1, DW_LNS_advance_line,
7170 "advance to line %lu", current_line);
7171 dw2_asm_output_data_sleb128 (line_offset, NULL);
7172 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
2f22d404 7173 }
a94dbf2c
JM
7174 }
7175 else
2ad9852d
RK
7176 /* We still need to start a new row, so output a copy insn. */
7177 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
a3f97cbb
JW
7178 }
7179
f19a6894
JW
7180 /* Emit debug info for the address of the end of the function. */
7181 if (0)
7182 {
2e4b9b8c
RH
7183 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7184 "DW_LNS_fixed_advance_pc");
7185 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
f19a6894
JW
7186 }
7187 else
7188 {
2e4b9b8c
RH
7189 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7190 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7191 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8e7fa2c8 7192 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
f19a6894 7193 }
bdb669cb 7194
2e4b9b8c
RH
7195 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7196 dw2_asm_output_data_uleb128 (1, NULL);
7197 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
e90b62db
JM
7198
7199 function = 0;
7200 current_file = 1;
7201 current_line = 1;
556273e0 7202 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
e90b62db 7203 {
b3694847 7204 dw_separate_line_info_ref line_info
e90b62db 7205 = &separate_line_info_table[lt_index];
71dfc51f 7206
10a11b75 7207#if 0
2f22d404
JM
7208 /* Don't emit anything for redundant notes. */
7209 if (line_info->dw_line_num == current_line
7210 && line_info->dw_file_num == current_file
7211 && line_info->function == function)
7212 goto cont;
10a11b75 7213#endif
2f22d404 7214
f19a6894
JW
7215 /* Emit debug info for the address of the current line. If this is
7216 a new function, or the first line of a function, then we need
7217 to handle it differently. */
5c90448c
JM
7218 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7219 lt_index);
e90b62db
JM
7220 if (function != line_info->function)
7221 {
7222 function = line_info->function;
71dfc51f 7223
e90b62db 7224 /* Set the address register to the first line in the function */
2e4b9b8c
RH
7225 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7226 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7227 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8e7fa2c8 7228 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
e90b62db
JM
7229 }
7230 else
7231 {
f19a6894
JW
7232 /* ??? See the DW_LNS_advance_pc comment above. */
7233 if (0)
7234 {
2e4b9b8c
RH
7235 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7236 "DW_LNS_fixed_advance_pc");
7237 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
f19a6894
JW
7238 }
7239 else
7240 {
2e4b9b8c
RH
7241 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7242 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7243 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8e7fa2c8 7244 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
f19a6894 7245 }
e90b62db 7246 }
2ad9852d 7247
f19a6894 7248 strcpy (prev_line_label, line_label);
71dfc51f 7249
f19a6894
JW
7250 /* Emit debug info for the source file of the current line, if
7251 different from the previous line. */
e90b62db
JM
7252 if (line_info->dw_file_num != current_file)
7253 {
7254 current_file = line_info->dw_file_num;
2e4b9b8c
RH
7255 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7256 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
981975b6 7257 file_table.table[current_file]);
e90b62db 7258 }
71dfc51f 7259
f19a6894
JW
7260 /* Emit debug info for the current line number, choosing the encoding
7261 that uses the least amount of space. */
e90b62db
JM
7262 if (line_info->dw_line_num != current_line)
7263 {
7264 line_offset = line_info->dw_line_num - current_line;
7265 line_delta = line_offset - DWARF_LINE_BASE;
7266 current_line = line_info->dw_line_num;
7267 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
2e4b9b8c
RH
7268 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7269 "line %lu", current_line);
e90b62db
JM
7270 else
7271 {
2e4b9b8c
RH
7272 dw2_asm_output_data (1, DW_LNS_advance_line,
7273 "advance to line %lu", current_line);
7274 dw2_asm_output_data_sleb128 (line_offset, NULL);
7275 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
e90b62db
JM
7276 }
7277 }
2f22d404 7278 else
2e4b9b8c 7279 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
71dfc51f 7280
10a11b75 7281#if 0
2f22d404 7282 cont:
10a11b75 7283#endif
2ad9852d
RK
7284
7285 lt_index++;
e90b62db
JM
7286
7287 /* If we're done with a function, end its sequence. */
7288 if (lt_index == separate_line_info_table_in_use
7289 || separate_line_info_table[lt_index].function != function)
7290 {
7291 current_file = 1;
7292 current_line = 1;
71dfc51f 7293
f19a6894 7294 /* Emit debug info for the address of the end of the function. */
5c90448c 7295 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
f19a6894
JW
7296 if (0)
7297 {
2e4b9b8c
RH
7298 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7299 "DW_LNS_fixed_advance_pc");
7300 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
f19a6894
JW
7301 }
7302 else
7303 {
2e4b9b8c
RH
7304 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7305 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7306 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8e7fa2c8 7307 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
f19a6894 7308 }
e90b62db
JM
7309
7310 /* Output the marker for the end of this sequence. */
2e4b9b8c
RH
7311 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7312 dw2_asm_output_data_uleb128 (1, NULL);
7313 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
e90b62db
JM
7314 }
7315 }
f19f17e0
JM
7316
7317 /* Output the marker for the end of the line number info. */
2e4b9b8c 7318 ASM_OUTPUT_LABEL (asm_out_file, l2);
a3f97cbb
JW
7319}
7320\f
a3f97cbb
JW
7321/* Given a pointer to a tree node for some base type, return a pointer to
7322 a DIE that describes the given type.
7323
7324 This routine must only be called for GCC type nodes that correspond to
7325 Dwarf base (fundamental) types. */
71dfc51f 7326
a3f97cbb
JW
7327static dw_die_ref
7328base_type_die (type)
b3694847 7329 tree type;
a3f97cbb 7330{
b3694847
SS
7331 dw_die_ref base_type_result;
7332 const char *type_name;
7333 enum dwarf_type encoding;
7334 tree name = TYPE_NAME (type);
a3f97cbb 7335
2ad9852d 7336 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
a3f97cbb
JW
7337 return 0;
7338
405f63da
MM
7339 if (name)
7340 {
7341 if (TREE_CODE (name) == TYPE_DECL)
7342 name = DECL_NAME (name);
7343
7344 type_name = IDENTIFIER_POINTER (name);
7345 }
7346 else
7347 type_name = "__unknown__";
a9d38797 7348
a3f97cbb
JW
7349 switch (TREE_CODE (type))
7350 {
a3f97cbb 7351 case INTEGER_TYPE:
a9d38797 7352 /* Carefully distinguish the C character types, without messing
a3f97cbb 7353 up if the language is not C. Note that we check only for the names
556273e0 7354 that contain spaces; other names might occur by coincidence in other
a3f97cbb 7355 languages. */
a9d38797
JM
7356 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7357 && (type == char_type_node
7358 || ! strcmp (type_name, "signed char")
7359 || ! strcmp (type_name, "unsigned char"))))
a3f97cbb 7360 {
a9d38797
JM
7361 if (TREE_UNSIGNED (type))
7362 encoding = DW_ATE_unsigned;
7363 else
7364 encoding = DW_ATE_signed;
7365 break;
a3f97cbb 7366 }
556273e0 7367 /* else fall through. */
a3f97cbb 7368
a9d38797
JM
7369 case CHAR_TYPE:
7370 /* GNU Pascal/Ada CHAR type. Not used in C. */
7371 if (TREE_UNSIGNED (type))
7372 encoding = DW_ATE_unsigned_char;
7373 else
7374 encoding = DW_ATE_signed_char;
a3f97cbb
JW
7375 break;
7376
7377 case REAL_TYPE:
a9d38797 7378 encoding = DW_ATE_float;
a3f97cbb
JW
7379 break;
7380
405f63da
MM
7381 /* Dwarf2 doesn't know anything about complex ints, so use
7382 a user defined type for it. */
a3f97cbb 7383 case COMPLEX_TYPE:
405f63da
MM
7384 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7385 encoding = DW_ATE_complex_float;
7386 else
7387 encoding = DW_ATE_lo_user;
a3f97cbb
JW
7388 break;
7389
7390 case BOOLEAN_TYPE:
a9d38797
JM
7391 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7392 encoding = DW_ATE_boolean;
a3f97cbb
JW
7393 break;
7394
7395 default:
2ad9852d
RK
7396 /* No other TREE_CODEs are Dwarf fundamental types. */
7397 abort ();
a3f97cbb
JW
7398 }
7399
54ba1f0d 7400 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
14a774a9
RK
7401 if (demangle_name_func)
7402 type_name = (*demangle_name_func) (type_name);
7403
a9d38797
JM
7404 add_AT_string (base_type_result, DW_AT_name, type_name);
7405 add_AT_unsigned (base_type_result, DW_AT_byte_size,
4e5a8d7b 7406 int_size_in_bytes (type));
a9d38797 7407 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
a3f97cbb
JW
7408
7409 return base_type_result;
7410}
7411
7412/* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7413 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7414 a given type is generally the same as the given type, except that if the
7415 given type is a pointer or reference type, then the root type of the given
7416 type is the root type of the "basis" type for the pointer or reference
7417 type. (This definition of the "root" type is recursive.) Also, the root
7418 type of a `const' qualified type or a `volatile' qualified type is the
7419 root type of the given type without the qualifiers. */
71dfc51f 7420
a3f97cbb
JW
7421static tree
7422root_type (type)
b3694847 7423 tree type;
a3f97cbb
JW
7424{
7425 if (TREE_CODE (type) == ERROR_MARK)
7426 return error_mark_node;
7427
7428 switch (TREE_CODE (type))
7429 {
7430 case ERROR_MARK:
7431 return error_mark_node;
7432
7433 case POINTER_TYPE:
7434 case REFERENCE_TYPE:
7435 return type_main_variant (root_type (TREE_TYPE (type)));
7436
7437 default:
7438 return type_main_variant (type);
7439 }
7440}
7441
cc2902df 7442/* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
a3f97cbb 7443 given input type is a Dwarf "fundamental" type. Otherwise return null. */
71dfc51f
RK
7444
7445static inline int
a3f97cbb 7446is_base_type (type)
b3694847 7447 tree type;
a3f97cbb
JW
7448{
7449 switch (TREE_CODE (type))
7450 {
7451 case ERROR_MARK:
7452 case VOID_TYPE:
7453 case INTEGER_TYPE:
7454 case REAL_TYPE:
7455 case COMPLEX_TYPE:
7456 case BOOLEAN_TYPE:
7457 case CHAR_TYPE:
7458 return 1;
7459
7460 case SET_TYPE:
7461 case ARRAY_TYPE:
7462 case RECORD_TYPE:
7463 case UNION_TYPE:
7464 case QUAL_UNION_TYPE:
7465 case ENUMERAL_TYPE:
7466 case FUNCTION_TYPE:
7467 case METHOD_TYPE:
7468 case POINTER_TYPE:
7469 case REFERENCE_TYPE:
7470 case FILE_TYPE:
7471 case OFFSET_TYPE:
7472 case LANG_TYPE:
604bb87d 7473 case VECTOR_TYPE:
a3f97cbb
JW
7474 return 0;
7475
7476 default:
7477 abort ();
7478 }
71dfc51f 7479
a3f97cbb
JW
7480 return 0;
7481}
7482
7483/* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7484 entry that chains various modifiers in front of the given type. */
71dfc51f 7485
a3f97cbb
JW
7486static dw_die_ref
7487modified_type_die (type, is_const_type, is_volatile_type, context_die)
b3694847
SS
7488 tree type;
7489 int is_const_type;
7490 int is_volatile_type;
7491 dw_die_ref context_die;
a3f97cbb 7492{
b3694847
SS
7493 enum tree_code code = TREE_CODE (type);
7494 dw_die_ref mod_type_die = NULL;
7495 dw_die_ref sub_die = NULL;
7496 tree item_type = NULL;
a3f97cbb
JW
7497
7498 if (code != ERROR_MARK)
7499 {
5101b304
MM
7500 tree qualified_type;
7501
7502 /* See if we already have the appropriately qualified variant of
7503 this type. */
c26fbbca 7504 qualified_type
5101b304
MM
7505 = get_qualified_type (type,
7506 ((is_const_type ? TYPE_QUAL_CONST : 0)
c26fbbca 7507 | (is_volatile_type
5101b304 7508 ? TYPE_QUAL_VOLATILE : 0)));
2ad9852d 7509
5101b304
MM
7510 /* If we do, then we can just use its DIE, if it exists. */
7511 if (qualified_type)
7512 {
7513 mod_type_die = lookup_type_die (qualified_type);
7514 if (mod_type_die)
7515 return mod_type_die;
7516 }
bdb669cb 7517
556273e0 7518 /* Handle C typedef types. */
c26fbbca 7519 if (qualified_type && TYPE_NAME (qualified_type)
5101b304
MM
7520 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7521 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
a94dbf2c 7522 {
5101b304
MM
7523 tree type_name = TYPE_NAME (qualified_type);
7524 tree dtype = TREE_TYPE (type_name);
2ad9852d 7525
5101b304 7526 if (qualified_type == dtype)
a94dbf2c
JM
7527 {
7528 /* For a named type, use the typedef. */
5101b304
MM
7529 gen_type_die (qualified_type, context_die);
7530 mod_type_die = lookup_type_die (qualified_type);
a94dbf2c
JM
7531 }
7532 else if (is_const_type < TYPE_READONLY (dtype)
7533 || is_volatile_type < TYPE_VOLATILE (dtype))
7534 /* cv-unqualified version of named type. Just use the unnamed
7535 type to which it refers. */
71dfc51f 7536 mod_type_die
5101b304 7537 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
71dfc51f
RK
7538 is_const_type, is_volatile_type,
7539 context_die);
2ad9852d 7540
71dfc51f 7541 /* Else cv-qualified version of named type; fall through. */
a94dbf2c
JM
7542 }
7543
7544 if (mod_type_die)
556273e0
KH
7545 /* OK. */
7546 ;
a94dbf2c 7547 else if (is_const_type)
a3f97cbb 7548 {
54ba1f0d 7549 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
a9d38797 7550 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
a3f97cbb
JW
7551 }
7552 else if (is_volatile_type)
7553 {
54ba1f0d 7554 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
a9d38797 7555 sub_die = modified_type_die (type, 0, 0, context_die);
a3f97cbb
JW
7556 }
7557 else if (code == POINTER_TYPE)
7558 {
54ba1f0d 7559 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
a3f97cbb 7560 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
61b32c02 7561#if 0
a3f97cbb 7562 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
61b32c02 7563#endif
a3f97cbb 7564 item_type = TREE_TYPE (type);
a3f97cbb
JW
7565 }
7566 else if (code == REFERENCE_TYPE)
7567 {
54ba1f0d 7568 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
a3f97cbb 7569 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
61b32c02 7570#if 0
a3f97cbb 7571 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
556273e0 7572#endif
a3f97cbb 7573 item_type = TREE_TYPE (type);
a3f97cbb
JW
7574 }
7575 else if (is_base_type (type))
71dfc51f 7576 mod_type_die = base_type_die (type);
a3f97cbb
JW
7577 else
7578 {
4b674448
JM
7579 gen_type_die (type, context_die);
7580
a3f97cbb
JW
7581 /* We have to get the type_main_variant here (and pass that to the
7582 `lookup_type_die' routine) because the ..._TYPE node we have
7583 might simply be a *copy* of some original type node (where the
7584 copy was created to help us keep track of typedef names) and
7585 that copy might have a different TYPE_UID from the original
a94dbf2c 7586 ..._TYPE node. */
0e98f924
AH
7587 if (TREE_CODE (type) != VECTOR_TYPE)
7588 mod_type_die = lookup_type_die (type_main_variant (type));
7589 else
7590 /* Vectors have the debugging information in the type,
7591 not the main variant. */
7592 mod_type_die = lookup_type_die (type);
3a88cbd1
JL
7593 if (mod_type_die == NULL)
7594 abort ();
a3f97cbb 7595 }
3d2999ba
MK
7596
7597 /* We want to equate the qualified type to the die below. */
8370aa3a 7598 type = qualified_type;
a3f97cbb 7599 }
71dfc51f 7600
8370aa3a
RH
7601 if (type)
7602 equate_type_number_to_die (type, mod_type_die);
dfcf9891 7603 if (item_type)
71dfc51f
RK
7604 /* We must do this after the equate_type_number_to_die call, in case
7605 this is a recursive type. This ensures that the modified_type_die
7606 recursion will terminate even if the type is recursive. Recursive
7607 types are possible in Ada. */
7608 sub_die = modified_type_die (item_type,
7609 TYPE_READONLY (item_type),
7610 TYPE_VOLATILE (item_type),
7611 context_die);
7612
a3f97cbb 7613 if (sub_die != NULL)
71dfc51f
RK
7614 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7615
a3f97cbb
JW
7616 return mod_type_die;
7617}
7618
a3f97cbb 7619/* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6d2f8887 7620 an enumerated type. */
71dfc51f
RK
7621
7622static inline int
a3f97cbb 7623type_is_enum (type)
b3694847 7624 tree type;
a3f97cbb
JW
7625{
7626 return TREE_CODE (type) == ENUMERAL_TYPE;
7627}
7628
7d9d8943
AM
7629/* Return the register number described by a given RTL node. */
7630
7631static unsigned int
7632reg_number (rtl)
b3694847 7633 rtx rtl;
7d9d8943 7634{
b3694847 7635 unsigned regno = REGNO (rtl);
7d9d8943
AM
7636
7637 if (regno >= FIRST_PSEUDO_REGISTER)
e7af1d45 7638 abort ();
7d9d8943 7639
e7af1d45 7640 return DBX_REGISTER_NUMBER (regno);
7d9d8943
AM
7641}
7642
e7af1d45
RK
7643/* Return a location descriptor that designates a machine register or
7644 zero if there is no such. */
71dfc51f 7645
a3f97cbb
JW
7646static dw_loc_descr_ref
7647reg_loc_descriptor (rtl)
b3694847 7648 rtx rtl;
a3f97cbb 7649{
b3694847 7650 dw_loc_descr_ref loc_result = NULL;
d22c2324 7651 unsigned reg;
71dfc51f 7652
e7af1d45
RK
7653 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7654 return 0;
7655
7656 reg = reg_number (rtl);
d22c2324
TT
7657 if (reg <= 31)
7658 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7659 else
7660 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
71dfc51f 7661
a3f97cbb
JW
7662 return loc_result;
7663}
7664
d8041cc8
RH
7665/* Return a location descriptor that designates a constant. */
7666
7667static dw_loc_descr_ref
7668int_loc_descriptor (i)
7669 HOST_WIDE_INT i;
7670{
7671 enum dwarf_location_atom op;
7672
7673 /* Pick the smallest representation of a constant, rather than just
7674 defaulting to the LEB encoding. */
7675 if (i >= 0)
7676 {
7677 if (i <= 31)
7678 op = DW_OP_lit0 + i;
7679 else if (i <= 0xff)
7680 op = DW_OP_const1u;
7681 else if (i <= 0xffff)
7682 op = DW_OP_const2u;
7683 else if (HOST_BITS_PER_WIDE_INT == 32
7684 || i <= 0xffffffff)
7685 op = DW_OP_const4u;
7686 else
7687 op = DW_OP_constu;
7688 }
7689 else
7690 {
7691 if (i >= -0x80)
7692 op = DW_OP_const1s;
7693 else if (i >= -0x8000)
7694 op = DW_OP_const2s;
7695 else if (HOST_BITS_PER_WIDE_INT == 32
7696 || i >= -0x80000000)
7697 op = DW_OP_const4s;
7698 else
7699 op = DW_OP_consts;
7700 }
7701
7702 return new_loc_descr (op, i, 0);
7703}
7704
a3f97cbb 7705/* Return a location descriptor that designates a base+offset location. */
71dfc51f 7706
a3f97cbb
JW
7707static dw_loc_descr_ref
7708based_loc_descr (reg, offset)
7709 unsigned reg;
7710 long int offset;
7711{
b3694847 7712 dw_loc_descr_ref loc_result;
810429b7
JM
7713 /* For the "frame base", we use the frame pointer or stack pointer
7714 registers, since the RTL for local variables is relative to one of
7715 them. */
b3694847
SS
7716 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7717 ? HARD_FRAME_POINTER_REGNUM
7718 : STACK_POINTER_REGNUM);
71dfc51f 7719
a3f97cbb 7720 if (reg == fp_reg)
71dfc51f 7721 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
85066503 7722 else if (reg <= 31)
71dfc51f 7723 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
a3f97cbb 7724 else
71dfc51f
RK
7725 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7726
a3f97cbb
JW
7727 return loc_result;
7728}
7729
7730/* Return true if this RTL expression describes a base+offset calculation. */
71dfc51f
RK
7731
7732static inline int
a3f97cbb 7733is_based_loc (rtl)
b3694847 7734 rtx rtl;
a3f97cbb 7735{
173bf5be
KH
7736 return (GET_CODE (rtl) == PLUS
7737 && ((GET_CODE (XEXP (rtl, 0)) == REG
7738 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7739 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
a3f97cbb
JW
7740}
7741
7742/* The following routine converts the RTL for a variable or parameter
7743 (resident in memory) into an equivalent Dwarf representation of a
7744 mechanism for getting the address of that same variable onto the top of a
7745 hypothetical "address evaluation" stack.
71dfc51f 7746
a3f97cbb
JW
7747 When creating memory location descriptors, we are effectively transforming
7748 the RTL for a memory-resident object into its Dwarf postfix expression
7749 equivalent. This routine recursively descends an RTL tree, turning
e60d4d7b
JL
7750 it into Dwarf postfix code as it goes.
7751
7752 MODE is the mode of the memory reference, needed to handle some
e7af1d45
RK
7753 autoincrement addressing modes.
7754
7755 Return 0 if we can't represent the location. */
71dfc51f 7756
a3f97cbb 7757static dw_loc_descr_ref
e60d4d7b 7758mem_loc_descriptor (rtl, mode)
b3694847 7759 rtx rtl;
e60d4d7b 7760 enum machine_mode mode;
a3f97cbb
JW
7761{
7762 dw_loc_descr_ref mem_loc_result = NULL;
e7af1d45 7763
556273e0 7764 /* Note that for a dynamically sized array, the location we will generate a
a3f97cbb
JW
7765 description of here will be the lowest numbered location which is
7766 actually within the array. That's *not* necessarily the same as the
7767 zeroth element of the array. */
71dfc51f 7768
1865dbb5
JM
7769#ifdef ASM_SIMPLIFY_DWARF_ADDR
7770 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7771#endif
7772
a3f97cbb
JW
7773 switch (GET_CODE (rtl))
7774 {
e60d4d7b
JL
7775 case POST_INC:
7776 case POST_DEC:
e2134eea 7777 case POST_MODIFY:
e60d4d7b
JL
7778 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7779 just fall into the SUBREG code. */
7780
2ad9852d 7781 /* ... fall through ... */
e60d4d7b 7782
a3f97cbb
JW
7783 case SUBREG:
7784 /* The case of a subreg may arise when we have a local (register)
7785 variable or a formal (register) parameter which doesn't quite fill
7786 up an entire register. For now, just assume that it is
7787 legitimate to make the Dwarf info refer to the whole register which
7788 contains the given subreg. */
ddef6bc7 7789 rtl = SUBREG_REG (rtl);
71dfc51f 7790
2ad9852d 7791 /* ... fall through ... */
a3f97cbb
JW
7792
7793 case REG:
7794 /* Whenever a register number forms a part of the description of the
7795 method for calculating the (dynamic) address of a memory resident
556273e0 7796 object, DWARF rules require the register number be referred to as
a3f97cbb
JW
7797 a "base register". This distinction is not based in any way upon
7798 what category of register the hardware believes the given register
7799 belongs to. This is strictly DWARF terminology we're dealing with
7800 here. Note that in cases where the location of a memory-resident
7801 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7802 OP_CONST (0)) the actual DWARF location descriptor that we generate
7803 may just be OP_BASEREG (basereg). This may look deceptively like
7804 the object in question was allocated to a register (rather than in
7805 memory) so DWARF consumers need to be aware of the subtle
7806 distinction between OP_REG and OP_BASEREG. */
e7af1d45
RK
7807 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7808 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
a3f97cbb
JW
7809 break;
7810
7811 case MEM:
f7d2b0ed 7812 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
e7af1d45
RK
7813 if (mem_loc_result != 0)
7814 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
a3f97cbb
JW
7815 break;
7816
d8041cc8
RH
7817 case LABEL_REF:
7818 /* Some ports can transform a symbol ref into a label ref, because
368f4cd6
NC
7819 the symbol ref is too far away and has to be dumped into a constant
7820 pool. */
a3f97cbb
JW
7821 case CONST:
7822 case SYMBOL_REF:
6331d1c1 7823 /* Alternatively, the symbol in the constant pool might be referenced
c6f9b9a1 7824 by a different symbol. */
2ad9852d 7825 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
79cdfa4b 7826 {
149d6f9e
JJ
7827 bool marked;
7828 rtx tmp = get_pool_constant_mark (rtl, &marked);
2ad9852d 7829
6331d1c1 7830 if (GET_CODE (tmp) == SYMBOL_REF)
149d6f9e
JJ
7831 {
7832 rtl = tmp;
7833 if (CONSTANT_POOL_ADDRESS_P (tmp))
7834 get_pool_constant_mark (tmp, &marked);
7835 else
7836 marked = true;
7837 }
7838
7839 /* If all references to this pool constant were optimized away,
7840 it was not output and thus we can't represent it.
7841 FIXME: might try to use DW_OP_const_value here, though
7842 DW_OP_piece complicates it. */
7843 if (!marked)
7844 return 0;
79cdfa4b
TM
7845 }
7846
a3f97cbb
JW
7847 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7848 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
c470afad
RK
7849 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7850 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
a3f97cbb
JW
7851 break;
7852
e2134eea
JH
7853 case PRE_MODIFY:
7854 /* Extract the PLUS expression nested inside and fall into
0407c02b 7855 PLUS code below. */
e2134eea
JH
7856 rtl = XEXP (rtl, 1);
7857 goto plus;
7858
e60d4d7b
JL
7859 case PRE_INC:
7860 case PRE_DEC:
7861 /* Turn these into a PLUS expression and fall into the PLUS code
7862 below. */
7863 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7864 GEN_INT (GET_CODE (rtl) == PRE_INC
556273e0
KH
7865 ? GET_MODE_UNIT_SIZE (mode)
7866 : -GET_MODE_UNIT_SIZE (mode)));
7867
2ad9852d 7868 /* ... fall through ... */
e60d4d7b 7869
a3f97cbb 7870 case PLUS:
e2134eea 7871 plus:
a3f97cbb 7872 if (is_based_loc (rtl))
71dfc51f
RK
7873 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7874 INTVAL (XEXP (rtl, 1)));
a3f97cbb
JW
7875 else
7876 {
d8041cc8 7877 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
e7af1d45
RK
7878 if (mem_loc_result == 0)
7879 break;
d8041cc8
RH
7880
7881 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7882 && INTVAL (XEXP (rtl, 1)) >= 0)
e7af1d45
RK
7883 add_loc_descr (&mem_loc_result,
7884 new_loc_descr (DW_OP_plus_uconst,
7885 INTVAL (XEXP (rtl, 1)), 0));
d8041cc8
RH
7886 else
7887 {
7888 add_loc_descr (&mem_loc_result,
7889 mem_loc_descriptor (XEXP (rtl, 1), mode));
7890 add_loc_descr (&mem_loc_result,
7891 new_loc_descr (DW_OP_plus, 0, 0));
7892 }
a3f97cbb
JW
7893 }
7894 break;
7895
dd2478ae 7896 case MULT:
e7af1d45
RK
7897 {
7898 /* If a pseudo-reg is optimized away, it is possible for it to
7899 be replaced with a MEM containing a multiply. */
7900 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7901 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7902
7903 if (op0 == 0 || op1 == 0)
7904 break;
7905
7906 mem_loc_result = op0;
7907 add_loc_descr (&mem_loc_result, op1);
7908 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7909 break;
7910 }
dd2478ae 7911
a3f97cbb 7912 case CONST_INT:
d8041cc8 7913 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
a3f97cbb
JW
7914 break;
7915
a9e8a5ee
RK
7916 case ADDRESSOF:
7917 /* If this is a MEM, return its address. Otherwise, we can't
7918 represent this. */
7919 if (GET_CODE (XEXP (rtl, 0)) == MEM)
7920 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
7921 else
7922 return 0;
7923
a3f97cbb
JW
7924 default:
7925 abort ();
7926 }
71dfc51f 7927
a3f97cbb
JW
7928 return mem_loc_result;
7929}
7930
956d6950 7931/* Return a descriptor that describes the concatenation of two locations.
4401bf24
JL
7932 This is typically a complex variable. */
7933
7934static dw_loc_descr_ref
7935concat_loc_descriptor (x0, x1)
b3694847 7936 rtx x0, x1;
4401bf24
JL
7937{
7938 dw_loc_descr_ref cc_loc_result = NULL;
e7af1d45
RK
7939 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7940 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
4401bf24 7941
e7af1d45
RK
7942 if (x0_ref == 0 || x1_ref == 0)
7943 return 0;
7944
7945 cc_loc_result = x0_ref;
4401bf24 7946 add_loc_descr (&cc_loc_result,
e7af1d45
RK
7947 new_loc_descr (DW_OP_piece,
7948 GET_MODE_SIZE (GET_MODE (x0)), 0));
4401bf24 7949
e7af1d45 7950 add_loc_descr (&cc_loc_result, x1_ref);
4401bf24 7951 add_loc_descr (&cc_loc_result,
e7af1d45
RK
7952 new_loc_descr (DW_OP_piece,
7953 GET_MODE_SIZE (GET_MODE (x1)), 0));
4401bf24
JL
7954
7955 return cc_loc_result;
7956}
7957
a3f97cbb
JW
7958/* Output a proper Dwarf location descriptor for a variable or parameter
7959 which is either allocated in a register or in a memory location. For a
7960 register, we just generate an OP_REG and the register number. For a
7961 memory location we provide a Dwarf postfix expression describing how to
e7af1d45
RK
7962 generate the (dynamic) address of the object onto the address stack.
7963
7964 If we don't know how to describe it, return 0. */
71dfc51f 7965
a3f97cbb
JW
7966static dw_loc_descr_ref
7967loc_descriptor (rtl)
b3694847 7968 rtx rtl;
a3f97cbb
JW
7969{
7970 dw_loc_descr_ref loc_result = NULL;
e7af1d45 7971
a3f97cbb
JW
7972 switch (GET_CODE (rtl))
7973 {
7974 case SUBREG:
a3f97cbb
JW
7975 /* The case of a subreg may arise when we have a local (register)
7976 variable or a formal (register) parameter which doesn't quite fill
71dfc51f 7977 up an entire register. For now, just assume that it is
a3f97cbb
JW
7978 legitimate to make the Dwarf info refer to the whole register which
7979 contains the given subreg. */
ddef6bc7 7980 rtl = SUBREG_REG (rtl);
71dfc51f 7981
2ad9852d 7982 /* ... fall through ... */
a3f97cbb
JW
7983
7984 case REG:
5c90448c 7985 loc_result = reg_loc_descriptor (rtl);
a3f97cbb
JW
7986 break;
7987
7988 case MEM:
e60d4d7b 7989 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
a3f97cbb
JW
7990 break;
7991
4401bf24
JL
7992 case CONCAT:
7993 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7994 break;
7995
a3f97cbb 7996 default:
71dfc51f 7997 abort ();
a3f97cbb 7998 }
71dfc51f 7999
a3f97cbb
JW
8000 return loc_result;
8001}
8002
2ad9852d
RK
8003/* Similar, but generate the descriptor from trees instead of rtl. This comes
8004 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8005 looking for an address. Otherwise, we return a value. If we can't make a
8006 descriptor, return 0. */
d8041cc8
RH
8007
8008static dw_loc_descr_ref
8009loc_descriptor_from_tree (loc, addressp)
8010 tree loc;
8011 int addressp;
8012{
e7af1d45
RK
8013 dw_loc_descr_ref ret, ret1;
8014 int indirect_p = 0;
d8041cc8
RH
8015 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8016 enum dwarf_location_atom op;
8017
8018 /* ??? Most of the time we do not take proper care for sign/zero
8019 extending the values properly. Hopefully this won't be a real
8020 problem... */
8021
8022 switch (TREE_CODE (loc))
8023 {
8024 case ERROR_MARK:
e7af1d45 8025 return 0;
d8041cc8 8026
b4ae5201 8027 case WITH_RECORD_EXPR:
e7af1d45 8028 case PLACEHOLDER_EXPR:
b4ae5201
RK
8029 /* This case involves extracting fields from an object to determine the
8030 position of other fields. We don't try to encode this here. The
8031 only user of this is Ada, which encodes the needed information using
8032 the names of types. */
e7af1d45 8033 return 0;
b4ae5201 8034
aea9695c
RK
8035 case CALL_EXPR:
8036 return 0;
8037
8038 case ADDR_EXPR:
8039 /* We can support this only if we can look through conversions and
8040 find an INDIRECT_EXPR. */
8041 for (loc = TREE_OPERAND (loc, 0);
8042 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8043 || TREE_CODE (loc) == NON_LVALUE_EXPR
8044 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8045 || TREE_CODE (loc) == SAVE_EXPR;
8046 loc = TREE_OPERAND (loc, 0))
8047 ;
8048
8049 return (TREE_CODE (loc) == INDIRECT_REF
8050 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8051 : 0);
8052
d8041cc8 8053 case VAR_DECL:
b9203463
RH
8054 if (DECL_THREAD_LOCAL (loc))
8055 {
8056 rtx rtl;
8057
8058#ifndef ASM_OUTPUT_DWARF_DTPREL
8059 /* If this is not defined, we have no way to emit the data. */
8060 return 0;
8061#endif
8062
8063 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8064 look up addresses of objects in the current module. */
8065 if (! (*targetm.binds_local_p) (loc))
8066 return 0;
8067
8068 rtl = rtl_for_decl_location (loc);
8069 if (rtl == NULL_RTX)
8070 return 0;
8071
8072 if (GET_CODE (rtl) != MEM)
8073 return 0;
8074 rtl = XEXP (rtl, 0);
8075 if (! CONSTANT_P (rtl))
8076 return 0;
8077
8078 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
8079 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8080 ret->dw_loc_oprnd1.v.val_addr = rtl;
8081
8082 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
8083 add_loc_descr (&ret, ret1);
8084
8085 indirect_p = 1;
8086 break;
8087 }
8088 /* FALLTHRU */
8089
d8041cc8
RH
8090 case PARM_DECL:
8091 {
8092 rtx rtl = rtl_for_decl_location (loc);
d8041cc8 8093
a97c9600 8094 if (rtl == NULL_RTX)
e7af1d45 8095 return 0;
a97c9600 8096 else if (CONSTANT_P (rtl))
d8041cc8
RH
8097 {
8098 ret = new_loc_descr (DW_OP_addr, 0, 0);
8099 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8100 ret->dw_loc_oprnd1.v.val_addr = rtl;
e7af1d45 8101 indirect_p = 1;
d8041cc8
RH
8102 }
8103 else
8104 {
c28abdf0
RH
8105 enum machine_mode mode = GET_MODE (rtl);
8106
d8041cc8
RH
8107 if (GET_CODE (rtl) == MEM)
8108 {
e7af1d45 8109 indirect_p = 1;
d8041cc8
RH
8110 rtl = XEXP (rtl, 0);
8111 }
2ad9852d 8112
d8041cc8
RH
8113 ret = mem_loc_descriptor (rtl, mode);
8114 }
8115 }
8116 break;
8117
8118 case INDIRECT_REF:
8119 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
e7af1d45 8120 indirect_p = 1;
d8041cc8
RH
8121 break;
8122
749552c4
RK
8123 case COMPOUND_EXPR:
8124 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8125
ed972b14
RK
8126 case NOP_EXPR:
8127 case CONVERT_EXPR:
8128 case NON_LVALUE_EXPR:
ed239f5a 8129 case VIEW_CONVERT_EXPR:
b4ae5201 8130 case SAVE_EXPR:
ed972b14 8131 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
e57cabac 8132
d8041cc8
RH
8133 case COMPONENT_REF:
8134 case BIT_FIELD_REF:
8135 case ARRAY_REF:
b4e3fabb 8136 case ARRAY_RANGE_REF:
d8041cc8
RH
8137 {
8138 tree obj, offset;
8139 HOST_WIDE_INT bitsize, bitpos, bytepos;
8140 enum machine_mode mode;
8141 int volatilep;
d8041cc8
RH
8142
8143 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
a06ef755 8144 &unsignedp, &volatilep);
e7af1d45
RK
8145
8146 if (obj == loc)
8147 return 0;
8148
d8041cc8 8149 ret = loc_descriptor_from_tree (obj, 1);
e7af1d45 8150 if (ret == 0
2ad9852d 8151 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
e7af1d45 8152 return 0;
d8041cc8
RH
8153
8154 if (offset != NULL_TREE)
8155 {
8156 /* Variable offset. */
8157 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8158 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8159 }
8160
e7af1d45
RK
8161 if (!addressp)
8162 indirect_p = 1;
d8041cc8
RH
8163
8164 bytepos = bitpos / BITS_PER_UNIT;
8165 if (bytepos > 0)
8166 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8167 else if (bytepos < 0)
8168 {
8169 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8170 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8171 }
8172 break;
8173 }
8174
8175 case INTEGER_CST:
8176 if (host_integerp (loc, 0))
8177 ret = int_loc_descriptor (tree_low_cst (loc, 0));
e7af1d45
RK
8178 else
8179 return 0;
d8041cc8 8180 break;
d8041cc8 8181
c26fbbca 8182 case TRUTH_AND_EXPR:
9702143f 8183 case TRUTH_ANDIF_EXPR:
d8041cc8
RH
8184 case BIT_AND_EXPR:
8185 op = DW_OP_and;
8186 goto do_binop;
e7af1d45 8187
9702143f 8188 case TRUTH_XOR_EXPR:
d8041cc8
RH
8189 case BIT_XOR_EXPR:
8190 op = DW_OP_xor;
8191 goto do_binop;
e7af1d45 8192
9702143f
RK
8193 case TRUTH_OR_EXPR:
8194 case TRUTH_ORIF_EXPR:
d8041cc8
RH
8195 case BIT_IOR_EXPR:
8196 op = DW_OP_or;
8197 goto do_binop;
e7af1d45 8198
d8041cc8
RH
8199 case TRUNC_DIV_EXPR:
8200 op = DW_OP_div;
8201 goto do_binop;
e7af1d45 8202
d8041cc8
RH
8203 case MINUS_EXPR:
8204 op = DW_OP_minus;
8205 goto do_binop;
e7af1d45 8206
d8041cc8
RH
8207 case TRUNC_MOD_EXPR:
8208 op = DW_OP_mod;
8209 goto do_binop;
e7af1d45 8210
d8041cc8
RH
8211 case MULT_EXPR:
8212 op = DW_OP_mul;
8213 goto do_binop;
e7af1d45 8214
d8041cc8
RH
8215 case LSHIFT_EXPR:
8216 op = DW_OP_shl;
8217 goto do_binop;
e7af1d45 8218
d8041cc8
RH
8219 case RSHIFT_EXPR:
8220 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8221 goto do_binop;
e7af1d45 8222
d8041cc8
RH
8223 case PLUS_EXPR:
8224 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8225 && host_integerp (TREE_OPERAND (loc, 1), 0))
8226 {
8227 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
e7af1d45
RK
8228 if (ret == 0)
8229 return 0;
8230
d8041cc8
RH
8231 add_loc_descr (&ret,
8232 new_loc_descr (DW_OP_plus_uconst,
8233 tree_low_cst (TREE_OPERAND (loc, 1),
8234 0),
8235 0));
8236 break;
8237 }
e7af1d45 8238
d8041cc8
RH
8239 op = DW_OP_plus;
8240 goto do_binop;
2ad9852d 8241
d8041cc8
RH
8242 case LE_EXPR:
8243 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
e7af1d45
RK
8244 return 0;
8245
d8041cc8
RH
8246 op = DW_OP_le;
8247 goto do_binop;
e7af1d45 8248
d8041cc8
RH
8249 case GE_EXPR:
8250 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
e7af1d45
RK
8251 return 0;
8252
d8041cc8
RH
8253 op = DW_OP_ge;
8254 goto do_binop;
e7af1d45 8255
d8041cc8
RH
8256 case LT_EXPR:
8257 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
e7af1d45
RK
8258 return 0;
8259
d8041cc8
RH
8260 op = DW_OP_lt;
8261 goto do_binop;
e7af1d45 8262
d8041cc8
RH
8263 case GT_EXPR:
8264 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
e7af1d45
RK
8265 return 0;
8266
d8041cc8
RH
8267 op = DW_OP_gt;
8268 goto do_binop;
e7af1d45 8269
d8041cc8
RH
8270 case EQ_EXPR:
8271 op = DW_OP_eq;
8272 goto do_binop;
e7af1d45 8273
d8041cc8
RH
8274 case NE_EXPR:
8275 op = DW_OP_ne;
8276 goto do_binop;
8277
8278 do_binop:
8279 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
e7af1d45
RK
8280 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8281 if (ret == 0 || ret1 == 0)
8282 return 0;
8283
8284 add_loc_descr (&ret, ret1);
d8041cc8
RH
8285 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8286 break;
8287
9702143f 8288 case TRUTH_NOT_EXPR:
d8041cc8
RH
8289 case BIT_NOT_EXPR:
8290 op = DW_OP_not;
8291 goto do_unop;
e7af1d45 8292
d8041cc8
RH
8293 case ABS_EXPR:
8294 op = DW_OP_abs;
8295 goto do_unop;
e7af1d45 8296
d8041cc8
RH
8297 case NEGATE_EXPR:
8298 op = DW_OP_neg;
8299 goto do_unop;
8300
8301 do_unop:
8302 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
e7af1d45
RK
8303 if (ret == 0)
8304 return 0;
8305
d8041cc8
RH
8306 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8307 break;
8308
8309 case MAX_EXPR:
8310 loc = build (COND_EXPR, TREE_TYPE (loc),
8311 build (LT_EXPR, integer_type_node,
8312 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8313 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
2ad9852d 8314
3ef42a0c 8315 /* ... fall through ... */
d8041cc8
RH
8316
8317 case COND_EXPR:
8318 {
e7af1d45
RK
8319 dw_loc_descr_ref lhs
8320 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8321 dw_loc_descr_ref rhs
8322 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
d8041cc8
RH
8323 dw_loc_descr_ref bra_node, jump_node, tmp;
8324
8325 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
e7af1d45
RK
8326 if (ret == 0 || lhs == 0 || rhs == 0)
8327 return 0;
8328
d8041cc8
RH
8329 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8330 add_loc_descr (&ret, bra_node);
8331
e7af1d45 8332 add_loc_descr (&ret, rhs);
d8041cc8
RH
8333 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8334 add_loc_descr (&ret, jump_node);
8335
e7af1d45 8336 add_loc_descr (&ret, lhs);
d8041cc8 8337 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
e7af1d45 8338 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
d8041cc8
RH
8339
8340 /* ??? Need a node to point the skip at. Use a nop. */
8341 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8342 add_loc_descr (&ret, tmp);
8343 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8344 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8345 }
8346 break;
8347
8348 default:
8349 abort ();
8350 }
8351
e7af1d45
RK
8352 /* Show if we can't fill the request for an address. */
8353 if (addressp && indirect_p == 0)
8354 return 0;
d8041cc8
RH
8355
8356 /* If we've got an address and don't want one, dereference. */
e7af1d45 8357 if (!addressp && indirect_p > 0)
d8041cc8 8358 {
e7af1d45
RK
8359 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8360
8361 if (size > DWARF2_ADDR_SIZE || size == -1)
8362 return 0;
2ad9852d 8363 else if (size == DWARF2_ADDR_SIZE)
d8041cc8
RH
8364 op = DW_OP_deref;
8365 else
8366 op = DW_OP_deref_size;
e7af1d45
RK
8367
8368 add_loc_descr (&ret, new_loc_descr (op, size, 0));
d8041cc8
RH
8369 }
8370
8371 return ret;
8372}
8373
665f2503 8374/* Given a value, round it up to the lowest multiple of `boundary'
a3f97cbb 8375 which is not less than the value itself. */
71dfc51f 8376
665f2503 8377static inline HOST_WIDE_INT
a3f97cbb 8378ceiling (value, boundary)
665f2503
RK
8379 HOST_WIDE_INT value;
8380 unsigned int boundary;
a3f97cbb
JW
8381{
8382 return (((value + boundary - 1) / boundary) * boundary);
8383}
8384
8385/* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8386 pointer to the declared type for the relevant field variable, or return
8387 `integer_type_node' if the given node turns out to be an
8388 ERROR_MARK node. */
71dfc51f
RK
8389
8390static inline tree
a3f97cbb 8391field_type (decl)
b3694847 8392 tree decl;
a3f97cbb 8393{
b3694847 8394 tree type;
a3f97cbb
JW
8395
8396 if (TREE_CODE (decl) == ERROR_MARK)
8397 return integer_type_node;
8398
8399 type = DECL_BIT_FIELD_TYPE (decl);
71dfc51f 8400 if (type == NULL_TREE)
a3f97cbb
JW
8401 type = TREE_TYPE (decl);
8402
8403 return type;
8404}
8405
5f446d21
DD
8406/* Given a pointer to a tree node, return the alignment in bits for
8407 it, or else return BITS_PER_WORD if the node actually turns out to
8408 be an ERROR_MARK node. */
71dfc51f
RK
8409
8410static inline unsigned
a3f97cbb 8411simple_type_align_in_bits (type)
b3694847 8412 tree type;
a3f97cbb
JW
8413{
8414 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8415}
8416
5f446d21
DD
8417static inline unsigned
8418simple_decl_align_in_bits (decl)
b3694847 8419 tree decl;
5f446d21
DD
8420{
8421 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8422}
8423
a3f97cbb
JW
8424/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8425 node, return the size in bits for the type if it is a constant, or else
8426 return the alignment for the type if the type's size is not constant, or
8427 else return BITS_PER_WORD if the type actually turns out to be an
8428 ERROR_MARK node. */
71dfc51f 8429
665f2503 8430static inline unsigned HOST_WIDE_INT
a3f97cbb 8431simple_type_size_in_bits (type)
b3694847 8432 tree type;
a3f97cbb 8433{
3df18884 8434
a3f97cbb
JW
8435 if (TREE_CODE (type) == ERROR_MARK)
8436 return BITS_PER_WORD;
2ad9852d 8437 else if (TYPE_SIZE (type) == NULL_TREE)
3df18884 8438 return 0;
2ad9852d
RK
8439 else if (host_integerp (TYPE_SIZE (type), 1))
8440 return tree_low_cst (TYPE_SIZE (type), 1);
8441 else
3df18884 8442 return TYPE_ALIGN (type);
a3f97cbb
JW
8443}
8444
2ad9852d
RK
8445/* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8446 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8447 or return 0 if we are unable to determine what that offset is, either
8448 because the argument turns out to be a pointer to an ERROR_MARK node, or
8449 because the offset is actually variable. (We can't handle the latter case
8450 just yet). */
71dfc51f 8451
665f2503 8452static HOST_WIDE_INT
a3f97cbb 8453field_byte_offset (decl)
b3694847 8454 tree decl;
a3f97cbb 8455{
665f2503 8456 unsigned int type_align_in_bits;
5f446d21 8457 unsigned int decl_align_in_bits;
665f2503 8458 unsigned HOST_WIDE_INT type_size_in_bits;
665f2503 8459 HOST_WIDE_INT object_offset_in_bits;
665f2503
RK
8460 tree type;
8461 tree field_size_tree;
8462 HOST_WIDE_INT bitpos_int;
8463 HOST_WIDE_INT deepest_bitpos;
8464 unsigned HOST_WIDE_INT field_size_in_bits;
a3f97cbb
JW
8465
8466 if (TREE_CODE (decl) == ERROR_MARK)
8467 return 0;
2ad9852d 8468 else if (TREE_CODE (decl) != FIELD_DECL)
a3f97cbb
JW
8469 abort ();
8470
8471 type = field_type (decl);
a3f97cbb
JW
8472 field_size_tree = DECL_SIZE (decl);
8473
3df18884
RH
8474 /* The size could be unspecified if there was an error, or for
8475 a flexible array member. */
50352c9c 8476 if (! field_size_tree)
3df18884 8477 field_size_tree = bitsize_zero_node;
50352c9c 8478
556273e0 8479 /* We cannot yet cope with fields whose positions are variable, so
a3f97cbb
JW
8480 for now, when we see such things, we simply return 0. Someday, we may
8481 be able to handle such cases, but it will be damn difficult. */
665f2503 8482 if (! host_integerp (bit_position (decl), 0))
a3f97cbb 8483 return 0;
14a774a9 8484
665f2503 8485 bitpos_int = int_bit_position (decl);
a3f97cbb 8486
3df18884 8487 /* If we don't know the size of the field, pretend it's a full word. */
665f2503
RK
8488 if (host_integerp (field_size_tree, 1))
8489 field_size_in_bits = tree_low_cst (field_size_tree, 1);
14a774a9
RK
8490 else
8491 field_size_in_bits = BITS_PER_WORD;
a3f97cbb
JW
8492
8493 type_size_in_bits = simple_type_size_in_bits (type);
a3f97cbb 8494 type_align_in_bits = simple_type_align_in_bits (type);
5f446d21 8495 decl_align_in_bits = simple_decl_align_in_bits (decl);
a3f97cbb 8496
2ad9852d
RK
8497 /* The GCC front-end doesn't make any attempt to keep track of the starting
8498 bit offset (relative to the start of the containing structure type) of the
8499 hypothetical "containing object" for a bit-field. Thus, when computing
8500 the byte offset value for the start of the "containing object" of a
8501 bit-field, we must deduce this information on our own. This can be rather
8502 tricky to do in some cases. For example, handling the following structure
8503 type definition when compiling for an i386/i486 target (which only aligns
8504 long long's to 32-bit boundaries) can be very tricky:
a3f97cbb
JW
8505
8506 struct S { int field1; long long field2:31; };
8507
2ad9852d
RK
8508 Fortunately, there is a simple rule-of-thumb which can be used in such
8509 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8510 structure shown above. It decides to do this based upon one simple rule
8511 for bit-field allocation. GCC allocates each "containing object" for each
8512 bit-field at the first (i.e. lowest addressed) legitimate alignment
8513 boundary (based upon the required minimum alignment for the declared type
8514 of the field) which it can possibly use, subject to the condition that
8515 there is still enough available space remaining in the containing object
8516 (when allocated at the selected point) to fully accommodate all of the
8517 bits of the bit-field itself.
8518
8519 This simple rule makes it obvious why GCC allocates 8 bytes for each
8520 object of the structure type shown above. When looking for a place to
8521 allocate the "containing object" for `field2', the compiler simply tries
8522 to allocate a 64-bit "containing object" at each successive 32-bit
8523 boundary (starting at zero) until it finds a place to allocate that 64-
8524 bit field such that at least 31 contiguous (and previously unallocated)
8525 bits remain within that selected 64 bit field. (As it turns out, for the
8526 example above, the compiler finds it is OK to allocate the "containing
8527 object" 64-bit field at bit-offset zero within the structure type.)
8528
8529 Here we attempt to work backwards from the limited set of facts we're
8530 given, and we try to deduce from those facts, where GCC must have believed
8531 that the containing object started (within the structure type). The value
8532 we deduce is then used (by the callers of this routine) to generate
8533 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8534 and, in the case of DW_AT_location, regular fields as well). */
a3f97cbb
JW
8535
8536 /* Figure out the bit-distance from the start of the structure to the
8537 "deepest" bit of the bit-field. */
8538 deepest_bitpos = bitpos_int + field_size_in_bits;
8539
8540 /* This is the tricky part. Use some fancy footwork to deduce where the
8541 lowest addressed bit of the containing object must be. */
5f446d21
DD
8542 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8543
8544 /* Round up to type_align by default. This works best for bitfields. */
8545 object_offset_in_bits += type_align_in_bits - 1;
8546 object_offset_in_bits /= type_align_in_bits;
8547 object_offset_in_bits *= type_align_in_bits;
a3f97cbb 8548
5f446d21
DD
8549 if (object_offset_in_bits > bitpos_int)
8550 {
8551 /* Sigh, the decl must be packed. */
8552 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8553
8554 /* Round up to decl_align instead. */
8555 object_offset_in_bits += decl_align_in_bits - 1;
8556 object_offset_in_bits /= decl_align_in_bits;
8557 object_offset_in_bits *= decl_align_in_bits;
8558 }
a3f97cbb 8559
2ad9852d 8560 return object_offset_in_bits / BITS_PER_UNIT;
a3f97cbb 8561}
a3f97cbb 8562\f
71dfc51f
RK
8563/* The following routines define various Dwarf attributes and any data
8564 associated with them. */
a3f97cbb 8565
ef76d03b 8566/* Add a location description attribute value to a DIE.
a3f97cbb 8567
ef76d03b 8568 This emits location attributes suitable for whole variables and
a3f97cbb
JW
8569 whole parameters. Note that the location attributes for struct fields are
8570 generated by the routine `data_member_location_attribute' below. */
71dfc51f 8571
b9203463
RH
8572static inline void
8573add_AT_location_description (die, attr_kind, descr)
a3f97cbb 8574 dw_die_ref die;
ef76d03b 8575 enum dwarf_attribute attr_kind;
b9203463 8576 dw_loc_descr_ref descr;
a3f97cbb 8577{
e7af1d45
RK
8578 if (descr != 0)
8579 add_AT_loc (die, attr_kind, descr);
a3f97cbb
JW
8580}
8581
2ad9852d
RK
8582/* Attach the specialized form of location attribute used for data members of
8583 struct and union types. In the special case of a FIELD_DECL node which
8584 represents a bit-field, the "offset" part of this special location
8585 descriptor must indicate the distance in bytes from the lowest-addressed
8586 byte of the containing struct or union type to the lowest-addressed byte of
8587 the "containing object" for the bit-field. (See the `field_byte_offset'
8588 function above).
8589
8590 For any given bit-field, the "containing object" is a hypothetical object
8591 (of some integral or enum type) within which the given bit-field lives. The
8592 type of this hypothetical "containing object" is always the same as the
8593 declared type of the individual bit-field itself (for GCC anyway... the
8594 DWARF spec doesn't actually mandate this). Note that it is the size (in
8595 bytes) of the hypothetical "containing object" which will be given in the
8596 DW_AT_byte_size attribute for this bit-field. (See the
8597 `byte_size_attribute' function below.) It is also used when calculating the
8598 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8599 function below.) */
71dfc51f 8600
a3f97cbb
JW
8601static void
8602add_data_member_location_attribute (die, decl)
b3694847
SS
8603 dw_die_ref die;
8604 tree decl;
a3f97cbb 8605{
649ce3f2
JM
8606 long offset;
8607 dw_loc_descr_ref loc_descr = 0;
a3f97cbb 8608
61b32c02 8609 if (TREE_CODE (decl) == TREE_VEC)
649ce3f2
JM
8610 {
8611 /* We're working on the TAG_inheritance for a base class. */
1d3d6b1e 8612 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
649ce3f2
JM
8613 {
8614 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8615 aren't at a fixed offset from all (sub)objects of the same
8616 type. We need to extract the appropriate offset from our
8617 vtable. The following dwarf expression means
8618
8619 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8620
8621 This is specific to the V3 ABI, of course. */
8622
8623 dw_loc_descr_ref tmp;
2ad9852d 8624
649ce3f2
JM
8625 /* Make a copy of the object address. */
8626 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8627 add_loc_descr (&loc_descr, tmp);
2ad9852d 8628
649ce3f2
JM
8629 /* Extract the vtable address. */
8630 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8631 add_loc_descr (&loc_descr, tmp);
2ad9852d 8632
649ce3f2
JM
8633 /* Calculate the address of the offset. */
8634 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8635 if (offset >= 0)
8636 abort ();
2ad9852d 8637
649ce3f2
JM
8638 tmp = int_loc_descriptor (-offset);
8639 add_loc_descr (&loc_descr, tmp);
8640 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8641 add_loc_descr (&loc_descr, tmp);
2ad9852d 8642
649ce3f2
JM
8643 /* Extract the offset. */
8644 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8645 add_loc_descr (&loc_descr, tmp);
2ad9852d 8646
649ce3f2
JM
8647 /* Add it to the object address. */
8648 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8649 add_loc_descr (&loc_descr, tmp);
8650 }
8651 else
8652 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8653 }
61b32c02
JM
8654 else
8655 offset = field_byte_offset (decl);
8656
649ce3f2
JM
8657 if (! loc_descr)
8658 {
8659 enum dwarf_location_atom op;
8660
2ad9852d
RK
8661 /* The DWARF2 standard says that we should assume that the structure
8662 address is already on the stack, so we can specify a structure field
8663 address by using DW_OP_plus_uconst. */
71dfc51f 8664
a3f97cbb 8665#ifdef MIPS_DEBUGGING_INFO
2ad9852d
RK
8666 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8667 operator correctly. It works only if we leave the offset on the
8668 stack. */
649ce3f2 8669 op = DW_OP_constu;
a3f97cbb 8670#else
649ce3f2 8671 op = DW_OP_plus_uconst;
a3f97cbb 8672#endif
71dfc51f 8673
649ce3f2
JM
8674 loc_descr = new_loc_descr (op, offset, 0);
8675 }
2ad9852d 8676
a3f97cbb
JW
8677 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8678}
8679
8680/* Attach an DW_AT_const_value attribute for a variable or a parameter which
8681 does not have a "location" either in memory or in a register. These
8682 things can arise in GNU C when a constant is passed as an actual parameter
8683 to an inlined function. They can also arise in C++ where declared
8684 constants do not necessarily get memory "homes". */
71dfc51f 8685
a3f97cbb
JW
8686static void
8687add_const_value_attribute (die, rtl)
b3694847
SS
8688 dw_die_ref die;
8689 rtx rtl;
a3f97cbb
JW
8690{
8691 switch (GET_CODE (rtl))
8692 {
8693 case CONST_INT:
2e4b9b8c
RH
8694 /* Note that a CONST_INT rtx could represent either an integer
8695 or a floating-point constant. A CONST_INT is used whenever
8696 the constant will fit into a single word. In all such
8697 cases, the original mode of the constant value is wiped
8698 out, and the CONST_INT rtx is assigned VOIDmode. */
8699 {
8700 HOST_WIDE_INT val = INTVAL (rtl);
c26fbbca 8701
2e4b9b8c 8702 /* ??? We really should be using HOST_WIDE_INT throughout. */
5929a2f0 8703 if (val < 0 && (long) val == val)
3d7a191f 8704 add_AT_int (die, DW_AT_const_value, (long) val);
5929a2f0
RH
8705 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8706 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
94784fb9
RK
8707 else
8708 {
e7af1d45 8709#if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
94784fb9
RK
8710 add_AT_long_long (die, DW_AT_const_value,
8711 val >> HOST_BITS_PER_LONG, val);
e7af1d45 8712#else
94784fb9 8713 abort ();
e7af1d45 8714#endif
94784fb9 8715 }
2e4b9b8c 8716 }
a3f97cbb
JW
8717 break;
8718
8719 case CONST_DOUBLE:
8720 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8721 floating-point constant. A CONST_DOUBLE is used whenever the
8722 constant requires more than one word in order to be adequately
469ac993
JM
8723 represented. We output CONST_DOUBLEs as blocks. */
8724 {
b3694847 8725 enum machine_mode mode = GET_MODE (rtl);
469ac993
JM
8726
8727 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8728 {
b3694847 8729 unsigned length = GET_MODE_SIZE (mode) / 4;
c26fbbca 8730 long *array = (long *) xmalloc (sizeof (long) * length);
71dfc51f 8731 REAL_VALUE_TYPE rv;
469ac993 8732
71dfc51f 8733 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
469ac993
JM
8734 switch (mode)
8735 {
8736 case SFmode:
71dfc51f 8737 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
469ac993
JM
8738 break;
8739
8740 case DFmode:
71dfc51f 8741 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
469ac993
JM
8742 break;
8743
8744 case XFmode:
8745 case TFmode:
71dfc51f 8746 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
469ac993
JM
8747 break;
8748
8749 default:
8750 abort ();
8751 }
8752
469ac993
JM
8753 add_AT_float (die, DW_AT_const_value, length, array);
8754 }
8755 else
2e4b9b8c
RH
8756 {
8757 /* ??? We really should be using HOST_WIDE_INT throughout. */
8758 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8759 abort ();
2ad9852d 8760
2e4b9b8c
RH
8761 add_AT_long_long (die, DW_AT_const_value,
8762 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8763 }
469ac993 8764 }
a3f97cbb
JW
8765 break;
8766
8767 case CONST_STRING:
8768 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8769 break;
8770
8771 case SYMBOL_REF:
8772 case LABEL_REF:
8773 case CONST:
c470afad
RK
8774 add_AT_addr (die, DW_AT_const_value, rtl);
8775 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
a3f97cbb
JW
8776 break;
8777
8778 case PLUS:
8779 /* In cases where an inlined instance of an inline function is passed
8780 the address of an `auto' variable (which is local to the caller) we
8781 can get a situation where the DECL_RTL of the artificial local
8782 variable (for the inlining) which acts as a stand-in for the
8783 corresponding formal parameter (of the inline function) will look
8784 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
556273e0
KH
8785 exactly a compile-time constant expression, but it isn't the address
8786 of the (artificial) local variable either. Rather, it represents the
a3f97cbb 8787 *value* which the artificial local variable always has during its
556273e0 8788 lifetime. We currently have no way to represent such quasi-constant
6a7a9f01 8789 values in Dwarf, so for now we just punt and generate nothing. */
a3f97cbb
JW
8790 break;
8791
8792 default:
8793 /* No other kinds of rtx should be possible here. */
8794 abort ();
8795 }
8796
8797}
8798
d8041cc8
RH
8799static rtx
8800rtl_for_decl_location (decl)
8801 tree decl;
a3f97cbb 8802{
b3694847 8803 rtx rtl;
71dfc51f 8804
a3f97cbb
JW
8805 /* Here we have to decide where we are going to say the parameter "lives"
8806 (as far as the debugger is concerned). We only have a couple of
8807 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
71dfc51f 8808
556273e0 8809 DECL_RTL normally indicates where the parameter lives during most of the
71dfc51f 8810 activation of the function. If optimization is enabled however, this
556273e0 8811 could be either NULL or else a pseudo-reg. Both of those cases indicate
a3f97cbb
JW
8812 that the parameter doesn't really live anywhere (as far as the code
8813 generation parts of GCC are concerned) during most of the function's
8814 activation. That will happen (for example) if the parameter is never
71dfc51f
RK
8815 referenced within the function.
8816
8817 We could just generate a location descriptor here for all non-NULL
8818 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8819 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8820 where DECL_RTL is NULL or is a pseudo-reg.
8821
8822 Note however that we can only get away with using DECL_INCOMING_RTL as
8823 a backup substitute for DECL_RTL in certain limited cases. In cases
8824 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8825 we can be sure that the parameter was passed using the same type as it is
8826 declared to have within the function, and that its DECL_INCOMING_RTL
8827 points us to a place where a value of that type is passed.
8828
8829 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8830 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8831 because in these cases DECL_INCOMING_RTL points us to a value of some
8832 type which is *different* from the type of the parameter itself. Thus,
8833 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8834 such cases, the debugger would end up (for example) trying to fetch a
8835 `float' from a place which actually contains the first part of a
8836 `double'. That would lead to really incorrect and confusing
8837 output at debug-time.
8838
8839 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8840 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8841 are a couple of exceptions however. On little-endian machines we can
8842 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8843 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8844 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8845 when (on a little-endian machine) a non-prototyped function has a
8846 parameter declared to be of type `short' or `char'. In such cases,
8847 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8848 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8849 passed `int' value. If the debugger then uses that address to fetch
8850 a `short' or a `char' (on a little-endian machine) the result will be
8851 the correct data, so we allow for such exceptional cases below.
8852
8853 Note that our goal here is to describe the place where the given formal
2ad9852d
RK
8854 parameter lives during most of the function's activation (i.e. between the
8855 end of the prologue and the start of the epilogue). We'll do that as best
8856 as we can. Note however that if the given formal parameter is modified
8857 sometime during the execution of the function, then a stack backtrace (at
8858 debug-time) will show the function as having been called with the *new*
8859 value rather than the value which was originally passed in. This happens
8860 rarely enough that it is not a major problem, but it *is* a problem, and
8861 I'd like to fix it.
8862
8863 A future version of dwarf2out.c may generate two additional attributes for
8864 any given DW_TAG_formal_parameter DIE which will describe the "passed
8865 type" and the "passed location" for the given formal parameter in addition
8866 to the attributes we now generate to indicate the "declared type" and the
8867 "active location" for each parameter. This additional set of attributes
8868 could be used by debuggers for stack backtraces. Separately, note that
8869 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8870 This happens (for example) for inlined-instances of inline function formal
8871 parameters which are never referenced. This really shouldn't be
8872 happening. All PARM_DECL nodes should get valid non-NULL
8873 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8874 values for inlined instances of inline function parameters, so when we see
8875 such cases, we are just out-of-luck for the time being (until integrate.c
a3f97cbb
JW
8876 gets fixed). */
8877
8878 /* Use DECL_RTL as the "location" unless we find something better. */
110c3568 8879 rtl = DECL_RTL_IF_SET (decl);
a3f97cbb 8880
c28abdf0
RH
8881 /* When generating abstract instances, ignore everything except
8882 constants and symbols living in memory. */
8883 if (! reload_completed)
8884 {
8885 if (rtl
8886 && (CONSTANT_P (rtl)
8887 || (GET_CODE (rtl) == MEM
8888 && CONSTANT_P (XEXP (rtl, 0)))))
4c8c0dec
JJ
8889 {
8890#ifdef ASM_SIMPLIFY_DWARF_ADDR
8891 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8892#endif
8893 return rtl;
8894 }
c28abdf0
RH
8895 rtl = NULL_RTX;
8896 }
8897 else if (TREE_CODE (decl) == PARM_DECL)
a3f97cbb
JW
8898 {
8899 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8900 {
d8041cc8
RH
8901 tree declared_type = type_main_variant (TREE_TYPE (decl));
8902 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
a3f97cbb 8903
71dfc51f 8904 /* This decl represents a formal parameter which was optimized out.
a3f97cbb 8905 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2ad9852d 8906 all cases where (rtl == NULL_RTX) just below. */
a3f97cbb 8907 if (declared_type == passed_type)
71dfc51f
RK
8908 rtl = DECL_INCOMING_RTL (decl);
8909 else if (! BYTES_BIG_ENDIAN
8910 && TREE_CODE (declared_type) == INTEGER_TYPE
555b6442
HPN
8911 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8912 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
556273e0 8913 rtl = DECL_INCOMING_RTL (decl);
a3f97cbb 8914 }
5a904a61
JW
8915
8916 /* If the parm was passed in registers, but lives on the stack, then
8917 make a big endian correction if the mode of the type of the
8918 parameter is not the same as the mode of the rtl. */
8919 /* ??? This is the same series of checks that are made in dbxout.c before
8920 we reach the big endian correction code there. It isn't clear if all
8921 of these checks are necessary here, but keeping them all is the safe
8922 thing to do. */
8923 else if (GET_CODE (rtl) == MEM
8924 && XEXP (rtl, 0) != const0_rtx
8925 && ! CONSTANT_P (XEXP (rtl, 0))
8926 /* Not passed in memory. */
8927 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8928 /* Not passed by invisible reference. */
8929 && (GET_CODE (XEXP (rtl, 0)) != REG
8930 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8931 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8932#if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8933 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8934#endif
8935 )
8936 /* Big endian correction check. */
8937 && BYTES_BIG_ENDIAN
8938 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8939 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8940 < UNITS_PER_WORD))
8941 {
8942 int offset = (UNITS_PER_WORD
8943 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
2ad9852d 8944
5a904a61
JW
8945 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8946 plus_constant (XEXP (rtl, 0), offset));
8947 }
a3f97cbb 8948 }
71dfc51f 8949
d8041cc8
RH
8950 if (rtl != NULL_RTX)
8951 {
8952 rtl = eliminate_regs (rtl, 0, NULL_RTX);
6a7a9f01 8953#ifdef LEAF_REG_REMAP
d8041cc8
RH
8954 if (current_function_uses_only_leaf_regs)
8955 leaf_renumber_regs_insn (rtl);
6a7a9f01 8956#endif
d8041cc8
RH
8957 }
8958
2ad9852d
RK
8959 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8960 and will have been substituted directly into all expressions that use it.
8961 C does not have such a concept, but C++ and other languages do. */
c28abdf0 8962 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
6d73371a
JJ
8963 {
8964 /* If a variable is initialized with a string constant without embedded
8965 zeros, build CONST_STRING. */
8966 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8967 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
8968 {
8969 tree arrtype = TREE_TYPE (decl);
8970 tree enttype = TREE_TYPE (arrtype);
8971 tree domain = TYPE_DOMAIN (arrtype);
8972 tree init = DECL_INITIAL (decl);
8973 enum machine_mode mode = TYPE_MODE (enttype);
8974
8975 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
8976 && domain
8977 && integer_zerop (TYPE_MIN_VALUE (domain))
8978 && compare_tree_int (TYPE_MAX_VALUE (domain),
8979 TREE_STRING_LENGTH (init) - 1) == 0
8980 && ((size_t) TREE_STRING_LENGTH (init)
8981 == strlen (TREE_STRING_POINTER (init)) + 1))
8982 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
8983 }
29b91443
JM
8984 /* If the initializer is something that we know will expand into an
8985 immediate RTL constant, expand it now. Expanding anything else
8986 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8987 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
8988 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
6d73371a
JJ
8989 {
8990 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8991 EXPAND_INITIALIZER);
29b91443 8992 /* If expand_expr returns a MEM, it wasn't immediate. */
6d73371a 8993 if (rtl && GET_CODE (rtl) == MEM)
29b91443 8994 abort ();
6d73371a
JJ
8995 }
8996 }
8063ddcf 8997
4c8c0dec
JJ
8998#ifdef ASM_SIMPLIFY_DWARF_ADDR
8999 if (rtl)
9000 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
9001#endif
b9203463
RH
9002
9003 /* If we don't look past the constant pool, we risk emitting a
9004 reference to a constant pool entry that isn't referenced from
9005 code, and thus is not emitted. */
9006 if (rtl)
9007 rtl = avoid_constant_pool_reference (rtl);
9008
d8041cc8
RH
9009 return rtl;
9010}
9011
9012/* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
9013 data attribute for a variable or a parameter. We generate the
9014 DW_AT_const_value attribute only in those cases where the given variable
9015 or parameter does not have a true "location" either in memory or in a
9016 register. This can happen (for example) when a constant is passed as an
9017 actual argument in a call to an inline function. (It's possible that
9018 these things can crop up in other ways also.) Note that one type of
9019 constant value which can be passed into an inlined function is a constant
9020 pointer. This can happen for example if an actual argument in an inlined
9021 function call evaluates to a compile-time constant address. */
9022
9023static void
9024add_location_or_const_value_attribute (die, decl)
b3694847
SS
9025 dw_die_ref die;
9026 tree decl;
d8041cc8 9027{
b3694847 9028 rtx rtl;
b9203463 9029 dw_loc_descr_ref descr;
d8041cc8
RH
9030
9031 if (TREE_CODE (decl) == ERROR_MARK)
9032 return;
2ad9852d 9033 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
d8041cc8
RH
9034 abort ();
9035
9036 rtl = rtl_for_decl_location (decl);
a97c9600
RH
9037 if (rtl == NULL_RTX)
9038 return;
6a7a9f01 9039
a3f97cbb
JW
9040 switch (GET_CODE (rtl))
9041 {
e9a25f70 9042 case ADDRESSOF:
b9203463
RH
9043 /* The address of a variable that was optimized away;
9044 don't emit anything. */
e9a25f70
JL
9045 break;
9046
a3f97cbb
JW
9047 case CONST_INT:
9048 case CONST_DOUBLE:
9049 case CONST_STRING:
9050 case SYMBOL_REF:
9051 case LABEL_REF:
9052 case CONST:
9053 case PLUS:
9054 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9055 add_const_value_attribute (die, rtl);
9056 break;
9057
9058 case MEM:
b9203463
RH
9059 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
9060 {
9061 /* Need loc_descriptor_from_tree since that's where we know
9062 how to handle TLS variables. Want the object's address
9063 since the top-level DW_AT_location assumes such. See
9064 the confusion in loc_descriptor for reference. */
9065 descr = loc_descriptor_from_tree (decl, 1);
9066 }
9067 else
9068 {
9069 case REG:
9070 case SUBREG:
9071 case CONCAT:
9072 descr = loc_descriptor (rtl);
9073 }
9074 add_AT_location_description (die, DW_AT_location, descr);
a3f97cbb 9075 break;
b9203463 9076
a3f97cbb 9077 default:
71dfc51f 9078 abort ();
a3f97cbb
JW
9079 }
9080}
9081
1bfb5f8f
JM
9082/* If we don't have a copy of this variable in memory for some reason (such
9083 as a C++ member constant that doesn't have an out-of-line definition),
9084 we should tell the debugger about the constant value. */
9085
9086static void
9087tree_add_const_value_attribute (var_die, decl)
9088 dw_die_ref var_die;
9089 tree decl;
9090{
9091 tree init = DECL_INITIAL (decl);
9092 tree type = TREE_TYPE (decl);
9093
9094 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9095 && initializer_constant_valid_p (init, type) == null_pointer_node)
9096 /* OK */;
9097 else
9098 return;
9099
9100 switch (TREE_CODE (type))
9101 {
9102 case INTEGER_TYPE:
9103 if (host_integerp (init, 0))
9104 add_AT_unsigned (var_die, DW_AT_const_value,
2ad9852d 9105 tree_low_cst (init, 0));
1bfb5f8f
JM
9106 else
9107 add_AT_long_long (var_die, DW_AT_const_value,
9108 TREE_INT_CST_HIGH (init),
9109 TREE_INT_CST_LOW (init));
9110 break;
9111
9112 default:;
9113 }
9114}
0b34cf1e 9115
a3f97cbb
JW
9116/* Generate an DW_AT_name attribute given some string value to be included as
9117 the value of the attribute. */
71dfc51f
RK
9118
9119static inline void
a3f97cbb 9120add_name_attribute (die, name_string)
b3694847
SS
9121 dw_die_ref die;
9122 const char *name_string;
a3f97cbb 9123{
71dfc51f 9124 if (name_string != NULL && *name_string != 0)
14a774a9
RK
9125 {
9126 if (demangle_name_func)
9127 name_string = (*demangle_name_func) (name_string);
9128
9129 add_AT_string (die, DW_AT_name, name_string);
9130 }
a3f97cbb
JW
9131}
9132
9133/* Given a tree node describing an array bound (either lower or upper) output
466446b0 9134 a representation for that bound. */
71dfc51f 9135
a3f97cbb
JW
9136static void
9137add_bound_info (subrange_die, bound_attr, bound)
b3694847
SS
9138 dw_die_ref subrange_die;
9139 enum dwarf_attribute bound_attr;
9140 tree bound;
a3f97cbb 9141{
a3f97cbb
JW
9142 switch (TREE_CODE (bound))
9143 {
9144 case ERROR_MARK:
9145 return;
9146
3ef42a0c 9147 /* All fixed-bounds are represented by INTEGER_CST nodes. */
a3f97cbb 9148 case INTEGER_CST:
665f2503
RK
9149 if (! host_integerp (bound, 0)
9150 || (bound_attr == DW_AT_lower_bound
28985b81 9151 && (((is_c_family () || is_java ()) && integer_zerop (bound))
665f2503
RK
9152 || (is_fortran () && integer_onep (bound)))))
9153 /* use the default */
9154 ;
141719a8 9155 else
665f2503 9156 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
a3f97cbb
JW
9157 break;
9158
b1ccbc24 9159 case CONVERT_EXPR:
a3f97cbb 9160 case NOP_EXPR:
b1ccbc24 9161 case NON_LVALUE_EXPR:
ed239f5a 9162 case VIEW_CONVERT_EXPR:
b1ccbc24
RK
9163 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9164 break;
556273e0 9165
a3f97cbb
JW
9166 case SAVE_EXPR:
9167 /* If optimization is turned on, the SAVE_EXPRs that describe how to
466446b0
JM
9168 access the upper bound values may be bogus. If they refer to a
9169 register, they may only describe how to get at these values at the
9170 points in the generated code right after they have just been
9171 computed. Worse yet, in the typical case, the upper bound values
9172 will not even *be* computed in the optimized code (though the
9173 number of elements will), so these SAVE_EXPRs are entirely
9174 bogus. In order to compensate for this fact, we check here to see
9175 if optimization is enabled, and if so, we don't add an attribute
9176 for the (unknown and unknowable) upper bound. This should not
9177 cause too much trouble for existing (stupid?) debuggers because
9178 they have to deal with empty upper bounds location descriptions
9179 anyway in order to be able to deal with incomplete array types.
9180 Of course an intelligent debugger (GDB?) should be able to
4fe9b91c 9181 comprehend that a missing upper bound specification in an array
466446b0
JM
9182 type used for a storage class `auto' local array variable
9183 indicates that the upper bound is both unknown (at compile- time)
9184 and unknowable (at run-time) due to optimization.
9185
9186 We assume that a MEM rtx is safe because gcc wouldn't put the
9187 value there unless it was going to be used repeatedly in the
9188 function, i.e. for cleanups. */
1edf43d6
JM
9189 if (SAVE_EXPR_RTL (bound)
9190 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
a3f97cbb 9191 {
b3694847 9192 dw_die_ref ctx = lookup_decl_die (current_function_decl);
54ba1f0d 9193 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
b3694847 9194 rtx loc = SAVE_EXPR_RTL (bound);
f5963e61
JL
9195
9196 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9197 it references an outer function's frame. */
f5963e61
JL
9198 if (GET_CODE (loc) == MEM)
9199 {
9200 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9201
9202 if (XEXP (loc, 0) != new_addr)
c5c76735 9203 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
f5963e61
JL
9204 }
9205
466446b0
JM
9206 add_AT_flag (decl_die, DW_AT_artificial, 1);
9207 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
b9203463
RH
9208 add_AT_location_description (decl_die, DW_AT_location,
9209 loc_descriptor (loc));
466446b0 9210 add_AT_die_ref (subrange_die, bound_attr, decl_die);
a3f97cbb 9211 }
71dfc51f
RK
9212
9213 /* Else leave out the attribute. */
a3f97cbb 9214 break;
3f76745e 9215
ef76d03b 9216 case VAR_DECL:
d8041cc8
RH
9217 case PARM_DECL:
9218 {
9219 dw_die_ref decl_die = lookup_decl_die (bound);
9220
9221 /* ??? Can this happen, or should the variable have been bound
9222 first? Probably it can, since I imagine that we try to create
9223 the types of parameters in the order in which they exist in
0b34cf1e 9224 the list, and won't have created a forward reference to a
d8041cc8
RH
9225 later parameter. */
9226 if (decl_die != NULL)
9227 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9228 break;
9229 }
ef76d03b 9230
3f76745e 9231 default:
d8041cc8
RH
9232 {
9233 /* Otherwise try to create a stack operation procedure to
9234 evaluate the value of the array bound. */
9235
9236 dw_die_ref ctx, decl_die;
9237 dw_loc_descr_ref loc;
9238
9239 loc = loc_descriptor_from_tree (bound, 0);
9240 if (loc == NULL)
9241 break;
9242
e7af1d45
RK
9243 if (current_function_decl == 0)
9244 ctx = comp_unit_die;
9245 else
9246 ctx = lookup_decl_die (current_function_decl);
d8041cc8 9247
aea9695c
RK
9248 /* If we weren't able to find a context, it's most likely the case
9249 that we are processing the return type of the function. So
9250 make a SAVE_EXPR to point to it and have the limbo DIE code
9251 find the proper die. The save_expr function doesn't always
9252 make a SAVE_EXPR, so do it ourselves. */
9253 if (ctx == 0)
9254 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9255 current_function_decl, NULL_TREE);
9256
54ba1f0d 9257 decl_die = new_die (DW_TAG_variable, ctx, bound);
d8041cc8
RH
9258 add_AT_flag (decl_die, DW_AT_artificial, 1);
9259 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9260 add_AT_loc (decl_die, DW_AT_location, loc);
9261
9262 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9263 break;
9264 }
a3f97cbb
JW
9265 }
9266}
9267
9268/* Note that the block of subscript information for an array type also
9269 includes information about the element type of type given array type. */
71dfc51f 9270
a3f97cbb
JW
9271static void
9272add_subscript_info (type_die, type)
b3694847
SS
9273 dw_die_ref type_die;
9274 tree type;
a3f97cbb 9275{
081f5e7e 9276#ifndef MIPS_DEBUGGING_INFO
b3694847 9277 unsigned dimension_number;
081f5e7e 9278#endif
b3694847
SS
9279 tree lower, upper;
9280 dw_die_ref subrange_die;
a3f97cbb 9281
556273e0 9282 /* The GNU compilers represent multidimensional array types as sequences of
a3f97cbb
JW
9283 one dimensional array types whose element types are themselves array
9284 types. Here we squish that down, so that each multidimensional array
556273e0 9285 type gets only one array_type DIE in the Dwarf debugging info. The draft
a3f97cbb
JW
9286 Dwarf specification say that we are allowed to do this kind of
9287 compression in C (because there is no difference between an array or
556273e0 9288 arrays and a multidimensional array in C) but for other source languages
a3f97cbb 9289 (e.g. Ada) we probably shouldn't do this. */
71dfc51f 9290
a3f97cbb
JW
9291 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9292 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9293 We work around this by disabling this feature. See also
9294 gen_array_type_die. */
9295#ifndef MIPS_DEBUGGING_INFO
9296 for (dimension_number = 0;
9297 TREE_CODE (type) == ARRAY_TYPE;
9298 type = TREE_TYPE (type), dimension_number++)
a3f97cbb 9299#endif
2ad9852d 9300 {
b3694847 9301 tree domain = TYPE_DOMAIN (type);
a3f97cbb
JW
9302
9303 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
556273e0 9304 and (in GNU C only) variable bounds. Handle all three forms
a3f97cbb 9305 here. */
54ba1f0d 9306 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
a3f97cbb
JW
9307 if (domain)
9308 {
9309 /* We have an array type with specified bounds. */
9310 lower = TYPE_MIN_VALUE (domain);
9311 upper = TYPE_MAX_VALUE (domain);
9312
a9d38797
JM
9313 /* define the index type. */
9314 if (TREE_TYPE (domain))
ef76d03b
JW
9315 {
9316 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9317 TREE_TYPE field. We can't emit debug info for this
9318 because it is an unnamed integral type. */
9319 if (TREE_CODE (domain) == INTEGER_TYPE
9320 && TYPE_NAME (domain) == NULL_TREE
9321 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9322 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
556273e0 9323 ;
ef76d03b
JW
9324 else
9325 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9326 type_die);
9327 }
a9d38797 9328
e1ee5cdc
RH
9329 /* ??? If upper is NULL, the array has unspecified length,
9330 but it does have a lower bound. This happens with Fortran
9331 dimension arr(N:*)
9332 Since the debugger is definitely going to need to know N
9333 to produce useful results, go ahead and output the lower
9334 bound solo, and hope the debugger can cope. */
9335
141719a8 9336 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
e1ee5cdc
RH
9337 if (upper)
9338 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
a3f97cbb 9339 }
71dfc51f 9340
2ad9852d
RK
9341 /* Otherwise we have an array type with an unspecified length. The
9342 DWARF-2 spec does not say how to handle this; let's just leave out the
9343 bounds. */
a3f97cbb 9344 }
a3f97cbb
JW
9345}
9346
9347static void
9348add_byte_size_attribute (die, tree_node)
9349 dw_die_ref die;
b3694847 9350 tree tree_node;
a3f97cbb 9351{
b3694847 9352 unsigned size;
a3f97cbb
JW
9353
9354 switch (TREE_CODE (tree_node))
9355 {
9356 case ERROR_MARK:
9357 size = 0;
9358 break;
9359 case ENUMERAL_TYPE:
9360 case RECORD_TYPE:
9361 case UNION_TYPE:
9362 case QUAL_UNION_TYPE:
9363 size = int_size_in_bytes (tree_node);
9364 break;
9365 case FIELD_DECL:
9366 /* For a data member of a struct or union, the DW_AT_byte_size is
9367 generally given as the number of bytes normally allocated for an
9368 object of the *declared* type of the member itself. This is true
9369 even for bit-fields. */
9370 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9371 break;
9372 default:
9373 abort ();
9374 }
9375
9376 /* Note that `size' might be -1 when we get to this point. If it is, that
9377 indicates that the byte size of the entity in question is variable. We
9378 have no good way of expressing this fact in Dwarf at the present time,
9379 so just let the -1 pass on through. */
a3f97cbb
JW
9380 add_AT_unsigned (die, DW_AT_byte_size, size);
9381}
9382
9383/* For a FIELD_DECL node which represents a bit-field, output an attribute
9384 which specifies the distance in bits from the highest order bit of the
9385 "containing object" for the bit-field to the highest order bit of the
9386 bit-field itself.
9387
2ad9852d
RK
9388 For any given bit-field, the "containing object" is a hypothetical object
9389 (of some integral or enum type) within which the given bit-field lives. The
9390 type of this hypothetical "containing object" is always the same as the
9391 declared type of the individual bit-field itself. The determination of the
9392 exact location of the "containing object" for a bit-field is rather
9393 complicated. It's handled by the `field_byte_offset' function (above).
a3f97cbb
JW
9394
9395 Note that it is the size (in bytes) of the hypothetical "containing object"
9396 which will be given in the DW_AT_byte_size attribute for this bit-field.
9397 (See `byte_size_attribute' above). */
71dfc51f
RK
9398
9399static inline void
a3f97cbb 9400add_bit_offset_attribute (die, decl)
b3694847
SS
9401 dw_die_ref die;
9402 tree decl;
a3f97cbb 9403{
665f2503
RK
9404 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9405 tree type = DECL_BIT_FIELD_TYPE (decl);
9406 HOST_WIDE_INT bitpos_int;
9407 HOST_WIDE_INT highest_order_object_bit_offset;
9408 HOST_WIDE_INT highest_order_field_bit_offset;
9409 HOST_WIDE_INT unsigned bit_offset;
a3f97cbb 9410
3a88cbd1
JL
9411 /* Must be a field and a bit field. */
9412 if (!type
9413 || TREE_CODE (decl) != FIELD_DECL)
9414 abort ();
a3f97cbb
JW
9415
9416 /* We can't yet handle bit-fields whose offsets are variable, so if we
9417 encounter such things, just return without generating any attribute
665f2503
RK
9418 whatsoever. Likewise for variable or too large size. */
9419 if (! host_integerp (bit_position (decl), 0)
9420 || ! host_integerp (DECL_SIZE (decl), 1))
71dfc51f
RK
9421 return;
9422
665f2503 9423 bitpos_int = int_bit_position (decl);
a3f97cbb
JW
9424
9425 /* Note that the bit offset is always the distance (in bits) from the
556273e0
KH
9426 highest-order bit of the "containing object" to the highest-order bit of
9427 the bit-field itself. Since the "high-order end" of any object or field
a3f97cbb
JW
9428 is different on big-endian and little-endian machines, the computation
9429 below must take account of these differences. */
9430 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9431 highest_order_field_bit_offset = bitpos_int;
9432
71dfc51f 9433 if (! BYTES_BIG_ENDIAN)
a3f97cbb 9434 {
665f2503 9435 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
a3f97cbb
JW
9436 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9437 }
71dfc51f
RK
9438
9439 bit_offset
9440 = (! BYTES_BIG_ENDIAN
9441 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9442 : highest_order_field_bit_offset - highest_order_object_bit_offset);
a3f97cbb
JW
9443
9444 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9445}
9446
9447/* For a FIELD_DECL node which represents a bit field, output an attribute
9448 which specifies the length in bits of the given field. */
71dfc51f
RK
9449
9450static inline void
a3f97cbb 9451add_bit_size_attribute (die, decl)
b3694847
SS
9452 dw_die_ref die;
9453 tree decl;
a3f97cbb 9454{
3a88cbd1
JL
9455 /* Must be a field and a bit field. */
9456 if (TREE_CODE (decl) != FIELD_DECL
9457 || ! DECL_BIT_FIELD_TYPE (decl))
9458 abort ();
665f2503
RK
9459
9460 if (host_integerp (DECL_SIZE (decl), 1))
9461 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
a3f97cbb
JW
9462}
9463
88dad228 9464/* If the compiled language is ANSI C, then add a 'prototyped'
a3f97cbb 9465 attribute, if arg types are given for the parameters of a function. */
71dfc51f
RK
9466
9467static inline void
a3f97cbb 9468add_prototyped_attribute (die, func_type)
b3694847
SS
9469 dw_die_ref die;
9470 tree func_type;
a3f97cbb 9471{
88dad228
JM
9472 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9473 && TYPE_ARG_TYPES (func_type) != NULL)
9474 add_AT_flag (die, DW_AT_prototyped, 1);
a3f97cbb
JW
9475}
9476
a3f97cbb
JW
9477/* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9478 by looking in either the type declaration or object declaration
9479 equate table. */
71dfc51f
RK
9480
9481static inline void
a3f97cbb 9482add_abstract_origin_attribute (die, origin)
b3694847
SS
9483 dw_die_ref die;
9484 tree origin;
a3f97cbb
JW
9485{
9486 dw_die_ref origin_die = NULL;
bbc6ae08 9487
d10b8e05 9488 if (TREE_CODE (origin) != FUNCTION_DECL)
e40a1c67
JM
9489 {
9490 /* We may have gotten separated from the block for the inlined
9491 function, if we're in an exception handler or some such; make
9492 sure that the abstract function has been written out.
9493
9494 Doing this for nested functions is wrong, however; functions are
9495 distinct units, and our context might not even be inline. */
fb13d4d0 9496 tree fn = origin;
2ad9852d 9497
fb13d4d0
JM
9498 if (TYPE_P (fn))
9499 fn = TYPE_STUB_DECL (fn);
2ad9852d 9500
fb13d4d0 9501 fn = decl_function_context (fn);
e40a1c67 9502 if (fn)
1edf43d6 9503 dwarf2out_abstract_function (fn);
e40a1c67 9504 }
44db1d9c 9505
2f939d94 9506 if (DECL_P (origin))
71dfc51f 9507 origin_die = lookup_decl_die (origin);
2f939d94 9508 else if (TYPE_P (origin))
71dfc51f
RK
9509 origin_die = lookup_type_die (origin);
9510
bbc6ae08 9511 if (origin_die == NULL)
1ae8994f 9512 abort ();
556273e0 9513
a3f97cbb
JW
9514 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9515}
9516
bdb669cb
JM
9517/* We do not currently support the pure_virtual attribute. */
9518
71dfc51f 9519static inline void
a3f97cbb 9520add_pure_or_virtual_attribute (die, func_decl)
b3694847
SS
9521 dw_die_ref die;
9522 tree func_decl;
a3f97cbb 9523{
a94dbf2c 9524 if (DECL_VINDEX (func_decl))
a3f97cbb 9525 {
bdb669cb 9526 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
665f2503
RK
9527
9528 if (host_integerp (DECL_VINDEX (func_decl), 0))
9529 add_AT_loc (die, DW_AT_vtable_elem_location,
9530 new_loc_descr (DW_OP_constu,
9531 tree_low_cst (DECL_VINDEX (func_decl), 0),
9532 0));
71dfc51f 9533
a94dbf2c
JM
9534 /* GNU extension: Record what type this method came from originally. */
9535 if (debug_info_level > DINFO_LEVEL_TERSE)
9536 add_AT_die_ref (die, DW_AT_containing_type,
9537 lookup_type_die (DECL_CONTEXT (func_decl)));
a3f97cbb
JW
9538 }
9539}
9540\f
b2932ae5 9541/* Add source coordinate attributes for the given decl. */
71dfc51f 9542
b2932ae5
JM
9543static void
9544add_src_coords_attributes (die, decl)
b3694847
SS
9545 dw_die_ref die;
9546 tree decl;
b2932ae5 9547{
b3694847 9548 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
71dfc51f 9549
b2932ae5
JM
9550 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9551 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9552}
9553
a3f97cbb
JW
9554/* Add an DW_AT_name attribute and source coordinate attribute for the
9555 given decl, but only if it actually has a name. */
71dfc51f 9556
a3f97cbb
JW
9557static void
9558add_name_and_src_coords_attributes (die, decl)
b3694847
SS
9559 dw_die_ref die;
9560 tree decl;
a3f97cbb 9561{
b3694847 9562 tree decl_name;
71dfc51f 9563
556273e0 9564 decl_name = DECL_NAME (decl);
71dfc51f 9565 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
a3f97cbb 9566 {
a1d7ffe3 9567 add_name_attribute (die, dwarf2_name (decl, 0));
a96c67ec
JM
9568 if (! DECL_ARTIFICIAL (decl))
9569 add_src_coords_attributes (die, decl);
e689ae67 9570
a1d7ffe3 9571 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
bc808e0b 9572 && TREE_PUBLIC (decl)
5daf7c0a
JM
9573 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9574 && !DECL_ABSTRACT (decl))
a1d7ffe3
JM
9575 add_AT_string (die, DW_AT_MIPS_linkage_name,
9576 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
a3f97cbb 9577 }
7a0c8d71
DR
9578
9579#ifdef VMS_DEBUGGING_INFO
7a0c8d71
DR
9580 /* Get the function's name, as described by its RTL. This may be different
9581 from the DECL_NAME name used in the source file. */
9582 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
c470afad
RK
9583 {
9584 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9585 XEXP (DECL_RTL (decl), 0));
9586 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9587 }
7a0c8d71 9588#endif
a3f97cbb
JW
9589}
9590
556273e0 9591/* Push a new declaration scope. */
71dfc51f 9592
a3f97cbb
JW
9593static void
9594push_decl_scope (scope)
9595 tree scope;
9596{
244a4af0 9597 VARRAY_PUSH_TREE (decl_scope_table, scope);
a3f97cbb
JW
9598}
9599
777ad4c2 9600/* Pop a declaration scope. */
2ad9852d 9601
777ad4c2
JM
9602static inline void
9603pop_decl_scope ()
9604{
244a4af0 9605 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
777ad4c2 9606 abort ();
2ad9852d 9607
244a4af0 9608 VARRAY_POP (decl_scope_table);
777ad4c2
JM
9609}
9610
9611/* Return the DIE for the scope that immediately contains this type.
9612 Non-named types get global scope. Named types nested in other
9613 types get their containing scope if it's open, or global scope
9614 otherwise. All other types (i.e. function-local named types) get
9615 the current active scope. */
71dfc51f 9616
a3f97cbb 9617static dw_die_ref
ab72d377 9618scope_die_for (t, context_die)
b3694847
SS
9619 tree t;
9620 dw_die_ref context_die;
a3f97cbb 9621{
b3694847
SS
9622 dw_die_ref scope_die = NULL;
9623 tree containing_scope;
9624 int i;
a3f97cbb 9625
777ad4c2
JM
9626 /* Non-types always go in the current scope. */
9627 if (! TYPE_P (t))
9628 abort ();
9629
9630 containing_scope = TYPE_CONTEXT (t);
ab72d377 9631
2addbe1d
JM
9632 /* Ignore namespaces for the moment. */
9633 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9634 containing_scope = NULL_TREE;
9635
5f2f160c
JM
9636 /* Ignore function type "scopes" from the C frontend. They mean that
9637 a tagged type is local to a parmlist of a function declarator, but
9638 that isn't useful to DWARF. */
9639 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9640 containing_scope = NULL_TREE;
9641
71dfc51f
RK
9642 if (containing_scope == NULL_TREE)
9643 scope_die = comp_unit_die;
777ad4c2 9644 else if (TYPE_P (containing_scope))
348bb3c7 9645 {
777ad4c2
JM
9646 /* For types, we can just look up the appropriate DIE. But
9647 first we check to see if we're in the middle of emitting it
9648 so we know where the new DIE should go. */
244a4af0
TF
9649 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9650 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
348bb3c7
JM
9651 break;
9652
9653 if (i < 0)
9654 {
348bb3c7
JM
9655 if (debug_info_level > DINFO_LEVEL_TERSE
9656 && !TREE_ASM_WRITTEN (containing_scope))
9657 abort ();
9658
9659 /* If none of the current dies are suitable, we get file scope. */
9660 scope_die = comp_unit_die;
9661 }
9662 else
777ad4c2 9663 scope_die = lookup_type_die (containing_scope);
348bb3c7 9664 }
a3f97cbb 9665 else
777ad4c2 9666 scope_die = context_die;
71dfc51f 9667
a3f97cbb
JW
9668 return scope_die;
9669}
9670
2ad9852d 9671/* Returns nonzero if CONTEXT_DIE is internal to a function. */
777ad4c2
JM
9672
9673static inline int
9674local_scope_p (context_die)
9675 dw_die_ref context_die;
a3f97cbb 9676{
777ad4c2
JM
9677 for (; context_die; context_die = context_die->die_parent)
9678 if (context_die->die_tag == DW_TAG_inlined_subroutine
9679 || context_die->die_tag == DW_TAG_subprogram)
9680 return 1;
2ad9852d 9681
777ad4c2 9682 return 0;
a3f97cbb
JW
9683}
9684
2ad9852d 9685/* Returns nonzero if CONTEXT_DIE is a class. */
9765e357
JM
9686
9687static inline int
9688class_scope_p (context_die)
9689 dw_die_ref context_die;
9690{
9691 return (context_die
9692 && (context_die->die_tag == DW_TAG_structure_type
9693 || context_die->die_tag == DW_TAG_union_type));
9694}
9695
a3f97cbb
JW
9696/* Many forms of DIEs require a "type description" attribute. This
9697 routine locates the proper "type descriptor" die for the type given
9698 by 'type', and adds an DW_AT_type attribute below the given die. */
71dfc51f 9699
a3f97cbb
JW
9700static void
9701add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
b3694847
SS
9702 dw_die_ref object_die;
9703 tree type;
9704 int decl_const;
9705 int decl_volatile;
9706 dw_die_ref context_die;
a3f97cbb 9707{
b3694847
SS
9708 enum tree_code code = TREE_CODE (type);
9709 dw_die_ref type_die = NULL;
a3f97cbb 9710
ef76d03b
JW
9711 /* ??? If this type is an unnamed subrange type of an integral or
9712 floating-point type, use the inner type. This is because we have no
9713 support for unnamed types in base_type_die. This can happen if this is
9714 an Ada subrange type. Correct solution is emit a subrange type die. */
b1ccbc24
RK
9715 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9716 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9717 type = TREE_TYPE (type), code = TREE_CODE (type);
9718
2ad9852d
RK
9719 if (code == ERROR_MARK
9720 /* Handle a special case. For functions whose return type is void, we
9721 generate *no* type attribute. (Note that no object may have type
9722 `void', so this only applies to function return types). */
9723 || code == VOID_TYPE)
b1ccbc24 9724 return;
a3f97cbb 9725
a3f97cbb
JW
9726 type_die = modified_type_die (type,
9727 decl_const || TYPE_READONLY (type),
9728 decl_volatile || TYPE_VOLATILE (type),
ab72d377 9729 context_die);
2ad9852d 9730
a3f97cbb 9731 if (type_die != NULL)
71dfc51f 9732 add_AT_die_ref (object_die, DW_AT_type, type_die);
a3f97cbb
JW
9733}
9734
9735/* Given a tree pointer to a struct, class, union, or enum type node, return
9736 a pointer to the (string) tag name for the given type, or zero if the type
9737 was declared without a tag. */
71dfc51f 9738
d3e3972c 9739static const char *
a3f97cbb 9740type_tag (type)
b3694847 9741 tree type;
a3f97cbb 9742{
b3694847 9743 const char *name = 0;
a3f97cbb
JW
9744
9745 if (TYPE_NAME (type) != 0)
9746 {
b3694847 9747 tree t = 0;
a3f97cbb
JW
9748
9749 /* Find the IDENTIFIER_NODE for the type name. */
9750 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9751 t = TYPE_NAME (type);
bdb669cb 9752
556273e0 9753 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
a3f97cbb 9754 a TYPE_DECL node, regardless of whether or not a `typedef' was
bdb669cb 9755 involved. */
a94dbf2c
JM
9756 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9757 && ! DECL_IGNORED_P (TYPE_NAME (type)))
a3f97cbb 9758 t = DECL_NAME (TYPE_NAME (type));
bdb669cb 9759
a3f97cbb
JW
9760 /* Now get the name as a string, or invent one. */
9761 if (t != 0)
a94dbf2c 9762 name = IDENTIFIER_POINTER (t);
a3f97cbb 9763 }
71dfc51f 9764
a3f97cbb
JW
9765 return (name == 0 || *name == '\0') ? 0 : name;
9766}
9767
9768/* Return the type associated with a data member, make a special check
9769 for bit field types. */
71dfc51f
RK
9770
9771static inline tree
a3f97cbb 9772member_declared_type (member)
b3694847 9773 tree member;
a3f97cbb 9774{
71dfc51f 9775 return (DECL_BIT_FIELD_TYPE (member)
2ad9852d 9776 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
a3f97cbb
JW
9777}
9778
d291dd49 9779/* Get the decl's label, as described by its RTL. This may be different
a3f97cbb 9780 from the DECL_NAME name used in the source file. */
71dfc51f 9781
487a6e06 9782#if 0
d3e3972c 9783static const char *
d291dd49 9784decl_start_label (decl)
b3694847 9785 tree decl;
a3f97cbb
JW
9786{
9787 rtx x;
d3e3972c 9788 const char *fnname;
2ad9852d 9789
a3f97cbb
JW
9790 x = DECL_RTL (decl);
9791 if (GET_CODE (x) != MEM)
71dfc51f
RK
9792 abort ();
9793
a3f97cbb
JW
9794 x = XEXP (x, 0);
9795 if (GET_CODE (x) != SYMBOL_REF)
71dfc51f
RK
9796 abort ();
9797
a3f97cbb
JW
9798 fnname = XSTR (x, 0);
9799 return fnname;
9800}
487a6e06 9801#endif
a3f97cbb 9802\f
956d6950 9803/* These routines generate the internal representation of the DIE's for
a3f97cbb 9804 the compilation unit. Debugging information is collected by walking
88dad228 9805 the declaration trees passed in from dwarf2out_decl(). */
a3f97cbb
JW
9806
9807static void
9808gen_array_type_die (type, context_die)
b3694847
SS
9809 tree type;
9810 dw_die_ref context_die;
a3f97cbb 9811{
b3694847
SS
9812 dw_die_ref scope_die = scope_die_for (type, context_die);
9813 dw_die_ref array_die;
9814 tree element_type;
bdb669cb 9815
a9d38797
JM
9816 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9817 the inner array type comes before the outer array type. Thus we must
9818 call gen_type_die before we call new_die. See below also. */
9819#ifdef MIPS_DEBUGGING_INFO
9820 gen_type_die (TREE_TYPE (type), context_die);
9821#endif
9822
54ba1f0d 9823 array_die = new_die (DW_TAG_array_type, scope_die, type);
84f0ace0
JM
9824 add_name_attribute (array_die, type_tag (type));
9825 equate_type_number_to_die (type, array_die);
9826
9827 if (TREE_CODE (type) == VECTOR_TYPE)
9828 {
9829 /* The frontend feeds us a representation for the vector as a struct
9830 containing an array. Pull out the array type. */
9831 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
9832 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
9833 }
a9d38797 9834
a3f97cbb
JW
9835#if 0
9836 /* We default the array ordering. SDB will probably do
9837 the right things even if DW_AT_ordering is not present. It's not even
9838 an issue until we start to get into multidimensional arrays anyway. If
9839 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9840 then we'll have to put the DW_AT_ordering attribute back in. (But if
9841 and when we find out that we need to put these in, we will only do so
9842 for multidimensional arrays. */
9843 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9844#endif
9845
a9d38797 9846#ifdef MIPS_DEBUGGING_INFO
4edb7b60
JM
9847 /* The SGI compilers handle arrays of unknown bound by setting
9848 AT_declaration and not emitting any subrange DIEs. */
a9d38797
JM
9849 if (! TYPE_DOMAIN (type))
9850 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9851 else
9852#endif
9853 add_subscript_info (array_die, type);
a3f97cbb 9854
a3f97cbb
JW
9855 /* Add representation of the type of the elements of this array type. */
9856 element_type = TREE_TYPE (type);
71dfc51f 9857
a3f97cbb
JW
9858 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9859 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9860 We work around this by disabling this feature. See also
9861 add_subscript_info. */
9862#ifndef MIPS_DEBUGGING_INFO
71dfc51f
RK
9863 while (TREE_CODE (element_type) == ARRAY_TYPE)
9864 element_type = TREE_TYPE (element_type);
9865
a3f97cbb 9866 gen_type_die (element_type, context_die);
a9d38797 9867#endif
a3f97cbb
JW
9868
9869 add_type_attribute (array_die, element_type, 0, 0, context_die);
9870}
9871
9872static void
9873gen_set_type_die (type, context_die)
b3694847
SS
9874 tree type;
9875 dw_die_ref context_die;
a3f97cbb 9876{
b3694847 9877 dw_die_ref type_die
54ba1f0d 9878 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
71dfc51f 9879
a3f97cbb 9880 equate_type_number_to_die (type, type_die);
a3f97cbb
JW
9881 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9882}
9883
d6f4ec51 9884#if 0
a3f97cbb
JW
9885static void
9886gen_entry_point_die (decl, context_die)
b3694847
SS
9887 tree decl;
9888 dw_die_ref context_die;
a3f97cbb 9889{
b3694847 9890 tree origin = decl_ultimate_origin (decl);
54ba1f0d 9891 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
2ad9852d 9892
a3f97cbb 9893 if (origin != NULL)
71dfc51f 9894 add_abstract_origin_attribute (decl_die, origin);
a3f97cbb
JW
9895 else
9896 {
9897 add_name_and_src_coords_attributes (decl_die, decl);
a3f97cbb
JW
9898 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9899 0, 0, context_die);
9900 }
71dfc51f 9901
a3f97cbb 9902 if (DECL_ABSTRACT (decl))
71dfc51f 9903 equate_decl_number_to_die (decl, decl_die);
a3f97cbb 9904 else
71dfc51f 9905 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
a3f97cbb 9906}
d6f4ec51 9907#endif
a3f97cbb 9908
8a8c3656
JM
9909/* Walk through the list of incomplete types again, trying once more to
9910 emit full debugging info for them. */
9911
9912static void
9913retry_incomplete_types ()
9914{
244a4af0 9915 int i;
2ad9852d 9916
244a4af0 9917 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
2ad9852d 9918 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
8a8c3656
JM
9919}
9920
a3f97cbb 9921/* Generate a DIE to represent an inlined instance of an enumeration type. */
71dfc51f 9922
a3f97cbb
JW
9923static void
9924gen_inlined_enumeration_type_die (type, context_die)
b3694847
SS
9925 tree type;
9926 dw_die_ref context_die;
a3f97cbb 9927{
54ba1f0d 9928 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
2ad9852d 9929
bbc6ae08
NC
9930 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9931 be incomplete and such types are not marked. */
a3f97cbb
JW
9932 add_abstract_origin_attribute (type_die, type);
9933}
9934
9935/* Generate a DIE to represent an inlined instance of a structure type. */
71dfc51f 9936
a3f97cbb
JW
9937static void
9938gen_inlined_structure_type_die (type, context_die)
b3694847
SS
9939 tree type;
9940 dw_die_ref context_die;
a3f97cbb 9941{
54ba1f0d 9942 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
777ad4c2 9943
bbc6ae08
NC
9944 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9945 be incomplete and such types are not marked. */
a3f97cbb
JW
9946 add_abstract_origin_attribute (type_die, type);
9947}
9948
9949/* Generate a DIE to represent an inlined instance of a union type. */
71dfc51f 9950
a3f97cbb
JW
9951static void
9952gen_inlined_union_type_die (type, context_die)
b3694847
SS
9953 tree type;
9954 dw_die_ref context_die;
a3f97cbb 9955{
54ba1f0d 9956 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
777ad4c2 9957
bbc6ae08
NC
9958 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9959 be incomplete and such types are not marked. */
a3f97cbb
JW
9960 add_abstract_origin_attribute (type_die, type);
9961}
9962
9963/* Generate a DIE to represent an enumeration type. Note that these DIEs
9964 include all of the information about the enumeration values also. Each
273dbe67
JM
9965 enumerated type name/value is listed as a child of the enumerated type
9966 DIE. */
71dfc51f 9967
a3f97cbb 9968static void
273dbe67 9969gen_enumeration_type_die (type, context_die)
b3694847
SS
9970 tree type;
9971 dw_die_ref context_die;
a3f97cbb 9972{
b3694847 9973 dw_die_ref type_die = lookup_type_die (type);
273dbe67 9974
a3f97cbb
JW
9975 if (type_die == NULL)
9976 {
9977 type_die = new_die (DW_TAG_enumeration_type,
54ba1f0d 9978 scope_die_for (type, context_die), type);
a3f97cbb
JW
9979 equate_type_number_to_die (type, type_die);
9980 add_name_attribute (type_die, type_tag (type));
a3f97cbb 9981 }
273dbe67
JM
9982 else if (! TYPE_SIZE (type))
9983 return;
9984 else
9985 remove_AT (type_die, DW_AT_declaration);
9986
9987 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9988 given enum type is incomplete, do not generate the DW_AT_byte_size
9989 attribute or the DW_AT_element_list attribute. */
9990 if (TYPE_SIZE (type))
a3f97cbb 9991 {
b3694847 9992 tree link;
71dfc51f 9993
a082c85a 9994 TREE_ASM_WRITTEN (type) = 1;
273dbe67 9995 add_byte_size_attribute (type_die, type);
e9a25f70 9996 if (TYPE_STUB_DECL (type) != NULL_TREE)
b2932ae5 9997 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
71dfc51f 9998
ef76d03b
JW
9999 /* If the first reference to this type was as the return type of an
10000 inline function, then it may not have a parent. Fix this now. */
10001 if (type_die->die_parent == NULL)
10002 add_child_die (scope_die_for (type, context_die), type_die);
10003
273dbe67
JM
10004 for (link = TYPE_FIELDS (type);
10005 link != NULL; link = TREE_CHAIN (link))
a3f97cbb 10006 {
54ba1f0d 10007 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
71dfc51f 10008
273dbe67
JM
10009 add_name_attribute (enum_die,
10010 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
665f2503
RK
10011
10012 if (host_integerp (TREE_VALUE (link), 0))
fc9e8a14
JJ
10013 {
10014 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
10015 add_AT_int (enum_die, DW_AT_const_value,
10016 tree_low_cst (TREE_VALUE (link), 0));
10017 else
10018 add_AT_unsigned (enum_die, DW_AT_const_value,
10019 tree_low_cst (TREE_VALUE (link), 0));
10020 }
a3f97cbb
JW
10021 }
10022 }
273dbe67
JM
10023 else
10024 add_AT_flag (type_die, DW_AT_declaration, 1);
a3f97cbb
JW
10025}
10026
a3f97cbb
JW
10027/* Generate a DIE to represent either a real live formal parameter decl or to
10028 represent just the type of some formal parameter position in some function
10029 type.
71dfc51f 10030
a3f97cbb
JW
10031 Note that this routine is a bit unusual because its argument may be a
10032 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10033 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10034 node. If it's the former then this function is being called to output a
10035 DIE to represent a formal parameter object (or some inlining thereof). If
10036 it's the latter, then this function is only being called to output a
10037 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10038 argument type of some subprogram type. */
71dfc51f 10039
a94dbf2c 10040static dw_die_ref
a3f97cbb 10041gen_formal_parameter_die (node, context_die)
b3694847
SS
10042 tree node;
10043 dw_die_ref context_die;
a3f97cbb 10044{
b3694847 10045 dw_die_ref parm_die
54ba1f0d 10046 = new_die (DW_TAG_formal_parameter, context_die, node);
b3694847 10047 tree origin;
71dfc51f 10048
a3f97cbb
JW
10049 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10050 {
a3f97cbb
JW
10051 case 'd':
10052 origin = decl_ultimate_origin (node);
10053 if (origin != NULL)
a94dbf2c 10054 add_abstract_origin_attribute (parm_die, origin);
a3f97cbb
JW
10055 else
10056 {
10057 add_name_and_src_coords_attributes (parm_die, node);
10058 add_type_attribute (parm_die, TREE_TYPE (node),
10059 TREE_READONLY (node),
10060 TREE_THIS_VOLATILE (node),
10061 context_die);
bdb669cb
JM
10062 if (DECL_ARTIFICIAL (node))
10063 add_AT_flag (parm_die, DW_AT_artificial, 1);
a3f97cbb 10064 }
71dfc51f 10065
141719a8
JM
10066 equate_decl_number_to_die (node, parm_die);
10067 if (! DECL_ABSTRACT (node))
a94dbf2c 10068 add_location_or_const_value_attribute (parm_die, node);
71dfc51f 10069
a3f97cbb
JW
10070 break;
10071
a3f97cbb 10072 case 't':
71dfc51f 10073 /* We were called with some kind of a ..._TYPE node. */
a3f97cbb
JW
10074 add_type_attribute (parm_die, node, 0, 0, context_die);
10075 break;
10076
a3f97cbb
JW
10077 default:
10078 abort ();
10079 }
71dfc51f 10080
a94dbf2c 10081 return parm_die;
a3f97cbb
JW
10082}
10083
10084/* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10085 at the end of an (ANSI prototyped) formal parameters list. */
71dfc51f 10086
a3f97cbb
JW
10087static void
10088gen_unspecified_parameters_die (decl_or_type, context_die)
54ba1f0d 10089 tree decl_or_type;
b3694847 10090 dw_die_ref context_die;
a3f97cbb 10091{
54ba1f0d 10092 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
a3f97cbb
JW
10093}
10094
10095/* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10096 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10097 parameters as specified in some function type specification (except for
1cfdcc15 10098 those which appear as part of a function *definition*). */
71dfc51f 10099
a3f97cbb
JW
10100static void
10101gen_formal_types_die (function_or_method_type, context_die)
b3694847
SS
10102 tree function_or_method_type;
10103 dw_die_ref context_die;
a3f97cbb 10104{
b3694847
SS
10105 tree link;
10106 tree formal_type = NULL;
10107 tree first_parm_type;
5daf7c0a 10108 tree arg;
a3f97cbb 10109
5daf7c0a
JM
10110 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10111 {
10112 arg = DECL_ARGUMENTS (function_or_method_type);
10113 function_or_method_type = TREE_TYPE (function_or_method_type);
10114 }
10115 else
10116 arg = NULL_TREE;
c26fbbca 10117
5daf7c0a 10118 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
a3f97cbb 10119
556273e0 10120 /* Make our first pass over the list of formal parameter types and output a
a3f97cbb 10121 DW_TAG_formal_parameter DIE for each one. */
5daf7c0a 10122 for (link = first_parm_type; link; )
a3f97cbb 10123 {
b3694847 10124 dw_die_ref parm_die;
556273e0 10125
a3f97cbb
JW
10126 formal_type = TREE_VALUE (link);
10127 if (formal_type == void_type_node)
10128 break;
10129
10130 /* Output a (nameless) DIE to represent the formal parameter itself. */
a94dbf2c 10131 parm_die = gen_formal_parameter_die (formal_type, context_die);
5daf7c0a
JM
10132 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10133 && link == first_parm_type)
10134 || (arg && DECL_ARTIFICIAL (arg)))
a94dbf2c 10135 add_AT_flag (parm_die, DW_AT_artificial, 1);
5daf7c0a
JM
10136
10137 link = TREE_CHAIN (link);
10138 if (arg)
10139 arg = TREE_CHAIN (arg);
a3f97cbb
JW
10140 }
10141
10142 /* If this function type has an ellipsis, add a
10143 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10144 if (formal_type != void_type_node)
10145 gen_unspecified_parameters_die (function_or_method_type, context_die);
10146
556273e0 10147 /* Make our second (and final) pass over the list of formal parameter types
a3f97cbb
JW
10148 and output DIEs to represent those types (as necessary). */
10149 for (link = TYPE_ARG_TYPES (function_or_method_type);
2ad9852d 10150 link && TREE_VALUE (link);
a3f97cbb 10151 link = TREE_CHAIN (link))
2ad9852d 10152 gen_type_die (TREE_VALUE (link), context_die);
a3f97cbb
JW
10153}
10154
10a11b75
JM
10155/* We want to generate the DIE for TYPE so that we can generate the
10156 die for MEMBER, which has been defined; we will need to refer back
10157 to the member declaration nested within TYPE. If we're trying to
10158 generate minimal debug info for TYPE, processing TYPE won't do the
10159 trick; we need to attach the member declaration by hand. */
10160
10161static void
10162gen_type_die_for_member (type, member, context_die)
10163 tree type, member;
10164 dw_die_ref context_die;
10165{
10166 gen_type_die (type, context_die);
10167
10168 /* If we're trying to avoid duplicate debug info, we may not have
10169 emitted the member decl for this function. Emit it now. */
10170 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10171 && ! lookup_decl_die (member))
10172 {
10173 if (decl_ultimate_origin (member))
10174 abort ();
10175
10176 push_decl_scope (type);
10177 if (TREE_CODE (member) == FUNCTION_DECL)
10178 gen_subprogram_die (member, lookup_type_die (type));
10179 else
10180 gen_variable_die (member, lookup_type_die (type));
2ad9852d 10181
10a11b75
JM
10182 pop_decl_scope ();
10183 }
10184}
10185
2ad9852d
RK
10186/* Generate the DWARF2 info for the "abstract" instance of a function which we
10187 may later generate inlined and/or out-of-line instances of. */
10a11b75 10188
e1772ac0 10189static void
1edf43d6 10190dwarf2out_abstract_function (decl)
10a11b75
JM
10191 tree decl;
10192{
b3694847 10193 dw_die_ref old_die;
777ad4c2 10194 tree save_fn;
5daf7c0a
JM
10195 tree context;
10196 int was_abstract = DECL_ABSTRACT (decl);
10197
10198 /* Make sure we have the actual abstract inline, not a clone. */
10199 decl = DECL_ORIGIN (decl);
10a11b75 10200
c26fbbca 10201 old_die = lookup_decl_die (decl);
10a11b75
JM
10202 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10203 /* We've already generated the abstract instance. */
10204 return;
10205
5daf7c0a
JM
10206 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10207 we don't get confused by DECL_ABSTRACT. */
8458e954
JS
10208 if (debug_info_level > DINFO_LEVEL_TERSE)
10209 {
10210 context = decl_class_context (decl);
10211 if (context)
10212 gen_type_die_for_member
10213 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10214 }
c26fbbca 10215
5daf7c0a 10216 /* Pretend we've just finished compiling this function. */
777ad4c2
JM
10217 save_fn = current_function_decl;
10218 current_function_decl = decl;
10219
10a11b75
JM
10220 set_decl_abstract_flags (decl, 1);
10221 dwarf2out_decl (decl);
5daf7c0a
JM
10222 if (! was_abstract)
10223 set_decl_abstract_flags (decl, 0);
777ad4c2
JM
10224
10225 current_function_decl = save_fn;
10a11b75
JM
10226}
10227
a3f97cbb
JW
10228/* Generate a DIE to represent a declared function (either file-scope or
10229 block-local). */
71dfc51f 10230
a3f97cbb
JW
10231static void
10232gen_subprogram_die (decl, context_die)
b3694847
SS
10233 tree decl;
10234 dw_die_ref context_die;
a3f97cbb
JW
10235{
10236 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
b3694847
SS
10237 tree origin = decl_ultimate_origin (decl);
10238 dw_die_ref subr_die;
10239 rtx fp_reg;
10240 tree fn_arg_types;
10241 tree outer_scope;
10242 dw_die_ref old_die = lookup_decl_die (decl);
10243 int declaration = (current_function_decl != decl
10244 || class_scope_p (context_die));
a3f97cbb 10245
2ad9852d
RK
10246 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10247 started to generate the abstract instance of an inline, decided to output
10248 its containing class, and proceeded to emit the declaration of the inline
10249 from the member list for the class. If so, DECLARATION takes priority;
10250 we'll get back to the abstract instance when done with the class. */
10a11b75 10251
1cfdcc15
JM
10252 /* The class-scope declaration DIE must be the primary DIE. */
10253 if (origin && declaration && class_scope_p (context_die))
10254 {
10255 origin = NULL;
10256 if (old_die)
10257 abort ();
10258 }
10259
a3f97cbb
JW
10260 if (origin != NULL)
10261 {
777ad4c2 10262 if (declaration && ! local_scope_p (context_die))
10a11b75
JM
10263 abort ();
10264
8d8238b6
JM
10265 /* Fixup die_parent for the abstract instance of a nested
10266 inline function. */
10267 if (old_die && old_die->die_parent == NULL)
10268 add_child_die (context_die, old_die);
10269
54ba1f0d 10270 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
a3f97cbb
JW
10271 add_abstract_origin_attribute (subr_die, origin);
10272 }
bdb669cb
JM
10273 else if (old_die)
10274 {
981975b6 10275 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
a94dbf2c 10276
1edf43d6
JM
10277 if (!get_AT_flag (old_die, DW_AT_declaration)
10278 /* We can have a normal definition following an inline one in the
10279 case of redefinition of GNU C extern inlines.
10280 It seems reasonable to use AT_specification in this case. */
10281 && !get_AT_unsigned (old_die, DW_AT_inline))
b75ab88b
NC
10282 {
10283 /* ??? This can happen if there is a bug in the program, for
10284 instance, if it has duplicate function definitions. Ideally,
10285 we should detect this case and ignore it. For now, if we have
10286 already reported an error, any error at all, then assume that
4fe9b91c 10287 we got here because of an input error, not a dwarf2 bug. */
b75ab88b
NC
10288 if (errorcount)
10289 return;
10290 abort ();
10291 }
4b674448
JM
10292
10293 /* If the definition comes from the same place as the declaration,
a94dbf2c
JM
10294 maybe use the old DIE. We always want the DIE for this function
10295 that has the *_pc attributes to be under comp_unit_die so the
cb9e9d8d
JM
10296 debugger can find it. We also need to do this for abstract
10297 instances of inlines, since the spec requires the out-of-line copy
10298 to have the same parent. For local class methods, this doesn't
10299 apply; we just use the old DIE. */
10300 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
a96c67ec
JM
10301 && (DECL_ARTIFICIAL (decl)
10302 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10303 && (get_AT_unsigned (old_die, DW_AT_decl_line)
556273e0 10304 == (unsigned) DECL_SOURCE_LINE (decl)))))
bdb669cb 10305 {
4b674448
JM
10306 subr_die = old_die;
10307
10308 /* Clear out the declaration attribute and the parm types. */
10309 remove_AT (subr_die, DW_AT_declaration);
10310 remove_children (subr_die);
10311 }
10312 else
10313 {
54ba1f0d 10314 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
4b674448 10315 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
bdb669cb
JM
10316 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10317 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10318 if (get_AT_unsigned (old_die, DW_AT_decl_line)
556273e0 10319 != (unsigned) DECL_SOURCE_LINE (decl))
bdb669cb
JM
10320 add_AT_unsigned
10321 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10322 }
10323 }
a3f97cbb
JW
10324 else
10325 {
54ba1f0d 10326 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
556273e0 10327
273dbe67
JM
10328 if (TREE_PUBLIC (decl))
10329 add_AT_flag (subr_die, DW_AT_external, 1);
71dfc51f 10330
a3f97cbb 10331 add_name_and_src_coords_attributes (subr_die, decl);
4927276d
JM
10332 if (debug_info_level > DINFO_LEVEL_TERSE)
10333 {
2ad9852d
RK
10334 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10335 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10336 0, 0, context_die);
4927276d 10337 }
71dfc51f 10338
a3f97cbb 10339 add_pure_or_virtual_attribute (subr_die, decl);
273dbe67
JM
10340 if (DECL_ARTIFICIAL (decl))
10341 add_AT_flag (subr_die, DW_AT_artificial, 1);
2ad9852d 10342
a94dbf2c
JM
10343 if (TREE_PROTECTED (decl))
10344 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10345 else if (TREE_PRIVATE (decl))
10346 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
a3f97cbb 10347 }
4edb7b60 10348
a94dbf2c
JM
10349 if (declaration)
10350 {
2ad9852d 10351 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
1edf43d6
JM
10352 {
10353 add_AT_flag (subr_die, DW_AT_declaration, 1);
10354
10355 /* The first time we see a member function, it is in the context of
10356 the class to which it belongs. We make sure of this by emitting
10357 the class first. The next time is the definition, which is
10358 handled above. The two may come from the same source text. */
10359 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10360 equate_decl_number_to_die (decl, subr_die);
10361 }
a94dbf2c
JM
10362 }
10363 else if (DECL_ABSTRACT (decl))
a3f97cbb 10364 {
10a11b75 10365 if (DECL_INLINE (decl) && !flag_no_inline)
61b32c02 10366 {
10a11b75
JM
10367 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10368 inline functions, but not for extern inline functions.
10369 We can't get this completely correct because information
10370 about whether the function was declared inline is not
10371 saved anywhere. */
10372 if (DECL_DEFER_OUTPUT (decl))
61b32c02
JM
10373 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10374 else
10a11b75 10375 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
61b32c02 10376 }
61b32c02 10377 else
10a11b75 10378 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
61b32c02 10379
a3f97cbb
JW
10380 equate_decl_number_to_die (decl, subr_die);
10381 }
10382 else if (!DECL_EXTERNAL (decl))
10383 {
2ad9852d 10384 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
ba7b35df 10385 equate_decl_number_to_die (decl, subr_die);
71dfc51f 10386
5c90448c 10387 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
df696a75 10388 current_function_funcdef_no);
7d4440be 10389 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
5c90448c 10390 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
df696a75 10391 current_function_funcdef_no);
a3f97cbb
JW
10392 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10393
d291dd49
JM
10394 add_pubname (decl, subr_die);
10395 add_arange (decl, subr_die);
10396
a3f97cbb 10397#ifdef MIPS_DEBUGGING_INFO
a3f97cbb
JW
10398 /* Add a reference to the FDE for this routine. */
10399 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10400#endif
10401
810429b7
JM
10402 /* Define the "frame base" location for this routine. We use the
10403 frame pointer or stack pointer registers, since the RTL for local
10404 variables is relative to one of them. */
b1ccbc24
RK
10405 fp_reg
10406 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10407 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
a3f97cbb 10408
ef76d03b
JW
10409#if 0
10410 /* ??? This fails for nested inline functions, because context_display
10411 is not part of the state saved/restored for inline functions. */
88dad228 10412 if (current_function_needs_context)
ef76d03b 10413 add_AT_location_description (subr_die, DW_AT_static_link,
b9203463 10414 loc_descriptor (lookup_static_chain (decl)));
ef76d03b 10415#endif
a3f97cbb
JW
10416 }
10417
10418 /* Now output descriptions of the arguments for this function. This gets
556273e0 10419 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
a3f97cbb
JW
10420 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10421 `...' at the end of the formal parameter list. In order to find out if
10422 there was a trailing ellipsis or not, we must instead look at the type
10423 associated with the FUNCTION_DECL. This will be a node of type
10424 FUNCTION_TYPE. If the chain of type nodes hanging off of this
556273e0 10425 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
a3f97cbb 10426 an ellipsis at the end. */
71dfc51f 10427
a3f97cbb 10428 /* In the case where we are describing a mere function declaration, all we
556273e0 10429 need to do here (and all we *can* do here) is to describe the *types* of
a3f97cbb 10430 its formal parameters. */
4927276d 10431 if (debug_info_level <= DINFO_LEVEL_TERSE)
71dfc51f 10432 ;
4edb7b60 10433 else if (declaration)
5daf7c0a 10434 gen_formal_types_die (decl, subr_die);
a3f97cbb
JW
10435 else
10436 {
10437 /* Generate DIEs to represent all known formal parameters */
b3694847
SS
10438 tree arg_decls = DECL_ARGUMENTS (decl);
10439 tree parm;
a3f97cbb
JW
10440
10441 /* When generating DIEs, generate the unspecified_parameters DIE
10442 instead if we come across the arg "__builtin_va_alist" */
10443 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
71dfc51f
RK
10444 if (TREE_CODE (parm) == PARM_DECL)
10445 {
db3cf6fb
MS
10446 if (DECL_NAME (parm)
10447 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10448 "__builtin_va_alist"))
71dfc51f
RK
10449 gen_unspecified_parameters_die (parm, subr_die);
10450 else
10451 gen_decl_die (parm, subr_die);
10452 }
a3f97cbb 10453
4fe9b91c 10454 /* Decide whether we need an unspecified_parameters DIE at the end.
556273e0 10455 There are 2 more cases to do this for: 1) the ansi ... declaration -
a3f97cbb
JW
10456 this is detectable when the end of the arg list is not a
10457 void_type_node 2) an unprototyped function declaration (not a
10458 definition). This just means that we have no info about the
10459 parameters at all. */
10460 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
71dfc51f 10461 if (fn_arg_types != NULL)
a3f97cbb
JW
10462 {
10463 /* this is the prototyped case, check for ... */
10464 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
71dfc51f 10465 gen_unspecified_parameters_die (decl, subr_die);
a3f97cbb 10466 }
71dfc51f
RK
10467 else if (DECL_INITIAL (decl) == NULL_TREE)
10468 gen_unspecified_parameters_die (decl, subr_die);
a3f97cbb
JW
10469 }
10470
10471 /* Output Dwarf info for all of the stuff within the body of the function
10472 (if it has one - it may be just a declaration). */
10473 outer_scope = DECL_INITIAL (decl);
10474
2ad9852d
RK
10475 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10476 a function. This BLOCK actually represents the outermost binding contour
10477 for the function, i.e. the contour in which the function's formal
10478 parameters and labels get declared. Curiously, it appears that the front
10479 end doesn't actually put the PARM_DECL nodes for the current function onto
10480 the BLOCK_VARS list for this outer scope, but are strung off of the
10481 DECL_ARGUMENTS list for the function instead.
10482
10483 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10484 the LABEL_DECL nodes for the function however, and we output DWARF info
10485 for those in decls_for_scope. Just within the `outer_scope' there will be
10486 a BLOCK node representing the function's outermost pair of curly braces,
10487 and any blocks used for the base and member initializers of a C++
d7248bff 10488 constructor function. */
4edb7b60 10489 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
7e23cb16
JM
10490 {
10491 current_function_has_inlines = 0;
10492 decls_for_scope (outer_scope, subr_die, 0);
71dfc51f 10493
ce61cc73 10494#if 0 && defined (MIPS_DEBUGGING_INFO)
7e23cb16
JM
10495 if (current_function_has_inlines)
10496 {
10497 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10498 if (! comp_unit_has_inlines)
10499 {
10500 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10501 comp_unit_has_inlines = 1;
10502 }
10503 }
10504#endif
10505 }
a3f97cbb
JW
10506}
10507
10508/* Generate a DIE to represent a declared data object. */
71dfc51f 10509
a3f97cbb
JW
10510static void
10511gen_variable_die (decl, context_die)
b3694847
SS
10512 tree decl;
10513 dw_die_ref context_die;
a3f97cbb 10514{
b3694847 10515 tree origin = decl_ultimate_origin (decl);
54ba1f0d 10516 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
71dfc51f 10517
bdb669cb 10518 dw_die_ref old_die = lookup_decl_die (decl);
9765e357
JM
10519 int declaration = (DECL_EXTERNAL (decl)
10520 || class_scope_p (context_die));
4edb7b60 10521
a3f97cbb 10522 if (origin != NULL)
71dfc51f 10523 add_abstract_origin_attribute (var_die, origin);
2ad9852d 10524
f76b8156 10525 /* Loop unrolling can create multiple blocks that refer to the same
2ad9852d
RK
10526 static variable, so we must test for the DW_AT_declaration flag.
10527
10528 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
f76b8156 10529 copy decls and set the DECL_ABSTRACT flag on them instead of
2ad9852d
RK
10530 sharing them.
10531
10532 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
f76b8156 10533 else if (old_die && TREE_STATIC (decl)
c26fbbca 10534 && get_AT_flag (old_die, DW_AT_declaration) == 1)
bdb669cb 10535 {
e689ae67 10536 /* This is a definition of a C++ class level static. */
bdb669cb
JM
10537 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10538 if (DECL_NAME (decl))
10539 {
981975b6 10540 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
71dfc51f 10541
bdb669cb
JM
10542 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10543 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
71dfc51f 10544
bdb669cb 10545 if (get_AT_unsigned (old_die, DW_AT_decl_line)
556273e0 10546 != (unsigned) DECL_SOURCE_LINE (decl))
71dfc51f
RK
10547
10548 add_AT_unsigned (var_die, DW_AT_decl_line,
10549 DECL_SOURCE_LINE (decl));
bdb669cb
JM
10550 }
10551 }
a3f97cbb
JW
10552 else
10553 {
10554 add_name_and_src_coords_attributes (var_die, decl);
2ad9852d 10555 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
a3f97cbb 10556 TREE_THIS_VOLATILE (decl), context_die);
71dfc51f 10557
273dbe67
JM
10558 if (TREE_PUBLIC (decl))
10559 add_AT_flag (var_die, DW_AT_external, 1);
71dfc51f 10560
273dbe67
JM
10561 if (DECL_ARTIFICIAL (decl))
10562 add_AT_flag (var_die, DW_AT_artificial, 1);
71dfc51f 10563
a94dbf2c
JM
10564 if (TREE_PROTECTED (decl))
10565 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10566 else if (TREE_PRIVATE (decl))
10567 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
a3f97cbb 10568 }
4edb7b60
JM
10569
10570 if (declaration)
10571 add_AT_flag (var_die, DW_AT_declaration, 1);
556273e0 10572
9765e357 10573 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
4edb7b60
JM
10574 equate_decl_number_to_die (decl, var_die);
10575
10576 if (! declaration && ! DECL_ABSTRACT (decl))
a3f97cbb
JW
10577 {
10578 add_location_or_const_value_attribute (var_die, decl);
d291dd49 10579 add_pubname (decl, var_die);
a3f97cbb 10580 }
1bfb5f8f
JM
10581 else
10582 tree_add_const_value_attribute (var_die, decl);
a3f97cbb
JW
10583}
10584
10585/* Generate a DIE to represent a label identifier. */
71dfc51f 10586
a3f97cbb
JW
10587static void
10588gen_label_die (decl, context_die)
b3694847
SS
10589 tree decl;
10590 dw_die_ref context_die;
a3f97cbb 10591{
b3694847 10592 tree origin = decl_ultimate_origin (decl);
54ba1f0d 10593 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
b3694847 10594 rtx insn;
a3f97cbb 10595 char label[MAX_ARTIFICIAL_LABEL_BYTES];
71dfc51f 10596
a3f97cbb 10597 if (origin != NULL)
71dfc51f 10598 add_abstract_origin_attribute (lbl_die, origin);
a3f97cbb 10599 else
71dfc51f
RK
10600 add_name_and_src_coords_attributes (lbl_die, decl);
10601
a3f97cbb 10602 if (DECL_ABSTRACT (decl))
71dfc51f 10603 equate_decl_number_to_die (decl, lbl_die);
a3f97cbb
JW
10604 else
10605 {
10606 insn = DECL_RTL (decl);
088e7160
NC
10607
10608 /* Deleted labels are programmer specified labels which have been
10609 eliminated because of various optimisations. We still emit them
10610 here so that it is possible to put breakpoints on them. */
10611 if (GET_CODE (insn) == CODE_LABEL
10612 || ((GET_CODE (insn) == NOTE
10613 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
a3f97cbb 10614 {
556273e0
KH
10615 /* When optimization is enabled (via -O) some parts of the compiler
10616 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
a3f97cbb
JW
10617 represent source-level labels which were explicitly declared by
10618 the user. This really shouldn't be happening though, so catch
10619 it if it ever does happen. */
10620 if (INSN_DELETED_P (insn))
71dfc51f
RK
10621 abort ();
10622
66234570 10623 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
a3f97cbb
JW
10624 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10625 }
10626 }
10627}
10628
10629/* Generate a DIE for a lexical block. */
71dfc51f 10630
a3f97cbb 10631static void
d7248bff 10632gen_lexical_block_die (stmt, context_die, depth)
b3694847
SS
10633 tree stmt;
10634 dw_die_ref context_die;
d7248bff 10635 int depth;
a3f97cbb 10636{
54ba1f0d 10637 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
a3f97cbb 10638 char label[MAX_ARTIFICIAL_LABEL_BYTES];
71dfc51f
RK
10639
10640 if (! BLOCK_ABSTRACT (stmt))
a3f97cbb 10641 {
a20612aa
RH
10642 if (BLOCK_FRAGMENT_CHAIN (stmt))
10643 {
10644 tree chain;
10645
2bee6045 10646 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
a20612aa
RH
10647
10648 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10649 do
10650 {
10651 add_ranges (chain);
10652 chain = BLOCK_FRAGMENT_CHAIN (chain);
10653 }
10654 while (chain);
10655 add_ranges (NULL);
10656 }
10657 else
10658 {
10659 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10660 BLOCK_NUMBER (stmt));
10661 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10662 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10663 BLOCK_NUMBER (stmt));
10664 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10665 }
a3f97cbb 10666 }
71dfc51f 10667
d7248bff 10668 decls_for_scope (stmt, stmt_die, depth);
a3f97cbb
JW
10669}
10670
10671/* Generate a DIE for an inlined subprogram. */
71dfc51f 10672
a3f97cbb 10673static void
d7248bff 10674gen_inlined_subroutine_die (stmt, context_die, depth)
b3694847
SS
10675 tree stmt;
10676 dw_die_ref context_die;
d7248bff 10677 int depth;
a3f97cbb 10678{
71dfc51f 10679 if (! BLOCK_ABSTRACT (stmt))
a3f97cbb 10680 {
b3694847 10681 dw_die_ref subr_die
54ba1f0d 10682 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
b3694847 10683 tree decl = block_ultimate_origin (stmt);
d7248bff 10684 char label[MAX_ARTIFICIAL_LABEL_BYTES];
71dfc51f 10685
10a11b75 10686 /* Emit info for the abstract instance first, if we haven't yet. */
1edf43d6 10687 dwarf2out_abstract_function (decl);
10a11b75 10688
ab72d377 10689 add_abstract_origin_attribute (subr_die, decl);
5c90448c 10690 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
18c038b9 10691 BLOCK_NUMBER (stmt));
a3f97cbb 10692 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
18c038b9
MM
10693 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10694 BLOCK_NUMBER (stmt));
a3f97cbb 10695 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
d7248bff 10696 decls_for_scope (stmt, subr_die, depth);
7e23cb16 10697 current_function_has_inlines = 1;
a3f97cbb 10698 }
06e224f7
AO
10699 else
10700 /* We may get here if we're the outer block of function A that was
10701 inlined into function B that was inlined into function C. When
10702 generating debugging info for C, dwarf2out_abstract_function(B)
10703 would mark all inlined blocks as abstract, including this one.
10704 So, we wouldn't (and shouldn't) expect labels to be generated
10705 for this one. Instead, just emit debugging info for
10706 declarations within the block. This is particularly important
10707 in the case of initializers of arguments passed from B to us:
10708 if they're statement expressions containing declarations, we
10709 wouldn't generate dies for their abstract variables, and then,
10710 when generating dies for the real variables, we'd die (pun
10711 intended :-) */
10712 gen_lexical_block_die (stmt, context_die, depth);
a3f97cbb
JW
10713}
10714
10715/* Generate a DIE for a field in a record, or structure. */
71dfc51f 10716
a3f97cbb
JW
10717static void
10718gen_field_die (decl, context_die)
b3694847
SS
10719 tree decl;
10720 dw_die_ref context_die;
a3f97cbb 10721{
54ba1f0d 10722 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
71dfc51f 10723
a3f97cbb 10724 add_name_and_src_coords_attributes (decl_die, decl);
a3f97cbb
JW
10725 add_type_attribute (decl_die, member_declared_type (decl),
10726 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10727 context_die);
71dfc51f 10728
a3f97cbb
JW
10729 if (DECL_BIT_FIELD_TYPE (decl))
10730 {
10731 add_byte_size_attribute (decl_die, decl);
10732 add_bit_size_attribute (decl_die, decl);
10733 add_bit_offset_attribute (decl_die, decl);
10734 }
71dfc51f 10735
a94dbf2c
JM
10736 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10737 add_data_member_location_attribute (decl_die, decl);
71dfc51f 10738
273dbe67
JM
10739 if (DECL_ARTIFICIAL (decl))
10740 add_AT_flag (decl_die, DW_AT_artificial, 1);
71dfc51f 10741
a94dbf2c
JM
10742 if (TREE_PROTECTED (decl))
10743 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10744 else if (TREE_PRIVATE (decl))
10745 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
a3f97cbb
JW
10746}
10747
ab72d377
JM
10748#if 0
10749/* Don't generate either pointer_type DIEs or reference_type DIEs here.
10750 Use modified_type_die instead.
a3f97cbb
JW
10751 We keep this code here just in case these types of DIEs may be needed to
10752 represent certain things in other languages (e.g. Pascal) someday. */
2ad9852d 10753
a3f97cbb
JW
10754static void
10755gen_pointer_type_die (type, context_die)
b3694847
SS
10756 tree type;
10757 dw_die_ref context_die;
a3f97cbb 10758{
b3694847 10759 dw_die_ref ptr_die
54ba1f0d 10760 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
71dfc51f 10761
a3f97cbb 10762 equate_type_number_to_die (type, ptr_die);
a3f97cbb 10763 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
ab72d377 10764 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
a3f97cbb
JW
10765}
10766
ab72d377
JM
10767/* Don't generate either pointer_type DIEs or reference_type DIEs here.
10768 Use modified_type_die instead.
a3f97cbb
JW
10769 We keep this code here just in case these types of DIEs may be needed to
10770 represent certain things in other languages (e.g. Pascal) someday. */
2ad9852d 10771
a3f97cbb
JW
10772static void
10773gen_reference_type_die (type, context_die)
b3694847
SS
10774 tree type;
10775 dw_die_ref context_die;
a3f97cbb 10776{
b3694847 10777 dw_die_ref ref_die
54ba1f0d 10778 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
71dfc51f 10779
a3f97cbb 10780 equate_type_number_to_die (type, ref_die);
a3f97cbb 10781 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
ab72d377 10782 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
a3f97cbb 10783}
ab72d377 10784#endif
a3f97cbb
JW
10785
10786/* Generate a DIE for a pointer to a member type. */
2ad9852d 10787
a3f97cbb
JW
10788static void
10789gen_ptr_to_mbr_type_die (type, context_die)
b3694847
SS
10790 tree type;
10791 dw_die_ref context_die;
a3f97cbb 10792{
b3694847 10793 dw_die_ref ptr_die
54ba1f0d
RH
10794 = new_die (DW_TAG_ptr_to_member_type,
10795 scope_die_for (type, context_die), type);
71dfc51f 10796
a3f97cbb 10797 equate_type_number_to_die (type, ptr_die);
a3f97cbb 10798 add_AT_die_ref (ptr_die, DW_AT_containing_type,
bdb669cb 10799 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
a3f97cbb
JW
10800 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10801}
10802
10803/* Generate the DIE for the compilation unit. */
71dfc51f 10804
a96c67ec
JM
10805static dw_die_ref
10806gen_compile_unit_die (filename)
b3694847 10807 const char *filename;
a3f97cbb 10808{
b3694847 10809 dw_die_ref die;
a3f97cbb 10810 char producer[250];
d3e3972c 10811 const char *wd = getpwd ();
3ac88239 10812 const char *language_string = lang_hooks.name;
a96c67ec 10813 int language;
a3f97cbb 10814
54ba1f0d 10815 die = new_die (DW_TAG_compile_unit, NULL, NULL);
a96c67ec 10816 add_name_attribute (die, filename);
bdb669cb 10817
a96c67ec
JM
10818 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10819 add_AT_string (die, DW_AT_comp_dir, wd);
a3f97cbb
JW
10820
10821 sprintf (producer, "%s %s", language_string, version_string);
10822
10823#ifdef MIPS_DEBUGGING_INFO
10824 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10825 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10826 not appear in the producer string, the debugger reaches the conclusion
10827 that the object file is stripped and has no debugging information.
10828 To get the MIPS/SGI debugger to believe that there is debugging
10829 information in the object file, we add a -g to the producer string. */
4927276d
JM
10830 if (debug_info_level > DINFO_LEVEL_TERSE)
10831 strcat (producer, " -g");
a3f97cbb
JW
10832#endif
10833
a96c67ec 10834 add_AT_string (die, DW_AT_producer, producer);
a9d38797 10835
a3f97cbb 10836 if (strcmp (language_string, "GNU C++") == 0)
a96c67ec 10837 language = DW_LANG_C_plus_plus;
a3f97cbb 10838 else if (strcmp (language_string, "GNU Ada") == 0)
a96c67ec 10839 language = DW_LANG_Ada83;
a9d38797 10840 else if (strcmp (language_string, "GNU F77") == 0)
a96c67ec 10841 language = DW_LANG_Fortran77;
bc28c45b 10842 else if (strcmp (language_string, "GNU Pascal") == 0)
a96c67ec 10843 language = DW_LANG_Pascal83;
28985b81
AG
10844 else if (strcmp (language_string, "GNU Java") == 0)
10845 language = DW_LANG_Java;
a3f97cbb 10846 else
a96c67ec 10847 language = DW_LANG_C89;
a9d38797 10848
a96c67ec 10849 add_AT_unsigned (die, DW_AT_language, language);
a96c67ec 10850 return die;
a3f97cbb
JW
10851}
10852
10853/* Generate a DIE for a string type. */
71dfc51f 10854
a3f97cbb
JW
10855static void
10856gen_string_type_die (type, context_die)
b3694847
SS
10857 tree type;
10858 dw_die_ref context_die;
a3f97cbb 10859{
b3694847 10860 dw_die_ref type_die
54ba1f0d 10861 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
71dfc51f 10862
bdb669cb 10863 equate_type_number_to_die (type, type_die);
a3f97cbb 10864
2ad9852d
RK
10865 /* ??? Fudge the string length attribute for now.
10866 TODO: add string length info. */
10867#if 0
10868 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10869 bound_representation (upper_bound, 0, 'u');
10870#endif
a3f97cbb
JW
10871}
10872
61b32c02 10873/* Generate the DIE for a base class. */
71dfc51f 10874
61b32c02
JM
10875static void
10876gen_inheritance_die (binfo, context_die)
b3694847
SS
10877 tree binfo;
10878 dw_die_ref context_die;
61b32c02 10879{
54ba1f0d 10880 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
71dfc51f 10881
61b32c02
JM
10882 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10883 add_data_member_location_attribute (die, binfo);
71dfc51f 10884
61b32c02
JM
10885 if (TREE_VIA_VIRTUAL (binfo))
10886 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
2ad9852d 10887
61b32c02
JM
10888 if (TREE_VIA_PUBLIC (binfo))
10889 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10890 else if (TREE_VIA_PROTECTED (binfo))
10891 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10892}
10893
956d6950 10894/* Generate a DIE for a class member. */
71dfc51f 10895
a3f97cbb
JW
10896static void
10897gen_member_die (type, context_die)
b3694847
SS
10898 tree type;
10899 dw_die_ref context_die;
a3f97cbb 10900{
b3694847 10901 tree member;
10a11b75 10902 dw_die_ref child;
71dfc51f 10903
a3f97cbb
JW
10904 /* If this is not an incomplete type, output descriptions of each of its
10905 members. Note that as we output the DIEs necessary to represent the
10906 members of this record or union type, we will also be trying to output
10907 DIEs to represent the *types* of those members. However the `type'
556273e0 10908 function (above) will specifically avoid generating type DIEs for member
eaec9b3d 10909 types *within* the list of member DIEs for this (containing) type except
a3f97cbb
JW
10910 for those types (of members) which are explicitly marked as also being
10911 members of this (containing) type themselves. The g++ front- end can
2ad9852d
RK
10912 force any given type to be treated as a member of some other (containing)
10913 type by setting the TYPE_CONTEXT of the given (member) type to point to
10914 the TREE node representing the appropriate (containing) type. */
a3f97cbb 10915
61b32c02
JM
10916 /* First output info about the base classes. */
10917 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
a3f97cbb 10918 {
b3694847
SS
10919 tree bases = TYPE_BINFO_BASETYPES (type);
10920 int n_bases = TREE_VEC_LENGTH (bases);
10921 int i;
61b32c02
JM
10922
10923 for (i = 0; i < n_bases; i++)
10924 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
a3f97cbb
JW
10925 }
10926
61b32c02
JM
10927 /* Now output info about the data members and type members. */
10928 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10a11b75
JM
10929 {
10930 /* If we thought we were generating minimal debug info for TYPE
10931 and then changed our minds, some of the member declarations
10932 may have already been defined. Don't define them again, but
10933 do put them in the right order. */
10934
10935 child = lookup_decl_die (member);
10936 if (child)
10937 splice_child_die (context_die, child);
10938 else
10939 gen_decl_die (member, context_die);
10940 }
61b32c02 10941
a3f97cbb 10942 /* Now output info about the function members (if any). */
61b32c02 10943 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10a11b75 10944 {
5daf7c0a
JM
10945 /* Don't include clones in the member list. */
10946 if (DECL_ABSTRACT_ORIGIN (member))
10947 continue;
10948
10a11b75
JM
10949 child = lookup_decl_die (member);
10950 if (child)
10951 splice_child_die (context_die, child);
10952 else
10953 gen_decl_die (member, context_die);
10954 }
a3f97cbb
JW
10955}
10956
10a11b75
JM
10957/* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10958 is set, we pretend that the type was never defined, so we only get the
10959 member DIEs needed by later specification DIEs. */
71dfc51f 10960
a3f97cbb 10961static void
273dbe67 10962gen_struct_or_union_type_die (type, context_die)
b3694847
SS
10963 tree type;
10964 dw_die_ref context_die;
a3f97cbb 10965{
b3694847
SS
10966 dw_die_ref type_die = lookup_type_die (type);
10967 dw_die_ref scope_die = 0;
10968 int nested = 0;
10a11b75 10969 int complete = (TYPE_SIZE (type)
65e1263a
JW
10970 && (! TYPE_STUB_DECL (type)
10971 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
273dbe67 10972
10a11b75 10973 if (type_die && ! complete)
273dbe67 10974 return;
a082c85a 10975
71dfc51f 10976 if (TYPE_CONTEXT (type) != NULL_TREE
5f2f160c 10977 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
a082c85a
JM
10978 nested = 1;
10979
a94dbf2c 10980 scope_die = scope_die_for (type, context_die);
a082c85a
JM
10981
10982 if (! type_die || (nested && scope_die == comp_unit_die))
273dbe67 10983 /* First occurrence of type or toplevel definition of nested class. */
a3f97cbb 10984 {
b3694847 10985 dw_die_ref old_die = type_die;
71dfc51f 10986
a3f97cbb
JW
10987 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10988 ? DW_TAG_structure_type : DW_TAG_union_type,
54ba1f0d 10989 scope_die, type);
a3f97cbb 10990 equate_type_number_to_die (type, type_die);
273dbe67
JM
10991 if (old_die)
10992 add_AT_die_ref (type_die, DW_AT_specification, old_die);
5de0e8d4
JM
10993 else
10994 add_name_attribute (type_die, type_tag (type));
a3f97cbb 10995 }
4b674448 10996 else
273dbe67 10997 remove_AT (type_die, DW_AT_declaration);
a3f97cbb
JW
10998
10999 /* If this type has been completed, then give it a byte_size attribute and
11000 then give a list of members. */
2081603c 11001 if (complete)
a3f97cbb 11002 {
556273e0 11003 /* Prevent infinite recursion in cases where the type of some member of
a3f97cbb
JW
11004 this type is expressed in terms of this type itself. */
11005 TREE_ASM_WRITTEN (type) = 1;
273dbe67 11006 add_byte_size_attribute (type_die, type);
e9a25f70 11007 if (TYPE_STUB_DECL (type) != NULL_TREE)
b2932ae5 11008 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
71dfc51f 11009
ef76d03b
JW
11010 /* If the first reference to this type was as the return type of an
11011 inline function, then it may not have a parent. Fix this now. */
11012 if (type_die->die_parent == NULL)
11013 add_child_die (scope_die, type_die);
11014
273dbe67
JM
11015 push_decl_scope (type);
11016 gen_member_die (type, type_die);
11017 pop_decl_scope ();
71dfc51f 11018
a94dbf2c
JM
11019 /* GNU extension: Record what type our vtable lives in. */
11020 if (TYPE_VFIELD (type))
11021 {
11022 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
71dfc51f 11023
de6e505e
JM
11024 gen_type_die (vtype, context_die);
11025 add_AT_die_ref (type_die, DW_AT_containing_type,
11026 lookup_type_die (vtype));
a94dbf2c 11027 }
a3f97cbb 11028 }
4b674448 11029 else
8a8c3656
JM
11030 {
11031 add_AT_flag (type_die, DW_AT_declaration, 1);
a30d4514 11032
9765e357 11033 /* We don't need to do this for function-local types. */
9702143f
RK
11034 if (TYPE_STUB_DECL (type)
11035 && ! decl_function_context (TYPE_STUB_DECL (type)))
2ad9852d 11036 VARRAY_PUSH_TREE (incomplete_types, type);
8a8c3656 11037 }
a3f97cbb
JW
11038}
11039
11040/* Generate a DIE for a subroutine _type_. */
71dfc51f 11041
a3f97cbb
JW
11042static void
11043gen_subroutine_type_die (type, context_die)
b3694847
SS
11044 tree type;
11045 dw_die_ref context_die;
a3f97cbb 11046{
b3694847
SS
11047 tree return_type = TREE_TYPE (type);
11048 dw_die_ref subr_die
54ba1f0d
RH
11049 = new_die (DW_TAG_subroutine_type,
11050 scope_die_for (type, context_die), type);
71dfc51f 11051
a3f97cbb
JW
11052 equate_type_number_to_die (type, subr_die);
11053 add_prototyped_attribute (subr_die, type);
a3f97cbb 11054 add_type_attribute (subr_die, return_type, 0, 0, context_die);
a94dbf2c 11055 gen_formal_types_die (type, subr_die);
a3f97cbb
JW
11056}
11057
11058/* Generate a DIE for a type definition */
71dfc51f 11059
a3f97cbb
JW
11060static void
11061gen_typedef_die (decl, context_die)
b3694847
SS
11062 tree decl;
11063 dw_die_ref context_die;
a3f97cbb 11064{
b3694847
SS
11065 dw_die_ref type_die;
11066 tree origin;
a94dbf2c
JM
11067
11068 if (TREE_ASM_WRITTEN (decl))
11069 return;
a94dbf2c 11070
2ad9852d 11071 TREE_ASM_WRITTEN (decl) = 1;
54ba1f0d 11072 type_die = new_die (DW_TAG_typedef, context_die, decl);
a94dbf2c 11073 origin = decl_ultimate_origin (decl);
a3f97cbb 11074 if (origin != NULL)
a94dbf2c 11075 add_abstract_origin_attribute (type_die, origin);
a3f97cbb
JW
11076 else
11077 {
b3694847 11078 tree type;
2ad9852d 11079
a3f97cbb 11080 add_name_and_src_coords_attributes (type_die, decl);
a94dbf2c
JM
11081 if (DECL_ORIGINAL_TYPE (decl))
11082 {
11083 type = DECL_ORIGINAL_TYPE (decl);
62e3bf54
JM
11084
11085 if (type == TREE_TYPE (decl))
11086 abort ();
11087 else
11088 equate_type_number_to_die (TREE_TYPE (decl), type_die);
a94dbf2c
JM
11089 }
11090 else
11091 type = TREE_TYPE (decl);
2ad9852d 11092
a94dbf2c
JM
11093 add_type_attribute (type_die, type, TREE_READONLY (decl),
11094 TREE_THIS_VOLATILE (decl), context_die);
a3f97cbb 11095 }
71dfc51f 11096
a3f97cbb 11097 if (DECL_ABSTRACT (decl))
a94dbf2c 11098 equate_decl_number_to_die (decl, type_die);
a3f97cbb
JW
11099}
11100
11101/* Generate a type description DIE. */
71dfc51f 11102
a3f97cbb
JW
11103static void
11104gen_type_die (type, context_die)
b3694847
SS
11105 tree type;
11106 dw_die_ref context_die;
a3f97cbb 11107{
348bb3c7
JM
11108 int need_pop;
11109
71dfc51f
RK
11110 if (type == NULL_TREE || type == error_mark_node)
11111 return;
a3f97cbb 11112
0e98f924
AH
11113 /* We are going to output a DIE to represent the unqualified version
11114 of this type (i.e. without any const or volatile qualifiers) so
11115 get the main variant (i.e. the unqualified version) of this type
11116 now. (Vectors are special because the debugging info is in the
11117 cloned type itself). */
11118 if (TREE_CODE (type) != VECTOR_TYPE)
11119 type = type_main_variant (type);
a3f97cbb
JW
11120
11121 if (TREE_ASM_WRITTEN (type))
71dfc51f 11122 return;
a3f97cbb 11123
a94dbf2c
JM
11124 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11125 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
556273e0 11126 {
29b91443
JM
11127 /* Prevent broken recursion; we can't hand off to the same type. */
11128 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11129 abort ();
11130
a94dbf2c
JM
11131 TREE_ASM_WRITTEN (type) = 1;
11132 gen_decl_die (TYPE_NAME (type), context_die);
11133 return;
11134 }
11135
a3f97cbb
JW
11136 switch (TREE_CODE (type))
11137 {
11138 case ERROR_MARK:
11139 break;
11140
11141 case POINTER_TYPE:
11142 case REFERENCE_TYPE:
956d6950
JL
11143 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11144 ensures that the gen_type_die recursion will terminate even if the
11145 type is recursive. Recursive types are possible in Ada. */
11146 /* ??? We could perhaps do this for all types before the switch
11147 statement. */
11148 TREE_ASM_WRITTEN (type) = 1;
11149
a3f97cbb
JW
11150 /* For these types, all that is required is that we output a DIE (or a
11151 set of DIEs) to represent the "basis" type. */
11152 gen_type_die (TREE_TYPE (type), context_die);
11153 break;
11154
11155 case OFFSET_TYPE:
556273e0 11156 /* This code is used for C++ pointer-to-data-member types.
71dfc51f 11157 Output a description of the relevant class type. */
a3f97cbb 11158 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
71dfc51f 11159
a3f97cbb
JW
11160 /* Output a description of the type of the object pointed to. */
11161 gen_type_die (TREE_TYPE (type), context_die);
71dfc51f 11162
a3f97cbb
JW
11163 /* Now output a DIE to represent this pointer-to-data-member type
11164 itself. */
11165 gen_ptr_to_mbr_type_die (type, context_die);
11166 break;
11167
11168 case SET_TYPE:
11169 gen_type_die (TYPE_DOMAIN (type), context_die);
11170 gen_set_type_die (type, context_die);
11171 break;
11172
11173 case FILE_TYPE:
11174 gen_type_die (TREE_TYPE (type), context_die);
11175 abort (); /* No way to represent these in Dwarf yet! */
11176 break;
11177
11178 case FUNCTION_TYPE:
11179 /* Force out return type (in case it wasn't forced out already). */
11180 gen_type_die (TREE_TYPE (type), context_die);
11181 gen_subroutine_type_die (type, context_die);
11182 break;
11183
11184 case METHOD_TYPE:
11185 /* Force out return type (in case it wasn't forced out already). */
11186 gen_type_die (TREE_TYPE (type), context_die);
11187 gen_subroutine_type_die (type, context_die);
11188 break;
11189
11190 case ARRAY_TYPE:
11191 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11192 {
11193 gen_type_die (TREE_TYPE (type), context_die);
11194 gen_string_type_die (type, context_die);
11195 }
11196 else
71dfc51f 11197 gen_array_type_die (type, context_die);
a3f97cbb
JW
11198 break;
11199
4061f623 11200 case VECTOR_TYPE:
84f0ace0 11201 gen_array_type_die (type, context_die);
4061f623
BS
11202 break;
11203
a3f97cbb
JW
11204 case ENUMERAL_TYPE:
11205 case RECORD_TYPE:
11206 case UNION_TYPE:
11207 case QUAL_UNION_TYPE:
2ad9852d
RK
11208 /* If this is a nested type whose containing class hasn't been written
11209 out yet, writing it out will cover this one, too. This does not apply
11210 to instantiations of member class templates; they need to be added to
11211 the containing class as they are generated. FIXME: This hurts the
11212 idea of combining type decls from multiple TUs, since we can't predict
11213 what set of template instantiations we'll get. */
a082c85a 11214 if (TYPE_CONTEXT (type)
5f2f160c 11215 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
a082c85a 11216 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
a94dbf2c
JM
11217 {
11218 gen_type_die (TYPE_CONTEXT (type), context_die);
11219
348bb3c7 11220 if (TREE_ASM_WRITTEN (type))
a94dbf2c
JM
11221 return;
11222
11223 /* If that failed, attach ourselves to the stub. */
11224 push_decl_scope (TYPE_CONTEXT (type));
11225 context_die = lookup_type_die (TYPE_CONTEXT (type));
348bb3c7 11226 need_pop = 1;
a94dbf2c 11227 }
348bb3c7
JM
11228 else
11229 need_pop = 0;
a94dbf2c
JM
11230
11231 if (TREE_CODE (type) == ENUMERAL_TYPE)
273dbe67 11232 gen_enumeration_type_die (type, context_die);
a3f97cbb 11233 else
273dbe67 11234 gen_struct_or_union_type_die (type, context_die);
4b674448 11235
348bb3c7 11236 if (need_pop)
a94dbf2c
JM
11237 pop_decl_scope ();
11238
4b674448 11239 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
a082c85a
JM
11240 it up if it is ever completed. gen_*_type_die will set it for us
11241 when appropriate. */
11242 return;
a3f97cbb
JW
11243
11244 case VOID_TYPE:
11245 case INTEGER_TYPE:
11246 case REAL_TYPE:
11247 case COMPLEX_TYPE:
11248 case BOOLEAN_TYPE:
11249 case CHAR_TYPE:
11250 /* No DIEs needed for fundamental types. */
11251 break;
11252
11253 case LANG_TYPE:
11254 /* No Dwarf representation currently defined. */
11255 break;
11256
11257 default:
11258 abort ();
11259 }
11260
11261 TREE_ASM_WRITTEN (type) = 1;
11262}
11263
11264/* Generate a DIE for a tagged type instantiation. */
71dfc51f 11265
a3f97cbb
JW
11266static void
11267gen_tagged_type_instantiation_die (type, context_die)
b3694847
SS
11268 tree type;
11269 dw_die_ref context_die;
a3f97cbb 11270{
71dfc51f
RK
11271 if (type == NULL_TREE || type == error_mark_node)
11272 return;
a3f97cbb 11273
38e01259 11274 /* We are going to output a DIE to represent the unqualified version of
a3f97cbb
JW
11275 this type (i.e. without any const or volatile qualifiers) so make sure
11276 that we have the main variant (i.e. the unqualified version) of this
11277 type now. */
bbc6ae08 11278 if (type != type_main_variant (type))
3a88cbd1 11279 abort ();
a3f97cbb 11280
203588e7 11281 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
bbc6ae08 11282 an instance of an unresolved type. */
556273e0 11283
a3f97cbb
JW
11284 switch (TREE_CODE (type))
11285 {
11286 case ERROR_MARK:
11287 break;
11288
11289 case ENUMERAL_TYPE:
11290 gen_inlined_enumeration_type_die (type, context_die);
11291 break;
11292
11293 case RECORD_TYPE:
11294 gen_inlined_structure_type_die (type, context_die);
11295 break;
11296
11297 case UNION_TYPE:
11298 case QUAL_UNION_TYPE:
11299 gen_inlined_union_type_die (type, context_die);
11300 break;
11301
11302 default:
71dfc51f 11303 abort ();
a3f97cbb
JW
11304 }
11305}
11306
11307/* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11308 things which are local to the given block. */
71dfc51f 11309
a3f97cbb 11310static void
d7248bff 11311gen_block_die (stmt, context_die, depth)
b3694847
SS
11312 tree stmt;
11313 dw_die_ref context_die;
d7248bff 11314 int depth;
a3f97cbb 11315{
b3694847
SS
11316 int must_output_die = 0;
11317 tree origin;
11318 tree decl;
11319 enum tree_code origin_code;
a3f97cbb
JW
11320
11321 /* Ignore blocks never really used to make RTL. */
1e7f092a
JM
11322 if (stmt == NULL_TREE || !TREE_USED (stmt)
11323 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
71dfc51f 11324 return;
a3f97cbb 11325
a20612aa
RH
11326 /* If the block is one fragment of a non-contiguous block, do not
11327 process the variables, since they will have been done by the
11328 origin block. Do process subblocks. */
11329 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11330 {
11331 tree sub;
11332
2ad9852d 11333 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
a20612aa 11334 gen_block_die (sub, context_die, depth + 1);
2ad9852d 11335
a20612aa
RH
11336 return;
11337 }
11338
a3f97cbb
JW
11339 /* Determine the "ultimate origin" of this block. This block may be an
11340 inlined instance of an inlined instance of inline function, so we have
11341 to trace all of the way back through the origin chain to find out what
11342 sort of node actually served as the original seed for the creation of
11343 the current block. */
11344 origin = block_ultimate_origin (stmt);
11345 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11346
11347 /* Determine if we need to output any Dwarf DIEs at all to represent this
11348 block. */
11349 if (origin_code == FUNCTION_DECL)
71dfc51f
RK
11350 /* The outer scopes for inlinings *must* always be represented. We
11351 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11352 must_output_die = 1;
a3f97cbb
JW
11353 else
11354 {
11355 /* In the case where the current block represents an inlining of the
556273e0 11356 "body block" of an inline function, we must *NOT* output any DIE for
2ad9852d
RK
11357 this block because we have already output a DIE to represent the whole
11358 inlined function scope and the "body block" of any function doesn't
11359 really represent a different scope according to ANSI C rules. So we
11360 check here to make sure that this block does not represent a "body
11361 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
d7248bff 11362 if (! is_body_block (origin ? origin : stmt))
a3f97cbb
JW
11363 {
11364 /* Determine if this block directly contains any "significant"
11365 local declarations which we will need to output DIEs for. */
11366 if (debug_info_level > DINFO_LEVEL_TERSE)
71dfc51f
RK
11367 /* We are not in terse mode so *any* local declaration counts
11368 as being a "significant" one. */
11369 must_output_die = (BLOCK_VARS (stmt) != NULL);
a3f97cbb 11370 else
71dfc51f
RK
11371 /* We are in terse mode, so only local (nested) function
11372 definitions count as "significant" local declarations. */
11373 for (decl = BLOCK_VARS (stmt);
11374 decl != NULL; decl = TREE_CHAIN (decl))
11375 if (TREE_CODE (decl) == FUNCTION_DECL
11376 && DECL_INITIAL (decl))
a3f97cbb 11377 {
71dfc51f
RK
11378 must_output_die = 1;
11379 break;
a3f97cbb 11380 }
a3f97cbb
JW
11381 }
11382 }
11383
11384 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11385 DIE for any block which contains no significant local declarations at
11386 all. Rather, in such cases we just call `decls_for_scope' so that any
11387 needed Dwarf info for any sub-blocks will get properly generated. Note
11388 that in terse mode, our definition of what constitutes a "significant"
11389 local declaration gets restricted to include only inlined function
11390 instances and local (nested) function definitions. */
11391 if (must_output_die)
11392 {
11393 if (origin_code == FUNCTION_DECL)
71dfc51f 11394 gen_inlined_subroutine_die (stmt, context_die, depth);
a3f97cbb 11395 else
71dfc51f 11396 gen_lexical_block_die (stmt, context_die, depth);
a3f97cbb
JW
11397 }
11398 else
d7248bff 11399 decls_for_scope (stmt, context_die, depth);
a3f97cbb
JW
11400}
11401
11402/* Generate all of the decls declared within a given scope and (recursively)
9ec36da5 11403 all of its sub-blocks. */
71dfc51f 11404
a3f97cbb 11405static void
d7248bff 11406decls_for_scope (stmt, context_die, depth)
b3694847
SS
11407 tree stmt;
11408 dw_die_ref context_die;
d7248bff 11409 int depth;
a3f97cbb 11410{
b3694847
SS
11411 tree decl;
11412 tree subblocks;
71dfc51f 11413
a3f97cbb 11414 /* Ignore blocks never really used to make RTL. */
71dfc51f
RK
11415 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11416 return;
11417
88dad228
JM
11418 /* Output the DIEs to represent all of the data objects and typedefs
11419 declared directly within this block but not within any nested
11420 sub-blocks. Also, nested function and tag DIEs have been
11421 generated with a parent of NULL; fix that up now. */
2ad9852d 11422 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
a3f97cbb 11423 {
b3694847 11424 dw_die_ref die;
a94dbf2c 11425
88dad228 11426 if (TREE_CODE (decl) == FUNCTION_DECL)
a94dbf2c 11427 die = lookup_decl_die (decl);
88dad228 11428 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
a94dbf2c
JM
11429 die = lookup_type_die (TREE_TYPE (decl));
11430 else
11431 die = NULL;
11432
71dfc51f 11433 if (die != NULL && die->die_parent == NULL)
ef76d03b 11434 add_child_die (context_die, die);
88dad228
JM
11435 else
11436 gen_decl_die (decl, context_die);
a3f97cbb
JW
11437 }
11438
11439 /* Output the DIEs to represent all sub-blocks (and the items declared
11440 therein) of this block. */
11441 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11442 subblocks != NULL;
11443 subblocks = BLOCK_CHAIN (subblocks))
71dfc51f 11444 gen_block_die (subblocks, context_die, depth + 1);
a3f97cbb
JW
11445}
11446
a94dbf2c 11447/* Is this a typedef we can avoid emitting? */
71dfc51f
RK
11448
11449static inline int
a94dbf2c 11450is_redundant_typedef (decl)
b3694847 11451 tree decl;
a94dbf2c
JM
11452{
11453 if (TYPE_DECL_IS_STUB (decl))
11454 return 1;
71dfc51f 11455
a94dbf2c
JM
11456 if (DECL_ARTIFICIAL (decl)
11457 && DECL_CONTEXT (decl)
11458 && is_tagged_type (DECL_CONTEXT (decl))
11459 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11460 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11461 /* Also ignore the artificial member typedef for the class name. */
11462 return 1;
71dfc51f 11463
a94dbf2c
JM
11464 return 0;
11465}
11466
a3f97cbb 11467/* Generate Dwarf debug information for a decl described by DECL. */
71dfc51f 11468
a3f97cbb
JW
11469static void
11470gen_decl_die (decl, context_die)
b3694847
SS
11471 tree decl;
11472 dw_die_ref context_die;
a3f97cbb 11473{
b3694847 11474 tree origin;
71dfc51f 11475
f11c3043 11476 if (DECL_P (decl) && DECL_IGNORED_P (decl))
71dfc51f 11477 return;
a3f97cbb 11478
a3f97cbb
JW
11479 switch (TREE_CODE (decl))
11480 {
2ad9852d
RK
11481 case ERROR_MARK:
11482 break;
11483
a3f97cbb 11484 case CONST_DECL:
556273e0 11485 /* The individual enumerators of an enum type get output when we output
a3f97cbb
JW
11486 the Dwarf representation of the relevant enum type itself. */
11487 break;
11488
11489 case FUNCTION_DECL:
4edb7b60
JM
11490 /* Don't output any DIEs to represent mere function declarations,
11491 unless they are class members or explicit block externs. */
11492 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
777ad4c2 11493 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
71dfc51f 11494 break;
bdb669cb 11495
5daf7c0a
JM
11496 /* If we're emitting a clone, emit info for the abstract instance. */
11497 if (DECL_ORIGIN (decl) != decl)
11498 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
2ad9852d 11499
1cfdcc15
JM
11500 /* If we're emitting an out-of-line copy of an inline function,
11501 emit info for the abstract instance and set up to refer to it. */
5daf7c0a
JM
11502 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11503 && ! class_scope_p (context_die)
11504 /* dwarf2out_abstract_function won't emit a die if this is just
11505 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11506 that case, because that works only if we have a die. */
11507 && DECL_INITIAL (decl) != NULL_TREE)
1cfdcc15 11508 {
1edf43d6 11509 dwarf2out_abstract_function (decl);
1cfdcc15
JM
11510 set_decl_origin_self (decl);
11511 }
2ad9852d 11512
5daf7c0a
JM
11513 /* Otherwise we're emitting the primary DIE for this decl. */
11514 else if (debug_info_level > DINFO_LEVEL_TERSE)
a94dbf2c
JM
11515 {
11516 /* Before we describe the FUNCTION_DECL itself, make sure that we
11517 have described its return type. */
11518 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11519
2081603c
JM
11520 /* And its virtual context. */
11521 if (DECL_VINDEX (decl) != NULL_TREE)
11522 gen_type_die (DECL_CONTEXT (decl), context_die);
11523
a94dbf2c
JM
11524 /* And its containing type. */
11525 origin = decl_class_context (decl);
71dfc51f 11526 if (origin != NULL_TREE)
10a11b75 11527 gen_type_die_for_member (origin, decl, context_die);
a94dbf2c 11528 }
a3f97cbb
JW
11529
11530 /* Now output a DIE to represent the function itself. */
11531 gen_subprogram_die (decl, context_die);
11532 break;
11533
11534 case TYPE_DECL:
11535 /* If we are in terse mode, don't generate any DIEs to represent any
4927276d 11536 actual typedefs. */
a3f97cbb 11537 if (debug_info_level <= DINFO_LEVEL_TERSE)
4927276d 11538 break;
a3f97cbb 11539
2ad9852d
RK
11540 /* In the special case of a TYPE_DECL node representing the declaration
11541 of some type tag, if the given TYPE_DECL is marked as having been
11542 instantiated from some other (original) TYPE_DECL node (e.g. one which
11543 was generated within the original definition of an inline function) we
11544 have to generate a special (abbreviated) DW_TAG_structure_type,
11545 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
2081603c 11546 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
a3f97cbb
JW
11547 {
11548 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11549 break;
11550 }
a3f97cbb 11551
a94dbf2c
JM
11552 if (is_redundant_typedef (decl))
11553 gen_type_die (TREE_TYPE (decl), context_die);
11554 else
71dfc51f
RK
11555 /* Output a DIE to represent the typedef itself. */
11556 gen_typedef_die (decl, context_die);
a3f97cbb
JW
11557 break;
11558
11559 case LABEL_DECL:
11560 if (debug_info_level >= DINFO_LEVEL_NORMAL)
71dfc51f 11561 gen_label_die (decl, context_die);
a3f97cbb
JW
11562 break;
11563
11564 case VAR_DECL:
11565 /* If we are in terse mode, don't generate any DIEs to represent any
11566 variable declarations or definitions. */
11567 if (debug_info_level <= DINFO_LEVEL_TERSE)
71dfc51f 11568 break;
a3f97cbb
JW
11569
11570 /* Output any DIEs that are needed to specify the type of this data
11571 object. */
11572 gen_type_die (TREE_TYPE (decl), context_die);
11573
a94dbf2c
JM
11574 /* And its containing type. */
11575 origin = decl_class_context (decl);
71dfc51f 11576 if (origin != NULL_TREE)
10a11b75 11577 gen_type_die_for_member (origin, decl, context_die);
a94dbf2c 11578
a3f97cbb
JW
11579 /* Now output the DIE to represent the data object itself. This gets
11580 complicated because of the possibility that the VAR_DECL really
11581 represents an inlined instance of a formal parameter for an inline
11582 function. */
11583 origin = decl_ultimate_origin (decl);
71dfc51f
RK
11584 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11585 gen_formal_parameter_die (decl, context_die);
a3f97cbb 11586 else
71dfc51f 11587 gen_variable_die (decl, context_die);
a3f97cbb
JW
11588 break;
11589
11590 case FIELD_DECL:
2ad9852d
RK
11591 /* Ignore the nameless fields that are used to skip bits but handle C++
11592 anonymous unions. */
71dfc51f
RK
11593 if (DECL_NAME (decl) != NULL_TREE
11594 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
a3f97cbb
JW
11595 {
11596 gen_type_die (member_declared_type (decl), context_die);
11597 gen_field_die (decl, context_die);
11598 }
11599 break;
11600
11601 case PARM_DECL:
11602 gen_type_die (TREE_TYPE (decl), context_die);
11603 gen_formal_parameter_die (decl, context_die);
11604 break;
11605
348bb3c7
JM
11606 case NAMESPACE_DECL:
11607 /* Ignore for now. */
11608 break;
11609
a3f97cbb
JW
11610 default:
11611 abort ();
11612 }
a3f97cbb 11613}
54ba1f0d
RH
11614
11615static void
11616mark_limbo_die_list (ptr)
11617 void *ptr ATTRIBUTE_UNUSED;
11618{
11619 limbo_die_node *node;
c26fbbca 11620 for (node = limbo_die_list; node; node = node->next)
54ba1f0d
RH
11621 ggc_mark_tree (node->created_for);
11622}
a3f97cbb 11623\f
14a774a9
RK
11624/* Add Ada "use" clause information for SGI Workshop debugger. */
11625
11626void
11627dwarf2out_add_library_unit_info (filename, context_list)
c6991660
KG
11628 const char *filename;
11629 const char *context_list;
14a774a9
RK
11630{
11631 unsigned int file_index;
11632
11633 if (filename != NULL)
11634 {
54ba1f0d 11635 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
556273e0 11636 tree context_list_decl
14a774a9
RK
11637 = build_decl (LABEL_DECL, get_identifier (context_list),
11638 void_type_node);
11639
11640 TREE_PUBLIC (context_list_decl) = TRUE;
11641 add_name_attribute (unit_die, context_list);
981975b6 11642 file_index = lookup_filename (filename);
14a774a9
RK
11643 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11644 add_pubname (context_list_decl, unit_die);
11645 }
11646}
11647
2ad9852d 11648/* Output debug information for global decl DECL. Called from toplev.c after
2b85879e 11649 compilation proper has finished. */
2ad9852d 11650
2b85879e
NB
11651static void
11652dwarf2out_global_decl (decl)
11653 tree decl;
11654{
11655 /* Output DWARF2 information for file-scope tentative data object
2ad9852d
RK
11656 declarations, file-scope (extern) function declarations (which had no
11657 corresponding body) and file-scope tagged type declarations and
11658 definitions which have not yet been forced out. */
2b85879e
NB
11659 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11660 dwarf2out_decl (decl);
11661}
11662
71dfc51f
RK
11663/* Write the debugging output for DECL. */
11664
a3f97cbb 11665void
88dad228 11666dwarf2out_decl (decl)
b3694847 11667 tree decl;
a3f97cbb 11668{
b3694847 11669 dw_die_ref context_die = comp_unit_die;
88dad228 11670
a3f97cbb
JW
11671 switch (TREE_CODE (decl))
11672 {
2ad9852d
RK
11673 case ERROR_MARK:
11674 return;
11675
a3f97cbb 11676 case FUNCTION_DECL:
556273e0 11677 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
a3f97cbb
JW
11678 builtin function. Explicit programmer-supplied declarations of
11679 these same functions should NOT be ignored however. */
9765e357 11680 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
b1ccbc24 11681 return;
a3f97cbb
JW
11682
11683 /* What we would really like to do here is to filter out all mere
11684 file-scope declarations of file-scope functions which are never
11685 referenced later within this translation unit (and keep all of ones
556273e0
KH
11686 that *are* referenced later on) but we aren't clairvoyant, so we have
11687 no idea which functions will be referenced in the future (i.e. later
a3f97cbb 11688 on within the current translation unit). So here we just ignore all
556273e0 11689 file-scope function declarations which are not also definitions. If
956d6950 11690 and when the debugger needs to know something about these functions,
556273e0 11691 it will have to hunt around and find the DWARF information associated
2ad9852d
RK
11692 with the definition of the function.
11693
11694 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11695 nodes represent definitions and which ones represent mere
11696 declarations. We have to check DECL_INITIAL instead. That's because
11697 the C front-end supports some weird semantics for "extern inline"
11698 function definitions. These can get inlined within the current
11699 translation unit (an thus, we need to generate Dwarf info for their
11700 abstract instances so that the Dwarf info for the concrete inlined
11701 instances can have something to refer to) but the compiler never
11702 generates any out-of-lines instances of such things (despite the fact
11703 that they *are* definitions).
11704
11705 The important point is that the C front-end marks these "extern
11706 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11707 them anyway. Note that the C++ front-end also plays some similar games
11708 for inline function definitions appearing within include files which
11709 also contain `#pragma interface' pragmas. */
a3f97cbb 11710 if (DECL_INITIAL (decl) == NULL_TREE)
b1ccbc24 11711 return;
88dad228 11712
9c6cd30e
JM
11713 /* If we're a nested function, initially use a parent of NULL; if we're
11714 a plain function, this will be fixed up in decls_for_scope. If
11715 we're a method, it will be ignored, since we already have a DIE. */
88dad228 11716 if (decl_function_context (decl))
9c6cd30e 11717 context_die = NULL;
a3f97cbb
JW
11718 break;
11719
11720 case VAR_DECL:
556273e0 11721 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
a3f97cbb
JW
11722 declaration and if the declaration was never even referenced from
11723 within this entire compilation unit. We suppress these DIEs in
11724 order to save space in the .debug section (by eliminating entries
11725 which are probably useless). Note that we must not suppress
11726 block-local extern declarations (whether used or not) because that
11727 would screw-up the debugger's name lookup mechanism and cause it to
11728 miss things which really ought to be in scope at a given point. */
11729 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
71dfc51f 11730 return;
a3f97cbb
JW
11731
11732 /* If we are in terse mode, don't generate any DIEs to represent any
11733 variable declarations or definitions. */
11734 if (debug_info_level <= DINFO_LEVEL_TERSE)
71dfc51f 11735 return;
a3f97cbb
JW
11736 break;
11737
11738 case TYPE_DECL:
57fb7689
JM
11739 /* Don't emit stubs for types unless they are needed by other DIEs. */
11740 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11741 return;
11742
a3f97cbb 11743 /* Don't bother trying to generate any DIEs to represent any of the
a9d38797
JM
11744 normal built-in types for the language we are compiling. */
11745 if (DECL_SOURCE_LINE (decl) == 0)
a94dbf2c
JM
11746 {
11747 /* OK, we need to generate one for `bool' so GDB knows what type
11748 comparisons have. */
11749 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11750 == DW_LANG_C_plus_plus)
f11c3043
RK
11751 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11752 && ! DECL_IGNORED_P (decl))
a94dbf2c 11753 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
71dfc51f 11754
a94dbf2c
JM
11755 return;
11756 }
a3f97cbb 11757
88dad228 11758 /* If we are in terse mode, don't generate any DIEs for types. */
a3f97cbb 11759 if (debug_info_level <= DINFO_LEVEL_TERSE)
4927276d 11760 return;
88dad228
JM
11761
11762 /* If we're a function-scope tag, initially use a parent of NULL;
11763 this will be fixed up in decls_for_scope. */
11764 if (decl_function_context (decl))
3f76745e 11765 context_die = NULL;
88dad228 11766
a3f97cbb
JW
11767 break;
11768
11769 default:
11770 return;
11771 }
11772
88dad228 11773 gen_decl_die (decl, context_die);
a3f97cbb
JW
11774}
11775
11776/* Output a marker (i.e. a label) for the beginning of the generated code for
11777 a lexical block. */
71dfc51f 11778
a5a42b92 11779static void
e2a12aca 11780dwarf2out_begin_block (line, blocknum)
a5a42b92
NB
11781 unsigned int line ATTRIBUTE_UNUSED;
11782 unsigned int blocknum;
a3f97cbb 11783{
a3f97cbb 11784 function_section (current_function_decl);
8215347e 11785 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
a3f97cbb
JW
11786}
11787
11788/* Output a marker (i.e. a label) for the end of the generated code for a
11789 lexical block. */
71dfc51f 11790
a5a42b92 11791static void
e2a12aca 11792dwarf2out_end_block (line, blocknum)
a5a42b92
NB
11793 unsigned int line ATTRIBUTE_UNUSED;
11794 unsigned int blocknum;
a3f97cbb 11795{
a3f97cbb 11796 function_section (current_function_decl);
8215347e 11797 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
a3f97cbb
JW
11798}
11799
64b59a80
JM
11800/* Returns nonzero if it is appropriate not to emit any debugging
11801 information for BLOCK, because it doesn't contain any instructions.
fcd7f76b 11802
64b59a80
JM
11803 Don't allow this for blocks with nested functions or local classes
11804 as we would end up with orphans, and in the presence of scheduling
11805 we may end up calling them anyway. */
11806
e1772ac0 11807static bool
fcd7f76b
JM
11808dwarf2out_ignore_block (block)
11809 tree block;
11810{
11811 tree decl;
2ad9852d 11812
fcd7f76b 11813 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
64b59a80
JM
11814 if (TREE_CODE (decl) == FUNCTION_DECL
11815 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11816 return 0;
2ad9852d 11817
64b59a80 11818 return 1;
fcd7f76b
JM
11819}
11820
2ad9852d 11821/* Lookup FILE_NAME (in the list of filenames that we know about here in
9a666dda 11822 dwarf2out.c) and return its "index". The index of each (known) filename is
2ad9852d
RK
11823 just a unique number which is associated with only that one filename. We
11824 need such numbers for the sake of generating labels (in the .debug_sfnames
11825 section) and references to those files numbers (in the .debug_srcinfo
11826 and.debug_macinfo sections). If the filename given as an argument is not
11827 found in our current list, add it to the list and assign it the next
11828 available unique index number. In order to speed up searches, we remember
11829 the index of the filename was looked up last. This handles the majority of
11830 all searches. */
71dfc51f 11831
a3f97cbb 11832static unsigned
981975b6 11833lookup_filename (file_name)
d560ee52 11834 const char *file_name;
a3f97cbb 11835{
b3694847 11836 unsigned i;
a3f97cbb 11837
981975b6
RH
11838 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11839 if (strcmp (file_name, "<internal>") == 0
11840 || strcmp (file_name, "<built-in>") == 0)
11841 return 0;
11842
2e18bbae
RH
11843 /* Check to see if the file name that was searched on the previous
11844 call matches this file name. If so, return the index. */
981975b6 11845 if (file_table.last_lookup_index != 0)
2ad9852d
RK
11846 if (0 == strcmp (file_name,
11847 file_table.table[file_table.last_lookup_index]))
981975b6 11848 return file_table.last_lookup_index;
a3f97cbb
JW
11849
11850 /* Didn't match the previous lookup, search the table */
2ad9852d 11851 for (i = 1; i < file_table.in_use; i++)
981975b6 11852 if (strcmp (file_name, file_table.table[i]) == 0)
71dfc51f 11853 {
981975b6 11854 file_table.last_lookup_index = i;
71dfc51f
RK
11855 return i;
11856 }
a3f97cbb 11857
556273e0 11858 /* Prepare to add a new table entry by making sure there is enough space in
a3f97cbb 11859 the table to do so. If not, expand the current table. */
981975b6 11860 if (i == file_table.allocated)
a3f97cbb 11861 {
981975b6
RH
11862 file_table.allocated = i + FILE_TABLE_INCREMENT;
11863 file_table.table = (char **)
11864 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
a3f97cbb
JW
11865 }
11866
71dfc51f 11867 /* Add the new entry to the end of the filename table. */
981975b6
RH
11868 file_table.table[i] = xstrdup (file_name);
11869 file_table.in_use = i + 1;
11870 file_table.last_lookup_index = i;
2e18bbae 11871
acc187f5 11872 if (DWARF2_ASM_LINE_DEBUG_INFO)
211a0cbe
GDR
11873 {
11874 fprintf (asm_out_file, "\t.file %u ", i);
11875 output_quoted_string (asm_out_file, file_name);
11876 fputc ('\n', asm_out_file);
11877 }
acc187f5 11878
2e18bbae
RH
11879 return i;
11880}
11881
11882static void
981975b6 11883init_file_table ()
2e18bbae
RH
11884{
11885 /* Allocate the initial hunk of the file_table. */
981975b6
RH
11886 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11887 file_table.allocated = FILE_TABLE_INCREMENT;
71dfc51f 11888
2e18bbae 11889 /* Skip the first entry - file numbers begin at 1. */
981975b6
RH
11890 file_table.in_use = 1;
11891 file_table.last_lookup_index = 0;
a3f97cbb
JW
11892}
11893
11894/* Output a label to mark the beginning of a source code line entry
11895 and record information relating to this source line, in
11896 'line_info_table' for later output of the .debug_line section. */
71dfc51f 11897
e2a12aca 11898static void
653e276c
NB
11899dwarf2out_source_line (line, filename)
11900 unsigned int line;
b3694847 11901 const char *filename;
a3f97cbb 11902{
a3f97cbb
JW
11903 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11904 {
11905 function_section (current_function_decl);
a3f97cbb 11906
8aaf55ac
JM
11907 /* If requested, emit something human-readable. */
11908 if (flag_debug_asm)
11909 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11910 filename, line);
11911
b2244e22
JW
11912 if (DWARF2_ASM_LINE_DEBUG_INFO)
11913 {
981975b6 11914 unsigned file_num = lookup_filename (filename);
b2244e22 11915
981975b6 11916 /* Emit the .loc directive understood by GNU as. */
2e18bbae 11917 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
b2244e22
JW
11918
11919 /* Indicate that line number info exists. */
2ad9852d 11920 line_info_table_in_use++;
b2244e22
JW
11921
11922 /* Indicate that multiple line number tables exist. */
11923 if (DECL_SECTION_NAME (current_function_decl))
2ad9852d 11924 separate_line_info_table_in_use++;
b2244e22
JW
11925 }
11926 else if (DECL_SECTION_NAME (current_function_decl))
a3f97cbb 11927 {
b3694847 11928 dw_separate_line_info_ref line_info;
5c90448c
JM
11929 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11930 separate_line_info_table_in_use);
e90b62db
JM
11931
11932 /* expand the line info table if necessary */
11933 if (separate_line_info_table_in_use
11934 == separate_line_info_table_allocated)
11935 {
11936 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11937 separate_line_info_table
71dfc51f
RK
11938 = (dw_separate_line_info_ref)
11939 xrealloc (separate_line_info_table,
11940 separate_line_info_table_allocated
11941 * sizeof (dw_separate_line_info_entry));
e90b62db 11942 }
71dfc51f
RK
11943
11944 /* Add the new entry at the end of the line_info_table. */
e90b62db
JM
11945 line_info
11946 = &separate_line_info_table[separate_line_info_table_in_use++];
981975b6 11947 line_info->dw_file_num = lookup_filename (filename);
e90b62db 11948 line_info->dw_line_num = line;
df696a75 11949 line_info->function = current_function_funcdef_no;
e90b62db
JM
11950 }
11951 else
11952 {
b3694847 11953 dw_line_info_ref line_info;
71dfc51f 11954
5c90448c
JM
11955 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11956 line_info_table_in_use);
e90b62db 11957
71dfc51f 11958 /* Expand the line info table if necessary. */
e90b62db
JM
11959 if (line_info_table_in_use == line_info_table_allocated)
11960 {
11961 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11962 line_info_table
71dfc51f
RK
11963 = (dw_line_info_ref)
11964 xrealloc (line_info_table,
11965 (line_info_table_allocated
11966 * sizeof (dw_line_info_entry)));
e90b62db 11967 }
71dfc51f
RK
11968
11969 /* Add the new entry at the end of the line_info_table. */
e90b62db 11970 line_info = &line_info_table[line_info_table_in_use++];
981975b6 11971 line_info->dw_file_num = lookup_filename (filename);
e90b62db 11972 line_info->dw_line_num = line;
a3f97cbb 11973 }
a3f97cbb
JW
11974 }
11975}
11976
30f7a378 11977/* Record the beginning of a new source file. */
71dfc51f 11978
7f905405 11979static void
84a5b4f8 11980dwarf2out_start_source_file (lineno, filename)
b3694847
SS
11981 unsigned int lineno;
11982 const char *filename;
a3f97cbb 11983{
881c6935
JM
11984 if (flag_eliminate_dwarf2_dups)
11985 {
11986 /* Record the beginning of the file for break_out_includes. */
54ba1f0d 11987 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
881c6935
JM
11988 add_AT_string (bincl_die, DW_AT_name, filename);
11989 }
2ad9852d 11990
84a5b4f8
DB
11991 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11992 {
715bdd29 11993 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
84a5b4f8 11994 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
7c262518
RH
11995 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11996 lineno);
11997 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11998 "Filename we just started");
84a5b4f8 11999 }
a3f97cbb
JW
12000}
12001
cc260610 12002/* Record the end of a source file. */
71dfc51f 12003
7f905405
NB
12004static void
12005dwarf2out_end_source_file (lineno)
12006 unsigned int lineno ATTRIBUTE_UNUSED;
a3f97cbb 12007{
881c6935 12008 if (flag_eliminate_dwarf2_dups)
2ad9852d 12009 /* Record the end of the file for break_out_includes. */
54ba1f0d 12010 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
2ad9852d 12011
84a5b4f8
DB
12012 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12013 {
715bdd29 12014 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
84a5b4f8
DB
12015 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12016 }
a3f97cbb
JW
12017}
12018
cc260610 12019/* Called from debug_define in toplev.c. The `buffer' parameter contains
a3f97cbb
JW
12020 the tail part of the directive line, i.e. the part which is past the
12021 initial whitespace, #, whitespace, directive-name, whitespace part. */
71dfc51f 12022
7f905405 12023static void
9a666dda 12024dwarf2out_define (lineno, buffer)
b3694847
SS
12025 unsigned lineno ATTRIBUTE_UNUSED;
12026 const char *buffer ATTRIBUTE_UNUSED;
a3f97cbb 12027{
84a5b4f8
DB
12028 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12029 {
715bdd29 12030 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
84a5b4f8
DB
12031 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
12032 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12033 dw2_asm_output_nstring (buffer, -1, "The macro");
12034 }
a3f97cbb
JW
12035}
12036
cc260610 12037/* Called from debug_undef in toplev.c. The `buffer' parameter contains
a3f97cbb
JW
12038 the tail part of the directive line, i.e. the part which is past the
12039 initial whitespace, #, whitespace, directive-name, whitespace part. */
71dfc51f 12040
7f905405 12041static void
9a666dda 12042dwarf2out_undef (lineno, buffer)
b3694847
SS
12043 unsigned lineno ATTRIBUTE_UNUSED;
12044 const char *buffer ATTRIBUTE_UNUSED;
a3f97cbb 12045{
84a5b4f8
DB
12046 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12047 {
715bdd29 12048 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
84a5b4f8
DB
12049 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
12050 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12051 dw2_asm_output_nstring (buffer, -1, "The macro");
12052 }
a3f97cbb
JW
12053}
12054
12055/* Set up for Dwarf output at the start of compilation. */
71dfc51f 12056
a51d908e 12057static void
e2a12aca 12058dwarf2out_init (main_input_filename)
b3694847 12059 const char *main_input_filename;
a3f97cbb 12060{
acc187f5
RH
12061 init_file_table ();
12062
a3f97cbb
JW
12063 /* Remember the name of the primary input file. */
12064 primary_filename = main_input_filename;
12065
acc187f5
RH
12066 /* Add it to the file table first, under the assumption that we'll
12067 be emitting line number data for it first, which avoids having
12068 to add an initial DW_LNS_set_file. */
12069 lookup_filename (main_input_filename);
a3f97cbb 12070
a3f97cbb
JW
12071 /* Allocate the initial hunk of the decl_die_table. */
12072 decl_die_table
3de90026 12073 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
a3f97cbb
JW
12074 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12075 decl_die_table_in_use = 0;
12076
12077 /* Allocate the initial hunk of the decl_scope_table. */
244a4af0 12078 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
a3f97cbb
JW
12079
12080 /* Allocate the initial hunk of the abbrev_die_table. */
12081 abbrev_die_table
3de90026
RH
12082 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
12083 sizeof (dw_die_ref));
a3f97cbb 12084 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
71dfc51f 12085 /* Zero-th entry is allocated, but unused */
a3f97cbb
JW
12086 abbrev_die_table_in_use = 1;
12087
12088 /* Allocate the initial hunk of the line_info_table. */
12089 line_info_table
3de90026
RH
12090 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
12091 sizeof (dw_line_info_entry));
a3f97cbb 12092 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
2ad9852d 12093
71dfc51f 12094 /* Zero-th entry is allocated, but unused */
a3f97cbb
JW
12095 line_info_table_in_use = 1;
12096
556273e0 12097 /* Generate the initial DIE for the .debug section. Note that the (string)
a3f97cbb 12098 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
556273e0 12099 will (typically) be a relative pathname and that this pathname should be
a3f97cbb
JW
12100 taken as being relative to the directory from which the compiler was
12101 invoked when the given (base) source file was compiled. */
a96c67ec 12102 comp_unit_die = gen_compile_unit_die (main_input_filename);
a3f97cbb 12103
244a4af0 12104 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
244a4af0 12105
1f8f4a0b 12106 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
1865dbb5 12107
54ba1f0d
RH
12108 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
12109
5c90448c 12110 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9d2f2c45
RH
12111 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12112 DEBUG_ABBREV_SECTION_LABEL, 0);
b366352b
MM
12113 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12114 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12115 else
f99ffb60 12116 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
2ad9852d 12117
556273e0 12118 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
8b790721 12119 DEBUG_INFO_SECTION_LABEL, 0);
556273e0 12120 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
8b790721 12121 DEBUG_LINE_SECTION_LABEL, 0);
2bee6045
JJ
12122 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12123 DEBUG_RANGES_SECTION_LABEL, 0);
715bdd29 12124 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
8b790721 12125 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
715bdd29 12126 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
8b790721 12127 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
715bdd29 12128 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
8b790721 12129 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
2ad9852d 12130
84a5b4f8
DB
12131 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12132 {
715bdd29 12133 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
84a5b4f8
DB
12134 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12135 DEBUG_MACINFO_SECTION_LABEL, 0);
12136 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12137 }
7c262518
RH
12138
12139 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12140 {
12141 text_section ();
12142 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12143 }
a3f97cbb
JW
12144}
12145
9eb4015a
JJ
12146/* Allocate a string in .debug_str hash table. */
12147
12148static hashnode
12149indirect_string_alloc (tab)
12150 hash_table *tab ATTRIBUTE_UNUSED;
12151{
12152 struct indirect_string_node *node;
12153
12154 node = xmalloc (sizeof (struct indirect_string_node));
12155 node->refcount = 0;
12156 node->form = 0;
12157 node->label = NULL;
2ad9852d 12158
9eb4015a
JJ
12159 return (hashnode) node;
12160}
12161
12162/* A helper function for dwarf2out_finish called through
12163 ht_forall. Emit one queued .debug_str string. */
12164
12165static int
12166output_indirect_string (pfile, h, v)
12167 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
12168 hashnode h;
12169 const PTR v ATTRIBUTE_UNUSED;
12170{
2ad9852d 12171 struct indirect_string_node *node = (struct indirect_string_node *) h;
9eb4015a 12172
9eb4015a
JJ
12173 if (node->form == DW_FORM_strp)
12174 {
12175 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12176 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12177 assemble_string ((const char *) HT_STR (&node->id),
12178 HT_LEN (&node->id) + 1);
12179 }
2ad9852d 12180
9eb4015a
JJ
12181 return 1;
12182}
12183
a3f97cbb
JW
12184/* Output stuff that dwarf requires at the end of every file,
12185 and generate the DWARF-2 debugging info. */
71dfc51f 12186
a51d908e 12187static void
e2a12aca 12188dwarf2out_finish (input_filename)
b3694847 12189 const char *input_filename ATTRIBUTE_UNUSED;
a3f97cbb 12190{
ef76d03b 12191 limbo_die_node *node, *next_node;
ae0ed63a 12192 dw_die_ref die = 0;
ef76d03b
JW
12193
12194 /* Traverse the limbo die list, and add parent/child links. The only
12195 dies without parents that should be here are concrete instances of
12196 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12197 For concrete instances, we can get the parent die from the abstract
12198 instance. */
12199 for (node = limbo_die_list; node; node = next_node)
12200 {
12201 next_node = node->next;
12202 die = node->die;
12203
12204 if (die->die_parent == NULL)
12205 {
a96c67ec 12206 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
54ba1f0d 12207 tree context;
2ad9852d 12208
a96c67ec
JM
12209 if (origin)
12210 add_child_die (origin->die_parent, die);
ef76d03b 12211 else if (die == comp_unit_die)
a96c67ec 12212 ;
aea9695c
RK
12213 /* If this was an expression for a bound involved in a function
12214 return type, it may be a SAVE_EXPR for which we weren't able
12215 to find a DIE previously. So try now. */
12216 else if (node->created_for
12217 && TREE_CODE (node->created_for) == SAVE_EXPR
12218 && 0 != (origin = (lookup_decl_die
12219 (SAVE_EXPR_CONTEXT
12220 (node->created_for)))))
12221 add_child_die (origin, die);
6bb28965
JM
12222 else if (errorcount > 0 || sorrycount > 0)
12223 /* It's OK to be confused by errors in the input. */
12224 add_child_die (comp_unit_die, die);
54ba1f0d
RH
12225 else if (node->created_for
12226 && ((DECL_P (node->created_for)
c26fbbca 12227 && (context = DECL_CONTEXT (node->created_for)))
54ba1f0d
RH
12228 || (TYPE_P (node->created_for)
12229 && (context = TYPE_CONTEXT (node->created_for))))
12230 && TREE_CODE (context) == FUNCTION_DECL)
12231 {
12232 /* In certain situations, the lexical block containing a
12233 nested function can be optimized away, which results
12234 in the nested function die being orphaned. Likewise
12235 with the return type of that nested function. Force
12236 this to be a child of the containing function. */
12237 origin = lookup_decl_die (context);
12238 if (! origin)
12239 abort ();
12240 add_child_die (origin, die);
12241 }
ef76d03b
JW
12242 else
12243 abort ();
12244 }
2ad9852d 12245
ef76d03b
JW
12246 free (node);
12247 }
2ad9852d 12248
a96c67ec 12249 limbo_die_list = NULL;
ef76d03b 12250
8a8c3656
JM
12251 /* Walk through the list of incomplete types again, trying once more to
12252 emit full debugging info for them. */
12253 retry_incomplete_types ();
12254
881c6935
JM
12255 /* We need to reverse all the dies before break_out_includes, or
12256 we'll see the end of an include file before the beginning. */
12257 reverse_all_dies (comp_unit_die);
12258
12259 /* Generate separate CUs for each of the include files we've seen.
12260 They will go into limbo_die_list. */
5f632b5e
JM
12261 if (flag_eliminate_dwarf2_dups)
12262 break_out_includes (comp_unit_die);
881c6935
JM
12263
12264 /* Traverse the DIE's and add add sibling attributes to those DIE's
12265 that have children. */
a3f97cbb 12266 add_sibling_attributes (comp_unit_die);
881c6935
JM
12267 for (node = limbo_die_list; node; node = node->next)
12268 add_sibling_attributes (node->die);
a3f97cbb
JW
12269
12270 /* Output a terminator label for the .text section. */
7c262518 12271 text_section ();
5c90448c 12272 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
a3f97cbb 12273
db3c0315
MM
12274 /* Output the source line correspondence table. We must do this
12275 even if there is no line information. Otherwise, on an empty
12276 translation unit, we will generate a present, but empty,
12277 .debug_info section. IRIX 6.5 `nm' will then complain when
12278 examining the file. */
12279 if (! DWARF2_ASM_LINE_DEBUG_INFO)
e90b62db 12280 {
715bdd29 12281 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
db3c0315
MM
12282 output_line_info ();
12283 }
71dfc51f 12284
b38a75e5
RH
12285 /* Output location list section if necessary. */
12286 if (have_location_lists)
12287 {
12288 /* Output the location lists info. */
12289 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12290 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12291 DEBUG_LOC_SECTION_LABEL, 0);
12292 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12293 output_location_lists (die);
12294 have_location_lists = 0;
12295 }
12296
db3c0315
MM
12297 /* We can only use the low/high_pc attributes if all of the code was
12298 in .text. */
12299 if (separate_line_info_table_in_use == 0)
12300 {
12301 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12302 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
e90b62db 12303 }
2ad9852d
RK
12304
12305 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12306 "base address". Use zero so that these addresses become absolute. */
a20612aa
RH
12307 else if (have_location_lists || ranges_table_in_use)
12308 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
e90b62db 12309
fe7cd37f
RH
12310 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12311 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12312 debug_line_section_label);
db3c0315 12313
84a5b4f8
DB
12314 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12315 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
a96c67ec 12316
881c6935
JM
12317 /* Output all of the compilation units. We put the main one last so that
12318 the offsets are available to output_pubnames. */
12319 for (node = limbo_die_list; node; node = node->next)
12320 output_comp_unit (node->die);
2ad9852d 12321
881c6935
JM
12322 output_comp_unit (comp_unit_die);
12323
a3f97cbb 12324 /* Output the abbreviation table. */
715bdd29 12325 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
a3f97cbb
JW
12326 output_abbrev_section ();
12327
2ad9852d 12328 /* Output public names table if necessary. */
d291dd49
JM
12329 if (pubname_table_in_use)
12330 {
715bdd29 12331 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
d291dd49
JM
12332 output_pubnames ();
12333 }
12334
2ad9852d
RK
12335 /* Output the address range information. We only put functions in the arange
12336 table, so don't write it out if we don't have any. */
a3f97cbb
JW
12337 if (fde_table_in_use)
12338 {
715bdd29 12339 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
a3f97cbb
JW
12340 output_aranges ();
12341 }
a20612aa 12342
a20612aa
RH
12343 /* Output ranges section if necessary. */
12344 if (ranges_table_in_use)
12345 {
715bdd29 12346 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
2bee6045 12347 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
a20612aa
RH
12348 output_ranges ();
12349 }
12350
30f7a378 12351 /* Have to end the primary source file. */
cc260610 12352 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
c26fbbca 12353 {
715bdd29 12354 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
cc260610 12355 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
2f8d482e 12356 dw2_asm_output_data (1, 0, "End compilation unit");
cc260610 12357 }
9eb4015a 12358
2ad9852d 12359 /* If we emitted any DW_FORM_strp form attribute, output the string
9eb4015a
JJ
12360 table too. */
12361 if (debug_str_hash)
12362 ht_forall (debug_str_hash, output_indirect_string, NULL);
a3f97cbb 12363}
e2500fed
GK
12364#else
12365
12366/* This should never be used, but its address is needed for comparisons. */
12367const struct gcc_debug_hooks dwarf2_debug_hooks;
12368
12369#endif /* DWARF2_DEBUGGING_INFO */
12370
12371#include "gt-dwarf2out.h"