LLDB mainline
OptionValueString.cpp
Go to the documentation of this file.
1//===-- OptionValueString.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/Utility/Args.h"
13#include "lldb/Utility/Stream.h"
14
15using namespace lldb;
16using namespace lldb_private;
17
19 uint32_t dump_mask) {
20 if (dump_mask & eDumpOptionType)
21 strm.Printf("(%s)", GetTypeAsCString());
22 if (dump_mask & eDumpOptionValue) {
23 if (dump_mask & eDumpOptionType)
24 strm.PutCString(" = ");
25 if (!m_current_value.empty() || m_value_was_set) {
27 std::string expanded_escape_value;
29 expanded_escape_value);
30 if (dump_mask & eDumpOptionRaw)
31 strm.Printf("%s", expanded_escape_value.c_str());
32 else
33 strm.Printf("\"%s\"", expanded_escape_value.c_str());
34 } else {
35 if (dump_mask & eDumpOptionRaw)
36 strm.Printf("%s", m_current_value.c_str());
37 else
38 strm.Printf("\"%s\"", m_current_value.c_str());
39 }
40 }
41 }
42}
43
47
48 std::string value_str = value.str();
49 value = value.trim();
50 if (value.size() > 0) {
51 switch (value.front()) {
52 case '"':
53 case '\'': {
54 if (value.size() <= 1 || value.back() != value.front()) {
55 error = Status::FromErrorString("mismatched quotes");
56 return error;
57 }
58 value = value.drop_front().drop_back();
59 } break;
60 }
61 value_str = value.str();
62 }
63
64 switch (op) {
69 if (m_validator) {
70 error = m_validator(value_str.c_str(), m_validator_baton);
71 if (error.Fail())
72 return error;
73 }
75 break;
76
78 std::string new_value(m_current_value);
79 if (value.size() > 0) {
81 std::string str;
82 Args::EncodeEscapeSequences(value_str.c_str(), str);
83 new_value.append(str);
84 } else
85 new_value.append(std::string(value));
86 }
87 if (m_validator) {
88 error = m_validator(new_value.c_str(), m_validator_baton);
89 if (error.Fail())
90 return error;
91 }
92 m_current_value.assign(new_value);
94 } break;
95
97 Clear();
99 break;
100
103 if (m_validator) {
104 error = m_validator(value_str.c_str(), m_validator_baton);
105 if (error.Fail())
106 return error;
107 }
108 m_value_was_set = true;
111 } else {
112 SetCurrentValue(value_str);
113 }
115 break;
116 }
117 return error;
118}
119
121 if (m_validator) {
122 Status error(m_validator(value.str().c_str(), m_validator_baton));
123 if (error.Fail())
124 return error;
125 }
126 m_current_value.assign(std::string(value));
127 return Status();
128}
129
131 if (value && value[0]) {
132 if (m_validator) {
133 std::string new_value(m_current_value);
134 new_value.append(value);
136 if (error.Fail())
137 return error;
138 m_current_value.assign(new_value);
139 } else
140 m_current_value.append(value);
141 }
142 return Status();
143}
static llvm::raw_ostream & error(Stream &strm)
static void ExpandEscapedCharacters(const char *src, std::string &dst)
ExpandEscapeSequences will change a string of possibly non-printable characters and expand them into ...
Definition: Args.cpp:562
static void EncodeEscapeSequences(const char *src, std::string &dst)
EncodeEscapeSequences will change the textual representation of common escape sequences like "\n" (tw...
Definition: Args.cpp:463
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
Status AppendToCurrentValue(const char *value)
Status SetCurrentValue(llvm::StringRef value)
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
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:115
static Status FromErrorString(const char *str)
Definition: Status.h:138
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.
VarSetOperationType
Settable state variable types.
Definition: SBAddress.h:15