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