[Lldb-commits] [lldb] r282205 - Serilize the thread options within the breakpoint options.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 22 15:01:00 PDT 2016


Author: jingham
Date: Thu Sep 22 17:00:59 2016
New Revision: 282205

URL: http://llvm.org/viewvc/llvm-project?rev=282205&view=rev
Log:
Serilize the thread options within the breakpoint options.

Modified:
    lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h
    lldb/trunk/include/lldb/Target/ThreadSpec.h
    lldb/trunk/source/Breakpoint/BreakpointOptions.cpp
    lldb/trunk/source/Target/ThreadSpec.cpp

Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h?rev=282205&r1=282204&r2=282205&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h Thu Sep 22 17:00:59 2016
@@ -359,22 +359,24 @@ protected:
   //------------------------------------------------------------------
   // Classes that inherit from BreakpointOptions can see and modify these
   //------------------------------------------------------------------
-  enum OptionNames {
+  enum class OptionNames {
     ConditionText = 0,
     IgnoreCount,
     EnabledState,
     OneShotState,
     LastOptionName
   };
-  static const char *g_option_names[LastOptionName];
+  static const char *g_option_names[(size_t) OptionNames::LastOptionName];
 
   static const char *GetKey(enum OptionNames enum_value) {
-    return g_option_names[enum_value];
+    return g_option_names[(size_t) enum_value];
   }
 
   static bool BreakpointOptionsCallbackFunction(
       void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id,
       lldb::user_id_t break_loc_id);
+      
+  void SetThreadSpec(std::unique_ptr<ThreadSpec> &thread_spec_up);
 
 private:
   //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Target/ThreadSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadSpec.h?rev=282205&r1=282204&r2=282205&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ThreadSpec.h (original)
+++ lldb/trunk/include/lldb/Target/ThreadSpec.h Thu Sep 22 17:00:59 2016
@@ -43,6 +43,14 @@ public:
 
   const ThreadSpec &operator=(const ThreadSpec &rhs);
 
+  static std::unique_ptr<ThreadSpec>
+  CreateFromStructuredData(const StructuredData::Dictionary &data_dict,
+                           Error &error);
+
+  StructuredData::ObjectSP SerializeToStructuredData();
+
+  static const char *GetSerializationKey() { return "ThreadSpec"; }
+
   void SetIndex(uint32_t index) { m_index = index; }
 
   void SetTID(lldb::tid_t tid) { m_tid = tid; }
@@ -106,6 +114,19 @@ public:
   void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
 
 private:
+  enum class OptionNames {
+    ThreadIndex = 0,
+    ThreadID,
+    ThreadName,
+    QueueName,
+    LastOptionName
+  };
+  static const char *g_option_names[(size_t)OptionNames::LastOptionName];
+
+  static const char *GetKey(enum OptionNames enum_value) {
+    return g_option_names[(size_t) enum_value];
+  }
+
   uint32_t m_index;
   lldb::tid_t m_tid;
   std::string m_name;

Modified: lldb/trunk/source/Breakpoint/BreakpointOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointOptions.cpp?rev=282205&r1=282204&r2=282205&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointOptions.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointOptions.cpp Thu Sep 22 17:00:59 2016
@@ -101,9 +101,9 @@ BreakpointOptions::CommandData::CreateFr
     return std::unique_ptr<BreakpointOptions::CommandData>();
 }
 
-const char *BreakpointOptions::g_option_names
-    [BreakpointOptions::OptionNames::LastOptionName]{
-        "ConditionText", "IgnoreCount", "EnabledState", "OneShotState"};
+const char *BreakpointOptions::g_option_names[(
+    size_t)BreakpointOptions::OptionNames::LastOptionName]{
+    "ConditionText", "IgnoreCount", "EnabledState", "OneShotState"};
 
 bool BreakpointOptions::NullCallback(void *baton,
                                      StoppointCallbackContext *context,
@@ -232,6 +232,23 @@ std::unique_ptr<BreakpointOptions> Break
       condition_text.c_str(), enabled, ignore_count, one_shot);
   if (cmd_data_up.get())
     bp_options->SetCommandDataCallback(cmd_data_up);
+
+  StructuredData::Dictionary *thread_spec_dict;
+  success = options_dict.GetValueForKeyAsDictionary(
+      ThreadSpec::GetSerializationKey(), thread_spec_dict);
+  if (success) {
+    Error thread_spec_error;
+    std::unique_ptr<ThreadSpec> thread_spec_up =
+        ThreadSpec::CreateFromStructuredData(*thread_spec_dict,
+                                             thread_spec_error);
+    if (thread_spec_error.Fail()) {
+      error.SetErrorStringWithFormat(
+          "Failed to deserialize breakpoint thread spec options: %s.",
+          thread_spec_error.AsCString());
+      return nullptr;
+    }
+    bp_options->SetThreadSpec(thread_spec_up);
+  }
   return bp_options;
 }
 
@@ -255,7 +272,12 @@ StructuredData::ObjectSP BreakpointOptio
           BreakpointOptions::CommandData::GetSerializationKey(), commands_sp);
     }
   }
-  // FIXME: Need to serialize thread filter...
+  if (m_thread_spec_ap) {
+    StructuredData::ObjectSP thread_spec_sp =
+        m_thread_spec_ap->SerializeToStructuredData();
+    options_dict_sp->AddItem(ThreadSpec::GetSerializationKey(), thread_spec_sp);
+  }
+
   return options_dict_sp;
 }
 
@@ -369,6 +391,11 @@ void BreakpointOptions::SetThreadID(lldb
   GetThreadSpec()->SetTID(thread_id);
 }
 
+void BreakpointOptions::SetThreadSpec(
+    std::unique_ptr<ThreadSpec> &thread_spec_up) {
+  m_thread_spec_ap = std::move(thread_spec_up);
+}
+
 void BreakpointOptions::GetDescription(Stream *s,
                                        lldb::DescriptionLevel level) const {
   // Figure out if there are any options not at their default value, and only

Modified: lldb/trunk/source/Target/ThreadSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadSpec.cpp?rev=282205&r1=282204&r2=282205&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadSpec.cpp (original)
+++ lldb/trunk/source/Target/ThreadSpec.cpp Thu Sep 22 17:00:59 2016
@@ -12,11 +12,16 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Target/Thread.h"
+#include "lldb/Core/StructuredData.h"
 #include "lldb/Target/ThreadSpec.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
+const char *ThreadSpec::g_option_names[static_cast<uint32_t>(
+    ThreadSpec::OptionNames::LastOptionName)]{"Index", "ID", "Name",
+                                              "QueueName"};
+
 ThreadSpec::ThreadSpec()
     : m_index(UINT32_MAX), m_tid(LLDB_INVALID_THREAD_ID), m_name(),
       m_queue_name() {}
@@ -33,6 +38,52 @@ const ThreadSpec &ThreadSpec::operator=(
   return *this;
 }
 
+std::unique_ptr<ThreadSpec> ThreadSpec::CreateFromStructuredData(
+    const StructuredData::Dictionary &spec_dict, Error &error) {
+  uint32_t index = UINT32_MAX;
+  lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
+  std::string name;
+  std::string queue_name;
+
+  std::unique_ptr<ThreadSpec> thread_spec_up(new ThreadSpec());
+  bool success = spec_dict.GetValueForKeyAsInteger(
+      GetKey(OptionNames::ThreadIndex), index);
+  if (success)
+    thread_spec_up->SetIndex(index);
+
+  success =
+      spec_dict.GetValueForKeyAsInteger(GetKey(OptionNames::ThreadID), tid);
+  if (success)
+    thread_spec_up->SetTID(tid);
+
+  success =
+      spec_dict.GetValueForKeyAsString(GetKey(OptionNames::ThreadName), name);
+  if (success)
+    thread_spec_up->SetName(name.c_str());
+
+  success = spec_dict.GetValueForKeyAsString(GetKey(OptionNames::ThreadName),
+                                             queue_name);
+  if (success)
+    thread_spec_up->SetQueueName(queue_name.c_str());
+
+  return thread_spec_up;
+}
+
+StructuredData::ObjectSP ThreadSpec::SerializeToStructuredData() {
+  StructuredData::DictionarySP data_dict_sp(new StructuredData::Dictionary());
+
+  if (m_index != UINT32_MAX)
+    data_dict_sp->AddIntegerItem(GetKey(OptionNames::ThreadIndex), m_index);
+  if (m_tid != LLDB_INVALID_THREAD_ID)
+    data_dict_sp->AddIntegerItem(GetKey(OptionNames::ThreadID), m_tid);
+  if (!m_name.empty())
+    data_dict_sp->AddStringItem(GetKey(OptionNames::ThreadName), m_name);
+  if (!m_queue_name.empty())
+    data_dict_sp->AddStringItem(GetKey(OptionNames::QueueName), m_queue_name);
+
+  return data_dict_sp;
+}
+
 const char *ThreadSpec::GetName() const {
   return m_name.empty() ? nullptr : m_name.c_str();
 }




More information about the lldb-commits mailing list