diff options
author | Jim Ingham <jingham@apple.com> | 2016-09-20 22:54:49 +0000 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2016-09-20 22:54:49 +0000 |
commit | 92d1960e3b63c4c9ca7e7af3463b39c46864c792 (patch) | |
tree | d8df5f1e30f279fa1a51213dc92d6899029d1cde /lldb/source | |
parent | b6b8f6c308ce165bc58a25f25f2226c18614e344 (diff) | |
download | bcm5719-llvm-92d1960e3b63c4c9ca7e7af3463b39c46864c792.tar.gz bcm5719-llvm-92d1960e3b63c4c9ca7e7af3463b39c46864c792.zip |
Add some more tests for breakpoint serialization.
Serialize breakpoint names & the hardware_requested attributes.
Also added a few missing affordances to SBBreakpoint whose absence
writing the tests pointed out.
<rdar://problem/12611863>
llvm-svn: 282036
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/API/SBBreakpoint.cpp | 25 | ||||
-rw-r--r-- | lldb/source/API/SBStringList.cpp | 6 | ||||
-rw-r--r-- | lldb/source/API/SBTarget.cpp | 18 | ||||
-rw-r--r-- | lldb/source/Breakpoint/Breakpoint.cpp | 38 | ||||
-rw-r--r-- | lldb/source/Breakpoint/BreakpointOptions.cpp | 46 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectBreakpointCommand.cpp | 4 |
6 files changed, 122 insertions, 15 deletions
diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index 7276713b1f9..7194101df53 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -448,6 +448,31 @@ size_t SBBreakpoint::GetNumLocations() const { return num_locs; } +void SBBreakpoint::SetCommandLineCommands(SBStringList &commands) { + if (!m_opaque_sp) + return; + if (commands.GetSize() == 0) + return; + + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up( + new BreakpointOptions::CommandData(*commands)); + + m_opaque_sp->GetOptions()->SetCommandDataCallback(cmd_data_up); +} + +bool SBBreakpoint::GetCommandLineCommands(SBStringList &commands) { + if (!m_opaque_sp) + return false; + StringList command_list; + bool has_commands = + m_opaque_sp->GetOptions()->GetCommandLineCallbacks(command_list); + if (has_commands) + commands.AppendList(command_list); + return has_commands; +} + bool SBBreakpoint::GetDescription(SBStream &s) { return GetDescription(s, true); } diff --git a/lldb/source/API/SBStringList.cpp b/lldb/source/API/SBStringList.cpp index 34465f76f61..075ee0d5bc4 100644 --- a/lldb/source/API/SBStringList.cpp +++ b/lldb/source/API/SBStringList.cpp @@ -75,6 +75,12 @@ void SBStringList::AppendList(const SBStringList &strings) { } } +void SBStringList::AppendList(const StringList &strings) { + if (!IsValid()) + m_opaque_ap.reset(new lldb_private::StringList()); + m_opaque_ap->AppendList(strings); +} + uint32_t SBStringList::GetSize() const { if (IsValid()) { return m_opaque_ap->GetSize(); diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 66d375aa457..7cf9215aab8 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -661,6 +661,14 @@ SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, SBBreakpoint SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, uint32_t line, lldb::addr_t offset) { + SBFileSpecList empty_list; + return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list); +} + +SBBreakpoint +SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, + uint32_t line, lldb::addr_t offset, + SBFileSpecList &sb_module_list) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); SBBreakpoint sb_bp; @@ -673,9 +681,13 @@ SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, const bool internal = false; const bool hardware = false; const LazyBool move_to_nearest_code = eLazyBoolCalculate; - *sb_bp = target_sp->CreateBreakpoint(NULL, *sb_file_spec, line, offset, - check_inlines, skip_prologue, internal, - hardware, move_to_nearest_code); + const FileSpecList *module_list = nullptr; + if (sb_module_list.GetSize() > 0) { + module_list = sb_module_list.get(); + } + *sb_bp = target_sp->CreateBreakpoint( + module_list, *sb_file_spec, line, offset, check_inlines, skip_prologue, + internal, hardware, move_to_nearest_code); } if (log) { diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp index 567ceaaee24..a9666f4bc21 100644 --- a/lldb/source/Breakpoint/Breakpoint.cpp +++ b/lldb/source/Breakpoint/Breakpoint.cpp @@ -41,6 +41,9 @@ const ConstString &Breakpoint::GetEventIdentifier() { return g_identifier; } +const char *Breakpoint::g_option_names[static_cast<uint32_t>( + Breakpoint::OptionNames::LastOptionName)]{"Names", "Hardware"}; + //---------------------------------------------------------------------- // Breakpoint constructor //---------------------------------------------------------------------- @@ -81,6 +84,19 @@ StructuredData::ObjectSP Breakpoint::SerializeToStructuredData() { StructuredData::DictionarySP breakpoint_contents_sp( new StructuredData::Dictionary()); + if (!m_name_list.empty()) { + StructuredData::ArraySP names_array_sp(new StructuredData::Array()); + for (auto name : m_name_list) { + names_array_sp->AddItem( + StructuredData::StringSP(new StructuredData::String(name))); + } + breakpoint_contents_sp->AddItem(Breakpoint::GetKey(OptionNames::Names), + names_array_sp); + } + + breakpoint_contents_sp->AddBooleanItem( + Breakpoint::GetKey(OptionNames::Hardware), m_hardware); + StructuredData::ObjectSP resolver_dict_sp( m_resolver_sp->SerializeToStructuredData()); if (!resolver_dict_sp) @@ -172,11 +188,31 @@ lldb::BreakpointSP Breakpoint::CreateFromStructuredData( return result_sp; } } + + bool hardware = false; + success = breakpoint_dict->GetValueForKeyAsBoolean( + Breakpoint::GetKey(OptionNames::Hardware), hardware); + result_sp = - target.CreateBreakpoint(filter_sp, resolver_sp, false, false, true); + target.CreateBreakpoint(filter_sp, resolver_sp, false, hardware, true); + if (result_sp && options_up) { result_sp->m_options_up = std::move(options_up); } + + StructuredData::Array *names_array; + success = breakpoint_dict->GetValueForKeyAsArray( + Breakpoint::GetKey(OptionNames::Names), names_array); + if (success && names_array) { + size_t num_names = names_array->GetSize(); + for (size_t i = 0; i < num_names; i++) { + std::string name; + Error error; + success = names_array->GetItemAtIndexAsString(i, name); + result_sp->AddName(name.c_str(), error); + } + } + return result_sp; } diff --git a/lldb/source/Breakpoint/BreakpointOptions.cpp b/lldb/source/Breakpoint/BreakpointOptions.cpp index d55a3447e5d..3095f77f220 100644 --- a/lldb/source/Breakpoint/BreakpointOptions.cpp +++ b/lldb/source/Breakpoint/BreakpointOptions.cpp @@ -66,26 +66,39 @@ std::unique_ptr<BreakpointOptions::CommandData> BreakpointOptions::CommandData::CreateFromStructuredData( const StructuredData::Dictionary &options_dict, Error &error) { std::string script_source; - CommandData *data = new CommandData(); + std::unique_ptr<CommandData> data_up(new CommandData()); + bool found_something = false; + bool success = options_dict.GetValueForKeyAsBoolean( - GetKey(OptionNames::StopOnError), data->stop_on_error); + GetKey(OptionNames::StopOnError), data_up->stop_on_error); + + if (success) + found_something = true; success = options_dict.GetValueForKeyAsString( - GetKey(OptionNames::ScriptSource), data->script_source); + GetKey(OptionNames::ScriptSource), data_up->script_source); + + if (success) + found_something = true; StructuredData::Array *user_source; success = options_dict.GetValueForKeyAsArray(GetKey(OptionNames::UserSource), user_source); if (success) { + found_something = true; size_t num_elems = user_source->GetSize(); for (size_t i = 0; i < num_elems; i++) { std::string elem_string; success = user_source->GetItemAtIndexAsString(i, elem_string); if (success) - data->user_source.AppendString(elem_string); + data_up->user_source.AppendString(elem_string); } } - return std::unique_ptr<BreakpointOptions::CommandData>(data); + + if (found_something) + return data_up; + else + return std::unique_ptr<BreakpointOptions::CommandData>(); } const char *BreakpointOptions::g_option_names @@ -200,13 +213,13 @@ std::unique_ptr<BreakpointOptions> BreakpointOptions::CreateFromStructuredData( return nullptr; } - std::unique_ptr<CommandData> cmd_data; + std::unique_ptr<CommandData> cmd_data_up; StructuredData::Dictionary *cmds_dict; success = options_dict.GetValueForKeyAsDictionary( CommandData::GetSerializationKey(), cmds_dict); if (success && cmds_dict) { Error cmds_error; - cmd_data = CommandData::CreateFromStructuredData(*cmds_dict, cmds_error); + cmd_data_up = CommandData::CreateFromStructuredData(*cmds_dict, cmds_error); if (cmds_error.Fail()) { error.SetErrorStringWithFormat( "Failed to deserialize breakpoint command options: %s.", @@ -217,7 +230,8 @@ std::unique_ptr<BreakpointOptions> BreakpointOptions::CreateFromStructuredData( auto bp_options = llvm::make_unique<BreakpointOptions>( condition_text.c_str(), enabled, ignore_count, one_shot); - bp_options->SetCommandDataCallback(std::move(cmd_data)); + if (cmd_data_up.get()) + bp_options->SetCommandDataCallback(cmd_data_up); return bp_options; } @@ -306,6 +320,20 @@ bool BreakpointOptions::HasCallback() const { return m_callback != BreakpointOptions::NullCallback; } +bool BreakpointOptions::GetCommandLineCallbacks(StringList &command_list) { + if (!HasCallback()) + return false; + if (!m_baton_is_command_baton) + return false; + + auto cmd_baton = std::static_pointer_cast<CommandBaton>(m_callback_baton_sp); + CommandData *data = cmd_baton->getItem(); + if (!data) + return false; + command_list = data->user_source; + return true; +} + void BreakpointOptions::SetCondition(const char *condition) { if (!condition) condition = ""; @@ -418,7 +446,7 @@ void BreakpointOptions::CommandBaton::GetDescription( } void BreakpointOptions::SetCommandDataCallback( - std::unique_ptr<CommandData> cmd_data) { + std::unique_ptr<CommandData> &cmd_data) { auto baton_sp = std::make_shared<CommandBaton>(std::move(cmd_data)); SetCallback(BreakpointOptions::BreakpointOptionsCallbackFunction, baton_sp); } diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index ed10a2454cc..18504947316 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -219,7 +219,7 @@ are no syntax errors may indicate that a function was declared but never called. auto cmd_data = llvm::make_unique<BreakpointOptions::CommandData>(); cmd_data->user_source.SplitIntoLines(line.c_str(), line.size()); - bp_options->SetCommandDataCallback(std::move(cmd_data)); + bp_options->SetCommandDataCallback(cmd_data); } } @@ -251,7 +251,7 @@ are no syntax errors may indicate that a function was declared but never called. cmd_data->script_source.assign(oneliner); cmd_data->stop_on_error = m_options.m_stop_on_error; - bp_options->SetCommandDataCallback(std::move(cmd_data)); + bp_options->SetCommandDataCallback(cmd_data); } } |