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