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