#include "lldb/Interpreter/OptionValueFileColonLine.h"
#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/State.h"
using namespace lldb;
using namespace lldb_private;
OptionValueFileColonLine::OptionValueFileColonLine() = default;
OptionValueFileColonLine::OptionValueFileColonLine(llvm::StringRef input)
{
SetValueFromString(input, eVarSetOperationAssign);
}
void OptionValueFileColonLine::DumpValue(const ExecutionContext *exe_ctx,
Stream &strm, uint32_t dump_mask) {
if (dump_mask & eDumpOptionType)
strm.Printf("(%s)", GetTypeAsCString());
if (dump_mask & eDumpOptionValue) {
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
if (m_file_spec)
strm << '"' << m_file_spec.GetPath().c_str() << '"';
if (m_line_number != LLDB_INVALID_LINE_NUMBER)
strm.Printf(":%d", m_line_number);
if (m_column_number != LLDB_INVALID_COLUMN_NUMBER)
strm.Printf(":%d", m_column_number);
}
}
Status OptionValueFileColonLine::SetValueFromString(llvm::StringRef value,
VarSetOperationType op) {
Status error;
switch (op) {
case eVarSetOperationClear:
Clear();
NotifyValueChanged();
break;
case eVarSetOperationReplace:
case eVarSetOperationAssign:
if (value.size() > 0) {
llvm::StringRef last_piece;
llvm::StringRef left_of_last_piece;
std::tie(left_of_last_piece, last_piece) = value.rsplit(':');
if (last_piece.empty()) {
error.SetErrorStringWithFormat("Line specifier must include file and "
"line: '%s'",
value.str().c_str());
return error;
}
llvm::StringRef file_name;
llvm::StringRef middle_piece;
std::tie(file_name, middle_piece) = left_of_last_piece.rsplit(':');
if (middle_piece.empty() ||
!llvm::to_integer(middle_piece, m_line_number)) {
file_name = left_of_last_piece;
if (!llvm::to_integer(last_piece, m_line_number)) {
error.SetErrorStringWithFormat("Bad line number value '%s' in: '%s'",
last_piece.str().c_str(),
value.str().c_str());
return error;
}
} else {
if (!llvm::to_integer(last_piece, m_column_number)) {
error.SetErrorStringWithFormat("Bad column value '%s' in: '%s'",
last_piece.str().c_str(),
value.str().c_str());
return error;
}
}
m_value_was_set = true;
m_file_spec.SetFile(file_name, FileSpec::Style::native);
NotifyValueChanged();
} else {
error.SetErrorString("invalid value string");
}
break;
case eVarSetOperationInsertBefore:
case eVarSetOperationInsertAfter:
case eVarSetOperationRemove:
case eVarSetOperationAppend:
case eVarSetOperationInvalid:
error = OptionValue::SetValueFromString(value, op);
break;
}
return error;
}
void OptionValueFileColonLine::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, m_completion_mask, request, nullptr);
}