1259698Sdim//===-- DWARFDebugLoc.cpp -------------------------------------------------===// 2259698Sdim// 3259698Sdim// The LLVM Compiler Infrastructure 4259698Sdim// 5259698Sdim// This file is distributed under the University of Illinois Open Source 6259698Sdim// License. See LICENSE.TXT for details. 7259698Sdim// 8259698Sdim//===----------------------------------------------------------------------===// 9259698Sdim 10259698Sdim#include "DWARFDebugLoc.h" 11259698Sdim#include "llvm/Support/Compiler.h" 12259698Sdim#include "llvm/Support/Format.h" 13259698Sdim#include "llvm/Support/raw_ostream.h" 14259698Sdim 15259698Sdimusing namespace llvm; 16259698Sdim 17259698Sdimvoid DWARFDebugLoc::dump(raw_ostream &OS) const { 18259698Sdim for (LocationLists::const_iterator I = Locations.begin(), E = Locations.end(); I != E; ++I) { 19259698Sdim OS << format("0x%8.8x: ", I->Offset); 20259698Sdim const unsigned Indent = 12; 21259698Sdim for (SmallVectorImpl<Entry>::const_iterator I2 = I->Entries.begin(), E2 = I->Entries.end(); I2 != E2; ++I2) { 22259698Sdim if (I2 != I->Entries.begin()) 23259698Sdim OS.indent(Indent); 24259698Sdim OS << "Beginning address offset: " << format("0x%016" PRIx64, I2->Begin) 25259698Sdim << '\n'; 26259698Sdim OS.indent(Indent) << " Ending address offset: " 27259698Sdim << format("0x%016" PRIx64, I2->End) << '\n'; 28259698Sdim OS.indent(Indent) << " Location description: "; 29259698Sdim for (SmallVectorImpl<unsigned char>::const_iterator I3 = I2->Loc.begin(), E3 = I2->Loc.end(); I3 != E3; ++I3) { 30259698Sdim OS << format("%2.2x ", *I3); 31259698Sdim } 32259698Sdim OS << "\n\n"; 33259698Sdim } 34259698Sdim } 35259698Sdim} 36259698Sdim 37259698Sdimvoid DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) { 38259698Sdim uint32_t Offset = 0; 39259698Sdim while (data.isValidOffset(Offset)) { 40259698Sdim Locations.resize(Locations.size() + 1); 41259698Sdim LocationList &Loc = Locations.back(); 42259698Sdim Loc.Offset = Offset; 43259698Sdim // 2.6.2 Location Lists 44259698Sdim // A location list entry consists of: 45259698Sdim while (true) { 46259698Sdim Entry E; 47259698Sdim RelocAddrMap::const_iterator AI = RelocMap.find(Offset); 48259698Sdim // 1. A beginning address offset. ... 49259698Sdim E.Begin = data.getUnsigned(&Offset, AddressSize); 50259698Sdim if (AI != RelocMap.end()) 51259698Sdim E.Begin += AI->second.second; 52259698Sdim 53259698Sdim AI = RelocMap.find(Offset); 54259698Sdim // 2. An ending address offset. ... 55259698Sdim E.End = data.getUnsigned(&Offset, AddressSize); 56259698Sdim if (AI != RelocMap.end()) 57259698Sdim E.End += AI->second.second; 58259698Sdim 59259698Sdim // The end of any given location list is marked by an end of list entry, 60259698Sdim // which consists of a 0 for the beginning address offset and a 0 for the 61259698Sdim // ending address offset. 62259698Sdim if (E.Begin == 0 && E.End == 0) 63259698Sdim break; 64259698Sdim 65259698Sdim unsigned Bytes = data.getU16(&Offset); 66259698Sdim // A single location description describing the location of the object... 67259698Sdim StringRef str = data.getData().substr(Offset, Bytes); 68259698Sdim Offset += Bytes; 69259698Sdim E.Loc.reserve(str.size()); 70259698Sdim std::copy(str.begin(), str.end(), std::back_inserter(E.Loc)); 71259698Sdim Loc.Entries.push_back(llvm_move(E)); 72259698Sdim } 73259698Sdim } 74259698Sdim} 75