<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 14, 2014 at 9:03 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Fri, Mar 14, 2014 at 1:25 AM, Alexey Samsonov <<a href="mailto:samsonov@google.com">samsonov@google.com</a>> wrote:<br>
> We might, but at the moment we generally don't copy DWARFContexts around<br>
> (and for now I don't see use cases where it would be convenient).<br>
<br>
</div>Oh, I meant making the units copyable/value types (not the context) -<br>
just to remove some excess new/delete/pointer/etc.<br></blockquote><div><br></div><div>Not sure if it's a good idea to copy DWARFUnit's around - it's not a lightweight object</div><div>at the moment - e.g. it contains a large vector of parsed DIEs.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
><br>
><br>
> On Thu, Mar 13, 2014 at 7:44 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
>><br>
>> On Thu, Mar 13, 2014 at 1:20 AM, Alexey Samsonov <<a href="mailto:samsonov@google.com">samsonov@google.com</a>><br>
>> wrote:<br>
>> > Author: samsonov<br>
>> > Date: Thu Mar 13 03:19:59 2014<br>
>> > New Revision: 203770<br>
>> ><br>
>> > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=203770&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=203770&view=rev</a><br>
>> > Log:<br>
>> > [C++11] DWARF parser: use SmallVector<std::unique_ptr> for parsed units<br>
>> > in DWARFContext, and delete custom destructors<br>
>><br>
>> Nice - we might be able to make them value objects (not sure if they<br>
>> need move-only semantics, but that'd be an option) too (either now or<br>
>> later).<br>
>><br>
>> ><br>
>> > Modified:<br>
>> > llvm/trunk/lib/DebugInfo/DWARFContext.cpp<br>
>> > llvm/trunk/lib/DebugInfo/DWARFContext.h<br>
>> ><br>
>> > Modified: llvm/trunk/lib/DebugInfo/DWARFContext.cpp<br>
>> > URL:<br>
>> > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.cpp?rev=203770&r1=203769&r2=203770&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.cpp?rev=203770&r1=203769&r2=203770&view=diff</a><br>
>> ><br>
>> > ==============================================================================<br>
>> > --- llvm/trunk/lib/DebugInfo/DWARFContext.cpp (original)<br>
>> > +++ llvm/trunk/lib/DebugInfo/DWARFContext.cpp Thu Mar 13 03:19:59 2014<br>
>> > @@ -8,7 +8,6 @@<br>
>> ><br>
>> > //===----------------------------------------------------------------------===//<br>
>> ><br>
>> > #include "DWARFContext.h"<br>
>> > -#include "llvm/ADT/STLExtras.h"<br>
>> > #include "llvm/ADT/SmallString.h"<br>
>> > #include "llvm/ADT/StringSwitch.h"<br>
>> > #include "llvm/Support/Compression.h"<br>
>> > @@ -23,13 +22,6 @@ using namespace object;<br>
>> ><br>
>> > typedef DWARFDebugLine::LineTable DWARFLineTable;<br>
>> ><br>
>> > -DWARFContext::~DWARFContext() {<br>
>> > - DeleteContainerPointers(CUs);<br>
>> > - DeleteContainerPointers(TUs);<br>
>> > - DeleteContainerPointers(DWOCUs);<br>
>> > - DeleteContainerPointers(DWOTUs);<br>
>> > -}<br>
>> > -<br>
>> > static void dumpPubSection(raw_ostream &OS, StringRef Name, StringRef<br>
>> > Data,<br>
>> > bool LittleEndian, bool GnuStyle) {<br>
>> > OS << "\n." << Name << " contents:\n";<br>
>> > @@ -125,7 +117,7 @@ void DWARFContext::dump(raw_ostream &OS,<br>
>> > savedAddressByteSize = CU->getAddressByteSize();<br>
>> > unsigned stmtOffset =<br>
>> > CU->getCompileUnitDIE()->getAttributeValueAsSectionOffset(<br>
>> > - CU, DW_AT_stmt_list, -1U);<br>
>> > + CU.get(), DW_AT_stmt_list, -1U);<br>
>> > if (stmtOffset != -1U) {<br>
>> > DataExtractor lineData(getLineSection().Data, isLittleEndian(),<br>
>> > savedAddressByteSize);<br>
>> > @@ -309,7 +301,7 @@ void DWARFContext::parseCompileUnits() {<br>
>> > if (!CU->extract(DIData, &offset)) {<br>
>> > break;<br>
>> > }<br>
>> > - CUs.push_back(CU.release());<br>
>> > + CUs.push_back(std::move(CU));<br>
>> > offset = CUs.back()->getNextUnitOffset();<br>
>> > }<br>
>> > }<br>
>> > @@ -328,7 +320,7 @@ void DWARFContext::parseTypeUnits() {<br>
>> > &I.second.Relocs, isLittleEndian()));<br>
>> > if (!TU->extract(DIData, &offset))<br>
>> > break;<br>
>> > - TUs.push_back(TU.release());<br>
>> > + TUs.push_back(std::move(TU));<br>
>> > offset = TUs.back()->getNextUnitOffset();<br>
>> > }<br>
>> > }<br>
>> > @@ -349,7 +341,7 @@ void DWARFContext::parseDWOCompileUnits(<br>
>> > if (!DWOCU->extract(DIData, &offset)) {<br>
>> > break;<br>
>> > }<br>
>> > - DWOCUs.push_back(DWOCU.release());<br>
>> > + DWOCUs.push_back(std::move(DWOCU));<br>
>> > offset = DWOCUs.back()->getNextUnitOffset();<br>
>> > }<br>
>> > }<br>
>> > @@ -369,7 +361,7 @@ void DWARFContext::parseDWOTypeUnits() {<br>
>> > isLittleEndian()));<br>
>> > if (!TU->extract(DIData, &offset))<br>
>> > break;<br>
>> > - DWOTUs.push_back(TU.release());<br>
>> > + DWOTUs.push_back(std::move(TU));<br>
>> > offset = DWOTUs.back()->getNextUnitOffset();<br>
>> > }<br>
>> > }<br>
>> > @@ -377,14 +369,17 @@ void DWARFContext::parseDWOTypeUnits() {<br>
>> ><br>
>> > namespace {<br>
>> > struct OffsetComparator {<br>
>> > - bool operator()(const DWARFCompileUnit *LHS,<br>
>> > - const DWARFCompileUnit *RHS) const {<br>
>> > +<br>
>> > + bool operator()(const std::unique_ptr<DWARFCompileUnit> &LHS,<br>
>> > + const std::unique_ptr<DWARFCompileUnit> &RHS) const<br>
>> > {<br>
>> > return LHS->getOffset() < RHS->getOffset();<br>
>> > }<br>
>> > - bool operator()(const DWARFCompileUnit *LHS, uint32_t RHS) const {<br>
>> > + bool operator()(const std::unique_ptr<DWARFCompileUnit> &LHS,<br>
>> > + uint32_t RHS) const {<br>
>> > return LHS->getOffset() < RHS;<br>
>> > }<br>
>> > - bool operator()(uint32_t LHS, const DWARFCompileUnit *RHS) const {<br>
>> > + bool operator()(uint32_t LHS,<br>
>> > + const std::unique_ptr<DWARFCompileUnit> &RHS) const<br>
>> > {<br>
>> > return LHS < RHS->getOffset();<br>
>> > }<br>
>> > };<br>
>> > @@ -393,10 +388,10 @@ namespace {<br>
>> > DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t<br>
>> > Offset) {<br>
>> > parseCompileUnits();<br>
>> ><br>
>> > - DWARFCompileUnit **CU =<br>
>> > + std::unique_ptr<DWARFCompileUnit> *CU =<br>
>> > std::lower_bound(CUs.begin(), CUs.end(), Offset,<br>
>> > OffsetComparator());<br>
>> > if (CU != CUs.end()) {<br>
>> > - return *CU;<br>
>> > + return CU->get();<br>
>> > }<br>
>> > return 0;<br>
>> > }<br>
>> > @@ -636,7 +631,7 @@ DWARFContextInMemory::DWARFContextInMemo<br>
>> > // Make data point to uncompressed section contents and save its<br>
>> > contents.<br>
>> > name = name.substr(1);<br>
>> > data = UncompressedSection->getBuffer();<br>
>> > - UncompressedSections.push_back(UncompressedSection.release());<br>
>> > + UncompressedSections.push_back(std::move(UncompressedSection));<br>
>> > }<br>
>> ><br>
>> > StringRef *Section =<br>
>> > @@ -755,8 +750,4 @@ DWARFContextInMemory::DWARFContextInMemo<br>
>> > }<br>
>> > }<br>
>> ><br>
>> > -DWARFContextInMemory::~DWARFContextInMemory() {<br>
>> > - DeleteContainerPointers(UncompressedSections);<br>
>> > -}<br>
>> > -<br>
>> > void DWARFContextInMemory::anchor() { }<br>
>> ><br>
>> > Modified: llvm/trunk/lib/DebugInfo/DWARFContext.h<br>
>> > URL:<br>
>> > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.h?rev=203770&r1=203769&r2=203770&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.h?rev=203770&r1=203769&r2=203770&view=diff</a><br>
>> ><br>
>> > ==============================================================================<br>
>> > --- llvm/trunk/lib/DebugInfo/DWARFContext.h (original)<br>
>> > +++ llvm/trunk/lib/DebugInfo/DWARFContext.h Thu Mar 13 03:19:59 2014<br>
>> > @@ -28,8 +28,8 @@ namespace llvm {<br>
>> > /// information parsing. The actual data is supplied through pure<br>
>> > virtual<br>
>> > /// methods that a concrete implementation provides.<br>
>> > class DWARFContext : public DIContext {<br>
>> > - typedef SmallVector<DWARFCompileUnit *, 1> CUVector;<br>
>> > - typedef SmallVector<DWARFTypeUnit *, 1> TUVector;<br>
>> > + typedef SmallVector<std::unique_ptr<DWARFCompileUnit>, 1> CUVector;<br>
>> > + typedef SmallVector<std::unique_ptr<DWARFTypeUnit>, 1> TUVector;<br>
>> ><br>
>> > CUVector CUs;<br>
>> > TUVector TUs;<br>
>> > @@ -69,7 +69,6 @@ public:<br>
>> > };<br>
>> ><br>
>> > DWARFContext() : DIContext(CK_DWARF) {}<br>
>> > - virtual ~DWARFContext();<br>
>> ><br>
>> > static bool classof(const DIContext *DICtx) {<br>
>> > return DICtx->getKind() == CK_DWARF;<br>
>> > @@ -131,13 +130,13 @@ public:<br>
>> > /// Get the compile unit at the specified index for this compile<br>
>> > unit.<br>
>> > DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {<br>
>> > parseCompileUnits();<br>
>> > - return CUs[index];<br>
>> > + return CUs[index].get();<br>
>> > }<br>
>> ><br>
>> > /// Get the compile unit at the specified index for the DWO compile<br>
>> > units.<br>
>> > DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {<br>
>> > parseDWOCompileUnits();<br>
>> > - return DWOCUs[index];<br>
>> > + return DWOCUs[index].get();<br>
>> > }<br>
>> ><br>
>> > /// Get a pointer to the parsed DebugAbbrev object.<br>
>> > @@ -237,11 +236,10 @@ class DWARFContextInMemory : public DWAR<br>
>> > StringRef RangeDWOSection;<br>
>> > StringRef AddrSection;<br>
>> ><br>
>> > - SmallVector<MemoryBuffer*, 4> UncompressedSections;<br>
>> > + SmallVector<std::unique_ptr<MemoryBuffer>, 4> UncompressedSections;<br>
>> ><br>
>> > public:<br>
>> > DWARFContextInMemory(object::ObjectFile *);<br>
>> > - ~DWARFContextInMemory();<br>
>> > bool isLittleEndian() const override { return IsLittleEndian; }<br>
>> > uint8_t getAddressSize() const override { return AddressSize; }<br>
>> > const Section &getInfoSection() override { return InfoSection; }<br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > llvm-commits mailing list<br>
>> > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
>> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
><br>
><br>
><br>
> --<br>
> Alexey Samsonov, MSK<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</div></div>