blob: 6ee71aed800b2f8087ab02414db46c6015e138dc [file] [log] [blame]
Greg Clayton715c2362011-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
Enrico Granata9d140842012-12-11 22:42:19 +000016#include "lldb/Core/Error.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000017#include "lldb/DataFormatters/DataVisualization.h"
Greg Clayton715c2362011-07-07 04:38:25 +000018#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000019#include "lldb/Target/Target.h"
Johnny Chen0a57b232011-09-10 01:19:01 +000020#include "lldb/Utility/Utils.h"
Greg Clayton715c2362011-07-07 04:38:25 +000021
22using namespace lldb;
23using namespace lldb_private;
24
Enrico Granataf9fa6ee2011-07-12 00:18:11 +000025// if you add any options here, remember to update the counters in OptionGroupVariable::GetNumDefinitions()
Greg Clayton715c2362011-07-07 04:38:25 +000026static OptionDefinition
27g_option_table[] =
28{
Zachary Turnerd37221d2014-07-09 16:31:49 +000029 { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Omit function arguments."},
30 { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Omit local variables."},
31 { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g', OptionParser::eNoArgument, nullptr, nullptr, 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', OptionParser::eNoArgument, nullptr, nullptr, 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', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."},
34 { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
35 { LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Specify the summary that the variable output should use."},
36 { LLDB_OPT_SET_2, false, "summary-string", 'z', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Specify a summary string to use to format the variable output."},
Greg Clayton715c2362011-07-07 04:38:25 +000037};
38
Enrico Granataef6b06d2013-01-17 20:24:11 +000039static Error
40ValidateNamedSummary (const char* str, void*)
41{
42 if (!str || !str[0])
43 return Error("must specify a valid named summary");
44 TypeSummaryImplSP summary_sp;
45 if (DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(str), summary_sp) == false)
46 return Error("must specify a valid named summary");
47 return Error();
48}
49
50static Error
51ValidateSummaryString (const char* str, void*)
52{
53 if (!str || !str[0])
54 return Error("must specify a non-empty summary string");
55 return Error();
56}
Greg Clayton715c2362011-07-07 04:38:25 +000057
58OptionGroupVariable::OptionGroupVariable (bool show_frame_options) :
59 OptionGroup(),
Enrico Granata9d140842012-12-11 22:42:19 +000060 include_frame_options (show_frame_options),
Enrico Granataef6b06d2013-01-17 20:24:11 +000061 summary(ValidateNamedSummary),
62 summary_string(ValidateSummaryString)
Greg Clayton715c2362011-07-07 04:38:25 +000063{
64}
65
66OptionGroupVariable::~OptionGroupVariable ()
67{
68}
69
70Error
Todd Fialae1cfbc72016-08-11 23:51:28 +000071OptionGroupVariable::SetOptionValue(uint32_t option_idx,
72 const char *option_arg,
73 ExecutionContext *execution_context)
Greg Clayton715c2362011-07-07 04:38:25 +000074{
75 Error error;
76 if (!include_frame_options)
77 option_idx += 3;
Greg Clayton3bcdfc02012-12-04 00:32:51 +000078 const int short_option = g_option_table[option_idx].short_option;
Greg Clayton715c2362011-07-07 04:38:25 +000079 switch (short_option)
80 {
81 case 'r': use_regex = true; break;
82 case 'a': show_args = false; break;
83 case 'l': show_locals = false; break;
84 case 'g': show_globals = true; break;
85 case 'c': show_decl = true; break;
Greg Clayton715c2362011-07-07 04:38:25 +000086 case 's':
87 show_scope = true;
88 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +000089 case 'y':
Enrico Granata9d140842012-12-11 22:42:19 +000090 error = summary.SetCurrentValue(option_arg);
Enrico Granata17b11742012-08-09 22:02:51 +000091 break;
92 case 'z':
Enrico Granata9d140842012-12-11 22:42:19 +000093 error = summary_string.SetCurrentValue(option_arg);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +000094 break;
Greg Clayton715c2362011-07-07 04:38:25 +000095 default:
Greg Clayton86edbf42011-10-26 00:56:27 +000096 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
Greg Clayton715c2362011-07-07 04:38:25 +000097 break;
98 }
99
100 return error;
101}
102
103void
Todd Fialae1cfbc72016-08-11 23:51:28 +0000104OptionGroupVariable::OptionParsingStarting(ExecutionContext *execution_context)
Greg Clayton715c2362011-07-07 04:38:25 +0000105{
106 show_args = true; // Frame option only
107 show_locals = true; // Frame option only
108 show_globals = false; // Frame option only
109 show_decl = false;
Greg Clayton715c2362011-07-07 04:38:25 +0000110 use_regex = false;
111 show_scope = false;
Enrico Granata17b11742012-08-09 22:02:51 +0000112 summary.Clear();
113 summary_string.Clear();
Greg Clayton715c2362011-07-07 04:38:25 +0000114}
115
Johnny Chen0a57b232011-09-10 01:19:01 +0000116#define NUM_FRAME_OPTS 3
Greg Clayton715c2362011-07-07 04:38:25 +0000117
118const OptionDefinition*
119OptionGroupVariable::GetDefinitions ()
120{
121 // Show the "--no-args", "--no-locals" and "--show-globals"
122 // options if we are showing frame specific options
123 if (include_frame_options)
124 return g_option_table;
125
126 // Skip the "--no-args", "--no-locals" and "--show-globals"
127 // options if we are not showing frame specific options (globals only)
Johnny Chen0a57b232011-09-10 01:19:01 +0000128 return &g_option_table[NUM_FRAME_OPTS];
Greg Clayton715c2362011-07-07 04:38:25 +0000129}
130
131uint32_t
132OptionGroupVariable::GetNumDefinitions ()
133{
Johnny Chen0a57b232011-09-10 01:19:01 +0000134 // Count the "--no-args", "--no-locals" and "--show-globals"
135 // options if we are showing frame specific options.
Greg Clayton715c2362011-07-07 04:38:25 +0000136 if (include_frame_options)
Johnny Chen6ebc8c452012-05-15 23:21:36 +0000137 return llvm::array_lengthof(g_option_table);
Greg Clayton715c2362011-07-07 04:38:25 +0000138 else
Johnny Chen6ebc8c452012-05-15 23:21:36 +0000139 return llvm::array_lengthof(g_option_table) - NUM_FRAME_OPTS;
Greg Clayton715c2362011-07-07 04:38:25 +0000140}
141
142