xref: /freebsd/contrib/llvm-project/lldb/source/Interpreter/OptionGroupWatchpoint.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
15ffd83dbSDimitry Andric //===-- OptionGroupWatchpoint.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/Interpreter/OptionGroupWatchpoint.h"
100b57cec5SDimitry Andric 
110b57cec5SDimitry Andric #include "lldb/Host/OptionParser.h"
120b57cec5SDimitry Andric #include "lldb/Interpreter/OptionArgParser.h"
1306c3fb27SDimitry Andric #include "lldb/Target/Language.h"
140b57cec5SDimitry Andric #include "lldb/lldb-enumerations.h"
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric using namespace lldb;
170b57cec5SDimitry Andric using namespace lldb_private;
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric static constexpr OptionEnumValueElement g_watch_type[] = {
209dba64beSDimitry Andric     {
219dba64beSDimitry Andric         OptionGroupWatchpoint::eWatchRead,
229dba64beSDimitry Andric         "read",
239dba64beSDimitry Andric         "Watch for read",
249dba64beSDimitry Andric     },
259dba64beSDimitry Andric     {
269dba64beSDimitry Andric         OptionGroupWatchpoint::eWatchWrite,
279dba64beSDimitry Andric         "write",
289dba64beSDimitry Andric         "Watch for write",
299dba64beSDimitry Andric     },
309dba64beSDimitry Andric     {
31*5f757f3fSDimitry Andric         OptionGroupWatchpoint::eWatchModify,
32*5f757f3fSDimitry Andric         "modify",
33*5f757f3fSDimitry Andric         "Watch for modifications",
34*5f757f3fSDimitry Andric     },
35*5f757f3fSDimitry Andric     {
369dba64beSDimitry Andric         OptionGroupWatchpoint::eWatchReadWrite,
379dba64beSDimitry Andric         "read_write",
389dba64beSDimitry Andric         "Watch for read/write",
399dba64beSDimitry Andric     },
409dba64beSDimitry Andric };
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric static constexpr OptionDefinition g_option_table[] = {
430b57cec5SDimitry Andric     {LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,
440b57cec5SDimitry Andric      nullptr, OptionEnumValues(g_watch_type), 0, eArgTypeWatchType,
450b57cec5SDimitry Andric      "Specify the type of watching to perform."},
460b57cec5SDimitry Andric     {LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,
47*5f757f3fSDimitry Andric      nullptr, {}, 0, eArgTypeByteSize,
4806c3fb27SDimitry Andric      "Number of bytes to use to watch a region."},
4906c3fb27SDimitry Andric     {LLDB_OPT_SET_2,
5006c3fb27SDimitry Andric      false,
5106c3fb27SDimitry Andric      "language",
5206c3fb27SDimitry Andric      'l',
5306c3fb27SDimitry Andric      OptionParser::eRequiredArgument,
5406c3fb27SDimitry Andric      nullptr,
5506c3fb27SDimitry Andric      {},
5606c3fb27SDimitry Andric      0,
5706c3fb27SDimitry Andric      eArgTypeLanguage,
5806c3fb27SDimitry Andric      "Language of expression to run"}};
590b57cec5SDimitry Andric 
600b57cec5SDimitry Andric Status
610b57cec5SDimitry Andric OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
620b57cec5SDimitry Andric                                       llvm::StringRef option_arg,
630b57cec5SDimitry Andric                                       ExecutionContext *execution_context) {
640b57cec5SDimitry Andric   Status error;
650b57cec5SDimitry Andric   const int short_option = g_option_table[option_idx].short_option;
660b57cec5SDimitry Andric   switch (short_option) {
6706c3fb27SDimitry Andric   case 'l': {
6806c3fb27SDimitry Andric     language_type = Language::GetLanguageTypeFromString(option_arg);
6906c3fb27SDimitry Andric     if (language_type == eLanguageTypeUnknown) {
7006c3fb27SDimitry Andric       StreamString sstr;
7106c3fb27SDimitry Andric       sstr.Printf("Unknown language type: '%s' for expression. List of "
7206c3fb27SDimitry Andric                   "supported languages:\n",
7306c3fb27SDimitry Andric                   option_arg.str().c_str());
7406c3fb27SDimitry Andric       Language::PrintSupportedLanguagesForExpressions(sstr, " ", "\n");
7506c3fb27SDimitry Andric       error.SetErrorString(sstr.GetString());
7606c3fb27SDimitry Andric     }
7706c3fb27SDimitry Andric     break;
7806c3fb27SDimitry Andric   }
790b57cec5SDimitry Andric   case 'w': {
800b57cec5SDimitry Andric     WatchType tmp_watch_type;
810b57cec5SDimitry Andric     tmp_watch_type = (WatchType)OptionArgParser::ToOptionEnum(
820b57cec5SDimitry Andric         option_arg, g_option_table[option_idx].enum_values, 0, error);
830b57cec5SDimitry Andric     if (error.Success()) {
840b57cec5SDimitry Andric       watch_type = tmp_watch_type;
850b57cec5SDimitry Andric       watch_type_specified = true;
860b57cec5SDimitry Andric     }
870b57cec5SDimitry Andric     break;
880b57cec5SDimitry Andric   }
890b57cec5SDimitry Andric   case 's':
90*5f757f3fSDimitry Andric     error = watch_size.SetValueFromString(option_arg);
91*5f757f3fSDimitry Andric     if (watch_size.GetCurrentValue() == 0)
92*5f757f3fSDimitry Andric       error.SetErrorStringWithFormat("invalid --size option value '%s'",
93*5f757f3fSDimitry Andric                                      option_arg.str().c_str());
940b57cec5SDimitry Andric     break;
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric   default:
979dba64beSDimitry Andric     llvm_unreachable("Unimplemented option");
980b57cec5SDimitry Andric   }
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric   return error;
1010b57cec5SDimitry Andric }
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric void OptionGroupWatchpoint::OptionParsingStarting(
1040b57cec5SDimitry Andric     ExecutionContext *execution_context) {
1050b57cec5SDimitry Andric   watch_type_specified = false;
1060b57cec5SDimitry Andric   watch_type = eWatchInvalid;
107*5f757f3fSDimitry Andric   watch_size.Clear();
10806c3fb27SDimitry Andric   language_type = eLanguageTypeUnknown;
1090b57cec5SDimitry Andric }
1100b57cec5SDimitry Andric 
1110b57cec5SDimitry Andric llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
112bdd1243dSDimitry Andric   return llvm::ArrayRef(g_option_table);
1130b57cec5SDimitry Andric }
114