aboutsummaryrefslogtreecommitdiff
path: root/binutils/dwarf.c
diff options
context:
space:
mode:
authorAlexandre Oliva <aoliva@redhat.com>2017-07-21 10:09:06 +0100
committerNick Clifton <nickc@redhat.com>2017-07-21 10:13:18 +0100
commitba8826a82a29a19b78c18ce4f44fe313de279af7 (patch)
tree2389430a2bbbff988df9fbba2fbb79f40345d735 /binutils/dwarf.c
parent47826cdbec2548cd1d25acf4cfaf908ae88f3325 (diff)
downloadgdb-ba8826a82a29a19b78c18ce4f44fe313de279af7.zip
gdb-ba8826a82a29a19b78c18ce4f44fe313de279af7.tar.gz
gdb-ba8826a82a29a19b78c18ce4f44fe313de279af7.tar.bz2
This patch introduces support for specifing views in .loc directives, so that the compiler can use the assembler to generate line number information and have the assembler determine view numbers to multiple views at the same program counter.
binutils* dwarf.c (struct State_Machine_Registers): Add view field. (reset_state_machine): Reset view. (process_extended_line_op): Reset view when appropriate. (display_debug_lines_raw): Increment or reset view when appropriate. Print nonzero views. Support print view resets, disabled by default. (display_debug_lines_decoded): Likewise. Disambiguate op_code tests, enabling printing of end_sequence. * testsuite/binutils-all/dw2-1.W: Add nonzero views. * testsuite/binutils-all/dw2-3.W: Likewise. * testsuite/binutils-all/dw2-3gabi.W: Likewise. * testsuite/binutils-all/dw5.W: Add end sequence lines. * testsuite/binutils-all/i386/compressed-1a.d: Add nonzero views. * testsuite/binutils-all/libdw2-compressedgabi.out: Likewise. * testsuite/binutils-all/objdump.W: Likewise. * testsuite/binutils-all/objdump.WL: Add end sequence lines. * testsuite/binutils-all/x86-64/compressed-1a.d: Add nonzero views. gas * doc/as.texinfo (.loc): Document view support. * dwarf2dbg.c (unused): Check offset of next in struct line_entry. (current): Initialize view. (force_reset_view, view_assert_failed): New variables. (reverse_line_entry_list): New function. (set_or_check_view): Likewise. (dwarf2_gen_line_info_1): Call it. (dwarf2_where): Set view to NULL. (dwarf2_emit_insn): Return early when called before first file. (dwarf2_directive_loc): Add view support. Emit insn immediately when view option is given. (process_entries): Avoid set_address to reset view when a known address change already implies the view reset. (dwarf2dbg_final_check): New function. * dwarf2dbg.h (struct dwarf2_line_info): Add view. (dwarf2dbg_final_check): Declare. * read.c (s_leb128): Parse expression as deferred. * testsuite/gas/all/gas.exp: Run sleb128-9. * testsuite/gas/all/sleb128-9.d: New. * testsuite/gas/all/sleb128-9.l: New. * testsuite/gas/all/sleb128-9.s: New. * testsuite/gas/elf/dwarf2-1.d: Add nonzero views. * testsuite/gas/elf/dwarf2-2.d: Likewise. * testsuite/gas/elf/dwarf2-5.d: New. * testsuite/gas/elf/dwarf2-5.s: New. * testsuite/gas/elf/dwarf2-6.d: New. * testsuite/gas/elf/dwarf2-6.s: New. * testsuite/gas/elf/dwarf2-7.d: New. * testsuite/gas/elf/dwarf2-7.s: New. * testsuite/gas/elf/dwarf2-8.d: New. * testsuite/gas/elf/dwarf2-8.l: New. * testsuite/gas/elf/dwarf2-8.s: New. * testsuite/gas/elf/dwarf2-9.d: New. * testsuite/gas/elf/dwarf2-9.l: New. * testsuite/gas/elf/dwarf2-9.s: New. * testsuite/gas/elf/dwarf2-10.d: New. * testsuite/gas/elf/dwarf2-10.l: New. * testsuite/gas/elf/dwarf2-10.s: New. * testsuite/gas/elf/dwarf2-11.d: New. * testsuite/gas/elf/dwarf2-11.s: New. * testsuite/gas/elf/dwarf2-12.d: New. * testsuite/gas/elf/dwarf2-12.s: New. * testsuite/gas/elf/dwarf2-13.d: New. * testsuite/gas/elf/dwarf2-13.s: New. * testsuite/gas/elf/dwarf2-14.d: New. * testsuite/gas/elf/dwarf2-14.s: New. * testsuite/gas/elf/dwarf2-15.d: New. * testsuite/gas/elf/dwarf2-15.s: New. * testsuite/gas/elf/dwarf2-16.d: New. * testsuite/gas/elf/dwarf2-16.s: New. * testsuite/gas/elf/dwarf2-17.d: New. * testsuite/gas/elf/dwarf2-17.s: New. * testsuite/gas/elf/dwarf2-18.d: New. * testsuite/gas/elf/dwarf2-18.s: New. * testsuite/gas/elf/elf.exp: Run dwarf2-5..18 tests. * testsuite/gas/i386/dw2-compress-1.d: Add nonzero views. * testsuite/gas/i386/dw2-compressed-1.d: Likewise. * testsuite/gas/i386/ilp32/lns/lns-duplicate.d: Likewise. * testsuite/gas/lns/lns-big-delta.d: Likewise. * testsuite/gas/lns/lns-duplicate.d: Likewise. * testsuite/gas/mips/loc-swap-2.d: Likewise. * testsuite/gas/mips/loc-swap-3.d: Likewise. * testsuite/gas/mips/loc-swap.d: Likewise. * testsuite/gas/mips/micromips@loc-swap-2.d: Likewise. * testsuite/gas/mips/micromips@loc-swap.d: Likewise. * testsuite/gas/mips/mips16@loc-swap-2.d: Likewise. * testsuite/gas/mips/mips16@loc-swap.d: Likewise. * testsuite/gas/mips/mips16e@loc-swap.d: Likewise. * write.c (write_object_file): Check pending view asserts. (cvt_frag_to_fill): Complain about undefined leb128 operand.
Diffstat (limited to 'binutils/dwarf.c')
-rw-r--r--binutils/dwarf.c166
1 files changed, 123 insertions, 43 deletions
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index f6fa157..ab6446d 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -426,6 +426,7 @@ read_uleb128 (unsigned char * data,
typedef struct State_Machine_Registers
{
dwarf_vma address;
+ unsigned int view;
unsigned int file;
unsigned int line;
unsigned int column;
@@ -433,8 +434,8 @@ typedef struct State_Machine_Registers
int basic_block;
unsigned char op_index;
unsigned char end_sequence;
-/* This variable hold the number of the last entry seen
- in the File Table. */
+ /* This variable hold the number of the last entry seen
+ in the File Table. */
unsigned int last_file_entry;
} SMR;
@@ -444,6 +445,7 @@ static void
reset_state_machine (int is_stmt)
{
state_machine_regs.address = 0;
+ state_machine_regs.view = 0;
state_machine_regs.op_index = 0;
state_machine_regs.file = 1;
state_machine_regs.line = 1;
@@ -502,6 +504,7 @@ process_extended_line_op (unsigned char * data,
SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
state_machine_regs.address = adr;
+ state_machine_regs.view = 0;
state_machine_regs.op_index = 0;
break;
@@ -3190,6 +3193,7 @@ display_debug_lines_raw (struct dwarf_section *section,
unsigned char *end, void *file)
{
unsigned char *start = section->start;
+ int verbose_view = 0;
printf (_("Raw dump of debug contents of section %s:\n\n"),
section->name);
@@ -3381,30 +3385,45 @@ display_debug_lines_raw (struct dwarf_section *section,
{
uladv *= linfo.li_min_insn_length;
state_machine_regs.address += uladv;
+ if (uladv)
+ state_machine_regs.view = 0;
printf (_(" Special opcode %d: "
- "advance Address by %s to 0x%s"),
+ "advance Address by %s to 0x%s%s"),
op_code, dwarf_vmatoa ("u", uladv),
- dwarf_vmatoa ("x", state_machine_regs.address));
+ dwarf_vmatoa ("x", state_machine_regs.address),
+ verbose_view && uladv
+ ? _(" (reset view)") : "");
}
else
{
- state_machine_regs.address
- += ((state_machine_regs.op_index + uladv)
+ unsigned addrdelta
+ = ((state_machine_regs.op_index + uladv)
/ linfo.li_max_ops_per_insn)
* linfo.li_min_insn_length;
+
+ state_machine_regs.address += addrdelta;
state_machine_regs.op_index
= (state_machine_regs.op_index + uladv)
% linfo.li_max_ops_per_insn;
+ if (addrdelta)
+ state_machine_regs.view = 0;
printf (_(" Special opcode %d: "
- "advance Address by %s to 0x%s[%d]"),
+ "advance Address by %s to 0x%s[%d]%s"),
op_code, dwarf_vmatoa ("u", uladv),
dwarf_vmatoa ("x", state_machine_regs.address),
- state_machine_regs.op_index);
+ state_machine_regs.op_index,
+ verbose_view && addrdelta
+ ? _(" (reset view)") : "");
}
adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
state_machine_regs.line += adv;
- printf (_(" and Line by %s to %d\n"),
+ printf (_(" and Line by %s to %d"),
dwarf_vmatoa ("d", adv), state_machine_regs.line);
+ if (verbose_view || state_machine_regs.view)
+ printf (_(" (view %u)\n"), state_machine_regs.view);
+ else
+ putchar ('\n');
+ state_machine_regs.view++;
}
else switch (op_code)
{
@@ -3413,7 +3432,12 @@ display_debug_lines_raw (struct dwarf_section *section,
break;
case DW_LNS_copy:
- printf (_(" Copy\n"));
+ printf (_(" Copy"));
+ if (verbose_view || state_machine_regs.view)
+ printf (_(" (view %u)\n"), state_machine_regs.view);
+ else
+ putchar ('\n');
+ state_machine_regs.view++;
break;
case DW_LNS_advance_pc:
@@ -3423,23 +3447,33 @@ display_debug_lines_raw (struct dwarf_section *section,
{
uladv *= linfo.li_min_insn_length;
state_machine_regs.address += uladv;
- printf (_(" Advance PC by %s to 0x%s\n"),
+ if (uladv)
+ state_machine_regs.view = 0;
+ printf (_(" Advance PC by %s to 0x%s%s\n"),
dwarf_vmatoa ("u", uladv),
- dwarf_vmatoa ("x", state_machine_regs.address));
+ dwarf_vmatoa ("x", state_machine_regs.address),
+ verbose_view && uladv
+ ? _(" (reset view)") : "");
}
else
{
- state_machine_regs.address
- += ((state_machine_regs.op_index + uladv)
- / linfo.li_max_ops_per_insn)
+ unsigned addrdelta
+ = ((state_machine_regs.op_index + uladv)
+ / linfo.li_max_ops_per_insn)
* linfo.li_min_insn_length;
+ state_machine_regs.address
+ += addrdelta;
state_machine_regs.op_index
= (state_machine_regs.op_index + uladv)
% linfo.li_max_ops_per_insn;
- printf (_(" Advance PC by %s to 0x%s[%d]\n"),
+ if (addrdelta)
+ state_machine_regs.view = 0;
+ printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
dwarf_vmatoa ("u", uladv),
dwarf_vmatoa ("x", state_machine_regs.address),
- state_machine_regs.op_index);
+ state_machine_regs.op_index,
+ verbose_view && addrdelta
+ ? _(" (reset view)") : "");
}
break;
@@ -3486,23 +3520,33 @@ display_debug_lines_raw (struct dwarf_section *section,
{
uladv *= linfo.li_min_insn_length;
state_machine_regs.address += uladv;
- printf (_(" Advance PC by constant %s to 0x%s\n"),
+ if (uladv)
+ state_machine_regs.view = 0;
+ printf (_(" Advance PC by constant %s to 0x%s%s\n"),
dwarf_vmatoa ("u", uladv),
- dwarf_vmatoa ("x", state_machine_regs.address));
+ dwarf_vmatoa ("x", state_machine_regs.address),
+ verbose_view && uladv
+ ? _(" (reset view)") : "");
}
else
{
- state_machine_regs.address
- += ((state_machine_regs.op_index + uladv)
- / linfo.li_max_ops_per_insn)
+ unsigned addrdelta
+ = ((state_machine_regs.op_index + uladv)
+ / linfo.li_max_ops_per_insn)
* linfo.li_min_insn_length;
+ state_machine_regs.address
+ += addrdelta;
state_machine_regs.op_index
= (state_machine_regs.op_index + uladv)
% linfo.li_max_ops_per_insn;
- printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
+ if (addrdelta)
+ state_machine_regs.view = 0;
+ printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
dwarf_vmatoa ("u", uladv),
dwarf_vmatoa ("x", state_machine_regs.address),
- state_machine_regs.op_index);
+ state_machine_regs.op_index,
+ verbose_view && addrdelta
+ ? _(" (reset view)") : "");
}
break;
@@ -3513,6 +3557,7 @@ display_debug_lines_raw (struct dwarf_section *section,
printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
dwarf_vmatoa ("u", uladv),
dwarf_vmatoa ("x", state_machine_regs.address));
+ /* Do NOT reset view. */
break;
case DW_LNS_set_prologue_end:
@@ -3925,7 +3970,7 @@ display_debug_lines_decoded (struct dwarf_section *section,
printf ("%s:\n", file_table[0].name);
}
- printf (_("File name Line number Starting address\n"));
+ printf (_("File name Line number Starting address View\n"));
saved_linfo = linfo;
}
@@ -3933,12 +3978,14 @@ display_debug_lines_decoded (struct dwarf_section *section,
while (data < end_of_sequence)
{
unsigned char op_code;
+ int xop;
int adv;
unsigned long int uladv;
unsigned int bytes_read;
int is_special_opcode = 0;
op_code = *data++;
+ xop = op_code;
if (op_code >= linfo.li_opcode_base)
{
@@ -3948,21 +3995,28 @@ display_debug_lines_decoded (struct dwarf_section *section,
{
uladv *= linfo.li_min_insn_length;
state_machine_regs.address += uladv;
+ if (uladv)
+ state_machine_regs.view = 0;
}
else
{
- state_machine_regs.address
- += ((state_machine_regs.op_index + uladv)
- / linfo.li_max_ops_per_insn)
+ unsigned addrdelta
+ = ((state_machine_regs.op_index + uladv)
+ / linfo.li_max_ops_per_insn)
* linfo.li_min_insn_length;
+ state_machine_regs.address
+ += addrdelta;
state_machine_regs.op_index
= (state_machine_regs.op_index + uladv)
% linfo.li_max_ops_per_insn;
+ if (addrdelta)
+ state_machine_regs.view = 0;
}
adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
state_machine_regs.line += adv;
is_special_opcode = 1;
+ /* Increment view after printing this row. */
}
else switch (op_code)
{
@@ -3983,11 +4037,13 @@ display_debug_lines_decoded (struct dwarf_section *section,
}
ext_op_code_len += bytes_read;
ext_op_code = *op_code_data++;
+ xop = ext_op_code;
+ xop = -xop;
switch (ext_op_code)
{
case DW_LNE_end_sequence:
- reset_state_machine (linfo.li_default_is_stmt);
+ /* Reset stuff after printing this row. */
break;
case DW_LNE_set_address:
SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
@@ -3995,6 +4051,7 @@ display_debug_lines_decoded (struct dwarf_section *section,
ext_op_code_len - bytes_read - 1,
end);
state_machine_regs.op_index = 0;
+ state_machine_regs.view = 0;
break;
case DW_LNE_define_file:
{
@@ -4037,6 +4094,7 @@ display_debug_lines_decoded (struct dwarf_section *section,
break;
}
case DW_LNS_copy:
+ /* Increment view after printing this row. */
break;
case DW_LNS_advance_pc:
@@ -4046,16 +4104,22 @@ display_debug_lines_decoded (struct dwarf_section *section,
{
uladv *= linfo.li_min_insn_length;
state_machine_regs.address += uladv;
+ if (uladv)
+ state_machine_regs.view = 0;
}
else
{
- state_machine_regs.address
- += ((state_machine_regs.op_index + uladv)
- / linfo.li_max_ops_per_insn)
+ unsigned addrdelta
+ = ((state_machine_regs.op_index + uladv)
+ / linfo.li_max_ops_per_insn)
* linfo.li_min_insn_length;
+ state_machine_regs.address
+ += addrdelta;
state_machine_regs.op_index
= (state_machine_regs.op_index + uladv)
% linfo.li_max_ops_per_insn;
+ if (addrdelta)
+ state_machine_regs.view = 0;
}
break;
@@ -4124,16 +4188,22 @@ display_debug_lines_decoded (struct dwarf_section *section,
{
uladv *= linfo.li_min_insn_length;
state_machine_regs.address += uladv;
+ if (uladv)
+ state_machine_regs.view = 0;
}
else
{
- state_machine_regs.address
- += ((state_machine_regs.op_index + uladv)
- / linfo.li_max_ops_per_insn)
+ unsigned addrdelta
+ = ((state_machine_regs.op_index + uladv)
+ / linfo.li_max_ops_per_insn)
* linfo.li_min_insn_length;
+ state_machine_regs.address
+ += addrdelta;
state_machine_regs.op_index
= (state_machine_regs.op_index + uladv)
% linfo.li_max_ops_per_insn;
+ if (addrdelta)
+ state_machine_regs.view = 0;
}
break;
@@ -4141,6 +4211,7 @@ display_debug_lines_decoded (struct dwarf_section *section,
SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
state_machine_regs.address += uladv;
state_machine_regs.op_index = 0;
+ /* Do NOT reset view. */
break;
case DW_LNS_set_prologue_end:
@@ -4172,8 +4243,8 @@ display_debug_lines_decoded (struct dwarf_section *section,
/* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
to the DWARF address/line matrix. */
- if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
- || (op_code == DW_LNS_copy))
+ if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
+ || (xop == DW_LNS_copy))
{
const unsigned int MAX_FILENAME_LENGTH = 35;
char *fileName;
@@ -4214,11 +4285,11 @@ display_debug_lines_decoded (struct dwarf_section *section,
if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
{
if (linfo.li_max_ops_per_insn == 1)
- printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
+ printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
newFileName, state_machine_regs.line,
state_machine_regs.address);
else
- printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
+ printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
newFileName, state_machine_regs.line,
state_machine_regs.address,
state_machine_regs.op_index);
@@ -4226,18 +4297,27 @@ display_debug_lines_decoded (struct dwarf_section *section,
else
{
if (linfo.li_max_ops_per_insn == 1)
- printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
+ printf ("%s %11d %#18" DWARF_VMA_FMT "x",
newFileName, state_machine_regs.line,
state_machine_regs.address);
else
- printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
+ printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
newFileName, state_machine_regs.line,
state_machine_regs.address,
state_machine_regs.op_index);
}
- if (op_code == DW_LNE_end_sequence)
- printf ("\n");
+ if (state_machine_regs.view)
+ printf (" %6u\n", state_machine_regs.view);
+ else
+ putchar ('\n');
+ state_machine_regs.view++;
+
+ if (xop == -DW_LNE_end_sequence)
+ {
+ reset_state_machine (linfo.li_default_is_stmt);
+ putchar ('\n');
+ }
free (newFileName);
}