(original) (raw)
Hello David
Thank you for the pointer.
I looked at llvm-symbolizer and I think it suffers from the same problem.
First output:
Case 1: Monolithic debug information:
Thank you for the pointer.
I looked at llvm-symbolizer and I think it suffers from the same problem.
First output:
Case 1: Monolithic debug information:
llvm-symbolizer --obj bzip2 --print-address 0x00000000004014b7
0x4014b7
copyFileName
/home/ayermolo/local/bzip2\_base/bzip2.c:941:3
main
/home/ayermolo/local/bzip2\_base/bzip2.c:1823:4
Case 2: Debug fission with upstream build
llvm-symbolizer --obj bzip2 --print-address 0x00000000004014b7
Case 3: Debug fission with changes (either one will work) proposed
llvm-symbolizer --obj bzip2 --print-address 0x00000000004014b7
llvm-symbolizer --obj bzip2 --print-address 0x00000000004014b7
0x4014b7
main
/home/ayermolo/local/bzip2\_DF/bzip2.c:941:3Case 3: Debug fission with changes (either one will work) proposed
llvm-symbolizer --obj bzip2 --print-address 0x00000000004014b7
0x4014b7
copyFileName
/home/ayermolo/local/bzip2\_DF/bzip2.c:941:3
main
/home/ayermolo/local/bzip2\_DF/bzip2.c:1823:4
For reference
Debug entry in Monolithic format
Debug entry in Debug fission format
0x0000052e: DW\_TAG\_inlined\_subroutine \[29\] \*
Debug entry in Monolithic format
0x00000784: DW\_TAG\_inlined\_subroutine \[29\] \*
DW\_AT\_abstract\_origin \[DW\_FORM\_ref4\] (cu + 0x06a9 => {0x000006a9} "copyFileName")
DW\_AT\_low\_pc \[DW\_FORM\_addr\] (0x00000000004014b7)
DW\_AT\_high\_pc \[DW\_FORM\_data4\] (0x0000001b)
DW\_AT\_call\_file \[DW\_FORM\_data1\] ("/home/ayermolo/local/bzip2\_base/bzip2.c")
DW\_AT\_call\_line \[DW\_FORM\_data2\] (1823)
DW\_AT\_call\_column \[DW\_FORM\_data1\] (0x04)
Debug entry in Debug fission format
0x0000052e: DW\_TAG\_inlined\_subroutine \[29\] \*
DW\_AT\_abstract\_origin \[DW\_FORM\_ref4\] (cu + 0x047e => {0x0000047e} "copyFileName")
DW\_AT\_low\_pc \[DW\_FORM\_GNU\_addr\_index\] (indexed (0000001a) address = 0x00000000000000a7 ".text.main")
DW\_AT\_high\_pc \[DW\_FORM\_data4\] (0x0000001b)
DW\_AT\_call\_file \[DW\_FORM\_data1\] (0x01)
DW\_AT\_call\_line \[DW\_FORM\_data2\] (1823)
DW\_AT\_call\_column \[DW\_FORM\_data1\] (0x04)To dig into APIs.
SymbolizableObjectFile::symbolizeInlinedCode → DWARFContext::getInliningInfoForAddress → DWARFUnit::getInlinedChainForAddress → DWARFUnit::parseDWO
At which point DWO Context is created, DWO CU is created and DWO field is set in Skeleton CU.
By comparison this is how I get DWO CU:
DWARFUnit::
By comparison this is how I get DWO CU:
DWARFUnit::
getNonSkeletonUnitDIE --> DWARFUnit::parseDWO()
After parseDWO a DWARFUnit::getSubroutineForAddress is called on DWO CU (since we are dealing with debug fission).
DWARFDie SubroutineDIE =
(DWO ? \*DWO : \*this).getSubroutineForAddress(Address);
(DWO ? \*DWO : \*this).getSubroutineForAddress(Address);
getSubroutineForAddress calls DWARFUnit::updateAddressDieMap.
As part of DWARFUnit::updateAddressDieMap we get this sequence of calls:
As part of DWARFUnit::updateAddressDieMap we get this sequence of calls:
DWARFDie::getAddressRanges() → DWARFDie::getLowAndHighPC → toSectionedAddress → DWARFFormValue::getAsAddress() → DWARFUnit::getAddrOffsetSectionItem
The DWARFUnit::getAddrOffsetSectionItem returns NONE (to circle back to original post) because in this DWO CU IsDWO
flag is set, it then tries to parse NormalUnits. Except now it gets un-relocated Skelton CU from .o/.dwo, and it invokes DWARFUnit::getAddrOffsetSectionItem
on that. Since AddrOffsetSectionBase is not set it returns NONE.
So we basically start from relocated Skeleton CU we got from binary debug information, create DWO CU from .o/.dwo, we then create Skeleton CU from .o/.dwo and try to get address from it. Since .debug\_addr is in the binary, and we never set correct section/offset in that Sketon CU clearly that doesn't work.
My usage model.
It is more from bottom up as you have mentioned. This is because of what needs to be done. Bolt moves functions around, hoists out cold sections into their own functions, etc. It also converts low\_pc/high\_pc to ranges. So .debug\_ranges, .debug\_addr, .debug\_loc are completely re-written. We then update every reference in DIE with new value of DW\_AT\_low\_pc or modify DW\_AT\_low\_pc/DW\_AT\_high\_pc to range semantic. This means that we need to iterate over every DIE get original address map it to new address/addresses and update the DIE. Both in CUs in binary (in case of monolithic or fission + -fsplit-dwarf-inlining), and in .debug\_info.dwo CUs.
For example, when processing DW\_TAG\_inline\_subroutine a DWARFDie::getAddressRanges() is invoked. Which follows the same execution path as when it is invoked in symbolizer and hits the same problem.
So we basically start from relocated Skeleton CU we got from binary debug information, create DWO CU from .o/.dwo, we then create Skeleton CU from .o/.dwo and try to get address from it. Since .debug\_addr is in the binary, and we never set correct section/offset in that Sketon CU clearly that doesn't work.
My usage model.
It is more from bottom up as you have mentioned. This is because of what needs to be done. Bolt moves functions around, hoists out cold sections into their own functions, etc. It also converts low\_pc/high\_pc to ranges. So .debug\_ranges, .debug\_addr, .debug\_loc are completely re-written. We then update every reference in DIE with new value of DW\_AT\_low\_pc or modify DW\_AT\_low\_pc/DW\_AT\_high\_pc to range semantic. This means that we need to iterate over every DIE get original address map it to new address/addresses and update the DIE. Both in CUs in binary (in case of monolithic or fission + -fsplit-dwarf-inlining), and in .debug\_info.dwo CUs.
For example, when processing DW\_TAG\_inline\_subroutine a DWARFDie::getAddressRanges() is invoked. Which follows the same execution path as when it is invoked in symbolizer and hits the same problem.
Now I can get raw index Value from DIE, then look up address in Skeleton CU with getAddrOffsetSectionItem,
but it exposes extra complexity.
I think if we can do a fix "under the hood" it will simplify things and looks like will help tools like symbolizer also.
To iterate the two patches are just to start the discussion, maybe a more extensive refactoring is necessary. Working on bolt and looking at symoblizer (or at least part of it) I don't quite understand logic in getAddrOffsetSectionItem.
Doesn't seem like it works at least in those usage models.
Alex
Alex
From: David Blaikie
Sent: Wednesday, February 24, 2021 4:42 PM
To: Alexander Yermolovich
Cc: Pavel Labath ; llvm-dev@lists.llvm.org
Subject: Re: \[llvm-dev\] Extracting LocList address ranges from DWO .debug\_info
Sent: Wednesday, February 24, 2021 4:42 PM
To: Alexander Yermolovich
Cc: Pavel Labath ; llvm-dev@lists.llvm.org
Subject: Re: \[llvm-dev\] Extracting LocList address ranges from DWO .debug\_info
On Mon, Feb 22, 2021 at 10:50 AM Alexander Yermolovich <ayermolo@fb.com> wrote:
Hello David.
My apologies, let me provide some context. I am helping with BOLT binary optimizer (soon to be upstreamed). As part of its functionality it updates debug information to reflect the changes it had made to the binary. Moving functions around, extracting cold blocks, ICF, etc.
Right now, it works with monolithic Debug information, but not with Fission one.
It completely re-writes debug line, ranges/aranges, and patches relevant DIEs entries to point to new offsets within those sections. Which means finding what current addresses are in DIE, mapping them to new addresses and from that new offsets within sections. For debug fission it also will need to re-write .debug\_addr and update indices that point to it.
I looked at llvm-symbolizer and this seems a bit high level.
It is, but somewhere down there it has to follow from executable to dwo/dwp files - that part of its implementation might be able to be reused (may benefit/require some refactoring to make it more reusable) for the purposes you have. I'd suggest looking there first, if you have a chance.
Perhaps that looks like refactoring llvm-symbolizer to use a codepath that looks like the ones you're already using, and making that work with dwos in a way that it doesn't already - or changing your code to more like some aspects of llvm-symbolizer's implementation and follow that codepath.
So llvm-symbolizer goes down through LLVMSymbolizer::symbolizeInlinedCodeCommon -> SymbolizableObjectFile::symbolizeInlinedCode -> DWARFContext::getInliningInfoForAddress
It looks like this code does correctly stitch together the addr and ranges tables in "parseDWO" (where it calls setAddrOffsetSection/setRangesSection).
But it sounds like you're trying to go from loading DWARFContext for dwo/dwp files directly, back to the skeleton/executable - it may be better to go forward instead of backwards? Load up the DWARFContext for the linked executable, then walk the (possibly skeleton) units there, and parseDWO/getDWO to walk into the split units - and those split units, loaded that way, should have their addr table working correctly due to the parseDWO code?
So usage model is closer to 1) I think.
Right now there is no link, but one solution would be to add it, when getNonSkeletonUnitDIE/parseDWO is called. This reflects the code in getAddrOffsetSection that tries to parse normal CUs current DWARFUnit is DWO. I don't know what original intent of that code was, but as it stands, I don't think it works because it parses none relocated skeleton CU in A.o.Rough idea: \*
https://reviews.llvm.org/D96826
Alternative, that whole code can be skipped entirely. \*
https://reviews.llvm.org/D96827
This works because in parseDWO we set AddrOffsetSectionBase, and AddrOffsetSection from .debug\_addr in binary. Then in getAddrOffsetSectionItem we have all the information to get addresses from indices. One weird part is that DWARFDataExtractor is created with A.o file, while AddrOffsetSection is from A binary.
The getAddrOffsetSectionItem is an important low level API. For example, it is also used by DWARFUnit::getLowandHighPC, along with DWARFDie::getLocations, DWARFUnit::findLocationLIstFromOffset. So, making a fix at that level, would make other more high-level APIs work for DWO contents.
\*Diffs are same ones as previously mentioned.
Alex
"Sorry I'm not really following all these pieces.There's two basic ways these APIs are predominantly used:
- llvm-dwarfdump: This opens one file/context at a time, and generally
doesn't open other files - such as dwos or o/exe for skeleton. (indeed,
there's no reliable way to find a skeleton, given a dwo - only to find dwos
given skeletons)- llvm-symbolizer: this opens executable files (or .o files) and from
there can load dwo/dwp/dsym related files as neededWhat sort of use case do you have? I guess it can/should look something
like (2) so can you use the LLVM debug info APIs in a similar manner to
llvm-symbolizer to achieve your goals?
"
From: David Blaikie <dblaikie@gmail.com>
Sent: Monday, February 15, 2021 10:09 PM
To: Alexander Yermolovich <ayermolo@fb.com>; Pavel Labath <pavel@labath.sk>
Cc: llvm-dev@lists.llvm.org <llvm-dev@lists.llvm.org>
Subject: Re: \[llvm-dev\] Extracting LocList address ranges from DWO .debug\_infoThis stuff is a bit ad-hoc at best.
I believe some of these APIs have been generalized enough to be usable
for your use-case, but it might be at a lower level - specifically I
think the loclist infrastructure is used by lldb when parsing DWARFv5.
But it might be used without some of the LLVM DWARF Unit abstractions
you're using. (those abstractions are used in llvm-dwarfdump - which
often isn't dealing with both .o and .dwo, but only dumping one of the
files & doing what it can (or sometimes dumping one file containing
both sets of sections, in which case it can do some address lookup,
etc, more conveniently))
On Fri, Feb 12, 2021 at 6:07 PM Alexander Yermolovich via llvm-dev
<llvm-dev@lists.llvm.org> wrote:
\>
\> Hello
\>
\> I am wondering if this is a bug, or more likely something I am doing wrong/using wrong APIs.
\> 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.
\> Relevant parts of the code:
\> for (const auto &CU : DwCtx->compile\_units()) {
\> auto \*const DwarfUnit = CU.get();
\> if (llvm::Optional DWOId = DwarfUnit->getDWOId()) {
\> auto \*CUDWO = static\_cast(DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit());
\> ...
\> }
\> }
\>
\> Later in the code I iterate over DIEs for .debug\_info.dwo and call
\> DIE.getLocations(dwarf::DW\_AT\_location);
\>
\> Alternatively can manually extract offset and call
\> CUnit->findLoclistFromOffset(Offset);
\>
\> It fails because it tries to look up address using DWARFUnit in NormalUnits that it extracts from A.o.
\> Under the hood vistAsoluteLocationList is called with getAddrOffsetSectionItem passed in.
\> 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.
\> Then calls itself, but from the newly constructed Debug DWARFUnit. The skeleton CU that is in A.o.
\>
\> Since the way it's constructed the AddrOffsetSectionBase is never set, so getAddrOffsetSectionItem returns None. Eventually error is returned from high level API call.
\>
\> I ended up doing this to get address ranges:
\> DWARFLocationExpressionsVector LocEVector;
\> auto CallBack = \[&\](const DWARFLocationEntry &Entry) -> bool {
\> auto StartAddress =
\> BaseUnit->getAddrOffsetSectionItem(Entry.Value0);
\> if (!StartAddress) {
\> //TODO: Handle Error
\> return false;
\> }
\> LocEVector.emplace\_back(DWARFLocationExpression{DWARFAddressRange{
\> (\*StartAddress).Address, (\*StartAddress).Address + Entry.Value1,
\> Entry.SectionIndex}, Entry.Loc});
\> return true;
\> };
\>
\> if(Unit->getLocationTable().visitLocationList(&Offset, CallBack))
\> ...
\>
\>
\> But back to original API calls. Are they just not designed to work with DWO CUs, or am I missing something?
\>
\> 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 AddrOffsetSectionBase).
\>
\> Thank You
\> Alex
\> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
\> LLVM Developers mailing list
\> llvm-dev@lists.llvm.org
\> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev