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