blob: 891e19ac577fa4baa763e6ea267321a05b21f480 [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
Daniel Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton368f8222011-07-07 04:38:25 +000012#include "lldb/Interpreter/OptionGroupVariable.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
Enrico Granata729e99e2012-12-11 22:42:19 +000018#include "lldb/Core/DataVisualization.h"
19#include "lldb/Core/Error.h"
Greg Clayton368f8222011-07-07 04:38:25 +000020#include "lldb/Target/Target.h"
21#include "lldb/Interpreter/CommandInterpreter.h"
Johnny Chencfbf7fe2011-09-10 01:19:01 +000022#include "lldb/Utility/Utils.h"
Greg Clayton368f8222011-07-07 04:38:25 +000023
24using namespace lldb;
25using namespace lldb_private;
26
Enrico Granata1a102082011-07-12 00:18:11 +000027// if you add any options here, remember to update the counters in OptionGroupVariable::GetNumDefinitions()
Greg Clayton368f8222011-07-07 04:38:25 +000028static OptionDefinition
29g_option_table[] =
30{
Greg Clayton6475c422012-12-04 00:32:51 +000031 { 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 Clayton368f8222011-07-07 04:38:25 +000039};
40
Enrico Granatac4f42012013-01-17 20:24:11 +000041static Error
42ValidateNamedSummary (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
52static Error
53ValidateSummaryString (const char* str, void*)
54{
55 if (!str || !str[0])
56 return Error("must specify a non-empty summary string");
57 return Error();
58}
Greg Clayton368f8222011-07-07 04:38:25 +000059
60OptionGroupVariable::OptionGroupVariable (bool show_frame_options) :
61 OptionGroup(),
Enrico Granata729e99e2012-12-11 22:42:19 +000062 include_frame_options (show_frame_options),
Enrico Granatac4f42012013-01-17 20:24:11 +000063 summary(ValidateNamedSummary),
64 summary_string(ValidateSummaryString)
Greg Clayton368f8222011-07-07 04:38:25 +000065{
66}
67
68OptionGroupVariable::~OptionGroupVariable ()
69{
70}
71
72Error
73OptionGroupVariable::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;
Greg Clayton6475c422012-12-04 00:32:51 +000080 const int short_option = g_option_table[option_idx].short_option;
Greg Clayton368f8222011-07-07 04:38:25 +000081 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;
Greg Clayton368f8222011-07-07 04:38:25 +000088 case 's':
89 show_scope = true;
90 break;
Enrico Granata1a102082011-07-12 00:18:11 +000091 case 'y':
Enrico Granata729e99e2012-12-11 22:42:19 +000092 error = summary.SetCurrentValue(option_arg);
Enrico Granata879de482012-08-09 22:02:51 +000093 break;
94 case 'z':
Enrico Granata729e99e2012-12-11 22:42:19 +000095 error = summary_string.SetCurrentValue(option_arg);
Enrico Granata1a102082011-07-12 00:18:11 +000096 break;
Greg Clayton368f8222011-07-07 04:38:25 +000097 default:
Greg Clayton9c236732011-10-26 00:56:27 +000098 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
Greg Clayton368f8222011-07-07 04:38:25 +000099 break;
100 }
101
102 return error;
103}
104
105void
106OptionGroupVariable::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;
Greg Clayton368f8222011-07-07 04:38:25 +0000112 use_regex = false;
113 show_scope = false;
Enrico Granata879de482012-08-09 22:02:51 +0000114 summary.Clear();
115 summary_string.Clear();
Greg Clayton368f8222011-07-07 04:38:25 +0000116}
117
Johnny Chencfbf7fe2011-09-10 01:19:01 +0000118#define NUM_FRAME_OPTS 3
Greg Clayton368f8222011-07-07 04:38:25 +0000119
120const OptionDefinition*
121OptionGroupVariable::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)
Johnny Chencfbf7fe2011-09-10 01:19:01 +0000130 return &g_option_table[NUM_FRAME_OPTS];
Greg Clayton368f8222011-07-07 04:38:25 +0000131}
132
133uint32_t
134OptionGroupVariable::GetNumDefinitions ()
135{
Johnny Chencfbf7fe2011-09-10 01:19:01 +0000136 // Count the "--no-args", "--no-locals" and "--show-globals"
137 // options if we are showing frame specific options.
Greg Clayton368f8222011-07-07 04:38:25 +0000138 if (include_frame_options)
Johnny Chen08af5982012-05-15 23:21:36 +0000139 return llvm::array_lengthof(g_option_table);
Greg Clayton368f8222011-07-07 04:38:25 +0000140 else
Johnny Chen08af5982012-05-15 23:21:36 +0000141 return llvm::array_lengthof(g_option_table) - NUM_FRAME_OPTS;
Greg Clayton368f8222011-07-07 04:38:25 +0000142}
143
144