[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:22:02 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'\\')
----------------
charles-zablit wrote:

> If backslash is known to be 1 byte then it's fine. Is that the logic?

Yes that's the logic. It's safe to index like this since `wcsnlen` counts code units and not characters.

https://github.com/llvm/llvm-project/pull/200231


More information about the lldb-commits mailing list