<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Hello<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0);">
I am wondering if this is a bug, or more likely something I am doing wrong/using wrong APIs.<br>
I have binary A, and object file A.o, compiled with Clang debug fission single mode. So .dwo sections are in the object file. Although with split mode it would bre the same behavior.<br>
Relevant parts of the code:<br>
<div style="background-color: rgb(30, 30, 30); font-family: Menlo, Monaco, "Courier New", monospace; font-weight: normal; font-size: 12px; line-height: 18px; color: rgb(212, 212, 212);">
<span style=""><span style="color: rgb(197, 134, 192);">for</span><span> (</span><span style="color: rgb(86, 156, 214);">const</span><span> </span><span style="color: rgb(86, 156, 214);">auto</span><span> &CU :
</span><span style="color: rgb(156, 220, 254);">DwCtx</span><span>-></span><span style="color: rgb(220, 220, 170);">compile_units</span><span>()) {</span></span>
<div style=""><span> </span><span style="color: rgb(86, 156, 214);">auto</span><span> *</span><span style="color: rgb(86, 156, 214);">const</span><span> DwarfUnit =
</span><span style="color: rgb(156, 220, 254);">CU</span><span>.</span><span style="color: rgb(220, 220, 170);">get</span><span>();</span></div>
<div style=""><span> </span><span style="color: rgb(197, 134, 192);">if</span><span> (</span><span style="color: rgb(78, 201, 176);">llvm</span><span>::Optional<</span><span style="color: rgb(86, 156, 214);">uint64_t</span><span>> DWOId =
</span><span style="color: rgb(156, 220, 254);">DwarfUnit</span><span>-></span><span style="color: rgb(220, 220, 170);">getDWOId</span><span>()) {</span></div>
<div style=""><span> </span><span style="color: rgb(86, 156, 214);">auto</span><span> *CUDWO =
</span><span style="color: rgb(86, 156, 214);">static_cast</span><span><DWARFCompileUnit*>(</span><span style="color: rgb(156, 220, 254);">DwarfUnit</span><span>-></span><span style="color: rgb(220, 220, 170);">getNonSkeletonUnitDIE</span><span>(</span><span style="color: rgb(86, 156, 214);">false</span><span>).</span><span style="color: rgb(220, 220, 170);">getDwarfUnit</span><span>());</span></div>
<div style=""><font> </font><font>...</font></div>
<div style=""><span> }</span></div>
<span style=""><span> }</span></span></div>
<br>
Later in the code I iterate over DIEs for .debug_info.dwo and call<br>
<div style="color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Menlo, Monaco, "Courier New", monospace; font-weight: normal; font-size: 12px; line-height: 18px;">
<span><span style="color: rgb(106, 153, 85);">DIE.getLocations(dwarf::DW_AT_location);</span></span></div>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Alternatively can manually extract offset and call<br>
<div style="color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Menlo, Monaco, "Courier New", monospace; font-weight: normal; font-size: 12px; line-height: 18px;">
<span><span style="color: rgb(156, 220, 254);">CUnit</span><span>-></span><span style="color: rgb(220, 220, 170);">findLoclistFromOffset</span><span>(Offset);</span></span></div>
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0);">
It fails because it tries to look up address using DWARFUnit in NormalUnits that it extracts from A.o.<br>
Under the hood vistAsoluteLocationList is called with getAddrOffsetSectionItem passed in.<br>
Since this DWARFUnit is DWO, it invokes Context.info_section_units(). Which uses A.o to create DW_SECT_INFO and DW_SECT_EXT_TYPES.<br>
Then calls itself, but from the newly constructed Debug DWARFUnit. The skeleton CU that is in A.o.<br>
<br>
Since the way it's constructed the AddrOffsetSectionBase is never set, so <span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); display: inline !important;">
getAddrOffsetSectionItem</span> returns None. Eventually error is returned from high level API call.<br>
<br>
I ended up doing this to get address ranges:<br>
<div style="background-color: rgb(30, 30, 30); font-family: Menlo, Monaco, "Courier New", monospace; font-weight: normal; font-size: 12px; line-height: 18px; color: rgb(212, 212, 212);">
<div style="color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Menlo, Monaco, "Courier New", monospace; font-weight: normal;">
<span><span> DWARFLocationExpressionsVector LocEVector;</span></span>
<div><span> </span><span style="color: rgb(86, 156, 214);">auto</span><span> CallBack = [&](</span><span style="color: rgb(86, 156, 214);">const</span><span> </span><span style="color: rgb(78, 201, 176);">DWARFLocationEntry</span><span> </span><span style="color: rgb(86, 156, 214);">&</span><span style="color: rgb(156, 220, 254);">Entry</span><span>)
-></span><span style="color: rgb(86, 156, 214);"> bool </span><span>{</span></div>
<div><span> </span><span style="color: rgb(86, 156, 214);">auto</span><span> StartAddress =</span></div>
<div><span> </span><span style="color: rgb(156, 220, 254);">BaseUnit</span><span>-></span><span style="color: rgb(220, 220, 170);">getAddrOffsetSectionItem</span><span>(</span><span style="color: rgb(156, 220, 254);">Entry</span><span>.</span><span style="color: rgb(156, 220, 254);">Value0</span><span>);</span></div>
<div><span> </span><span style="color: rgb(197, 134, 192);">if</span><span> (!StartAddress) {</span></div>
<div><span style="color: rgb(106, 153, 85);"> //TODO: Handle Error</span></div>
<div><span> </span><span style="color: rgb(197, 134, 192);">return</span><span> </span><span style="color: rgb(86, 156, 214);">false</span><span>;</span></div>
<div><span> }</span></div>
<div><span> </span><span style="color: rgb(156, 220, 254);">LocEVector</span><span>.</span><span style="color: rgb(220, 220, 170);">emplace_back</span><span>(DWARFLocationExpression{DWARFAddressRange{</span></div>
<div><span> (*StartAddress).</span><span style="color: rgb(156, 220, 254);">Address</span><span>, (*StartAddress).</span><span style="color: rgb(156, 220, 254);">Address</span><span> +
</span><span style="color: rgb(156, 220, 254);">Entry</span><span>.</span><span style="color: rgb(156, 220, 254);">Value1</span><span>,</span></div>
<div><span> </span><span style="color: rgb(156, 220, 254);">Entry</span><span>.</span><span style="color: rgb(156, 220, 254);">SectionIndex</span><span>},
</span><span style="color: rgb(156, 220, 254);">Entry</span><span>.</span><span style="color: rgb(156, 220, 254);">Loc</span><span>});</span></div>
<div><span> </span><span style="color: rgb(197, 134, 192);">return</span><span> </span><span style="color: rgb(86, 156, 214);">true</span><span>;</span></div>
<span><span> };</span></span></div>
<br>
<div style=""><span> </span><span style="color: rgb(197, 134, 192);">if</span><span>(</span><span style="color: rgb(156, 220, 254);">Unit</span><span>-></span><span style="color: rgb(220, 220, 170);">getLocationTable</span><span>().</span><span style="color: rgb(220, 220, 170);">visitLocationList</span><span>(&Offset,
CallBack))</span></div>
<font> </font><font>...</font></div>
<br>
<br>
But back to original API calls. Are they just not designed to work with DWO CUs, or am I missing something?<br>
<br>
Even if AddrOffsetSectionBase was set to 0, the address section it is accessing is in A.o and is not relocated. One would still need to get base address from the address from Skeleton CU to get fully resolved address ranges, or what I did to use index to access
binary .debug_addr section directly (with appropriate <span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); display: inline !important;">AddrOffsetSectionBase).<br>
<br>
Thank You<br>
Alex</span></div>
</body>
</html>