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