[Lldb-commits] [lldb] 8b68360 - [lldb] Assert on invalid index in OptionValueProperties (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue May 2 12:49:44 PDT 2023


Author: Jonas Devlieghere
Date: 2023-05-02T12:49:36-07:00
New Revision: 8b6836020464a537c829c56d34ec8f348e1f6056

URL: https://github.com/llvm/llvm-project/commit/8b6836020464a537c829c56d34ec8f348e1f6056
DIFF: https://github.com/llvm/llvm-project/commit/8b6836020464a537c829c56d34ec8f348e1f6056.diff

LOG: [lldb] Assert on invalid index in OptionValueProperties (NFC)

All indexes passed to GetPropertyAtIndex are constants generated by
ablegen. We should never pass an invalid index.

Added: 
    

Modified: 
    lldb/include/lldb/Interpreter/OptionValueProperties.h
    lldb/source/Core/Debugger.cpp
    lldb/source/Interpreter/OptionValueProperties.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Interpreter/OptionValueProperties.h b/lldb/include/lldb/Interpreter/OptionValueProperties.h
index b32bb8fa91c8..4782d7eff947 100644
--- a/lldb/include/lldb/Interpreter/OptionValueProperties.h
+++ b/lldb/include/lldb/Interpreter/OptionValueProperties.h
@@ -68,8 +68,6 @@ class OptionValueProperties
 
   // Subclass specific functions
 
-  virtual size_t GetNumProperties() const;
-
   // Get the index of a property given its exact name in this property
   // collection, "name" can't be a path to a property path that refers to a
   // property within a property
@@ -205,10 +203,12 @@ class OptionValueProperties
 
 protected:
   Property *ProtectedGetPropertyAtIndex(uint32_t idx) {
+    assert(idx < m_properties.size() && "invalid property index");
     return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
   }
 
   const Property *ProtectedGetPropertyAtIndex(uint32_t idx) const {
+    assert(idx < m_properties.size() && "invalid property index");
     return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
   }
 

diff  --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 349f1c91d1e3..ff249bc1952f 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -812,6 +812,9 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
                     GetStaticBroadcasterClass().AsCString()),
       m_forward_listener_sp(), m_clear_once() {
   m_instance_name.SetString(llvm::formatv("debugger_{0}", GetID()).str());
+  // Initialize the debugger properties as early as possible as other parts of
+  // LLDB will start querying them during construction.
+  m_collection_sp->Initialize(g_debugger_properties);
   if (log_callback)
     m_callback_handler_sp =
         std::make_shared<CallbackLogHandler>(log_callback, baton);
@@ -833,7 +836,6 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
   }
   assert(m_dummy_target_sp.get() && "Couldn't construct dummy target?");
 
-  m_collection_sp->Initialize(g_debugger_properties);
   m_collection_sp->AppendProperty(
       ConstString("target"), "Settings specify to debugging targets.", true,
       Target::GetGlobalProperties().GetValueProperties());

diff  --git a/lldb/source/Interpreter/OptionValueProperties.cpp b/lldb/source/Interpreter/OptionValueProperties.cpp
index 7f402374a12e..20d613af9481 100644
--- a/lldb/source/Interpreter/OptionValueProperties.cpp
+++ b/lldb/source/Interpreter/OptionValueProperties.cpp
@@ -22,10 +22,6 @@ using namespace lldb_private;
 
 OptionValueProperties::OptionValueProperties(ConstString name) : m_name(name) {}
 
-size_t OptionValueProperties::GetNumProperties() const {
-  return m_properties.size();
-}
-
 void OptionValueProperties::Initialize(const PropertyDefinitions &defs) {
   for (const auto &definition : defs) {
     Property property(definition);


        


More information about the lldb-commits mailing list