1 /* dwarf2dbg.c - DWARF2 debug support
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* Logical line numbers can be controlled by the compiler via the
23 following two directives:
26 .loc FILENO LINENO [COLUMN]
28 FILENO is the filenumber. */
37 #include "dwarf2dbg.h"
40 #include "elf/dwarf2.h"
42 /* Since we can't generate the prolog until the body is complete, we
43 use three different subsegments for .debug_line: one holding the
44 prolog, one for the directory and filename info, and one for the
45 body ("statement program"). */
50 /* First special line opcde - leave room for the standard opcodes.
51 Note: If you want to change this, you'll have to update the
52 "standard_opcode_lengths" table that is emitted below in
54 #define DWARF2_LINE_OPCODE_BASE 10
56 #ifndef DWARF2_LINE_BASE
57 /* Minimum line offset in a special line info. opcode. This value
58 was chosen to give a reasonable range of values. */
59 # define DWARF2_LINE_BASE -5
62 /* Range of line offsets in a special line info. opcode. */
63 #ifndef DWARF2_LINE_RANGE
64 # define DWARF2_LINE_RANGE 14
67 #ifndef DWARF2_LINE_MIN_INSN_LENGTH
68 /* Define the architecture-dependent minimum instruction length (in
69 bytes). This value should be rather too small than too big. */
70 # define DWARF2_LINE_MIN_INSN_LENGTH 1
73 /* Flag that indicates the initial value of the is_stmt_start flag.
74 In the present implementation, we do not mark any lines as
75 the beginning of a source statement, because that information
76 is not made available by the GCC front-end. */
77 #define DWARF2_LINE_DEFAULT_IS_STMT 1
79 /* Given a special op, return the line skip amount. */
80 #define SPECIAL_LINE(op) \
81 (((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE)
83 /* Given a special op, return the address skip amount (in units of
84 DWARF2_LINE_MIN_INSN_LENGTH. */
85 #define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
87 /* The maximum address skip amount that can be encoded with a special op. */
88 #define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
93 struct line_entry
*next
;
96 struct dwarf2_line_info loc
;
101 struct line_subseg
*next
;
103 struct line_entry
*head
;
104 struct line_entry
**ptail
;
109 struct line_seg
*next
;
111 struct line_subseg
*head
;
116 /* Collects data for all line table entries during assembly. */
117 static struct line_seg
*all_segs
;
125 /* Table of files used by .debug_line. */
126 static struct file_entry
*files
;
127 static unsigned int files_in_use
;
128 static unsigned int files_allocated
;
130 /* Correlate file numbers as given by the user in .file/.loc directives
131 with the file numbers used in the output debug info. */
132 static unsigned int *user_filenum
;
133 static unsigned int user_filenum_allocated
;
135 /* True when we've seen a .loc directive recently. Used to avoid
136 doing work when there's nothing to do. */
137 static boolean loc_directive_seen
;
139 /* Current location as indicated by the most recent .loc directive. */
140 static struct dwarf2_line_info current
;
142 /* Fake label name. */
143 static char const fake_label_name
[] = ".L0\001";
145 /* The size of an address on the target. */
146 static unsigned int sizeof_address
;
148 static struct line_subseg
*get_line_subseg
PARAMS ((segT
, subsegT
));
149 static unsigned int get_filenum
PARAMS ((const char *));
150 static struct frag
*first_frag_for_seg
PARAMS ((segT
));
151 static struct frag
*last_frag_for_seg
PARAMS ((segT
));
152 static void out_byte
PARAMS ((int));
153 static void out_opcode
PARAMS ((int));
154 static void out_two
PARAMS ((int));
155 static void out_four
PARAMS ((int));
156 static void out_abbrev
PARAMS ((int, int));
157 static void out_uleb128
PARAMS ((addressT
));
158 static symbolS
*symbol_new_now
PARAMS ((void));
159 static void set_symbol_value_now
PARAMS ((symbolS
*));
160 static offsetT get_frag_fix
PARAMS ((fragS
*));
161 static void out_set_addr
PARAMS ((segT
, fragS
*, addressT
));
162 static int size_inc_line_addr
PARAMS ((int, addressT
));
163 static void emit_inc_line_addr
PARAMS ((int, addressT
, char *, int));
164 static void out_inc_line_addr
PARAMS ((int, addressT
));
165 static void relax_inc_line_addr
PARAMS ((int, segT
, fragS
*, addressT
,
167 static void process_entries
PARAMS ((segT
, struct line_entry
*));
168 static void out_file_list
PARAMS ((void));
169 static void out_debug_line
PARAMS ((segT
));
170 static void out_debug_aranges
PARAMS ((segT
, segT
));
171 static void out_debug_abbrev
PARAMS ((segT
));
172 static void out_debug_info
PARAMS ((segT
, segT
, segT
));
174 /* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */
176 static struct line_subseg
*
177 get_line_subseg (seg
, subseg
)
181 static segT last_seg
;
182 static subsegT last_subseg
;
183 static struct line_subseg
*last_line_subseg
;
186 struct line_subseg
**pss
, *ss
;
188 if (seg
== last_seg
&& subseg
== last_subseg
)
189 return last_line_subseg
;
191 for (s
= all_segs
; s
; s
= s
->next
)
195 s
= (struct line_seg
*) xmalloc (sizeof (*s
));
202 for (pss
= &s
->head
; (ss
= *pss
) != NULL
; pss
= &ss
->next
)
204 if (ss
->subseg
== subseg
)
206 if (ss
->subseg
> subseg
)
210 ss
= (struct line_subseg
*) xmalloc (sizeof (*ss
));
214 ss
->ptail
= &ss
->head
;
219 last_subseg
= subseg
;
220 last_line_subseg
= ss
;
225 /* Record an entry for LOC ocurring at OFS within the current fragment. */
228 dwarf2_gen_line_info (ofs
, loc
)
230 struct dwarf2_line_info
*loc
;
232 struct line_subseg
*ss
;
233 struct line_entry
*e
;
235 /* Early out for as-yet incomplete location information. */
236 if (loc
->filenum
== 0 || loc
->line
== 0)
239 e
= (struct line_entry
*) xmalloc (sizeof (*e
));
245 ss
= get_line_subseg (now_seg
, now_subseg
);
247 ss
->ptail
= &e
->next
;
252 struct dwarf2_line_info
*line
;
254 if (debug_type
== DEBUG_DWARF2
)
257 as_where (&filename
, &line
->line
);
258 line
->filenum
= get_filenum (filename
);
260 line
->flags
= DWARF2_FLAG_BEGIN_STMT
;
266 /* Called for each machine instruction, or relatively atomic group of
267 machine instructions (ie built-in macro). The instruction or group
268 is SIZE bytes in length. If dwarf2 line number generation is called
269 for, emit a line statement appropriately. */
272 dwarf2_emit_insn (size
)
275 struct dwarf2_line_info loc
;
277 if (debug_type
!= DEBUG_DWARF2
&& ! loc_directive_seen
)
279 loc_directive_seen
= false;
282 dwarf2_gen_line_info (frag_now_fix () - size
, &loc
);
285 /* Get a .debug_line file number for FILENAME. */
288 get_filenum (filename
)
289 const char *filename
;
291 static unsigned int last_used
;
295 if (strcmp (filename
, files
[last_used
].filename
) == 0)
298 for (i
= 1; i
< files_in_use
; ++i
)
299 if (strcmp (filename
, files
[i
].filename
) == 0)
302 if (i
>= files_allocated
)
304 files_allocated
= i
+ 32;
305 files
= (struct file_entry
*)
306 xrealloc (files
, (i
+ 32) * sizeof(struct file_entry
));
309 files
[i
].filename
= xstrdup(filename
);
311 files_in_use
= i
+ 1;
317 /* Handle the .file directive. */
320 dwarf2_directive_file (dummy
)
321 int dummy ATTRIBUTE_UNUSED
;
324 const char *filename
;
327 /* Continue to accept a bare string and pass it off. */
329 if (*input_line_pointer
== '"')
335 num
= get_absolute_expression ();
336 filename
= demand_copy_C_string (&filename_len
);
337 demand_empty_rest_of_line ();
341 as_bad (_("File number less than zero"));
345 if (num
>= (int) user_filenum_allocated
)
347 unsigned int old
= user_filenum_allocated
;
349 user_filenum_allocated
= num
+ 16;
350 user_filenum
= (unsigned int *)
351 xrealloc (user_filenum
, (num
+ 16) * sizeof (unsigned int));
353 /* Zero the new memory. */
354 memset (user_filenum
+ old
, 0, (num
+ 16 - old
) * sizeof(unsigned int));
357 user_filenum
[num
] = get_filenum (filename
);
361 dwarf2_directive_loc (dummy
)
362 int dummy ATTRIBUTE_UNUSED
;
364 offsetT filenum
, line
, column
;
366 filenum
= get_absolute_expression ();
368 line
= get_absolute_expression ();
370 column
= get_absolute_expression ();
371 demand_empty_rest_of_line ();
375 as_bad (_("File number less than zero"));
378 if (filenum
>= (int) user_filenum_allocated
379 || user_filenum
[filenum
] == 0)
381 as_bad (_("Unassigned file number %ld"), (long) filenum
);
385 current
.filenum
= user_filenum
[filenum
];
387 current
.column
= column
;
388 current
.flags
= DWARF2_FLAG_BEGIN_STMT
;
390 loc_directive_seen
= true;
394 listing_source_line (line
);
400 first_frag_for_seg (seg
)
403 frchainS
*f
, *first
= NULL
;
405 for (f
= frchain_root
; f
; f
= f
->frch_next
)
406 if (f
->frch_seg
== seg
407 && (! first
|| first
->frch_subseg
> f
->frch_subseg
))
410 return first
? first
->frch_root
: NULL
;
414 last_frag_for_seg (seg
)
417 frchainS
*f
, *last
= NULL
;
419 for (f
= frchain_root
; f
; f
= f
->frch_next
)
420 if (f
->frch_seg
== seg
421 && (! last
|| last
->frch_subseg
< f
->frch_subseg
))
424 return last
? last
->frch_last
: NULL
;
427 /* Emit a single byte into the current segment. */
433 FRAG_APPEND_1_CHAR (byte
);
436 /* Emit a statement program opcode into the current segment. */
445 /* Emit a two-byte word into the current segment. */
451 md_number_to_chars (frag_more (2), data
, 2);
454 /* Emit a four byte word into the current segment. */
460 md_number_to_chars (frag_more (4), data
, 4);
463 /* Emit an unsigned "little-endian base 128" number. */
469 output_leb128 (frag_more (sizeof_leb128 (value
, 0)), value
, 0);
472 /* Emit a tuple for .debug_abbrev. */
475 out_abbrev (name
, form
)
482 /* Create a new fake symbol whose value is the current position. */
487 return symbol_new (fake_label_name
, now_seg
, frag_now_fix (), frag_now
);
490 /* Set the value of SYM to the current position in the current segment. */
493 set_symbol_value_now (sym
)
496 S_SET_SEGMENT (sym
, now_seg
);
497 S_SET_VALUE (sym
, frag_now_fix ());
498 symbol_set_frag (sym
, frag_now
);
501 /* Get the size of a fragment. */
512 /* If a fragment is the last in the chain, special measures must be
513 taken to find its size before relaxation, since it may be pending
514 on some subsegment chain. */
515 for (fr
= frchain_root
; fr
; fr
= fr
->frch_next
)
516 if (fr
->frch_last
== frag
)
518 return ((char *) obstack_next_free (&fr
->frch_obstack
)
525 /* Set an absolute address (may result in a relocation entry). */
528 out_set_addr (seg
, frag
, ofs
)
536 sym
= symbol_new (fake_label_name
, seg
, ofs
, frag
);
538 out_opcode (DW_LNS_extended_op
);
539 out_uleb128 (sizeof_address
+ 1);
541 out_opcode (DW_LNE_set_address
);
542 expr
.X_op
= O_symbol
;
543 expr
.X_add_symbol
= sym
;
544 expr
.X_add_number
= 0;
545 emit_expr (&expr
, sizeof_address
);
548 /* Encode a pair of line and address skips as efficiently as possible.
549 Note that the line skip is signed, whereas the address skip is unsigned.
551 The following two routines *must* be kept in sync. This is
552 enforced by making emit_inc_line_addr abort if we do not emit
553 exactly the expected number of bytes. */
556 size_inc_line_addr (line_delta
, addr_delta
)
560 unsigned int tmp
, opcode
;
563 /* Scale the address delta by the minimum instruction length. */
564 #if DWARF2_LINE_MIN_INSN_LENGTH > 1
565 assert (addr_delta
% DWARF2_LINE_MIN_INSN_LENGTH
== 0);
566 addr_delta
/= DWARF2_LINE_MIN_INSN_LENGTH
;
569 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
570 We cannot use special opcodes here, since we want the end_sequence
571 to emit the matrix entry. */
572 if (line_delta
== INT_MAX
)
574 if (addr_delta
== MAX_SPECIAL_ADDR_DELTA
)
577 len
= 1 + sizeof_leb128 (addr_delta
, 0);
581 /* Bias the line delta by the base. */
582 tmp
= line_delta
- DWARF2_LINE_BASE
;
584 /* If the line increment is out of range of a special opcode, we
585 must encode it with DW_LNS_advance_line. */
586 if (tmp
>= DWARF2_LINE_RANGE
)
588 len
= 1 + sizeof_leb128 (line_delta
, 1);
590 tmp
= 0 - DWARF2_LINE_BASE
;
593 /* Bias the opcode by the special opcode base. */
594 tmp
+= DWARF2_LINE_OPCODE_BASE
;
596 /* Avoid overflow when addr_delta is large. */
597 if (addr_delta
< 256 + MAX_SPECIAL_ADDR_DELTA
)
599 /* Try using a special opcode. */
600 opcode
= tmp
+ addr_delta
* DWARF2_LINE_RANGE
;
604 /* Try using DW_LNS_const_add_pc followed by special op. */
605 opcode
= tmp
+ (addr_delta
- MAX_SPECIAL_ADDR_DELTA
) * DWARF2_LINE_RANGE
;
610 /* Otherwise use DW_LNS_advance_pc. */
611 len
+= 1 + sizeof_leb128 (addr_delta
, 0);
613 /* DW_LNS_copy or special opcode. */
620 emit_inc_line_addr (line_delta
, addr_delta
, p
, len
)
626 unsigned int tmp
, opcode
;
630 #if DWARF2_LINE_MIN_INSN_LENGTH > 1
631 /* Scale the address delta by the minimum instruction length. */
632 assert (addr_delta
% DWARF2_LINE_MIN_INSN_LENGTH
== 0);
633 addr_delta
/= DWARF2_LINE_MIN_INSN_LENGTH
;
635 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
636 We cannot use special opcodes here, since we want the end_sequence
637 to emit the matrix entry. */
638 if (line_delta
== INT_MAX
)
640 if (addr_delta
== MAX_SPECIAL_ADDR_DELTA
)
641 *p
++ = DW_LNS_const_add_pc
;
644 *p
++ = DW_LNS_advance_pc
;
645 p
+= output_leb128 (p
, addr_delta
, 0);
648 *p
++ = DW_LNS_extended_op
;
650 *p
++ = DW_LNE_end_sequence
;
654 /* Bias the line delta by the base. */
655 tmp
= line_delta
- DWARF2_LINE_BASE
;
657 /* If the line increment is out of range of a special opcode, we
658 must encode it with DW_LNS_advance_line. */
659 if (tmp
>= DWARF2_LINE_RANGE
)
661 *p
++ = DW_LNS_advance_line
;
662 p
+= output_leb128 (p
, line_delta
, 1);
664 /* Prettier, I think, to use DW_LNS_copy instead of a
665 "line +0, addr +0" special opcode. */
673 tmp
= 0 - DWARF2_LINE_BASE
;
677 /* Bias the opcode by the special opcode base. */
678 tmp
+= DWARF2_LINE_OPCODE_BASE
;
680 /* Avoid overflow when addr_delta is large. */
681 if (addr_delta
< 256 + MAX_SPECIAL_ADDR_DELTA
)
683 /* Try using a special opcode. */
684 opcode
= tmp
+ addr_delta
* DWARF2_LINE_RANGE
;
691 /* Try using DW_LNS_const_add_pc followed by special op. */
692 opcode
= tmp
+ (addr_delta
- MAX_SPECIAL_ADDR_DELTA
) * DWARF2_LINE_RANGE
;
695 *p
++ = DW_LNS_const_add_pc
;
701 /* Otherwise use DW_LNS_advance_pc. */
702 *p
++ = DW_LNS_advance_pc
;
703 p
+= output_leb128 (p
, addr_delta
, 0);
714 /* Handy routine to combine calls to the above two routines. */
717 out_inc_line_addr (line_delta
, addr_delta
)
721 int len
= size_inc_line_addr (line_delta
, addr_delta
);
722 emit_inc_line_addr (line_delta
, addr_delta
, frag_more (len
), len
);
725 /* Generate a variant frag that we can use to relax address/line
726 increments between fragments of the target segment. */
729 relax_inc_line_addr (line_delta
, seg
, to_frag
, to_ofs
, from_frag
, from_ofs
)
732 fragS
*to_frag
, *from_frag
;
733 addressT to_ofs
, from_ofs
;
735 symbolS
*to_sym
, *from_sym
;
739 to_sym
= symbol_new (fake_label_name
, seg
, to_ofs
, to_frag
);
740 from_sym
= symbol_new (fake_label_name
, seg
, from_ofs
, from_frag
);
742 expr
.X_op
= O_subtract
;
743 expr
.X_add_symbol
= to_sym
;
744 expr
.X_op_symbol
= from_sym
;
745 expr
.X_add_number
= 0;
747 /* The maximum size of the frag is the line delta with a maximum
748 sized address delta. */
749 max_chars
= size_inc_line_addr (line_delta
, -DWARF2_LINE_MIN_INSN_LENGTH
);
751 frag_var (rs_dwarf2dbg
, max_chars
, max_chars
, 1,
752 make_expr_symbol (&expr
), line_delta
, NULL
);
755 /* The function estimates the size of a rs_dwarf2dbg variant frag
756 based on the current values of the symbols. It is called before
757 the relaxation loop. We set fr_subtype to the expected length. */
760 dwarf2dbg_estimate_size_before_relax (frag
)
766 addr_delta
= resolve_symbol_value (frag
->fr_symbol
, 0);
767 size
= size_inc_line_addr (frag
->fr_offset
, addr_delta
);
769 frag
->fr_subtype
= size
;
774 /* This function relaxes a rs_dwarf2dbg variant frag based on the
775 current values of the symbols. fr_subtype is the current length
776 of the frag. This returns the change in frag length. */
779 dwarf2dbg_relax_frag (frag
)
782 int old_size
, new_size
;
784 old_size
= frag
->fr_subtype
;
785 new_size
= dwarf2dbg_estimate_size_before_relax (frag
);
787 return new_size
- old_size
;
790 /* This function converts a rs_dwarf2dbg variant frag into a normal
791 fill frag. This is called after all relaxation has been done.
792 fr_subtype will be the desired length of the frag. */
795 dwarf2dbg_convert_frag (frag
)
800 addr_diff
= resolve_symbol_value (frag
->fr_symbol
, 1);
802 /* fr_var carries the max_chars that we created the fragment with.
803 fr_subtype carries the current expected length. We must, of
804 course, have allocated enough memory earlier. */
805 assert (frag
->fr_var
>= (int) frag
->fr_subtype
);
807 emit_inc_line_addr (frag
->fr_offset
, addr_diff
,
808 frag
->fr_literal
+ frag
->fr_fix
, frag
->fr_subtype
);
810 frag
->fr_fix
+= frag
->fr_subtype
;
811 frag
->fr_type
= rs_fill
;
816 /* Generate .debug_line content for the chain of line number entries
817 beginning at E, for segment SEG. */
820 process_entries (seg
, e
)
822 struct line_entry
*e
;
824 unsigned filenum
= 1;
827 unsigned flags
= DWARF2_LINE_DEFAULT_IS_STMT
? DWARF2_FLAG_BEGIN_STMT
: 0;
830 addressT frag_ofs
= 0;
831 addressT last_frag_ofs
;
832 struct line_entry
*next
;
838 if (filenum
!= e
->loc
.filenum
)
840 filenum
= e
->loc
.filenum
;
841 out_opcode (DW_LNS_set_file
);
842 out_uleb128 (filenum
);
846 if (column
!= e
->loc
.column
)
848 column
= e
->loc
.column
;
849 out_opcode (DW_LNS_set_column
);
850 out_uleb128 (column
);
854 if ((e
->loc
.flags
^ flags
) & DWARF2_FLAG_BEGIN_STMT
)
856 flags
= e
->loc
.flags
;
857 out_opcode (DW_LNS_negate_stmt
);
861 if (e
->loc
.flags
& DWARF2_FLAG_BEGIN_BLOCK
)
863 out_opcode (DW_LNS_set_basic_block
);
867 if (line
!= e
->loc
.line
|| changed
)
869 int line_delta
= e
->loc
.line
- line
;
872 out_set_addr (seg
, e
->frag
, e
->frag_ofs
);
873 out_inc_line_addr (line_delta
, 0);
875 else if (frag
== e
->frag
)
876 out_inc_line_addr (line_delta
, e
->frag_ofs
- frag_ofs
);
878 relax_inc_line_addr (line_delta
, seg
, e
->frag
, e
->frag_ofs
,
882 frag_ofs
= e
->frag_ofs
;
885 else if (frag
== NULL
)
887 out_set_addr (seg
, e
->frag
, e
->frag_ofs
);
889 frag_ofs
= e
->frag_ofs
;
897 /* Emit a DW_LNE_end_sequence for the end of the section. */
898 last_frag
= last_frag_for_seg (seg
);
899 last_frag_ofs
= get_frag_fix (last_frag
);
900 if (frag
== last_frag
)
901 out_inc_line_addr (INT_MAX
, last_frag_ofs
- frag_ofs
);
903 relax_inc_line_addr (INT_MAX
, seg
, last_frag
, last_frag_ofs
,
907 /* Emit the directory and file tables for .debug_line. */
916 /* Terminate directory list. */
919 for (i
= 1; i
< files_in_use
; ++i
)
921 size
= strlen (files
[i
].filename
) + 1;
922 cp
= frag_more (size
);
923 memcpy (cp
, files
[i
].filename
, size
);
925 out_uleb128 (files
[i
].dir
); /* directory number */
926 out_uleb128 (0); /* last modification timestamp */
927 out_uleb128 (0); /* filesize */
930 /* Terminate filename list. */
934 /* Emit the collected .debug_line data. */
937 out_debug_line (line_seg
)
942 symbolS
*prologue_end
;
946 subseg_set (line_seg
, 0);
948 line_start
= symbol_new_now ();
949 prologue_end
= symbol_make (fake_label_name
);
950 line_end
= symbol_make (fake_label_name
);
952 /* Total length of the information for this compilation unit. */
953 expr
.X_op
= O_subtract
;
954 expr
.X_add_symbol
= line_end
;
955 expr
.X_op_symbol
= line_start
;
956 expr
.X_add_number
= -4;
957 emit_expr (&expr
, 4);
962 /* Length of the prologue following this length. */
963 expr
.X_op
= O_subtract
;
964 expr
.X_add_symbol
= prologue_end
;
965 expr
.X_op_symbol
= line_start
;
966 expr
.X_add_number
= - (4 + 2 + 4);
967 emit_expr (&expr
, 4);
969 /* Parameters of the state machine. */
970 out_byte (DWARF2_LINE_MIN_INSN_LENGTH
);
971 out_byte (DWARF2_LINE_DEFAULT_IS_STMT
);
972 out_byte (DWARF2_LINE_BASE
);
973 out_byte (DWARF2_LINE_RANGE
);
974 out_byte (DWARF2_LINE_OPCODE_BASE
);
976 /* Standard opcode lengths. */
977 out_byte (0); /* DW_LNS_copy */
978 out_byte (1); /* DW_LNS_advance_pc */
979 out_byte (1); /* DW_LNS_advance_line */
980 out_byte (1); /* DW_LNS_set_file */
981 out_byte (1); /* DW_LNS_set_column */
982 out_byte (0); /* DW_LNS_negate_stmt */
983 out_byte (0); /* DW_LNS_set_basic_block */
984 out_byte (0); /* DW_LNS_const_add_pc */
985 out_byte (1); /* DW_LNS_fixed_advance_pc */
989 set_symbol_value_now (prologue_end
);
991 /* For each section, emit a statement program. */
992 for (s
= all_segs
; s
; s
= s
->next
)
993 process_entries (s
->seg
, s
->head
->head
);
995 set_symbol_value_now (line_end
);
998 /* Emit data for .debug_aranges. */
1001 out_debug_aranges (aranges_seg
, info_seg
)
1005 unsigned int addr_size
= sizeof_address
;
1006 addressT size
, skip
;
1011 size
= 4 + 2 + 4 + 1 + 1;
1013 skip
= 2*addr_size
- (size
& (2*addr_size
- 1));
1014 if (skip
== 2*addr_size
)
1018 for (s
= all_segs
; s
; s
= s
->next
)
1019 size
+= 2*addr_size
;
1021 size
+= 2*addr_size
;
1023 subseg_set (aranges_seg
, 0);
1025 /* Length of the compilation unit. */
1026 out_four (size
- 4);
1031 /* Offset to .debug_info. */
1032 expr
.X_op
= O_symbol
;
1033 expr
.X_add_symbol
= section_symbol (info_seg
);
1034 expr
.X_add_number
= 0;
1035 emit_expr (&expr
, 4);
1037 /* Size of an address (offset portion). */
1038 out_byte (addr_size
);
1040 /* Size of a segment descriptor. */
1043 /* Align the header. */
1045 frag_align (ffs (2*addr_size
) - 1, 0, 0);
1047 for (s
= all_segs
; s
; s
= s
->next
)
1052 frag
= first_frag_for_seg (s
->seg
);
1053 beg
= symbol_new (fake_label_name
, s
->seg
, 0, frag
);
1054 s
->text_start
= beg
;
1056 frag
= last_frag_for_seg (s
->seg
);
1057 end
= symbol_new (fake_label_name
, s
->seg
, get_frag_fix (frag
), frag
);
1060 expr
.X_op
= O_symbol
;
1061 expr
.X_add_symbol
= beg
;
1062 expr
.X_add_number
= 0;
1063 emit_expr (&expr
, addr_size
);
1065 expr
.X_op
= O_subtract
;
1066 expr
.X_add_symbol
= end
;
1067 expr
.X_op_symbol
= beg
;
1068 expr
.X_add_number
= 0;
1069 emit_expr (&expr
, addr_size
);
1072 p
= frag_more (2 * addr_size
);
1073 md_number_to_chars (p
, 0, addr_size
);
1074 md_number_to_chars (p
+ addr_size
, 0, addr_size
);
1077 /* Emit data for .debug_abbrev. Note that this must be kept in
1078 sync with out_debug_info below. */
1081 out_debug_abbrev (abbrev_seg
)
1084 subseg_set (abbrev_seg
, 0);
1087 out_uleb128 (DW_TAG_compile_unit
);
1088 out_byte (DW_CHILDREN_no
);
1089 out_abbrev (DW_AT_stmt_list
, DW_FORM_data4
);
1090 if (all_segs
->next
== NULL
)
1092 out_abbrev (DW_AT_low_pc
, DW_FORM_addr
);
1093 out_abbrev (DW_AT_high_pc
, DW_FORM_addr
);
1095 out_abbrev (DW_AT_comp_dir
, DW_FORM_string
);
1096 out_abbrev (DW_AT_producer
, DW_FORM_string
);
1097 out_abbrev (DW_AT_language
, DW_FORM_data2
);
1101 /* Emit a description of this compilation unit for .debug_info. */
1104 out_debug_info (info_seg
, abbrev_seg
, line_seg
)
1112 symbolS
*info_start
;
1117 subseg_set (info_seg
, 0);
1119 info_start
= symbol_new_now();
1120 info_end
= symbol_make (fake_label_name
);
1122 /* Compilation Unit length. */
1123 expr
.X_op
= O_subtract
;
1124 expr
.X_add_symbol
= info_end
;
1125 expr
.X_op_symbol
= info_start
;
1126 expr
.X_add_number
= -4;
1127 emit_expr (&expr
, 4);
1129 /* DWARF version. */
1132 /* .debug_abbrev offset */
1133 expr
.X_op
= O_symbol
;
1134 expr
.X_add_symbol
= section_symbol (abbrev_seg
);
1135 expr
.X_add_number
= 0;
1136 emit_expr (&expr
, 4);
1138 /* Target address size. */
1139 out_byte (sizeof_address
);
1141 /* DW_TAG_compile_unit DIE abbrev */
1144 /* DW_AT_stmt_list */
1145 expr
.X_op
= O_symbol
;
1146 expr
.X_add_symbol
= section_symbol (line_seg
);
1147 expr
.X_add_number
= 0;
1148 emit_expr (&expr
, 4);
1150 /* These two attributes may only be emitted if all of the code is
1151 contiguous. Multiple sections are not that. */
1152 if (all_segs
->next
== NULL
)
1155 expr
.X_op
= O_symbol
;
1156 expr
.X_add_symbol
= all_segs
->text_start
;
1157 expr
.X_add_number
= 0;
1158 emit_expr (&expr
, sizeof_address
);
1161 expr
.X_op
= O_symbol
;
1162 expr
.X_add_symbol
= all_segs
->text_end
;
1163 expr
.X_add_number
= 0;
1164 emit_expr (&expr
, sizeof_address
);
1167 /* DW_AT_comp_dir */
1168 comp_dir
= getpwd ();
1169 len
= strlen (comp_dir
) + 1;
1170 p
= frag_more (len
);
1171 memcpy (p
, comp_dir
, len
);
1173 /* DW_AT_producer */
1174 sprintf (producer
, "GNU AS %s", VERSION
);
1175 len
= strlen (producer
) + 1;
1176 p
= frag_more (len
);
1177 memcpy (p
, producer
, len
);
1179 /* DW_AT_language. Yes, this is probably not really MIPS, but the
1180 dwarf2 draft has no standard code for assembler. */
1181 out_two (DW_LANG_Mips_Assembler
);
1183 set_symbol_value_now (info_end
);
1192 /* If no debug information was recorded, nothing to do. */
1193 if (all_segs
== NULL
)
1196 /* Calculate the size of an address for the target machine. */
1197 #ifdef BFD_ASSEMBLER
1198 sizeof_address
= bfd_arch_bits_per_address (stdoutput
) / 8;
1204 /* Create and switch to the line number section. */
1205 line_seg
= subseg_new (".debug_line", 0);
1206 #ifdef BFD_ASSEMBLER
1207 bfd_set_section_flags (stdoutput
, line_seg
, SEC_READONLY
);
1210 /* For each subsection, chain the debug entries together. */
1211 for (s
= all_segs
; s
; s
= s
->next
)
1213 struct line_subseg
*ss
= s
->head
;
1214 struct line_entry
**ptail
= ss
->ptail
;
1216 while ((ss
= ss
->next
) != NULL
)
1223 out_debug_line (line_seg
);
1225 /* If this is assembler generated line info, we need .debug_info
1226 and .debug_abbrev sections as well. */
1227 if (debug_type
== DEBUG_DWARF2
)
1233 info_seg
= subseg_new (".debug_info", 0);
1234 abbrev_seg
= subseg_new (".debug_abbrev", 0);
1235 aranges_seg
= subseg_new (".debug_aranges", 0);
1237 #ifdef BFD_ASSEMBLER
1238 bfd_set_section_flags (stdoutput
, info_seg
, SEC_READONLY
);
1239 bfd_set_section_flags (stdoutput
, abbrev_seg
, SEC_READONLY
);
1240 bfd_set_section_flags (stdoutput
, aranges_seg
, SEC_READONLY
);
1243 record_alignment (aranges_seg
, ffs (2*sizeof_address
) - 1);
1245 out_debug_aranges (aranges_seg
, info_seg
);
1246 out_debug_abbrev (abbrev_seg
);
1247 out_debug_info (info_seg
, abbrev_seg
, line_seg
);
1258 dwarf2dbg_estimate_size_before_relax (frag
)
1259 fragS
*frag ATTRIBUTE_UNUSED
;
1261 as_fatal (_("dwarf2 is not supported for this object file format"));
1266 dwarf2dbg_relax_frag (frag
)
1267 fragS
*frag ATTRIBUTE_UNUSED
;
1269 as_fatal (_("dwarf2 is not supported for this object file format"));
1274 dwarf2dbg_convert_frag (frag
)
1275 fragS
*frag ATTRIBUTE_UNUSED
;
1277 as_fatal (_("dwarf2 is not supported for this object file format"));
1281 dwarf2_emit_insn (size
)
1282 int size ATTRIBUTE_UNUSED
;
1287 dwarf2_directive_file (dummy
)
1288 int dummy ATTRIBUTE_UNUSED
;
1290 as_fatal (_("dwarf2 is not supported for this object file format"));
1294 dwarf2_directive_loc (dummy
)
1295 int dummy ATTRIBUTE_UNUSED
;
1297 as_fatal (_("dwarf2 is not supported for this object file format"));
1299 #endif /* BFD_ASSEMBLER */