<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Menlo;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap: break-word;-webkit-nbsp-mode: space;line-break:after-white-space">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">A contiguous range certainly can be described with a low_pc/high_pc pair. if LLDB is looking for DW_AT_ranges but not low/high pairs, it risks missing information
 about a CU.  I'm not an LLDB dev but I can't imagine anyone thinking that it would be a problem to fix that.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> sgraenitz@apple.com [mailto:sgraenitz@apple.com]
<br>
<b>Sent:</b> Tuesday, September 18, 2018 1:35 PM<br>
<b>To:</b> Robinson, Paul<br>
<b>Cc:</b> LLDB Dev<br>
<b>Subject:</b> Re: [lldb-dev] Extract compile unit infos from OSO entries for LTO objects<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hi Paul, thanks for the clarification. Yes, that was my fault. The LTO object DWARF has multiple top-level compile unit tags and only the first one has a DW_AT_ranges attribute.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">One more thought here: In DWARFDebugInfo::GetCompileUnitAranges() LLDB currently tries to read .debug_aranges and if it can’t, it falls back to reading DW_AT_ranges from the compile unit tags. Would you have  objections from constructing
 that range from DW_AT_low_pc and DW_AT_high_pc here, if they exist? IIUC code for a single compile unit is not guaranteed to be compact, but in practice it usually is right?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Stefan<o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<div>
<p class="MsoNormal">On 18. Sep 2018, at 15:01, <a href="mailto:paul.robinson@sony.com">
paul.robinson@sony.com</a> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Are the nested DW_TAG_compile_unit tags in my LTO object missing their DW_AT_ranges or is that expected?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Compile units should never be nested. That's invalid DWARF.  A unit is the root of the DIE tree described by each unit header.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Whatever is producing one unit contained inside another is doing something wrong.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<div>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span class="apple-converted-space"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> </span></span><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">lldb-dev
 [<a href="mailto:lldb-dev-bounces@lists.llvm.org">mailto:lldb-dev-bounces@lists.llvm.org</a>]<span class="apple-converted-space"> </span><b>On Behalf Of<span class="apple-converted-space"> </span></b>Stefan Gränitz via lldb-dev<br>
<b>Sent:</b><span class="apple-converted-space"> </span>Friday, September 14, 2018 11:57 AM<br>
<b>To:</b><span class="apple-converted-space"> </span>LLDB Dev<br>
<b>Subject:</b><span class="apple-converted-space"> </span>Re: [lldb-dev] Extract compile unit infos from OSO entries for LTO objects</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">I made some progress on this and next to many small issues, I found that DWARFDebugAranges::FindAddress() returns 0 as the CU offset for my file addresses and wonder if this is expected?<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">DWARFDebugAranges::FindAddress() is supposed to read from .debug_aranges section or DW_AT_ranges attributes right? When dumping with llvm-dwarfdump, it looks like regular objects have exactly one DW_TAG_compile_unit and it has a DW_AT_ranges
 attribute. Same for the top-level DW_TAG_compile_unit in LTO objects, but all further DW_TAG_compile_unit tags have no DW_AT_ranges attribute here. The comment in DWARFUnit::BuildAddressRangeTable() states that Clang “emits DW_AT_ranges for DW_TAG_compile_units”.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Are the nested DW_TAG_compile_unit tags in my LTO object missing their DW_AT_ranges or is that expected?<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">It looks like FindAddress() would return the offset correctly if it was there and the fix may get simpler.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Menlo","serif"">Top-level:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Menlo","serif"">0x0000000b: DW_TAG_compile_unit</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Menlo","serif"">    ...<br>
    DW_AT_low_pc.  (0x0000000000000000)<br>
    DW_AT_ranges.  (0x00000040<br>
       [0x0000000000000000, 0x00000000000007de)<br>
       [0x00000000000007f0, 0x00000000000033cd))</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Menlo","serif"">Nested:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Menlo","serif"">0x000130b3: DW_TAG_compile_unit</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Menlo","serif"">    ...<br>
    DW_AT_low_pc   (0x0000000000003f50)<br>
    DW_AT_high_pc. (0x000000000000dd0f)</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<br>
<o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">As far as I can tell, we need the actual number of CUs only after we discovered plugins.<o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Split that off into HasCompileUnits() and GetNumCompileUnits(). It works well so far. Also managed to extract the single CUs with correct offsets in the LTO object file once GetNumCompileUnits() calls InitOSO(). I kept the logic for associating
 the CUs with line ranges in the Symtab, so first/last_symbol_id/index are the same for all those CUs. Maybe the code needs a few more adjustments to support this, but so far I don’t see showstoppers.<o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">Short recap for what works after the simple changes:<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">* We iterate over the actual CUs in BreakpointResolverFileLine::SearchCallback().<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">* For the matching CU, we get the actual list of support files and find the correct file_idx and line_entry in CompileUnit::ResolveSymbolContext().<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">* We correctly link the OSO line table for this CU (with some overhead due to overlapping symbol ranges, but IIUC it’s fine as we only pick the ones for the CU).<o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<div>
<p class="MsoNormal">IF you do make a patch, please remove any functions in SymbolFileDWARFDebugMap that are dead code. SymbolFileDWARFDebugMap::GetModuleByOSOIndex() seems to be dead. If that is dead thenvSymbolFileDWARFDebugMap::GetObjectFileByOSOIndex()
 seems to be dead also.<o:p></o:p></p>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Yes both functions are dead and yes sure, I can include that in my patch. Another one is SymbolFileDWARFDebugMap::PrivateFindGlobalVariables(), which is one of the clients for symbol slices/ranges. The remaining ones are SymbolFileDWARFDebugMap::SymbolContainsSymbolWithID/Index()
 and SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap(), which are all alive.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<br>
<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">On 11. Sep 2018, at 20:13, Stefan Gränitz via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org"><span style="color:purple">lldb-dev@lists.llvm.org</span></a>> wrote:<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Thanks for your replies!<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<br>
<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<p class="MsoNormal">Right now we assume that each .o file has only on CU so we don't need to open all .o files in SymbolFileDWARFDebugMap::CalculateAbilities() which is something that gets run when we are trying to figure out which SymbolFile plug-in to load.
 [...] The problem used to be that even if we had a dSYM file, the loop that selected the symbol file plug-in would give each and every symbol file plugin a chance ...<o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Ok makes total sense, kind of historical reason.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<p class="MsoNormal">But that being said, in the past I re-ordered how the SymbolFile plug-ins were initialized to always put SymbolFileDWARF first and if it finds DWARF debug info or a dSYM file and has all the abilities then we stop looking for symbol file
 plug-ins that can load the current file. [...] So as soon as a SymbolFile plug-in can do everything we now stop.<o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
</blockquote>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">Good to know!<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal">Note that counting the number of compile units can be done extremely cheaply (of course, except the cost of opening the file). Each unit as a header that contain its length (which gives you the next unit). I’m not sure we have a primitive
 that does this without parsing the DWARF, but it should be easy to add.<o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Right, so we only need to parse the CU headers. That should be fast.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Opening each candidate .o file for the relatively rare case of having multiple CUs still sounds expensive, assuming that “thousands of .o files” may actually happen.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">CalculateAbilities() does indeed call GetNumCompileUnits(), but what it really wants to know at this time is “do we have any CU in there”:<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><br>
uint32_t SymbolFileDWARFDebugMap::CalculateAbilities() {<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">  ...<br>
  const uint32_t oso_index_count = GetNumCompileUnits();<br>
  if (oso_index_count > 0) {<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">    InitOSO();<br>
    if (!m_compile_unit_infos.empty()) {<br>
      return SymbolFile::CompileUnits | SymbolFile::Functions | …;<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">  }<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">}<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">As far as I can tell, we need the actual number of CUs only after we discovered plugins. In my case it’s during breakpoint resolution (i.e. BreakpointResolverFileLine::SearchCallback()). If we separated these two concerns conceptually (into
 HasCompileUnits() and GetNumCompileUnits()), couldn’t we then also do InitOSO() in two steps? Especially since lazy init is used everywhere already. This would avoid impact on CalculateAbilities() entirely.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">That said, I don’t really know how big the change would get then. And it probably adds complexity, while the implementation is quite complex already.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Anyway, for now what do you think about the idea?<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal">Do we really need this CU <-> Symbol mapping?<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">It’s used in SymbolFileDWARFDebugMap::SymbolContainsSymbolWithIndex(), which looks like dead code.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">It’s also used in SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap(), which initialises the OSO range map once. In order to do that it iterates over all CUs, so changing this or adding a special case here seems possible.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><a href="https://github.com/llvm-mirror/lldb/blob/59608853be9b52d3c01609196d152b3e3dbb4dac/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp#L172"><span style="color:purple">https://github.com/llvm-mirror/lldb/blob/59608853be9b52d3c01609196d152b3e3dbb4dac/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp#L172</span></a><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">What do you think?<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Best<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Stefan<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<br>
<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">On 11. Sep 2018, at 18:03, Frédéric Riss <<a href="mailto:friss@apple.com"><span style="color:purple">friss@apple.com</span></a>> wrote:<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><br>
<span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
<br>
</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">On Sep 11, 2018, at 8:48 AM, Greg Clayton <<a href="mailto:clayborg@gmail.com"><span style="color:purple">clayborg@gmail.com</span></a>> wrote:</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
On Sep 11, 2018, at 2:55 AM, Stefan Gränitz <<a href="mailto:sgraenitz@apple.com"><span style="color:purple">sgraenitz@apple.com</span></a>> wrote:</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Hello everyone</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">I am investigating a bug that prevents correct breakpoint resolution in LTO objects with embedded DWARF (no separate dSYM file) and tracked it down to the initialization
 of SymbolFileDWARFDebugMap. This code seems to assume there is only one compile unit per object file, but LTO objects have more than that:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">void SymbolFileDWARFDebugMap::InitOSO() {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">...</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">  const uint32_t oso_index_count =</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">    symtab->AppendSymbolIndexesWithTypeAndFlagsValue(</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">        eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">...</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">  m_compile_unit_infos.resize(oso_index_count); // <—— one CU per OSO entry in the Symtab</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">  for (uint32_t i = 0; i < oso_index_count; ++i) {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">    const uint32_t so_idx = oso_indexes[i] - 1;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">    const uint32_t oso_idx = oso_indexes[i];</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">    const Symbol *so_symbol = symtab->SymbolAtIndex(so_idx);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">    const Symbol *oso_symbol = symtab->SymbolAtIndex(oso_idx);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">...</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">      const Symbol *last_symbol = symtab->SymbolAtIndex(sibling_idx - 1);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">      m_compile_unit_infos[i].first_symbol_index = so_idx;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">      m_compile_unit_infos[i].last_symbol_index = sibling_idx - 1;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">      m_compile_unit_infos[i].first_symbol_id = so_symbol->GetID();</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Menlo","serif"">      m_compile_unit_infos[i].last_symbol_id = last_symbol->GetID();</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">The symptom is that LLDB will only read debug_line for one CU and miss all the rest. Thus, breakpoints in other CUs can’t be associated with line information.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">I wonder if there is a good way to populate the correct number of compile units from the OSO entry at this point?</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</blockquote>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">The reason it is like this is we don't want to have to open all .o files when we parse the debug map in order to figure out a compile unit index. Right now the compile unit
 UserID is just the index of the .o file in the debug map. Opening thousands of .o files can impose a performance issue.<br>
<br>
<br>
</span><o:p></o:p></p>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">The situation may appear similar to an archive file with a number of objects, but then we have separate OSO entries like “path/to/lib/libLLVMMCParser.a(AsmLexer.cpp.o)”.
 Furthermore LTO objects have one common symtab for all compile units and it was probably mixed up by optimization, so we cannot simply say that CUs start/end at certain symbol indexes as in the above code. The latter is used rarely and only in SymbolFileDWARFDebugMap,
 so there may be a workaround, but first I have to figure out the initial question:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">How to get more information about compile units in an LTO object? Any ideas welcome!</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">The only way is to open each .o file and see how many compile units they contain. Right now we assume that each .o file has only on CU so we don't need to open all .o files
 in SymbolFileDWARFDebugMap::CalculateAbilities() which is something that gets run when we are trying to figure out which SymbolFile plug-in to load. But that being said, in the past I re-ordered how the SymbolFile plug-ins were initialized to always put SymbolFileDWARF
 first and if it finds DWARF debug info or a dSYM file and has all the abilities then we stop looking for symbol file plug-ins that can load the current file. The problem used to be that even if we had a dSYM file, the loop that selected the symbol file plug-in
 would give each and every symbol file plugin a chance to tell us how much info they could extract via a call to SymbolFile::CalculateAbilities() and that would cause us to open all .o files just to say "I parse all debug info" just like a previous plug-in
 could. So as soon as a SymbolFile plug-in can do everything we now stop.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">If that’s not possible, I may find another way to fix it further down the road, but then the name m_compile_unit_infos seems not exactly correct here. It’s rather something
 like m_referenced_object_infos, right?</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</blockquote>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">So now that that change has been in for a while, it might be ok to open each .o file and see how many compile units they contain and then populate m_compile_unit_infos as
 needed.</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Note that counting the number of compile units can be done extremely cheaply (of course, except the cost of opening the file). Each unit as a header that contain its length
 (which gives you the next unit). I’m not sure we have a primitive that does this without parsing the DWARF, but it should be easy to add. </span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
<br>
</span><o:p></o:p></p>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">You will need to watch for any usage of m_compile_unit_infos and make sure it does the correct thing.</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">That’s the part I was worried about. The structure of m_compile_unit_infos makes the assumption that we can associate slices of symbols to a compile unit. I don’t think
 this is a correct assumption to make in the LTO case, and even if it were, we’d need to parse the DWARF and do some pretty heavy processing to extract the information. Do we really need this CU <-> Symbol mapping?</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Fred </span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
<br>
</span><o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
<br>
</span><o:p></o:p></p>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Btw.: My first attempt was a workaround for the symptom (see<span class="apple-converted-space"> </span><a href="https://reviews.llvm.org/D51546"><span style="color:purple">https://reviews.llvm.org/D51546</span></a>).
 It simply reads all debug_lines for a single CU, but I’d really appreciate a better solution.</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">The fix in D51546 seems wrong because the only way we get to a line table is via the DW_AT_stmt_list from a compile unit. If we can fix the LTO case to load all compile
 units from the LTO.o files with multiple CU's this fix won't be needed.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">So the correct solution is to detect how many compile units are in each .o file and then make sure to find all places that were assuming anything about the OSO index being
 the compile unit UserID are fixed. Now that plug-in loading stops after a SymbolFile says it can handle everything we can probably do a bit more work. One issue is that .o files might have been cleaned up or removed, so be sure to test any solution by removing
 the .o files and seeing how we do.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">I will be happy to review any patch you have. I can't think of any other reason the the OSO index needs to be the compile unit index. IF you do make a patch, please remove
 any functions in SymbolFileDWARFDebugMap that are dead code. SymbolFileDWARFDebugMap::GetModuleByOSOIndex() seems to be dead. If that is dead thenvSymbolFileDWARFDebugMap::GetObjectFileByOSOIndex() seems to be dead also.</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">_______________________________________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@lists.llvm.org"><span style="color:purple">lldb-dev@lists.llvm.org</span></a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>