1

在尝试使用 objdump 生成汇编代码(与源代码混合)时,

gcc -g -c test.c ;
objdump -S -M intel test.o > out.asm

我收到以下错误。

BFD: Dwarf Error: mangled line number section.

生成的输出程序集不与源代码混合。有人可以澄清这意味着什么吗?有没有什么办法解决这一问题 ?

4

2 回答 2

2

“objdump -S -M”显然期待 .o 文件中有一个“.debug_abbrev section”部分,而“gcc -g”显然没有写它:

我认为您对此无能为力(您已经在使用“-g”来包含调试符号)。我认为忽略它是完全安全的。

有问题的包是“binutils”。这是完整的代码:

http://opensource.apple.com/source/binutils/binutils-20/src/bfd/dwarf2.c

/* In DWARF version 2, the description of the debugging information is
   stored in a separate .debug_abbrev section.  Before we read any
   dies from a section we read in all abbreviations and install them
   in a hash table.  */

static struct abbrev_info**
read_abbrevs (abfd, offset)
     bfd * abfd;
     unsigned int offset;
{
  struct abbrev_info **abbrevs;
  char *abbrev_ptr;
  struct abbrev_info *cur_abbrev;
  unsigned int abbrev_number, bytes_read, abbrev_name;
  unsigned int abbrev_form, hash_number;
  struct dwarf2_debug *stash;

  stash = elf_tdata(abfd)->dwarf2_find_line_info;

  if (! stash->dwarf_abbrev_buffer)
    {
      asection *msec;

      msec = bfd_get_section_by_name (abfd, ".debug_abbrev");
      if (! msec)
    {
      (*_bfd_error_handler) (_("Dwarf Error: Can't find .debug_abbrev section."));
      bfd_set_error (bfd_error_bad_value);
      return 0;
    }
于 2012-11-28T20:40:58.607 回答
2

此问题通常显示 .debug_line 部分中由链接器 (ld) 编码问题引起的重定位表问题 - 内存副本重叠。工具链需要一个错误修复和重建。

它不会影响程序的加载和运行,但是这个问题会导致由于地址/符号不匹配而无法调试。这是一个示例,代码在 0x0038ca82 处被破坏(在错误的链接器情况下)。

0038ca80 00 = op_code = DW_LNS_extended_op
0038ca81 05 = op length = 5 bytes
0038ca82 02 = extended_op_code = DW_LNE_set_address
0038ca83 nn nn nn nn = 4-byte address

在有问题的 ELF 链接中,扩展操作码(32 未定义)

0038ca82 32 = extended_op_code = Unknown -> mangled line number section

问题 ld 导致 ELF(损坏的行号部分):

0038ca60  62 6c 69 63 2e 68 00 01  00 00 68 65 61 70 5f 6d  |blic.h....heap_m|
0038ca70  67 72 5f 70 75 62 6c 69  63 2e 68 00 02 00 00 00  |gr_public.h.....|
0038ca80  00 05 32 00 40 18 02 94  32 00 40 00 01 01 00 05  |..2.@...2.@.....|
0038ca90  02 94 32 00 40 00 01 01  00 05 02 94 32 00 40 00  |..2.@.......2.@.|
0038caa0  01 01 00 05 32 00 40 15  02 b0 32 00 40 00 01 01  |....2.@...2.@...|
0038cab0  00 05 02 b0 32 00 40 00  01 01 00 05 02 b0 32 00  |....2.@.......2.|
0038cac0  40 00 01 01 00 05 02 c0  32 00 40 94 00 05 40 17  |@.......2.@...@.|

正常 ld 导致 ELF:

0038ca60  62 6c 69 63 2e 68 00 01  00 00 68 65 61 70 5f 6d  |blic.h....heap_m|
0038ca70  67 72 5f 70 75 62 6c 69  63 2e 68 00 02 00 00 00  |gr_public.h.....|
0038ca80  00 05 02 80 32 00 40 38  00 05 02 80 32 00 40 18  |....2.@8....2.@.|
0038ca90  00 05 02 90 32 00 40 1a  00 05 02 94 32 00 40 00  |....2.@.....2.@.|
0038caa0  01 01 00 05 02 a0 32 00  40 49 00 05 02 a0 32 00  |......2.@I....2.|
0038cab0  40 15 00 05 02 ac 32 00  40 15 00 05 02 b0 32 00  |@.....2.@.....2.|
0038cac0  40 00 01 01 00 05 02 c0  32 00 40 94 00 05 02 c0  |@.......2.@.....|
于 2017-05-23T00:32:53.340 回答