blob: 06973f8b644aa7ff7d04b4542bb35c65d988eb9d [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
Greg Clayton67cc0632012-08-22 17:17:09 +000010#include "lldb/Interpreter/OptionValueArch.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Greg Clayton67cc0632012-08-22 17:17:09 +000016#include "lldb/Core/State.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000017#include "lldb/DataFormatters/FormatManager.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000018#include "lldb/Interpreter/Args.h"
19#include "lldb/Interpreter/CommandCompletions.h"
Todd Fialae1cfbc72016-08-11 23:51:28 +000020#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000021
22using namespace lldb;
23using namespace lldb_private;
24
25void
26OptionValueArch::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
27{
28 if (dump_mask & eDumpOptionType)
29 strm.Printf ("(%s)", GetTypeAsCString ());
30 if (dump_mask & eDumpOptionValue)
31 {
32 if (dump_mask & eDumpOptionType)
33 strm.PutCString (" = ");
34
35 if (m_current_value.IsValid())
36 {
37 const char *arch_name = m_current_value.GetArchitectureName();
38 if (arch_name)
39 strm.PutCString (arch_name);
40 }
41 }
42}
43
44Error
Pavel Labathc95f7e22015-02-20 11:14:59 +000045OptionValueArch::SetValueFromString (llvm::StringRef value, VarSetOperationType op)
Greg Clayton67cc0632012-08-22 17:17:09 +000046{
47 Error error;
48 switch (op)
49 {
50 case eVarSetOperationClear:
51 Clear();
Greg Clayton332e8b12015-01-13 21:13:08 +000052 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000053 break;
54
55 case eVarSetOperationReplace:
56 case eVarSetOperationAssign:
Greg Clayton67cc0632012-08-22 17:17:09 +000057 {
Pavel Labathc95f7e22015-02-20 11:14:59 +000058 std::string value_str = value.trim().str();
59 if (m_current_value.SetTriple (value_str.c_str()))
Greg Clayton332e8b12015-01-13 21:13:08 +000060 {
Greg Clayton67cc0632012-08-22 17:17:09 +000061 m_value_was_set = true;
Greg Clayton332e8b12015-01-13 21:13:08 +000062 NotifyValueChanged();
63 }
Greg Clayton67cc0632012-08-22 17:17:09 +000064 else
Pavel Labathc95f7e22015-02-20 11:14:59 +000065 error.SetErrorStringWithFormat("unsupported architecture '%s'", value_str.c_str());
66 break;
Greg Clayton67cc0632012-08-22 17:17:09 +000067 }
Greg Clayton67cc0632012-08-22 17:17:09 +000068 case eVarSetOperationInsertBefore:
69 case eVarSetOperationInsertAfter:
70 case eVarSetOperationRemove:
71 case eVarSetOperationAppend:
72 case eVarSetOperationInvalid:
Pavel Labathc95f7e22015-02-20 11:14:59 +000073 error = OptionValue::SetValueFromString (value, op);
Greg Clayton67cc0632012-08-22 17:17:09 +000074 break;
75 }
76 return error;
77}
78
79lldb::OptionValueSP
80OptionValueArch::DeepCopy () const
81{
82 return OptionValueSP(new OptionValueArch(*this));
83}
84
85
86size_t
87OptionValueArch::AutoComplete (CommandInterpreter &interpreter,
88 const char *s,
89 int match_start_point,
90 int max_return_elements,
91 bool &word_complete,
92 StringList &matches)
93{
94 word_complete = false;
95 matches.Clear();
96 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
97 CommandCompletions::eArchitectureCompletion,
98 s,
99 match_start_point,
100 max_return_elements,
Ed Masted78c9572014-04-20 00:31:37 +0000101 nullptr,
Greg Clayton67cc0632012-08-22 17:17:09 +0000102 word_complete,
103 matches);
104 return matches.GetSize();
105}
106
107
108
109