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