blob: 9cf8d417610baaf912b86f91fc19b580bd38d968 [file] [log] [blame]
Greg Clayton368f8222011-07-07 04:38:25 +00001//===-- 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"
18
19using namespace lldb;
20using namespace lldb_private;
21
Enrico Granata1a102082011-07-12 00:18:11 +000022// if you add any options here, remember to update the counters in OptionGroupVariable::GetNumDefinitions()
Greg Clayton368f8222011-07-07 04:38:25 +000023static OptionDefinition
24g_option_table[] =
25{
26 { LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
27 { LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
28 { LLDB_OPT_SET_1, false, "show-globals", 'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
29 { LLDB_OPT_SET_1, false, "show-declaration",'c', no_argument, NULL, 0, eArgTypeNone, "Show variable declaration information (source file and line where the variable was declared)."},
30 { LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, eArgTypeExprFormat, "Specify the format that the variable output should use."},
31 { LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."},
Enrico Granata1a102082011-07-12 00:18:11 +000032 { LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
33 { LLDB_OPT_SET_1, false, "summary", 'y', required_argument, NULL, 0, eArgTypeName, "Specify the summary that the variable output should use."},
Greg Clayton368f8222011-07-07 04:38:25 +000034};
35
36
37OptionGroupVariable::OptionGroupVariable (bool show_frame_options) :
38 OptionGroup(),
39 include_frame_options (show_frame_options)
40{
41}
42
43OptionGroupVariable::~OptionGroupVariable ()
44{
45}
46
47Error
48OptionGroupVariable::SetOptionValue (CommandInterpreter &interpreter,
49 uint32_t option_idx,
50 const char *option_arg)
51{
52 Error error;
53 if (!include_frame_options)
54 option_idx += 3;
55 char short_option = (char) g_option_table[option_idx].short_option;
56 switch (short_option)
57 {
58 case 'r': use_regex = true; break;
59 case 'a': show_args = false; break;
60 case 'l': show_locals = false; break;
61 case 'g': show_globals = true; break;
62 case 'c': show_decl = true; break;
63 case 'f': error = Args::StringToFormat(option_arg, format, NULL); break;
64 case 's':
65 show_scope = true;
66 break;
Enrico Granata1a102082011-07-12 00:18:11 +000067 case 'y':
68 summary = std::string(option_arg);
69 break;
Greg Clayton368f8222011-07-07 04:38:25 +000070 default:
71 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
72 break;
73 }
74
75 return error;
76}
77
78void
79OptionGroupVariable::OptionParsingStarting (CommandInterpreter &interpreter)
80{
81 show_args = true; // Frame option only
82 show_locals = true; // Frame option only
83 show_globals = false; // Frame option only
84 show_decl = false;
85 format = lldb::eFormatDefault;
86 use_regex = false;
87 show_scope = false;
Enrico Granata1a102082011-07-12 00:18:11 +000088 summary = "";
Greg Clayton368f8222011-07-07 04:38:25 +000089}
90
91
92const OptionDefinition*
93OptionGroupVariable::GetDefinitions ()
94{
95 // Show the "--no-args", "--no-locals" and "--show-globals"
96 // options if we are showing frame specific options
97 if (include_frame_options)
98 return g_option_table;
99
100 // Skip the "--no-args", "--no-locals" and "--show-globals"
101 // options if we are not showing frame specific options (globals only)
102 return &g_option_table[3];
103}
104
105uint32_t
106OptionGroupVariable::GetNumDefinitions ()
107{
108 if (include_frame_options)
Enrico Granata1a102082011-07-12 00:18:11 +0000109 return 8;
Greg Clayton368f8222011-07-07 04:38:25 +0000110 else
Enrico Granata1a102082011-07-12 00:18:11 +0000111 return 5;
Greg Clayton368f8222011-07-07 04:38:25 +0000112}
113
114