blob: a2bdbb26e2a6ddbc772307ed84123083fe8f3db1 [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"
Johnny Chencfbf7fe2011-09-10 01:19:01 +000018#include "lldb/Utility/Utils.h"
Greg Clayton368f8222011-07-07 04:38:25 +000019
20using namespace lldb;
21using namespace lldb_private;
22
Enrico Granata1a102082011-07-12 00:18:11 +000023// if you add any options here, remember to update the counters in OptionGroupVariable::GetNumDefinitions()
Greg Clayton368f8222011-07-07 04:38:25 +000024static OptionDefinition
25g_option_table[] =
26{
27 { LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
28 { LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
29 { LLDB_OPT_SET_1, false, "show-globals", 'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
30 { 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)."},
31 { LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, eArgTypeExprFormat, "Specify the format that the variable output should use."},
32 { 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 +000033 { LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
34 { 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 +000035};
36
37
38OptionGroupVariable::OptionGroupVariable (bool show_frame_options) :
39 OptionGroup(),
40 include_frame_options (show_frame_options)
41{
42}
43
44OptionGroupVariable::~OptionGroupVariable ()
45{
46}
47
48Error
49OptionGroupVariable::SetOptionValue (CommandInterpreter &interpreter,
50 uint32_t option_idx,
51 const char *option_arg)
52{
53 Error error;
54 if (!include_frame_options)
55 option_idx += 3;
56 char short_option = (char) g_option_table[option_idx].short_option;
57 switch (short_option)
58 {
59 case 'r': use_regex = true; break;
60 case 'a': show_args = false; break;
61 case 'l': show_locals = false; break;
62 case 'g': show_globals = true; break;
63 case 'c': show_decl = true; break;
64 case 'f': error = Args::StringToFormat(option_arg, format, NULL); break;
65 case 's':
66 show_scope = true;
67 break;
Enrico Granata1a102082011-07-12 00:18:11 +000068 case 'y':
69 summary = std::string(option_arg);
70 break;
Greg Clayton368f8222011-07-07 04:38:25 +000071 default:
72 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
73 break;
74 }
75
76 return error;
77}
78
79void
80OptionGroupVariable::OptionParsingStarting (CommandInterpreter &interpreter)
81{
82 show_args = true; // Frame option only
83 show_locals = true; // Frame option only
84 show_globals = false; // Frame option only
85 show_decl = false;
86 format = lldb::eFormatDefault;
87 use_regex = false;
88 show_scope = false;
Enrico Granata1a102082011-07-12 00:18:11 +000089 summary = "";
Greg Clayton368f8222011-07-07 04:38:25 +000090}
91
Johnny Chencfbf7fe2011-09-10 01:19:01 +000092#define NUM_FRAME_OPTS 3
Greg Clayton368f8222011-07-07 04:38:25 +000093
94const OptionDefinition*
95OptionGroupVariable::GetDefinitions ()
96{
97 // Show the "--no-args", "--no-locals" and "--show-globals"
98 // options if we are showing frame specific options
99 if (include_frame_options)
100 return g_option_table;
101
102 // Skip the "--no-args", "--no-locals" and "--show-globals"
103 // options if we are not showing frame specific options (globals only)
Johnny Chencfbf7fe2011-09-10 01:19:01 +0000104 return &g_option_table[NUM_FRAME_OPTS];
Greg Clayton368f8222011-07-07 04:38:25 +0000105}
106
107uint32_t
108OptionGroupVariable::GetNumDefinitions ()
109{
Johnny Chencfbf7fe2011-09-10 01:19:01 +0000110 // Count the "--no-args", "--no-locals" and "--show-globals"
111 // options if we are showing frame specific options.
Greg Clayton368f8222011-07-07 04:38:25 +0000112 if (include_frame_options)
Johnny Chencfbf7fe2011-09-10 01:19:01 +0000113 return arraysize(g_option_table);
Greg Clayton368f8222011-07-07 04:38:25 +0000114 else
Johnny Chencfbf7fe2011-09-10 01:19:01 +0000115 return arraysize(g_option_table) - NUM_FRAME_OPTS;
Greg Clayton368f8222011-07-07 04:38:25 +0000116}
117
118