1 //===-- OptionValueFileSpec.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/OptionValueFileSpec.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 27 OptionValueFileSpec::OptionValueFileSpec () : 28 OptionValue(), 29 m_current_value (), 30 m_default_value (), 31 m_data_sp(), 32 m_completion_mask (CommandCompletions::eDiskFileCompletion) 33 { 34 } 35 36 OptionValueFileSpec::OptionValueFileSpec (const FileSpec &value) : 37 OptionValue(), 38 m_current_value (value), 39 m_default_value (value), 40 m_data_sp(), 41 m_completion_mask (CommandCompletions::eDiskFileCompletion) 42 { 43 } 44 45 OptionValueFileSpec::OptionValueFileSpec (const FileSpec ¤t_value, 46 const FileSpec &default_value) : 47 OptionValue(), 48 m_current_value (current_value), 49 m_default_value (default_value), 50 m_data_sp(), 51 m_completion_mask (CommandCompletions::eDiskFileCompletion) 52 { 53 } 54 55 void 56 OptionValueFileSpec::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 57 { 58 if (dump_mask & eDumpOptionType) 59 strm.Printf ("(%s)", GetTypeAsCString ()); 60 if (dump_mask & eDumpOptionValue) 61 { 62 if (dump_mask & eDumpOptionType) 63 strm.PutCString (" = "); 64 65 if (m_current_value) 66 { 67 strm << '"' << m_current_value.GetPath().c_str() << '"'; 68 } 69 } 70 } 71 72 Error 73 OptionValueFileSpec::SetValueFromCString (const char *value_cstr, 74 VarSetOperationType op) 75 { 76 Error error; 77 switch (op) 78 { 79 case eVarSetOperationClear: 80 Clear (); 81 break; 82 83 case eVarSetOperationReplace: 84 case eVarSetOperationAssign: 85 if (value_cstr && value_cstr[0]) 86 { 87 m_value_was_set = true; 88 m_current_value.SetFile(value_cstr, true); 89 } 90 else 91 { 92 error.SetErrorString("invalid value string"); 93 } 94 break; 95 96 case eVarSetOperationInsertBefore: 97 case eVarSetOperationInsertAfter: 98 case eVarSetOperationRemove: 99 case eVarSetOperationAppend: 100 case eVarSetOperationInvalid: 101 error = OptionValue::SetValueFromCString (value_cstr, op); 102 break; 103 } 104 return error; 105 } 106 107 lldb::OptionValueSP 108 OptionValueFileSpec::DeepCopy () const 109 { 110 return OptionValueSP(new OptionValueFileSpec(*this)); 111 } 112 113 114 size_t 115 OptionValueFileSpec::AutoComplete (CommandInterpreter &interpreter, 116 const char *s, 117 int match_start_point, 118 int max_return_elements, 119 bool &word_complete, 120 StringList &matches) 121 { 122 word_complete = false; 123 matches.Clear(); 124 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, 125 m_completion_mask, 126 s, 127 match_start_point, 128 max_return_elements, 129 NULL, 130 word_complete, 131 matches); 132 return matches.GetSize(); 133 } 134 135 136 137 const lldb::DataBufferSP & 138 OptionValueFileSpec::GetFileContents(bool null_terminate) 139 { 140 if (!m_data_sp && m_current_value) 141 { 142 if (null_terminate) 143 m_data_sp = m_current_value.ReadFileContentsAsCString(); 144 else 145 m_data_sp = m_current_value.ReadFileContents(); 146 } 147 return m_data_sp; 148 } 149 150 151