LLDB mainline
ClangREPL.cpp
Go to the documentation of this file.
1//===-- ClangREPL.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
9#include "ClangREPL.h"
10#include "lldb/Core/Debugger.h"
13
14using namespace lldb_private;
15
17
18char ClangREPL::ID;
19
21 : llvm::RTTIExtends<ClangREPL, REPL>(target), m_language(language),
22 m_implicit_expr_result_regex("\\$[0-9]+") {}
23
24ClangREPL::~ClangREPL() = default;
25
27 LanguageSet languages;
28 // FIXME: There isn't a way to ask CPlusPlusLanguage and ObjCLanguage for
29 // a list of languages they support.
41 &CreateInstance, languages);
42}
43
46}
47
49 lldb::LanguageType language,
50 Debugger *debugger, Target *target,
51 const char *repl_options) {
52 // Creating a dummy target if only a debugger is given isn't implemented yet.
53 if (!target) {
54 error = Status::FromErrorString("must have a target to create a REPL");
55 return nullptr;
56 }
57 lldb::REPLSP result = std::make_shared<ClangREPL>(language, *target);
58 target->SetREPL(language, result);
59 error = Status();
60 return result;
61}
62
64
66 static constexpr llvm::StringLiteral g_repl("repl.c");
67 return g_repl;
68}
69
70const char *ClangREPL::GetAutoIndentCharacters() { return " "; }
71
72bool ClangREPL::SourceIsComplete(const std::string &source) {
73 // FIXME: There isn't a good way to know if the input source is complete or
74 // not, so just say that every single REPL line is ready to be parsed.
75 return !source.empty();
76}
77
79 int cursor_position,
80 int tab_size) {
81 // FIXME: Not implemented.
83}
84
86
88 lldb::StreamFileSP &output_sp,
89 lldb::ValueObjectSP &valobj_sp,
90 ExpressionVariable *var) {
91 // If a ExpressionVariable was passed, check first if that variable is just
92 // an automatically created expression result. These variables are already
93 // printed by the REPL so this is done to prevent printing the variable twice.
94 if (var) {
96 return true;
97 }
98 if (llvm::Error error = valobj_sp->Dump(*output_sp))
99 *output_sp << "error: " << toString(std::move(error));
100
101 return true;
102}
103
104void ClangREPL::CompleteCode(const std::string &current_code,
105 CompletionRequest &request) {
106 // Not implemented.
107}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:32
Implements a Clang-based REPL for C languages on top of LLDB's REPL framework.
Definition: ClangREPL.h:17
ClangREPL(lldb::LanguageType language, Target &target)
Definition: ClangREPL.cpp:20
lldb::LanguageType GetLanguage() override
Definition: ClangREPL.cpp:85
static void Initialize()
Definition: ClangREPL.cpp:26
static void Terminate()
Definition: ClangREPL.cpp:44
const char * GetAutoIndentCharacters() override
Definition: ClangREPL.cpp:70
lldb_private::RegularExpression m_implicit_expr_result_regex
A regex matching the implicitly created LLDB result variables.
Definition: ClangREPL.h:62
static llvm::StringRef GetPluginNameStatic()
Definition: ClangREPL.h:34
static lldb::REPLSP CreateInstance(Status &error, lldb::LanguageType language, Debugger *debugger, Target *target, const char *repl_options)
Definition: ClangREPL.cpp:48
Status DoInitialization() override
Definition: ClangREPL.cpp:63
void CompleteCode(const std::string &current_code, CompletionRequest &request) override
Definition: ClangREPL.cpp:104
llvm::StringRef GetSourceFileBasename() override
Definition: ClangREPL.cpp:65
lldb::offset_t GetDesiredIndentation(const StringList &lines, int cursor_position, int tab_size) override
Definition: ClangREPL.cpp:78
bool SourceIsComplete(const std::string &source) override
Definition: ClangREPL.cpp:72
bool PrintOneVariable(Debugger &debugger, lldb::StreamFileSP &output_sp, lldb::ValueObjectSP &valobj_sp, ExpressionVariable *var=nullptr) override
Definition: ClangREPL.cpp:87
lldb::LanguageType m_language
The specific C language of this REPL.
Definition: ClangREPL.h:60
"lldb/Utility/ArgCompletionRequest.h"
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
A class to manage flag bits.
Definition: Debugger.h:80
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
An error handling class.
Definition: Status.h:115
static Status FromErrorString(const char *str)
Definition: Status.h:138
void SetREPL(lldb::LanguageType language, lldb::REPLSP repl_sp)
Definition: Target.cpp:350
#define LLDB_INVALID_OFFSET
Definition: lldb-defines.h:93
A class that represents a running process on the host machine.
const char * toString(AppleArm64ExceptionClass EC)
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
uint64_t offset_t
Definition: lldb-types.h:85
LanguageType
Programming language type.
@ eLanguageTypeC_plus_plus_14
ISO C++:2014.
@ eLanguageTypeC11
ISO C:2011.
@ eLanguageTypeC99
ISO C:1999.
@ eLanguageTypeC_plus_plus_03
ISO C++:2003.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeC_plus_plus_11
ISO C++:2011.
@ eLanguageTypeC89
ISO C:1989.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::StreamFile > StreamFileSP
Definition: lldb-forward.h:433
std::shared_ptr< lldb_private::REPL > REPLSP
Definition: lldb-forward.h:401
Definition: Debugger.h:54
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: Type.h:38
void Insert(lldb::LanguageType language)
Definition: TypeSystem.cpp:34