1 //===-- 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 
10 #include "lldb/lldb-python.h"
11 
12 #include "lldb/Interpreter/OptionValueArch.h"
13 
14 // C Includes
15 // C++ Includes
16 // Other libraries and framework includes
17 // Project includes
18 #include "lldb/Core/State.h"
19 #include "lldb/DataFormatters/FormatManager.h"
20 #include "lldb/Interpreter/Args.h"
21 #include "lldb/Interpreter/CommandCompletions.h"
22 
23 using namespace lldb;
24 using namespace lldb_private;
25 
26 void
27 OptionValueArch::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 
45 Error
46 OptionValueArch::SetValueFromString (llvm::StringRef value, VarSetOperationType op)
47 {
48     Error error;
49     switch (op)
50     {
51     case eVarSetOperationClear:
52         Clear();
53         NotifyValueChanged();
54         break;
55 
56     case eVarSetOperationReplace:
57     case eVarSetOperationAssign:
58         {
59             std::string value_str = value.trim().str();
60             if (m_current_value.SetTriple (value_str.c_str()))
61             {
62                 m_value_was_set = true;
63                 NotifyValueChanged();
64             }
65             else
66                 error.SetErrorStringWithFormat("unsupported architecture '%s'", value_str.c_str());
67             break;
68         }
69     case eVarSetOperationInsertBefore:
70     case eVarSetOperationInsertAfter:
71     case eVarSetOperationRemove:
72     case eVarSetOperationAppend:
73     case eVarSetOperationInvalid:
74         error = OptionValue::SetValueFromString (value, op);
75         break;
76     }
77     return error;
78 }
79 
80 lldb::OptionValueSP
81 OptionValueArch::DeepCopy () const
82 {
83     return OptionValueSP(new OptionValueArch(*this));
84 }
85 
86 
87 size_t
88 OptionValueArch::AutoComplete (CommandInterpreter &interpreter,
89                                    const char *s,
90                                    int match_start_point,
91                                    int max_return_elements,
92                                    bool &word_complete,
93                                    StringList &matches)
94 {
95     word_complete = false;
96     matches.Clear();
97     CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
98                                                          CommandCompletions::eArchitectureCompletion,
99                                                          s,
100                                                          match_start_point,
101                                                          max_return_elements,
102                                                          nullptr,
103                                                          word_complete,
104                                                          matches);
105     return matches.GetSize();
106 }
107 
108 
109 
110 
111