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/Core/Error.h" 17 #include "lldb/DataFormatters/DataVisualization.h" 18 #include "lldb/Interpreter/CommandInterpreter.h" 19 #include "lldb/Target/Target.h" 20 #include "lldb/Utility/Utils.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 Error ValidateNamedSummary(const char *str, void *) { 56 if (!str || !str[0]) 57 return Error("must specify a valid named summary"); 58 TypeSummaryImplSP summary_sp; 59 if (DataVisualization::NamedSummaryFormats::GetSummaryFormat( 60 ConstString(str), summary_sp) == false) 61 return Error("must specify a valid named summary"); 62 return Error(); 63 } 64 65 static Error ValidateSummaryString(const char *str, void *) { 66 if (!str || !str[0]) 67 return Error("must specify a non-empty summary string"); 68 return Error(); 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 Error OptionGroupVariable::SetOptionValue(uint32_t option_idx, 78 llvm::StringRef option_arg, 79 ExecutionContext *execution_context) { 80 Error error; 81 if (!include_frame_options) 82 option_idx += 3; 83 const int short_option = g_variable_options[option_idx].short_option; 84 switch (short_option) { 85 case 'r': 86 use_regex = true; 87 break; 88 case 'a': 89 show_args = false; 90 break; 91 case 'l': 92 show_locals = false; 93 break; 94 case 'g': 95 show_globals = true; 96 break; 97 case 'c': 98 show_decl = true; 99 break; 100 case 's': 101 show_scope = true; 102 break; 103 case 'y': 104 error = summary.SetCurrentValue(option_arg); 105 break; 106 case 'z': 107 error = summary_string.SetCurrentValue(option_arg); 108 break; 109 default: 110 error.SetErrorStringWithFormat("unrecognized short option '%c'", 111 short_option); 112 break; 113 } 114 115 return error; 116 } 117 118 void OptionGroupVariable::OptionParsingStarting( 119 ExecutionContext *execution_context) { 120 show_args = true; // Frame option only 121 show_locals = true; // Frame option only 122 show_globals = false; // Frame option only 123 show_decl = false; 124 use_regex = false; 125 show_scope = false; 126 summary.Clear(); 127 summary_string.Clear(); 128 } 129 130 #define NUM_FRAME_OPTS 3 131 132 llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() { 133 auto result = llvm::makeArrayRef(g_variable_options); 134 // Show the "--no-args", "--no-locals" and "--show-globals" 135 // options if we are showing frame specific options 136 if (include_frame_options) 137 return result; 138 139 // Skip the "--no-args", "--no-locals" and "--show-globals" 140 // options if we are not showing frame specific options (globals only) 141 return result.drop_front(NUM_FRAME_OPTS); 142 } 143