[Lldb-commits] [lldb] [lldb] Realpath symlinks for breakpoints (PR #102223)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 9 08:56:24 PDT 2024
================
@@ -0,0 +1,66 @@
+//===-- RealpathPrefixes.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/RealpathPrefixes.h"
+
+#include "lldb/Target/Statistics.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/FileSpecList.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+
+using namespace lldb_private;
+
+RealpathPrefixes::RealpathPrefixes(const FileSpecList &file_spec_list)
+ : m_fs(llvm::vfs::getRealFileSystem()), m_target(nullptr) {
+ m_prefixes.reserve(file_spec_list.GetSize());
+ for (const FileSpec &file_spec : file_spec_list) {
+ m_prefixes.emplace_back(file_spec.GetPath());
+ }
+}
+
+void RealpathPrefixes::SetFileSystem(
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs) {
+ m_fs = fs;
+}
+
+std::optional<FileSpec>
+RealpathPrefixes::ResolveSymlinks(const FileSpec &file_spec) const {
+ if (m_prefixes.empty())
+ return std::nullopt;
+
+ auto is_prefix = [](llvm::StringRef a, llvm::StringRef b,
+ bool case_sensitive) -> bool {
+ return case_sensitive ? a.consume_front(b) : a.consume_front_insensitive(b);
----------------
royitaqi wrote:
That's reasonable.
IIUC, the source path logic:
* Say the source-map is: /foo => /bar
* The user set breakpoint for /barqux/main.cpp:1
* It causes `PathMappingList::ReverseRemapPath()`
* STRING prefix match is successful (/bar is prefix of /barqux/main.cpp)
* qux/main.cpp is the remaining list of components
* Each COMPONENT is added onto the other side of the mapping, the /foo, as separate path components
* The result is /foo/qux/main.cpp
Overall I'd say this logic cares about components of paths. (Side note: It's a bit weird to me that the [prefix match](https://github.com/llvm/llvm-project/blob/main/lldb/source/Target/PathMappingList.cpp#L209) is done as a pure string match.)
Let me change `is_prefix` into component-sensitive, too. Probably by checking if the remaining path is empty or starts with a "/", similar to what the `is_suffix` does.
https://github.com/llvm/llvm-project/pull/102223
More information about the lldb-commits
mailing list