title: How to determine local static variable in non-member function using dwarf
body: <p>Im trying to use dwarf to compare two c++ files, but I am running into issues when I get to local variables in non-member functions. Consider the following code - </p>
  
  <pre><code>int f(){
      [static] int j=0;
      return j;
  }
  </code></pre>
  
  <p>If I compile it <em>without</em> the <code>static</code> modifier I get the following dwarf info - </p>
  
  <pre><code> &lt;1&gt;&lt;eb&gt;: Abbrev Number: 13 (DW_TAG_subprogram)
      &lt;ec&gt;   DW_AT_external    : 1
      &lt;ed&gt;   DW_AT_name        : f
      &lt;ef&gt;   DW_AT_decl_file   : 1
      &lt;f0&gt;   DW_AT_decl_line   : 15
      &lt;f1&gt;   DW_AT_MIPS_linkage_name: (indirect string, offset: 0x22): _Z1fv
      &lt;f5&gt;   DW_AT_type        : &lt;0xa8&gt;
      &lt;f9&gt;   DW_AT_low_pc      : 0x0
      &lt;101&gt;   DW_AT_high_pc     : 0x10
      &lt;109&gt;   DW_AT_frame_base  : 0x0     (location list)
      &lt;10d&gt;   DW_AT_sibling     : &lt;0x130&gt;
   &lt;2&gt;&lt;111&gt;: Abbrev Number: 14 (DW_TAG_lexical_block)
      &lt;112&gt;   DW_AT_low_pc      : 0x4
      &lt;11a&gt;   DW_AT_high_pc     : 0xe
   &lt;3&gt;&lt;122&gt;: Abbrev Number: 15 (DW_TAG_variable)
      &lt;123&gt;   DW_AT_name        : j
      &lt;125&gt;   DW_AT_decl_file   : 1
      &lt;126&gt;   DW_AT_decl_line   : 16
      &lt;127&gt;   DW_AT_type        : &lt;0xa8&gt;
      &lt;12b&gt;   DW_AT_location    : 2 byte block: 91 6c     (DW_OP_fbreg: -20)
  </code></pre>
  
  <p>but if I compile it <em>with</em> the <code>static</code> modifier I get - </p>
  
  <pre><code> &lt;1&gt;&lt;eb&gt;: Abbrev Number: 13 (DW_TAG_subprogram)
      &lt;ec&gt;   DW_AT_external    : 1
      &lt;ed&gt;   DW_AT_name        : f
      &lt;ef&gt;   DW_AT_decl_file   : 1
      &lt;f0&gt;   DW_AT_decl_line   : 22
      &lt;f1&gt;   DW_AT_MIPS_linkage_name: (indirect string, offset: 0x24): _Z1fv
      &lt;f5&gt;   DW_AT_type        : &lt;0xa8&gt;
      &lt;f9&gt;   DW_AT_low_pc      : 0x0
      &lt;101&gt;   DW_AT_high_pc     : 0xc
      &lt;109&gt;   DW_AT_frame_base  : 0x0     (location list)
      &lt;10d&gt;   DW_AT_sibling     : &lt;0x137&gt;
   &lt;2&gt;&lt;111&gt;: Abbrev Number: 14 (DW_TAG_lexical_block)
      &lt;112&gt;   DW_AT_low_pc      : 0x4
      &lt;11a&gt;   DW_AT_high_pc     : 0xa
   &lt;3&gt;&lt;122&gt;: Abbrev Number: 15 (DW_TAG_variable)
      &lt;123&gt;   DW_AT_name        : j
      &lt;125&gt;   DW_AT_decl_file   : 1
      &lt;126&gt;   DW_AT_decl_line   : 23
      &lt;127&gt;   DW_AT_type        : &lt;0xa8&gt;
      &lt;12b&gt;   DW_AT_location    : 9 byte block: 3 20 0 0 0 0 0 0 0        (DW_OP_addr: 20)
  </code></pre>
  
  <p>Now as far as I can tell, there is only one real difference between these file - the byte block size on the <code>DW_AT_location</code> attributes for variable j is different (this is why the <code>DW_AT_sibling</code> attributes in function f's tag are different, so I don't count that). I presume this somehow implies static, but I dont know how.</p>