LLDB mainline
OptionValueFileColonLine.cpp
Go to the documentation of this file.
1//===-- OptionValueFileColonLine.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
14#include "lldb/Utility/Args.h"
15#include "lldb/Utility/State.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20// This is an OptionValue for parsing file:line:column specifications.
21// I set the completer to "source file" which isn't quite right, but we can
22// only usefully complete in the file name part of it so it should be good
23// enough.
25
31
33 Stream &strm, uint32_t dump_mask) {
34 if (dump_mask & eDumpOptionType)
35 strm.Printf("(%s)", GetTypeAsCString());
36 if (dump_mask & eDumpOptionValue) {
37 if (dump_mask & eDumpOptionType)
38 strm.PutCString(" = ");
39
40 if (m_file_spec)
41 strm << '"' << m_file_spec.GetPath().c_str() << '"';
43 strm.Printf(":%d", m_line_number);
45 strm.Printf(":%d", m_column_number);
46 }
47}
48
49llvm::json::Value
51 StreamString stream;
52 if (m_file_spec)
53 stream << '"' << m_file_spec.GetPath().c_str() << '"';
55 stream.Printf(":%d", m_line_number);
57 stream.Printf(":%d", m_column_number);
58
59 return llvm::json::Value(stream.GetString());
60}
61
65 switch (op) {
67 Clear();
69 break;
70
73 if (value.size() > 0) {
74 // This is in the form filename:linenumber:column.
75 // I wish we could use filename:linenumber.column, that would make the
76 // parsing unambiguous and so much easier...
77 // But clang & gcc both print the output with two : so we're stuck with
78 // the two colons. Practically, the only actual ambiguity this introduces
79 // is with files like "foo:10", which doesn't seem terribly likely.
80
81 // Providing the column is optional, so the input value might have one or
82 // two colons. First pick off the last colon separated piece.
83 // It has to be there, since the line number is required:
84 llvm::StringRef last_piece;
85 llvm::StringRef left_of_last_piece;
86
87 std::tie(left_of_last_piece, last_piece) = value.rsplit(':');
88 if (last_piece.empty()) {
90 "Line specifier must include file and "
91 "line: '%s'",
92 value.str().c_str());
93 return error;
94 }
95
96 // Now see if there's another colon and if so pull out the middle piece:
97 // Then check whether the middle piece is an integer. If it is, then it
98 // was the line number, and if it isn't we're going to assume that there
99 // was a colon in the filename (see note at the beginning of the function)
100 // and ignore it.
101 llvm::StringRef file_name;
102 llvm::StringRef middle_piece;
103
104 std::tie(file_name, middle_piece) = left_of_last_piece.rsplit(':');
105 if (middle_piece.empty() ||
106 !llvm::to_integer(middle_piece, m_line_number)) {
107 // The middle piece was empty or not an integer, so there were only two
108 // legit pieces; our original division was right. Reassign the file
109 // name and pull out the line number:
110 file_name = left_of_last_piece;
111 if (!llvm::to_integer(last_piece, m_line_number)) {
113 "Bad line number value '%s' in: '%s'", last_piece.str().c_str(),
114 value.str().c_str());
115 return error;
116 }
117 } else {
118 // There were three pieces, and we've got the line number. So now
119 // we just need to check the column number which was the last peice.
120 if (!llvm::to_integer(last_piece, m_column_number)) {
122 "Bad column value '%s' in: '%s'", last_piece.str().c_str(),
123 value.str().c_str());
124 return error;
125 }
126 }
127
128 m_value_was_set = true;
129 m_file_spec.SetFile(file_name, FileSpec::Style::native);
131 } else {
132 error = Status::FromErrorString("invalid value string");
133 }
134 break;
135
142 break;
143 }
144 return error;
145}
146
static llvm::raw_ostream & error(Stream &strm)
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
"lldb/Utility/ArgCompletionRequest.h"
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
void AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request) override
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
virtual const char * GetTypeAsCString() const
Definition OptionValue.h:89
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
llvm::StringRef GetString() const
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
#define LLDB_INVALID_LINE_NUMBER
#define LLDB_INVALID_COLUMN_NUMBER
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.