<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 26, 2013 at 4:19 PM, Manman Ren <span dir="ltr"><<a href="mailto:mren@apple.com" target="_blank">mren@apple.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div>
<div>On Feb 26, 2013, at 4:09 PM, Eric Christopher <<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>> wrote:</div><br><blockquote type="cite"><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Debug Info: for static member variables, add AT_MIPS_linkage_name to the<br>
definition DIE, to make old GDB happy.<br>
<br></blockquote><div><br></div><div>Again, is this for compatibility or for correctness?</div></div></div></div></blockquote></div>To me this is to fix a regression. Not sure whether that belongs to compatibility or correctness.<div>

<br></div></div></div></blockquote><div><br></div><div>Correctness is something that should be so because it's defined to be (or in this case "defined" by the compiler that it started in), compatibility is because another tool has a hard time dealing with the input, but it's not something we control directly.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div>
<blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


We have a regression for old GDB when Clang uses DW_TAG_member to declare<br>
static members inside a class, instead of DW_TAG_variable. This patch will fix<br>
this regression.<br><br></blockquote><div><br></div><div>So, did you check the other uses of AT_MIPS_linkage_name?</div></div></div></div></blockquote></div>Do you mean uses of AT_MIPS_linkage_name by the debuggers?<div>

<br></div></div></div></blockquote><div><br></div><div>Output of AT_MIPS_linkage_name by both clang and gcc.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div style="word-wrap:break-word"><div><div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=176143&r1=176142&r2=176143&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=176143&r1=176142&r2=176143&view=diff</a><br>




==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Tue Feb 26 18:02:32 2013<br>
@@ -1348,9 +1348,15 @@ void CompileUnit::createGlobalVariableDI<br>
     }<br>
     // Add linkage name.<br>
     StringRef LinkageName = GV.getLinkageName();<br>
-    if (!LinkageName.empty() && isGlobalVariable)<br>
+    if (!LinkageName.empty() && isGlobalVariable) {<br>
       addString(VariableDIE, dwarf::DW_AT_MIPS_linkage_name,<br>
                 getRealLinkageName(LinkageName));<br>
+      // To make old GDB happy, for static member variables, we add<br>
+      // AT_MIPS_linkage_name to the definition DIE as well.<br></blockquote><div><br></div><div>Can you explain this more? What's going on? What's the problem?</div></div></div></div></blockquote></div>I don't quite know how gdb works, but apparently we are getting errors when running gdb (GNU 6.3.50) with a simple testing case:</div>

<div><div>class MyClass {</div><div>public:</div><div>static MyClass* A;</div><div>MyClass() {</div><div>}</div><div>};</div><div>MyClass* MyClass::A = 0;</div></div></div></blockquote><div><br></div><div><br></div><div>

OK, this should be your testcase and you should be checking this for the debug information that you expect. Just create some IR, stick the C++ code in as a comment, and use llvm-dwarfdump to verify it.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div style="word-wrap:break-word"><div><div><br></div><div>clang++ test.cpp -O0 -g -c -o test3.o</div><div>with Apple's gdb, run "gdb test3.o"</div><div>Error: gdb does not handle things like classes defined inside functions correctly; debug info for 'test3.o' skipped</div>

<div><br></div><div>This testing case used to work when we use DW_TAG_variable inside a class for static members.</div><div>Adding this extra AT_MIPS_linkage_name to the definition DIE will make old GDB happy.</div><div>
It should not break other debugger.</div>
<div><br></div><div>CC' Jim.</div><div><br></div></div></div></blockquote><div><br></div><div>The difference comes down to whether or not we're emitting something merely for compatibility or if we're more correct to do so. In this case we'll call correct the output of gcc as far as AT_MIPS_linkage_name is concerned, if they're not currently emitting it for that code then stick it under the compatibility option. I've gone ahead and run g++ on the file and the current output of gcc is (sorry, llvm-dwarfdump doesn't support all of dwarf-4 yet so it's not that pretty):</div>

<div><br></div><div><div>Contents of the .debug_info section:</div><div><br></div><div>  Compilation Unit @ offset 0x0:</div><div>   Length:        0x5d (32-bit)</div><div>   Version:       4</div><div>   Abbrev Offset: 0x0</div>

<div>   Pointer Size:  8</div><div> <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)</div><div>    <c>   DW_AT_producer    : (indirect string, offset: 0x0): GNU C++ 4.8.0 20130219 (experimental) -mtune=generic -march=x86-64 -g     </div>

<div>    <10>   DW_AT_language    : 4        (C++)</div><div>    <11>   DW_AT_name        : (indirect string, offset: 0x81): foo.cpp </div><div>    <15>   DW_AT_comp_dir    : (indirect string, offset: 0x55): /usr/local/google/home/echristo/tmp     </div>

<div>    <19>   DW_AT_stmt_list   : 0x0      </div><div> <1><1d>: Abbrev Number: 2 (DW_TAG_class_type)</div><div>    <1e>   DW_AT_name        : (indirect string, offset: 0x79): MyClass </div><div>
    <22>   DW_AT_byte_size   : 1        </div>
<div>    <23>   DW_AT_decl_file   : 1        </div><div>    <24>   DW_AT_decl_line   : 1        </div><div>    <25>   DW_AT_sibling     : <0x46>   </div><div> <2><29>: Abbrev Number: 3 (DW_TAG_member)</div>

<div>    <2a>   DW_AT_name        : A        </div><div>    <2c>   DW_AT_decl_file   : 1        </div><div>    <2d>   DW_AT_decl_line   : 3        </div><div>    <2e>   DW_AT_type        : <0x46>   </div>

<div>    <32>   DW_AT_external    : 1        </div><div>    <32>   DW_AT_accessibility: 1       (public)</div><div>    <33>   DW_AT_declaration : 1        </div><div> <2><33>: Abbrev Number: 4 (DW_TAG_subprogram)</div>

<div>    <34>   DW_AT_external    : 1        </div><div>    <34>   DW_AT_name        : (indirect string, offset: 0x79): MyClass </div><div>    <38>   DW_AT_decl_file   : 1        </div><div>    <39>   DW_AT_decl_line   : 4        </div>

<div>    <3a>   DW_AT_accessibility: 1       (public)</div><div>    <3b>   DW_AT_declaration : 1        </div><div>    <3b>   DW_AT_object_pointer: <0x3f> </div><div> <3><3f>: Abbrev Number: 5 (DW_TAG_formal_parameter)</div>

<div>    <40>   DW_AT_type        : <0x46>   </div><div>    <44>   DW_AT_artificial  : 1        </div><div> <1><46>: Abbrev Number: 6 (DW_TAG_pointer_type)</div><div>    <47>   DW_AT_byte_size   : 8        </div>

<div>    <48>   DW_AT_type        : <0x1d>   </div><div> <1><4c>: Abbrev Number: 7 (DW_TAG_variable)</div><div>    <4d>   DW_AT_specification: <0x29>  </div><div>    <51>   DW_AT_decl_line   : 7        </div>

<div>    <52>   DW_AT_linkage_name: (indirect string, offset: 0x46): _ZN7MyClass1AE  </div><div>    <56>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0  (DW_OP_addr: 0)</div><div><br></div></div><div>
<br></div><div>which seems to have the linkage name on the TAG_variable die and nowhere else (for this testcase) which partially seems what you're doing (adding it to the TAG_variable).</div><div><br></div>
<div><div>0x0000000b: DW_TAG_compile_unit [1] *</div><div>0x0000000c:   DW_AT_producer [DW_FORM_strp]     ( .debug_str[0x00000000] = "clang version 3.3 (trunk 176146) (llvm/trunk 176143)")</div><div>0x00000010:   DW_AT_language [DW_FORM_data2]    (0x0004)</div>

<div>0x00000012:   DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000035] = "foo.cpp")</div><div>0x00000016:   DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)</div><div>0x0000001e:   DW_AT_stmt_list [DW_FORM_data4]   (0x00000000)</div>

<div>0x00000022:   DW_AT_comp_dir [DW_FORM_strp]     ( .debug_str[0x0000003d] = "/Users/echristo/tmp")</div><div><br></div><div>0x00000026:   DW_TAG_pointer_type [2]  </div><div>0x00000027:     DW_AT_type [DW_FORM_ref4]       (cu + 0x0030 => {0x00000030})</div>

<div><br></div><div>0x0000002b:   DW_TAG_pointer_type [2]  </div><div>0x0000002c:     DW_AT_type [DW_FORM_ref4]       (cu + 0x0030 => {0x00000030})</div><div><br></div><div>0x00000030:   DW_TAG_class_type [3] *</div><div>

0x00000031:     DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000053] = "MyClass")</div><div>0x00000035:     DW_AT_byte_size [DW_FORM_data1] (0x01)</div><div>0x00000036:     DW_AT_decl_file [DW_FORM_data1] (0x01)</div>

<div>0x00000037:     DW_AT_decl_line [DW_FORM_data1] (0x01)</div><div><br></div><div>0x00000038:     DW_TAG_member [4]  </div><div>0x00000039:       DW_AT_name [DW_FORM_strp]     ( .debug_str[0x00000051] = "A")</div>

<div>0x0000003d:       DW_AT_type [DW_FORM_ref4]     (cu + 0x0026 => {0x00000026})</div><div>0x00000041:       DW_AT_decl_file [DW_FORM_data1]       (0x01)</div><div>0x00000042:       DW_AT_decl_line [DW_FORM_data1]       (0x03)</div>

<div>0x00000043:       DW_AT_external [DW_FORM_flag] (0x01)</div><div>0x00000044:       DW_AT_declaration [DW_FORM_flag]      (0x01)</div><div>0x00000045:       DW_AT_accessibility [DW_FORM_data1]   (0x01)</div><div>0x00000046:       DW_AT_MIPS_linkage_name [DW_FORM_strp]        ( .debug_str[0x0000005b] = "_ZN7MyClass1AE")</div>

<div><br></div><div>0x0000004a:     DW_TAG_subprogram [5] *</div><div>0x0000004b:       DW_AT_name [DW_FORM_strp]     ( .debug_str[0x00000053] = "MyClass")</div><div>0x0000004f:       DW_AT_decl_file [DW_FORM_data1]       (0x01)</div>

<div>0x00000050:       DW_AT_decl_line [DW_FORM_data1]       (0x04)</div><div>0x00000051:       DW_AT_declaration [DW_FORM_flag]      (0x01)</div><div>0x00000052:       DW_AT_external [DW_FORM_flag] (0x01)</div><div>0x00000053:       DW_AT_accessibility [DW_FORM_data1]   (0x01)</div>

<div><br></div><div>0x00000054:       DW_TAG_formal_parameter [6]  </div><div>0x00000055:         DW_AT_type [DW_FORM_ref4]   (cu + 0x002b => {0x0000002b})</div><div>0x00000059:         DW_AT_artificial [DW_FORM_flag]     (0x01)</div>

<div><br></div><div>0x0000005a:       NULL</div><div><br></div><div>0x0000005b:     NULL</div><div><br></div><div>0x0000005c:   DW_TAG_variable [7]  </div><div>0x0000005d:     DW_AT_specification [DW_FORM_ref4]      (cu + 0x0038 => {0x00000038})</div>

<div>0x00000061:     DW_AT_location [DW_FORM_block1] (<0x09> 03 78 02 00 00 00 00 00 00 )</div><div><div>0x0000006b:     DW_AT_MIPS_linkage_name [DW_FORM_strp]  ( .debug_str[0x0000005b] = "_ZN7MyClass1AE")</div>

</div><div><br></div><div><br></div></div><div>It doesn't seem to be necessary on the member that we're adding it to above (according to gcc-4.8), but I don't know what the old gdb on darwin systems needs for TAG_member. It should, theoretically, be unnecessary since there's an AT_specification, but if it's a bug in the darwin gdb we should put it under a flag.</div>
<div><br></div><div style>Make sense?</div><div><br></div><div>-eric</div></div></div>
</div>