blob: cd6fbefd05dd1d75c1da0d6c716ddde7e14dbd8e [file] [log] [blame]
David Blaikie18e73502013-06-19 21:37:13 +00001//===-- DWARFDebugLoc.cpp -------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Zachary Turner82af9432015-01-30 18:07:45 +000010#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
David Blaikie18e73502013-06-19 21:37:13 +000011#include "llvm/Support/Compiler.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000012#include "llvm/Support/Dwarf.h"
David Blaikie18e73502013-06-19 21:37:13 +000013#include "llvm/Support/Format.h"
14#include "llvm/Support/raw_ostream.h"
15
16using namespace llvm;
17
18void DWARFDebugLoc::dump(raw_ostream &OS) const {
Alexey Samsonov1eabf982014-03-13 07:52:54 +000019 for (const LocationList &L : Locations) {
20 OS << format("0x%8.8x: ", L.Offset);
David Blaikie18e73502013-06-19 21:37:13 +000021 const unsigned Indent = 12;
Alexey Samsonov1eabf982014-03-13 07:52:54 +000022 for (const Entry &E : L.Entries) {
23 if (&E != L.Entries.begin())
David Blaikie18e73502013-06-19 21:37:13 +000024 OS.indent(Indent);
Alexey Samsonov1eabf982014-03-13 07:52:54 +000025 OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin)
David Blaikie18e73502013-06-19 21:37:13 +000026 << '\n';
David Blaikieb9a18702013-06-19 21:42:05 +000027 OS.indent(Indent) << " Ending address offset: "
Alexey Samsonov1eabf982014-03-13 07:52:54 +000028 << format("0x%016" PRIx64, E.End) << '\n';
David Blaikieb9a18702013-06-19 21:42:05 +000029 OS.indent(Indent) << " Location description: ";
Alexey Samsonov1eabf982014-03-13 07:52:54 +000030 for (unsigned char Loc : E.Loc) {
31 OS << format("%2.2x ", Loc);
David Blaikie18e73502013-06-19 21:37:13 +000032 }
33 OS << "\n\n";
34 }
35 }
36}
37
38void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
39 uint32_t Offset = 0;
Adrian Prantl6f84d312014-02-11 21:22:53 +000040 while (data.isValidOffset(Offset+AddressSize-1)) {
David Blaikie18e73502013-06-19 21:37:13 +000041 Locations.resize(Locations.size() + 1);
42 LocationList &Loc = Locations.back();
43 Loc.Offset = Offset;
44 // 2.6.2 Location Lists
45 // A location list entry consists of:
46 while (true) {
47 Entry E;
48 RelocAddrMap::const_iterator AI = RelocMap.find(Offset);
49 // 1. A beginning address offset. ...
50 E.Begin = data.getUnsigned(&Offset, AddressSize);
51 if (AI != RelocMap.end())
52 E.Begin += AI->second.second;
53
54 AI = RelocMap.find(Offset);
55 // 2. An ending address offset. ...
56 E.End = data.getUnsigned(&Offset, AddressSize);
57 if (AI != RelocMap.end())
58 E.End += AI->second.second;
59
60 // The end of any given location list is marked by an end of list entry,
61 // which consists of a 0 for the beginning address offset and a 0 for the
62 // ending address offset.
63 if (E.Begin == 0 && E.End == 0)
64 break;
65
66 unsigned Bytes = data.getU16(&Offset);
67 // A single location description describing the location of the object...
68 StringRef str = data.getData().substr(Offset, Bytes);
69 Offset += Bytes;
Benjamin Kramer4f6ac162015-02-28 10:11:12 +000070 E.Loc.append(str.begin(), str.end());
Chandler Carruth002da5d2014-03-02 04:08:41 +000071 Loc.Entries.push_back(std::move(E));
David Blaikie18e73502013-06-19 21:37:13 +000072 }
73 }
Adrian Prantl6f84d312014-02-11 21:22:53 +000074 if (data.isValidOffset(Offset))
75 llvm::errs() << "error: failed to consume entire .debug_loc section\n";
David Blaikie18e73502013-06-19 21:37:13 +000076}
David Blaikie9c550ac2014-03-25 01:44:02 +000077
78void DWARFDebugLocDWO::parse(DataExtractor data) {
79 uint32_t Offset = 0;
80 while (data.isValidOffset(Offset)) {
81 Locations.resize(Locations.size() + 1);
82 LocationList &Loc = Locations.back();
83 Loc.Offset = Offset;
84 dwarf::LocationListEntry Kind;
85 while ((Kind = static_cast<dwarf::LocationListEntry>(
86 data.getU8(&Offset))) != dwarf::DW_LLE_end_of_list_entry) {
87
88 if (Kind != dwarf::DW_LLE_start_length_entry) {
89 llvm::errs() << "error: dumping support for LLE of kind " << (int)Kind
90 << " not implemented\n";
91 return;
92 }
93
94 Entry E;
95
96 E.Start = data.getULEB128(&Offset);
97 E.Length = data.getU32(&Offset);
98
99 unsigned Bytes = data.getU16(&Offset);
100 // A single location description describing the location of the object...
101 StringRef str = data.getData().substr(Offset, Bytes);
102 Offset += Bytes;
103 E.Loc.resize(str.size());
104 std::copy(str.begin(), str.end(), E.Loc.begin());
105
106 Loc.Entries.push_back(std::move(E));
107 }
108 }
109}
110
111void DWARFDebugLocDWO::dump(raw_ostream &OS) const {
112 for (const LocationList &L : Locations) {
113 OS << format("0x%8.8x: ", L.Offset);
114 const unsigned Indent = 12;
115 for (const Entry &E : L.Entries) {
116 if (&E != L.Entries.begin())
117 OS.indent(Indent);
118 OS << "Beginning address index: " << E.Start << '\n';
119 OS.indent(Indent) << " Length: " << E.Length << '\n';
120 OS.indent(Indent) << " Location description: ";
121 for (unsigned char Loc : E.Loc)
122 OS << format("%2.2x ", Loc);
123 OS << "\n\n";
124 }
125 }
126}
127