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