1 //===-- OptionGroupVariable.cpp -----------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Interpreter/OptionGroupVariable.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/DataFormatters/DataVisualization.h" 17 #include "lldb/Host/OptionParser.h" 18 #include "lldb/Interpreter/CommandInterpreter.h" 19 #include "lldb/Target/Target.h" 20 #include "lldb/Utility/Status.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 // if you add any options here, remember to update the counters in 26 // OptionGroupVariable::GetNumDefinitions() 27 static OptionDefinition g_variable_options[] = { 28 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a', 29 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 30 "Omit function arguments."}, 31 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l', 32 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 33 "Omit local variables."}, 34 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g', 35 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 36 "Show the current frame source file global and static variables."}, 37 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c', 38 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 39 "Show variable declaration information (source file and line where the " 40 "variable was declared)."}, 41 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r', 42 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, 43 "The <variable-name> argument for name lookups are regular expressions."}, 44 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's', 45 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 46 "Show variable scope (argument, local, global, static)."}, 47 {LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument, 48 nullptr, nullptr, 0, eArgTypeName, 49 "Specify the summary that the variable output should use."}, 50 {LLDB_OPT_SET_2, false, "summary-string", 'z', 51 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, 52 "Specify a summary string to use to format the variable output."}, 53 }; 54 55 static Status ValidateNamedSummary(const char *str, void *) { 56 if (!str || !str[0]) 57 return Status("must specify a valid named summary"); 58 TypeSummaryImplSP summary_sp; 59 if (DataVisualization::NamedSummaryFormats::GetSummaryFormat( 60 ConstString(str), summary_sp) == false) 61 return Status("must specify a valid named summary"); 62 return Status(); 63 } 64 65 static Status ValidateSummaryString(const char *str, void *) { 66 if (!str || !str[0]) 67 return Status("must specify a non-empty summary string"); 68 return Status(); 69 } 70 71 OptionGroupVariable::OptionGroupVariable(bool show_frame_options) 72 : OptionGroup(), include_frame_options(show_frame_options), 73 summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {} 74 75 OptionGroupVariable::~OptionGroupVariable() {} 76 77 Status 78 OptionGroupVariable::SetOptionValue(uint32_t option_idx, 79 llvm::StringRef option_arg, 80 ExecutionContext *execution_context) { 81 Status error; 82 if (!include_frame_options) 83 option_idx += 3; 84 const int short_option = g_variable_options[option_idx].short_option; 85 switch (short_option) { 86 case 'r': 87 use_regex = true; 88 break; 89 case 'a': 90 show_args = false; 91 break; 92 case 'l': 93 show_locals = false; 94 break; 95 case 'g': 96 show_globals = true; 97 break; 98 case 'c': 99 show_decl = true; 100 break; 101 case 's': 102 show_scope = true; 103 break; 104 case 'y': 105 error = summary.SetCurrentValue(option_arg); 106 break; 107 case 'z': 108 error = summary_string.SetCurrentValue(option_arg); 109 break; 110 default: 111 error.SetErrorStringWithFormat("unrecognized short option '%c'", 112 short_option); 113 break; 114 } 115 116 return error; 117 } 118 119 void OptionGroupVariable::OptionParsingStarting( 120 ExecutionContext *execution_context) { 121 show_args = true; // Frame option only 122 show_locals = true; // Frame option only 123 show_globals = false; // Frame option only 124 show_decl = false; 125 use_regex = false; 126 show_scope = false; 127 summary.Clear(); 128 summary_string.Clear(); 129 } 130 131 #define NUM_FRAME_OPTS 3 132 133 llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() { 134 auto result = llvm::makeArrayRef(g_variable_options); 135 // Show the "--no-args", "--no-locals" and "--show-globals" options if we are 136 // showing frame specific options 137 if (include_frame_options) 138 return result; 139 140 // Skip the "--no-args", "--no-locals" and "--show-globals" options if we are 141 // not showing frame specific options (globals only) 142 return result.drop_front(NUM_FRAME_OPTS); 143 } 144