LLDB mainline
OptionValueFormatEntity.cpp
Go to the documentation of this file.
1//===-- OptionValueFormatEntity.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
11#include "lldb/Core/Module.h"
13#include "lldb/Utility/Stream.h"
15using namespace lldb;
16using namespace lldb_private;
17
19 if (default_format && default_format[0]) {
20 llvm::StringRef default_format_str(default_format);
21 Status error = FormatEntity::Parse(default_format_str, m_default_entry);
22 if (error.Success()) {
23 m_default_format = default_format;
24 m_current_format = default_format;
26 }
27 }
28}
29
33 m_value_was_set = false;
34}
35
36static void EscapeBackticks(llvm::StringRef str, std::string &dst) {
37 dst.clear();
38 dst.reserve(str.size());
39
40 for (size_t i = 0, e = str.size(); i != e; ++i) {
41 char c = str[i];
42 if (c == '`') {
43 if (i == 0 || str[i - 1] != '\\')
44 dst += '\\';
45 }
46 dst += c;
47 }
48}
49
51 Stream &strm, uint32_t dump_mask) {
52 if (dump_mask & eDumpOptionType)
53 strm.Printf("(%s)", GetTypeAsCString());
54 if (dump_mask & eDumpOptionValue) {
55 if (dump_mask & eDumpOptionType)
56 strm.PutCString(" = ");
57 std::string escaped;
59 strm << '"' << escaped << '"';
60 }
61}
62
63llvm::json::Value
65 std::string escaped;
67 return escaped;
68}
69
73 switch (op) {
75 Clear();
77 break;
78
81 // Check if the string starts with a quote character after removing leading
82 // and trailing spaces. If it does start with a quote character, make sure
83 // it ends with the same quote character and remove the quotes before we
84 // parse the format string. If the string doesn't start with a quote, leave
85 // the string alone and parse as is.
86 llvm::StringRef trimmed_value_str = value_str.trim();
87 if (!trimmed_value_str.empty()) {
88 const char first_char = trimmed_value_str[0];
89 if (first_char == '"' || first_char == '\'') {
90 const size_t trimmed_len = trimmed_value_str.size();
91 if (trimmed_len == 1 || value_str[trimmed_len - 1] != first_char) {
92 error.SetErrorString("mismatched quotes");
93 return error;
94 }
95 value_str = trimmed_value_str.substr(1, trimmed_len - 2);
96 }
97 }
99 error = FormatEntity::Parse(value_str, entry);
100 if (error.Success()) {
101 m_current_entry = std::move(entry);
102 m_current_format = std::string(value_str);
103 m_value_was_set = true;
105 }
106 } break;
107
113 error = OptionValue::SetValueFromString(value_str, op);
114 break;
115 }
116 return error;
117}
118
120 CompletionRequest &request) {
122}
static llvm::raw_ostream & error(Stream &strm)
static void EscapeBackticks(llvm::StringRef str, std::string &dst)
"lldb/Utility/ArgCompletionRequest.h"
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
static void AutoComplete(lldb_private::CompletionRequest &request)
static Status Parse(const llvm::StringRef &format, Entry &entry)
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
void AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request) override
OptionValueFormatEntity(const char *default_format)
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
virtual const char * GetTypeAsCString() const
Definition: OptionValue.h:77
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:107
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.
Definition: SBAddress.h:15