1 /* dwarf2dbg.c - DWARF2 debug support
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
3 Free Software Foundation, Inc.
4 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 /* Logical line numbers can be controlled by the compiler via the
27 .loc FILENO LINENO [COLUMN] [basic_block] [prologue_end] \
28 [epilogue_begin] [is_stmt VALUE] [isa VALUE] \
33 #include "safe-ctype.h"
38 #ifdef HAVE_SYS_PARAM_H
39 #include <sys/param.h>
42 #define INT_MAX (int) (((unsigned) (-1)) >> 1)
46 #include "dwarf2dbg.h"
47 #include <filenames.h>
49 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
50 /* We need to decide which character to use as a directory separator.
51 Just because HAVE_DOS_BASED_FILE_SYSTEM is defined, it does not
52 necessarily mean that the backslash character is the one to use.
53 Some environments, eg Cygwin, can support both naming conventions.
54 So we use the heuristic that we only need to use the backslash if
55 the path is an absolute path starting with a DOS style drive
56 selector. eg C: or D: */
57 # define INSERT_DIR_SEPARATOR(string, offset) \
62 && string[1] == ':') \
63 string [offset] = '\\'; \
65 string [offset] = '/'; \
69 # define INSERT_DIR_SEPARATOR(string, offset) string[offset] = '/'
73 # define DWARF2_FORMAT(SEC) dwarf2_format_32bit
76 #ifndef DWARF2_ADDR_SIZE
77 # define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
80 #ifndef DWARF2_FILE_NAME
81 #define DWARF2_FILE_NAME(FILENAME, DIRNAME) FILENAME
84 #ifndef DWARF2_FILE_TIME_NAME
85 #define DWARF2_FILE_TIME_NAME(FILENAME,DIRNAME) 0
88 #ifndef DWARF2_FILE_SIZE_NAME
89 #define DWARF2_FILE_SIZE_NAME(FILENAME,DIRNAME) 0
92 #ifndef DWARF2_VERSION
93 #define DWARF2_VERSION 2
100 /* Since we can't generate the prolog until the body is complete, we
101 use three different subsegments for .debug_line: one holding the
102 prolog, one for the directory and filename info, and one for the
103 body ("statement program"). */
108 /* If linker relaxation might change offsets in the code, the DWARF special
109 opcodes and variable-length operands cannot be used. If this macro is
110 nonzero, use the DW_LNS_fixed_advance_pc opcode instead. */
111 #ifndef DWARF2_USE_FIXED_ADVANCE_PC
112 # define DWARF2_USE_FIXED_ADVANCE_PC 0
115 /* First special line opcde - leave room for the standard opcodes.
116 Note: If you want to change this, you'll have to update the
117 "standard_opcode_lengths" table that is emitted below in
119 #define DWARF2_LINE_OPCODE_BASE 13
121 #ifndef DWARF2_LINE_BASE
122 /* Minimum line offset in a special line info. opcode. This value
123 was chosen to give a reasonable range of values. */
124 # define DWARF2_LINE_BASE -5
127 /* Range of line offsets in a special line info. opcode. */
128 #ifndef DWARF2_LINE_RANGE
129 # define DWARF2_LINE_RANGE 14
132 #ifndef DWARF2_LINE_MIN_INSN_LENGTH
133 /* Define the architecture-dependent minimum instruction length (in
134 bytes). This value should be rather too small than too big. */
135 # define DWARF2_LINE_MIN_INSN_LENGTH 1
138 /* Flag that indicates the initial value of the is_stmt_start flag. */
139 #define DWARF2_LINE_DEFAULT_IS_STMT 1
141 /* Given a special op, return the line skip amount. */
142 #define SPECIAL_LINE(op) \
143 (((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE)
145 /* Given a special op, return the address skip amount (in units of
146 DWARF2_LINE_MIN_INSN_LENGTH. */
147 #define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
149 /* The maximum address skip amount that can be encoded with a special op. */
150 #define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
153 struct line_entry
*next
;
155 struct dwarf2_line_info loc
;
159 struct line_subseg
*next
;
161 struct line_entry
*head
;
162 struct line_entry
**ptail
;
166 struct line_seg
*next
;
168 struct line_subseg
*head
;
173 /* Collects data for all line table entries during assembly. */
174 static struct line_seg
*all_segs
;
175 /* Hash used to quickly lookup a segment by name, avoiding the need to search
176 through the all_segs list. */
177 static struct hash_control
*all_segs_hash
;
178 static struct line_seg
**last_seg_ptr
;
181 const char *filename
;
185 /* Table of files used by .debug_line. */
186 static struct file_entry
*files
;
187 static unsigned int files_in_use
;
188 static unsigned int files_allocated
;
190 /* Table of directories used by .debug_line. */
192 static unsigned int dirs_in_use
;
193 static unsigned int dirs_allocated
;
195 /* TRUE when we've seen a .loc directive recently. Used to avoid
196 doing work when there's nothing to do. */
197 bfd_boolean dwarf2_loc_directive_seen
;
199 /* TRUE when we're supposed to set the basic block mark whenever a
201 bfd_boolean dwarf2_loc_mark_labels
;
203 /* Current location as indicated by the most recent .loc directive. */
204 static struct dwarf2_line_info current
= {
206 DWARF2_LINE_DEFAULT_IS_STMT
? DWARF2_FLAG_IS_STMT
: 0,
210 /* Lines that are at the same location as CURRENT, and which are waiting
212 static struct line_entry
*pending_lines
, **pending_lines_tail
= &pending_lines
;
214 /* The size of an address on the target. */
215 static unsigned int sizeof_address
;
217 static unsigned int get_filenum (const char *, unsigned int);
219 #ifndef TC_DWARF2_EMIT_OFFSET
220 #define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
222 /* Create an offset to .dwarf2_*. */
225 generic_dwarf2_emit_offset (symbolS
*symbol
, unsigned int size
)
230 exp
.X_add_symbol
= symbol
;
231 exp
.X_add_number
= 0;
232 emit_expr (&exp
, size
);
236 /* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */
238 static struct line_subseg
*
239 get_line_subseg (segT seg
, subsegT subseg
)
241 static segT last_seg
;
242 static subsegT last_subseg
;
243 static struct line_subseg
*last_line_subseg
;
246 struct line_subseg
**pss
, *lss
;
248 if (seg
== last_seg
&& subseg
== last_subseg
)
249 return last_line_subseg
;
251 s
= (struct line_seg
*) hash_find (all_segs_hash
, seg
->name
);
254 s
= (struct line_seg
*) xmalloc (sizeof (*s
));
259 last_seg_ptr
= &s
->next
;
260 hash_insert (all_segs_hash
, seg
->name
, s
);
262 gas_assert (seg
== s
->seg
);
264 for (pss
= &s
->head
; (lss
= *pss
) != NULL
; pss
= &lss
->next
)
266 if (lss
->subseg
== subseg
)
268 if (lss
->subseg
> subseg
)
272 lss
= (struct line_subseg
*) xmalloc (sizeof (*lss
));
274 lss
->subseg
= subseg
;
276 lss
->ptail
= &lss
->head
;
281 last_subseg
= subseg
;
282 last_line_subseg
= lss
;
287 /* Push LOC onto the pending lines list. */
290 dwarf2_push_line (struct dwarf2_line_info
*loc
)
292 struct line_entry
*e
;
294 e
= (struct line_entry
*) xmalloc (sizeof (*e
));
299 *pending_lines_tail
= e
;
300 pending_lines_tail
= &(*pending_lines_tail
)->next
;
303 /* Emit all pending line information. LABEL is the label with which the
304 lines should be associated, or null if they should be associated with
305 the current position. */
308 dwarf2_flush_pending_lines (symbolS
*label
)
312 struct line_subseg
*lss
;
313 struct line_entry
*e
;
316 label
= symbol_temp_new_now ();
318 for (e
= pending_lines
; e
; e
= e
->next
)
321 lss
= get_line_subseg (now_seg
, now_subseg
);
322 *lss
->ptail
= pending_lines
;
323 lss
->ptail
= pending_lines_tail
;
325 pending_lines
= NULL
;
326 pending_lines_tail
= &pending_lines
;
330 /* Record an entry for LOC occurring at OFS within the current fragment. */
333 dwarf2_gen_line_info (addressT ofs
, struct dwarf2_line_info
*loc
)
335 static unsigned int line
= -1;
336 static unsigned int filenum
= -1;
338 /* Early out for as-yet incomplete location information. */
339 if (loc
->filenum
== 0 || loc
->line
== 0)
342 /* Don't emit sequences of line symbols for the same line when the
343 symbols apply to assembler code. It is necessary to emit
344 duplicate line symbols when a compiler asks for them, because GDB
345 uses them to determine the end of the prologue. */
346 if (debug_type
== DEBUG_DWARF2
347 && line
== loc
->line
&& filenum
== loc
->filenum
)
351 filenum
= loc
->filenum
;
353 dwarf2_push_line (loc
);
354 dwarf2_flush_pending_lines (symbol_temp_new (now_seg
, ofs
, frag_now
));
357 /* Returns the current source information. If .file directives have
358 been encountered, the info for the corresponding source file is
359 returned. Otherwise, the info for the assembly source file is
363 dwarf2_where (struct dwarf2_line_info
*line
)
365 if (debug_type
== DEBUG_DWARF2
)
368 as_where (&filename
, &line
->line
);
369 line
->filenum
= get_filenum (filename
, 0);
371 line
->flags
= DWARF2_FLAG_IS_STMT
;
372 line
->isa
= current
.isa
;
373 line
->discriminator
= current
.discriminator
;
379 /* A hook to allow the target backend to inform the line number state
380 machine of isa changes when assembler debug info is enabled. */
383 dwarf2_set_isa (unsigned int isa
)
388 /* Called for each machine instruction, or relatively atomic group of
389 machine instructions (ie built-in macro). The instruction or group
390 is SIZE bytes in length. If dwarf2 line number generation is called
391 for, emit a line statement appropriately. */
394 dwarf2_emit_insn (int size
)
396 struct dwarf2_line_info loc
;
398 if (!dwarf2_loc_directive_seen
&& debug_type
!= DEBUG_DWARF2
)
403 dwarf2_gen_line_info (frag_now_fix () - size
, &loc
);
404 dwarf2_consume_line_info ();
407 /* Called after the current line information has been either used with
408 dwarf2_gen_line_info or saved with a machine instruction for later use.
409 This resets the state of the line number information to reflect that
413 dwarf2_consume_line_info (void)
415 /* If the consumer has stashed the current location away for later use,
416 assume that any earlier location information should be associated
418 dwarf2_flush_pending_lines (NULL
);
420 /* Unless we generate DWARF2 debugging information for each
421 assembler line, we only emit one line symbol for one LOC. */
422 dwarf2_loc_directive_seen
= FALSE
;
424 current
.flags
&= ~(DWARF2_FLAG_BASIC_BLOCK
425 | DWARF2_FLAG_PROLOGUE_END
426 | DWARF2_FLAG_EPILOGUE_BEGIN
);
427 current
.discriminator
= 0;
430 /* Called for each (preferably code) label. If dwarf2_loc_mark_labels
431 is enabled, emit a basic block marker. */
434 dwarf2_emit_label (symbolS
*label
)
436 struct dwarf2_line_info loc
;
438 if (!dwarf2_loc_mark_labels
)
440 if (S_GET_SEGMENT (label
) != now_seg
)
442 if (!(bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
))
444 if (files_in_use
== 0 && debug_type
!= DEBUG_DWARF2
)
449 loc
.flags
|= DWARF2_FLAG_BASIC_BLOCK
;
451 dwarf2_push_line (&loc
);
452 dwarf2_flush_pending_lines (label
);
453 dwarf2_consume_line_info ();
456 /* Get a .debug_line file number for FILENAME. If NUM is nonzero,
457 allocate it on that file table slot, otherwise return the first
461 get_filenum (const char *filename
, unsigned int num
)
463 static unsigned int last_used
, last_used_dir_len
;
468 if (num
== 0 && last_used
)
470 if (! files
[last_used
].dir
471 && filename_cmp (filename
, files
[last_used
].filename
) == 0)
473 if (files
[last_used
].dir
474 && filename_ncmp (filename
, dirs
[files
[last_used
].dir
],
475 last_used_dir_len
) == 0
476 && IS_DIR_SEPARATOR (filename
[last_used_dir_len
])
477 && filename_cmp (filename
+ last_used_dir_len
+ 1,
478 files
[last_used
].filename
) == 0)
482 file
= lbasename (filename
);
483 /* Don't make empty string from / or A: from A:/ . */
484 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
485 if (file
<= filename
+ 3)
488 if (file
== filename
+ 1)
491 dir_len
= file
- filename
;
496 #ifndef DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
499 for (dir
= 1; dir
< dirs_in_use
; ++dir
)
500 if (filename_ncmp (filename
, dirs
[dir
], dir_len
) == 0
501 && dirs
[dir
][dir_len
] == '\0')
504 if (dir
>= dirs_in_use
)
506 if (dir
>= dirs_allocated
)
508 dirs_allocated
= dir
+ 32;
510 xrealloc (dirs
, (dir
+ 32) * sizeof (const char *));
513 dirs
[dir
] = (char *) xmalloc (dir_len
+ 1);
514 memcpy (dirs
[dir
], filename
, dir_len
);
515 dirs
[dir
][dir_len
] = '\0';
516 dirs_in_use
= dir
+ 1;
522 for (i
= 1; i
< files_in_use
; ++i
)
523 if (files
[i
].dir
== dir
525 && filename_cmp (file
, files
[i
].filename
) == 0)
528 last_used_dir_len
= dir_len
;
535 if (i
>= files_allocated
)
537 unsigned int old
= files_allocated
;
539 files_allocated
= i
+ 32;
540 files
= (struct file_entry
*)
541 xrealloc (files
, (i
+ 32) * sizeof (struct file_entry
));
543 memset (files
+ old
, 0, (i
+ 32 - old
) * sizeof (struct file_entry
));
546 files
[i
].filename
= num
? file
: xstrdup (file
);
548 if (files_in_use
< i
+ 1)
549 files_in_use
= i
+ 1;
551 last_used_dir_len
= dir_len
;
556 /* Handle two forms of .file directive:
557 - Pass .file "source.c" to s_app_file
558 - Handle .file 1 "source.c" by adding an entry to the DWARF-2 file table
560 If an entry is added to the file table, return a pointer to the filename. */
563 dwarf2_directive_file (int dummy ATTRIBUTE_UNUSED
)
569 /* Continue to accept a bare string and pass it off. */
571 if (*input_line_pointer
== '"')
577 num
= get_absolute_expression ();
578 filename
= demand_copy_C_string (&filename_len
);
579 if (filename
== NULL
)
581 demand_empty_rest_of_line ();
585 as_bad (_("file number less than one"));
589 /* A .file directive implies compiler generated debug information is
590 being supplied. Turn off gas generated debug info. */
591 debug_type
= DEBUG_NONE
;
593 if (num
< (int) files_in_use
&& files
[num
].filename
!= 0)
595 as_bad (_("file number %ld already allocated"), (long) num
);
599 get_filenum (filename
, num
);
605 dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED
)
607 offsetT filenum
, line
;
609 /* If we see two .loc directives in a row, force the first one to be
611 if (dwarf2_loc_directive_seen
)
612 dwarf2_push_line (¤t
);
614 filenum
= get_absolute_expression ();
616 line
= get_absolute_expression ();
620 as_bad (_("file number less than one"));
623 if (filenum
>= (int) files_in_use
|| files
[filenum
].filename
== 0)
625 as_bad (_("unassigned file number %ld"), (long) filenum
);
629 current
.filenum
= filenum
;
631 current
.discriminator
= 0;
636 if (files
[filenum
].dir
)
638 size_t dir_len
= strlen (dirs
[files
[filenum
].dir
]);
639 size_t file_len
= strlen (files
[filenum
].filename
);
640 char *cp
= (char *) alloca (dir_len
+ 1 + file_len
+ 1);
642 memcpy (cp
, dirs
[files
[filenum
].dir
], dir_len
);
643 INSERT_DIR_SEPARATOR (cp
, dir_len
);
644 memcpy (cp
+ dir_len
+ 1, files
[filenum
].filename
, file_len
);
645 cp
[dir_len
+ file_len
+ 1] = '\0';
646 listing_source_file (cp
);
649 listing_source_file (files
[filenum
].filename
);
650 listing_source_line (line
);
655 if (ISDIGIT (*input_line_pointer
))
657 current
.column
= get_absolute_expression ();
661 while (ISALPHA (*input_line_pointer
))
666 p
= input_line_pointer
;
667 c
= get_symbol_end ();
669 if (strcmp (p
, "basic_block") == 0)
671 current
.flags
|= DWARF2_FLAG_BASIC_BLOCK
;
672 *input_line_pointer
= c
;
674 else if (strcmp (p
, "prologue_end") == 0)
676 current
.flags
|= DWARF2_FLAG_PROLOGUE_END
;
677 *input_line_pointer
= c
;
679 else if (strcmp (p
, "epilogue_begin") == 0)
681 current
.flags
|= DWARF2_FLAG_EPILOGUE_BEGIN
;
682 *input_line_pointer
= c
;
684 else if (strcmp (p
, "is_stmt") == 0)
686 *input_line_pointer
= c
;
687 value
= get_absolute_expression ();
689 current
.flags
&= ~DWARF2_FLAG_IS_STMT
;
691 current
.flags
|= DWARF2_FLAG_IS_STMT
;
694 as_bad (_("is_stmt value not 0 or 1"));
698 else if (strcmp (p
, "isa") == 0)
700 *input_line_pointer
= c
;
701 value
= get_absolute_expression ();
706 as_bad (_("isa number less than zero"));
710 else if (strcmp (p
, "discriminator") == 0)
712 *input_line_pointer
= c
;
713 value
= get_absolute_expression ();
715 current
.discriminator
= value
;
718 as_bad (_("discriminator less than zero"));
724 as_bad (_("unknown .loc sub-directive `%s'"), p
);
725 *input_line_pointer
= c
;
732 demand_empty_rest_of_line ();
733 dwarf2_loc_directive_seen
= TRUE
;
734 debug_type
= DEBUG_NONE
;
738 dwarf2_directive_loc_mark_labels (int dummy ATTRIBUTE_UNUSED
)
740 offsetT value
= get_absolute_expression ();
742 if (value
!= 0 && value
!= 1)
744 as_bad (_("expected 0 or 1"));
745 ignore_rest_of_line ();
749 dwarf2_loc_mark_labels
= value
!= 0;
750 demand_empty_rest_of_line ();
755 first_frag_for_seg (segT seg
)
757 return seg_info (seg
)->frchainP
->frch_root
;
761 last_frag_for_seg (segT seg
)
763 frchainS
*f
= seg_info (seg
)->frchainP
;
765 while (f
->frch_next
!= NULL
)
771 /* Emit a single byte into the current segment. */
776 FRAG_APPEND_1_CHAR (byte
);
779 /* Emit a statement program opcode into the current segment. */
787 /* Emit a two-byte word into the current segment. */
792 md_number_to_chars (frag_more (2), data
, 2);
795 /* Emit a four byte word into the current segment. */
800 md_number_to_chars (frag_more (4), data
, 4);
803 /* Emit an unsigned "little-endian base 128" number. */
806 out_uleb128 (addressT value
)
808 output_leb128 (frag_more (sizeof_leb128 (value
, 0)), value
, 0);
811 /* Emit a signed "little-endian base 128" number. */
814 out_leb128 (addressT value
)
816 output_leb128 (frag_more (sizeof_leb128 (value
, 1)), value
, 1);
819 /* Emit a tuple for .debug_abbrev. */
822 out_abbrev (int name
, int form
)
828 /* Get the size of a fragment. */
831 get_frag_fix (fragS
*frag
, segT seg
)
838 /* If a fragment is the last in the chain, special measures must be
839 taken to find its size before relaxation, since it may be pending
840 on some subsegment chain. */
841 for (fr
= seg_info (seg
)->frchainP
; fr
; fr
= fr
->frch_next
)
842 if (fr
->frch_last
== frag
)
843 return (char *) obstack_next_free (&fr
->frch_obstack
) - frag
->fr_literal
;
848 /* Set an absolute address (may result in a relocation entry). */
851 out_set_addr (symbolS
*sym
)
855 out_opcode (DW_LNS_extended_op
);
856 out_uleb128 (sizeof_address
+ 1);
858 out_opcode (DW_LNE_set_address
);
860 exp
.X_add_symbol
= sym
;
861 exp
.X_add_number
= 0;
862 emit_expr (&exp
, sizeof_address
);
865 #if DWARF2_LINE_MIN_INSN_LENGTH > 1
866 static void scale_addr_delta (addressT
*);
869 scale_addr_delta (addressT
*addr_delta
)
871 static int printed_this
= 0;
872 if (*addr_delta
% DWARF2_LINE_MIN_INSN_LENGTH
!= 0)
875 as_bad("unaligned opcodes detected in executable segment");
878 *addr_delta
/= DWARF2_LINE_MIN_INSN_LENGTH
;
881 #define scale_addr_delta(A)
884 /* Encode a pair of line and address skips as efficiently as possible.
885 Note that the line skip is signed, whereas the address skip is unsigned.
887 The following two routines *must* be kept in sync. This is
888 enforced by making emit_inc_line_addr abort if we do not emit
889 exactly the expected number of bytes. */
892 size_inc_line_addr (int line_delta
, addressT addr_delta
)
894 unsigned int tmp
, opcode
;
897 /* Scale the address delta by the minimum instruction length. */
898 scale_addr_delta (&addr_delta
);
900 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
901 We cannot use special opcodes here, since we want the end_sequence
902 to emit the matrix entry. */
903 if (line_delta
== INT_MAX
)
905 if (addr_delta
== MAX_SPECIAL_ADDR_DELTA
)
908 len
= 1 + sizeof_leb128 (addr_delta
, 0);
912 /* Bias the line delta by the base. */
913 tmp
= line_delta
- DWARF2_LINE_BASE
;
915 /* If the line increment is out of range of a special opcode, we
916 must encode it with DW_LNS_advance_line. */
917 if (tmp
>= DWARF2_LINE_RANGE
)
919 len
= 1 + sizeof_leb128 (line_delta
, 1);
921 tmp
= 0 - DWARF2_LINE_BASE
;
924 /* Bias the opcode by the special opcode base. */
925 tmp
+= DWARF2_LINE_OPCODE_BASE
;
927 /* Avoid overflow when addr_delta is large. */
928 if (addr_delta
< 256 + MAX_SPECIAL_ADDR_DELTA
)
930 /* Try using a special opcode. */
931 opcode
= tmp
+ addr_delta
* DWARF2_LINE_RANGE
;
935 /* Try using DW_LNS_const_add_pc followed by special op. */
936 opcode
= tmp
+ (addr_delta
- MAX_SPECIAL_ADDR_DELTA
) * DWARF2_LINE_RANGE
;
941 /* Otherwise use DW_LNS_advance_pc. */
942 len
+= 1 + sizeof_leb128 (addr_delta
, 0);
944 /* DW_LNS_copy or special opcode. */
951 emit_inc_line_addr (int line_delta
, addressT addr_delta
, char *p
, int len
)
953 unsigned int tmp
, opcode
;
957 /* Line number sequences cannot go backward in addresses. This means
958 we've incorrectly ordered the statements in the sequence. */
959 gas_assert ((offsetT
) addr_delta
>= 0);
961 /* Scale the address delta by the minimum instruction length. */
962 scale_addr_delta (&addr_delta
);
964 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
965 We cannot use special opcodes here, since we want the end_sequence
966 to emit the matrix entry. */
967 if (line_delta
== INT_MAX
)
969 if (addr_delta
== MAX_SPECIAL_ADDR_DELTA
)
970 *p
++ = DW_LNS_const_add_pc
;
973 *p
++ = DW_LNS_advance_pc
;
974 p
+= output_leb128 (p
, addr_delta
, 0);
977 *p
++ = DW_LNS_extended_op
;
979 *p
++ = DW_LNE_end_sequence
;
983 /* Bias the line delta by the base. */
984 tmp
= line_delta
- DWARF2_LINE_BASE
;
986 /* If the line increment is out of range of a special opcode, we
987 must encode it with DW_LNS_advance_line. */
988 if (tmp
>= DWARF2_LINE_RANGE
)
990 *p
++ = DW_LNS_advance_line
;
991 p
+= output_leb128 (p
, line_delta
, 1);
994 tmp
= 0 - DWARF2_LINE_BASE
;
998 /* Prettier, I think, to use DW_LNS_copy instead of a "line +0, addr +0"
1000 if (line_delta
== 0 && addr_delta
== 0)
1006 /* Bias the opcode by the special opcode base. */
1007 tmp
+= DWARF2_LINE_OPCODE_BASE
;
1009 /* Avoid overflow when addr_delta is large. */
1010 if (addr_delta
< 256 + MAX_SPECIAL_ADDR_DELTA
)
1012 /* Try using a special opcode. */
1013 opcode
= tmp
+ addr_delta
* DWARF2_LINE_RANGE
;
1020 /* Try using DW_LNS_const_add_pc followed by special op. */
1021 opcode
= tmp
+ (addr_delta
- MAX_SPECIAL_ADDR_DELTA
) * DWARF2_LINE_RANGE
;
1024 *p
++ = DW_LNS_const_add_pc
;
1030 /* Otherwise use DW_LNS_advance_pc. */
1031 *p
++ = DW_LNS_advance_pc
;
1032 p
+= output_leb128 (p
, addr_delta
, 0);
1040 gas_assert (p
== end
);
1043 /* Handy routine to combine calls to the above two routines. */
1046 out_inc_line_addr (int line_delta
, addressT addr_delta
)
1048 int len
= size_inc_line_addr (line_delta
, addr_delta
);
1049 emit_inc_line_addr (line_delta
, addr_delta
, frag_more (len
), len
);
1052 /* Write out an alternative form of line and address skips using
1053 DW_LNS_fixed_advance_pc opcodes. This uses more space than the default
1054 line and address information, but it is required if linker relaxation
1055 could change the code offsets. The following two routines *must* be
1059 size_fixed_inc_line_addr (int line_delta
, addressT addr_delta
)
1063 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. */
1064 if (line_delta
!= INT_MAX
)
1065 len
= 1 + sizeof_leb128 (line_delta
, 1);
1067 if (addr_delta
> 50000)
1069 /* DW_LNS_extended_op */
1070 len
+= 1 + sizeof_leb128 (sizeof_address
+ 1, 0);
1071 /* DW_LNE_set_address */
1072 len
+= 1 + sizeof_address
;
1075 /* DW_LNS_fixed_advance_pc */
1078 if (line_delta
== INT_MAX
)
1079 /* DW_LNS_extended_op + DW_LNE_end_sequence */
1089 emit_fixed_inc_line_addr (int line_delta
, addressT addr_delta
, fragS
*frag
,
1094 char *end
= p
+ len
;
1096 /* Line number sequences cannot go backward in addresses. This means
1097 we've incorrectly ordered the statements in the sequence. */
1098 gas_assert ((offsetT
) addr_delta
>= 0);
1100 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. */
1101 if (line_delta
!= INT_MAX
)
1103 *p
++ = DW_LNS_advance_line
;
1104 p
+= output_leb128 (p
, line_delta
, 1);
1107 pexp
= symbol_get_value_expression (frag
->fr_symbol
);
1108 line_seg
= subseg_get (".debug_line", 0);
1110 /* The DW_LNS_fixed_advance_pc opcode has a 2-byte operand so it can
1111 advance the address by at most 64K. Linker relaxation (without
1112 which this function would not be used) could change the operand by
1113 an unknown amount. If the address increment is getting close to
1114 the limit, just reset the address. */
1115 if (addr_delta
> 50000)
1120 gas_assert (pexp
->X_op
== O_subtract
);
1121 to_sym
= pexp
->X_add_symbol
;
1123 *p
++ = DW_LNS_extended_op
;
1124 p
+= output_leb128 (p
, sizeof_address
+ 1, 0);
1125 *p
++ = DW_LNE_set_address
;
1126 exp
.X_op
= O_symbol
;
1127 exp
.X_add_symbol
= to_sym
;
1128 exp
.X_add_number
= 0;
1129 subseg_change (line_seg
, 0);
1130 emit_expr_fix (&exp
, sizeof_address
, frag
, p
);
1131 p
+= sizeof_address
;
1135 *p
++ = DW_LNS_fixed_advance_pc
;
1136 subseg_change (line_seg
, 0);
1137 emit_expr_fix (pexp
, 2, frag
, p
);
1141 if (line_delta
== INT_MAX
)
1143 *p
++ = DW_LNS_extended_op
;
1145 *p
++ = DW_LNE_end_sequence
;
1150 gas_assert (p
== end
);
1153 /* Generate a variant frag that we can use to relax address/line
1154 increments between fragments of the target segment. */
1157 relax_inc_line_addr (int line_delta
, symbolS
*to_sym
, symbolS
*from_sym
)
1162 exp
.X_op
= O_subtract
;
1163 exp
.X_add_symbol
= to_sym
;
1164 exp
.X_op_symbol
= from_sym
;
1165 exp
.X_add_number
= 0;
1167 /* The maximum size of the frag is the line delta with a maximum
1168 sized address delta. */
1169 if (DWARF2_USE_FIXED_ADVANCE_PC
)
1170 max_chars
= size_fixed_inc_line_addr (line_delta
,
1171 -DWARF2_LINE_MIN_INSN_LENGTH
);
1173 max_chars
= size_inc_line_addr (line_delta
, -DWARF2_LINE_MIN_INSN_LENGTH
);
1175 frag_var (rs_dwarf2dbg
, max_chars
, max_chars
, 1,
1176 make_expr_symbol (&exp
), line_delta
, NULL
);
1179 /* The function estimates the size of a rs_dwarf2dbg variant frag
1180 based on the current values of the symbols. It is called before
1181 the relaxation loop. We set fr_subtype to the expected length. */
1184 dwarf2dbg_estimate_size_before_relax (fragS
*frag
)
1189 addr_delta
= resolve_symbol_value (frag
->fr_symbol
);
1190 if (DWARF2_USE_FIXED_ADVANCE_PC
)
1191 size
= size_fixed_inc_line_addr (frag
->fr_offset
, addr_delta
);
1193 size
= size_inc_line_addr (frag
->fr_offset
, addr_delta
);
1195 frag
->fr_subtype
= size
;
1200 /* This function relaxes a rs_dwarf2dbg variant frag based on the
1201 current values of the symbols. fr_subtype is the current length
1202 of the frag. This returns the change in frag length. */
1205 dwarf2dbg_relax_frag (fragS
*frag
)
1207 int old_size
, new_size
;
1209 old_size
= frag
->fr_subtype
;
1210 new_size
= dwarf2dbg_estimate_size_before_relax (frag
);
1212 return new_size
- old_size
;
1215 /* This function converts a rs_dwarf2dbg variant frag into a normal
1216 fill frag. This is called after all relaxation has been done.
1217 fr_subtype will be the desired length of the frag. */
1220 dwarf2dbg_convert_frag (fragS
*frag
)
1224 addr_diff
= resolve_symbol_value (frag
->fr_symbol
);
1226 /* fr_var carries the max_chars that we created the fragment with.
1227 fr_subtype carries the current expected length. We must, of
1228 course, have allocated enough memory earlier. */
1229 gas_assert (frag
->fr_var
>= (int) frag
->fr_subtype
);
1231 if (DWARF2_USE_FIXED_ADVANCE_PC
)
1232 emit_fixed_inc_line_addr (frag
->fr_offset
, addr_diff
, frag
,
1233 frag
->fr_literal
+ frag
->fr_fix
,
1236 emit_inc_line_addr (frag
->fr_offset
, addr_diff
,
1237 frag
->fr_literal
+ frag
->fr_fix
, frag
->fr_subtype
);
1239 frag
->fr_fix
+= frag
->fr_subtype
;
1240 frag
->fr_type
= rs_fill
;
1242 frag
->fr_offset
= 0;
1245 /* Generate .debug_line content for the chain of line number entries
1246 beginning at E, for segment SEG. */
1249 process_entries (segT seg
, struct line_entry
*e
)
1251 unsigned filenum
= 1;
1253 unsigned column
= 0;
1255 unsigned flags
= DWARF2_LINE_DEFAULT_IS_STMT
? DWARF2_FLAG_IS_STMT
: 0;
1256 fragS
*last_frag
= NULL
, *frag
;
1257 addressT last_frag_ofs
= 0, frag_ofs
;
1258 symbolS
*last_lab
= NULL
, *lab
;
1259 struct line_entry
*next
;
1265 if (filenum
!= e
->loc
.filenum
)
1267 filenum
= e
->loc
.filenum
;
1268 out_opcode (DW_LNS_set_file
);
1269 out_uleb128 (filenum
);
1272 if (column
!= e
->loc
.column
)
1274 column
= e
->loc
.column
;
1275 out_opcode (DW_LNS_set_column
);
1276 out_uleb128 (column
);
1279 if (e
->loc
.discriminator
!= 0)
1281 out_opcode (DW_LNS_extended_op
);
1282 out_leb128 (1 + sizeof_leb128 (e
->loc
.discriminator
, 0));
1283 out_opcode (DW_LNE_set_discriminator
);
1284 out_uleb128 (e
->loc
.discriminator
);
1287 if (isa
!= e
->loc
.isa
)
1290 out_opcode (DW_LNS_set_isa
);
1294 if ((e
->loc
.flags
^ flags
) & DWARF2_FLAG_IS_STMT
)
1296 flags
= e
->loc
.flags
;
1297 out_opcode (DW_LNS_negate_stmt
);
1300 if (e
->loc
.flags
& DWARF2_FLAG_BASIC_BLOCK
)
1301 out_opcode (DW_LNS_set_basic_block
);
1303 if (e
->loc
.flags
& DWARF2_FLAG_PROLOGUE_END
)
1304 out_opcode (DW_LNS_set_prologue_end
);
1306 if (e
->loc
.flags
& DWARF2_FLAG_EPILOGUE_BEGIN
)
1307 out_opcode (DW_LNS_set_epilogue_begin
);
1309 /* Don't try to optimize away redundant entries; gdb wants two
1310 entries for a function where the code starts on the same line as
1311 the {, and there's no way to identify that case here. Trust gcc
1312 to optimize appropriately. */
1313 line_delta
= e
->loc
.line
- line
;
1315 frag
= symbol_get_frag (lab
);
1316 frag_ofs
= S_GET_VALUE (lab
);
1318 if (last_frag
== NULL
)
1321 out_inc_line_addr (line_delta
, 0);
1323 else if (frag
== last_frag
&& ! DWARF2_USE_FIXED_ADVANCE_PC
)
1324 out_inc_line_addr (line_delta
, frag_ofs
- last_frag_ofs
);
1326 relax_inc_line_addr (line_delta
, lab
, last_lab
);
1331 last_frag_ofs
= frag_ofs
;
1339 /* Emit a DW_LNE_end_sequence for the end of the section. */
1340 frag
= last_frag_for_seg (seg
);
1341 frag_ofs
= get_frag_fix (frag
, seg
);
1342 if (frag
== last_frag
&& ! DWARF2_USE_FIXED_ADVANCE_PC
)
1343 out_inc_line_addr (INT_MAX
, frag_ofs
- last_frag_ofs
);
1346 lab
= symbol_temp_new (seg
, frag_ofs
, frag
);
1347 relax_inc_line_addr (INT_MAX
, lab
, last_lab
);
1351 /* Emit the directory and file tables for .debug_line. */
1354 out_file_list (void)
1361 /* Emit directory list. */
1362 for (i
= 1; i
< dirs_in_use
; ++i
)
1364 dir
= remap_debug_filename (dirs
[i
]);
1365 size
= strlen (dir
) + 1;
1366 cp
= frag_more (size
);
1367 memcpy (cp
, dir
, size
);
1372 for (i
= 1; i
< files_in_use
; ++i
)
1374 const char *fullfilename
;
1376 if (files
[i
].filename
== NULL
)
1378 as_bad (_("unassigned file number %ld"), (long) i
);
1379 /* Prevent a crash later, particularly for file 1. */
1380 files
[i
].filename
= "";
1384 fullfilename
= DWARF2_FILE_NAME (files
[i
].filename
,
1385 files
[i
].dir
? dirs
[files
[i
].dir
] : "");
1386 size
= strlen (fullfilename
) + 1;
1387 cp
= frag_more (size
);
1388 memcpy (cp
, fullfilename
, size
);
1390 out_uleb128 (files
[i
].dir
); /* directory number */
1391 /* Output the last modification timestamp. */
1392 out_uleb128 (DWARF2_FILE_TIME_NAME (files
[i
].filename
,
1393 files
[i
].dir
? dirs
[files
[i
].dir
] : ""));
1394 /* Output the filesize. */
1395 out_uleb128 (DWARF2_FILE_SIZE_NAME (files
[i
].filename
,
1396 files
[i
].dir
? dirs
[files
[i
].dir
] : ""));
1399 /* Terminate filename list. */
1403 /* Switch to SEC and output a header length field. Return the size of
1404 offsets used in SEC. The caller must set EXPR->X_add_symbol value
1405 to the end of the section. */
1408 out_header (asection
*sec
, expressionS
*exp
)
1413 subseg_set (sec
, 0);
1414 start_sym
= symbol_temp_new_now ();;
1415 end_sym
= symbol_temp_make ();
1417 /* Total length of the information. */
1418 exp
->X_op
= O_subtract
;
1419 exp
->X_add_symbol
= end_sym
;
1420 exp
->X_op_symbol
= start_sym
;
1422 switch (DWARF2_FORMAT (sec
))
1424 case dwarf2_format_32bit
:
1425 exp
->X_add_number
= -4;
1429 case dwarf2_format_64bit
:
1430 exp
->X_add_number
= -12;
1435 case dwarf2_format_64bit_irix
:
1436 exp
->X_add_number
= -8;
1441 as_fatal (_("internal error: unknown dwarf2 format"));
1445 /* Emit the collected .debug_line data. */
1448 out_debug_line (segT line_seg
)
1451 symbolS
*prologue_end
;
1456 sizeof_offset
= out_header (line_seg
, &exp
);
1457 line_end
= exp
.X_add_symbol
;
1460 out_two (DWARF2_VERSION
);
1462 /* Length of the prologue following this length. */
1463 prologue_end
= symbol_temp_make ();
1464 exp
.X_add_symbol
= prologue_end
;
1465 exp
.X_add_number
= - (4 + 2 + 4);
1466 emit_expr (&exp
, sizeof_offset
);
1468 /* Parameters of the state machine. */
1469 out_byte (DWARF2_LINE_MIN_INSN_LENGTH
);
1470 out_byte (DWARF2_LINE_DEFAULT_IS_STMT
);
1471 out_byte (DWARF2_LINE_BASE
);
1472 out_byte (DWARF2_LINE_RANGE
);
1473 out_byte (DWARF2_LINE_OPCODE_BASE
);
1475 /* Standard opcode lengths. */
1476 out_byte (0); /* DW_LNS_copy */
1477 out_byte (1); /* DW_LNS_advance_pc */
1478 out_byte (1); /* DW_LNS_advance_line */
1479 out_byte (1); /* DW_LNS_set_file */
1480 out_byte (1); /* DW_LNS_set_column */
1481 out_byte (0); /* DW_LNS_negate_stmt */
1482 out_byte (0); /* DW_LNS_set_basic_block */
1483 out_byte (0); /* DW_LNS_const_add_pc */
1484 out_byte (1); /* DW_LNS_fixed_advance_pc */
1485 out_byte (0); /* DW_LNS_set_prologue_end */
1486 out_byte (0); /* DW_LNS_set_epilogue_begin */
1487 out_byte (1); /* DW_LNS_set_isa */
1491 symbol_set_value_now (prologue_end
);
1493 /* For each section, emit a statement program. */
1494 for (s
= all_segs
; s
; s
= s
->next
)
1495 if (SEG_NORMAL (s
->seg
))
1496 process_entries (s
->seg
, s
->head
->head
);
1498 as_warn ("dwarf line number information for %s ignored",
1499 segment_name (s
->seg
));
1501 symbol_set_value_now (line_end
);
1505 out_debug_ranges (segT ranges_seg
)
1507 unsigned int addr_size
= sizeof_address
;
1512 subseg_set (ranges_seg
, 0);
1514 /* Base Address Entry. */
1515 for (i
= 0; i
< addr_size
; i
++)
1517 for (i
= 0; i
< addr_size
; i
++)
1520 /* Range List Entry. */
1521 for (s
= all_segs
; s
; s
= s
->next
)
1526 frag
= first_frag_for_seg (s
->seg
);
1527 beg
= symbol_temp_new (s
->seg
, 0, frag
);
1528 s
->text_start
= beg
;
1530 frag
= last_frag_for_seg (s
->seg
);
1531 end
= symbol_temp_new (s
->seg
, get_frag_fix (frag
, s
->seg
), frag
);
1534 exp
.X_op
= O_symbol
;
1535 exp
.X_add_symbol
= beg
;
1536 exp
.X_add_number
= 0;
1537 emit_expr (&exp
, addr_size
);
1539 exp
.X_op
= O_symbol
;
1540 exp
.X_add_symbol
= end
;
1541 exp
.X_add_number
= 0;
1542 emit_expr (&exp
, addr_size
);
1545 /* End of Range Entry. */
1546 for (i
= 0; i
< addr_size
; i
++)
1548 for (i
= 0; i
< addr_size
; i
++)
1552 /* Emit data for .debug_aranges. */
1555 out_debug_aranges (segT aranges_seg
, segT info_seg
)
1557 unsigned int addr_size
= sizeof_address
;
1560 symbolS
*aranges_end
;
1564 sizeof_offset
= out_header (aranges_seg
, &exp
);
1565 aranges_end
= exp
.X_add_symbol
;
1568 out_two (DWARF2_VERSION
);
1570 /* Offset to .debug_info. */
1571 TC_DWARF2_EMIT_OFFSET (section_symbol (info_seg
), sizeof_offset
);
1573 /* Size of an address (offset portion). */
1574 out_byte (addr_size
);
1576 /* Size of a segment descriptor. */
1579 /* Align the header. */
1580 frag_align (ffs (2 * addr_size
) - 1, 0, 0);
1582 for (s
= all_segs
; s
; s
= s
->next
)
1587 frag
= first_frag_for_seg (s
->seg
);
1588 beg
= symbol_temp_new (s
->seg
, 0, frag
);
1589 s
->text_start
= beg
;
1591 frag
= last_frag_for_seg (s
->seg
);
1592 end
= symbol_temp_new (s
->seg
, get_frag_fix (frag
, s
->seg
), frag
);
1595 exp
.X_op
= O_symbol
;
1596 exp
.X_add_symbol
= beg
;
1597 exp
.X_add_number
= 0;
1598 emit_expr (&exp
, addr_size
);
1600 exp
.X_op
= O_subtract
;
1601 exp
.X_add_symbol
= end
;
1602 exp
.X_op_symbol
= beg
;
1603 exp
.X_add_number
= 0;
1604 emit_expr (&exp
, addr_size
);
1607 p
= frag_more (2 * addr_size
);
1608 md_number_to_chars (p
, 0, addr_size
);
1609 md_number_to_chars (p
+ addr_size
, 0, addr_size
);
1611 symbol_set_value_now (aranges_end
);
1614 /* Emit data for .debug_abbrev. Note that this must be kept in
1615 sync with out_debug_info below. */
1618 out_debug_abbrev (segT abbrev_seg
,
1619 segT info_seg ATTRIBUTE_UNUSED
,
1620 segT line_seg ATTRIBUTE_UNUSED
)
1622 subseg_set (abbrev_seg
, 0);
1625 out_uleb128 (DW_TAG_compile_unit
);
1626 out_byte (DW_CHILDREN_no
);
1627 if (DWARF2_FORMAT (line_seg
) == dwarf2_format_32bit
)
1628 out_abbrev (DW_AT_stmt_list
, DW_FORM_data4
);
1630 out_abbrev (DW_AT_stmt_list
, DW_FORM_data8
);
1631 if (all_segs
->next
== NULL
)
1633 out_abbrev (DW_AT_low_pc
, DW_FORM_addr
);
1634 out_abbrev (DW_AT_high_pc
, DW_FORM_addr
);
1638 if (DWARF2_FORMAT (info_seg
) == dwarf2_format_32bit
)
1639 out_abbrev (DW_AT_ranges
, DW_FORM_data4
);
1641 out_abbrev (DW_AT_ranges
, DW_FORM_data8
);
1643 out_abbrev (DW_AT_name
, DW_FORM_string
);
1644 out_abbrev (DW_AT_comp_dir
, DW_FORM_string
);
1645 out_abbrev (DW_AT_producer
, DW_FORM_string
);
1646 out_abbrev (DW_AT_language
, DW_FORM_data2
);
1649 /* Terminate the abbreviations for this compilation unit. */
1653 /* Emit a description of this compilation unit for .debug_info. */
1656 out_debug_info (segT info_seg
, segT abbrev_seg
, segT line_seg
, segT ranges_seg
)
1659 const char *comp_dir
;
1660 const char *dirname
;
1667 sizeof_offset
= out_header (info_seg
, &exp
);
1668 info_end
= exp
.X_add_symbol
;
1670 /* DWARF version. */
1671 out_two (DWARF2_VERSION
);
1673 /* .debug_abbrev offset */
1674 TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg
), sizeof_offset
);
1676 /* Target address size. */
1677 out_byte (sizeof_address
);
1679 /* DW_TAG_compile_unit DIE abbrev */
1682 /* DW_AT_stmt_list */
1683 TC_DWARF2_EMIT_OFFSET (section_symbol (line_seg
),
1684 (DWARF2_FORMAT (line_seg
) == dwarf2_format_32bit
1687 /* These two attributes are emitted if all of the code is contiguous. */
1688 if (all_segs
->next
== NULL
)
1691 exp
.X_op
= O_symbol
;
1692 exp
.X_add_symbol
= all_segs
->text_start
;
1693 exp
.X_add_number
= 0;
1694 emit_expr (&exp
, sizeof_address
);
1697 exp
.X_op
= O_symbol
;
1698 exp
.X_add_symbol
= all_segs
->text_end
;
1699 exp
.X_add_number
= 0;
1700 emit_expr (&exp
, sizeof_address
);
1704 /* This attribute is emitted if the code is disjoint. */
1706 TC_DWARF2_EMIT_OFFSET (section_symbol (ranges_seg
), sizeof_offset
);
1709 /* DW_AT_name. We don't have the actual file name that was present
1710 on the command line, so assume files[1] is the main input file.
1711 We're not supposed to get called unless at least one line number
1712 entry was emitted, so this should always be defined. */
1713 if (files_in_use
== 0)
1717 dirname
= remap_debug_filename (dirs
[files
[1].dir
]);
1718 len
= strlen (dirname
);
1720 /* Already has trailing slash. */
1721 p
= frag_more (len
);
1722 memcpy (p
, dirname
, len
);
1724 p
= frag_more (len
+ 1);
1725 memcpy (p
, dirname
, len
);
1726 INSERT_DIR_SEPARATOR (p
, len
);
1729 len
= strlen (files
[1].filename
) + 1;
1730 p
= frag_more (len
);
1731 memcpy (p
, files
[1].filename
, len
);
1733 /* DW_AT_comp_dir */
1734 comp_dir
= remap_debug_filename (getpwd ());
1735 len
= strlen (comp_dir
) + 1;
1736 p
= frag_more (len
);
1737 memcpy (p
, comp_dir
, len
);
1739 /* DW_AT_producer */
1740 sprintf (producer
, "GNU AS %s", VERSION
);
1741 len
= strlen (producer
) + 1;
1742 p
= frag_more (len
);
1743 memcpy (p
, producer
, len
);
1745 /* DW_AT_language. Yes, this is probably not really MIPS, but the
1746 dwarf2 draft has no standard code for assembler. */
1747 out_two (DW_LANG_Mips_Assembler
);
1749 symbol_set_value_now (info_end
);
1755 all_segs_hash
= hash_new ();
1756 last_seg_ptr
= &all_segs
;
1760 /* Finish the dwarf2 debug sections. We emit .debug.line if there
1761 were any .file/.loc directives, or --gdwarf2 was given, or if the
1762 file has a non-empty .debug_info section and an empty .debug_line
1763 section. If we emit .debug_line, and the .debug_info section is
1764 empty, we also emit .debug_info, .debug_aranges and .debug_abbrev.
1765 ALL_SEGS will be non-null if there were any .file/.loc directives,
1766 or --gdwarf2 was given and there were any located instructions
1770 dwarf2_finish (void)
1775 int emit_other_sections
= 0;
1776 int empty_debug_line
= 0;
1778 info_seg
= bfd_get_section_by_name (stdoutput
, ".debug_info");
1779 emit_other_sections
= info_seg
== NULL
|| !seg_not_empty_p (info_seg
);
1781 line_seg
= bfd_get_section_by_name (stdoutput
, ".debug_line");
1782 empty_debug_line
= line_seg
== NULL
|| !seg_not_empty_p (line_seg
);
1784 /* We can't construct a new debug_line section if we already have one.
1786 if (all_segs
&& !empty_debug_line
)
1787 as_fatal ("duplicate .debug_line sections");
1789 if ((!all_segs
&& emit_other_sections
)
1790 || (!emit_other_sections
&& !empty_debug_line
))
1791 /* If there is no line information and no non-empty .debug_info
1792 section, or if there is both a non-empty .debug_info and a non-empty
1793 .debug_line, then we do nothing. */
1796 /* Calculate the size of an address for the target machine. */
1797 sizeof_address
= DWARF2_ADDR_SIZE (stdoutput
);
1799 /* Create and switch to the line number section. */
1800 line_seg
= subseg_new (".debug_line", 0);
1801 bfd_set_section_flags (stdoutput
, line_seg
, SEC_READONLY
| SEC_DEBUGGING
);
1803 /* For each subsection, chain the debug entries together. */
1804 for (s
= all_segs
; s
; s
= s
->next
)
1806 struct line_subseg
*lss
= s
->head
;
1807 struct line_entry
**ptail
= lss
->ptail
;
1809 while ((lss
= lss
->next
) != NULL
)
1816 out_debug_line (line_seg
);
1818 /* If this is assembler generated line info, and there is no
1819 debug_info already, we need .debug_info and .debug_abbrev
1820 sections as well. */
1821 if (emit_other_sections
)
1827 gas_assert (all_segs
);
1829 info_seg
= subseg_new (".debug_info", 0);
1830 abbrev_seg
= subseg_new (".debug_abbrev", 0);
1831 aranges_seg
= subseg_new (".debug_aranges", 0);
1833 bfd_set_section_flags (stdoutput
, info_seg
,
1834 SEC_READONLY
| SEC_DEBUGGING
);
1835 bfd_set_section_flags (stdoutput
, abbrev_seg
,
1836 SEC_READONLY
| SEC_DEBUGGING
);
1837 bfd_set_section_flags (stdoutput
, aranges_seg
,
1838 SEC_READONLY
| SEC_DEBUGGING
);
1840 record_alignment (aranges_seg
, ffs (2 * sizeof_address
) - 1);
1842 if (all_segs
->next
== NULL
)
1846 ranges_seg
= subseg_new (".debug_ranges", 0);
1847 bfd_set_section_flags (stdoutput
, ranges_seg
,
1848 SEC_READONLY
| SEC_DEBUGGING
);
1849 record_alignment (ranges_seg
, ffs (2 * sizeof_address
) - 1);
1850 out_debug_ranges (ranges_seg
);
1853 out_debug_aranges (aranges_seg
, info_seg
);
1854 out_debug_abbrev (abbrev_seg
, info_seg
, line_seg
);
1855 out_debug_info (info_seg
, abbrev_seg
, line_seg
, ranges_seg
);