Go to the documentation of this file.
21 #include "llvm/ADT/STLExtras.h"
27 *BreakpointOptions::CommandData::g_option_names[
static_cast<uint32_t>(
28 BreakpointOptions::CommandData::OptionNames::LastOptionName)]{
29 "UserSource",
"ScriptSource",
"StopOnError"};
32 BreakpointOptions::CommandData::SerializeToStructuredData() {
33 size_t num_strings = user_source.GetSize();
34 if (num_strings == 0 && script_source.empty()) {
42 options_dict_sp->AddBooleanItem(GetKey(OptionNames::StopOnError),
46 for (
size_t i = 0; i < num_strings; i++) {
49 user_source_sp->AddItem(item_sp);
50 options_dict_sp->AddItem(GetKey(OptionNames::UserSource), user_source_sp);
53 options_dict_sp->AddStringItem(
54 GetKey(OptionNames::Interpreter),
55 ScriptInterpreter::LanguageToString(interpreter));
56 return options_dict_sp;
59 std::unique_ptr<BreakpointOptions::CommandData>
60 BreakpointOptions::CommandData::CreateFromStructuredData(
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.");
77 interp_language = ScriptInterpreter::StringToLanguage(interpreter_str);
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 llvm::StringRef elem_string;
94 data_up->user_source.AppendString(elem_string);
101 const char *BreakpointOptions::g_option_names[(
102 size_t)BreakpointOptions::OptionNames::LastOptionName]{
103 "ConditionText",
"IgnoreCount",
104 "EnabledState",
"OneShotState",
"AutoContinue"};
106 bool BreakpointOptions::NullCallback(
void *baton,
114 BreakpointOptions::BreakpointOptions(
bool all_flags_set)
116 m_baton_is_command_baton(false), m_callback_is_synchronous(false),
117 m_enabled(true), m_one_shot(false), m_ignore_count(0),
118 m_condition_text_hash(0), m_inject_condition(false),
119 m_auto_continue(false), m_set_flags(0) {
125 int32_t ignore,
bool one_shot,
127 : m_callback(nullptr), m_baton_is_command_baton(false),
128 m_callback_is_synchronous(false), m_enabled(enabled),
129 m_one_shot(one_shot), m_ignore_count(ignore), m_condition_text_hash(0),
130 m_inject_condition(false), m_auto_continue(auto_continue) {
132 if (condition && *condition !=
'\0') {
139 : m_callback(rhs.m_callback), m_callback_baton_sp(rhs.m_callback_baton_sp),
140 m_baton_is_command_baton(rhs.m_baton_is_command_baton),
141 m_callback_is_synchronous(rhs.m_callback_is_synchronous),
142 m_enabled(rhs.m_enabled), m_one_shot(rhs.m_one_shot),
143 m_ignore_count(rhs.m_ignore_count), m_inject_condition(false),
144 m_auto_continue(rhs.m_auto_continue), m_set_flags(rhs.m_set_flags) {
231 bool one_shot =
false;
232 bool auto_continue =
false;
233 int32_t ignore_count = 0;
234 llvm::StringRef condition_ref(
"");
239 if (key && options_dict.
HasKey(key)) {
242 error.SetErrorStringWithFormat(
"%s key is not a boolean.", key);
249 if (key && options_dict.
HasKey(key)) {
252 error.SetErrorStringWithFormat(
"%s key is not a boolean.", key);
259 if (key && options_dict.
HasKey(key)) {
262 error.SetErrorStringWithFormat(
"%s key is not a boolean.", key);
269 if (key && options_dict.
HasKey(key)) {
272 error.SetErrorStringWithFormat(
"%s key is not an integer.", key);
279 if (key && options_dict.
HasKey(key)) {
282 error.SetErrorStringWithFormat(
"%s key is not an string.", key);
288 std::unique_ptr<CommandData> cmd_data_up;
292 if (success && cmds_dict) {
295 if (cmds_error.
Fail()) {
296 error.SetErrorStringWithFormat(
297 "Failed to deserialize breakpoint command options: %s.",
303 auto bp_options = std::make_unique<BreakpointOptions>(
304 condition_ref.str().c_str(), enabled,
305 ignore_count, one_shot, auto_continue);
308 bp_options->SetCommandDataCallback(cmd_data_up);
312 error.SetErrorString(
313 "Can't set script commands - no script interpreter");
316 if (interp->
GetLanguage() != cmd_data_up->interpreter) {
317 error.SetErrorStringWithFormat(
318 "Current script language doesn't match breakpoint's language: %s",
326 if (script_error.
Fail()) {
327 error.SetErrorStringWithFormat(
"Error generating script callback: %s.",
339 std::unique_ptr<ThreadSpec> thread_spec_up =
342 if (thread_spec_error.
Fail()) {
343 error.SetErrorStringWithFormat(
344 "Failed to deserialize breakpoint thread spec options: %s.",
348 bp_options->SetThreadSpec(thread_spec_up);
376 cmd_baton->getItem()->SerializeToStructuredData();
378 options_dict_sp->AddItem(
388 return options_dict_sp;
393 const lldb::BatonSP &callback_baton_sp,
394 bool callback_is_synchronous) {
413 BreakpointHitCallback callback,
415 bool callback_is_synchronous) {
444 context, break_id, break_loc_id);
471 if (!condition || condition[0] ==
'\0') {
479 std::hash<std::string> hasher;
513 std::unique_ptr<ThreadSpec> &thread_spec_up) {
544 s->
Printf(
"auto-continue ");
572 unsigned indentation)
const {
577 << ((
data &&
data->user_source.GetSize() > 0) ?
"yes" :
"no");
582 s.indent(indentation);
583 s <<
"Breakpoint commands";
585 s << llvm::formatv(
" ({0}):\n",
591 if (
data &&
data->user_source.GetSize() > 0) {
592 for (llvm::StringRef str :
data->user_source) {
593 s.indent(indentation);
597 s <<
"No commands.\n";
601 std::unique_ptr<CommandData> &cmd_data) {
603 auto baton_sp = std::make_shared<CommandBaton>(std::move(cmd_data));
611 bool ret_value =
true;
612 if (baton ==
nullptr)
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
std::string m_condition_text
The condition to test.
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.
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
ThreadSpec * GetThreadSpec()
Returns a pointer to the ThreadSpec for this option, creating it.
ScriptLanguage
Script interpreter types.
size_t m_condition_text_hash
Its hash, so that locations know when the condition is updated.
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
BreakpointHitCallback m_callback
For BreakpointOptions only.
bool m_baton_is_command_baton
Baton * GetBaton()
Fetch the baton from the callback.
CommandInterpreter & GetCommandInterpreter()
void SetCondition(const char *condition)
Set the breakpoint option's condition.
bool m_one_shot
If set, the breakpoint delete itself after being hit once.
const char * GetConditionText(size_t *hash=nullptr) const
Return a pointer to the text of the condition expression.
void SetThreadID(lldb::tid_t thread_id)
ValueType Clear(ValueType mask=~static_cast< ValueType >(0))
Clear one or more flags.
void SetAddToHistory(bool add_to_history)
ExecutionContextRef exe_ctx_ref
bool Test(ValueType bit) const
Test a single flag bit.
static bool NullCallback(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
This is the default empty callback.
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
const ThreadSpec * GetThreadSpecNoCreate() const
Return the current thread spec for this option.
lldb::ScriptLanguage GetLanguage()
static std::unique_ptr< BreakpointOptions > CreateFromStructuredData(Target &target, const StructuredData::Dictionary &data_dict, Status &error)
static llvm::raw_ostream & error(Stream &strm)
void SetEchoCommands(bool echo_commands)
std::shared_ptr< String > StringSP
bool m_inject_condition
If set, inject breakpoint condition into process.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
virtual ~BreakpointOptions()
void SetStopOnContinue(bool stop_on_continue)
uint32_t m_ignore_count
Number of times to ignore this breakpoint.
bool Fail() const
Test for error condition.
void SetCallback(BreakpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous=false)
Adds a callback to the breakpoint option set.
lldb::StreamSP GetAsyncOutputStream()
std::shared_ptr< Object > ObjectSP
lldb::StreamSP GetImmediateErrorStream()
std::unique_ptr< ThreadSpec > m_thread_spec_up
Thread for which this breakpoint will stop.
std::shared_ptr< CommandBaton > CommandBatonSP
bool HasCallback() const
Check if the breakpoint option has a callback set.
lldb::StreamSP GetAsyncErrorStream()
Flags m_set_flags
Which options are set at this level.
lldb::StreamSP GetImmediateOutputStream()
std::shared_ptr< Dictionary > DictionarySP
unsigned GetIndentLevel() const
Get the current indentation level.
void SetCommandDataCallback(std::unique_ptr< CommandData > &cmd_data)
Set a callback based on BreakpointOptions::CommandData.
void SetTID(lldb::tid_t tid)
static bool BreakpointOptionsCallbackFunction(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
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.
virtual StructuredData::ObjectSP SerializeToStructuredData()
void SetThreadSpec(std::unique_ptr< ThreadSpec > &thread_spec_up)
void IndentMore(unsigned amount=2)
Increment the current indentation level.
void SetImmediateOutputStream(const lldb::StreamSP &stream_sp)
const BreakpointOptions & operator=(const BreakpointOptions &rhs)
size_t EOL()
Output and End of Line character to the stream.
static const char * GetSerializationKey()
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.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
bool HasKey(llvm::StringRef key) const
static std::string LanguageToString(lldb::ScriptLanguage language)
lldb::BatonSP m_callback_baton_sp
This is the client data for the callback.
bool IsCallbackSynchronous() const
Used in InvokeCallback to tell whether it is the right time to run this kind of callback.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
static const char * GetSerializationKey()
bool m_callback_is_synchronous
static const char * GetKey(OptionNames enum_value)
void SetPrintResults(bool print_results)
bool m_auto_continue
If set, auto-continue from breakpoint.
A class that represents a running process on the host machine.
@ eDescriptionLevelVerbose
bool GetValueForKeyAsDictionary(llvm::StringRef key, Dictionary *&result) const
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level, unsigned indentation) const override
static std::unique_ptr< ThreadSpec > CreateFromStructuredData(const StructuredData::Dictionary &data_dict, Status &error)
void SetImmediateErrorStream(const lldb::StreamSP &stream_sp)
bool GetItemAtIndexAsString(size_t idx, llvm::StringRef &result) const
std::shared_ptr< Array > ArraySP
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
void SetStopOnError(bool stop_on_error)
bool GetCommandLineCallbacks(StringList &command_list)
Returns the command line commands for the callback on this breakpoint.
bool GetValueForKeyAsBoolean(llvm::StringRef key, bool &result) const
void SetPrintErrors(bool print_errors)
void ClearCallback()
Remove the callback from this option set.
Target * GetTargetPtr() const
Returns a pointer to the target object.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
void CopyOverSetOptions(const BreakpointOptions &rhs)
Copy over only the options set in the incoming BreakpointOptions.
void HandleCommands(const StringList &commands, const ExecutionContext &context, const CommandInterpreterRunOptions &options, CommandReturnObject &result)
Execute a list of commands in sequence.
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
static std::unique_ptr< CommandData > CreateFromStructuredData(const StructuredData::Dictionary &options_dict, Status &error)