diff options
-rw-r--r-- | lldb/include/lldb/Breakpoint/BreakpointOptions.h | 8 | ||||
-rw-r--r-- | lldb/include/lldb/Target/ThreadSpec.h | 21 | ||||
-rw-r--r-- | lldb/source/Breakpoint/BreakpointOptions.cpp | 35 | ||||
-rw-r--r-- | lldb/source/Target/ThreadSpec.cpp | 51 |
4 files changed, 108 insertions, 7 deletions
diff --git a/lldb/include/lldb/Breakpoint/BreakpointOptions.h b/lldb/include/lldb/Breakpoint/BreakpointOptions.h index 1b72ba0dd84..791c66c81b6 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointOptions.h +++ b/lldb/include/lldb/Breakpoint/BreakpointOptions.h @@ -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: //------------------------------------------------------------------ diff --git a/lldb/include/lldb/Target/ThreadSpec.h b/lldb/include/lldb/Target/ThreadSpec.h index 36b23542dab..7b22c2835ff 100644 --- a/lldb/include/lldb/Target/ThreadSpec.h +++ b/lldb/include/lldb/Target/ThreadSpec.h @@ -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; diff --git a/lldb/source/Breakpoint/BreakpointOptions.cpp b/lldb/source/Breakpoint/BreakpointOptions.cpp index 3095f77f220..783e51c7260 100644 --- a/lldb/source/Breakpoint/BreakpointOptions.cpp +++ b/lldb/source/Breakpoint/BreakpointOptions.cpp @@ -101,9 +101,9 @@ BreakpointOptions::CommandData::CreateFromStructuredData( 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> BreakpointOptions::CreateFromStructuredData( 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 BreakpointOptions::SerializeToStructuredData() { 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::tid_t thread_id) { 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 diff --git a/lldb/source/Target/ThreadSpec.cpp b/lldb/source/Target/ThreadSpec.cpp index 1d217e00035..c7eec078612 100644 --- a/lldb/source/Target/ThreadSpec.cpp +++ b/lldb/source/Target/ThreadSpec.cpp @@ -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=(const ThreadSpec &rhs) { 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(); } |