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