/* dwarf2dbg.c - DWARF2 debug support
- Copyright 1999-2013 Free Software Foundation, Inc.
+ Copyright (C) 1999-2015 Free Software Foundation, Inc.
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of GAS, the GNU Assembler.
/* The maximum address skip amount that can be encoded with a special op. */
#define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
+#ifndef TC_PARSE_CONS_RETURN_NONE
+#define TC_PARSE_CONS_RETURN_NONE BFD_RELOC_NONE
+#endif
+
struct line_entry {
struct line_entry *next;
symbolS *label;
subsegT subseg;
struct line_entry *head;
struct line_entry **ptail;
+ struct line_entry **pmove_tail;
};
struct line_seg {
/* Collects data for all line table entries during assembly. */
static struct line_seg *all_segs;
-/* Hash used to quickly lookup a segment by name, avoiding the need to search
- through the all_segs list. */
-static struct hash_control *all_segs_hash;
static struct line_seg **last_seg_ptr;
struct file_entry {
0
};
-/* Lines that are at the same location as CURRENT, and which are waiting
- for a label. */
-static struct line_entry *pending_lines, **pending_lines_tail = &pending_lines;
-
/* The size of an address on the target. */
static unsigned int sizeof_address;
\f
}
#endif
-/* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */
+/* Find or create (if CREATE_P) an entry for SEG+SUBSEG in ALL_SEGS. */
static struct line_subseg *
-get_line_subseg (segT seg, subsegT subseg)
+get_line_subseg (segT seg, subsegT subseg, bfd_boolean create_p)
{
- static segT last_seg;
- static subsegT last_subseg;
- static struct line_subseg *last_line_subseg;
-
- struct line_seg *s;
+ struct line_seg *s = seg_info (seg)->dwarf2_line_seg;
struct line_subseg **pss, *lss;
- if (seg == last_seg && subseg == last_subseg)
- return last_line_subseg;
-
- s = (struct line_seg *) hash_find (all_segs_hash, seg->name);
if (s == NULL)
{
+ if (!create_p)
+ return NULL;
+
s = (struct line_seg *) xmalloc (sizeof (*s));
s->next = NULL;
s->seg = seg;
s->head = NULL;
*last_seg_ptr = s;
last_seg_ptr = &s->next;
- hash_insert (all_segs_hash, seg->name, s);
+ seg_info (seg)->dwarf2_line_seg = s;
}
gas_assert (seg == s->seg);
lss->subseg = subseg;
lss->head = NULL;
lss->ptail = &lss->head;
+ lss->pmove_tail = &lss->head;
*pss = lss;
found_subseg:
- last_seg = seg;
- last_subseg = subseg;
- last_line_subseg = lss;
-
return lss;
}
-/* Push LOC onto the pending lines list. */
+/* Record an entry for LOC occurring at LABEL. */
static void
-dwarf2_push_line (struct dwarf2_line_info *loc)
+dwarf2_gen_line_info_1 (symbolS *label, struct dwarf2_line_info *loc)
{
+ struct line_subseg *lss;
struct line_entry *e;
e = (struct line_entry *) xmalloc (sizeof (*e));
e->next = NULL;
- e->label = NULL;
+ e->label = label;
e->loc = *loc;
- *pending_lines_tail = e;
- pending_lines_tail = &(*pending_lines_tail)->next;
-}
-
-/* Emit all pending line information. LABEL is the label with which the
- lines should be associated, or null if they should be associated with
- the current position. */
-
-static void
-dwarf2_flush_pending_lines (symbolS *label)
-{
- if (pending_lines)
- {
- struct line_subseg *lss;
- struct line_entry *e;
-
- if (!label)
- label = symbol_temp_new_now ();
-
- for (e = pending_lines; e; e = e->next)
- e->label = label;
-
- lss = get_line_subseg (now_seg, now_subseg);
- *lss->ptail = pending_lines;
- lss->ptail = pending_lines_tail;
-
- pending_lines = NULL;
- pending_lines_tail = &pending_lines;
- }
+ lss = get_line_subseg (now_seg, now_subseg, TRUE);
+ *lss->ptail = e;
+ lss->ptail = &e->next;
}
/* Record an entry for LOC occurring at OFS within the current fragment. */
static unsigned int line = -1;
static unsigned int filenum = -1;
+ symbolS *sym;
+
/* Early out for as-yet incomplete location information. */
if (loc->filenum == 0 || loc->line == 0)
return;
line = loc->line;
filenum = loc->filenum;
- dwarf2_push_line (loc);
if (linkrelax)
{
char name[120];
/* Use a non-fake name for the line number location,
so that it can be referred to by relocations. */
sprintf (name, ".Loc.%u.%u", line, filenum);
- dwarf2_flush_pending_lines (symbol_new (name, now_seg, ofs, frag_now));
+ sym = symbol_new (name, now_seg, ofs, frag_now);
}
else
- dwarf2_flush_pending_lines (symbol_temp_new (now_seg, ofs, frag_now));
+ sym = symbol_temp_new (now_seg, ofs, frag_now);
+ dwarf2_gen_line_info_1 (sym, loc);
}
/* Returns the current source information. If .file directives have
dwarf2_consume_line_info ();
}
+/* Move all previously-emitted line entries for the current position by
+ DELTA bytes. This function cannot be used to move the same entries
+ twice. */
+
+void
+dwarf2_move_insn (int delta)
+{
+ struct line_subseg *lss;
+ struct line_entry *e;
+ valueT now;
+
+ if (delta == 0)
+ return;
+
+ lss = get_line_subseg (now_seg, now_subseg, FALSE);
+ if (!lss)
+ return;
+
+ now = frag_now_fix ();
+ while ((e = *lss->pmove_tail))
+ {
+ if (S_GET_VALUE (e->label) == now)
+ S_SET_VALUE (e->label, now + delta);
+ lss->pmove_tail = &e->next;
+ }
+}
+
/* Called after the current line information has been either used with
dwarf2_gen_line_info or saved with a machine instruction for later use.
This resets the state of the line number information to reflect that
void
dwarf2_consume_line_info (void)
{
- /* If the consumer has stashed the current location away for later use,
- assume that any earlier location information should be associated
- with ".". */
- dwarf2_flush_pending_lines (NULL);
-
/* Unless we generate DWARF2 debugging information for each
assembler line, we only emit one line symbol for one LOC. */
dwarf2_loc_directive_seen = FALSE;
loc.flags |= DWARF2_FLAG_BASIC_BLOCK;
- dwarf2_push_line (&loc);
- dwarf2_flush_pending_lines (label);
+ dwarf2_gen_line_info_1 (label, &loc);
dwarf2_consume_line_info ();
}
/* If we see two .loc directives in a row, force the first one to be
output now. */
if (dwarf2_loc_directive_seen)
- dwarf2_push_line (¤t);
+ dwarf2_emit_insn (0);
filenum = get_absolute_expression ();
SKIP_WHITESPACE ();
exp.X_op = O_symbol;
exp.X_add_symbol = to_sym;
exp.X_add_number = 0;
- emit_expr_fix (&exp, sizeof_address, frag, p);
+ emit_expr_fix (&exp, sizeof_address, frag, p, TC_PARSE_CONS_RETURN_NONE);
p += sizeof_address;
}
else
{
*p++ = DW_LNS_fixed_advance_pc;
- emit_expr_fix (pexp, 2, frag, p);
+ emit_expr_fix (pexp, 2, frag, p, TC_PARSE_CONS_RETURN_NONE);
p += 2;
}
symbolS *end_sym;
subseg_set (sec, 0);
- start_sym = symbol_temp_new_now ();
- end_sym = symbol_temp_make ();
+#if 1
+ if (flag_dwarf_sections)
+ {
+ /* If we are going to put the start and end symbols in different
+ sections, then we need real symbols, not just fake, local ones. */
+ frag_now_fix ();
+ start_sym = symbol_make (".Ldebug_line_start");
+ end_sym = symbol_make (".Ldebug_line_end");
+ symbol_set_value_now (start_sym);
+ }
+ else
+#endif
+ {
+ start_sym = symbol_temp_new_now ();
+ end_sym = symbol_temp_make ();
+ }
/* Total length of the information. */
exp->X_op = O_subtract;
out_debug_line (segT line_seg)
{
expressionS exp;
- symbolS *prologue_end;
+ symbolS *prologue_start, *prologue_end;
symbolS *line_end;
struct line_seg *s;
int sizeof_offset;
out_two (DWARF2_LINE_VERSION);
/* Length of the prologue following this length. */
+ prologue_start = symbol_temp_make ();
prologue_end = symbol_temp_make ();
+ exp.X_op = O_subtract;
exp.X_add_symbol = prologue_end;
- exp.X_add_number = - (4 + 2 + 4);
+ exp.X_op_symbol = prologue_start;
+ exp.X_add_number = 0;
emit_expr (&exp, sizeof_offset);
+ symbol_set_value_now (prologue_start);
/* Parameters of the state machine. */
out_byte (DWARF2_LINE_MIN_INSN_LENGTH);
void
dwarf2_init (void)
{
- all_segs_hash = hash_new ();
last_seg_ptr = &all_segs;
}