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"
32std::string GetModulePath(HMODULE module) {
33 std::vector<WCHAR> buffer(MAX_PATH);
34 while (buffer.size() <= PATHCCH_MAX_CCH) {
35 DWORD len = ::GetModuleFileNameW(module, buffer.data(), buffer.size());
38 if (len < buffer.size()) {
40 if (llvm::convertWideToUTF8(std::wstring(buffer.data(), len), utf8))
44 if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
45 buffer.resize(buffer.size() * 2);
50#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
51std::string ExeRelativeCandidate() {
52#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
53 std::string exe = GetModulePath(
nullptr);
56 llvm::SmallString<MAX_PATH> path(exe);
57 llvm::sys::path::remove_filename(path);
58 llvm::sys::path::append(path, LLDB_PYTHON_DLL_RELATIVE_PATH);
59 llvm::sys::path::append(path, LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME);
60 llvm::sys::fs::make_absolute(path);
61 return std::string(path);
71 llvm::function_ref<
bool(
const char *)> callback) {
75#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
76 if (callback(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME))
80#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
81 std::string exe_relative = ExeRelativeCandidate();
82 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...