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 
12 #include "lldb/Host/FileSystem.h"
15 #include "lldb/Utility/Args.h"
16 #include "lldb/Utility/State.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 OptionValueFileSpec::OptionValueFileSpec(bool resolve) : m_resolve(resolve) {}
22 
24  : m_current_value(value), m_default_value(value),
25  m_completion_mask(CommandCompletions::eDiskFileCompletion),
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  m_completion_mask(CommandCompletions::eDiskFileCompletion),
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 
51  Status error;
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 
91 const lldb::DataBufferSP &OptionValueFileSpec::GetFileContents() {
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 }
lldb_private::eVarSetOperationInsertBefore
@ eVarSetOperationInsertBefore
Definition: lldb-private-enumerations.h:85
lldb_private::eVarSetOperationReplace
@ eVarSetOperationReplace
Definition: lldb-private-enumerations.h:84
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
FileSystem.h
lldb_private::OptionValueFileSpec::m_completion_mask
uint32_t m_completion_mask
Definition: OptionValueFileSpec.h:78
FormatManager.h
lldb_private::OptionValueFileSpec::m_current_value
FileSpec m_current_value
Definition: OptionValueFileSpec.h:74
lldb_private::Stream
Definition: Stream.h:28
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::VarSetOperationType
VarSetOperationType
Settable state variable types.
Definition: lldb-private-enumerations.h:83
lldb_private::CommandCompletions
Definition: CommandCompletions.h:24
lldb_private::OptionValue::NotifyValueChanged
void NotifyValueChanged()
Definition: OptionValue.h:318
Args.h
lldb_private::OptionValue::SetValueFromString
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
Definition: OptionValue.cpp:579
lldb_private::OptionValueFileSpec::AutoComplete
void AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request) override
Definition: OptionValueFileSpec.cpp:85
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
Definition: CommandCompletions.cpp:49
lldb_private::eVarSetOperationAppend
@ eVarSetOperationAppend
Definition: lldb-private-enumerations.h:88
lldb_private::FileSystem::CreateDataBuffer
std::shared_ptr< DataBufferLLVM > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
Definition: common/FileSystem.cpp:297
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::FileSystem::GetModificationTime
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
Definition: common/FileSystem.cpp:116
lldb_private::OptionValue::eDumpOptionValue
@ eDumpOptionValue
Definition: OptionValue.h:53
lldb_private::FileSystem::Resolve
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
Definition: common/FileSystem.cpp:255
lldb_private::OptionValue::GetTypeAsCString
virtual const char * GetTypeAsCString() const
Definition: OptionValue.h:76
lldb_private::Status
Definition: Status.h:44
lldb_private::OptionValueFileSpec::m_data_sp
lldb::DataBufferSP m_data_sp
Definition: OptionValueFileSpec.h:76
uint32_t
lldb_private::OptionValue::m_value_was_set
bool m_value_was_set
Definition: OptionValue.h:332
lldb_private::OptionValue::eDumpOptionType
@ eDumpOptionType
Definition: OptionValue.h:52
lldb_private::OptionValueFileSpec::m_data_mod_time
llvm::sys::TimePoint m_data_mod_time
Definition: OptionValueFileSpec.h:77
lldb_private::OptionValueFileSpec::GetFileContents
const lldb::DataBufferSP & GetFileContents()
Definition: OptionValueFileSpec.cpp:91
lldb_private::eVarSetOperationRemove
@ eVarSetOperationRemove
Definition: lldb-private-enumerations.h:87
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:45
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::OptionValueFileSpec::OptionValueFileSpec
OptionValueFileSpec(bool resolve=true)
Definition: OptionValueFileSpec.cpp:21
lldb_private::OptionValueFileSpec::SetValueFromString
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
Definition: OptionValueFileSpec.cpp:49
CommandInterpreter.h
State.h
lldb_private::eVarSetOperationInvalid
@ eVarSetOperationInvalid
Definition: lldb-private-enumerations.h:91
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb_private::OptionValueFileSpec::Clear
void Clear() override
Definition: OptionValueFileSpec.h:42
lldb_private::FileSpec::SetFile
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:174
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:348
lldb_private::OptionValueFileSpec::DumpValue
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
Definition: OptionValueFileSpec.cpp:35
OptionValueFileSpec.h
lldb
Definition: SBAddress.h:15
lldb_private::eVarSetOperationClear
@ eVarSetOperationClear
Definition: lldb-private-enumerations.h:89
CommandCompletions.h
lldb_private::OptionValueFileSpec::m_resolve
bool m_resolve
Definition: OptionValueFileSpec.h:79
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::eVarSetOperationInsertAfter
@ eVarSetOperationInsertAfter
Definition: lldb-private-enumerations.h:86
lldb_private::eVarSetOperationAssign
@ eVarSetOperationAssign
Definition: lldb-private-enumerations.h:90