/* dwarf2dbg.c - DWARF2 debug support
- Copyright (C) 1999 Hewlett-Packard Co
+ Copyright (C) 1999, 2000 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.
+ 02111-1307, USA. */
- Logical line numbers can be controlled by the compiler via the
+/* Logical line numbers can be controlled by the compiler via the
following two directives:
.file FILENO "file.c"
#include "dwarf2dbg.h"
#include "subsegs.h"
-#include <elf/dwarf2.h>
-
-#define BYTES_PER_ADDRESS (BFD_ARCH_SIZE / 8)
+#include "elf/dwarf2.h"
/* Since we can't generate the prolog until the body is complete, we
use three different subsegments for .debug_line: one holding the
is not made available by the GCC front-end. */
#define DWARF2_LINE_DEFAULT_IS_STMT 1
-/* Given a special op, return the line skip amount: */
+/* Given a special op, return the line skip amount. */
#define SPECIAL_LINE(op) \
(((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE)
DWARF2_LINE_MIN_INSN_LENGTH. */
#define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
-/* The maximum address skip amont that can be encoded with a special op: */
+/* The maximum address skip amount that can be encoded with a special op. */
#define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
#define INITIAL_STATE \
- /* initialize as per DWARF2.0 standard: */ \
+ /* Initialize as per DWARF2.0 standard. */ \
0, /* address */ \
1, /* file */ \
1, /* line */ \
/* state machine state as per DWARF2 manual: */
struct dwarf2_sm
{
- bfd_vma addr;
+ addressT addr;
unsigned int filenum;
unsigned int line;
unsigned int column;
unsigned int
any_dwarf2_directives : 1; /* did we emit any DWARF2 line debug directives? */
+ fragS * frag; /* frag that "addr" is relative to */
segT text_seg; /* text segment "addr" is relative to */
subsegT text_subseg;
segT line_seg; /* ".debug_line" segment */
{
INITIAL_STATE
},
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ NULL,
+ { NULL, 0, 0, 0, 0 },
+ 0,
+ {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ }
};
+
+/* Function prototypes: */
+static void out_uleb128 PARAMS ((addressT));
+static void out_sleb128 PARAMS ((offsetT));
+static void gen_addr_line PARAMS ((int, addressT));
+static void reset_state_machine PARAMS ((void));
+static void out_set_addr PARAMS ((addressT));
+static void out_end_sequence PARAMS ((void));
+static int get_filenum PARAMS ((int, char *));
+static void gen_dir_list PARAMS ((void));
+static void gen_file_list PARAMS ((void));
+static void print_stats PARAMS ((unsigned long));
+
+
#define out_byte(byte) FRAG_APPEND_1_CHAR(byte)
#define out_opcode(opc) (out_byte ((opc)), ++ls.opcode_hist[(opc) & 0xff])
/* Output an unsigned "little-endian base 128" number. */
static void
-out_uleb128 (bfd_vma value)
+out_uleb128 (value)
+ addressT value;
{
unsigned char byte, more = 0x80;
/* Output a signed "little-endian base 128" number. */
static void
-out_sleb128 (bfd_signed_vma value)
+out_sleb128 (value)
+ offsetT value;
{
unsigned char byte, more = 0x80;
Note that the line skip is signed, whereas the address skip is
unsigned. */
static void
-gen_addr_line (int line_delta, bfd_vma addr_delta)
+gen_addr_line (line_delta, addr_delta)
+ int line_delta;
+ addressT addr_delta;
{
unsigned int tmp, opcode;
}
static void
-reset_state_machine (void)
+reset_state_machine ()
{
static const struct dwarf2_sm initial_state = { INITIAL_STATE };
/* Set an absolute address (may results in a relocation entry): */
static void
-out_set_addr (bfd_vma addr)
+out_set_addr (addr)
+ addressT addr;
{
subsegT saved_subseg;
segT saved_seg;
expressionS expr;
symbolS *sym;
+ int bytes_per_address;
saved_seg = now_seg;
saved_subseg = now_subseg;
subseg_set (saved_seg, saved_subseg);
+#ifdef BFD_ASSEMBLER
+ bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
+#else
+ /* FIXME. */
+ bytes_per_address = 4;
+#endif
+
out_opcode (DW_LNS_extended_op);
- out_uleb128 (BYTES_PER_ADDRESS + 1);
+ out_uleb128 (bytes_per_address + 1);
out_opcode (DW_LNE_set_address);
expr.X_op = O_symbol;
expr.X_add_symbol = sym;
expr.X_add_number = 0;
- emit_expr (&expr, BYTES_PER_ADDRESS);
+ emit_expr (&expr, bytes_per_address);
}
/* Emit DW_LNS_end_sequence and reset state machine. Does not
preserve the current segment/sub-segment! */
static void
-out_end_sequence (void)
+out_end_sequence ()
{
- bfd_vma addr, delta;
+ addressT addr, delta;
+ fragS *text_frag;
if (ls.text_seg)
{
#else
addr = frag_now_fix ();
#endif
+ text_frag = frag_now;
subseg_set (ls.line_seg, DL_BODY);
- if (addr < ls.sm.addr)
+ if (text_frag != ls.frag)
{
out_set_addr (addr);
ls.sm.addr = addr;
+ ls.frag = text_frag;
}
else
{
- delta = addr - ls.sm.addr;
+ delta = (addr - ls.sm.addr) / DWARF2_LINE_MIN_INSN_LENGTH;
if (delta > 0)
- gen_addr_line (0, delta / DWARF2_LINE_MIN_INSN_LENGTH);
+ {
+ /* Advance address without updating the line-debug
+ matrix---the end_sequence entry is used only to tell
+ the debugger the end of the sequence.*/
+ out_opcode (DW_LNS_advance_pc);
+ out_uleb128 (delta);
+ }
}
}
else
/* Look up a filenumber either by filename or by filenumber. If both
a filenumber and a filename are specified, lookup by filename takes
precedence. If the filename cannot be found, it is added to the
- filetable the filenumber for the new entry is returned. */
+ filetable and the filenumber for the new entry is returned. */
static int
-get_filenum (int filenum, char *file)
+get_filenum (filenum, file)
+ int filenum;
+ char *file;
{
int i, last = filenum - 1;
char char0 = file[0];
- if ((unsigned) last >= ls.num_filenames)
+ /* If filenum is out of range of the filename table, then try using the
+ table entry returned from the previous call. */
+ if (last >= ls.num_filenames || last < 0)
last = ls.last_filename;
- /* do a quick check against the previously used filename: */
+ /* Do a quick check against the specified or previously used filenum. */
if (ls.num_filenames > 0 && ls.file[last].name[0] == char0
&& strcmp (ls.file[last].name + 1, file + 1) == 0)
return last + 1;
}
ls.file[ls.num_filenames].dir = 0;
ls.file[ls.num_filenames].name = file;
+ ls.last_filename = ls.num_filenames;
return ++ls.num_filenames;
}
+/* Emit an entry in the line number table if the address or line has changed.
+ ADDR is relative to the current frag in the text section. */
+
void
-dwarf2_gen_line_info (bfd_vma addr, struct dwarf2_line_info *l)
+dwarf2_gen_line_info (addr, l)
+ addressT addr;
+ struct dwarf2_line_info *l;
{
unsigned int filenum = l->filenum;
unsigned int any_output = 0;
subsegT saved_subseg;
segT saved_seg;
- char *frag;
+ fragS *saved_frag;
if (flag_debug)
- fprintf (stderr, "line: addr %llx file `%s' line %u col %u flags %lx\n",
- (long long) addr, l->filename, l->line, l->column, l->flags);
+ fprintf (stderr, "line: addr %lx file `%s' line %u col %u flags %x\n",
+ (unsigned long) addr, l->filename, l->line, l->column, l->flags);
if (filenum > 0 && !l->filename)
{
- if (filenum >= ls.num_filenames)
+ if (filenum >= (unsigned int) ls.num_filenames)
{
as_warn ("Encountered bad file number in line number debug info!");
return;
else
return; /* no filename, no filnum => no play */
+ /* Must save these before the subseg_new call, as that call will change
+ them. */
+ saved_seg = now_seg;
+ saved_subseg = now_subseg;
+ saved_frag = frag_now;
+
if (!ls.line_seg)
{
+#ifdef BFD_ASSEMBLER
+ symbolS *secsym;
+#endif
+
ls.line_seg = subseg_new (".debug_line", 0);
+
+#ifdef BFD_ASSEMBLER
bfd_set_section_flags (stdoutput, ls.line_seg, SEC_READONLY);
/* We're going to need this symbol. */
- (void) section_symbol (ls.line_seg);
+ secsym = symbol_find (".debug_line");
+ if (secsym != NULL)
+ symbol_set_bfdsym (secsym, ls.line_seg->symbol);
+ else
+ symbol_table_insert (section_symbol (ls.line_seg));
+#endif
}
- saved_seg = now_seg;
- saved_subseg = now_subseg;
subseg_set (ls.line_seg, DL_BODY);
if (ls.text_seg != saved_seg || ls.text_subseg != saved_subseg)
ls.text_subseg = saved_subseg;
out_set_addr (addr);
ls.sm.addr = addr;
+ ls.frag = saved_frag;
}
if (ls.sm.filenum != filenum)
if (ls.sm.line != l->line)
{
any_output = 1;
- if (addr < ls.sm.addr)
+ if (saved_frag != ls.frag)
{
- if (!ls.sm.empty_sequence)
- {
- out_end_sequence ();
- ls.sm.empty_sequence = 1;
- }
+ /* If a new frag got allocated (for whatever reason), then
+ deal with it by generating a reference symbol. Note: no
+ end_sequence needs to be generated because the address did
+ not really decrease (only the reference point changed). */
out_set_addr (addr);
ls.sm.addr = addr;
+ ls.frag = saved_frag;
}
gen_addr_line (l->line - ls.sm.line,
(addr - ls.sm.addr) / DWARF2_LINE_MIN_INSN_LENGTH);
}
static void
-gen_dir_list (void)
+gen_dir_list ()
{
char *str, *slash, *dir_list, *dp, *cp;
int i, j, num_dirs;
{
if (strcmp (str, dp) == 0)
{
- ls.file[i].dir = j;
+ ls.file[i].dir = j + 1;
break;
}
dp += strlen (dp);
}
static void
-gen_file_list (void)
+gen_file_list ()
{
size_t size;
char *cp;
out_byte (0); /* terminate filename list */
}
-void
-print_stats (unsigned long total_size)
+static void
+print_stats (total_size)
+ unsigned long total_size;
{
static const char *opc_name[] =
{
"set_column", "negate_stmt", "set_basic_block", "const_add_pc",
"fixed_advance_pc"
};
- int i, j;
+ size_t i;
+ int j;
fprintf (stderr, "Average size: %g bytes/line\n",
total_size / (double) ls.num_line_entries);
j = SPECIAL_LINE (i);
if (j == DWARF2_LINE_BASE)
fprintf (stderr, "\n%4u: ",
- DWARF2_LINE_MIN_INSN_LENGTH*SPECIAL_ADDR (i));
+ ((unsigned int)
+ DWARF2_LINE_MIN_INSN_LENGTH * SPECIAL_ADDR (i)));
fprintf (stderr, " %2u", ls.opcode_hist[i]);
}
fprintf (stderr, "\n");
}
void
-dwarf2_finish (void)
+dwarf2_finish ()
{
- bfd_vma addr, body_size, total_size, prolog_size;
- subsegT saved_subseg, line_prolog;
+ addressT body_size, total_size, prolog_size;
+ subsegT saved_subseg;
segT saved_seg;
char *cp;
}
void
-dwarf2_directive_file (int dummy)
+dwarf2_directive_file (dummy)
+ int dummy ATTRIBUTE_UNUSED;
{
int len;
+ /* Continue to accept a bare string and pass it off. */
+ SKIP_WHITESPACE ();
+ if (*input_line_pointer == '"')
+ {
+ s_app_file (0);
+ return;
+ }
+
ls.any_dwarf2_directives = 1;
if (debug_type == DEBUG_NONE)
}
void
-dwarf2_directive_loc (int dummy)
+dwarf2_directive_loc (dummy)
+ int dummy ATTRIBUTE_UNUSED;
{
ls.any_dwarf2_directives = 1;
}
void
-dwarf2_where (struct dwarf2_line_info *line)
+dwarf2_where (line)
+ struct dwarf2_line_info *line;
{
if (ls.any_dwarf2_directives)
*line = ls.current;
else
{
- char *filename;
-
as_where (&line->filename, &line->line);
line->filenum = 0;
line->column = 0;