[Lldb-commits] [lldb] [lldb][windows] enumerate volumes via FindFirstVolumeW (PR #200231)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Fri May 29 04:28:43 PDT 2026
================
@@ -485,33 +485,73 @@ DebuggerThread::HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,
static std::optional<std::string>
ConvertNtDevicePathToDosPath(llvm::ArrayRef<wchar_t> nt_path) {
- std::array<wchar_t, 512> drive_strings;
- drive_strings[0] = L'\0';
- if (!::GetLogicalDriveStringsW(drive_strings.size(), drive_strings.data()))
+ Log *log = GetLog(WindowsLog::Event);
+
+ std::array<wchar_t, MAX_PATH> volume_name;
+ HANDLE hVolFind = ::FindFirstVolumeW(volume_name.data(), volume_name.size());
+ if (hVolFind == INVALID_HANDLE_VALUE) {
+ LLDB_LOG(log,
+ "ConvertNtDevicePathToDosPath: FindFirstVolumeW failed, error={0}",
+ ::GetLastError());
return std::nullopt;
+ }
- std::array<wchar_t, 3> drive = {L"_:"};
- for (const wchar_t *it = drive_strings.data(); *it != L'\0';
- it += wcslen(it) + 1) {
- drive[0] = it[0];
+ std::optional<std::string> result;
+ do {
+ // FindFirstVolumeW yields names of the form "\\?\Volume{GUID}\".
+ // QueryDosDeviceW expects "Volume{GUID}".
+ size_t vlen = ::wcsnlen(volume_name.data(), volume_name.size());
+ if (vlen < 5 || volume_name[vlen - 1] != L'\\')
+ continue;
+
+ volume_name[vlen - 1] = L'\0';
std::array<wchar_t, MAX_PATH> device_name;
- if (!::QueryDosDeviceW(drive.data(), device_name.data(),
- device_name.size()))
+ BOOL ok = ::QueryDosDeviceW(volume_name.data() + 4, device_name.data(),
----------------
charles-zablit wrote:
> I was going to say a stringref would allow you to drop_front('\?') instead of a magical plus 4, but would that be misleading because this string is in an unusual format?
It would yes, at the cost of adding more noise.
More generally (and for a follow up PR), I wonder if we should have wrapper classes for NT/DOS paths that would wrap those common operations. We use these magic numbers in different places accross the codebase for Windows.
https://github.com/llvm/llvm-project/pull/200231
More information about the lldb-commits
mailing list