blob: c1bcae2fc6c1d6c6476a9dd8192c57db88f0601f [file] [log] [blame]
Greg Clayton73844aa2012-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 Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton73844aa2012-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 Clayton73844aa2012-08-22 17:17:09 +000018#include "lldb/Core/State.h"
Enrico Granataf509c5e2013-01-28 23:47:25 +000019#include "lldb/DataFormatters/FormatManager.h"
Greg Clayton73844aa2012-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 Clayton437b5bc2012-09-27 22:26:11 +000026
27OptionValueFileSpec::OptionValueFileSpec () :
28 OptionValue(),
29 m_current_value (),
30 m_default_value (),
31 m_data_sp(),
32 m_completion_mask (CommandCompletions::eDiskFileCompletion)
33{
34}
35
36OptionValueFileSpec::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
45OptionValueFileSpec::OptionValueFileSpec (const FileSpec &current_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 Clayton73844aa2012-08-22 17:17:09 +000055void
56OptionValueFileSpec::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 if (m_current_value.GetDirectory())
68 {
69 strm << '"' << m_current_value.GetDirectory();
70 if (m_current_value.GetFilename())
71 strm << '/' << m_current_value.GetFilename();
72 strm << '"';
73 }
74 else
75 {
76 strm << '"' << m_current_value.GetFilename() << '"';
77 }
78 }
79 }
80}
81
82Error
83OptionValueFileSpec::SetValueFromCString (const char *value_cstr,
84 VarSetOperationType op)
85{
86 Error error;
87 switch (op)
88 {
89 case eVarSetOperationClear:
90 Clear ();
91 break;
92
93 case eVarSetOperationReplace:
94 case eVarSetOperationAssign:
95 if (value_cstr && value_cstr[0])
96 {
Sean Callananeff83202013-03-15 01:39:44 +000097 Args args(value_cstr);
98 if (args.GetArgumentCount() == 1)
99 {
100 const char *path = args.GetArgumentAtIndex(0);
101 m_value_was_set = true;
102 m_current_value.SetFile(path, true);
103 }
104 else
105 {
106 error.SetErrorString("please supply a single path argument for this file or quote the path if it contains spaces");
107 }
Greg Clayton73844aa2012-08-22 17:17:09 +0000108 }
109 else
110 {
111 error.SetErrorString("invalid value string");
112 }
113 break;
114
115 case eVarSetOperationInsertBefore:
116 case eVarSetOperationInsertAfter:
117 case eVarSetOperationRemove:
118 case eVarSetOperationAppend:
119 case eVarSetOperationInvalid:
120 error = OptionValue::SetValueFromCString (value_cstr, op);
121 break;
122 }
123 return error;
124}
125
126lldb::OptionValueSP
127OptionValueFileSpec::DeepCopy () const
128{
129 return OptionValueSP(new OptionValueFileSpec(*this));
130}
131
132
133size_t
134OptionValueFileSpec::AutoComplete (CommandInterpreter &interpreter,
135 const char *s,
136 int match_start_point,
137 int max_return_elements,
138 bool &word_complete,
139 StringList &matches)
140{
141 word_complete = false;
142 matches.Clear();
143 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
Greg Clayton437b5bc2012-09-27 22:26:11 +0000144 m_completion_mask,
Greg Clayton73844aa2012-08-22 17:17:09 +0000145 s,
146 match_start_point,
147 max_return_elements,
148 NULL,
149 word_complete,
150 matches);
151 return matches.GetSize();
152}
153
154
155
Greg Claytonc6e82e42012-08-22 18:39:03 +0000156const lldb::DataBufferSP &
Greg Claytonfc04d242012-08-30 18:15:10 +0000157OptionValueFileSpec::GetFileContents(bool null_terminate)
Greg Claytonc6e82e42012-08-22 18:39:03 +0000158{
159 if (!m_data_sp && m_current_value)
Greg Claytonfc04d242012-08-30 18:15:10 +0000160 {
161 if (null_terminate)
162 m_data_sp = m_current_value.ReadFileContentsAsCString();
163 else
164 m_data_sp = m_current_value.ReadFileContents();
165 }
Greg Claytonc6e82e42012-08-22 18:39:03 +0000166 return m_data_sp;
167}
168
Greg Clayton73844aa2012-08-22 17:17:09 +0000169