[DWARF parser] DWARFDebugFrame: use unique_ptr instead of raw pointer

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207459 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov 2014-04-28 22:52:24 +00:00
parent d200f074f5
commit 2f9c1f2f17
2 changed files with 10 additions and 23 deletions

View File

@ -285,14 +285,9 @@ private:
DWARFDebugFrame::DWARFDebugFrame() { DWARFDebugFrame::DWARFDebugFrame() {
} }
DWARFDebugFrame::~DWARFDebugFrame() { DWARFDebugFrame::~DWARFDebugFrame() {
for (const auto &Entry : Entries) {
delete Entry;
}
} }
static void LLVM_ATTRIBUTE_UNUSED dumpDataAux(DataExtractor Data, static void LLVM_ATTRIBUTE_UNUSED dumpDataAux(DataExtractor Data,
uint32_t Offset, int Length) { uint32_t Offset, int Length) {
errs() << "DUMP: "; errs() << "DUMP: ";
@ -334,7 +329,6 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
Id = Data.getUnsigned(&Offset, IsDWARF64 ? 8 : 4); Id = Data.getUnsigned(&Offset, IsDWARF64 ? 8 : 4);
bool IsCIE = ((IsDWARF64 && Id == DW64_CIE_ID) || Id == DW_CIE_ID); bool IsCIE = ((IsDWARF64 && Id == DW64_CIE_ID) || Id == DW_CIE_ID);
FrameEntry *Entry = nullptr;
if (IsCIE) { if (IsCIE) {
// Note: this is specifically DWARFv3 CIE header structure. It was // Note: this is specifically DWARFv3 CIE header structure. It was
// changed in DWARFv4. We currently don't support reading DWARFv4 // changed in DWARFv4. We currently don't support reading DWARFv4
@ -346,30 +340,25 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
int64_t DataAlignmentFactor = Data.getSLEB128(&Offset); int64_t DataAlignmentFactor = Data.getSLEB128(&Offset);
uint64_t ReturnAddressRegister = Data.getULEB128(&Offset); uint64_t ReturnAddressRegister = Data.getULEB128(&Offset);
Entry = new CIE(Data, StartOffset, Length, Version, Entries.emplace_back(new CIE(Data, StartOffset, Length, Version,
StringRef(Augmentation), CodeAlignmentFactor, StringRef(Augmentation), CodeAlignmentFactor,
DataAlignmentFactor, ReturnAddressRegister); DataAlignmentFactor, ReturnAddressRegister));
} else { } else {
// FDE // FDE
uint64_t CIEPointer = Id; uint64_t CIEPointer = Id;
uint64_t InitialLocation = Data.getAddress(&Offset); uint64_t InitialLocation = Data.getAddress(&Offset);
uint64_t AddressRange = Data.getAddress(&Offset); uint64_t AddressRange = Data.getAddress(&Offset);
Entry = new FDE(Data, StartOffset, Length, CIEPointer, Entries.emplace_back(new FDE(Data, StartOffset, Length, CIEPointer,
InitialLocation, AddressRange); InitialLocation, AddressRange));
} }
assert(Entry && "Expected Entry to be populated with CIE or FDE"); Entries.back()->parseInstructions(&Offset, EndStructureOffset);
Entry->parseInstructions(&Offset, EndStructureOffset);
if (Offset == EndStructureOffset) { if (Offset != EndStructureOffset) {
// Entry instrucitons parsed successfully.
Entries.push_back(Entry);
} else {
std::string Str; std::string Str;
raw_string_ostream OS(Str); raw_string_ostream OS(Str);
OS << format("Parsing entry instructions at %lx failed", OS << format("Parsing entry instructions at %lx failed", StartOffset);
Entry->getOffset());
report_fatal_error(Str); report_fatal_error(Str);
} }
} }

View File

@ -12,14 +12,13 @@
#include "llvm/Support/DataExtractor.h" #include "llvm/Support/DataExtractor.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <memory>
#include <vector> #include <vector>
namespace llvm { namespace llvm {
class FrameEntry; class FrameEntry;
/// \brief A parsed .debug_frame section /// \brief A parsed .debug_frame section
/// ///
class DWARFDebugFrame { class DWARFDebugFrame {
@ -35,8 +34,7 @@ public:
void parse(DataExtractor Data); void parse(DataExtractor Data);
private: private:
typedef std::vector<FrameEntry *> EntryVector; std::vector<std::unique_ptr<FrameEntry>> Entries;
EntryVector Entries;
}; };