Serilize the thread options within the breakpoint options.

llvm-svn: 282205
This commit is contained in:
Jim Ingham 2016-09-22 22:00:59 +00:00
parent 547ebad0b9
commit 778ef39294
4 changed files with 108 additions and 7 deletions

View File

@ -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:
//------------------------------------------------------------------

View File

@ -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;

View File

@ -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

View File

@ -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();
}