LLDB mainline
OptionValueFileSpecList.cpp
Go to the documentation of this file.
1//===-- OptionValueFileSpecList.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/Utility/Args.h"
12#include "lldb/Utility/Stream.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
18 Stream &strm, uint32_t dump_mask) {
19 std::lock_guard<std::recursive_mutex> lock(m_mutex);
20 if (dump_mask & eDumpOptionType)
21 strm.Printf("(%s)", GetTypeAsCString());
22 if (dump_mask & eDumpOptionValue) {
23 const bool one_line = dump_mask & eDumpOptionCommand;
24 const uint32_t size = m_current_value.GetSize();
25 if (dump_mask & eDumpOptionType)
26 strm.Printf(" =%s",
27 (m_current_value.GetSize() > 0 && !one_line) ? "\n" : "");
28 if (!one_line)
29 strm.IndentMore();
30 for (uint32_t i = 0; i < size; ++i) {
31 if (!one_line) {
32 strm.Indent();
33 strm.Printf("[%u]: ", i);
34 }
36 if (one_line)
37 strm << ' ';
38 }
39 if (!one_line)
40 strm.IndentLess();
41 }
42}
43
46 std::lock_guard<std::recursive_mutex> lock(m_mutex);
48 Args args(value.str());
49 const size_t argc = args.GetArgumentCount();
50
51 switch (op) {
53 Clear();
55 break;
56
58 if (argc > 1) {
59 uint32_t idx;
60 const uint32_t count = m_current_value.GetSize();
61 if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
63 "invalid file list index %s, index must be 0 through %u",
64 args.GetArgumentAtIndex(0), count);
65 } else {
66 for (size_t i = 1; i < argc; ++i, ++idx) {
67 FileSpec file(args.GetArgumentAtIndex(i));
68 if (idx < count)
69 m_current_value.Replace(idx, file);
70 else
72 }
74 }
75 } else {
77 "replace operation takes an array index followed by "
78 "one or more values");
79 }
80 break;
81
84 // Fall through to append case
85 [[fallthrough]];
87 if (argc > 0) {
88 m_value_was_set = true;
89 for (size_t i = 0; i < argc; ++i) {
90 FileSpec file(args.GetArgumentAtIndex(i));
92 }
94 } else {
96 "assign operation takes at least one file path argument");
97 }
98 break;
99
102 if (argc > 1) {
103 uint32_t idx;
104 const uint32_t count = m_current_value.GetSize();
105 if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
107 "invalid insert file list index %s, index must be 0 through %u",
108 args.GetArgumentAtIndex(0), count);
109 } else {
111 ++idx;
112 for (size_t i = 1; i < argc; ++i, ++idx) {
113 FileSpec file(args.GetArgumentAtIndex(i));
114 m_current_value.Insert(idx, file);
115 }
117 }
118 } else {
120 "insert operation takes an array index followed by "
121 "one or more values");
122 }
123 break;
124
126 if (argc > 0) {
127 std::vector<int> remove_indexes;
128 bool all_indexes_valid = true;
129 size_t i;
130 for (i = 0; all_indexes_valid && i < argc; ++i) {
131 int idx;
132 if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx))
133 all_indexes_valid = false;
134 else
135 remove_indexes.push_back(idx);
136 }
137
138 if (all_indexes_valid) {
139 size_t num_remove_indexes = remove_indexes.size();
140 if (num_remove_indexes) {
141 // Sort and then erase in reverse so indexes are always valid
142 llvm::sort(remove_indexes);
143 for (size_t j = num_remove_indexes - 1; j < num_remove_indexes; ++j) {
145 }
146 }
148 } else {
150 "invalid array index '%s', aborting remove operation",
151 args.GetArgumentAtIndex(i));
152 }
153 } else {
155 "remove operation takes one or more array index");
156 }
157 break;
158
161 break;
162 }
163 return error;
164}
165
167 std::lock_guard<std::recursive_mutex> lock(m_mutex);
168 return Cloneable::Clone();
169}
static llvm::raw_ostream & error(Stream &strm)
A command line argument class.
Definition: Args.h:33
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:120
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition: Args.cpp:273
std::shared_ptr< typename Base::TopmostBase > Clone() const override
Definition: Cloneable.h:44
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool Insert(size_t idx, const FileSpec &file)
Definition: FileSpecList.h:217
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
void Clear()
Clears the file list.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
size_t GetSize() const
Get the number of files in the file list.
bool Remove(size_t idx)
Definition: FileSpecList.h:236
bool Replace(size_t idx, const FileSpec &file)
Definition: FileSpecList.h:228
A file utility class.
Definition: FileSpec.h:56
void Dump(llvm::raw_ostream &s) const
Dump this object to a Stream.
Definition: FileSpec.cpp:325
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
lldb::OptionValueSP Clone() const 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:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
static Status FromErrorString(const char *str)
Definition: Status.h:141
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:401
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition: Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition: Stream.cpp:198
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition: Stream.cpp:195
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::OptionValue > OptionValueSP
Definition: lldb-forward.h:384