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