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