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 
14 using namespace lldb_private;
15 
17 
19  : REPL(eKindClang, target), m_language(language),
20  m_implicit_expr_result_regex("\\$[0-9]+") {}
21 
23 
25  LanguageSet languages;
26  // FIXME: There isn't a way to ask CPlusPlusLanguage and ObjCLanguage for
27  // a list of languages they support.
39  &CreateInstance, languages);
40 }
41 
44 }
45 
47  lldb::LanguageType language,
48  Debugger *debugger, Target *target,
49  const char *repl_options) {
50  // Creating a dummy target if only a debugger is given isn't implemented yet.
51  if (!target) {
52  error.SetErrorString("must have a target to create a REPL");
53  return nullptr;
54  }
55  lldb::REPLSP result = std::make_shared<ClangREPL>(language, *target);
56  target->SetREPL(language, result);
57  error = Status();
58  return result;
59 }
60 
62 
64  return ConstString("repl.c");
65 }
66 
67 const char *ClangREPL::GetAutoIndentCharacters() { return " "; }
68 
70  // FIXME: There isn't a good way to know if the input source is complete or
71  // not, so just say that every single REPL line is ready to be parsed.
72  return !source.empty();
73 }
74 
76  int cursor_position,
77  int tab_size) {
78  // FIXME: Not implemented.
79  return LLDB_INVALID_OFFSET;
80 }
81 
83 
85  lldb::StreamFileSP &output_sp,
86  lldb::ValueObjectSP &valobj_sp,
87  ExpressionVariable *var) {
88  // If a ExpressionVariable was passed, check first if that variable is just
89  // an automatically created expression result. These variables are already
90  // printed by the REPL so this is done to prevent printing the variable twice.
91  if (var) {
93  return true;
94  }
95  valobj_sp->Dump(*output_sp);
96  return true;
97 }
98 
99 void ClangREPL::CompleteCode(const std::string &current_code,
100  CompletionRequest &request) {
101  // Not implemented.
102 }
lldb_private::ClangREPL::GetLanguage
lldb::LanguageType GetLanguage() override
Definition: ClangREPL.cpp:82
lldb_private::ClangREPL::Terminate
static void Terminate()
Definition: ClangREPL.cpp:42
ClangREPL.h
ExpressionVariable.h
lldb_private::REPL
Definition: REPL.h:21
lldb_private::ClangREPL::DoInitialization
Status DoInitialization() override
Definition: ClangREPL.cpp:61
lldb::eLanguageTypeC99
@ eLanguageTypeC99
ISO C:1999.
Definition: lldb-enumerations.h:449
lldb_private::ClangREPL::GetDesiredIndentation
lldb::offset_t GetDesiredIndentation(const StringList &lines, int cursor_position, int tab_size) override
Definition: ClangREPL.cpp:75
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::LanguageSet::Insert
void Insert(lldb::LanguageType language)
Definition: TypeSystem.cpp:33
Debugger.h
lldb_private::Target
Definition: Target.h:450
lldb_private::ClangREPL
Implements a Clang-based REPL for C languages on top of LLDB's REPL framework.
Definition: ClangREPL.h:17
lldb_private::ClangREPL::GetAutoIndentCharacters
const char * GetAutoIndentCharacters() override
Definition: ClangREPL.cpp:67
lldb::eLanguageTypeC_plus_plus_11
@ eLanguageTypeC_plus_plus_11
ISO C++:2011.
Definition: lldb-enumerations.h:465
lldb_private::PluginManager::RegisterPlugin
static bool RegisterPlugin(ConstString name, const char *description, ABICreateInstance create_callback)
Definition: PluginManager.cpp:288
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::eLanguageTypeC_plus_plus_03
@ eLanguageTypeC_plus_plus_03
ISO C++:2003.
Definition: lldb-enumerations.h:464
lldb_private::PluginManager::UnregisterPlugin
static bool UnregisterPlugin(ABICreateInstance create_callback)
Definition: PluginManager.cpp:293
LLDB_INVALID_OFFSET
#define LLDB_INVALID_OFFSET
Definition: lldb-defines.h:97
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
lldb_private::ClangREPL::SourceIsComplete
bool SourceIsComplete(const std::string &source) override
Definition: ClangREPL.cpp:69
lldb_private::ClangREPL::~ClangREPL
~ClangREPL() override
Definition: ClangREPL.cpp:22
lldb_private::ClangREPL::Initialize
static void Initialize()
Definition: ClangREPL.cpp:24
lldb_private::ClangREPL::GetSourceFileBasename
ConstString GetSourceFileBasename() override
Definition: ClangREPL.cpp:63
lldb_private::ClangREPL::m_implicit_expr_result_regex
lldb_private::RegularExpression m_implicit_expr_result_regex
A regex matching the implicitly created LLDB result variables.
Definition: ClangREPL.h:61
lldb_private::StringList
Definition: StringList.h:25
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ClangREPL::m_language
lldb::LanguageType m_language
The specific C language of this REPL.
Definition: ClangREPL.h:59
lldb::eLanguageTypeC89
@ eLanguageTypeC89
ISO C:1989.
Definition: lldb-enumerations.h:438
lldb::eLanguageTypeC11
@ eLanguageTypeC11
ISO C:2011.
Definition: lldb-enumerations.h:468
lldb_private::Debugger
Definition: Debugger.h:70
lldb::eLanguageTypeObjC
@ eLanguageTypeObjC
Objective-C.
Definition: lldb-enumerations.h:453
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb::eLanguageTypeObjC_plus_plus
@ eLanguageTypeObjC_plus_plus
Objective-C++.
Definition: lldb-enumerations.h:454
lldb_private::ExpressionVariable
Definition: ExpressionVariable.h:23
lldb_private::Status
Definition: Status.h:44
lldb_private::Target::SetREPL
void SetREPL(lldb::LanguageType language, lldb::REPLSP repl_sp)
Definition: Target.cpp:264
lldb_private::ClangREPL::PrintOneVariable
bool PrintOneVariable(Debugger &debugger, lldb::StreamFileSP &output_sp, lldb::ValueObjectSP &valobj_sp, ExpressionVariable *var=nullptr) override
Definition: ClangREPL.cpp:84
lldb_private::ClangREPL::CompleteCode
void CompleteCode(const std::string &current_code, CompletionRequest &request) override
Definition: ClangREPL.cpp:99
lldb::eLanguageTypeC_plus_plus_14
@ eLanguageTypeC_plus_plus_14
ISO C++:2014.
Definition: lldb-enumerations.h:472
lldb_private::ClangREPL::GetPluginNameStatic
static lldb_private::ConstString GetPluginNameStatic()
Definition: ClangREPL.h:31
PluginManager.h
lldb::eLanguageTypeC
@ eLanguageTypeC
Non-standardized C, such as K&R.
Definition: lldb-enumerations.h:439
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::RegularExpression::Execute
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...
Definition: RegularExpression.cpp:23
lldb_private::LanguageSet
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: TypeSystem.h:40
LLDB_PLUGIN_DEFINE
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
lldb
Definition: SBAddress.h:15
lldb_private::ExpressionVariable::GetName
ConstString GetName()
Definition: ExpressionVariable.h:37
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::ClangREPL::CreateInstance
static lldb::REPLSP CreateInstance(Status &error, lldb::LanguageType language, Debugger *debugger, Target *target, const char *repl_options)
Definition: ClangREPL.cpp:46
lldb::eLanguageTypeC_plus_plus
@ eLanguageTypeC_plus_plus
ISO C++:1998.
Definition: lldb-enumerations.h:441