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