Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 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 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 12 | #include "lldb/Interpreter/OptionGroupVariable.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
| 17 | // Project includes |
Enrico Granata | 729e99e | 2012-12-11 22:42:19 +0000 | [diff] [blame^] | 18 | #include "lldb/Core/DataVisualization.h" |
| 19 | #include "lldb/Core/Error.h" |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 20 | #include "lldb/Target/Target.h" |
| 21 | #include "lldb/Interpreter/CommandInterpreter.h" |
Johnny Chen | cfbf7fe | 2011-09-10 01:19:01 +0000 | [diff] [blame] | 22 | #include "lldb/Utility/Utils.h" |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace lldb; |
| 25 | using namespace lldb_private; |
| 26 | |
Enrico Granata | 1a10208 | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 27 | // if you add any options here, remember to update the counters in OptionGroupVariable::GetNumDefinitions() |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 28 | static OptionDefinition |
| 29 | g_option_table[] = |
| 30 | { |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 31 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."}, |
| 32 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."}, |
| 33 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."}, |
| 34 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration",'c', no_argument, NULL, 0, eArgTypeNone, "Show variable declaration information (source file and line where the variable was declared)."}, |
| 35 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r', no_argument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."}, |
| 36 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."}, |
| 37 | { LLDB_OPT_SET_1, false, "summary", 'y', required_argument, NULL, 0, eArgTypeName, "Specify the summary that the variable output should use."}, |
| 38 | { LLDB_OPT_SET_2, false, "summary-string", 'z', required_argument, NULL, 0, eArgTypeName, "Specify a summary string to use to format the variable output."}, |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | |
| 42 | OptionGroupVariable::OptionGroupVariable (bool show_frame_options) : |
| 43 | OptionGroup(), |
Enrico Granata | 729e99e | 2012-12-11 22:42:19 +0000 | [diff] [blame^] | 44 | include_frame_options (show_frame_options), |
| 45 | summary([] (const char* str,void*)->Error |
| 46 | { |
| 47 | if (!str || !str[0]) |
| 48 | return Error("must specify a valid named summary"); |
| 49 | TypeSummaryImplSP summary_sp; |
| 50 | if (DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(str), summary_sp) == false) |
| 51 | return Error("must specify a valid named summary"); |
| 52 | return Error(); |
| 53 | }), |
| 54 | summary_string([] (const char* str, void*)->Error |
| 55 | { |
| 56 | if (!str || !str[0]) |
| 57 | return Error("must specify a non-empty summary string"); |
| 58 | return Error(); |
| 59 | }) |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 60 | { |
| 61 | } |
| 62 | |
| 63 | OptionGroupVariable::~OptionGroupVariable () |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | Error |
| 68 | OptionGroupVariable::SetOptionValue (CommandInterpreter &interpreter, |
| 69 | uint32_t option_idx, |
| 70 | const char *option_arg) |
| 71 | { |
| 72 | Error error; |
| 73 | if (!include_frame_options) |
| 74 | option_idx += 3; |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 75 | const int short_option = g_option_table[option_idx].short_option; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 76 | switch (short_option) |
| 77 | { |
| 78 | case 'r': use_regex = true; break; |
| 79 | case 'a': show_args = false; break; |
| 80 | case 'l': show_locals = false; break; |
| 81 | case 'g': show_globals = true; break; |
| 82 | case 'c': show_decl = true; break; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 83 | case 's': |
| 84 | show_scope = true; |
| 85 | break; |
Enrico Granata | 1a10208 | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 86 | case 'y': |
Enrico Granata | 729e99e | 2012-12-11 22:42:19 +0000 | [diff] [blame^] | 87 | error = summary.SetCurrentValue(option_arg); |
Enrico Granata | 879de48 | 2012-08-09 22:02:51 +0000 | [diff] [blame] | 88 | break; |
| 89 | case 'z': |
Enrico Granata | 729e99e | 2012-12-11 22:42:19 +0000 | [diff] [blame^] | 90 | error = summary_string.SetCurrentValue(option_arg); |
Enrico Granata | 1a10208 | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 91 | break; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 92 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 93 | error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 94 | break; |
| 95 | } |
| 96 | |
| 97 | return error; |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | OptionGroupVariable::OptionParsingStarting (CommandInterpreter &interpreter) |
| 102 | { |
| 103 | show_args = true; // Frame option only |
| 104 | show_locals = true; // Frame option only |
| 105 | show_globals = false; // Frame option only |
| 106 | show_decl = false; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 107 | use_regex = false; |
| 108 | show_scope = false; |
Enrico Granata | 879de48 | 2012-08-09 22:02:51 +0000 | [diff] [blame] | 109 | summary.Clear(); |
| 110 | summary_string.Clear(); |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Johnny Chen | cfbf7fe | 2011-09-10 01:19:01 +0000 | [diff] [blame] | 113 | #define NUM_FRAME_OPTS 3 |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 114 | |
| 115 | const OptionDefinition* |
| 116 | OptionGroupVariable::GetDefinitions () |
| 117 | { |
| 118 | // Show the "--no-args", "--no-locals" and "--show-globals" |
| 119 | // options if we are showing frame specific options |
| 120 | if (include_frame_options) |
| 121 | return g_option_table; |
| 122 | |
| 123 | // Skip the "--no-args", "--no-locals" and "--show-globals" |
| 124 | // options if we are not showing frame specific options (globals only) |
Johnny Chen | cfbf7fe | 2011-09-10 01:19:01 +0000 | [diff] [blame] | 125 | return &g_option_table[NUM_FRAME_OPTS]; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | uint32_t |
| 129 | OptionGroupVariable::GetNumDefinitions () |
| 130 | { |
Johnny Chen | cfbf7fe | 2011-09-10 01:19:01 +0000 | [diff] [blame] | 131 | // Count the "--no-args", "--no-locals" and "--show-globals" |
| 132 | // options if we are showing frame specific options. |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 133 | if (include_frame_options) |
Johnny Chen | 08af598 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 134 | return llvm::array_lengthof(g_option_table); |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 135 | else |
Johnny Chen | 08af598 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 136 | return llvm::array_lengthof(g_option_table) - NUM_FRAME_OPTS; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | |