mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-21 03:37:47 +00:00
Add basic support for .debug_ranges section to LLVM's DebugInfo library.
This section (introduced in DWARF-3) is used to define instruction address ranges for functions that are not contiguous and can't be described by low_pc/high_pc attributes (this is the usual case for inlined subroutines). The patch is the first step to support fetching complete inlining info from DWARF. Reviewed by Benjamin Kramer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162657 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
903090c55e
commit
eceb5b9977
@ -81,7 +81,8 @@ public:
|
||||
StringRef abbrevSection,
|
||||
StringRef aRangeSection = StringRef(),
|
||||
StringRef lineSection = StringRef(),
|
||||
StringRef stringSection = StringRef());
|
||||
StringRef stringSection = StringRef(),
|
||||
StringRef rangeSection = StringRef());
|
||||
|
||||
virtual void dump(raw_ostream &OS) = 0;
|
||||
|
||||
|
@ -18,7 +18,9 @@ DIContext *DIContext::getDWARFContext(bool isLittleEndian,
|
||||
StringRef abbrevSection,
|
||||
StringRef aRangeSection,
|
||||
StringRef lineSection,
|
||||
StringRef stringSection) {
|
||||
StringRef stringSection,
|
||||
StringRef rangeSection) {
|
||||
return new DWARFContextInMemory(isLittleEndian, infoSection, abbrevSection,
|
||||
aRangeSection, lineSection, stringSection);
|
||||
aRangeSection, lineSection, stringSection,
|
||||
rangeSection);
|
||||
}
|
||||
|
@ -32,15 +32,17 @@ void DWARFContext::dump(raw_ostream &OS) {
|
||||
while (set.extract(arangesData, &offset))
|
||||
set.dump(OS);
|
||||
|
||||
uint8_t savedAddressByteSize = 0;
|
||||
OS << "\n.debug_lines contents:\n";
|
||||
for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i) {
|
||||
DWARFCompileUnit *cu = getCompileUnitAtIndex(i);
|
||||
savedAddressByteSize = cu->getAddressByteSize();
|
||||
unsigned stmtOffset =
|
||||
cu->getCompileUnitDIE()->getAttributeValueAsUnsigned(cu, DW_AT_stmt_list,
|
||||
-1U);
|
||||
if (stmtOffset != -1U) {
|
||||
DataExtractor lineData(getLineSection(), isLittleEndian(),
|
||||
cu->getAddressByteSize());
|
||||
savedAddressByteSize);
|
||||
DWARFDebugLine::DumpingState state(OS);
|
||||
DWARFDebugLine::parseStatementTable(lineData, &stmtOffset, state);
|
||||
}
|
||||
@ -54,6 +56,18 @@ void DWARFContext::dump(raw_ostream &OS) {
|
||||
OS << format("0x%8.8x: \"%s\"\n", lastOffset, s);
|
||||
lastOffset = offset;
|
||||
}
|
||||
|
||||
OS << "\n.debug_ranges contents:\n";
|
||||
// In fact, different compile units may have different address byte
|
||||
// sizes, but for simplicity we just use the address byte size of the last
|
||||
// compile unit (there is no easy and fast way to associate address range
|
||||
// list and the compile unit it describes).
|
||||
DataExtractor rangesData(getRangeSection(), isLittleEndian(),
|
||||
savedAddressByteSize);
|
||||
offset = 0;
|
||||
DWARFDebugRangeList rangeList;
|
||||
while (rangeList.extract(rangesData, &offset))
|
||||
rangeList.dump(OS);
|
||||
}
|
||||
|
||||
const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "DWARFCompileUnit.h"
|
||||
#include "DWARFDebugAranges.h"
|
||||
#include "DWARFDebugLine.h"
|
||||
#include "DWARFDebugRangeList.h"
|
||||
#include "llvm/DebugInfo/DIContext.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
@ -76,6 +77,7 @@ public:
|
||||
virtual StringRef getARangeSection() = 0;
|
||||
virtual StringRef getLineSection() = 0;
|
||||
virtual StringRef getStringSection() = 0;
|
||||
virtual StringRef getRangeSection() = 0;
|
||||
|
||||
static bool isSupportedVersion(unsigned version) {
|
||||
return version == 2 || version == 3;
|
||||
@ -93,19 +95,22 @@ class DWARFContextInMemory : public DWARFContext {
|
||||
StringRef ARangeSection;
|
||||
StringRef LineSection;
|
||||
StringRef StringSection;
|
||||
StringRef RangeSection;
|
||||
public:
|
||||
DWARFContextInMemory(bool isLittleEndian,
|
||||
StringRef infoSection,
|
||||
StringRef abbrevSection,
|
||||
StringRef aRangeSection,
|
||||
StringRef lineSection,
|
||||
StringRef stringSection)
|
||||
StringRef stringSection,
|
||||
StringRef rangeSection)
|
||||
: DWARFContext(isLittleEndian),
|
||||
InfoSection(infoSection),
|
||||
AbbrevSection(abbrevSection),
|
||||
ARangeSection(aRangeSection),
|
||||
LineSection(lineSection),
|
||||
StringSection(stringSection)
|
||||
StringSection(stringSection),
|
||||
RangeSection(rangeSection)
|
||||
{}
|
||||
|
||||
virtual StringRef getInfoSection() { return InfoSection; }
|
||||
@ -113,6 +118,7 @@ public:
|
||||
virtual StringRef getARangeSection() { return ARangeSection; }
|
||||
virtual StringRef getLineSection() { return LineSection; }
|
||||
virtual StringRef getStringSection() { return StringSection; }
|
||||
virtual StringRef getRangeSection() { return RangeSection; }
|
||||
};
|
||||
|
||||
}
|
||||
|
58
lib/DebugInfo/DWARFDebugRangeList.cpp
Normal file
58
lib/DebugInfo/DWARFDebugRangeList.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
//===-- DWARFDebugRangesList.cpp ------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "DWARFDebugRangeList.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
void DWARFDebugRangeList::clear() {
|
||||
Offset = -1U;
|
||||
AddressSize = 0;
|
||||
Entries.clear();
|
||||
}
|
||||
|
||||
bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr) {
|
||||
clear();
|
||||
if (!data.isValidOffset(*offset_ptr))
|
||||
return false;
|
||||
AddressSize = data.getAddressSize();
|
||||
if (AddressSize != 4 && AddressSize != 8)
|
||||
return false;
|
||||
Offset = *offset_ptr;
|
||||
while (true) {
|
||||
RangeListEntry entry;
|
||||
uint32_t prev_offset = *offset_ptr;
|
||||
entry.StartAddress = data.getAddress(offset_ptr);
|
||||
entry.EndAddress = data.getAddress(offset_ptr);
|
||||
// Check that both values were extracted correctly.
|
||||
if (*offset_ptr != prev_offset + 2 * AddressSize) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
// The end of any given range list is marked by an end of list entry,
|
||||
// which consists of a 0 for the beginning address offset
|
||||
// and a 0 for the ending address offset.
|
||||
if (entry.StartAddress == 0 && entry.EndAddress == 0)
|
||||
break;
|
||||
Entries.push_back(entry);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DWARFDebugRangeList::dump(raw_ostream &OS) const {
|
||||
for (int i = 0, n = Entries.size(); i != n; ++i) {
|
||||
const char *format_str = (AddressSize == 4) ? "%08x %08x %08x\n"
|
||||
: "%08x %016x %016x\n";
|
||||
OS << format(format_str, Offset, Entries[i].StartAddress,
|
||||
Entries[i].EndAddress);
|
||||
}
|
||||
OS << format("%08x <End of list>\n", Offset);
|
||||
}
|
51
lib/DebugInfo/DWARFDebugRangeList.h
Normal file
51
lib/DebugInfo/DWARFDebugRangeList.h
Normal file
@ -0,0 +1,51 @@
|
||||
//===-- DWARFDebugRangeList.h -----------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H
|
||||
#define LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H
|
||||
|
||||
#include "llvm/Support/DataExtractor.h"
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class raw_ostream;
|
||||
|
||||
class DWARFDebugRangeList {
|
||||
public:
|
||||
struct RangeListEntry {
|
||||
// A beginning address offset. This address offset has the size of an
|
||||
// address and is relative to the applicable base address of the
|
||||
// compilation unit referencing this range list. It marks the beginning
|
||||
// of an address range.
|
||||
uint64_t StartAddress;
|
||||
// An ending address offset. This address offset again has the size of
|
||||
// an address and is relative to the applicable base address of the
|
||||
// compilation unit referencing this range list. It marks the first
|
||||
// address past the end of the address range. The ending address must
|
||||
// be greater than or equal to the beginning address.
|
||||
uint64_t EndAddress;
|
||||
};
|
||||
|
||||
private:
|
||||
// Offset in .debug_ranges section.
|
||||
uint32_t Offset;
|
||||
uint8_t AddressSize;
|
||||
std::vector<RangeListEntry> Entries;
|
||||
|
||||
public:
|
||||
DWARFDebugRangeList() { clear(); }
|
||||
void clear();
|
||||
void dump(raw_ostream &OS) const;
|
||||
bool extract(DataExtractor data, uint32_t *offset_ptr);
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H
|
@ -17,6 +17,8 @@ RUN: --address=0x56d --functions | FileCheck %s -check-prefix INCLUDE_TEST_2
|
||||
RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test4.elf-x86-64 \
|
||||
RUN: --address=0x55c --functions \
|
||||
RUN: | FileCheck %s -check-prefix MANY_SEQ_IN_LINE_TABLE
|
||||
RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test4.elf-x86-64 \
|
||||
RUN: | FileCheck %s -check-prefix DEBUG_RANGES
|
||||
|
||||
MAIN: main
|
||||
MAIN-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test.cc:16:10
|
||||
@ -44,3 +46,11 @@ INCLUDE_TEST_2-NEXT: /tmp/include{{[/\\]}}decl.h:5:0
|
||||
|
||||
MANY_SEQ_IN_LINE_TABLE: _Z1cv
|
||||
MANY_SEQ_IN_LINE_TABLE-NEXT: /tmp/dbginfo/sequences{{[/\\]}}c.cc:2:0
|
||||
|
||||
DEBUG_RANGES: .debug_ranges contents:
|
||||
DEBUG_RANGES-NEXT: 00000000 000000000000055c 0000000000000567
|
||||
DEBUG_RANGES-NEXT: 00000000 0000000000000567 000000000000056d
|
||||
DEBUG_RANGES-NEXT: 00000000 <End of list>
|
||||
DEBUG_RANGES-NEXT: 00000030 0000000000000570 000000000000057b
|
||||
DEBUG_RANGES-NEXT: 00000030 0000000000000567 000000000000056d
|
||||
DEBUG_RANGES-NEXT: 00000030 <End of list>
|
||||
|
@ -59,6 +59,7 @@ static void DumpInput(const StringRef &Filename) {
|
||||
StringRef DebugLineSection;
|
||||
StringRef DebugArangesSection;
|
||||
StringRef DebugStringSection;
|
||||
StringRef DebugRangesSection;
|
||||
|
||||
error_code ec;
|
||||
for (section_iterator i = Obj->begin_sections(),
|
||||
@ -82,6 +83,8 @@ static void DumpInput(const StringRef &Filename) {
|
||||
DebugArangesSection = data;
|
||||
else if (name == "debug_str")
|
||||
DebugStringSection = data;
|
||||
else if (name == "debug_ranges")
|
||||
DebugRangesSection = data;
|
||||
}
|
||||
|
||||
OwningPtr<DIContext> dictx(DIContext::getDWARFContext(/*FIXME*/true,
|
||||
@ -89,7 +92,8 @@ static void DumpInput(const StringRef &Filename) {
|
||||
DebugAbbrevSection,
|
||||
DebugArangesSection,
|
||||
DebugLineSection,
|
||||
DebugStringSection));
|
||||
DebugStringSection,
|
||||
DebugRangesSection));
|
||||
if (Address == -1ULL) {
|
||||
outs() << Filename
|
||||
<< ":\tfile format " << Obj->getFileFormatName() << "\n\n";
|
||||
|
Loading…
x
Reference in New Issue
Block a user