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