title: Determine inlined function address in dwarf
body: <p>I have a virtual address (instruction pointer) of the function, obtained from <a href="https://www.gnu.org/software/libc/manual/html_node/Backtraces.html" rel="nofollow noreferrer">backtrace</a> call. I need to figure out the debug information about it. </p>
  
  <p>For example, I need the information about <code>attach_backtraces</code> function. </p>
  
  <pre><code>nm -a Backtrace.so | grep attach_backtraces
  000000000002cdfe t _ZN2xsL17attach_backtracesENS_3RefE
  </code></pre>
  
  <p>The offset <code>0x2cdfe</code> can be determined by substracting from PC (IP) the .so loaded address. And it matches the output from <code>nm</code>. </p>
  
  <p>The following infrormation I get from <code>readelf -w Backtrace.so</code></p>
  
  <pre><code>&lt;3&gt;&lt;3a14f&gt;: Abbrev Number: 0
  &lt;2&gt;&lt;3a150&gt;: Abbrev Number: 161 (DW_TAG_subprogram)
    &lt;3a152&gt;   DW_AT_name        : (indirect string, offset: 0x21bf5): attach_backtraces
    &lt;3a156&gt;   DW_AT_decl_file   : 22
    &lt;3a157&gt;   DW_AT_decl_line   : 201
    &lt;3a158&gt;   DW_AT_decl_column : 13
    &lt;3a159&gt;   DW_AT_declaration : 1
    &lt;3a159&gt;   DW_AT_sibling     : &lt;0x3a163&gt;
  &lt;3&gt;&lt;3a15d&gt;: Abbrev Number: 1 (DW_TAG_formal_parameter)
    &lt;3a15e&gt;   DW_AT_type        : &lt;0x36aac&gt;
  &lt;3&gt;&lt;3a162&gt;: Abbrev Number: 0
  </code></pre>
  
  <p>Why it's offset is <code>0x21bf5</code> and not the expected <code>0x2cdfe</code>? What a piece do I miss?  My next step would be query DWARF-info for the function at the offset <code>0x2cdfe</code> to get debug info.</p>
  
  <p>PS. I'm gathering full backtrace, where symbol name, file and line should be presented. What C/C++ library are better to use to parse/get information from <code>DWARF</code> ?</p>
  
  <p>Addon:</p>
  
  <p>No, there are no other <code>attach_backtraces</code> in the <code>readelf -w</code> output. I have found that</p>
  
  <p>DW_AT_sibling     : &lt;0x3a163></p>
  
  <p>and it's definition:</p>
  
  <p>No, there are no other <code>attach_backtraces</code> in the <code>readelf -w</code> output. I have found that</p>
  
  <pre><code>DW_AT_sibling     : &lt;0x3a163&gt;
  </code></pre>
  
  <p>and it's definition:</p>
  
  <pre><code>&lt;1&gt;&lt;3f9f5&gt;: Abbrev Number: 27 (DW_TAG_subprogram)
     &lt;3f9f6&gt;   DW_AT_specification: &lt;0x3a163&gt;
     &lt;3f9fa&gt;   DW_AT_low_pc      : 0x2c59e
     &lt;3fa02&gt;   DW_AT_high_pc     : 0x860
     &lt;3fa0a&gt;   DW_AT_frame_base  : 1 byte block: 9c      (DW_OP_call_frame_cfa)
     &lt;3fa0c&gt;   DW_AT_GNU_all_tail_call_sites: 1
     &lt;3fa0c&gt;   DW_AT_sibling     : &lt;0x3fb21&gt;
  </code></pre>
  
  <p>0x2c59e (<code>DW_AT_low_pc</code>) -  0x860 (<code>DW_AT_high_pc</code>) = 0x2cdfe (the target function address). </p>
  
  <p>Is this calculation correct?</p>