brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 8d4966d Raw
108 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Interpreter/OptionValueFileSpec.h"10 11#include "lldb/DataFormatters/FormatManager.h"12#include "lldb/Host/FileSystem.h"13#include "lldb/Interpreter/CommandCompletions.h"14#include "lldb/Interpreter/CommandInterpreter.h"15#include "lldb/Interpreter/OptionValue.h"16#include "lldb/Utility/Args.h"17#include "lldb/Utility/State.h"18 19using namespace lldb;20using namespace lldb_private;21 22OptionValueFileSpec::OptionValueFileSpec(bool resolve) : m_resolve(resolve) {}23 24OptionValueFileSpec::OptionValueFileSpec(const FileSpec &value, bool resolve)25    : m_current_value(value), m_default_value(value),26 27      m_resolve(resolve) {}28 29OptionValueFileSpec::OptionValueFileSpec(const FileSpec &current_value,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 36void OptionValueFileSpec::DumpValue(const ExecutionContext *exe_ctx,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 &&48        m_current_value != m_default_value && m_default_value) {49      DefaultValueFormat label(strm);50      strm << '"' << m_default_value.GetPath() << '"';51    }52  }53}54 55Status OptionValueFileSpec::SetValueFromString(llvm::StringRef value,56                                               VarSetOperationType op) {57  Status error;58  switch (op) {59  case eVarSetOperationClear:60    Clear();61    NotifyValueChanged();62    break;63 64  case eVarSetOperationReplace:65  case eVarSetOperationAssign: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)71        FileSystem::Instance().Resolve(m_current_value);72      m_data_sp.reset();73      m_data_mod_time = llvm::sys::TimePoint<>();74      NotifyValueChanged();75    } else {76      error = Status::FromErrorString("invalid value string");77    }78    break;79 80  case eVarSetOperationInsertBefore:81  case eVarSetOperationInsertAfter:82  case eVarSetOperationRemove:83  case eVarSetOperationAppend:84  case eVarSetOperationInvalid:85    error = OptionValue::SetValueFromString(value, op);86    break;87  }88  return error;89}90 91void OptionValueFileSpec::AutoComplete(CommandInterpreter &interpreter,92                                       CompletionRequest &request) {93  lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(94      interpreter, m_completion_mask, request, nullptr);95}96 97const lldb::DataBufferSP &OptionValueFileSpec::GetFileContents() {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 =103        FileSystem::Instance().CreateDataBuffer(m_current_value.GetPath());104    m_data_mod_time = file_mod_time;105  }106  return m_data_sp;107}108