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