Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 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 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 12 | #include "lldb/Interpreter/OptionValueFileSpec.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
| 17 | // Project includes |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 18 | #include "lldb/Core/State.h" |
Enrico Granata | f509c5e | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 19 | #include "lldb/DataFormatters/FormatManager.h" |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 20 | #include "lldb/Interpreter/Args.h" |
| 21 | #include "lldb/Interpreter/CommandCompletions.h" |
| 22 | |
| 23 | using namespace lldb; |
| 24 | using namespace lldb_private; |
| 25 | |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 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 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 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 | { |
Greg Clayton | 97a19b2 | 2013-04-29 17:25:54 +0000 | [diff] [blame^] | 67 | strm << '"' << m_current_value.GetPath().c_str() << '"'; |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 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 | { |
Sean Callanan | eff8320 | 2013-03-15 01:39:44 +0000 | [diff] [blame] | 87 | Args args(value_cstr); |
| 88 | if (args.GetArgumentCount() == 1) |
| 89 | { |
| 90 | const char *path = args.GetArgumentAtIndex(0); |
| 91 | m_value_was_set = true; |
| 92 | m_current_value.SetFile(path, true); |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | error.SetErrorString("please supply a single path argument for this file or quote the path if it contains spaces"); |
| 97 | } |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 98 | } |
| 99 | else |
| 100 | { |
| 101 | error.SetErrorString("invalid value string"); |
| 102 | } |
| 103 | break; |
| 104 | |
| 105 | case eVarSetOperationInsertBefore: |
| 106 | case eVarSetOperationInsertAfter: |
| 107 | case eVarSetOperationRemove: |
| 108 | case eVarSetOperationAppend: |
| 109 | case eVarSetOperationInvalid: |
| 110 | error = OptionValue::SetValueFromCString (value_cstr, op); |
| 111 | break; |
| 112 | } |
| 113 | return error; |
| 114 | } |
| 115 | |
| 116 | lldb::OptionValueSP |
| 117 | OptionValueFileSpec::DeepCopy () const |
| 118 | { |
| 119 | return OptionValueSP(new OptionValueFileSpec(*this)); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | size_t |
| 124 | OptionValueFileSpec::AutoComplete (CommandInterpreter &interpreter, |
| 125 | const char *s, |
| 126 | int match_start_point, |
| 127 | int max_return_elements, |
| 128 | bool &word_complete, |
| 129 | StringList &matches) |
| 130 | { |
| 131 | word_complete = false; |
| 132 | matches.Clear(); |
| 133 | CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 134 | m_completion_mask, |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 135 | s, |
| 136 | match_start_point, |
| 137 | max_return_elements, |
| 138 | NULL, |
| 139 | word_complete, |
| 140 | matches); |
| 141 | return matches.GetSize(); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 146 | const lldb::DataBufferSP & |
Greg Clayton | fc04d24 | 2012-08-30 18:15:10 +0000 | [diff] [blame] | 147 | OptionValueFileSpec::GetFileContents(bool null_terminate) |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 148 | { |
| 149 | if (!m_data_sp && m_current_value) |
Greg Clayton | fc04d24 | 2012-08-30 18:15:10 +0000 | [diff] [blame] | 150 | { |
| 151 | if (null_terminate) |
| 152 | m_data_sp = m_current_value.ReadFileContentsAsCString(); |
| 153 | else |
| 154 | m_data_sp = m_current_value.ReadFileContents(); |
| 155 | } |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 156 | return m_data_sp; |
| 157 | } |
| 158 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 159 | |