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