• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/lldb-python.h"
11 
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/Core/Error.h"
19 #include "lldb/DataFormatters/DataVisualization.h"
20 #include "lldb/Interpreter/CommandInterpreter.h"
21 #include "lldb/Target/Target.h"
22 #include "lldb/Utility/Utils.h"
23 
24 using namespace lldb;
25 using namespace lldb_private;
26 
27 // if you add any options here, remember to update the counters in OptionGroupVariable::GetNumDefinitions()
28 static OptionDefinition
29 g_option_table[] =
30 {
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."},
39 };
40 
41 static Error
ValidateNamedSummary(const char * str,void *)42 ValidateNamedSummary (const char* str, void*)
43 {
44     if (!str || !str[0])
45         return Error("must specify a valid named summary");
46     TypeSummaryImplSP summary_sp;
47     if (DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(str), summary_sp) == false)
48         return Error("must specify a valid named summary");
49     return Error();
50 }
51 
52 static Error
ValidateSummaryString(const char * str,void *)53 ValidateSummaryString (const char* str, void*)
54 {
55     if (!str || !str[0])
56         return Error("must specify a non-empty summary string");
57     return Error();
58 }
59 
OptionGroupVariable(bool show_frame_options)60 OptionGroupVariable::OptionGroupVariable (bool show_frame_options) :
61     OptionGroup(),
62     include_frame_options (show_frame_options),
63     summary(ValidateNamedSummary),
64     summary_string(ValidateSummaryString)
65 {
66 }
67 
~OptionGroupVariable()68 OptionGroupVariable::~OptionGroupVariable ()
69 {
70 }
71 
72 Error
SetOptionValue(CommandInterpreter & interpreter,uint32_t option_idx,const char * option_arg)73 OptionGroupVariable::SetOptionValue (CommandInterpreter &interpreter,
74                                      uint32_t option_idx,
75                                      const char *option_arg)
76 {
77     Error error;
78     if (!include_frame_options)
79         option_idx += 3;
80     const int short_option = g_option_table[option_idx].short_option;
81     switch (short_option)
82     {
83         case 'r':   use_regex    = true;  break;
84         case 'a':   show_args    = false; break;
85         case 'l':   show_locals  = false; break;
86         case 'g':   show_globals = true;  break;
87         case 'c':   show_decl    = true;  break;
88         case 's':
89             show_scope = true;
90             break;
91         case 'y':
92             error = summary.SetCurrentValue(option_arg);
93             break;
94         case 'z':
95             error = summary_string.SetCurrentValue(option_arg);
96             break;
97         default:
98             error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
99             break;
100     }
101 
102     return error;
103 }
104 
105 void
OptionParsingStarting(CommandInterpreter & interpreter)106 OptionGroupVariable::OptionParsingStarting (CommandInterpreter &interpreter)
107 {
108     show_args     = true;   // Frame option only
109     show_locals   = true;   // Frame option only
110     show_globals  = false;  // Frame option only
111     show_decl     = false;
112     use_regex     = false;
113     show_scope    = false;
114     summary.Clear();
115     summary_string.Clear();
116 }
117 
118 #define NUM_FRAME_OPTS 3
119 
120 const OptionDefinition*
GetDefinitions()121 OptionGroupVariable::GetDefinitions ()
122 {
123     // Show the "--no-args", "--no-locals" and "--show-globals"
124     // options if we are showing frame specific options
125     if (include_frame_options)
126         return g_option_table;
127 
128     // Skip the "--no-args", "--no-locals" and "--show-globals"
129     // options if we are not showing frame specific options (globals only)
130     return &g_option_table[NUM_FRAME_OPTS];
131 }
132 
133 uint32_t
GetNumDefinitions()134 OptionGroupVariable::GetNumDefinitions ()
135 {
136     // Count the "--no-args", "--no-locals" and "--show-globals"
137     // options if we are showing frame specific options.
138     if (include_frame_options)
139         return llvm::array_lengthof(g_option_table);
140     else
141         return llvm::array_lengthof(g_option_table) - NUM_FRAME_OPTS;
142 }
143 
144 
145