But then why does it work on Mac?<br><br>And why is this workaround needed at all, when you can just have it check the basename in the first place (e.g. in FindExternalVisibleDecls)?<div><br></div><div>I guess a higher level, more general question - Why is name lookup so complicated? Clang already knows everything, why does LLDB need to modify the default behavior of Clang's name lookup? I know LLDB can insert its own decls into the AST, but it seems like we can just get avoid returning those to the user, and still use clang for everything else.</div><br><div class="gmail_quote">On Tue Jan 13 2015 at 2:54:15 AM Abid, Hafiz <<a href="mailto:Hafiz_Abid@mentor.com">Hafiz_Abid@mentor.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-GB" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">In SymbolFileDWARF::FindFunctions (), there is code that runs only for Linux and BSD. That finds the function in global namespace.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Abid<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:lldb-dev-bounces@cs.uiuc.edu" target="_blank">lldb-dev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:lldb-dev-bounces@cs.uiuc.edu" target="_blank">lldb-dev-bounces@cs.uiuc.edu</a>]
<b>On Behalf Of </b>Zachary Turner<br>
<b>Sent:</b> 12 January 2015 19:51<br>
<b>To:</b> <a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank">lldb-dev@cs.uiuc.edu</a>; Jim Ingham<br>
<b>Subject:</b> [lldb-dev] Problem with ClangExpressionDeclMap<u></u><u></u></span></p>
</div>
</div></div></div></div><div lang="EN-GB" link="blue" vlink="purple"><div><div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Was looking into <a href="http://llvm.org/bugs/show_bug.cgi?id=22177" target="_blank">
this bug</a> on Windows, and I traced it down to an issue in ClangExpressionDeclMap. ClangExpressionDeclMap::FindExternalVisibleDecls has a piece of code that looks like this:<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> if (namespace_decl && module_sp)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> const bool include_symbols = false;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> module_sp->FindFunctions(name,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> &namespace_decl,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> eFunctionNameTypeBase,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> include_symbols,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> include_inlines,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> append,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> sc_list);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> }<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> else if (target && !namespace_decl)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> const bool include_symbols = true;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> // TODO Fix FindFunctions so that it doesn't return<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> // instance methods for eFunctionNameTypeBase.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> target->GetImages().FindFunctions(name,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> eFunctionNameTypeFull,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> include_symbols,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> include_inlines,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> append,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> sc_list);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> }<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">So it's only searching for the base name if the function is in a namespace, and if it's at global scope it's searching for the full name.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I'm not sure why this works on other platforms, but on Windows it doesn't work because if I have this code:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">int foo(int x)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">{<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">}<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">then the full name of this function is ?foo@@YAHH@Z<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">If I change eFunctionNameTypeFull to eFunctionNameTypeBase then everything works, and "p foo" finds the function. So I've got a couple of questions:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">1) Why all this complicated logic? I would expect that if I type "p foo" then it would just print everything whose base name is foo and is visible from within the current scope? Am I underthinking this? There's special cases for namespaces,
global scope, instance methods, variables, functions, and it looks for things in certain orders, etc. Is there any reason why it can't just find everything with a basename of foo visible within the current stack frame?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">2) I'm not sure what this comment means: <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> // TODO Fix FindFunctions so that it doesn't return<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> // instance methods for eFunctionNameTypeBase.<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal">I changed it to eFunctionNameTypeBase and it fixes the original bug on Windows. I inserted a class with an instance method named foo() and also a global method named foo(), and running "p foo" doesn't find the instance method, only the
global method. Is it possible this was somehow fixed, and it was forgotten to change this back to eFunctionNameTypeBase?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">3) Why does this work on other platforms? full names are mangled on other platforms too, so I don't know how "p foo" doesn't run into this same issue on other platforms. Any ideas?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Currently the best fix I have for this bug on Windows is to change eFunctionNameTypeFull to eFunctionNameTypeBase. but I want to get some thoughts on that worrisome comment before I go forward with that patch.<u></u><u></u></p>
</div>
</div></div></div></blockquote></div>