[debuginfo-tests] r361889 - Add debuginfo-tests that use cdb on Windows

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Tue May 28 16:03:34 PDT 2019


Author: rnk
Date: Tue May 28 16:03:33 2019
New Revision: 361889

URL: http://llvm.org/viewvc/llvm-project?rev=361889&view=rev
Log:
Add debuginfo-tests that use cdb on Windows

This is an initial prototype of how we can run debugger integration
tests on Windows. cdb and windbg share a command language and debugger
engine. Visual Studio has its own, but we should at least be able to use
cdb as the basis for optimized debug info integration tests.

There's a lot of work to do here still. For example:
- Make fewer assumptions about the SDK location
- Don't assume x64 (important, I need x86 testing)
- More environment isolation, have lit setup vcvars instead of passing
  LIB and INCLUDE down.
- Write a .py file to replace the grep+sed RUN line

But, this seemed like a good enough concept to commit as is, since it's
useful to me already.

Reviewers: aprantl, zturner

Differential Revision: https://reviews.llvm.org/D54187

Added:
    debuginfo-tests/trunk/win_cdb/
    debuginfo-tests/trunk/win_cdb/README.txt
    debuginfo-tests/trunk/win_cdb/hello.c
    debuginfo-tests/trunk/win_cdb/lit.local.cfg.py
    debuginfo-tests/trunk/win_cdb/realigned-frame.cpp
Modified:
    debuginfo-tests/trunk/CMakeLists.txt
    debuginfo-tests/trunk/lit.cfg.py
    debuginfo-tests/trunk/lit.site.cfg.py.in

Modified: debuginfo-tests/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/CMakeLists.txt?rev=361889&r1=361888&r2=361889&view=diff
==============================================================================
--- debuginfo-tests/trunk/CMakeLists.txt (original)
+++ debuginfo-tests/trunk/CMakeLists.txt Tue May 28 16:03:33 2019
@@ -13,6 +13,9 @@ set(DEBUGINFO_TEST_DEPS
   not
   )
 
+# Indicate if this is an MSVC environment.
+pythonize_bool(MSVC)
+
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py

Modified: debuginfo-tests/trunk/lit.cfg.py
URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/lit.cfg.py?rev=361889&r1=361888&r2=361889&view=diff
==============================================================================
--- debuginfo-tests/trunk/lit.cfg.py (original)
+++ debuginfo-tests/trunk/lit.cfg.py Tue May 28 16:03:33 2019
@@ -38,6 +38,36 @@ config.test_source_root = os.path.join(c
 # test_exec_root: The root path where tests should be run.
 config.test_exec_root = config.debuginfo_tests_obj_root
 
+tools = [
+    ToolSubst('%test_debuginfo', command=os.path.join(
+        config.debuginfo_tests_src_root, 'test_debuginfo.pl')),
+]
+
+def get_required_attr(config, attr_name):
+  attr_value = getattr(config, attr_name, None)
+  if attr_value == None:
+    lit_config.fatal(
+      "No attribute %r in test configuration! You may need to run "
+      "tests from your build directory or add this attribute "
+      "to lit.site.cfg " % attr_name)
+  return attr_value
+
+# If this is an MSVC environment, the tests at the root of the tree are
+# unsupported. The local win_cdb test suite, however, is supported.
+is_msvc = get_required_attr(config, "is_msvc")
+if is_msvc:
+    # FIXME: We should add some llvm lit utility code to find the Windows SDK
+    # and set up the environment appopriately.
+    win_sdk = 'C:/Program Files (x86)/Windows Kits/10/'
+    arch = 'x64'
+    config.unsupported = True
+    llvm_config.with_system_environment(['LIB', 'LIBPATH', 'INCLUDE'])
+    # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from
+    # the network.
+    llvm_config.with_environment('_NT_SYMBOL_PATH', '')
+    tools.append(ToolSubst('%cdb', '"%s"' % os.path.join(win_sdk, 'Debuggers',
+                                                         arch, 'cdb.exe')))
+
 llvm_config.use_default_substitutions()
 
 # clang_src_dir is not used by these tests, but is required by
@@ -53,11 +83,6 @@ if config.llvm_use_sanitizer:
 
 tool_dirs = [config.llvm_tools_dir]
 
-tools = [
-    ToolSubst('%test_debuginfo', command=os.path.join(
-        config.debuginfo_tests_src_root, 'test_debuginfo.pl')),
-]
-
 llvm_config.add_tool_substitutions(tools, tool_dirs)
 
 lit.util.usePlatformSdkOnDarwin(config, lit_config)

Modified: debuginfo-tests/trunk/lit.site.cfg.py.in
URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/lit.site.cfg.py.in?rev=361889&r1=361888&r2=361889&view=diff
==============================================================================
--- debuginfo-tests/trunk/lit.site.cfg.py.in (original)
+++ debuginfo-tests/trunk/lit.site.cfg.py.in Tue May 28 16:03:33 2019
@@ -17,6 +17,7 @@ config.has_lld = lit.util.pythonize_bool
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.target_triple = "@TARGET_TRIPLE@"
 config.host_arch = "@HOST_ARCH@"
+config.is_msvc = @MSVC_PYBOOL@
 
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 

Added: debuginfo-tests/trunk/win_cdb/README.txt
URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/win_cdb/README.txt?rev=361889&view=auto
==============================================================================
--- debuginfo-tests/trunk/win_cdb/README.txt (added)
+++ debuginfo-tests/trunk/win_cdb/README.txt Tue May 28 16:03:33 2019
@@ -0,0 +1,6 @@
+These are debug info integration tests similar to the ones in the parent
+directory, except that these are designed to test compatibility between clang,
+lld, and cdb, the command line debugger that ships as part of the Microsoft
+Windows SDK. The debugger command language that cdb uses is very different from
+gdb and LLDB, so it's useful to be able to write some tests directly in the cdb
+command language.

Added: debuginfo-tests/trunk/win_cdb/hello.c
URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/win_cdb/hello.c?rev=361889&view=auto
==============================================================================
--- debuginfo-tests/trunk/win_cdb/hello.c (added)
+++ debuginfo-tests/trunk/win_cdb/hello.c Tue May 28 16:03:33 2019
@@ -0,0 +1,14 @@
+// RUN: %clang_cl %s -o %t.exe -fuse-ld=lld -Z7
+// RUN: grep DE[B]UGGER: %s | sed -e 's/.*DE[B]UGGER: //' > %t.script
+// RUN: %cdb -cf %t.script %t.exe | FileCheck %s --check-prefixes=DEBUGGER,CHECK
+
+#include <stdio.h>
+int main() {
+  printf("hello world\n");
+  int x = 42;
+  __debugbreak();
+  // DEBUGGER: g
+  // DEBUGGER: dv
+  // CHECK: x = 0n42
+}
+// DEBUGGER: q

Added: debuginfo-tests/trunk/win_cdb/lit.local.cfg.py
URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/win_cdb/lit.local.cfg.py?rev=361889&view=auto
==============================================================================
--- debuginfo-tests/trunk/win_cdb/lit.local.cfg.py (added)
+++ debuginfo-tests/trunk/win_cdb/lit.local.cfg.py Tue May 28 16:03:33 2019
@@ -0,0 +1,2 @@
+# The win_cdb tests are supported when cmake was run in an MSVC environment.
+config.unsupported = not config.is_msvc

Added: debuginfo-tests/trunk/win_cdb/realigned-frame.cpp
URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/win_cdb/realigned-frame.cpp?rev=361889&view=auto
==============================================================================
--- debuginfo-tests/trunk/win_cdb/realigned-frame.cpp (added)
+++ debuginfo-tests/trunk/win_cdb/realigned-frame.cpp Tue May 28 16:03:33 2019
@@ -0,0 +1,34 @@
+// RUN: %clang_cl %s -o %t.exe -fuse-ld=lld -Z7
+// RUN: grep DE[B]UGGER: %s | sed -e 's/.*DE[B]UGGER: //' > %t.script
+// RUN: %cdb -cf %t.script %t.exe | FileCheck %s --check-prefixes=DEBUGGER,CHECK
+
+// From https://llvm.org/pr38857, where we had issues with stack realignment.
+
+struct Foo {
+  int x = 42;
+  int __declspec(noinline) foo();
+  void __declspec(noinline) bar(int *a, int *b, double *c);
+};
+int Foo::foo() {
+  int a = 1;
+  int b = 2;
+  double __declspec(align(32)) force_alignment = 0.42;
+  bar(&a, &b, &force_alignment);
+  // DEBUGGER: g
+  // DEBUGGER: .frame 1
+  // DEBUGGER: dv
+  // CHECK: a = 0n1
+  // CHECK: b = 0n2
+  // CHECK: force_alignment = 0.41999{{.*}}
+  // DEBUGGER: q
+  x += (int)force_alignment;
+  return x;
+}
+void Foo::bar(int *a, int *b, double *c) {
+  __debugbreak();
+  *c += *a + *b;
+}
+int main() {
+  Foo o;
+  o.foo();
+}




More information about the llvm-commits mailing list