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/Path.h"
21#include "llvm/Support/Windows/WindowsSupport.h"
31std::string GetModulePath(HMODULE module) {
32 std::vector<WCHAR> buffer(MAX_PATH);
33 while (buffer.size() <= PATHCCH_MAX_CCH) {
34 DWORD len = ::GetModuleFileNameW(module, buffer.data(), buffer.size());
37 if (len < buffer.size()) {
39 if (llvm::convertWideToUTF8(std::wstring(buffer.data(), len), utf8))
43 if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
44 buffer.resize(buffer.size() * 2);
49#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
50std::string ExeRelativeCandidate() {
51#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
52 std::string exe = GetModulePath(
nullptr);
55 llvm::SmallString<MAX_PATH> path(exe);
56 llvm::sys::path::remove_filename(path);
57 llvm::sys::path::append(path, LLDB_PYTHON_DLL_RELATIVE_PATH);
58 llvm::sys::path::append(path, LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME);
59 llvm::sys::fs::make_absolute(path);
60 return std::string(path);
70 llvm::function_ref<
bool(
const char *)> callback) {
74#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
75 if (callback(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME))
79#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
80 std::string exe_relative = ExeRelativeCandidate();
81 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...