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