Files
clang-p2996/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
Kate Stone b9c1b51e45 *** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style.  This kind of mass change has
*** two obvious implications:

Firstly, merging this particular commit into a downstream fork may be a huge
effort.  Alternatively, it may be worth merging all changes up to this commit,
performing the same reformatting operation locally, and then discarding the
merge for this particular commit.  The commands used to accomplish this
reformatting were as follows (with current working directory as the root of
the repository):

    find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} +
    find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ;

The version of clang-format used was 3.9.0, and autopep8 was 1.2.4.

Secondly, “blame” style tools will generally point to this commit instead of
a meaningful prior commit.  There are alternatives available that will attempt
to look through this change and find the appropriate prior commit.  YMMV.

llvm-svn: 280751
2016-09-06 20:57:50 +00:00

130 lines
3.9 KiB
C++

//===-- DWARFDebugRanges.cpp ------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "DWARFDebugRanges.h"
#include "SymbolFileDWARF.h"
#include "lldb/Core/Stream.h"
#include <assert.h>
using namespace lldb_private;
using namespace std;
DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {}
DWARFDebugRanges::~DWARFDebugRanges() {}
void DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data) {
DWARFRangeList range_list;
lldb::offset_t offset = 0;
dw_offset_t debug_ranges_offset = offset;
while (Extract(dwarf2Data, &offset, range_list)) {
range_list.Sort();
m_range_map[debug_ranges_offset] = range_list;
debug_ranges_offset = offset;
}
}
bool DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data,
lldb::offset_t *offset_ptr,
DWARFRangeList &range_list) {
range_list.Clear();
lldb::offset_t range_offset = *offset_ptr;
const DWARFDataExtractor &debug_ranges_data =
dwarf2Data->get_debug_ranges_data();
uint32_t addr_size = debug_ranges_data.GetAddressByteSize();
while (
debug_ranges_data.ValidOffsetForDataOfSize(*offset_ptr, 2 * addr_size)) {
dw_addr_t begin = debug_ranges_data.GetMaxU64(offset_ptr, addr_size);
dw_addr_t end = debug_ranges_data.GetMaxU64(offset_ptr, addr_size);
if (!begin && !end) {
// End of range list
break;
}
// Extend 4 byte addresses that consists of 32 bits of 1's to be 64 bits
// of ones
switch (addr_size) {
case 2:
if (begin == 0xFFFFull)
begin = LLDB_INVALID_ADDRESS;
break;
case 4:
if (begin == 0xFFFFFFFFull)
begin = LLDB_INVALID_ADDRESS;
break;
case 8:
break;
default:
assert(!"DWARFRangeList::Extract() unsupported address size.");
break;
}
// Filter out empty ranges
if (begin < end)
range_list.Append(DWARFRangeList::Entry(begin, end - begin));
}
// Make sure we consumed at least something
return range_offset != *offset_ptr;
}
void DWARFDebugRanges::Dump(Stream &s,
const DWARFDataExtractor &debug_ranges_data,
lldb::offset_t *offset_ptr,
dw_addr_t cu_base_addr) {
uint32_t addr_size = s.GetAddressByteSize();
bool verbose = s.GetVerbose();
dw_addr_t base_addr = cu_base_addr;
while (
debug_ranges_data.ValidOffsetForDataOfSize(*offset_ptr, 2 * addr_size)) {
dw_addr_t begin = debug_ranges_data.GetMaxU64(offset_ptr, addr_size);
dw_addr_t end = debug_ranges_data.GetMaxU64(offset_ptr, addr_size);
// Extend 4 byte addresses that consists of 32 bits of 1's to be 64 bits
// of ones
if (begin == 0xFFFFFFFFull && addr_size == 4)
begin = LLDB_INVALID_ADDRESS;
s.Indent();
if (verbose) {
s.AddressRange(begin, end, sizeof(dw_addr_t), " offsets = ");
}
if (begin == 0 && end == 0) {
s.PutCString(" End");
break;
} else if (begin == LLDB_INVALID_ADDRESS) {
// A base address selection entry
base_addr = end;
s.Address(base_addr, sizeof(dw_addr_t), " Base address = ");
} else {
// Convert from offset to an address
dw_addr_t begin_addr = begin + base_addr;
dw_addr_t end_addr = end + base_addr;
s.AddressRange(begin_addr, end_addr, sizeof(dw_addr_t),
verbose ? " ==> addrs = " : NULL);
}
}
}
bool DWARFDebugRanges::FindRanges(dw_offset_t debug_ranges_offset,
DWARFRangeList &range_list) const {
range_map_const_iterator pos = m_range_map.find(debug_ranges_offset);
if (pos != m_range_map.end()) {
range_list = pos->second;
return true;
}
return false;
}