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