9#include "lldb/Host/Config.h"
15#include "llvm/ADT/STLFunctionalExtras.h"
16#include "llvm/ADT/SmallString.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/ConvertUTF.h"
20#include "llvm/Support/FileSystem.h"
21#include "llvm/Support/Path.h"
22#include "llvm/Support/Windows/WindowsSupport.h"
31#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
32#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
34std::string GetModulePath(HMODULE module) {
37 DWORD len = ::GetModuleFileNameW(module, buffer.data(), buffer.size());
40 if (len < buffer.size()) {
42 if (llvm::convertWideToUTF8(std::wstring(buffer.data(), len), utf8))
46 if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
47 buffer.resize(buffer.size() * 2);
53std::string ExeRelativeCandidate() {
54#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
55 std::string exe = GetModulePath(
nullptr);
58 llvm::SmallString<MAX_PATH> path(exe);
59 llvm::sys::path::remove_filename(path);
60 llvm::sys::path::append(path, LLDB_PYTHON_DLL_RELATIVE_PATH);
61 llvm::sys::path::append(path, LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME);
62 llvm::sys::fs::make_absolute(path);
63 return std::string(path);
73 llvm::function_ref<
bool(
const char *)> callback) {
77#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
78 if (callback(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME))
82#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
83 std::string exe_relative = ExeRelativeCandidate();
84 if (!exe_relative.empty() && callback(exe_relative.c_str()))
A class that represents a running process on the host machine.
void ForEachPythonRuntimeCandidate(llvm::function_ref< bool(const char *)> callback)
Visits candidate Python runtime paths in priority order, stopping at the first call that returns true...