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
15#include "lldb/Utility/Args.h"
16#include "lldb/Utility/State.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
21OptionValueFileSpec::OptionValueFileSpec(bool resolve) : m_resolve(resolve) {}
22
24 : m_current_value(value), m_default_value(value),
25
26 m_resolve(resolve) {}
27
29 const FileSpec &default_value,
30 bool resolve)
31 : m_current_value(current_value), m_default_value(default_value),
32
33 m_resolve(resolve) {}
34
36 Stream &strm, uint32_t dump_mask) {
37 if (dump_mask & eDumpOptionType)
38 strm.Printf("(%s)", GetTypeAsCString());
39 if (dump_mask & eDumpOptionValue) {
40 if (dump_mask & eDumpOptionType)
41 strm.PutCString(" = ");
42
43 if (m_current_value) {
44 strm << '"' << m_current_value.GetPath().c_str() << '"';
45 }
46 }
47}
48
52 switch (op) {
54 Clear();
56 break;
57
60 if (value.size() > 0) {
61 value = value.trim("\"' \t");
62 m_value_was_set = true;
63 m_current_value.SetFile(value.str(), FileSpec::Style::native);
64 if (m_resolve)
66 m_data_sp.reset();
67 m_data_mod_time = llvm::sys::TimePoint<>();
69 } else {
70 error.SetErrorString("invalid value string");
71 }
72 break;
73
80 break;
81 }
82 return error;
83}
84
86 CompletionRequest &request) {
88 interpreter, m_completion_mask, request, nullptr);
89}
90
92 if (m_current_value) {
93 const auto file_mod_time = FileSystem::Instance().GetModificationTime(m_current_value);
94 if (m_data_sp && m_data_mod_time == file_mod_time)
95 return m_data_sp;
96 m_data_sp =
98 m_data_mod_time = file_mod_time;
99 }
100 return m_data_sp;
101}
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:56
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:174
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:367
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:87
An error handling class.
Definition: Status.h:44
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.
Definition: SBAttachInfo.h:14
VarSetOperationType
Settable state variable types.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:328