<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">LLDB’s module support (implemented here: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_svn_llvm-2Dproject_lldb_trunk_source_Expression_ClangModulesDeclVendor.cpp&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=qJ7PzNcXqcUiCKOoFs9S4BDpb3TOf64WitZDB3JoLdM&s=WSvUUkZckMbgeN5UAaJKYWcqxxQzarzUBnC0_xfDRZ4&e=" class="">http://llvm.org/svn/llvm-project/lldb/trunk/source/Expression/ClangModulesDeclVendor.cpp</a>) sets up its own CompilerInstance and then loads modules into it.<div class=""><br class=""></div><div class="">The way we import macros from modules into expressions is by textual inclusion – we iterate across the macros like this:</div><div class=""><br class=""></div><div class="">–</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="color: rgb(49, 89, 93); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">m_compiler_instance</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">-></span>getPreprocessor<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">().</span>getExternalSource<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">())</span></div><div style="color: rgb(79, 129, 135); margin: 0px; line-height: normal;" class=""><span style="color: rgb(0, 0, 0);" class="">{</span></div><div style="margin: 0px; line-height: normal;" class="">  <span style="color: rgb(79, 129, 135);" class="">m_compiler_instance</span><span style="color: rgb(0, 0, 0);" class="">-></span><font color="#31595d" class="">getPreprocessor</font><span style="color: rgb(0, 0, 0);" class="">().</span><font color="#31595d" class="">getExternalSource</font><span style="color: rgb(0, 0, 0);" class="">()-></span><font color="#31595d" class="">ReadDefinedMacros</font><span style="color: rgb(0, 0, 0);" class="">();</span></div><div style="color: rgb(79, 129, 135); margin: 0px; line-height: normal;" class=""><span style="color: rgb(0, 0, 0);" class="">}</span></div><div style="color: rgb(79, 129, 135);" class=""><br class=""></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (</span>clang<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">::</span>Preprocessor<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">::</span>macro_iterator<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> mi = </span>m_compiler_instance<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">-></span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">getPreprocessor</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">().</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">macro_begin</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(),</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">                                         me = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">m_compiler_instance</span>-><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">getPreprocessor</span>().<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">macro_end</span>();</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">     mi != me; ++mi)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="color: rgb(0, 0, 0);" class="">{</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(79, 129, 135);" class="">  </span><span style="color: rgb(0, 132, 0);" class="">// ...</span></div><div class=""><span style="font-family: Menlo; font-size: 11px;" class="">  </span><span style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);" class="">clang</span><span style="font-family: Menlo; font-size: 11px;" class="">::</span><span style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);" class="">MacroInfo</span><span style="font-family: Menlo; font-size: 11px;" class=""> *macro_info = </span><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">nullptr</span><span style="font-family: Menlo; font-size: 11px;" class="">;</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">        <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> (<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">clang</span>::<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ModuleMacro</span> *module_macro : <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">m_compiler_instance</span>-><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">getPreprocessor</span>().<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">getLeafModuleMacros</span>(ii))</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">    <span style="color: rgb(0, 132, 0);" class="">// pick the macro_info from the module we care most about; that might be NULL</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">        <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> (macro_info)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">    <span style="color: rgb(0, 132, 0);" class="">// make a string from the macro</span></div><div class=""><span style="font-family: Menlo; font-size: 11px;" class="">  }</span></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">}</span></font></div><div class="">–</div><div class=""><br class=""></div><div class="">What Im noticing is that a macro (say, “MAX”) doesn’t appear in the <span style="font-family: Menlo; font-size: 11px; color: rgb(49, 89, 93);" class="">macro_begin</span><span style="font-family: Menlo; font-size: 11px;" class="">()</span> list at all.  Only later, after I’ve done a name lookup for “MAX" (on the assumption that it might be a variable, see <span style="color: rgb(79, 129, 135); font-family: Menlo; font-size: 11px;" class="">ClangModulesDeclVendorImpl</span><span style="font-family: Menlo; font-size: 11px;" class="">::FindDecls</span><span style="font-family: Menlo; font-size: 11px;" class="">()</span>), does it appear in the list.</div><div class=""><br class=""></div><div class="">Is there something else I need to tickle here, or is this a bug in the API?</div><div class=""><br class=""></div><div class="">Sean</div></body></html>