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