15#include "llvm/ADT/StringRef.h"
44 bool process_is_valid =
46 if (!process_is_valid) {
47 result.
AppendError(
"There's no process or it is not alive.");
55static const char *
RSA[4] = {
"-",
"to",
"To",
"TO"};
61 for (i = 0; i < 4; ++i)
62 if (Arg.contains(
RSA[i]))
70 Target &target,
Args &args, std::vector<uint32_t> &wp_ids) {
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);
104 uint32_t beg, end,
id;
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) {
170 const int short_option = m_getopt_table[option_idx].val;
172 switch (short_option) {
183 llvm_unreachable(
"Unimplemented option");
194 return llvm::ArrayRef(g_watchpoint_list_options);
204 Target &target = GetTarget();
207 if (process_sp->IsAlive()) {
208 std::optional<uint32_t> num_supported_hardware_watchpoints =
209 process_sp->GetWatchpointSlotCount();
211 if (num_supported_hardware_watchpoints)
213 "Number of supported hardware watchpoints: %u\n",
214 *num_supported_hardware_watchpoints);
220 std::unique_lock<std::recursive_mutex> lock;
223 size_t num_watchpoints = watchpoints.
GetSize();
225 if (num_watchpoints == 0) {
236 for (
size_t i = 0; i < num_watchpoints; ++i) {
243 std::vector<uint32_t> wp_ids;
245 target, command, wp_ids)) {
246 result.
AppendError(
"Invalid watchpoints specification.");
250 const size_t size = wp_ids.size();
251 for (
size_t i = 0; i < size; ++i) {
271 "Enable the specified disabled watchpoint(s). If "
272 "no watchpoints are specified, enable all of them.",
273 nullptr, eCommandRequiresTarget) {
289 Target &target = GetTarget();
293 std::unique_lock<std::recursive_mutex> lock;
298 size_t num_watchpoints = watchpoints.
GetSize();
300 if (num_watchpoints == 0) {
301 result.
AppendError(
"No watchpoints exist to be enabled.");
310 (uint64_t)num_watchpoints);
314 std::vector<uint32_t> wp_ids;
316 target, command, wp_ids)) {
317 result.
AppendError(
"Invalid watchpoints specification.");
322 const size_t size = wp_ids.size();
323 for (
size_t i = 0; i < size; ++i)
339 "Disable the specified watchpoint(s) without "
340 "removing it/them. If no watchpoints are "
341 "specified, disable them all.",
342 nullptr, eCommandRequiresTarget) {
358 Target &target = GetTarget();
362 std::unique_lock<std::recursive_mutex> lock;
366 size_t num_watchpoints = watchpoints.
GetSize();
368 if (num_watchpoints == 0) {
369 result.
AppendError(
"No watchpoints exist to be disabled.");
378 (uint64_t)num_watchpoints);
381 result.
AppendError(
"Disable all watchpoints failed\n");
385 std::vector<uint32_t> wp_ids;
387 target, command, wp_ids)) {
388 result.
AppendError(
"Invalid watchpoints specification.");
393 const size_t size = wp_ids.size();
394 for (
size_t i = 0; i < size; ++i)
404#define LLDB_OPTIONS_watchpoint_delete
405#include "CommandOptions.inc"
414 "Delete the specified watchpoint(s). If no "
415 "watchpoints are specified, delete them all.",
416 nullptr, eCommandRequiresTarget) {
440 const int short_option = m_getopt_table[option_idx].val;
442 switch (short_option) {
447 llvm_unreachable(
"Unimplemented option");
458 return llvm::ArrayRef(g_watchpoint_delete_options);
462 bool m_force =
false;
467 Target &target = GetTarget();
471 std::unique_lock<std::recursive_mutex> lock;
476 size_t num_watchpoints = watchpoints.
GetSize();
478 if (num_watchpoints == 0) {
479 result.
AppendError(
"No watchpoints exist to be deleted.");
483 if (command.
empty()) {
484 if (!m_options.m_force &&
485 !m_interpreter.Confirm(
486 "About to delete all watchpoints, do you want to do that?",
493 (uint64_t)num_watchpoints);
500 std::vector<uint32_t> wp_ids;
503 result.
AppendError(
"Invalid watchpoints specification.");
508 const size_t size = wp_ids.size();
509 for (
size_t i = 0; i < size; ++i)
522#pragma mark Ignore::CommandOptions
523#define LLDB_OPTIONS_watchpoint_ignore
524#include "CommandOptions.inc"
530 "Set ignore count on the specified watchpoint(s). "
531 "If no watchpoints are specified, set them all.",
532 nullptr, eCommandRequiresTarget) {
557 const int short_option = m_getopt_table[option_idx].val;
559 switch (short_option) {
561 if (option_arg.getAsInteger(0, m_ignore_count))
562 error.SetErrorStringWithFormat(
"invalid ignore count '%s'",
563 option_arg.str().c_str());
566 llvm_unreachable(
"Unimplemented option");
577 return llvm::ArrayRef(g_watchpoint_ignore_options);
582 uint32_t m_ignore_count = 0;
587 Target &target = GetTarget();
591 std::unique_lock<std::recursive_mutex> lock;
596 size_t num_watchpoints = watchpoints.
GetSize();
598 if (num_watchpoints == 0) {
599 result.
AppendError(
"No watchpoints exist to be ignored.");
607 (uint64_t)num_watchpoints);
611 std::vector<uint32_t> wp_ids;
613 target, command, wp_ids)) {
614 result.
AppendError(
"Invalid watchpoints specification.");
619 const size_t size = wp_ids.size();
620 for (
size_t i = 0; i < size; ++i)
634#pragma mark Modify::CommandOptions
635#define LLDB_OPTIONS_watchpoint_modify
636#include "CommandOptions.inc"
644 interpreter,
"watchpoint modify",
645 "Modify the options on a watchpoint or set of watchpoints in the "
647 "If no watchpoint is specified, act on the last created "
649 "Passing an empty argument clears the modification.",
650 nullptr, eCommandRequiresTarget) {
675 const int short_option = m_getopt_table[option_idx].val;
677 switch (short_option) {
679 m_condition = std::string(option_arg);
680 m_condition_passed =
true;
683 llvm_unreachable(
"Unimplemented option");
691 m_condition_passed =
false;
695 return llvm::ArrayRef(g_watchpoint_modify_options);
701 bool m_condition_passed =
false;
706 Target &target = GetTarget();
710 std::unique_lock<std::recursive_mutex> lock;
715 size_t num_watchpoints = watchpoints.
GetSize();
717 if (num_watchpoints == 0) {
718 result.
AppendError(
"No watchpoints exist to be modified.");
724 watch_sp->SetCondition(m_options.m_condition.c_str());
728 std::vector<uint32_t> wp_ids;
730 target, command, wp_ids)) {
731 result.
AppendError(
"Invalid watchpoints specification.");
736 const size_t size = wp_ids.size();
737 for (
size_t i = 0; i < size; ++i) {
740 watch_sp->SetCondition(m_options.m_condition.c_str());
754#pragma mark SetVariable
760 interpreter,
"watchpoint set variable",
761 "Set a watchpoint on a variable. "
762 "Use the '-w' option to specify the type of watchpoint and "
763 "the '-s' option to specify the byte size to watch for. "
764 "If no '-w' option is specified, it defaults to modify. "
765 "If no '-s' option is specified, it defaults to the variable's "
767 "Note that there are limited hardware resources for watchpoints. "
768 "If watchpoint setting fails, consider disable/delete existing "
770 "to free up resources.",
772 eCommandRequiresFrame | eCommandTryTargetAPILock |
773 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
778(lldb) watchpoint set variable -w read_write my_global_var
781 " Watches my_global_var for read/write access, with the region to watch \
782corresponding to the byte size of the data type.");
788 m_option_group.Finalize();
793 Options *GetOptions()
override {
return &m_option_group; }
796 static size_t GetVariableCallback(
void *baton,
const char *name,
798 size_t old_size = variable_list.
GetSize();
803 return variable_list.
GetSize() - old_size;
807 Target &target = GetTarget();
814 "specify your program variable to watch for");
819 if (!m_option_watchpoint.watch_type_specified) {
834 result.
AppendError(
"specify exactly one variable to watch for");
840 uint32_t expr_path_options =
855 m_exe_ctx.GetBestExecutionContextScope(), GetVariableCallback,
856 &target, variable_list, valobj_list));
866 addr = valobj_sp->GetAddressOf(
false, &addr_type);
870 size = m_option_watchpoint.watch_size.GetCurrentValue() == 0
872 : m_option_watchpoint.watch_size.GetCurrentValue();
874 compiler_type = valobj_sp->GetCompilerType();
876 const char *error_cstr =
error.AsCString(
nullptr);
881 "expression path that matches '%s'",
887 uint32_t watch_type = 0;
888 switch (m_option_watchpoint.watch_type) {
910 "Watchpoint creation failed (addr=0x%" PRIx64
", size=%" PRIu64
911 ", variable expression='%s').\n",
913 if (
const char *error_message =
error.AsCString(
nullptr))
919 watch_sp->SetWatchVariable(
true);
921 if (var_sp->GetDeclaration().GetFile()) {
924 var_sp->GetDeclaration().DumpStopContext(&ss,
true);
925 watch_sp->SetDeclInfo(std::string(ss.
GetString()));
928 watch_sp->SetupVariableWatchpointDisabler(m_exe_ctx.GetFrameSP());
930 output_stream.
Printf(
"Watchpoint created: ");
948 interpreter,
"watchpoint set expression",
949 "Set a watchpoint on an address by supplying an expression. "
950 "Use the '-l' option to specify the language of the expression. "
951 "Use the '-w' option to specify the type of watchpoint and "
952 "the '-s' option to specify the byte size to watch for. "
953 "If no '-w' option is specified, it defaults to modify. "
954 "If no '-s' option is specified, it defaults to the target's "
955 "pointer byte size. "
956 "Note that there are limited hardware resources for watchpoints. "
957 "If watchpoint setting fails, consider disable/delete existing "
959 "to free up resources.",
961 eCommandRequiresFrame | eCommandTryTargetAPILock |
962 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
967(lldb) watchpoint set expression -w modify -s 1 -- foo + 32
969 Watches write access for the 1-byte region pointed to by the address 'foo + 32')");
976 m_option_group.Finalize();
983 bool WantsCompletion()
override {
return true; }
985 Options *GetOptions()
override {
return &m_option_group; }
988 void DoExecute(llvm::StringRef raw_command,
990 auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
994 Target &target = GetTarget();
999 llvm::StringRef expr = args.GetRawPart();
1002 if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group,
1008 if (raw_command.trim().empty()) {
1009 result.
AppendError(
"required argument missing; specify an expression "
1010 "to evaluate into the address to watch for");
1015 if (!m_option_watchpoint.watch_type_specified) {
1034 options.
SetLanguage(m_option_watchpoint.language_type);
1039 result.
AppendError(
"expression evaluation of address to watch failed");
1041 if (valobj_sp && !valobj_sp->GetError().Success())
1042 result.
AppendError(valobj_sp->GetError().AsCString());
1047 bool success =
false;
1048 addr = valobj_sp->GetValueAsUnsigned(0, &success);
1050 result.
AppendError(
"expression did not evaluate to an address");
1054 if (m_option_watchpoint.watch_size.GetCurrentValue() != 0)
1055 size = m_option_watchpoint.watch_size.GetCurrentValue();
1060 uint32_t watch_type;
1061 switch (m_option_watchpoint.watch_type) {
1081 CompilerType compiler_type(valobj_sp->GetCompilerType());
1083 std::optional<uint64_t> valobj_size = valobj_sp->GetByteSize();
1087 if (valobj_size && size > *valobj_size) {
1091 type_system->GetBuiltinTypeForEncodingAndBitSize(
eEncodingUint, 8);
1100 watch_sp->SetWatchSpec(std::string(expr));
1102 output_stream.
Printf(
"Watchpoint created: ");
1104 output_stream.
EOL();
1108 ", size=%" PRIu64
").\n",
1109 addr, (uint64_t)size);
1110 if (
error.AsCString(
nullptr))
1127 interpreter,
"watchpoint set",
"Commands for setting a watchpoint.",
1128 "watchpoint set <subcommand> [<subcommand-options>]") {
1142#pragma mark MultiwordWatchpoint
1147 "Commands for operating on watchpoints.",
1148 "watchpoint <subcommand> [<command-options>]") {
1166 list_command_object->SetCommandName(
"watchpoint list");
1167 enable_command_object->SetCommandName(
"watchpoint enable");
1168 disable_command_object->SetCommandName(
"watchpoint disable");
1169 delete_command_object->SetCommandName(
"watchpoint delete");
1170 ignore_command_object->SetCommandName(
"watchpoint ignore");
1171 command_command_object->SetCommandName(
"watchpoint command");
1172 modify_command_object->SetCommandName(
"watchpoint modify");
1173 set_command_object->SetCommandName(
"watchpoint set");
static void AddWatchpointDescription(Stream &s, Watchpoint &wp, lldb::DescriptionLevel level)
static int32_t WithRSAIndex(llvm::StringRef Arg)
static bool CheckTargetForWatchpointOperations(Target &target, CommandReturnObject &result)
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
CommandObjectWatchpointDelete(CommandInterpreter &interpreter)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
Options * GetOptions() override
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectWatchpointDelete() override=default
~CommandObjectWatchpointDisable() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
CommandObjectWatchpointDisable(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectWatchpointEnable(CommandInterpreter &interpreter)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
~CommandObjectWatchpointEnable() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
~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 default version handles argument definitions that have only one argument type,...
CommandObjectWatchpointIgnore(CommandInterpreter &interpreter)
~CommandObjectWatchpointIgnore() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
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
void 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 default version handles argument definitions that have only one argument type,...
void DoExecute(Args &command, CommandReturnObject &result) override
Options * GetOptions() override
~CommandObjectWatchpointModify() override=default
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)
~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
void AddIDsArgumentData(IDType type)
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.
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
CompilerType GetArrayType(uint64_t size) const
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
"lldb/Utility/ArgCompletionRequest.h"
A uniqued constant string class.
void SetUnwindOnError(bool unwind=false)
void SetKeepInMemory(bool keep=true)
void SetCoerceToId(bool coerce=true)
void SetLanguage(lldb::LanguageType language_type)
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)
#define LLDB_WATCH_TYPE_WRITE
#define LLDB_WATCH_TYPE_MODIFY
#define LLDB_WATCH_TYPE_READ
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.
@ eWatchpointIDCompletion
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
@ eLanguageTypeUnknown
Unknown or invalid language value.
ExpressionResults
The results of expression evaluation.
std::shared_ptr< lldb_private::Process > ProcessSP
@ eEncodingUint
unsigned integer
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
std::shared_ptr< lldb_private::Variable > VariableSP
@ eValueTypeVariableLocal
function local variables