================ @@ -0,0 +1,99 @@ +//===-- PythonPathSetup.cpp -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Utility/PythonPathSetup/PythonPathSetup.h" + +#ifdef _WIN32 +#include "lldb/Host/windows/windows.h" +#include "llvm/Support/Windows/WindowsSupport.h" + +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/WithColor.h" + +using namespace llvm; + +#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH +/// Returns the full path to the lldb.exe executable. +inline std::wstring GetPathToExecutableW() { + // Iterate until we reach the Windows API maximum path length (32,767). + std::vector<WCHAR> buffer; + buffer.resize(MAX_PATH /*=260*/); + while (buffer.size() < 32767) { + if (GetModuleFileNameW(NULL, buffer.data(), buffer.size()) < buffer.size()) + return std::wstring(buffer.begin(), buffer.end()); + buffer.resize(buffer.size() * 2); ---------------- charles-zablit wrote:
> this is resizing the buffer even in the failure case. This is intended. `GetModuleFileNameW` fails with the same error code if the buffer is too small or if there is another failure. The only option to find the correct buffer size is to resize it until it fits (or we exceed the max buffer size). https://github.com/llvm/llvm-project/pull/179306 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
