14#include "llvm/ADT/StringRef.h"
42 bool process_is_valid =
44 if (!process_is_valid) {
45 result.
AppendError(
"There's no process or it is not alive.");
53static const char *
RSA[4] = {
"-",
"to",
"To",
"TO"};
59 for (i = 0; i < 4; ++i)
60 if (Arg.contains(
RSA[i]))
68 Target *target,
Args &args, std::vector<uint32_t> &wp_ids) {
71 if (target ==
nullptr)
75 wp_ids.push_back(watch_sp->GetID());
81 llvm::StringRef Minus(
"-");
82 std::vector<llvm::StringRef> StrRefArgs;
83 llvm::StringRef first;
84 llvm::StringRef second;
89 for (
auto &entry : args.
entries()) {
91 StrRefArgs.push_back(entry.ref());
95 std::tie(first, second) = entry.ref().split(
RSA[idx]);
97 StrRefArgs.push_back(first);
98 StrRefArgs.push_back(Minus);
100 StrRefArgs.push_back(second);
105 size_t size = StrRefArgs.size();
106 bool in_range =
false;
107 for (i = 0; i < size; ++i) {
108 llvm::StringRef Arg = StrRefArgs[i];
112 if (Arg.getAsInteger(0, end))
115 for (
id = beg;
id <= end; ++
id)
116 wp_ids.push_back(
id);
120 if (i < (size - 1) && StrRefArgs[i + 1] == Minus) {
121 if (Arg.getAsInteger(0, beg))
129 if (Arg.getAsInteger(0, beg))
131 wp_ids.push_back(beg);
141#pragma mark List::CommandOptions
142#define LLDB_OPTIONS_watchpoint_list
143#include "CommandOptions.inc"
151 interpreter,
"watchpoint list",
152 "List all watchpoints at configurable levels of detail.", nullptr,
153 eCommandRequiresTarget) {
159 m_arguments.push_back(arg);
175 const int short_option = m_getopt_table[option_idx].val;
177 switch (short_option) {
188 llvm_unreachable(
"Unimplemented option");
199 return llvm::ArrayRef(g_watchpoint_list_options);
209 Target *target = &GetSelectedTarget();
212 std::optional<uint32_t> num_supported_hardware_watchpoints =
215 if (num_supported_hardware_watchpoints)
217 "Number of supported hardware watchpoints: %u\n",
218 *num_supported_hardware_watchpoints);
223 std::unique_lock<std::recursive_mutex> lock;
226 size_t num_watchpoints = watchpoints.
GetSize();
228 if (num_watchpoints == 0) {
239 for (
size_t i = 0; i < num_watchpoints; ++i) {
240 WatchpointSP watch_sp = watchpoints.
GetByIndex(i);
246 std::vector<uint32_t> wp_ids;
248 target, command, wp_ids)) {
249 result.
AppendError(
"Invalid watchpoints specification.");
253 const size_t size = wp_ids.size();
254 for (
size_t i = 0; i < size; ++i) {
255 WatchpointSP watch_sp = watchpoints.
FindByID(wp_ids[i]);
276 "Enable the specified disabled watchpoint(s). If "
277 "no watchpoints are specified, enable all of them.",
278 nullptr, eCommandRequiresTarget) {
284 m_arguments.push_back(arg);
299 Target *target = &GetSelectedTarget();
303 std::unique_lock<std::recursive_mutex> lock;
308 size_t num_watchpoints = watchpoints.
GetSize();
310 if (num_watchpoints == 0) {
311 result.
AppendError(
"No watchpoints exist to be enabled.");
320 (uint64_t)num_watchpoints);
324 std::vector<uint32_t> wp_ids;
326 target, command, wp_ids)) {
327 result.
AppendError(
"Invalid watchpoints specification.");
332 const size_t size = wp_ids.size();
333 for (
size_t i = 0; i < size; ++i)
351 "Disable the specified watchpoint(s) without "
352 "removing it/them. If no watchpoints are "
353 "specified, disable them all.",
354 nullptr, eCommandRequiresTarget) {
360 m_arguments.push_back(arg);
375 Target *target = &GetSelectedTarget();
379 std::unique_lock<std::recursive_mutex> lock;
383 size_t num_watchpoints = watchpoints.
GetSize();
385 if (num_watchpoints == 0) {
386 result.
AppendError(
"No watchpoints exist to be disabled.");
395 (uint64_t)num_watchpoints);
398 result.
AppendError(
"Disable all watchpoints failed\n");
402 std::vector<uint32_t> wp_ids;
404 target, command, wp_ids)) {
405 result.
AppendError(
"Invalid watchpoints specification.");
410 const size_t size = wp_ids.size();
411 for (
size_t i = 0; i < size; ++i)
423#define LLDB_OPTIONS_watchpoint_delete
424#include "CommandOptions.inc"
433 "Delete the specified watchpoint(s). If no "
434 "watchpoints are specified, delete them all.",
435 nullptr, eCommandRequiresTarget) {
441 m_arguments.push_back(arg);
464 const int short_option = m_getopt_table[option_idx].val;
466 switch (short_option) {
471 llvm_unreachable(
"Unimplemented option");
482 return llvm::ArrayRef(g_watchpoint_delete_options);
486 bool m_force =
false;
491 Target *target = &GetSelectedTarget();
495 std::unique_lock<std::recursive_mutex> lock;
500 size_t num_watchpoints = watchpoints.
GetSize();
502 if (num_watchpoints == 0) {
503 result.
AppendError(
"No watchpoints exist to be deleted.");
507 if (command.
empty()) {
508 if (!m_options.m_force &&
509 !m_interpreter.Confirm(
510 "About to delete all watchpoints, do you want to do that?",
517 (uint64_t)num_watchpoints);
524 std::vector<uint32_t> wp_ids;
527 result.
AppendError(
"Invalid watchpoints specification.");
532 const size_t size = wp_ids.size();
533 for (
size_t i = 0; i < size; ++i)
548#pragma mark Ignore::CommandOptions
549#define LLDB_OPTIONS_watchpoint_ignore
550#include "CommandOptions.inc"
556 "Set ignore count on the specified watchpoint(s). "
557 "If no watchpoints are specified, set them all.",
558 nullptr, eCommandRequiresTarget) {
564 m_arguments.push_back(arg);
588 const int short_option = m_getopt_table[option_idx].val;
590 switch (short_option) {
592 if (option_arg.getAsInteger(0, m_ignore_count))
593 error.SetErrorStringWithFormat(
"invalid ignore count '%s'",
594 option_arg.str().c_str());
597 llvm_unreachable(
"Unimplemented option");
608 return llvm::ArrayRef(g_watchpoint_ignore_options);
618 Target *target = &GetSelectedTarget();
622 std::unique_lock<std::recursive_mutex> lock;
627 size_t num_watchpoints = watchpoints.
GetSize();
629 if (num_watchpoints == 0) {
630 result.
AppendError(
"No watchpoints exist to be ignored.");
638 (uint64_t)num_watchpoints);
642 std::vector<uint32_t> wp_ids;
644 target, command, wp_ids)) {
645 result.
AppendError(
"Invalid watchpoints specification.");
650 const size_t size = wp_ids.size();
651 for (
size_t i = 0; i < size; ++i)
667#pragma mark Modify::CommandOptions
668#define LLDB_OPTIONS_watchpoint_modify
669#include "CommandOptions.inc"
677 interpreter,
"watchpoint modify",
678 "Modify the options on a watchpoint or set of watchpoints in the "
680 "If no watchpoint is specified, act on the last created "
682 "Passing an empty argument clears the modification.",
683 nullptr, eCommandRequiresTarget) {
689 m_arguments.push_back(arg);
713 const int short_option = m_getopt_table[option_idx].val;
715 switch (short_option) {
717 m_condition = std::string(option_arg);
718 m_condition_passed =
true;
721 llvm_unreachable(
"Unimplemented option");
729 m_condition_passed =
false;
733 return llvm::ArrayRef(g_watchpoint_modify_options);
739 bool m_condition_passed =
false;
744 Target *target = &GetSelectedTarget();
748 std::unique_lock<std::recursive_mutex> lock;
753 size_t num_watchpoints = watchpoints.
GetSize();
755 if (num_watchpoints == 0) {
756 result.
AppendError(
"No watchpoints exist to be modified.");
762 watch_sp->SetCondition(m_options.m_condition.c_str());
766 std::vector<uint32_t> wp_ids;
768 target, command, wp_ids)) {
769 result.
AppendError(
"Invalid watchpoints specification.");
774 const size_t size = wp_ids.size();
775 for (
size_t i = 0; i < size; ++i) {
776 WatchpointSP watch_sp = watchpoints.
FindByID(wp_ids[i]);
778 watch_sp->SetCondition(m_options.m_condition.c_str());
794#pragma mark SetVariable
800 interpreter,
"watchpoint set variable",
801 "Set a watchpoint on a variable. "
802 "Use the '-w' option to specify the type of watchpoint and "
803 "the '-s' option to specify the byte size to watch for. "
804 "If no '-w' option is specified, it defaults to write. "
805 "If no '-s' option is specified, it defaults to the variable's "
807 "Note that there are limited hardware resources for watchpoints. "
808 "If watchpoint setting fails, consider disable/delete existing "
810 "to free up resources.",
812 eCommandRequiresFrame | eCommandTryTargetAPILock |
813 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
818(lldb) watchpoint set variable -w read_write my_global_var
821 " Watches my_global_var for read/write access, with the region to watch \
822corresponding to the byte size of the data type.");
832 arg.push_back(var_name_arg);
835 m_arguments.push_back(arg);
840 m_option_group.Finalize();
855 Options *GetOptions()
override {
return &m_option_group; }
858 static size_t GetVariableCallback(
void *baton,
const char *name,
860 size_t old_size = variable_list.
GetSize();
865 return variable_list.
GetSize() - old_size;
869 Target *target = GetDebugger().GetSelectedTarget().get();
876 "specify your program variable to watch for");
881 if (!m_option_watchpoint.watch_type_specified) {
891 ValueObjectSP valobj_sp;
896 result.
AppendError(
"specify exactly one variable to watch for");
917 m_exe_ctx.GetBestExecutionContextScope(), GetVariableCallback, target,
918 variable_list, valobj_list));
928 addr = valobj_sp->GetAddressOf(
false, &addr_type);
932 size = m_option_watchpoint.watch_size == 0
934 : m_option_watchpoint.watch_size;
936 compiler_type = valobj_sp->GetCompilerType();
938 const char *error_cstr =
error.AsCString(
nullptr);
943 "expression path that matches '%s'",
949 uint32_t watch_type = m_option_watchpoint.watch_type;
952 WatchpointSP watch_sp =
956 watch_sp->SetWatchVariable(
true);
957 if (var_sp && var_sp->GetDeclaration().GetFile()) {
960 var_sp->GetDeclaration().DumpStopContext(&ss,
true);
961 watch_sp->SetDeclInfo(std::string(ss.
GetString()));
963 output_stream.
Printf(
"Watchpoint created: ");
969 "Watchpoint creation failed (addr=0x%" PRIx64
", size=%" PRIu64
970 ", variable expression='%s').\n",
972 if (
error.AsCString(
nullptr))
991 interpreter,
"watchpoint set expression",
992 "Set a watchpoint on an address by supplying an expression. "
993 "Use the '-w' option to specify the type of watchpoint and "
994 "the '-s' option to specify the byte size to watch for. "
995 "If no '-w' option is specified, it defaults to write. "
996 "If no '-s' option is specified, it defaults to the target's "
997 "pointer byte size. "
998 "Note that there are limited hardware resources for watchpoints. "
999 "If watchpoint setting fails, consider disable/delete existing "
1001 "to free up resources.",
1003 eCommandRequiresFrame | eCommandTryTargetAPILock |
1004 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
1009(lldb) watchpoint set expression -w write -s 1 -- foo + 32
1011 Watches write access for the 1-byte region pointed to by the address 'foo + 32')");
1021 arg.push_back(expression_arg);
1024 m_arguments.push_back(arg);
1029 m_option_group.Finalize();
1036 bool WantsCompletion()
override {
return true; }
1038 Options *GetOptions()
override {
return &m_option_group; }
1041 bool DoExecute(llvm::StringRef raw_command,
1043 auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
1047 Target *target = GetDebugger().GetSelectedTarget().get();
1052 llvm::StringRef expr = args.GetRawPart();
1055 if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group,
1061 if (raw_command.trim().empty()) {
1062 result.
AppendError(
"required argument missing; specify an expression "
1063 "to evaluate into the address to watch for");
1068 if (!m_option_watchpoint.watch_type_specified) {
1077 ValueObjectSP valobj_sp;
1090 result.
AppendError(
"expression evaluation of address to watch failed");
1092 if (valobj_sp && !valobj_sp->GetError().Success())
1093 result.
AppendError(valobj_sp->GetError().AsCString());
1098 bool success =
false;
1099 addr = valobj_sp->GetValueAsUnsigned(0, &success);
1101 result.
AppendError(
"expression did not evaluate to an address");
1105 if (m_option_watchpoint.watch_size != 0)
1106 size = m_option_watchpoint.watch_size;
1111 uint32_t watch_type = m_option_watchpoint.watch_type;
1116 CompilerType compiler_type(valobj_sp->GetCompilerType());
1119 WatchpointSP watch_sp =
1122 watch_sp->SetWatchSpec(std::string(expr));
1124 output_stream.
Printf(
"Watchpoint created: ");
1126 output_stream.
EOL();
1130 ", size=%" PRIu64
").\n",
1131 addr, (uint64_t)size);
1132 if (
error.AsCString(
nullptr))
1151 interpreter,
"watchpoint set",
"Commands for setting a watchpoint.",
1152 "watchpoint set <subcommand> [<subcommand-options>]") {
1166#pragma mark MultiwordWatchpoint
1171 "Commands for operating on watchpoints.",
1172 "watchpoint <subcommand> [<command-options>]") {
1173 CommandObjectSP list_command_object(
1175 CommandObjectSP enable_command_object(
1177 CommandObjectSP disable_command_object(
1179 CommandObjectSP delete_command_object(
1181 CommandObjectSP ignore_command_object(
1183 CommandObjectSP command_command_object(
1185 CommandObjectSP modify_command_object(
1187 CommandObjectSP set_command_object(
1190 list_command_object->SetCommandName(
"watchpoint list");
1191 enable_command_object->SetCommandName(
"watchpoint enable");
1192 disable_command_object->SetCommandName(
"watchpoint disable");
1193 delete_command_object->SetCommandName(
"watchpoint delete");
1194 ignore_command_object->SetCommandName(
"watchpoint ignore");
1195 command_command_object->SetCommandName(
"watchpoint command");
1196 modify_command_object->SetCommandName(
"watchpoint modify");
1197 set_command_object->SetCommandName(
"watchpoint set");
static bool CheckTargetForWatchpointOperations(Target *target, CommandReturnObject &result)
static void AddWatchpointDescription(Stream &s, Watchpoint &wp, lldb::DescriptionLevel level)
static int32_t WithRSAIndex(llvm::StringRef Arg)
static const char * RSA[4]
static llvm::raw_ostream & error(Stream &strm)
~CommandOptions() override=default
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectWatchpointDelete(CommandInterpreter &interpreter)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
Options * GetOptions() override
~CommandObjectWatchpointDelete() override=default
~CommandObjectWatchpointDisable() override=default
bool DoExecute(Args &command, CommandReturnObject &result) override
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
CommandObjectWatchpointDisable(CommandInterpreter &interpreter)
CommandObjectWatchpointEnable(CommandInterpreter &interpreter)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
bool DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectWatchpointEnable() override=default
~CommandOptions() override=default
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
CommandObjectWatchpointIgnore(CommandInterpreter &interpreter)
bool DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectWatchpointIgnore() override=default
Options * GetOptions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
~CommandOptions() override=default
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
CommandObjectWatchpointList(CommandInterpreter &interpreter)
~CommandObjectWatchpointList() override=default
Options * GetOptions() override
bool DoExecute(Args &command, CommandReturnObject &result) override
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
~CommandOptions() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
Options * GetOptions() override
~CommandObjectWatchpointModify() override=default
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectWatchpointModify(CommandInterpreter &interpreter)
CommandObjectWatchpointSetExpression(CommandInterpreter &interpreter)
CommandObjectWatchpointSetVariable(CommandInterpreter &interpreter)
~CommandObjectWatchpointSet() override=default
CommandObjectWatchpointSet(CommandInterpreter &interpreter)
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
A command line argument class.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
llvm::ArrayRef< ArgEntry > entries() const
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
@ eWatchPointIDCompletion
@ eVariablePathCompletion
~CommandObjectMultiwordWatchpoint() override
CommandObjectMultiwordWatchpoint(CommandInterpreter &interpreter)
static bool VerifyWatchpointIDs(Target *target, Args &args, std::vector< uint32_t > &wp_ids)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
std::vector< CommandArgumentData > CommandArgumentEntry
static void AddIDsArgumentData(CommandArgumentEntry &arg, lldb::CommandArgumentType ID, lldb::CommandArgumentType IDRange)
void AppendMessage(llvm::StringRef in_string)
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
Stream & GetOutputStream()
Generic representation of a type in a programming language.
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
"lldb/Utility/ArgCompletionRequest.h"
size_t GetCursorIndex() const
A uniqued constant string class.
void SetUnwindOnError(bool unwind=false)
void SetKeepInMemory(bool keep=true)
void SetCoerceToId(bool coerce=true)
void SetTryAllThreads(bool try_others=true)
void SetTimeout(const Timeout< std::micro > &timeout)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void FindGlobalVariables(ConstString name, size_t max_matches, VariableList &variable_list) const
Find global and static variables by name.
A pair of an option list with a 'raw' string as a suffix.
A command line option parsing protocol class.
void NotifyOptionParsingStarting(ExecutionContext *execution_context)
This base class provides an interface to stack frames.
@ eExpressionPathOptionCheckPtrVsMember
@ eExpressionPathOptionsAllowDirectIVarAccess
lldb::ValueObjectSP GetValueForVariableExpressionPath(llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic, uint32_t options, lldb::VariableSP &var_sp, Status &error)
Create a ValueObject for a variable name / pathname, possibly including simple dereference/child sele...
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output 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.
lldb::WatchpointSP CreateWatchpoint(lldb::addr_t addr, size_t size, const CompilerType *type, uint32_t kind, Status &error)
bool IgnoreWatchpointByID(lldb::watch_id_t watch_id, uint32_t ignore_count)
bool EnableWatchpointByID(lldb::watch_id_t watch_id)
const lldb::ProcessSP & GetProcessSP() const
bool RemoveAllWatchpoints(bool end_to_end=true)
bool RemoveWatchpointByID(lldb::watch_id_t watch_id)
bool DisableAllWatchpoints(bool end_to_end=true)
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
WatchpointList & GetWatchpointList()
bool IgnoreAllWatchpoints(uint32_t ignore_count)
bool DisableWatchpointByID(lldb::watch_id_t watch_id)
lldb::WatchpointSP GetLastCreatedWatchpoint()
bool EnableAllWatchpoints(bool end_to_end=true)
lldb::ExpressionResults EvaluateExpression(llvm::StringRef expression, ExecutionContextScope *exe_scope, lldb::ValueObjectSP &result_valobj_sp, const EvaluateExpressionOptions &options=EvaluateExpressionOptions(), std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
A collection of ValueObject values that.
lldb::ValueObjectSP GetValueObjectAtIndex(size_t idx)
static Status GetValuesForVariableExpressionPath(llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list)
This class is used by Watchpoint to manage a list of watchpoints,.
lldb::WatchpointSP GetByIndex(uint32_t i)
Returns a shared pointer to the watchpoint with index i.
lldb::WatchpointSP FindByID(lldb::watch_id_t watchID) const
Returns a shared pointer to the watchpoint with id watchID, const version.
void GetListMutex(std::unique_lock< std::recursive_mutex > &lock)
Sets the passed in Locker to hold the Watchpoint List mutex.
size_t GetSize() const
Returns the number of elements in this watchpoint list.
void GetDescription(Stream *s, lldb::DescriptionLevel level)
A class that represents a running process on the host machine.
std::vector< OptionArgElement > OptionElementVector
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
ExpressionResults
The results of expression evaluation.
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
@ eArgTypeWatchpointIDRange
Used to build individual command argument lists.
ArgumentRepetitionType arg_repetition
lldb::CommandArgumentType arg_type