Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions DebugIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class DIUpdater : public InstVisitor<DIUpdater> {
int tempNameCounter;

ValueMap<const Function *, DISubprogram *> SubprogramDescriptors;
ValueMap<const BasicBlock *, DILexicalBlock *> BlockDescriptors;
ValueMap<const Value *, DILexicalBlock *> ScopeDescriptors;
DenseMap<const Type *, DIType *> TypeDescriptors;

public:
Expand Down Expand Up @@ -296,9 +296,10 @@ class DIUpdater : public InstVisitor<DIUpdater> {
}

DIScope *getBlockScope(DIScope *ParentScope, const BasicBlock *B) {
auto BScope = BlockDescriptors.find(B);
if (BScope != BlockDescriptors.end()) {
return BScope->second;
auto S = BBAlwaysNewScope ? dyn_cast<Value>(B) : dyn_cast<Value>(B->getParent());
auto ScopeIt = ScopeDescriptors.find(S);
if (ScopeIt != ScopeDescriptors.end()) {
return ScopeIt->second;
} else {
// Let's build a scope for this block.
unsigned Line = 0;
Expand All @@ -308,7 +309,7 @@ class DIUpdater : public InstVisitor<DIUpdater> {
<< B->getParent()->getName().str() << "\n");
}
auto Scope = Builder.createLexicalBlock(ParentScope, FileNode, Line, 0);
BlockDescriptors[B] = Scope;
ScopeDescriptors[S] = Scope;
return Scope;
}
}
Expand Down Expand Up @@ -496,6 +497,8 @@ class DIUpdater : public InstVisitor<DIUpdater> {

namespace llvm {

bool BBAlwaysNewScope = false;

std::unique_ptr<Module> createDebugInfo(Module &M, std::string Directory,
std::string Filename) {

Expand Down
4 changes: 4 additions & 0 deletions DebugIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

namespace llvm {

// Each BasicBlock uses a different DIScope.
// Default is false.
extern bool BBAlwaysNewScope;

// Attaches debug info to M, assuming it is parsed from Directory/Filename.
// Returns a module for display in debugger devoid of any debug info.
std::unique_ptr<llvm::Module>
Expand Down
8 changes: 7 additions & 1 deletion Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ using namespace llvm;
namespace {

// Command line arguments parsed using LLVM's command line parser.
cl::opt<std::string> InputFile(cl::Positional, cl::desc("<Input file>"),
cl::opt<std::string> InputFile(cl::Positional, cl::desc("<Input files ...>"),
cl::Required);
cl::opt<bool>
RunInstNamer("instnamer",
cl::desc("Run instnamer on input, prior to processing it"));

cl::opt<bool, true>
AlwaysNew("newscope",
cl::desc("Each BasicBlock uses a different DIScope."),
cl::location(BBAlwaysNewScope),
cl::init(false));

void versionPrinter(llvm::raw_ostream &OS) { OS << "debugir: v0.1.0\n"; }

ExitOnError ExitOnErr;
Expand Down