[pkg-d-commits] [ldc] 52/211: Debuginfo: try harder to find a suitable filename is location is empty
Matthias Klumpp
mak at moszumanska.debian.org
Sun Apr 23 22:36:09 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.1.0
in repository ldc.
commit 3ed8f25ae296d2150308caef5490a0d82a623dec
Author: Rainer Schuetze <r.sagitario at gmx.de>
Date: Sat Sep 24 11:31:50 2016 +0200
Debuginfo: try harder to find a suitable filename is location is empty
---
gen/dibuilder.cpp | 78 ++++++++++++++++++++++++++++-------------------
gen/dibuilder.h | 1 +
tests/debuginfo/srcname.d | 71 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 119 insertions(+), 31 deletions(-)
diff --git a/gen/dibuilder.cpp b/gen/dibuilder.cpp
index 22f5fe3..f7c7232 100644
--- a/gen/dibuilder.cpp
+++ b/gen/dibuilder.cpp
@@ -131,7 +131,10 @@ void ldc::DIBuilder::Declare(const Loc &loc, llvm::Value *var,
}
ldc::DIFile ldc::DIBuilder::CreateFile(Loc &loc) {
- llvm::SmallString<128> path(loc.filename ? loc.filename : "");
+ const char* filename = loc.filename;
+ if (!filename)
+ filename = IR->dmodule->srcfile->toChars();
+ llvm::SmallString<128> path(filename);
llvm::sys::fs::make_absolute(path);
return DBuilder.createFile(llvm::sys::path::filename(path),
@@ -143,6 +146,13 @@ ldc::DIFile ldc::DIBuilder::CreateFile() {
return CreateFile(loc);
}
+ldc::DIFile ldc::DIBuilder::CreateFile(Dsymbol* decl) {
+ Loc loc;
+ for (Dsymbol* sym = decl; sym && !loc.filename; sym = sym->parent)
+ loc = sym->loc;
+ return loc.filename ? CreateFile(loc) : CreateFile();
+}
+
ldc::DIType ldc::DIBuilder::CreateBasicType(Type *type) {
using namespace llvm::dwarf;
@@ -243,7 +253,7 @@ ldc::DIType ldc::DIBuilder::CreateEnumType(Type *type) {
llvm::StringRef Name = te->toChars();
unsigned LineNumber = te->sym->loc.linnum;
- ldc::DIFile File(CreateFile(te->sym->loc));
+ ldc::DIFile File(CreateFile(te->sym));
return DBuilder.createEnumerationType(
GetCU(), Name, File, LineNumber,
@@ -426,7 +436,7 @@ ldc::DIType ldc::DIBuilder::CreateCompositeType(Type *type) {
unsigned linnum = sd->loc.linnum;
ldc::DICompileUnit CU(GetCU());
assert(CU && "Compilation unit missing or corrupted");
- ldc::DIFile file = CreateFile(sd->loc);
+ ldc::DIFile file = CreateFile(sd);
ldc::DIType derivedFrom = getNullDIType();
// set diCompositeType to handle recursive types properly
@@ -735,7 +745,7 @@ ldc::DISubprogram ldc::DIBuilder::EmitSubProgram(FuncDeclaration *fd) {
assert(CU &&
"Compilation unit missing or corrupted in DIBuilder::EmitSubProgram");
- ldc::DIFile file = CreateFile(fd->loc);
+ ldc::DIFile file = CreateFile(fd);
// Create subroutine type
ldc::DISubroutineType DIFnType =
@@ -782,7 +792,7 @@ ldc::DISubprogram ldc::DIBuilder::EmitThunk(llvm::Function *Thunk,
ldc::DICompileUnit CU(GetCU());
assert(CU && "Compilation unit missing or corrupted in DIBuilder::EmitThunk");
- ldc::DIFile file = CreateFile(fd->loc);
+ ldc::DIFile file = CreateFile(fd);
// Create subroutine type (thunk has same type as wrapped function)
ldc::DISubroutineType DIFnType = CreateFunctionType(fd->type);
@@ -930,9 +940,9 @@ void ldc::DIBuilder::EmitStopPoint(Loc &loc) {
if (!global.params.symdebug)
return;
-// If we already have a location set and the current loc is invalid
-// (line 0), then we can just ignore it (see GitHub issue #998 for why we
-// cannot do this in all cases).
+ // If we already have a location set and the current loc is invalid
+ // (line 0), then we can just ignore it (see GitHub issue #998 for why we
+ // cannot do this in all cases).
#if LDC_LLVM_VER >= 307
if (!loc.linnum && IR->ir->getCurrentDebugLocation())
return;
@@ -940,13 +950,20 @@ void ldc::DIBuilder::EmitStopPoint(Loc &loc) {
if (!loc.linnum && !IR->ir->getCurrentDebugLocation().isUnknown())
return;
#endif
+ unsigned linnum = loc.linnum;
+ // without proper loc use the line of the enclosing symbol that has line
+ // number debug info
+ for (Dsymbol *sym = IR->func()->decl; sym && !linnum; sym = sym->parent)
+ linnum = sym->loc.linnum;
+ if (!linnum)
+ linnum = 1;
unsigned charnum = (loc.linnum ? loc.charnum : 0);
- Logger::println("D to dwarf stoppoint at line %u, column %u", loc.linnum,
+ Logger::println("D to dwarf stoppoint at line %u, column %u", linnum,
charnum);
LOG_SCOPE;
IR->ir->SetCurrentDebugLocation(
- llvm::DebugLoc::get(loc.linnum, charnum, GetCurrentScope()));
+ llvm::DebugLoc::get(linnum, charnum, GetCurrentScope()));
currentLoc = loc;
}
@@ -1024,7 +1041,7 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
debugVariable = DBuilder.createLocalVariable(tag, // tag
GetCurrentScope(), // scope
vd->toChars(), // name
- CreateFile(vd->loc), // file
+ CreateFile(vd), // file
vd->loc.linnum, // line num
TD, // type
true, // preserve
@@ -1034,7 +1051,7 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
debugVariable = DBuilder.createComplexVariable(tag, // tag
GetCurrentScope(), // scope
vd->toChars(), // name
- CreateFile(vd->loc), // file
+ CreateFile(vd), // file
vd->loc.linnum, // line num
TD, // type
addr);
@@ -1043,7 +1060,7 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
debugVariable = DBuilder.createLocalVariable(tag, // tag
GetCurrentScope(), // scope
vd->toChars(), // name
- CreateFile(vd->loc), // file
+ CreateFile(vd), // file
vd->loc.linnum, // line num
TD, // type
true, // preserve
@@ -1065,24 +1082,23 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
argNo++;
}
- debugVariable =
- DBuilder.createParameterVariable(GetCurrentScope(), // scope
- vd->toChars(), // name
- argNo + 1,
- CreateFile(vd->loc), // file
- vd->loc.linnum, // line num
- TD, // type
- true, // preserve
- Flags // flags
- );
+ debugVariable = DBuilder.createParameterVariable(GetCurrentScope(), // scope
+ vd->toChars(), // name
+ argNo + 1,
+ CreateFile(vd), // file
+ vd->loc.linnum, // line num
+ TD, // type
+ true, // preserve
+ Flags // flags
+ );
} else {
- debugVariable = DBuilder.createAutoVariable(GetCurrentScope(), // scope
- vd->toChars(), // name
- CreateFile(vd->loc), // file
- vd->loc.linnum, // line num
- TD, // type
- true, // preserve
- Flags // flags
+ debugVariable = DBuilder.createAutoVariable(GetCurrentScope(), // scope
+ vd->toChars(), // name
+ CreateFile(vd), // file
+ vd->loc.linnum, // line num
+ TD, // type
+ true, // preserve
+ Flags // flags
);
}
#endif
@@ -1118,7 +1134,7 @@ void ldc::DIBuilder::EmitGlobalVariable(llvm::GlobalVariable *llVar,
#endif
vd->toChars(), // name
mangle(vd), // linkage name
- CreateFile(vd->loc), // file
+ CreateFile(vd), // file
vd->loc.linnum, // line num
CreateTypeDescription(vd->type, false), // type
vd->protection.kind == PROTprivate, // is local to unit
diff --git a/gen/dibuilder.h b/gen/dibuilder.h
index 5f88f11..c44ea99 100644
--- a/gen/dibuilder.h
+++ b/gen/dibuilder.h
@@ -181,6 +181,7 @@ private:
);
DIFile CreateFile(Loc &loc);
DIFile CreateFile();
+ DIFile CreateFile(Dsymbol* decl);
DIType CreateBasicType(Type *type);
DIType CreateEnumType(Type *type);
DIType CreatePointerType(Type *type);
diff --git a/tests/debuginfo/srcname.d b/tests/debuginfo/srcname.d
new file mode 100644
index 0000000..3ddaf46
--- /dev/null
+++ b/tests/debuginfo/srcname.d
@@ -0,0 +1,71 @@
+// RUN: %ldc -g -output-ll -of=%t.ll %s
+// RUN: FileCheck %s < %t.ll
+
+// CHECK-NOT: !DIFile(filename: "."
+
+// constructs likely to produce compiler generated functions
+// or that use lowering losing source file information
+struct S1
+{
+ int x, y, z;
+ C1 c; // guarantees compiler generated compare function
+}
+
+class C1
+{
+ int c1;
+ int c2;
+ C1 next;
+}
+
+enum E1
+{
+ value1 = 1,
+}
+
+int tryCatch(void delegate() dg)
+{
+ int ret;
+ scope(failure) ret = 2;
+ scope(exit) ret = 1;
+ scope(success) ret = 3;
+ try
+ {
+ dg();
+ }
+ catch(Exception e)
+ {
+ ret = 4;
+ }
+ finally
+ {
+ ret = 5;
+ }
+ return ret;
+}
+
+void forloop(int delegate(int) dg)
+{
+ int s = 0;
+ foreach(i; 0..4)
+ s += dg(i);
+
+ int[] arr = new int[3];
+ foreach(i; arr)
+ s += dg(i);
+}
+
+void main()
+{
+ auto c1 = new C1;
+ auto c2 = new C1;
+ auto s = S1(5);
+ S1 s2;
+ s2 = s;
+ auto e = E1.value1;
+ bool scmp = s2 == s;
+ bool ccmp = c1 == c2;
+
+ tryCatch(() {});
+ forloop((int){return 1;});
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list