[pkg-d-commits] [ldc] 76/211: Win64 workaround: Emit slice and vector params as DI locals

Matthias Klumpp mak at moszumanska.debian.org
Sun Apr 23 22:36:11 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 6b6cafcd602d9ed2255aa2529abc79793ac23d0b
Author: Martin <noone at nowhere.com>
Date:   Mon Oct 10 20:36:17 2016 +0200

    Win64 workaround: Emit slice and vector params as DI locals
    
    This works for both cdb/Windbg and Visual Studio debuggers, otherwise the
    DI values are garbage in both debuggers too.
---
 gen/dibuilder.cpp             | 12 +++++++++++-
 gen/dibuilder.h               |  2 ++
 tests/debuginfo/args_cdb.d    | 25 ++++++++++++++++++++-----
 tests/debuginfo/strings_cdb.d |  5 ++---
 4 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/gen/dibuilder.cpp b/gen/dibuilder.cpp
index 1f872e4..813b9e7 100644
--- a/gen/dibuilder.cpp
+++ b/gen/dibuilder.cpp
@@ -98,7 +98,9 @@ Module *ldc::DIBuilder::getDefinedModule(Dsymbol *s) {
 ////////////////////////////////////////////////////////////////////////////////
 
 ldc::DIBuilder::DIBuilder(IRState *const IR)
-    : IR(IR), DBuilder(IR->module), CUNode(nullptr) {}
+    : IR(IR), DBuilder(IR->module), CUNode(nullptr),
+      isTargetMSVCx64(global.params.targetTriple->isWindowsMSVCEnvironment() &&
+                      global.params.targetTriple->isArch64Bit()) {}
 
 llvm::LLVMContext &ldc::DIBuilder::getContext() { return IR->context(); }
 
@@ -1028,6 +1030,14 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
 #else
     TD = DBuilder.createReferenceType(llvm::dwarf::DW_TAG_reference_type, TD);
 #endif
+  } else {
+    // FIXME: For MSVC x64 targets, declare dynamic array and vector parameters
+    //        as DI locals to work around garbage for both cdb and VS debuggers.
+    if (isTargetMSVCx64) {
+      TY ty = type->toBasetype()->ty;
+      if (ty == Tarray || ty == Tvector)
+        forceAsLocal = true;
+    }
   }
 
   // get variable description
diff --git a/gen/dibuilder.h b/gen/dibuilder.h
index 6bc4200..92fc80f 100644
--- a/gen/dibuilder.h
+++ b/gen/dibuilder.h
@@ -79,6 +79,8 @@ class DIBuilder {
   const llvm::MDNode *CUNode;
 #endif
 
+  const bool isTargetMSVCx64;
+
   DICompileUnit GetCU() {
 #if LDC_LLVM_VER >= 307
     return CUNode;
diff --git a/tests/debuginfo/args_cdb.d b/tests/debuginfo/args_cdb.d
index 55cdffc..b12c0b9 100644
--- a/tests/debuginfo/args_cdb.d
+++ b/tests/debuginfo/args_cdb.d
@@ -40,18 +40,22 @@ int byValue(ubyte ub, ushort us, uint ui, ulong ul,
 // x64: int delegate() * dg =
 // x86: int delegate() dg =
 // CHECK: <function> * fun = {{0x[0-9a-f`]*}}
-// x64: struct int[] * slice =
 // x86: struct int[] slice =
 // CHECK: unsigned char * aa = {{0x[0-9a-f`]*}}
 // "Internal implementation error for fa" with cdb on x64, ok in VS
 // x86: unsigned char [16] fa
-// CHECK: float [4] f4 = float [4]
-// CHECK: double [4] d4 = double [4]
+// x86: float [4] f4 = float [4]
+// x86: double [4] d4 = double [4]
 // x64: Interface * ifc
 // x86: Interface ifc
 // CHECK: struct TypeInfo_Class * ti = {{0x[0-9a-f`]*}}
 // CHECK: void * np = {{0x[0`]*}}
 
+// params emitted as locals (listed after params) for Win64:
+// x64: struct int[] slice
+// x64: float [4] f4 = float [4]
+// x64: double [4] d4 = double [4]
+
 // check arguments with indirections
 // CDB: ?? c
 // CHECK: cdouble
@@ -64,10 +68,21 @@ int byValue(ubyte ub, ushort us, uint ui, ulong ul,
 // CHECK-NEXT: funcptr
 // CHECK-SAME: args_cdb.main.__lambda
 
+// CDB: ?? slice
+// CHECK: struct int[]
+// CHECK-NEXT: length : 2
+// CHECK-NEXT: ptr
+
 // CDB: ?? fa[1]
 // "Internal implementation error for fa" with cdb on x64, ok in VS
 // no-x86: unsigned char 0x0e (displays 0xf6)
 
+// CDB: ?? f4[1]
+// CHECK: float 16
+
+// CDB: ?? d4[2]
+// CHECK: double 17
+
 // CDB: ?? ifc
 // CHECK: Interface
 // CHECK-NEXT: classinfo
@@ -87,7 +102,7 @@ int byPtr(ubyte* ub, ushort* us, uint* ui, ulong* ul,
           float4* f4, double4* d4,
           Interface* ifc, TypeInfo_Class* ti, typeof(null)* np)
 {
-// CDB: bp `args_cdb.d:91`
+// CDB: bp `args_cdb.d:106`
 // CDB: g
     return 3;
 // CHECK: !args_cdb.byPtr
@@ -148,7 +163,7 @@ int byRef(ref ubyte ub, ref ushort us, ref uint ui, ref ulong ul,
           ref float4 f4, ref double4 d4,
           ref Interface ifc, ref TypeInfo_Class ti, ref typeof(null) np)
 {
-// CDB: bp `args_cdb.d:203`
+// CDB: bp `args_cdb.d:218`
 // CDB: g
 // CHECK: !args_cdb.byRef
 
diff --git a/tests/debuginfo/strings_cdb.d b/tests/debuginfo/strings_cdb.d
index 9558a88..1c9c2a1 100644
--- a/tests/debuginfo/strings_cdb.d
+++ b/tests/debuginfo/strings_cdb.d
@@ -43,8 +43,7 @@ int main(string[] args)
 // CHECK: +[[OFF]] ptr {{ *}}: [[PTR]]
 
 // CDB: dv /t
-// x64: string[] * args
-// x86: string[] args
+// CHECK: string[] args
 // CHECK: string[] nargs
 // CHECK: string ns
 // CHECK: string ws
@@ -53,7 +52,7 @@ int main(string[] args)
 // CDB: ?? ns
 // CHECK: +0x000 length {{ *}}: 1
 // CHECK: +[[OFF]] ptr {{ *}}: 0x{{[0-9a-f`]* *}} "a"
-// CDB: ?? nargs.ptr[0]
+// CDB: ?? args.ptr[0]
 // CHECK: +0x000 length
 // CHECK: +[[OFF]] ptr {{ *}}: 0x{{[0-9a-f`]* *".*exe.*"}}
 }

-- 
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