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