[Lldb-commits] [lldb] 300dce9 - [lldb] Migrate to GetPropertyAtIndexAs for FileSpecList (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu May 4 22:24:28 PDT 2023


Author: Jonas Devlieghere
Date: 2023-05-04T22:24:23-07:00
New Revision: 300dce986f656a2d787b8e882381f39746d2fc0a

URL: https://github.com/llvm/llvm-project/commit/300dce986f656a2d787b8e882381f39746d2fc0a
DIFF: https://github.com/llvm/llvm-project/commit/300dce986f656a2d787b8e882381f39746d2fc0a.diff

LOG: [lldb] Migrate to GetPropertyAtIndexAs for FileSpecList (NFC)

Use the templated GetPropertyAtIndexAs helper for FileSpecList.

Added: 
    

Modified: 
    lldb/include/lldb/Interpreter/OptionValue.h
    lldb/source/Core/ModuleList.cpp
    lldb/source/Interpreter/OptionValue.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
    lldb/source/Target/Target.cpp
    lldb/source/Target/Thread.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Interpreter/OptionValue.h b/lldb/include/lldb/Interpreter/OptionValue.h
index 41dc6c440593..8735106c3d14 100644
--- a/lldb/include/lldb/Interpreter/OptionValue.h
+++ b/lldb/include/lldb/Interpreter/OptionValue.h
@@ -14,6 +14,7 @@
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/FileSpecList.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-private-enumerations.h"
@@ -274,7 +275,9 @@ class OptionValue {
 
   bool SetFileSpecValue(FileSpec file_spec);
 
-  FileSpecList GetFileSpecListValue() const;
+  bool AppendFileSpecValue(FileSpec file_spec);
+
+  std::optional<FileSpecList> GetFileSpecListValue() const;
 
   std::optional<lldb::Format> GetFormatValue() const;
 
@@ -337,6 +340,8 @@ class OptionValue {
       return GetFormatValue();
     if constexpr (std::is_same_v<T, FileSpec>)
       return GetFileSpecValue();
+    if constexpr (std::is_same_v<T, FileSpecList>)
+      return GetFileSpecListValue();
     if constexpr (std::is_same_v<T, lldb::LanguageType>)
       return GetLanguageValue();
     if constexpr (std::is_same_v<T, llvm::StringRef>)

diff  --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 256b4afa7bd6..212b1186b4ef 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -161,9 +161,7 @@ uint64_t ModuleListProperties::GetLLDBIndexCacheExpirationDays() {
 
 void ModuleListProperties::UpdateSymlinkMappings() {
   FileSpecList list =
-      m_collection_sp
-          ->GetPropertyAtIndexAsOptionValueFileSpecList(ePropertySymLinkPaths)
-          ->GetCurrentValue();
+      GetPropertyAtIndexAs<FileSpecList>(ePropertySymLinkPaths, {});
   llvm::sys::ScopedWriter lock(m_symlink_paths_mutex);
   const bool notify = false;
   m_symlink_paths.Clear(notify);

diff  --git a/lldb/source/Interpreter/OptionValue.cpp b/lldb/source/Interpreter/OptionValue.cpp
index dd293047695a..b9da1f122ebe 100644
--- a/lldb/source/Interpreter/OptionValue.cpp
+++ b/lldb/source/Interpreter/OptionValue.cpp
@@ -312,11 +312,18 @@ bool OptionValue::SetFileSpecValue(FileSpec file_spec) {
   return false;
 }
 
-FileSpecList OptionValue::GetFileSpecListValue() const {
-  const OptionValueFileSpecList *option_value = GetAsFileSpecList();
-  if (option_value)
+bool OptionValue::AppendFileSpecValue(FileSpec file_spec) {
+  if (OptionValueFileSpecList *option_value = GetAsFileSpecList()) {
+    option_value->AppendCurrentValue(file_spec);
+    return true;
+  }
+  return false;
+}
+
+std::optional<FileSpecList> OptionValue::GetFileSpecListValue() const {
+  if (const OptionValueFileSpecList *option_value = GetAsFileSpecList())
     return option_value->GetCurrentValue();
-  return FileSpecList();
+  return {};
 }
 
 std::optional<lldb::Format> OptionValue::GetFormatValue() const {

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
index a50d35b7d40a..c29007fb9a34 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
@@ -201,10 +201,7 @@ class PlatformDarwinKernelProperties : public Properties {
 
   FileSpecList GetKextDirectories() const {
     const uint32_t idx = ePropertyKextDirectories;
-    const OptionValueFileSpecList *option_value =
-        m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(idx);
-    assert(option_value);
-    return option_value->GetCurrentValue();
+    return GetPropertyAtIndexAs<FileSpecList>(idx, {});
   }
 };
 

diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 1290281d8c27..091027342110 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -4390,26 +4390,17 @@ void TargetProperties::AppendExecutableSearchPaths(const FileSpec &dir) {
 
 FileSpecList TargetProperties::GetExecutableSearchPaths() {
   const uint32_t idx = ePropertyExecutableSearchPaths;
-  const OptionValueFileSpecList *option_value =
-      m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(idx);
-  assert(option_value);
-  return option_value->GetCurrentValue();
+  return GetPropertyAtIndexAs<FileSpecList>(idx, {});
 }
 
 FileSpecList TargetProperties::GetDebugFileSearchPaths() {
   const uint32_t idx = ePropertyDebugFileSearchPaths;
-  const OptionValueFileSpecList *option_value =
-      m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(idx);
-  assert(option_value);
-  return option_value->GetCurrentValue();
+  return GetPropertyAtIndexAs<FileSpecList>(idx, {});
 }
 
 FileSpecList TargetProperties::GetClangModuleSearchPaths() {
   const uint32_t idx = ePropertyClangModuleSearchPaths;
-  const OptionValueFileSpecList *option_value =
-      m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(idx);
-  assert(option_value);
-  return option_value->GetCurrentValue();
+  return GetPropertyAtIndexAs<FileSpecList>(idx, {});
 }
 
 bool TargetProperties::GetEnableAutoImportClangModules() const {

diff  --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index a9c01e388b13..b5caf402b66f 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -117,10 +117,7 @@ const RegularExpression *ThreadProperties::GetSymbolsToAvoidRegexp() {
 
 FileSpecList ThreadProperties::GetLibrariesToAvoid() const {
   const uint32_t idx = ePropertyStepAvoidLibraries;
-  const OptionValueFileSpecList *option_value =
-      m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(idx);
-  assert(option_value);
-  return option_value->GetCurrentValue();
+  return GetPropertyAtIndexAs<FileSpecList>(idx, {});
 }
 
 bool ThreadProperties::GetTraceEnabledState() const {


        


More information about the lldb-commits mailing list