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