Skip to content

Commit

Permalink
[BOLT] Fix debug info update for zero-length ranges.
Browse files Browse the repository at this point in the history
Summary:
Due to a clowntown on my part we were generating wrong ranges
when an empty range was seen on input. We were basically expanding
the range to include all basic blocks following such range and setting
wrong sizes at the same time.

Add "-dump-cu" option to llvm-dwarfdump that allows to look at debug
info of a single compile unit only. Saves time if we are only interested
in a subset of information.

(cherry picked from FBD4430989)
  • Loading branch information
maksfb committed Jan 18, 2017
1 parent 0894905 commit 1985937
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
34 changes: 23 additions & 11 deletions bolt/DebugData.cpp
Expand Up @@ -18,6 +18,9 @@
#include <algorithm>
#include <cassert>

#undef DEBUG_TYPE
#define DEBUG_TYPE "bolt-debug-info"

namespace opts {
extern llvm::cl::opt<unsigned> Verbosity;
}
Expand All @@ -31,11 +34,18 @@ void BasicBlockOffsetRanges::addAddressRange(BinaryFunction &Function,
uint64_t BeginAddress,
uint64_t EndAddress,
const BinaryData *Data) {
auto BBRange = Function.getBasicBlockRangeFromOffsetToEnd(
BeginAddress - Function.getAddress());
if (Function.getState() != BinaryFunction::State::CFG)
return;

const auto BBRange = Function.getBasicBlockRangeFromOffsetToEnd(
BeginAddress - Function.getAddress());

DEBUG(dbgs() << "adding range [0x" << Twine::utohexstr(BeginAddress) << ", 0x"
<< Twine::utohexstr(EndAddress) << ") to function " << Function
<< '\n');

if (BBRange.begin() == BBRange.end()) {
if (opts::Verbosity >= 2) {
if (opts::Verbosity >= 1) {
errs() << "BOLT-WARNING: no basic blocks in function "
<< Function << " intersect with debug range [0x"
<< Twine::utohexstr(BeginAddress) << ", 0x"
Expand All @@ -45,19 +55,21 @@ void BasicBlockOffsetRanges::addAddressRange(BinaryFunction &Function,
}

for (auto &BB : BBRange) {
uint64_t BBAddress = Function.getBasicBlockOriginalAddress(&BB);
// Note the special handling for [a, a) address range.
if (BBAddress >= EndAddress && BeginAddress != EndAddress)
const auto BBAddress = Function.getBasicBlockOriginalAddress(&BB);

// Some ranges could be of the form [BBAddress, BBAddress).
if (BBAddress > EndAddress ||
(BBAddress == EndAddress && EndAddress != BeginAddress))
break;

uint64_t InternalAddressRangeBegin = std::max(BBAddress, BeginAddress);
assert(BB.getFunction() == &Function &&
"Mismatching functions.\n");
uint64_t InternalAddressRangeEnd =
const auto InternalAddressRangeBegin = std::max(BBAddress, BeginAddress);
assert(BB.getFunction() == &Function && "mismatching functions\n");
const auto InternalAddressRangeEnd =
std::min(BBAddress + Function.getBasicBlockOriginalSize(&BB),
EndAddress);

assert(BB.isValid() && "Attempting to record debug info for a deleted BB.");
assert(BB.isValid() && "attempting to record debug info for a deleted BB.");

AddressRanges.emplace_back(
BBAddressRange{
&BB,
Expand Down
8 changes: 8 additions & 0 deletions bolt/DebugData.h
Expand Up @@ -22,6 +22,8 @@
#include <utility>
#include <vector>

#include "BinaryBasicBlock.h"

namespace llvm {

class DWARFCompileUnit;
Expand Down Expand Up @@ -107,6 +109,12 @@ class BasicBlockOffsetRanges {
uint16_t RangeEndOffset;
/// Binary data associated with this range.
const BinaryData *Data;

void print(raw_ostream &OS) const {
OS << " BasicBlock : " << BasicBlock->getName() << '\n';
OS << " StartOffset: " << RangeBeginOffset << '\n';
OS << " EndOffset: " << RangeEndOffset << '\n';
}
};

std::vector<BBAddressRange> AddressRanges;
Expand Down

0 comments on commit 1985937

Please sign in to comment.