Skip to content

Commit d502ba9

Browse files
fixup! [lldb][windows] print an error if python.dll is not in the DLL search path
1 parent 3d2976b commit d502ba9

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

lldb/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ if (LLDB_ENABLE_PYTHON)
6161
"Path to python interpreter exectuable, relative to python's install prefix")
6262
set(cachestring_LLDB_PYTHON_EXT_SUFFIX
6363
"Filename extension for native code python modules")
64-
set(cachestring_LLDB_PYTHON_SHARED_LIBRARY_NAME
65-
"Filename of Python's shared library")
64+
set(cachestring_LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
65+
"Filename of Python's runtime library")
6666

6767
foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
6868
if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
@@ -89,8 +89,7 @@ if (LLDB_ENABLE_PYTHON)
8989
set(LLDB_PYTHON_EXT_SUFFIX "_d${LLDB_PYTHON_EXT_SUFFIX}")
9090
endif()
9191
endif()
92-
set(LLDB_PYTHON_SHARED_LIBRARY_FILENAME
93-
"python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
92+
get_filename_component(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME Python3_RUNTIME_LIBRARY NAME)
9493
endif ()
9594

9695
if (LLDB_ENABLE_LUA)

lldb/tools/driver/Driver.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,21 +477,33 @@ bool AddPythonDLLToSearchPath() {
477477
}
478478
#endif
479479

480-
#ifdef LLDB_PYTHON_SHARED_LIBRARY_FILENAME
480+
#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
481481
/// Returns whether `python3x.dll` is in the DLL search path.
482482
bool IsPythonDLLInPath() {
483483
#define WIDEN2(x) L##x
484484
#define WIDEN(x) WIDEN2(x)
485485
WCHAR foundPath[MAX_PATH];
486486
DWORD result =
487-
SearchPathW(nullptr, WIDEN(LLDB_PYTHON_SHARED_LIBRARY_FILENAME), nullptr,
487+
SearchPathW(nullptr, WIDEN(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME), nullptr,
488488
MAX_PATH, foundPath, nullptr);
489489
#undef WIDEN2
490490
#undef WIDEN
491491

492492
return result > 0;
493493
}
494494
#endif
495+
496+
void SetupPythonRuntimeLibrary() {
497+
#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
498+
if (!IsPythonDLLInPath())
499+
#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
500+
if (AddPythonDLLToSearchPath())
501+
return
502+
#endif
503+
llvm::errs() << "error: unable to find "
504+
<< LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME << ".\n";
505+
#endif
506+
}
495507
#endif
496508

497509
std::string EscapeString(std::string arg) {
@@ -796,13 +808,8 @@ int main(int argc, char const *argv[]) {
796808
"~/Library/Logs/DiagnosticReports/.\n");
797809
#endif
798810

799-
#if defined(_WIN32) && defined(LLDB_PYTHON_SHARED_LIBRARY_FILENAME)
800-
if (!IsPythonDLLInPath())
801-
#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
802-
if (!AddPythonDLLToSearchPath())
803-
#endif
804-
llvm::errs() << "error: unable to find "
805-
<< LLDB_PYTHON_SHARED_LIBRARY_FILENAME << ".\n";
811+
#ifdef _WIN32
812+
SetupPythonRuntimeLibrary();
806813
#endif
807814

808815
// Parse arguments.

0 commit comments

Comments
 (0)