blob: 221a5c5f1b2b0c732b8c7c63f7a5db982b5810d7 [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- 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 Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton67cc0632012-08-22 17:17:09 +000012#include "lldb/Interpreter/OptionValueFileSpec.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
Greg Claytonb5f0fea2012-09-27 22:26:11 +000026
Vince Harron1f4706c2015-02-18 23:12:26 +000027OptionValueFileSpec::OptionValueFileSpec (bool resolve) :
Greg Claytonb5f0fea2012-09-27 22:26:11 +000028 OptionValue(),
29 m_current_value (),
30 m_default_value (),
31 m_data_sp(),
Vince Harron1f4706c2015-02-18 23:12:26 +000032 m_completion_mask (CommandCompletions::eDiskFileCompletion),
33 m_resolve (resolve)
Greg Claytonb5f0fea2012-09-27 22:26:11 +000034{
35}
36
Vince Harron1f4706c2015-02-18 23:12:26 +000037OptionValueFileSpec::OptionValueFileSpec (const FileSpec &value,
38 bool resolve) :
Greg Claytonb5f0fea2012-09-27 22:26:11 +000039 OptionValue(),
40 m_current_value (value),
41 m_default_value (value),
42 m_data_sp(),
Vince Harron1f4706c2015-02-18 23:12:26 +000043 m_completion_mask (CommandCompletions::eDiskFileCompletion),
44 m_resolve (resolve)
Greg Claytonb5f0fea2012-09-27 22:26:11 +000045{
46}
47
48OptionValueFileSpec::OptionValueFileSpec (const FileSpec &current_value,
Vince Harron1f4706c2015-02-18 23:12:26 +000049 const FileSpec &default_value,
50 bool resolve) :
Greg Claytonb5f0fea2012-09-27 22:26:11 +000051 OptionValue(),
52 m_current_value (current_value),
53 m_default_value (default_value),
54 m_data_sp(),
Vince Harron1f4706c2015-02-18 23:12:26 +000055 m_completion_mask (CommandCompletions::eDiskFileCompletion),
56 m_resolve (resolve)
Greg Claytonb5f0fea2012-09-27 22:26:11 +000057{
58}
59
Greg Clayton67cc0632012-08-22 17:17:09 +000060void
61OptionValueFileSpec::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
62{
63 if (dump_mask & eDumpOptionType)
64 strm.Printf ("(%s)", GetTypeAsCString ());
65 if (dump_mask & eDumpOptionValue)
66 {
67 if (dump_mask & eDumpOptionType)
68 strm.PutCString (" = ");
69
70 if (m_current_value)
71 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +000072 strm << '"' << m_current_value.GetPath().c_str() << '"';
Greg Clayton67cc0632012-08-22 17:17:09 +000073 }
74 }
75}
76
77Error
Pavel Labathc95f7e22015-02-20 11:14:59 +000078OptionValueFileSpec::SetValueFromString (llvm::StringRef value,
Greg Clayton67cc0632012-08-22 17:17:09 +000079 VarSetOperationType op)
80{
81 Error error;
82 switch (op)
83 {
84 case eVarSetOperationClear:
85 Clear ();
Greg Clayton332e8b12015-01-13 21:13:08 +000086 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000087 break;
88
89 case eVarSetOperationReplace:
90 case eVarSetOperationAssign:
Pavel Labathc95f7e22015-02-20 11:14:59 +000091 if (value.size() > 0)
Greg Clayton67cc0632012-08-22 17:17:09 +000092 {
Jason Molenda5c98b1c2013-09-13 02:33:15 +000093 // The setting value may have whitespace, double-quotes, or single-quotes around the file
94 // path to indicate that internal spaces are not word breaks. Strip off any ws & quotes
95 // from the start and end of the file path - we aren't doing any word // breaking here so
96 // the quoting is unnecessary. NB this will cause a problem if someone tries to specify
97 // a file path that legitimately begins or ends with a " or ' character, or whitespace.
Pavel Labathc95f7e22015-02-20 11:14:59 +000098 value = value.trim("\"' \t");
Jason Molenda36d44612013-08-27 04:58:31 +000099 m_value_was_set = true;
Pavel Labathc95f7e22015-02-20 11:14:59 +0000100 m_current_value.SetFile(value.str().c_str(), m_resolve);
Jim Ingham2e3881c2014-04-04 18:06:54 +0000101 m_data_sp.reset();
Greg Clayton332e8b12015-01-13 21:13:08 +0000102 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +0000103 }
104 else
105 {
106 error.SetErrorString("invalid value string");
107 }
108 break;
109
110 case eVarSetOperationInsertBefore:
111 case eVarSetOperationInsertAfter:
112 case eVarSetOperationRemove:
113 case eVarSetOperationAppend:
114 case eVarSetOperationInvalid:
Pavel Labathc95f7e22015-02-20 11:14:59 +0000115 error = OptionValue::SetValueFromString (value, op);
Greg Clayton67cc0632012-08-22 17:17:09 +0000116 break;
117 }
118 return error;
119}
120
121lldb::OptionValueSP
122OptionValueFileSpec::DeepCopy () const
123{
124 return OptionValueSP(new OptionValueFileSpec(*this));
125}
126
127
128size_t
129OptionValueFileSpec::AutoComplete (CommandInterpreter &interpreter,
130 const char *s,
131 int match_start_point,
132 int max_return_elements,
133 bool &word_complete,
134 StringList &matches)
135{
136 word_complete = false;
137 matches.Clear();
138 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
Greg Claytonb5f0fea2012-09-27 22:26:11 +0000139 m_completion_mask,
Greg Clayton67cc0632012-08-22 17:17:09 +0000140 s,
141 match_start_point,
142 max_return_elements,
Ed Masted78c9572014-04-20 00:31:37 +0000143 nullptr,
Greg Clayton67cc0632012-08-22 17:17:09 +0000144 word_complete,
145 matches);
146 return matches.GetSize();
147}
148
149
150
Greg Clayton6920b522012-08-22 18:39:03 +0000151const lldb::DataBufferSP &
Greg Clayton0b0b5122012-08-30 18:15:10 +0000152OptionValueFileSpec::GetFileContents(bool null_terminate)
Greg Clayton6920b522012-08-22 18:39:03 +0000153{
154 if (!m_data_sp && m_current_value)
Greg Clayton0b0b5122012-08-30 18:15:10 +0000155 {
156 if (null_terminate)
157 m_data_sp = m_current_value.ReadFileContentsAsCString();
158 else
159 m_data_sp = m_current_value.ReadFileContents();
160 }
Greg Clayton6920b522012-08-22 18:39:03 +0000161 return m_data_sp;
162}
163
Greg Clayton67cc0632012-08-22 17:17:09 +0000164