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 | |
| 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/Target/Target.h" |
| 17 | #include "lldb/Interpreter/CommandInterpreter.h" |
Johnny Chen | cfbf7fe | 2011-09-10 01:19:01 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Utils.h" |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Enrico Granata | 1a10208 | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 23 | // 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] | 24 | static OptionDefinition |
| 25 | g_option_table[] = |
| 26 | { |
Enrico Granata | 879de48 | 2012-08-09 22:02:51 +0000 | [diff] [blame] | 27 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."}, |
| 28 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."}, |
| 29 | { 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."}, |
| 30 | { 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)."}, |
| 31 | { 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."}, |
| 32 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."}, |
Enrico Granata | 1a10208 | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 33 | { LLDB_OPT_SET_1, false, "summary", 'y', required_argument, NULL, 0, eArgTypeName, "Specify the summary that the variable output should use."}, |
Enrico Granata | 879de48 | 2012-08-09 22:02:51 +0000 | [diff] [blame] | 34 | { 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] | 35 | }; |
| 36 | |
| 37 | |
| 38 | OptionGroupVariable::OptionGroupVariable (bool show_frame_options) : |
| 39 | OptionGroup(), |
| 40 | include_frame_options (show_frame_options) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | OptionGroupVariable::~OptionGroupVariable () |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | Error |
| 49 | OptionGroupVariable::SetOptionValue (CommandInterpreter &interpreter, |
| 50 | uint32_t option_idx, |
| 51 | const char *option_arg) |
| 52 | { |
| 53 | Error error; |
| 54 | if (!include_frame_options) |
| 55 | option_idx += 3; |
| 56 | char short_option = (char) g_option_table[option_idx].short_option; |
| 57 | switch (short_option) |
| 58 | { |
| 59 | case 'r': use_regex = true; break; |
| 60 | case 'a': show_args = false; break; |
| 61 | case 'l': show_locals = false; break; |
| 62 | case 'g': show_globals = true; break; |
| 63 | case 'c': show_decl = true; break; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 64 | case 's': |
| 65 | show_scope = true; |
| 66 | break; |
Enrico Granata | 1a10208 | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 67 | case 'y': |
Enrico Granata | 879de48 | 2012-08-09 22:02:51 +0000 | [diff] [blame] | 68 | summary.SetCurrentValue(option_arg); |
| 69 | break; |
| 70 | case 'z': |
| 71 | summary_string.SetCurrentValue(option_arg); |
Enrico Granata | 1a10208 | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 72 | break; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 73 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 74 | error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 75 | break; |
| 76 | } |
| 77 | |
| 78 | return error; |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | OptionGroupVariable::OptionParsingStarting (CommandInterpreter &interpreter) |
| 83 | { |
| 84 | show_args = true; // Frame option only |
| 85 | show_locals = true; // Frame option only |
| 86 | show_globals = false; // Frame option only |
| 87 | show_decl = false; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 88 | use_regex = false; |
| 89 | show_scope = false; |
Enrico Granata | 879de48 | 2012-08-09 22:02:51 +0000 | [diff] [blame] | 90 | summary.Clear(); |
| 91 | summary_string.Clear(); |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Johnny Chen | cfbf7fe | 2011-09-10 01:19:01 +0000 | [diff] [blame] | 94 | #define NUM_FRAME_OPTS 3 |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 95 | |
| 96 | const OptionDefinition* |
| 97 | OptionGroupVariable::GetDefinitions () |
| 98 | { |
| 99 | // Show the "--no-args", "--no-locals" and "--show-globals" |
| 100 | // options if we are showing frame specific options |
| 101 | if (include_frame_options) |
| 102 | return g_option_table; |
| 103 | |
| 104 | // Skip the "--no-args", "--no-locals" and "--show-globals" |
| 105 | // options if we are not showing frame specific options (globals only) |
Johnny Chen | cfbf7fe | 2011-09-10 01:19:01 +0000 | [diff] [blame] | 106 | return &g_option_table[NUM_FRAME_OPTS]; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | uint32_t |
| 110 | OptionGroupVariable::GetNumDefinitions () |
| 111 | { |
Johnny Chen | cfbf7fe | 2011-09-10 01:19:01 +0000 | [diff] [blame] | 112 | // Count the "--no-args", "--no-locals" and "--show-globals" |
| 113 | // options if we are showing frame specific options. |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 114 | if (include_frame_options) |
Johnny Chen | 08af598 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 115 | return llvm::array_lengthof(g_option_table); |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 116 | else |
Johnny Chen | 08af598 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 117 | return llvm::array_lengthof(g_option_table) - NUM_FRAME_OPTS; |
Greg Clayton | 368f822 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | |