LLDB mainline
OptionValueFileSpec.cpp
Go to the documentation of this file.
1//===-- OptionValueFileSpec.cpp -------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
16#include "lldb/Utility/Args.h"
17#include "lldb/Utility/State.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
23
25 : m_current_value(value), m_default_value(value),
26
27 m_resolve(resolve) {}
28
30 const FileSpec &default_value,
31 bool resolve)
32 : m_current_value(current_value), m_default_value(default_value),
33
34 m_resolve(resolve) {}
35
37 Stream &strm, uint32_t dump_mask) {
38 if (dump_mask & eDumpOptionType)
39 strm.Printf("(%s)", GetTypeAsCString());
40 if (dump_mask & eDumpOptionValue) {
41 if (dump_mask & eDumpOptionType)
42 strm.PutCString(" = ");
43
44 if (m_current_value) {
45 strm << '"' << m_current_value.GetPath() << '"';
46 }
47 if (dump_mask & eDumpOptionDefaultValue &&
49 DefaultValueFormat label(strm);
50 strm << '"' << m_default_value.GetPath() << '"';
51 }
52 }
53}
54
58 switch (op) {
60 Clear();
62 break;
63
66 if (value.size() > 0) {
67 value = value.trim("\"' \t");
68 m_value_was_set = true;
69 m_current_value.SetFile(value.str(), FileSpec::Style::native);
70 if (m_resolve)
72 m_data_sp.reset();
73 m_data_mod_time = llvm::sys::TimePoint<>();
75 } else {
76 error = Status::FromErrorString("invalid value string");
77 }
78 break;
79
86 break;
87 }
88 return error;
89}
90
96
98 if (m_current_value) {
99 const auto file_mod_time = FileSystem::Instance().GetModificationTime(m_current_value);
100 if (m_data_sp && m_data_mod_time == file_mod_time)
101 return m_data_sp;
102 m_data_sp =
104 m_data_mod_time = file_mod_time;
105 }
106 return m_data_sp;
107}
static llvm::raw_ostream & error(Stream &strm)
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
"lldb/Utility/ArgCompletionRequest.h"
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition FileSpec.h:57
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
static FileSystem & Instance()
std::shared_ptr< DataBuffer > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
void AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request) override
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
const lldb::DataBufferSP & GetFileContents()
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
virtual const char * GetTypeAsCString() const
Definition OptionValue.h:89
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP