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