21#include "llvm/ADT/STLExtras.h"
28 BreakpointOptions::CommandData::OptionNames::LastOptionName)]{
29 "UserSource",
"ScriptSource",
"StopOnError"};
46 for (
size_t i = 0; i < num_strings; i++) {
49 user_source_sp->AddItem(item_sp);
53 options_dict_sp->AddStringItem(
56 return options_dict_sp;
59std::unique_ptr<BreakpointOptions::CommandData>
62 std::unique_ptr<CommandData> data_up(
new CommandData());
65 GetKey(OptionNames::StopOnError), data_up->stop_on_error);
67 llvm::StringRef interpreter_str;
70 GetKey(OptionNames::Interpreter), interpreter_str);
73 error.SetErrorString(
"Missing command language value.");
79 error.SetErrorStringWithFormatv(
"Unknown breakpoint command language: {0}.",
83 data_up->interpreter = interp_language;
89 size_t num_elems = user_source->
GetSize();
90 for (
size_t i = 0; i < num_elems; i++) {
91 if (std::optional<llvm::StringRef> maybe_elem_string =
93 data_up->user_source.AppendString(*maybe_elem_string);
102 "ConditionText",
"IgnoreCount",
103 "EnabledState",
"OneShotState",
"AutoContinue"};
116 int32_t ignore,
bool one_shot,
118 : m_callback(nullptr), m_baton_is_command_baton(false),
119 m_callback_is_synchronous(false), m_enabled(enabled),
120 m_one_shot(one_shot), m_ignore_count(ignore), m_condition_text_hash(0),
121 m_inject_condition(false), m_auto_continue(auto_continue) {
123 if (condition && *condition !=
'\0') {
130 : m_callback(rhs.m_callback), m_callback_baton_sp(rhs.m_callback_baton_sp),
131 m_baton_is_command_baton(rhs.m_baton_is_command_baton),
132 m_callback_is_synchronous(rhs.m_callback_is_synchronous),
133 m_enabled(rhs.m_enabled), m_one_shot(rhs.m_one_shot),
134 m_ignore_count(rhs.m_ignore_count), m_inject_condition(false),
135 m_auto_continue(rhs.m_auto_continue), m_set_flags(rhs.m_set_flags) {
222 bool one_shot =
false;
223 bool auto_continue =
false;
224 uint32_t ignore_count = 0;
225 llvm::StringRef condition_ref(
"");
230 if (key && options_dict.
HasKey(key)) {
233 error.SetErrorStringWithFormat(
"%s key is not a boolean.", key);
240 if (key && options_dict.
HasKey(key)) {
243 error.SetErrorStringWithFormat(
"%s key is not a boolean.", key);
250 if (key && options_dict.
HasKey(key)) {
253 error.SetErrorStringWithFormat(
"%s key is not a boolean.", key);
260 if (key && options_dict.
HasKey(key)) {
263 error.SetErrorStringWithFormat(
"%s key is not an integer.", key);
270 if (key && options_dict.
HasKey(key)) {
273 error.SetErrorStringWithFormat(
"%s key is not an string.", key);
279 std::unique_ptr<CommandData> cmd_data_up;
283 if (success && cmds_dict) {
286 if (cmds_error.
Fail()) {
287 error.SetErrorStringWithFormat(
288 "Failed to deserialize breakpoint command options: %s.",
294 auto bp_options = std::make_unique<BreakpointOptions>(
295 condition_ref.str().c_str(), enabled,
296 ignore_count, one_shot, auto_continue);
299 bp_options->SetCommandDataCallback(cmd_data_up);
303 error.SetErrorString(
304 "Can't set script commands - no script interpreter");
307 if (interp->
GetLanguage() != cmd_data_up->interpreter) {
308 error.SetErrorStringWithFormat(
309 "Current script language doesn't match breakpoint's language: %s",
317 if (script_error.
Fail()) {
318 error.SetErrorStringWithFormat(
"Error generating script callback: %s.",
330 std::unique_ptr<ThreadSpec> thread_spec_up =
333 if (thread_spec_error.
Fail()) {
334 error.SetErrorStringWithFormat(
335 "Failed to deserialize breakpoint thread spec options: %s.",
339 bp_options->SetThreadSpec(thread_spec_up);
367 cmd_baton->getItem()->SerializeToStructuredData();
369 options_dict_sp->AddItem(
379 return options_dict_sp;
385 bool callback_is_synchronous) {
406 bool callback_is_synchronous) {
435 context, break_id, break_loc_id);
462 if (!condition || condition[0] ==
'\0') {
470 std::hash<std::string> hasher;
504 std::unique_ptr<ThreadSpec> &thread_spec_up) {
535 s->
Printf(
"auto-continue ");
563 unsigned indentation)
const {
568 << ((
data &&
data->user_source.GetSize() > 0) ?
"yes" :
"no");
573 s.indent(indentation);
574 s <<
"Breakpoint commands";
576 s << llvm::formatv(
" ({0}):\n",
582 if (
data &&
data->user_source.GetSize() > 0) {
583 for (llvm::StringRef str :
data->user_source) {
584 s.indent(indentation);
588 s <<
"No commands.\n";
592 std::unique_ptr<CommandData> &cmd_data) {
594 auto baton_sp = std::make_shared<CommandBaton>(std::move(cmd_data));
602 bool ret_value =
true;
603 if (baton ==
nullptr)
static llvm::raw_ostream & error(Stream &strm)
A class designed to wrap callback batons so they can cleanup any acquired resources.
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level, unsigned indentation) const override
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
bool IsCallbackSynchronous() const
Used in InvokeCallback to tell whether it is the right time to run this kind of callback.
bool InvokeCallback(StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
Use this function to invoke the callback for a specific stop.
void ClearCallback()
Remove the callback from this option set.
Flags m_set_flags
Which options are set at this level.
void SetCondition(const char *condition)
Set the breakpoint option's condition.
bool GetCommandLineCallbacks(StringList &command_list)
Returns the command line commands for the callback on this breakpoint.
std::shared_ptr< CommandBaton > CommandBatonSP
static const char * GetKey(OptionNames enum_value)
Baton * GetBaton()
Fetch the baton from the callback.
static bool BreakpointOptionsCallbackFunction(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
virtual StructuredData::ObjectSP SerializeToStructuredData()
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
bool m_one_shot
If set, the breakpoint delete itself after being hit once.
static const char * g_option_names[(size_t) OptionNames::LastOptionName]
bool m_callback_is_synchronous
bool m_baton_is_command_baton
lldb::BatonSP m_callback_baton_sp
This is the client data for the callback.
ThreadSpec * GetThreadSpec()
Returns a pointer to the ThreadSpec for this option, creating it.
const ThreadSpec * GetThreadSpecNoCreate() const
Return the current thread spec for this option.
std::unique_ptr< ThreadSpec > m_thread_spec_up
Thread for which this breakpoint will stop.
BreakpointHitCallback m_callback
For BreakpointOptions only.
bool m_inject_condition
If set, inject breakpoint condition into process.
std::string m_condition_text
The condition to test.
bool m_auto_continue
If set, auto-continue from breakpoint.
static std::unique_ptr< BreakpointOptions > CreateFromStructuredData(Target &target, const StructuredData::Dictionary &data_dict, Status &error)
virtual ~BreakpointOptions()
uint32_t m_ignore_count
Number of times to ignore this breakpoint.
void SetThreadID(lldb::tid_t thread_id)
void CopyOverSetOptions(const BreakpointOptions &rhs)
Copy over only the options set in the incoming BreakpointOptions.
BreakpointOptions(const char *condition, bool enabled=true, int32_t ignore=0, bool one_shot=false, bool auto_continue=false)
This constructor allows you to specify all the breakpoint options except the callback.
size_t m_condition_text_hash
Its hash, so that locations know when the condition is updated.
const char * GetConditionText(size_t *hash=nullptr) const
Return a pointer to the text of the condition expression.
bool HasCallback() const
Check if the breakpoint option has a callback set.
const BreakpointOptions & operator=(const BreakpointOptions &rhs)
void SetCommandDataCallback(std::unique_ptr< CommandData > &cmd_data)
Set a callback based on BreakpointOptions::CommandData.
void SetThreadSpec(std::unique_ptr< ThreadSpec > &thread_spec_up)
void SetCallback(BreakpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous=false)
Adds a callback to the breakpoint option set.
void SetStopOnContinue(bool stop_on_continue)
void SetPrintErrors(bool print_errors)
void SetEchoCommands(bool echo_commands)
void SetAddToHistory(bool add_to_history)
void SetStopOnError(bool stop_on_error)
void SetPrintResults(bool print_results)
void HandleCommands(const StringList &commands, const ExecutionContext &context, const CommandInterpreterRunOptions &options, CommandReturnObject &result)
Execute a list of commands in sequence.
void SetImmediateErrorStream(const lldb::StreamSP &stream_sp)
lldb::StreamSP GetImmediateOutputStream()
void SetImmediateOutputStream(const lldb::StreamSP &stream_sp)
lldb::StreamSP GetImmediateErrorStream()
A class to manage flag bits.
lldb::StreamSP GetAsyncOutputStream()
CommandInterpreter & GetCommandInterpreter()
lldb::StreamSP GetAsyncErrorStream()
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Target * GetTargetPtr() const
Returns a pointer to the target object.
ValueType Clear(ValueType mask=~static_cast< ValueType >(0))
Clear one or more flags.
uint32_t ValueType
The value type for flags is a 32 bit unsigned integer type.
bool Test(ValueType bit) const
Test a single flag bit.
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
static lldb::ScriptLanguage StringToLanguage(const llvm::StringRef &string)
Status SetBreakpointCommandCallback(std::vector< std::reference_wrapper< BreakpointOptions > > &bp_options_vec, const char *callback_text)
Set the specified text as the callback for the breakpoint.
static std::string LanguageToString(lldb::ScriptLanguage language)
lldb::ScriptLanguage GetLanguage()
bool Fail() const
Test for error condition.
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
ExecutionContextRef exe_ctx_ref
A stream class that can stream formatted output to a file.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
void IndentMore(unsigned amount=2)
Increment the current indentation level.
unsigned GetIndentLevel() const
Get the current indentation level.
std::optional< llvm::StringRef > GetItemAtIndexAsString(size_t idx) const
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
bool GetValueForKeyAsBoolean(llvm::StringRef key, bool &result) const
bool HasKey(llvm::StringRef key) const
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
bool GetValueForKeyAsDictionary(llvm::StringRef key, Dictionary *&result) const
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
std::shared_ptr< String > StringSP
std::shared_ptr< Array > ArraySP
void SetTID(lldb::tid_t tid)
static const char * GetSerializationKey()
static std::unique_ptr< ThreadSpec > CreateFromStructuredData(const StructuredData::Dictionary &data_dict, Status &error)
A class that represents a running process on the host machine.
std::function< bool(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)> BreakpointHitCallback
ScriptLanguage
Script interpreter types.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::Stream > StreamSP
std::shared_ptr< lldb_private::Baton > BatonSP
enum lldb::ScriptLanguage interpreter
std::string script_source
static std::unique_ptr< CommandData > CreateFromStructuredData(const StructuredData::Dictionary &options_dict, Status &error)
static const char * GetSerializationKey()
StructuredData::ObjectSP SerializeToStructuredData()
static const char * GetKey(OptionNames enum_value)
static const char * g_option_names[static_cast< uint32_t >(OptionNames::LastOptionName)]