首页 > 解决方案 > DW_FORM_strp 值的位置

问题描述

我试图了解DW_FORM_strp属性值实际存储在 ELF 文件中的位置(可在此处找到:https ://filebin.net/77bb8359o0ibqu67 )。

我找到了部分.debug_info.debug_abbrev.debug_str。然后,我解析了 中的编译单元标题.debug_info,并找到了编译单元的缩写表条目并迭代了它的缩写。第一个缩写是DW_AT_producerwith form DW_FORM_strp。我想知道的是如何找到这个偏移量的位置?

从我读到的 DWARF4 规范中:Each debugging information entry begins with a code that represents an entry in a separate abbreviations table. This code is followed directly by a series of attribute values.我对此的理解是,如果我回到编译单元头,跳过它的内容,我应该最终到达编译单元。它以 ULEB128(我对其进行解析)开始,之后应该出现属性值。但是,在我的 ELF 文件中,这些字节都是 0。我已经readelf -w在文件上运行,我看到以下内容:

Contents of the .debug_info section:

  Compilation Unit @ offset 0x0:
   Length:        0xf6 (32-bit)
   Version:       4
   Abbrev Offset: 0x0
   Pointer Size:  8
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <c>   DW_AT_producer    : (indirect string, offset: 0x62): GNU C11 7.5.0 -mtune=generic -march=x86-64 -g -O0 -fstack-protector-strong
    <10>   DW_AT_language    : 12   (ANSI C99)
    <11>   DW_AT_name        : (indirect string, offset: 0xd9): elf.c
    <15>   DW_AT_comp_dir    : (indirect string, offset: 0xad): /home//struct_analyzer
    <19>   DW_AT_low_pc      : 0x0
    <21>   DW_AT_high_pc     : 0x39
    <29>   DW_AT_stmt_list   : 0x0

这告诉我字符串表的偏移量是0x62,并且名称是偏移量0xd9。但是,在解析ULEB128任何 DIE 的第一部分后,接下来的 4 个字节(第一个属性的值)是0x00 00 00 00. 这我不明白?

编辑雇佣俄罗斯人:

是的,我知道偏移0x62点进入该.debug_str部分。但是,我想知道我在哪里找到这个0x62值?

每个 DIE 都以 ULEB128 值(缩写表条目代码)开头,然后是属性。相应缩写表条目中的第一个属性是 aDW_AT_producer形式DW_FORM_strp。这意味着 DIE 中接下来的 4 个字节应该是.debug_str. 但是,接下来的 4 个字节是0x00 00 00 00,而不是0x62 00 00 00我正在寻找的值。0x62驻留在0x5c8ELF 文件的偏移量处,而 DIE 的属性从偏移量开始,0x85据我所知(请参阅所附图像以获取 hexdump(小端序) - 突出显示的字节是 ULEB128,以下字节是我期望的中的偏移量.debug_str)。 在此处输入图像描述

编辑 2

我已经能够确定 form 的实际属性值DW_FORM_strp位于.rela.debug_infoELF 文件的部分中,因此我将不得不阅读更多相关信息。

标签: elfdwarf

解决方案


为此问题发布的特定 ELF 文件也有一个rela.debug_info部分,其中包含该.debug_info部分的重定位条目。从 ELF 规范:

 .relaNAME
              This section holds relocation information as described below.
              If the file has a loadable segment that includes relocation,
              the section's attributes will include the SHF_ALLOC bit.  Oth‐
              erwise, the bit will be off.  By convention, "NAME" is sup‐
              plied by the section to which the relocations apply.  Thus a
              relocation section for .text normally would have the name
              .rela.text.  This section is of type SHT_RELA.

此部分中的每个重定位条目(Elf64_Rela在此特定情况下为类型)都应迭代,并且每个条目的值应与该.debug_info部分中的相应值相加。


推荐阅读