<div dir="ltr"><div>shortly say, the section list of target was used when it isn't available in <span style="font-size:13px">ObjectFileMachO::ParseSymtab</span>.<br></div><div><br></div><div>look these:</div><div><br></div><div><div style="font-size:13px">#0 ObjectFileMachO::ParseSymtab() at source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:1744</div><div style="font-size:13px">#1 ObjectFileMachO::GetSymtab() at source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:1039</div><div style="font-size:13px">#2 SymbolFileSymtab::CalculateAbilities() at source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp:96</div><div style="font-size:13px">#3 lldb_private::SymbolFile::GetAbilities() at include/lldb/Symbol/SymbolFile.h:96</div><div style="font-size:13px">#4 lldb_private::SymbolFile::FindPlugin(lldb_private::ObjectFile*) at source/Symbol/SymbolFile.cpp:55</div><div style="font-size:13px">#5 lldb_private::SymbolVendor::AddSymbolFileRepresentation(std::__1::shared_ptr<lldb_private::ObjectFile> const&) at source/Symbol/SymbolVendor.cpp:92</div><div style="font-size:13px">#6 SymbolVendorMacOSX::CreateInstance(...) at source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp:291</div><div style="font-size:13px">#7 lldb_private::SymbolVendor::FindPlugin(...) at source/Symbol/SymbolVendor.cpp:42</div><div style="font-size:13px">#8<span style="white-space:pre-wrap"> </span>lldb_private::Module::GetSymbolVendor(bool, lldb_private::Stream*) at source/Core/Module.cpp:958</div><div style="font-size:13px">#9<span style="white-space:pre-wrap"> </span>PlatformDarwin::LocateExecutableScriptingResources(...) at source/Plugins/Platform/MacOSX/PlatformDarwin.cpp:72</div><div style="font-size:13px">#10<span style="white-space:pre-wrap"> </span>lldb_private::Module::LoadScriptingResourceInTarget(...) at source/Core/Module.cpp:1441</div><div style="font-size:13px">#11<span style="white-space:pre-wrap"> </span>LoadScriptingResourceForModule(...) at source/Target/Target.cpp:1006</div><div style="font-size:13px">#12<span style="white-space:pre-wrap"> </span>lldb_private::Target::ModuleAdded(...) at source/Target/Target.cpp:1146</div><div style="font-size:13px">#13<span style="white-space:pre-wrap"> </span>non-virtual thunk to lldb_private::Target::ModuleAdded(...) at source/Target/Target.cpp:1148</div><div style="font-size:13px">#14<span style="white-space:pre-wrap"> </span>lldb_private::ModuleList::AppendImpl(...) at source/Core/ModuleList.cpp:87</div><div style="font-size:13px">#15<span style="white-space:pre-wrap"> </span>lldb_private::ModuleList::Append(...) at source/Core/ModuleList.cpp:94</div><div style="font-size:13px">#16<span style="white-space:pre-wrap"> </span>lldb_private::Target::SetExecutableModule(...) at source/Target/Target.cpp:1049</div><div style="font-size:13px">#17<span style="white-space:pre-wrap"> </span>DynamicLoaderMacOSXDYLD::UpdateImageInfosHeaderAndLoadCommands(...) at source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp:1349</div><div style="font-size:13px">#18<span style="white-space:pre-wrap"> </span>DynamicLoaderMacOSXDYLD::AddModulesUsingImageInfosAddress(...) at source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp:805</div><div style="font-size:13px"><br></div><div style="font-size:13px">void Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)<br>{<br> Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));<br> <font color="#ff0000">ClearModules(false);</font><br> <br> if (executable_sp.get())<br> {<br> Timer scoped_timer (<div> __PRETTY_FUNCTION__,<div> "Target::SetExecutableModule (executable = '%s')",<br> executable_sp->GetFileSpec().GetPath().c_str()</div><div> );</div><div><br></div><div> // The first image is our exectuable file</div><div> // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.<br> <font color="#ff0000">m_images.Append(executable_sp);</font> </div><div><br></div><div> ...</div><div> }</div><div>}</div></div></div><div style="font-size:13px"><br></div><div style="font-size:13px"><div>size_t ObjectFileMachO::ParseSymtab () </div><div>{</div><div> ...</div><div><br></div><div> <font color="#ff0000">SectionSP</font><font color="#ff0000"> linkedit_section_sp(section_list->FindSectionByName(GetSegmentNameLINKEDIT()));</font></div><div> // Reading mach file from memory in a process or core file...</div><div> if (linkedit_section_sp)</div><div> {</div><div> <font color="#ff0000"> const</font><font color="#ff0000"> addr_t linkedit_load_addr = linkedit_section_sp->GetLoadBaseAddress(&target);</font></div><div> </div><div> ....</div><div> </div><div> PlatformSP platform_sp (target.GetPlatform());</div><div> if (platform_sp && platform_sp->IsHost() && use_lldb_cache)</div><div> {</div><div> data_was_read = true;</div><div> nlist_data.SetData((void *)symoff_addr, nlist_data_byte_size, eByteOrderLittle);</div><div> strtab_data.SetData((void *)strtab_addr, strtab_data_byte_size, eByteOrderLittle);</div><div> if (function_starts_load_command.cmd)</div><div> {</div><div> <font color="#ff0000">const</font><font color="#ff0000"> addr_t func_start_addr = linkedit_load_addr + function_starts_load_command.dataoff - linkedit_file_offset;</font></div><div> function_starts_data.SetData ((void *)func_start_addr, function_starts_load_command.datasize, eByteOrderLittle);</div><div> }</div><div> }</div><div><br></div><div> ...</div><div>}</div></div><div style="font-size:13px"><br></div><div>void DynamicLoaderMacOSXDYLD::UpdateImageInfosHeaderAndLoadCommands(DYLDImageInfo::collection &image_infos, uint32_t infos_count, bool update_executable)<br>{<br> uint32_t exe_idx = UINT32_MAX;<br> // Read any UUID values that we can get<br><br> for (uint32_t i = 0; i < infos_count; i++)<br> {<br> if (!image_infos[i].UUIDValid())<br> {<br> DataExtractor data; // Load command data<br><br> if (!ReadMachHeader (image_infos[i].address, &image_infos[i].header, &data))<br> continue;<br><br> ParseLoadCommands (data, image_infos[i], NULL);<div style="font-size:13px"><br> if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE)<br> exe_idx = i;<br> }<br> }<br><br> Target &target = m_process->GetTarget();<div><br> if (exe_idx < image_infos.size())<br> {<br> const bool can_create = true;<br> ModuleSP exe_module_sp (FindTargetModuleForDYLDImageInfo (image_infos[exe_idx], can_create, NULL));<br><br><br> if (exe_module_sp)<br> {<br> <font color="#ff0000">UpdateImageLoadAddress (exe_module_sp.get(), image_infos[exe_idx]);</font><div><br> if (exe_module_sp.get() != target.GetExecutableModulePointer())<br> {<br> // Don't load dependent images since we are in dyld where we will know<br> // and find out about all images that are loaded. Also when setting the<br> // executable module, it will clear the targets module list, and if we<br> // have an in memory dyld module, it will get removed from the list<br> // so we will need to add it back after setting the executable module,<br> // so we first try and see if we already have a weak pointer to the<br> // dyld module, make it into a shared pointer, then add the executable,<br> // then re-add it back to make sure it is always in the list.<br><br> ModuleSP dyld_module_sp(m_dyld_module_wp.lock());<div><br> const bool get_dependent_images = false;<br> <font color="#ff0000">m_process->GetTarget().SetExecutableModule (exe_module_sp, get_dependent_images);</font></div><div><br> if (dyld_module_sp)<br> target.GetImages().AppendIfNeeded (dyld_module_sp);<br> }<br> }<br> }<br>}</div></div></div></div><div style="font-size:13px"> </div><div style="font-size:13px">There're two related problem:</div><div style="font-size:13px">1. linkedit_load_addr must be invalid, because Target::ClearsModules empty the section list of target</div><div style="font-size:13px">2. <span style="font-size:small">DynamicLoaderMacOSXDYLD::UpdateImageLoadAddress happened before Target::SetExecutableModule.</span></div><div style="font-size:13px"><span style="font-size:small"><br></span></div><div>The first problem won't fix even if we fix the second problem by moving UpdateImageLoadAddress below. </div></div><div>Maybe these code need some refactory. </div><div style="font-size:13px"><br></div><div style="font-size:13px"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 20, 2015 at 8:20 AM, Greg Clayton <span dir="ltr"><<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Jan 18, 2015, at 6:38 PM, Lei Shi <<a href="mailto:cosmo.shih@gmail.com">cosmo.shih@gmail.com</a>> wrote:<br>
><br>
> Hi, everyone<br>
><br>
> The Target::SetExecutableModule invoke Target::ClearModules at the very beginning. Target::ClearModules clears the m_section_load_histroy which maintains the section list of the target. the following symbol parsing phase needs section list of the executable. Empty section list will leads to Misinterpreting various symbol data including Function Starts.<br>
<br>
</span>How are you setting up your symbols prior to setting the target executable? Or is the dynamic loader plug-in doing this? Either way the target's main executable should be set, then the sections should be setup.<br>
<br>
How are you getting this to happen?<br>
<span class=""><br>
><br>
> I've tried to fix the issue by avoiding clear the m_section_history in Target::SetExecutableModule. It's work, but I not show weather it's a proper way to fix the issue.<br>
<br>
</span>This isn't the right way to do things. Let me know how you are getting Target::SetExecutableModule() to be called and I might be able to tell you more.<br>
<span class=""><br>
><br>
> Hope someone can review the fix.<br>
><br>
> Best,<br>
> Lei Shi<br>
</span>> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>
<br>
</blockquote></div><br></div></div>