15ffd83dbSDimitry Andric //===-- BreakpointOptions.cpp ---------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointOptions.h"
100b57cec5SDimitry Andric 
110b57cec5SDimitry Andric #include "lldb/Breakpoint/StoppointCallbackContext.h"
120b57cec5SDimitry Andric #include "lldb/Core/Value.h"
130b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
140b57cec5SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
150b57cec5SDimitry Andric #include "lldb/Target/Process.h"
160b57cec5SDimitry Andric #include "lldb/Target/Target.h"
170b57cec5SDimitry Andric #include "lldb/Target/ThreadSpec.h"
180b57cec5SDimitry Andric #include "lldb/Utility/Stream.h"
190b57cec5SDimitry Andric #include "lldb/Utility/StringList.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h"
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric using namespace lldb;
240b57cec5SDimitry Andric using namespace lldb_private;
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric const char
270b57cec5SDimitry Andric     *BreakpointOptions::CommandData::g_option_names[static_cast<uint32_t>(
280b57cec5SDimitry Andric         BreakpointOptions::CommandData::OptionNames::LastOptionName)]{
290b57cec5SDimitry Andric         "UserSource", "ScriptSource", "StopOnError"};
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric StructuredData::ObjectSP
SerializeToStructuredData()320b57cec5SDimitry Andric BreakpointOptions::CommandData::SerializeToStructuredData() {
330b57cec5SDimitry Andric   size_t num_strings = user_source.GetSize();
340b57cec5SDimitry Andric   if (num_strings == 0 && script_source.empty()) {
350b57cec5SDimitry Andric     // We shouldn't serialize commands if there aren't any, return an empty sp
360b57cec5SDimitry Andric     // to indicate this.
370b57cec5SDimitry Andric     return StructuredData::ObjectSP();
380b57cec5SDimitry Andric   }
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric   StructuredData::DictionarySP options_dict_sp(
410b57cec5SDimitry Andric       new StructuredData::Dictionary());
420b57cec5SDimitry Andric   options_dict_sp->AddBooleanItem(GetKey(OptionNames::StopOnError),
430b57cec5SDimitry Andric                                   stop_on_error);
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric   StructuredData::ArraySP user_source_sp(new StructuredData::Array());
460b57cec5SDimitry Andric   for (size_t i = 0; i < num_strings; i++) {
470b57cec5SDimitry Andric     StructuredData::StringSP item_sp(
480b57cec5SDimitry Andric         new StructuredData::String(user_source[i]));
490b57cec5SDimitry Andric     user_source_sp->AddItem(item_sp);
500b57cec5SDimitry Andric     options_dict_sp->AddItem(GetKey(OptionNames::UserSource), user_source_sp);
510b57cec5SDimitry Andric   }
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric   options_dict_sp->AddStringItem(
540b57cec5SDimitry Andric       GetKey(OptionNames::Interpreter),
550b57cec5SDimitry Andric       ScriptInterpreter::LanguageToString(interpreter));
560b57cec5SDimitry Andric   return options_dict_sp;
570b57cec5SDimitry Andric }
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric std::unique_ptr<BreakpointOptions::CommandData>
CreateFromStructuredData(const StructuredData::Dictionary & options_dict,Status & error)600b57cec5SDimitry Andric BreakpointOptions::CommandData::CreateFromStructuredData(
610b57cec5SDimitry Andric     const StructuredData::Dictionary &options_dict, Status &error) {
620b57cec5SDimitry Andric   std::unique_ptr<CommandData> data_up(new CommandData());
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric   bool success = options_dict.GetValueForKeyAsBoolean(
650b57cec5SDimitry Andric       GetKey(OptionNames::StopOnError), data_up->stop_on_error);
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric   llvm::StringRef interpreter_str;
680b57cec5SDimitry Andric   ScriptLanguage interp_language;
690b57cec5SDimitry Andric   success = options_dict.GetValueForKeyAsString(
700b57cec5SDimitry Andric       GetKey(OptionNames::Interpreter), interpreter_str);
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric   if (!success) {
730b57cec5SDimitry Andric     error.SetErrorString("Missing command language value.");
740b57cec5SDimitry Andric     return data_up;
750b57cec5SDimitry Andric   }
760b57cec5SDimitry Andric 
770b57cec5SDimitry Andric   interp_language = ScriptInterpreter::StringToLanguage(interpreter_str);
780b57cec5SDimitry Andric   if (interp_language == eScriptLanguageUnknown) {
790b57cec5SDimitry Andric     error.SetErrorStringWithFormatv("Unknown breakpoint command language: {0}.",
800b57cec5SDimitry Andric                                     interpreter_str);
810b57cec5SDimitry Andric     return data_up;
820b57cec5SDimitry Andric   }
830b57cec5SDimitry Andric   data_up->interpreter = interp_language;
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric   StructuredData::Array *user_source;
860b57cec5SDimitry Andric   success = options_dict.GetValueForKeyAsArray(GetKey(OptionNames::UserSource),
870b57cec5SDimitry Andric                                                user_source);
880b57cec5SDimitry Andric   if (success) {
890b57cec5SDimitry Andric     size_t num_elems = user_source->GetSize();
900b57cec5SDimitry Andric     for (size_t i = 0; i < num_elems; i++) {
915f757f3fSDimitry Andric       if (std::optional<llvm::StringRef> maybe_elem_string =
925f757f3fSDimitry Andric               user_source->GetItemAtIndexAsString(i))
935f757f3fSDimitry Andric         data_up->user_source.AppendString(*maybe_elem_string);
940b57cec5SDimitry Andric     }
950b57cec5SDimitry Andric   }
960b57cec5SDimitry Andric 
970b57cec5SDimitry Andric   return data_up;
980b57cec5SDimitry Andric }
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric const char *BreakpointOptions::g_option_names[(
1010b57cec5SDimitry Andric     size_t)BreakpointOptions::OptionNames::LastOptionName]{
1020b57cec5SDimitry Andric     "ConditionText", "IgnoreCount",
1030b57cec5SDimitry Andric     "EnabledState", "OneShotState", "AutoContinue"};
1040b57cec5SDimitry Andric 
NullCallback(void * baton,StoppointCallbackContext * context,lldb::user_id_t break_id,lldb::user_id_t break_loc_id)1050b57cec5SDimitry Andric bool BreakpointOptions::NullCallback(void *baton,
1060b57cec5SDimitry Andric                                      StoppointCallbackContext *context,
1070b57cec5SDimitry Andric                                      lldb::user_id_t break_id,
1080b57cec5SDimitry Andric                                      lldb::user_id_t break_loc_id) {
1090b57cec5SDimitry Andric   return true;
1100b57cec5SDimitry Andric }
1110b57cec5SDimitry Andric 
1120b57cec5SDimitry Andric // BreakpointOptions constructor
BreakpointOptions(bool all_flags_set)1130b57cec5SDimitry Andric BreakpointOptions::BreakpointOptions(bool all_flags_set)
11481ad6265SDimitry Andric     : m_callback(BreakpointOptions::NullCallback),
1150b57cec5SDimitry Andric       m_baton_is_command_baton(false), m_callback_is_synchronous(false),
11681ad6265SDimitry Andric       m_enabled(true), m_one_shot(false), m_ignore_count(0),
117bdd1243dSDimitry Andric       m_condition_text_hash(0), m_inject_condition(false),
118bdd1243dSDimitry Andric       m_auto_continue(false), m_set_flags(0) {
1190b57cec5SDimitry Andric   if (all_flags_set)
1200b57cec5SDimitry Andric     m_set_flags.Set(~((Flags::ValueType)0));
1210b57cec5SDimitry Andric }
1220b57cec5SDimitry Andric 
BreakpointOptions(const char * condition,bool enabled,int32_t ignore,bool one_shot,bool auto_continue)1230b57cec5SDimitry Andric BreakpointOptions::BreakpointOptions(const char *condition, bool enabled,
1240b57cec5SDimitry Andric                                      int32_t ignore, bool one_shot,
1250b57cec5SDimitry Andric                                      bool auto_continue)
1260b57cec5SDimitry Andric     : m_callback(nullptr), m_baton_is_command_baton(false),
1270b57cec5SDimitry Andric       m_callback_is_synchronous(false), m_enabled(enabled),
128bdd1243dSDimitry Andric       m_one_shot(one_shot), m_ignore_count(ignore), m_condition_text_hash(0),
129bdd1243dSDimitry Andric       m_inject_condition(false), m_auto_continue(auto_continue) {
130bdd1243dSDimitry Andric   m_set_flags.Set(eEnabled | eIgnoreCount | eOneShot | eAutoContinue);
1310b57cec5SDimitry Andric     if (condition && *condition != '\0') {
1320b57cec5SDimitry Andric       SetCondition(condition);
1330b57cec5SDimitry Andric     }
1340b57cec5SDimitry Andric }
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric // BreakpointOptions copy constructor
BreakpointOptions(const BreakpointOptions & rhs)1370b57cec5SDimitry Andric BreakpointOptions::BreakpointOptions(const BreakpointOptions &rhs)
1380b57cec5SDimitry Andric     : m_callback(rhs.m_callback), m_callback_baton_sp(rhs.m_callback_baton_sp),
1390b57cec5SDimitry Andric       m_baton_is_command_baton(rhs.m_baton_is_command_baton),
1400b57cec5SDimitry Andric       m_callback_is_synchronous(rhs.m_callback_is_synchronous),
1410b57cec5SDimitry Andric       m_enabled(rhs.m_enabled), m_one_shot(rhs.m_one_shot),
142bdd1243dSDimitry Andric       m_ignore_count(rhs.m_ignore_count), m_inject_condition(false),
143bdd1243dSDimitry Andric       m_auto_continue(rhs.m_auto_continue), m_set_flags(rhs.m_set_flags) {
1440b57cec5SDimitry Andric   if (rhs.m_thread_spec_up != nullptr)
1455ffd83dbSDimitry Andric     m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
1460b57cec5SDimitry Andric   m_condition_text = rhs.m_condition_text;
1470b57cec5SDimitry Andric   m_condition_text_hash = rhs.m_condition_text_hash;
1480b57cec5SDimitry Andric }
1490b57cec5SDimitry Andric 
1500b57cec5SDimitry Andric // BreakpointOptions assignment operator
1510b57cec5SDimitry Andric const BreakpointOptions &BreakpointOptions::
operator =(const BreakpointOptions & rhs)1520b57cec5SDimitry Andric operator=(const BreakpointOptions &rhs) {
1530b57cec5SDimitry Andric   m_callback = rhs.m_callback;
1540b57cec5SDimitry Andric   m_callback_baton_sp = rhs.m_callback_baton_sp;
1550b57cec5SDimitry Andric   m_baton_is_command_baton = rhs.m_baton_is_command_baton;
1560b57cec5SDimitry Andric   m_callback_is_synchronous = rhs.m_callback_is_synchronous;
1570b57cec5SDimitry Andric   m_enabled = rhs.m_enabled;
1580b57cec5SDimitry Andric   m_one_shot = rhs.m_one_shot;
1590b57cec5SDimitry Andric   m_ignore_count = rhs.m_ignore_count;
1600b57cec5SDimitry Andric   if (rhs.m_thread_spec_up != nullptr)
1615ffd83dbSDimitry Andric     m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
1620b57cec5SDimitry Andric   m_condition_text = rhs.m_condition_text;
1630b57cec5SDimitry Andric   m_condition_text_hash = rhs.m_condition_text_hash;
164bdd1243dSDimitry Andric   m_inject_condition = rhs.m_inject_condition;
1650b57cec5SDimitry Andric   m_auto_continue = rhs.m_auto_continue;
1660b57cec5SDimitry Andric   m_set_flags = rhs.m_set_flags;
1670b57cec5SDimitry Andric   return *this;
1680b57cec5SDimitry Andric }
1690b57cec5SDimitry Andric 
CopyOverSetOptions(const BreakpointOptions & incoming)1700b57cec5SDimitry Andric void BreakpointOptions::CopyOverSetOptions(const BreakpointOptions &incoming)
1710b57cec5SDimitry Andric {
1720b57cec5SDimitry Andric   if (incoming.m_set_flags.Test(eEnabled))
1730b57cec5SDimitry Andric   {
1740b57cec5SDimitry Andric     m_enabled = incoming.m_enabled;
1750b57cec5SDimitry Andric     m_set_flags.Set(eEnabled);
1760b57cec5SDimitry Andric   }
1770b57cec5SDimitry Andric   if (incoming.m_set_flags.Test(eOneShot))
1780b57cec5SDimitry Andric   {
1790b57cec5SDimitry Andric     m_one_shot = incoming.m_one_shot;
1800b57cec5SDimitry Andric     m_set_flags.Set(eOneShot);
1810b57cec5SDimitry Andric   }
1820b57cec5SDimitry Andric   if (incoming.m_set_flags.Test(eCallback))
1830b57cec5SDimitry Andric   {
1840b57cec5SDimitry Andric     m_callback = incoming.m_callback;
1850b57cec5SDimitry Andric     m_callback_baton_sp = incoming.m_callback_baton_sp;
1860b57cec5SDimitry Andric     m_callback_is_synchronous = incoming.m_callback_is_synchronous;
1870b57cec5SDimitry Andric     m_baton_is_command_baton = incoming.m_baton_is_command_baton;
1880b57cec5SDimitry Andric     m_set_flags.Set(eCallback);
1890b57cec5SDimitry Andric   }
1900b57cec5SDimitry Andric   if (incoming.m_set_flags.Test(eIgnoreCount))
1910b57cec5SDimitry Andric   {
1920b57cec5SDimitry Andric     m_ignore_count = incoming.m_ignore_count;
1930b57cec5SDimitry Andric     m_set_flags.Set(eIgnoreCount);
1940b57cec5SDimitry Andric   }
1950b57cec5SDimitry Andric   if (incoming.m_set_flags.Test(eCondition))
1960b57cec5SDimitry Andric   {
1970b57cec5SDimitry Andric     // If we're copying over an empty condition, mark it as unset.
1980b57cec5SDimitry Andric     if (incoming.m_condition_text.empty()) {
1990b57cec5SDimitry Andric       m_condition_text.clear();
2000b57cec5SDimitry Andric       m_condition_text_hash = 0;
2010b57cec5SDimitry Andric       m_set_flags.Clear(eCondition);
2020b57cec5SDimitry Andric     } else {
2030b57cec5SDimitry Andric       m_condition_text = incoming.m_condition_text;
2040b57cec5SDimitry Andric       m_condition_text_hash = incoming.m_condition_text_hash;
2050b57cec5SDimitry Andric       m_set_flags.Set(eCondition);
2060b57cec5SDimitry Andric     }
2070b57cec5SDimitry Andric   }
2080b57cec5SDimitry Andric   if (incoming.m_set_flags.Test(eAutoContinue))
2090b57cec5SDimitry Andric   {
2100b57cec5SDimitry Andric     m_auto_continue = incoming.m_auto_continue;
2110b57cec5SDimitry Andric     m_set_flags.Set(eAutoContinue);
2120b57cec5SDimitry Andric   }
2130b57cec5SDimitry Andric   if (incoming.m_set_flags.Test(eThreadSpec) && incoming.m_thread_spec_up) {
2140b57cec5SDimitry Andric     if (!m_thread_spec_up)
2155ffd83dbSDimitry Andric       m_thread_spec_up =
2165ffd83dbSDimitry Andric           std::make_unique<ThreadSpec>(*incoming.m_thread_spec_up);
2170b57cec5SDimitry Andric     else
2180b57cec5SDimitry Andric       *m_thread_spec_up = *incoming.m_thread_spec_up;
2190b57cec5SDimitry Andric     m_set_flags.Set(eThreadSpec);
2200b57cec5SDimitry Andric   }
2210b57cec5SDimitry Andric }
2220b57cec5SDimitry Andric 
2230b57cec5SDimitry Andric // Destructor
2240b57cec5SDimitry Andric BreakpointOptions::~BreakpointOptions() = default;
2250b57cec5SDimitry Andric 
CreateFromStructuredData(Target & target,const StructuredData::Dictionary & options_dict,Status & error)2260b57cec5SDimitry Andric std::unique_ptr<BreakpointOptions> BreakpointOptions::CreateFromStructuredData(
2270b57cec5SDimitry Andric     Target &target, const StructuredData::Dictionary &options_dict,
2280b57cec5SDimitry Andric     Status &error) {
2290b57cec5SDimitry Andric   bool enabled = true;
2300b57cec5SDimitry Andric   bool one_shot = false;
2310b57cec5SDimitry Andric   bool auto_continue = false;
23206c3fb27SDimitry Andric   uint32_t ignore_count = 0;
2330b57cec5SDimitry Andric   llvm::StringRef condition_ref("");
2340b57cec5SDimitry Andric   Flags set_options;
2350b57cec5SDimitry Andric 
2360b57cec5SDimitry Andric   const char *key = GetKey(OptionNames::EnabledState);
2370b57cec5SDimitry Andric   bool success;
2380b57cec5SDimitry Andric   if (key && options_dict.HasKey(key)) {
2390b57cec5SDimitry Andric     success = options_dict.GetValueForKeyAsBoolean(key, enabled);
2400b57cec5SDimitry Andric     if (!success) {
2410b57cec5SDimitry Andric       error.SetErrorStringWithFormat("%s key is not a boolean.", key);
2420b57cec5SDimitry Andric       return nullptr;
2430b57cec5SDimitry Andric     }
2440b57cec5SDimitry Andric     set_options.Set(eEnabled);
2450b57cec5SDimitry Andric   }
2460b57cec5SDimitry Andric 
2470b57cec5SDimitry Andric   key = GetKey(OptionNames::OneShotState);
2480b57cec5SDimitry Andric   if (key && options_dict.HasKey(key)) {
2490b57cec5SDimitry Andric     success = options_dict.GetValueForKeyAsBoolean(key, one_shot);
2500b57cec5SDimitry Andric     if (!success) {
2510b57cec5SDimitry Andric       error.SetErrorStringWithFormat("%s key is not a boolean.", key);
2520b57cec5SDimitry Andric       return nullptr;
2530b57cec5SDimitry Andric       }
2540b57cec5SDimitry Andric       set_options.Set(eOneShot);
2550b57cec5SDimitry Andric   }
2560b57cec5SDimitry Andric 
2570b57cec5SDimitry Andric   key = GetKey(OptionNames::AutoContinue);
2580b57cec5SDimitry Andric   if (key && options_dict.HasKey(key)) {
2590b57cec5SDimitry Andric     success = options_dict.GetValueForKeyAsBoolean(key, auto_continue);
2600b57cec5SDimitry Andric     if (!success) {
2610b57cec5SDimitry Andric       error.SetErrorStringWithFormat("%s key is not a boolean.", key);
2620b57cec5SDimitry Andric       return nullptr;
2630b57cec5SDimitry Andric       }
2640b57cec5SDimitry Andric       set_options.Set(eAutoContinue);
2650b57cec5SDimitry Andric   }
2660b57cec5SDimitry Andric 
2670b57cec5SDimitry Andric   key = GetKey(OptionNames::IgnoreCount);
2680b57cec5SDimitry Andric   if (key && options_dict.HasKey(key)) {
2690b57cec5SDimitry Andric     success = options_dict.GetValueForKeyAsInteger(key, ignore_count);
2700b57cec5SDimitry Andric     if (!success) {
2710b57cec5SDimitry Andric       error.SetErrorStringWithFormat("%s key is not an integer.", key);
2720b57cec5SDimitry Andric       return nullptr;
2730b57cec5SDimitry Andric     }
2740b57cec5SDimitry Andric     set_options.Set(eIgnoreCount);
2750b57cec5SDimitry Andric   }
2760b57cec5SDimitry Andric 
2770b57cec5SDimitry Andric   key = GetKey(OptionNames::ConditionText);
2780b57cec5SDimitry Andric   if (key && options_dict.HasKey(key)) {
2790b57cec5SDimitry Andric     success = options_dict.GetValueForKeyAsString(key, condition_ref);
2800b57cec5SDimitry Andric     if (!success) {
2810b57cec5SDimitry Andric       error.SetErrorStringWithFormat("%s key is not an string.", key);
2820b57cec5SDimitry Andric       return nullptr;
2830b57cec5SDimitry Andric     }
2840b57cec5SDimitry Andric     set_options.Set(eCondition);
2850b57cec5SDimitry Andric   }
2860b57cec5SDimitry Andric 
2870b57cec5SDimitry Andric   std::unique_ptr<CommandData> cmd_data_up;
2880b57cec5SDimitry Andric   StructuredData::Dictionary *cmds_dict;
2890b57cec5SDimitry Andric   success = options_dict.GetValueForKeyAsDictionary(
2900b57cec5SDimitry Andric       CommandData::GetSerializationKey(), cmds_dict);
2910b57cec5SDimitry Andric   if (success && cmds_dict) {
2920b57cec5SDimitry Andric     Status cmds_error;
2930b57cec5SDimitry Andric     cmd_data_up = CommandData::CreateFromStructuredData(*cmds_dict, cmds_error);
2940b57cec5SDimitry Andric     if (cmds_error.Fail()) {
2950b57cec5SDimitry Andric       error.SetErrorStringWithFormat(
2960b57cec5SDimitry Andric           "Failed to deserialize breakpoint command options: %s.",
2970b57cec5SDimitry Andric           cmds_error.AsCString());
2980b57cec5SDimitry Andric       return nullptr;
2990b57cec5SDimitry Andric     }
3000b57cec5SDimitry Andric   }
3010b57cec5SDimitry Andric 
3029dba64beSDimitry Andric   auto bp_options = std::make_unique<BreakpointOptions>(
3030b57cec5SDimitry Andric       condition_ref.str().c_str(), enabled,
3040b57cec5SDimitry Andric       ignore_count, one_shot, auto_continue);
3050b57cec5SDimitry Andric   if (cmd_data_up) {
3060b57cec5SDimitry Andric     if (cmd_data_up->interpreter == eScriptLanguageNone)
3070b57cec5SDimitry Andric       bp_options->SetCommandDataCallback(cmd_data_up);
3080b57cec5SDimitry Andric     else {
3090b57cec5SDimitry Andric       ScriptInterpreter *interp = target.GetDebugger().GetScriptInterpreter();
3100b57cec5SDimitry Andric       if (!interp) {
311e8d8bef9SDimitry Andric         error.SetErrorString(
3120b57cec5SDimitry Andric             "Can't set script commands - no script interpreter");
3130b57cec5SDimitry Andric         return nullptr;
3140b57cec5SDimitry Andric       }
3150b57cec5SDimitry Andric       if (interp->GetLanguage() != cmd_data_up->interpreter) {
3160b57cec5SDimitry Andric         error.SetErrorStringWithFormat(
3170b57cec5SDimitry Andric             "Current script language doesn't match breakpoint's language: %s",
3180b57cec5SDimitry Andric             ScriptInterpreter::LanguageToString(cmd_data_up->interpreter)
3190b57cec5SDimitry Andric                 .c_str());
3200b57cec5SDimitry Andric         return nullptr;
3210b57cec5SDimitry Andric       }
3220b57cec5SDimitry Andric       Status script_error;
3230b57cec5SDimitry Andric       script_error =
324fe6060f1SDimitry Andric           interp->SetBreakpointCommandCallback(*bp_options, cmd_data_up);
3250b57cec5SDimitry Andric       if (script_error.Fail()) {
3260b57cec5SDimitry Andric         error.SetErrorStringWithFormat("Error generating script callback: %s.",
3270b57cec5SDimitry Andric                                        error.AsCString());
3280b57cec5SDimitry Andric         return nullptr;
3290b57cec5SDimitry Andric       }
3300b57cec5SDimitry Andric     }
3310b57cec5SDimitry Andric   }
3320b57cec5SDimitry Andric 
3330b57cec5SDimitry Andric   StructuredData::Dictionary *thread_spec_dict;
3340b57cec5SDimitry Andric   success = options_dict.GetValueForKeyAsDictionary(
3350b57cec5SDimitry Andric       ThreadSpec::GetSerializationKey(), thread_spec_dict);
3360b57cec5SDimitry Andric   if (success) {
3370b57cec5SDimitry Andric     Status thread_spec_error;
3380b57cec5SDimitry Andric     std::unique_ptr<ThreadSpec> thread_spec_up =
3390b57cec5SDimitry Andric         ThreadSpec::CreateFromStructuredData(*thread_spec_dict,
3400b57cec5SDimitry Andric                                              thread_spec_error);
3410b57cec5SDimitry Andric     if (thread_spec_error.Fail()) {
3420b57cec5SDimitry Andric       error.SetErrorStringWithFormat(
3430b57cec5SDimitry Andric           "Failed to deserialize breakpoint thread spec options: %s.",
3440b57cec5SDimitry Andric           thread_spec_error.AsCString());
3450b57cec5SDimitry Andric       return nullptr;
3460b57cec5SDimitry Andric     }
3470b57cec5SDimitry Andric     bp_options->SetThreadSpec(thread_spec_up);
3480b57cec5SDimitry Andric   }
3490b57cec5SDimitry Andric   return bp_options;
3500b57cec5SDimitry Andric }
3510b57cec5SDimitry Andric 
SerializeToStructuredData()3520b57cec5SDimitry Andric StructuredData::ObjectSP BreakpointOptions::SerializeToStructuredData() {
3530b57cec5SDimitry Andric   StructuredData::DictionarySP options_dict_sp(
3540b57cec5SDimitry Andric       new StructuredData::Dictionary());
3550b57cec5SDimitry Andric   if (m_set_flags.Test(eEnabled))
3560b57cec5SDimitry Andric     options_dict_sp->AddBooleanItem(GetKey(OptionNames::EnabledState),
3570b57cec5SDimitry Andric                                     m_enabled);
3580b57cec5SDimitry Andric   if (m_set_flags.Test(eOneShot))
3590b57cec5SDimitry Andric     options_dict_sp->AddBooleanItem(GetKey(OptionNames::OneShotState),
3600b57cec5SDimitry Andric                                m_one_shot);
3610b57cec5SDimitry Andric   if (m_set_flags.Test(eAutoContinue))
3620b57cec5SDimitry Andric     options_dict_sp->AddBooleanItem(GetKey(OptionNames::AutoContinue),
3630b57cec5SDimitry Andric                                m_auto_continue);
3640b57cec5SDimitry Andric   if (m_set_flags.Test(eIgnoreCount))
3650b57cec5SDimitry Andric     options_dict_sp->AddIntegerItem(GetKey(OptionNames::IgnoreCount),
3660b57cec5SDimitry Andric                                     m_ignore_count);
3670b57cec5SDimitry Andric   if (m_set_flags.Test(eCondition))
3680b57cec5SDimitry Andric     options_dict_sp->AddStringItem(GetKey(OptionNames::ConditionText),
3690b57cec5SDimitry Andric                                    m_condition_text);
3700b57cec5SDimitry Andric 
3710b57cec5SDimitry Andric   if (m_set_flags.Test(eCallback) && m_baton_is_command_baton) {
3720b57cec5SDimitry Andric     auto cmd_baton =
3730b57cec5SDimitry Andric         std::static_pointer_cast<CommandBaton>(m_callback_baton_sp);
3740b57cec5SDimitry Andric     StructuredData::ObjectSP commands_sp =
3750b57cec5SDimitry Andric         cmd_baton->getItem()->SerializeToStructuredData();
3760b57cec5SDimitry Andric     if (commands_sp) {
3770b57cec5SDimitry Andric       options_dict_sp->AddItem(
3780b57cec5SDimitry Andric           BreakpointOptions::CommandData::GetSerializationKey(), commands_sp);
3790b57cec5SDimitry Andric     }
3800b57cec5SDimitry Andric   }
3810b57cec5SDimitry Andric   if (m_set_flags.Test(eThreadSpec) && m_thread_spec_up) {
3820b57cec5SDimitry Andric     StructuredData::ObjectSP thread_spec_sp =
3830b57cec5SDimitry Andric         m_thread_spec_up->SerializeToStructuredData();
3840b57cec5SDimitry Andric     options_dict_sp->AddItem(ThreadSpec::GetSerializationKey(), thread_spec_sp);
3850b57cec5SDimitry Andric   }
3860b57cec5SDimitry Andric 
3870b57cec5SDimitry Andric   return options_dict_sp;
3880b57cec5SDimitry Andric }
3890b57cec5SDimitry Andric 
3900b57cec5SDimitry Andric // Callbacks
SetCallback(BreakpointHitCallback callback,const lldb::BatonSP & callback_baton_sp,bool callback_is_synchronous)3910b57cec5SDimitry Andric void BreakpointOptions::SetCallback(BreakpointHitCallback callback,
3920b57cec5SDimitry Andric                                     const lldb::BatonSP &callback_baton_sp,
3930b57cec5SDimitry Andric                                     bool callback_is_synchronous) {
3940b57cec5SDimitry Andric   // FIXME: This seems unsafe.  If BatonSP actually *is* a CommandBaton, but
3950b57cec5SDimitry Andric   // in a shared_ptr<Baton> instead of a shared_ptr<CommandBaton>, then we will
3960b57cec5SDimitry Andric   // set m_baton_is_command_baton to false, which is incorrect. One possible
3970b57cec5SDimitry Andric   // solution is to make the base Baton class provide a method such as:
3980b57cec5SDimitry Andric   //     virtual StringRef getBatonId() const { return ""; }
3990b57cec5SDimitry Andric   // and have CommandBaton override this to return something unique, and then
4000b57cec5SDimitry Andric   // check for it here.  Another option might be to make Baton using the llvm
4010b57cec5SDimitry Andric   // casting infrastructure, so that we could write something like:
4020b57cec5SDimitry Andric   //     if (llvm::isa<CommandBaton>(callback_baton_sp))
4030b57cec5SDimitry Andric   // at relevant callsites instead of storing a boolean.
4040b57cec5SDimitry Andric   m_callback_is_synchronous = callback_is_synchronous;
4050b57cec5SDimitry Andric   m_callback = callback;
4060b57cec5SDimitry Andric   m_callback_baton_sp = callback_baton_sp;
4070b57cec5SDimitry Andric   m_baton_is_command_baton = false;
4080b57cec5SDimitry Andric   m_set_flags.Set(eCallback);
4090b57cec5SDimitry Andric }
4100b57cec5SDimitry Andric 
SetCallback(BreakpointHitCallback callback,const BreakpointOptions::CommandBatonSP & callback_baton_sp,bool callback_is_synchronous)4110b57cec5SDimitry Andric void BreakpointOptions::SetCallback(
4120b57cec5SDimitry Andric     BreakpointHitCallback callback,
4130b57cec5SDimitry Andric     const BreakpointOptions::CommandBatonSP &callback_baton_sp,
4140b57cec5SDimitry Andric     bool callback_is_synchronous) {
4150b57cec5SDimitry Andric   m_callback_is_synchronous = callback_is_synchronous;
4160b57cec5SDimitry Andric   m_callback = callback;
4170b57cec5SDimitry Andric   m_callback_baton_sp = callback_baton_sp;
4180b57cec5SDimitry Andric   m_baton_is_command_baton = true;
4190b57cec5SDimitry Andric   m_set_flags.Set(eCallback);
4200b57cec5SDimitry Andric }
4210b57cec5SDimitry Andric 
ClearCallback()4220b57cec5SDimitry Andric void BreakpointOptions::ClearCallback() {
4230b57cec5SDimitry Andric   m_callback = BreakpointOptions::NullCallback;
4240b57cec5SDimitry Andric   m_callback_is_synchronous = false;
4250b57cec5SDimitry Andric   m_callback_baton_sp.reset();
4260b57cec5SDimitry Andric   m_baton_is_command_baton = false;
4270b57cec5SDimitry Andric   m_set_flags.Clear(eCallback);
4280b57cec5SDimitry Andric }
4290b57cec5SDimitry Andric 
GetBaton()4300b57cec5SDimitry Andric Baton *BreakpointOptions::GetBaton() { return m_callback_baton_sp.get(); }
4310b57cec5SDimitry Andric 
GetBaton() const4320b57cec5SDimitry Andric const Baton *BreakpointOptions::GetBaton() const {
4330b57cec5SDimitry Andric   return m_callback_baton_sp.get();
4340b57cec5SDimitry Andric }
4350b57cec5SDimitry Andric 
InvokeCallback(StoppointCallbackContext * context,lldb::user_id_t break_id,lldb::user_id_t break_loc_id)4360b57cec5SDimitry Andric bool BreakpointOptions::InvokeCallback(StoppointCallbackContext *context,
4370b57cec5SDimitry Andric                                        lldb::user_id_t break_id,
4380b57cec5SDimitry Andric                                        lldb::user_id_t break_loc_id) {
4390b57cec5SDimitry Andric   if (m_callback) {
4400b57cec5SDimitry Andric     if (context->is_synchronous == IsCallbackSynchronous()) {
4410b57cec5SDimitry Andric         return m_callback(m_callback_baton_sp ? m_callback_baton_sp->data()
4420b57cec5SDimitry Andric                                           : nullptr,
4430b57cec5SDimitry Andric                       context, break_id, break_loc_id);
4440b57cec5SDimitry Andric     } else if (IsCallbackSynchronous()) {
4450b57cec5SDimitry Andric       return false;
4460b57cec5SDimitry Andric     }
4470b57cec5SDimitry Andric   }
4480b57cec5SDimitry Andric   return true;
4490b57cec5SDimitry Andric }
4500b57cec5SDimitry Andric 
HasCallback() const4510b57cec5SDimitry Andric bool BreakpointOptions::HasCallback() const {
4520b57cec5SDimitry Andric   return m_callback != BreakpointOptions::NullCallback;
4530b57cec5SDimitry Andric }
4540b57cec5SDimitry Andric 
GetCommandLineCallbacks(StringList & command_list)4550b57cec5SDimitry Andric bool BreakpointOptions::GetCommandLineCallbacks(StringList &command_list) {
4560b57cec5SDimitry Andric   if (!HasCallback())
4570b57cec5SDimitry Andric     return false;
4580b57cec5SDimitry Andric   if (!m_baton_is_command_baton)
4590b57cec5SDimitry Andric     return false;
4600b57cec5SDimitry Andric 
4610b57cec5SDimitry Andric   auto cmd_baton = std::static_pointer_cast<CommandBaton>(m_callback_baton_sp);
4620b57cec5SDimitry Andric   CommandData *data = cmd_baton->getItem();
4630b57cec5SDimitry Andric   if (!data)
4640b57cec5SDimitry Andric     return false;
4650b57cec5SDimitry Andric   command_list = data->user_source;
4660b57cec5SDimitry Andric   return true;
4670b57cec5SDimitry Andric }
4680b57cec5SDimitry Andric 
SetCondition(const char * condition)4690b57cec5SDimitry Andric void BreakpointOptions::SetCondition(const char *condition) {
4700b57cec5SDimitry Andric   if (!condition || condition[0] == '\0') {
4710b57cec5SDimitry Andric     condition = "";
4720b57cec5SDimitry Andric     m_set_flags.Clear(eCondition);
4730b57cec5SDimitry Andric   }
4740b57cec5SDimitry Andric   else
4750b57cec5SDimitry Andric     m_set_flags.Set(eCondition);
4760b57cec5SDimitry Andric 
4770b57cec5SDimitry Andric   m_condition_text.assign(condition);
4780b57cec5SDimitry Andric   std::hash<std::string> hasher;
4790b57cec5SDimitry Andric   m_condition_text_hash = hasher(m_condition_text);
4800b57cec5SDimitry Andric }
4810b57cec5SDimitry Andric 
GetConditionText(size_t * hash) const4820b57cec5SDimitry Andric const char *BreakpointOptions::GetConditionText(size_t *hash) const {
4830b57cec5SDimitry Andric   if (!m_condition_text.empty()) {
4840b57cec5SDimitry Andric     if (hash)
4850b57cec5SDimitry Andric       *hash = m_condition_text_hash;
4860b57cec5SDimitry Andric 
4870b57cec5SDimitry Andric     return m_condition_text.c_str();
4880b57cec5SDimitry Andric   } else {
4890b57cec5SDimitry Andric     return nullptr;
4900b57cec5SDimitry Andric   }
4910b57cec5SDimitry Andric }
4920b57cec5SDimitry Andric 
GetThreadSpecNoCreate() const4930b57cec5SDimitry Andric const ThreadSpec *BreakpointOptions::GetThreadSpecNoCreate() const {
4940b57cec5SDimitry Andric   return m_thread_spec_up.get();
4950b57cec5SDimitry Andric }
4960b57cec5SDimitry Andric 
GetThreadSpec()4970b57cec5SDimitry Andric ThreadSpec *BreakpointOptions::GetThreadSpec() {
4980b57cec5SDimitry Andric   if (m_thread_spec_up == nullptr) {
4990b57cec5SDimitry Andric     m_set_flags.Set(eThreadSpec);
5005ffd83dbSDimitry Andric     m_thread_spec_up = std::make_unique<ThreadSpec>();
5010b57cec5SDimitry Andric   }
5020b57cec5SDimitry Andric 
5030b57cec5SDimitry Andric   return m_thread_spec_up.get();
5040b57cec5SDimitry Andric }
5050b57cec5SDimitry Andric 
SetThreadID(lldb::tid_t thread_id)5060b57cec5SDimitry Andric void BreakpointOptions::SetThreadID(lldb::tid_t thread_id) {
5070b57cec5SDimitry Andric   GetThreadSpec()->SetTID(thread_id);
5080b57cec5SDimitry Andric   m_set_flags.Set(eThreadSpec);
5090b57cec5SDimitry Andric }
5100b57cec5SDimitry Andric 
SetThreadSpec(std::unique_ptr<ThreadSpec> & thread_spec_up)5110b57cec5SDimitry Andric void BreakpointOptions::SetThreadSpec(
5120b57cec5SDimitry Andric     std::unique_ptr<ThreadSpec> &thread_spec_up) {
5130b57cec5SDimitry Andric   m_thread_spec_up = std::move(thread_spec_up);
5140b57cec5SDimitry Andric   m_set_flags.Set(eThreadSpec);
5150b57cec5SDimitry Andric }
5160b57cec5SDimitry Andric 
GetDescription(Stream * s,lldb::DescriptionLevel level) const5170b57cec5SDimitry Andric void BreakpointOptions::GetDescription(Stream *s,
5180b57cec5SDimitry Andric                                        lldb::DescriptionLevel level) const {
5190b57cec5SDimitry Andric   // Figure out if there are any options not at their default value, and only
5200b57cec5SDimitry Andric   // print anything if there are:
5210b57cec5SDimitry Andric 
5220b57cec5SDimitry Andric   if (m_ignore_count != 0 || !m_enabled || m_one_shot || m_auto_continue ||
5230b57cec5SDimitry Andric       (GetThreadSpecNoCreate() != nullptr &&
5240b57cec5SDimitry Andric        GetThreadSpecNoCreate()->HasSpecification())) {
5250b57cec5SDimitry Andric     if (level == lldb::eDescriptionLevelVerbose) {
5260b57cec5SDimitry Andric       s->EOL();
5270b57cec5SDimitry Andric       s->IndentMore();
5280b57cec5SDimitry Andric       s->Indent();
5290b57cec5SDimitry Andric       s->PutCString("Breakpoint Options:\n");
5300b57cec5SDimitry Andric       s->IndentMore();
5310b57cec5SDimitry Andric       s->Indent();
5320b57cec5SDimitry Andric     } else
5330b57cec5SDimitry Andric       s->PutCString(" Options: ");
5340b57cec5SDimitry Andric 
5350b57cec5SDimitry Andric     if (m_ignore_count > 0)
5360b57cec5SDimitry Andric       s->Printf("ignore: %d ", m_ignore_count);
5370b57cec5SDimitry Andric     s->Printf("%sabled ", m_enabled ? "en" : "dis");
5380b57cec5SDimitry Andric 
5390b57cec5SDimitry Andric     if (m_one_shot)
5400b57cec5SDimitry Andric       s->Printf("one-shot ");
5410b57cec5SDimitry Andric 
5420b57cec5SDimitry Andric     if (m_auto_continue)
5430b57cec5SDimitry Andric       s->Printf("auto-continue ");
5440b57cec5SDimitry Andric 
5450b57cec5SDimitry Andric     if (m_thread_spec_up)
5460b57cec5SDimitry Andric       m_thread_spec_up->GetDescription(s, level);
5470b57cec5SDimitry Andric 
5480b57cec5SDimitry Andric     if (level == lldb::eDescriptionLevelFull) {
5490b57cec5SDimitry Andric       s->IndentLess();
5500b57cec5SDimitry Andric       s->IndentMore();
5510b57cec5SDimitry Andric     }
5520b57cec5SDimitry Andric   }
5530b57cec5SDimitry Andric 
5540b57cec5SDimitry Andric   if (m_callback_baton_sp.get()) {
5550b57cec5SDimitry Andric     if (level != eDescriptionLevelBrief) {
5560b57cec5SDimitry Andric       s->EOL();
557480093f4SDimitry Andric       m_callback_baton_sp->GetDescription(s->AsRawOstream(), level,
558480093f4SDimitry Andric                                           s->GetIndentLevel());
5590b57cec5SDimitry Andric     }
5600b57cec5SDimitry Andric   }
5610b57cec5SDimitry Andric   if (!m_condition_text.empty()) {
5620b57cec5SDimitry Andric     if (level != eDescriptionLevelBrief) {
5630b57cec5SDimitry Andric       s->EOL();
5640b57cec5SDimitry Andric       s->Printf("Condition: %s\n", m_condition_text.c_str());
5650b57cec5SDimitry Andric     }
5660b57cec5SDimitry Andric   }
5670b57cec5SDimitry Andric }
5680b57cec5SDimitry Andric 
GetDescription(llvm::raw_ostream & s,lldb::DescriptionLevel level,unsigned indentation) const5690b57cec5SDimitry Andric void BreakpointOptions::CommandBaton::GetDescription(
570480093f4SDimitry Andric     llvm::raw_ostream &s, lldb::DescriptionLevel level,
571480093f4SDimitry Andric     unsigned indentation) const {
5720b57cec5SDimitry Andric   const CommandData *data = getItem();
5730b57cec5SDimitry Andric 
5740b57cec5SDimitry Andric   if (level == eDescriptionLevelBrief) {
575480093f4SDimitry Andric     s << ", commands = "
576480093f4SDimitry Andric       << ((data && data->user_source.GetSize() > 0) ? "yes" : "no");
5770b57cec5SDimitry Andric     return;
5780b57cec5SDimitry Andric   }
5790b57cec5SDimitry Andric 
580480093f4SDimitry Andric   indentation += 2;
581480093f4SDimitry Andric   s.indent(indentation);
582480093f4SDimitry Andric   s << "Breakpoint commands";
5830b57cec5SDimitry Andric   if (data->interpreter != eScriptLanguageNone)
584480093f4SDimitry Andric     s << llvm::formatv(" ({0}):\n",
585480093f4SDimitry Andric                        ScriptInterpreter::LanguageToString(data->interpreter));
5860b57cec5SDimitry Andric   else
587480093f4SDimitry Andric     s << ":\n";
5880b57cec5SDimitry Andric 
589480093f4SDimitry Andric   indentation += 2;
5900b57cec5SDimitry Andric   if (data && data->user_source.GetSize() > 0) {
591480093f4SDimitry Andric     for (llvm::StringRef str : data->user_source) {
592480093f4SDimitry Andric       s.indent(indentation);
593480093f4SDimitry Andric       s << str << "\n";
5940b57cec5SDimitry Andric     }
595480093f4SDimitry Andric   } else
596480093f4SDimitry Andric     s << "No commands.\n";
5970b57cec5SDimitry Andric }
5980b57cec5SDimitry Andric 
SetCommandDataCallback(std::unique_ptr<CommandData> & cmd_data)5990b57cec5SDimitry Andric void BreakpointOptions::SetCommandDataCallback(
6000b57cec5SDimitry Andric     std::unique_ptr<CommandData> &cmd_data) {
6010b57cec5SDimitry Andric   cmd_data->interpreter = eScriptLanguageNone;
6020b57cec5SDimitry Andric   auto baton_sp = std::make_shared<CommandBaton>(std::move(cmd_data));
6030b57cec5SDimitry Andric   SetCallback(BreakpointOptions::BreakpointOptionsCallbackFunction, baton_sp);
6040b57cec5SDimitry Andric   m_set_flags.Set(eCallback);
6050b57cec5SDimitry Andric }
6060b57cec5SDimitry Andric 
BreakpointOptionsCallbackFunction(void * baton,StoppointCallbackContext * context,lldb::user_id_t break_id,lldb::user_id_t break_loc_id)6070b57cec5SDimitry Andric bool BreakpointOptions::BreakpointOptionsCallbackFunction(
6080b57cec5SDimitry Andric     void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id,
6090b57cec5SDimitry Andric     lldb::user_id_t break_loc_id) {
6100b57cec5SDimitry Andric   bool ret_value = true;
6110b57cec5SDimitry Andric   if (baton == nullptr)
6120b57cec5SDimitry Andric     return true;
6130b57cec5SDimitry Andric 
6140b57cec5SDimitry Andric   CommandData *data = (CommandData *)baton;
6150b57cec5SDimitry Andric   StringList &commands = data->user_source;
6160b57cec5SDimitry Andric 
6170b57cec5SDimitry Andric   if (commands.GetSize() > 0) {
6180b57cec5SDimitry Andric     ExecutionContext exe_ctx(context->exe_ctx_ref);
6190b57cec5SDimitry Andric     Target *target = exe_ctx.GetTargetPtr();
6200b57cec5SDimitry Andric     if (target) {
6210b57cec5SDimitry Andric       Debugger &debugger = target->GetDebugger();
6225ffd83dbSDimitry Andric       CommandReturnObject result(debugger.GetUseColor());
6235ffd83dbSDimitry Andric 
6240b57cec5SDimitry Andric       // Rig up the results secondary output stream to the debugger's, so the
6250b57cec5SDimitry Andric       // output will come out synchronously if the debugger is set up that way.
6260b57cec5SDimitry Andric       StreamSP output_stream(debugger.GetAsyncOutputStream());
6270b57cec5SDimitry Andric       StreamSP error_stream(debugger.GetAsyncErrorStream());
6280b57cec5SDimitry Andric       result.SetImmediateOutputStream(output_stream);
6290b57cec5SDimitry Andric       result.SetImmediateErrorStream(error_stream);
6300b57cec5SDimitry Andric 
6310b57cec5SDimitry Andric       CommandInterpreterRunOptions options;
6320b57cec5SDimitry Andric       options.SetStopOnContinue(true);
6330b57cec5SDimitry Andric       options.SetStopOnError(data->stop_on_error);
6340b57cec5SDimitry Andric       options.SetEchoCommands(true);
6350b57cec5SDimitry Andric       options.SetPrintResults(true);
6360b57cec5SDimitry Andric       options.SetPrintErrors(true);
6370b57cec5SDimitry Andric       options.SetAddToHistory(false);
6380b57cec5SDimitry Andric 
639fe6060f1SDimitry Andric       debugger.GetCommandInterpreter().HandleCommands(commands, exe_ctx,
6400b57cec5SDimitry Andric                                                       options, result);
6410b57cec5SDimitry Andric       result.GetImmediateOutputStream()->Flush();
6420b57cec5SDimitry Andric       result.GetImmediateErrorStream()->Flush();
6430b57cec5SDimitry Andric     }
6440b57cec5SDimitry Andric   }
6450b57cec5SDimitry Andric   return ret_value;
6460b57cec5SDimitry Andric }
6470b57cec5SDimitry Andric 
Clear()6480b57cec5SDimitry Andric void BreakpointOptions::Clear()
6490b57cec5SDimitry Andric {
6500b57cec5SDimitry Andric   m_set_flags.Clear();
6510b57cec5SDimitry Andric   m_thread_spec_up.release();
6520b57cec5SDimitry Andric   m_one_shot = false;
6530b57cec5SDimitry Andric   m_ignore_count = 0;
6540b57cec5SDimitry Andric   m_auto_continue = false;
6550b57cec5SDimitry Andric   m_callback = nullptr;
6560b57cec5SDimitry Andric   m_callback_baton_sp.reset();
6570b57cec5SDimitry Andric   m_baton_is_command_baton = false;
6580b57cec5SDimitry Andric   m_callback_is_synchronous = false;
6590b57cec5SDimitry Andric   m_enabled = false;
6600b57cec5SDimitry Andric   m_condition_text.clear();
6610b57cec5SDimitry Andric }
662