/* dwarf2dbg.c - DWARF2 debug support
- Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005
+ Free Software Foundation, Inc.
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of GAS, the GNU Assembler.
You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to the Free
- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
+ Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
+ 02110-1301, USA. */
/* Logical line numbers can be controlled by the compiler via the
following two directives:
#endif
#ifndef DWARF2_ADDR_SIZE
-# define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8);
-#endif
-
-#ifndef TC_DWARF2_EMIT_OFFSET
-# define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
+# define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
#endif
#ifdef BFD_ASSEMBLER
/* The size of an address on the target. */
static unsigned int sizeof_address;
\f
-static void generic_dwarf2_emit_offset PARAMS((symbolS *, unsigned int));
-static struct line_subseg *get_line_subseg PARAMS ((segT, subsegT));
-static unsigned int get_filenum PARAMS ((const char *, unsigned int));
-static struct frag *first_frag_for_seg PARAMS ((segT));
-static struct frag *last_frag_for_seg PARAMS ((segT));
-static void out_byte PARAMS ((int));
-static void out_opcode PARAMS ((int));
-static void out_two PARAMS ((int));
-static void out_four PARAMS ((int));
-static void out_abbrev PARAMS ((int, int));
-static void out_uleb128 PARAMS ((addressT));
-static offsetT get_frag_fix PARAMS ((fragS *));
-static void out_set_addr PARAMS ((segT, fragS *, addressT));
-static int size_inc_line_addr PARAMS ((int, addressT));
-static void emit_inc_line_addr PARAMS ((int, addressT, char *, int));
-static void out_inc_line_addr PARAMS ((int, addressT));
-static void relax_inc_line_addr PARAMS ((int, segT, fragS *, addressT,
- fragS *, addressT));
-static void process_entries PARAMS ((segT, struct line_entry *));
-static void out_file_list PARAMS ((void));
-static void out_debug_line PARAMS ((segT));
-static void out_debug_aranges PARAMS ((segT, segT));
-static void out_debug_abbrev PARAMS ((segT));
-static void out_debug_info PARAMS ((segT, segT, segT));
+static struct line_subseg *get_line_subseg (segT, subsegT);
+static unsigned int get_filenum (const char *, unsigned int);
+static struct frag *first_frag_for_seg (segT);
+static struct frag *last_frag_for_seg (segT);
+static void out_byte (int);
+static void out_opcode (int);
+static void out_two (int);
+static void out_four (int);
+static void out_abbrev (int, int);
+static void out_uleb128 (addressT);
+static offsetT get_frag_fix (fragS *);
+static void out_set_addr (segT, fragS *, addressT);
+static int size_inc_line_addr (int, addressT);
+static void emit_inc_line_addr (int, addressT, char *, int);
+static void out_inc_line_addr (int, addressT);
+static void relax_inc_line_addr (int, segT, fragS *, addressT,
+ fragS *, addressT);
+static void process_entries (segT, struct line_entry *);
+static void out_file_list (void);
+static void out_debug_line (segT);
+static void out_debug_aranges (segT, segT);
+static void out_debug_abbrev (segT);
+static void out_debug_info (segT, segT, segT);
\f
+#ifndef TC_DWARF2_EMIT_OFFSET
+# define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
+static void generic_dwarf2_emit_offset (symbolS *, unsigned int);
+
/* Create an offset to .dwarf2_*. */
static void
-generic_dwarf2_emit_offset (symbol, size)
- symbolS *symbol;
- unsigned int size;
+generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
{
expressionS expr;
expr.X_add_number = 0;
emit_expr (&expr, size);
}
+#endif
/* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */
static struct line_subseg *
-get_line_subseg (seg, subseg)
- segT seg;
- subsegT subseg;
+get_line_subseg (segT seg, subsegT subseg)
{
static segT last_seg;
static subsegT last_subseg;
return ss;
}
-/* Record an entry for LOC ocurring at OFS within the current fragment. */
+/* Record an entry for LOC occurring at OFS within the current fragment. */
void
-dwarf2_gen_line_info (ofs, loc)
- addressT ofs;
- struct dwarf2_line_info *loc;
+dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
{
struct line_subseg *ss;
struct line_entry *e;
}
void
-dwarf2_where (line)
- struct dwarf2_line_info *line;
+dwarf2_where (struct dwarf2_line_info *line)
{
if (debug_type == DEBUG_DWARF2)
{
for, emit a line statement appropriately. */
void
-dwarf2_emit_insn (size)
- int size;
+dwarf2_emit_insn (int size)
{
struct dwarf2_line_info loc;
empty one. */
static unsigned int
-get_filenum (filename, num)
- const char *filename;
- unsigned int num;
+get_filenum (const char *filename, unsigned int num)
{
static unsigned int last_used, last_used_dir_len;
const char *file;
{
--dir_len;
for (dir = 1; dir < dirs_in_use; ++dir)
- if (memcmp (filename, dirs[dir], dir_len) == 0
+ if (strncmp (filename, dirs[dir], dir_len) == 0
&& dirs[dir][dir_len] == '\0')
break;
If an entry is added to the file table, return a pointer to the filename. */
char *
-dwarf2_directive_file (dummy)
- int dummy ATTRIBUTE_UNUSED;
+dwarf2_directive_file (int dummy ATTRIBUTE_UNUSED)
{
offsetT num;
char *filename;
}
void
-dwarf2_directive_loc (dummy)
- int dummy ATTRIBUTE_UNUSED;
+dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
{
offsetT filenum, line, column;
}
\f
static struct frag *
-first_frag_for_seg (seg)
- segT seg;
+first_frag_for_seg (segT seg)
{
frchainS *f, *first = NULL;
}
static struct frag *
-last_frag_for_seg (seg)
- segT seg;
+last_frag_for_seg (segT seg)
{
frchainS *f, *last = NULL;
/* Emit a single byte into the current segment. */
static inline void
-out_byte (byte)
- int byte;
+out_byte (int byte)
{
FRAG_APPEND_1_CHAR (byte);
}
/* Emit a statement program opcode into the current segment. */
static inline void
-out_opcode (opc)
- int opc;
+out_opcode (int opc)
{
out_byte (opc);
}
/* Emit a two-byte word into the current segment. */
static inline void
-out_two (data)
- int data;
+out_two (int data)
{
md_number_to_chars (frag_more (2), data, 2);
}
/* Emit a four byte word into the current segment. */
static inline void
-out_four (data)
- int data;
+out_four (int data)
{
md_number_to_chars (frag_more (4), data, 4);
}
/* Emit an unsigned "little-endian base 128" number. */
static void
-out_uleb128 (value)
- addressT value;
+out_uleb128 (addressT value)
{
output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0);
}
/* Emit a tuple for .debug_abbrev. */
static inline void
-out_abbrev (name, form)
- int name, form;
+out_abbrev (int name, int form)
{
out_uleb128 (name);
out_uleb128 (form);
/* Get the size of a fragment. */
static offsetT
-get_frag_fix (frag)
- fragS *frag;
+get_frag_fix (fragS *frag)
{
frchainS *fr;
on some subsegment chain. */
for (fr = frchain_root; fr; fr = fr->frch_next)
if (fr->frch_last == frag)
- {
- long align_mask = -1 << get_recorded_alignment (fr->frch_seg);
- return (((char *) obstack_next_free (&fr->frch_obstack)
- - frag->fr_literal) + ~align_mask) & align_mask;
- }
+ return (char *) obstack_next_free (&fr->frch_obstack) - frag->fr_literal;
abort ();
}
/* Set an absolute address (may result in a relocation entry). */
static void
-out_set_addr (seg, frag, ofs)
- segT seg;
- fragS *frag;
- addressT ofs;
+out_set_addr (segT seg, fragS *frag, addressT ofs)
{
expressionS expr;
symbolS *sym;
}
#if DWARF2_LINE_MIN_INSN_LENGTH > 1
-static void scale_addr_delta PARAMS ((addressT *));
+static void scale_addr_delta (addressT *);
static void
-scale_addr_delta (addr_delta)
- addressT *addr_delta;
+scale_addr_delta (addressT *addr_delta)
{
static int printed_this = 0;
if (*addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0)
exactly the expected number of bytes. */
static int
-size_inc_line_addr (line_delta, addr_delta)
- int line_delta;
- addressT addr_delta;
+size_inc_line_addr (int line_delta, addressT addr_delta)
{
unsigned int tmp, opcode;
int len = 0;
}
static void
-emit_inc_line_addr (line_delta, addr_delta, p, len)
- int line_delta;
- addressT addr_delta;
- char *p;
- int len;
+emit_inc_line_addr (int line_delta, addressT addr_delta, char *p, int len)
{
unsigned int tmp, opcode;
int need_copy = 0;
/* Handy routine to combine calls to the above two routines. */
static void
-out_inc_line_addr (line_delta, addr_delta)
- int line_delta;
- addressT addr_delta;
+out_inc_line_addr (int line_delta, addressT addr_delta)
{
int len = size_inc_line_addr (line_delta, addr_delta);
emit_inc_line_addr (line_delta, addr_delta, frag_more (len), len);
increments between fragments of the target segment. */
static void
-relax_inc_line_addr (line_delta, seg, to_frag, to_ofs, from_frag, from_ofs)
- int line_delta;
- segT seg;
- fragS *to_frag, *from_frag;
- addressT to_ofs, from_ofs;
+relax_inc_line_addr (int line_delta, segT seg,
+ fragS *to_frag, addressT to_ofs,
+ fragS *from_frag, addressT from_ofs)
{
symbolS *to_sym, *from_sym;
expressionS expr;
the relaxation loop. We set fr_subtype to the expected length. */
int
-dwarf2dbg_estimate_size_before_relax (frag)
- fragS *frag;
+dwarf2dbg_estimate_size_before_relax (fragS *frag)
{
offsetT addr_delta;
int size;
of the frag. This returns the change in frag length. */
int
-dwarf2dbg_relax_frag (frag)
- fragS *frag;
+dwarf2dbg_relax_frag (fragS *frag)
{
int old_size, new_size;
fr_subtype will be the desired length of the frag. */
void
-dwarf2dbg_convert_frag (frag)
- fragS *frag;
+dwarf2dbg_convert_frag (fragS *frag)
{
offsetT addr_diff;
beginning at E, for segment SEG. */
static void
-process_entries (seg, e)
- segT seg;
- struct line_entry *e;
+process_entries (segT seg, struct line_entry *e)
{
unsigned filenum = 1;
unsigned line = 1;
/* Emit the directory and file tables for .debug_line. */
static void
-out_file_list ()
+out_file_list (void)
{
size_t size;
char *cp;
/* Emit the collected .debug_line data. */
static void
-out_debug_line (line_seg)
- segT line_seg;
+out_debug_line (segT line_seg)
{
expressionS expr;
symbolS *line_start;
/* Emit data for .debug_aranges. */
static void
-out_debug_aranges (aranges_seg, info_seg)
- segT aranges_seg;
- segT info_seg;
+out_debug_aranges (segT aranges_seg, segT info_seg)
{
unsigned int addr_size = sizeof_address;
addressT size, skip;
sync with out_debug_info below. */
static void
-out_debug_abbrev (abbrev_seg)
- segT abbrev_seg;
+out_debug_abbrev (segT abbrev_seg)
{
subseg_set (abbrev_seg, 0);
/* Emit a description of this compilation unit for .debug_info. */
static void
-out_debug_info (info_seg, abbrev_seg, line_seg)
- segT info_seg;
- segT abbrev_seg;
- segT line_seg;
+out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg)
{
char producer[128];
char *comp_dir;
symbol_set_value_now (info_end);
}
+/* Finish the dwarf2 debug sections. We emit .debug.line if there
+ were any .file/.loc directives, or --gdwarf2 was given, or if the
+ file has a non-empty .debug_info section. If we emit .debug_line,
+ and the .debug_info section is empty, we also emit .debug_info,
+ .debug_aranges and .debug_abbrev. ALL_SEGS will be non-null if
+ there were any .file/.loc directives, or --gdwarf2 was given and
+ there were any located instructions emitted. */
+
void
-dwarf2_finish ()
+dwarf2_finish (void)
{
segT line_seg;
struct line_seg *s;
+ segT info_seg;
+ int emit_other_sections = 0;
+
+ info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
+ emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
- /* We don't need to do anything unless:
- - Some debug information was recorded via .file/.loc
- - or, we are generating DWARF2 information ourself (--gdwarf2)
- - or, there is a user-provided .debug_info section which could
- reference the file table in the .debug_line section we generate
- below. */
- if (all_segs == NULL
- && debug_type != DEBUG_DWARF2
- && bfd_get_section_by_name (stdoutput, ".debug_info") == NULL)
+ if (!all_segs && emit_other_sections)
+ /* There is no line information and no non-empty .debug_info
+ section. */
return;
/* Calculate the size of an address for the target machine. */
/* Create and switch to the line number section. */
line_seg = subseg_new (".debug_line", 0);
- bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY);
+ bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY | SEC_DEBUGGING);
/* For each subsection, chain the debug entries together. */
for (s = all_segs; s; s = s->next)
out_debug_line (line_seg);
- /* If this is assembler generated line info, we need .debug_info
- and .debug_abbrev sections as well. */
- if (all_segs != NULL && debug_type == DEBUG_DWARF2)
+ /* If this is assembler generated line info, and there is no
+ debug_info already, we need .debug_info and .debug_abbrev
+ sections as well. */
+ if (emit_other_sections)
{
segT abbrev_seg;
- segT info_seg;
segT aranges_seg;
+ assert (all_segs);
+
info_seg = subseg_new (".debug_info", 0);
abbrev_seg = subseg_new (".debug_abbrev", 0);
aranges_seg = subseg_new (".debug_aranges", 0);
- bfd_set_section_flags (stdoutput, info_seg, SEC_READONLY);
- bfd_set_section_flags (stdoutput, abbrev_seg, SEC_READONLY);
- bfd_set_section_flags (stdoutput, aranges_seg, SEC_READONLY);
+ bfd_set_section_flags (stdoutput, info_seg,
+ SEC_READONLY | SEC_DEBUGGING);
+ bfd_set_section_flags (stdoutput, abbrev_seg,
+ SEC_READONLY | SEC_DEBUGGING);
+ bfd_set_section_flags (stdoutput, aranges_seg,
+ SEC_READONLY | SEC_DEBUGGING);
record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);