[Lldb-commits] [lldb] r213410 - Make lldb -P work on Windows.

Zachary Turner zturner at google.com
Fri Jul 18 13:36:08 PDT 2014


Author: zturner
Date: Fri Jul 18 15:36:08 2014
New Revision: 213410

URL: http://llvm.org/viewvc/llvm-project?rev=213410&view=rev
Log:
Make lldb -P work on Windows.

lldb -P, which outputs its python path, works by using Host-layer
facilities to get information about the loaded python module.  This
Host functionality was unimplemented on Windows, so this patch
implements it.  Additionally, it removes a pexpect dependency from
the test runner and uses an equivalent invocation of subprocess.

Reviewed by: Todd Fiala

Differential Revision: http://reviews.llvm.org/D4548

Modified:
    lldb/trunk/source/Host/common/Host.cpp
    lldb/trunk/source/Host/windows/Host.cpp
    lldb/trunk/test/dotest.py

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=213410&r1=213409&r2=213410&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Fri Jul 18 15:36:08 2014
@@ -1152,6 +1152,10 @@ Host::GetLLDBPath (PathType path_type, F
                 {
                     char raw_path[PATH_MAX];
                     char resolved_path[PATH_MAX];
+#if defined(_WIN32)
+                    lldb_file_spec.AppendPathComponent("../lib/site-packages");
+                    lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
+#else
                     lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
 
 #if defined (__APPLE__)
@@ -1174,7 +1178,7 @@ Host::GetLLDBPath (PathType path_type, F
 
                         ::strncat(raw_path, python_version_dir.c_str(),
                                   sizeof(raw_path) - strlen(raw_path) - 1);
-
+#endif
 #if defined (__APPLE__)
                     }
 #endif

Modified: lldb/trunk/source/Host/windows/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Host.cpp?rev=213410&r1=213409&r2=213410&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Host.cpp (original)
+++ lldb/trunk/source/Host/windows/Host.cpp Fri Jul 18 15:36:08 2014
@@ -247,6 +247,20 @@ FileSpec
 Host::GetModuleFileSpecForHostAddress (const void *host_addr)
 {
     FileSpec module_filespec;
+
+    HMODULE hmodule = NULL;
+    if (!::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)host_addr, &hmodule))
+        return module_filespec;
+
+    std::vector<char> buffer(MAX_PATH);
+    DWORD chars_copied = 0;
+    do {
+        chars_copied = ::GetModuleFileName(hmodule, &buffer[0], buffer.size());
+        if (chars_copied == buffer.size() && ::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+            buffer.resize(buffer.size() * 2);
+    } while (chars_copied >= buffer.size());
+
+    module_filespec.SetFile(&buffer[0], false);
     return module_filespec;
 }
 

Modified: lldb/trunk/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=213410&r1=213409&r2=213410&view=diff
==============================================================================
--- lldb/trunk/test/dotest.py (original)
+++ lldb/trunk/test/dotest.py Fri Jul 18 15:36:08 2014
@@ -1004,17 +1004,17 @@ def setupSysPath():
         
         # If our lldb supports the -P option, use it to find the python path:
         init_in_python_dir = 'lldb/__init__.py'
-        import pexpect
         lldb_dash_p_result = None
 
         if lldbHere:
-            lldb_dash_p_result = pexpect.run("%s -P"%(lldbHere))
+            lldb_dash_p_result = subprocess.check_output([lldbHere, "-P"], stderr=subprocess.STDOUT)
         elif lldbExec:
-            lldb_dash_p_result = pexpect.run("%s -P"%(lldbExec))
+            lldb_dash_p_result = subprocess.check_output([lldbExec, "-P"], stderr=subprocess.STDOUT)
 
-        if lldb_dash_p_result and not lldb_dash_p_result.startswith(("<", "lldb: invalid option:")):
+        if lldb_dash_p_result and not lldb_dash_p_result.startswith(("<", "lldb: invalid option:")) \
+							  and not lldb_dash_p_result.startswith("Traceback"):
             lines = lldb_dash_p_result.splitlines()
-            if len(lines) == 1 and os.path.isfile(os.path.join(lines[0], init_in_python_dir)):
+            if len(lines) >= 1 and os.path.isfile(os.path.join(lines[0], init_in_python_dir)):
                 lldbPath = lines[0]
                 if "freebsd" in sys.platform or "linux" in sys.platform:
                     os.environ['LLDB_LIB_DIR'] = os.path.join(lldbPath, '..', '..')





More information about the lldb-commits mailing list