12#include "llvm/Support/Windows/WindowsSupport.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/Support/ConvertUTF.h"
16#include "llvm/Support/FileSystem.h"
17#include "llvm/Support/Path.h"
23 std::vector<WCHAR> buffer(MAX_PATH);
24 while (buffer.size() <= PATHCCH_MAX_CCH) {
25 DWORD len = GetModuleFileNameW(module, buffer.data(), buffer.size());
28 if (len < buffer.size()) {
29 std::string buffer_utf8;
30 if (convertWideToUTF8(std::wstring(buffer.data(), len), buffer_utf8))
34 if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
35 buffer.resize(buffer.size() * 2);
43#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
44bool AddPythonDLLToSearchPath() {
49 SmallVector<char, MAX_PATH> path(path_str.begin(), path_str.end());
50 sys::path::remove_filename(path);
51 sys::path::append(path, LLDB_PYTHON_DLL_RELATIVE_PATH);
52 sys::fs::make_absolute(path);
54 SmallVector<wchar_t, 1> path_wide;
55 if (sys::windows::widenPath(path.data(), path_wide))
58 if (sys::fs::exists(path))
59 return SetDllDirectoryW(path_wide.data());
64#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
65std::optional<std::string> GetPythonDLLPath() {
67#define WIDEN(x) WIDEN2(x)
68 HMODULE h = LoadLibraryW(WIDEN(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME));
82#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
83 if (std::optional<std::string> python_path = GetPythonDLLPath())
85#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
86 if (AddPythonDLLToSearchPath()) {
87 if (std::optional<std::string> python_path = GetPythonDLLPath())
92 inconvertibleErrorCode(),
93 "unable to find '" LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
"'");
94#elif defined(LLDB_PYTHON_DLL_RELATIVE_PATH)
95 if (!AddPythonDLLToSearchPath())
97 "unable to find the Python runtime library");
static std::string GetPathToExecutable()
Returns the full path to the lldb.exe executable.
llvm::Expected< std::string > SetupPythonRuntimeLibrary()
Attempts to setup the DLL search path for the Python runtime library.
static std::string GetModulePath(HMODULE module)
static llvm::Error createStringError(const char *format, Args &&...args)