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