blob: eae903ce5be485b6a2b3042ae13b83e7592e1a6d [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- OptionValueArch.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 Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton67cc0632012-08-22 17:17:09 +000012#include "lldb/Interpreter/OptionValueArch.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
Greg Clayton67cc0632012-08-22 17:17:09 +000018#include "lldb/Core/State.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000019#include "lldb/DataFormatters/FormatManager.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000020#include "lldb/Interpreter/Args.h"
21#include "lldb/Interpreter/CommandCompletions.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26void
27OptionValueArch::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
28{
29 if (dump_mask & eDumpOptionType)
30 strm.Printf ("(%s)", GetTypeAsCString ());
31 if (dump_mask & eDumpOptionValue)
32 {
33 if (dump_mask & eDumpOptionType)
34 strm.PutCString (" = ");
35
36 if (m_current_value.IsValid())
37 {
38 const char *arch_name = m_current_value.GetArchitectureName();
39 if (arch_name)
40 strm.PutCString (arch_name);
41 }
42 }
43}
44
45Error
46OptionValueArch::SetValueFromCString (const char *value_cstr, VarSetOperationType op)
47{
48 Error error;
49 switch (op)
50 {
51 case eVarSetOperationClear:
52 Clear();
Greg Clayton332e8b12015-01-13 21:13:08 +000053 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000054 break;
55
56 case eVarSetOperationReplace:
57 case eVarSetOperationAssign:
Pavel Labathdf50f942015-02-16 13:13:39 +000058 if (value_cstr)
Greg Clayton67cc0632012-08-22 17:17:09 +000059 {
Pavel Labathdf50f942015-02-16 13:13:39 +000060 std::string value = llvm::StringRef(value_cstr).trim().str();
61 value_cstr = value.c_str();
Greg Clayton67cc0632012-08-22 17:17:09 +000062 if (m_current_value.SetTriple (value_cstr))
Greg Clayton332e8b12015-01-13 21:13:08 +000063 {
Greg Clayton67cc0632012-08-22 17:17:09 +000064 m_value_was_set = true;
Greg Clayton332e8b12015-01-13 21:13:08 +000065 NotifyValueChanged();
66 }
Greg Clayton67cc0632012-08-22 17:17:09 +000067 else
68 error.SetErrorStringWithFormat("unsupported architecture '%s'", value_cstr);
69 }
70 else
71 {
72 error.SetErrorString("invalid value string");
73 }
74 break;
75
76 case eVarSetOperationInsertBefore:
77 case eVarSetOperationInsertAfter:
78 case eVarSetOperationRemove:
79 case eVarSetOperationAppend:
80 case eVarSetOperationInvalid:
81 error = OptionValue::SetValueFromCString (value_cstr, op);
82 break;
83 }
84 return error;
85}
86
87lldb::OptionValueSP
88OptionValueArch::DeepCopy () const
89{
90 return OptionValueSP(new OptionValueArch(*this));
91}
92
93
94size_t
95OptionValueArch::AutoComplete (CommandInterpreter &interpreter,
96 const char *s,
97 int match_start_point,
98 int max_return_elements,
99 bool &word_complete,
100 StringList &matches)
101{
102 word_complete = false;
103 matches.Clear();
104 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
105 CommandCompletions::eArchitectureCompletion,
106 s,
107 match_start_point,
108 max_return_elements,
Ed Masted78c9572014-04-20 00:31:37 +0000109 nullptr,
Greg Clayton67cc0632012-08-22 17:17:09 +0000110 word_complete,
111 matches);
112 return matches.GetSize();
113}
114
115
116
117