9 #include "clang/AST/ASTContext.h"
10 #include "clang/AST/ASTDiagnostic.h"
11 #include "clang/AST/ExternalASTSource.h"
12 #include "clang/AST/PrettyPrinter.h"
13 #include "clang/Basic/Builtins.h"
14 #include "clang/Basic/DiagnosticIDs.h"
15 #include "clang/Basic/SourceLocation.h"
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/Version.h"
18 #include "clang/CodeGen/CodeGenAction.h"
19 #include "clang/CodeGen/ModuleBuilder.h"
20 #include "clang/Edit/Commit.h"
21 #include "clang/Edit/EditedSource.h"
22 #include "clang/Edit/EditsReceiver.h"
23 #include "clang/Frontend/CompilerInstance.h"
24 #include "clang/Frontend/CompilerInvocation.h"
25 #include "clang/Frontend/FrontendActions.h"
26 #include "clang/Frontend/FrontendDiagnostic.h"
27 #include "clang/Frontend/FrontendPluginRegistry.h"
28 #include "clang/Frontend/TextDiagnosticBuffer.h"
29 #include "clang/Frontend/TextDiagnosticPrinter.h"
30 #include "clang/Lex/Preprocessor.h"
31 #include "clang/Parse/ParseAST.h"
32 #include "clang/Rewrite/Core/Rewriter.h"
33 #include "clang/Rewrite/Frontend/FrontendActions.h"
34 #include "clang/Sema/CodeCompleteConsumer.h"
35 #include "clang/Sema/Sema.h"
36 #include "clang/Sema/SemaConsumer.h"
38 #include "llvm/ADT/StringRef.h"
39 #include "llvm/ExecutionEngine/ExecutionEngine.h"
40 #include "llvm/Support/CrashRecoveryContext.h"
41 #include "llvm/Support/Debug.h"
42 #include "llvm/Support/FileSystem.h"
43 #include "llvm/Support/TargetSelect.h"
45 #include "llvm/IR/LLVMContext.h"
46 #include "llvm/IR/Module.h"
47 #include "llvm/Support/DynamicLibrary.h"
48 #include "llvm/Support/ErrorHandling.h"
49 #include "llvm/Support/Host.h"
50 #include "llvm/Support/MemoryBuffer.h"
51 #include "llvm/Support/Signals.h"
100 using namespace clang;
101 using namespace llvm;
113 bool m_has_errors =
false;
118 clang::SourceManager &source_mgr)
119 : m_decl_vendor(decl_vendor), m_persistent_vars(persistent_vars),
120 m_source_mgr(source_mgr) {}
122 void moduleImport(SourceLocation import_location, clang::ModuleIdPath path,
123 const clang::Module * )
override {
126 llvm::StringRef filename =
127 m_source_mgr.getPresumedLoc(import_location).getFilename();
128 if (filename == ClangExpressionSourceCode::g_prefix_file_name)
133 for (
const std::pair<IdentifierInfo *, SourceLocation> &component : path)
139 if (!m_decl_vendor.
AddModule(module, &exported_modules, m_error_stream))
152 for (
auto &fix_it : Info.getFixItHints()) {
162 DiagnosticOptions *options =
new DiagnosticOptions(opts);
163 options->ShowPresumedLoc =
true;
164 options->ShowLevel =
false;
165 m_os = std::make_shared<llvm::raw_string_ostream>(m_output);
167 std::make_shared<clang::TextDiagnosticPrinter>(*m_os, options);
178 if (m_manager->Diagnostics().empty())
186 const clang::Diagnostic &Info)
override {
195 llvm::SmallVector<char, 32> diag_str;
196 Info.FormatDiagnostic(diag_str);
197 diag_str.push_back(
'\0');
198 const char *plain_diag = diag_str.data();
199 LLDB_LOG(log,
"Received diagnostic outside parsing: {0}", plain_diag);
205 DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
209 m_passthrough->HandleDiagnostic(DiagLevel, Info);
213 bool make_new_diagnostic =
true;
216 case DiagnosticsEngine::Level::Fatal:
220 case DiagnosticsEngine::Level::Warning:
223 case DiagnosticsEngine::Level::Remark:
224 case DiagnosticsEngine::Level::Ignored:
227 case DiagnosticsEngine::Level::Note:
228 m_manager->AppendMessageToDiagnostic(m_output);
229 make_new_diagnostic =
false;
235 auto *clang_diag = MaybeGetLastClangDiag();
240 if (!clang_diag || clang_diag->HasFixIts())
248 if (make_new_diagnostic) {
254 auto new_diagnostic = std::make_unique<ClangDiagnostic>(
255 stripped_output, severity, Info.getID());
264 m_manager->AddDiagnostic(std::move(new_diagnostic));
269 m_passthrough->BeginSourceFile(LO, PP);
278 std::shared_ptr<llvm::raw_string_ostream>
m_os;
285 lldb::TargetSP target_sp) {
288 HeaderSearchOptions &search_opts = compiler->getHeaderSearchOpts();
291 search_opts.AddPath(dir, frontend::System,
false,
true);
292 LLDB_LOG(log,
"Added user include dir: {0}", dir);
295 llvm::SmallString<128> module_cache;
296 const auto &props = ModuleList::GetGlobalModuleListProperties();
297 props.GetClangModulesCachePath().GetPath(module_cache);
298 search_opts.ModuleCachePath =
std::string(module_cache.str());
299 LLDB_LOG(log,
"Using module cache path: {0}", module_cache.c_str());
303 search_opts.ImplicitModuleMaps =
true;
311 if (token ==
"using")
314 if (token ==
"__null")
317 LangOptions cpp_lang_opts;
318 cpp_lang_opts.CPlusPlus =
true;
319 cpp_lang_opts.CPlusPlus11 =
true;
320 cpp_lang_opts.CPlusPlus20 =
true;
322 clang::IdentifierInfo &ii = idents.get(token);
325 if (!ii.isCPlusPlusKeyword(cpp_lang_opts))
328 if (ii.getTokenID() == clang::tok::identifier)
332 ii.revertTokenIDToIdentifier();
337 #define KEYWORD(NAME, FLAGS) RemoveCppKeyword(idents, llvm::StringRef(#NAME));
338 #include "clang/Basic/TokenKinds.def"
344 const std::vector<const char *> groupsToIgnore = {
347 "unused-getter-return-value",
349 for (
const char *group : groupsToIgnore) {
350 compiler.getDiagnostics().setSeverityForGroup(
351 clang::diag::Flavor::WarningOrError, group,
352 clang::diag::Severity::Ignored, SourceLocation());
360 ClangExpressionParser::ClangExpressionParser(
365 m_pp_callbacks(nullptr),
367 m_filename(std::move(filename)) {
379 "Can't make an expression parser with a null scope.");
383 lldb::TargetSP target_sp;
387 "Can't make an expression parser with a null target.");
392 m_compiler = std::make_unique<CompilerInstance>();
399 std::make_shared<ModuleDependencyCollectorAdaptor>(
400 fp.GetFileCollector()));
401 DependencyOutputOptions &opts =
m_compiler->getDependencyOutputOpts();
402 opts.IncludeSystemHeaders =
true;
403 opts.IncludeModuleFiles =
true;
411 bool overridden_target_opts =
false;
416 target_arch = target_sp->GetArchitecture();
418 const auto target_machine = target_arch.
GetMachine();
429 frame_lang = frame_sp->GetLanguage();
432 lang_rt = process_sp->GetLanguageRuntime(frame_lang);
433 LLDB_LOGF(log,
"Frame has language of type %s",
442 LLDB_LOGF(log,
"Using %s as the target triple",
451 m_compiler->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple();
452 LLDB_LOGF(log,
"Using default target triple of %s",
457 if (
m_compiler->getTargetOpts().Triple.find(
"arm64") == std::string::npos &&
458 m_compiler->getTargetOpts().Triple.find(
"arm") != std::string::npos &&
459 m_compiler->getTargetOpts().Triple.find(
"ios") != std::string::npos) {
463 if (target_machine == llvm::Triple::x86 ||
464 target_machine == llvm::Triple::x86_64) {
465 m_compiler->getTargetOpts().Features.push_back(
"+sse");
466 m_compiler->getTargetOpts().Features.push_back(
"+sse2");
486 if (
auto *renderscript_rt =
487 llvm::dyn_cast_or_null<RenderScriptRuntime>(lang_rt))
488 overridden_target_opts =
489 renderscript_rt->GetOverrideExprOptions(
m_compiler->getTargetOpts());
491 if (overridden_target_opts)
494 log,
"Using overridden target options for the expression evaluation");
497 LLDB_LOGV(log,
"Triple: '{0}'", opts.Triple);
499 LLDB_LOGV(log,
"FPMath: '{0}'", opts.FPMath);
501 LLDB_LOGV(log,
"LinkerVersion: '{0}'", opts.LinkerVersion);
510 m_compiler->getDiagnostics().setErrorLimit(target_sp->GetExprErrorLimit());
512 auto target_info = TargetInfo::CreateTargetInfo(
515 LLDB_LOGF(log,
"Using SIMD alignment: %d",
516 target_info->getSimdDefaultAlign());
517 LLDB_LOGF(log,
"Target datalayout string: '%s'",
518 target_info->getDataLayoutString());
519 LLDB_LOGF(log,
"Target ABI: '%s'", target_info->getABI().str().c_str());
520 LLDB_LOGF(log,
"Target vector alignment: %d",
521 target_info->getMaxVectorAlign());
529 LangOptions &lang_opts =
m_compiler->getLangOpts();
541 lang_opts.CPlusPlus =
true;
544 lang_opts.ObjC =
true;
547 lang_opts.CPlusPlus =
true;
555 lang_opts.CPlusPlus11 =
true;
560 lang_opts.CPlusPlus11 =
true;
561 m_compiler->getHeaderSearchOpts().UseLibcxx =
true;
564 lang_opts.CPlusPlus =
true;
572 lang_opts.ObjC =
true;
573 lang_opts.CPlusPlus =
true;
574 lang_opts.CPlusPlus11 =
true;
575 m_compiler->getHeaderSearchOpts().UseLibcxx =
true;
579 lang_opts.Bool =
true;
580 lang_opts.WChar =
true;
581 lang_opts.Blocks =
true;
582 lang_opts.DebuggerSupport =
585 lang_opts.DebuggerCastResultToId =
true;
593 lang_opts.SpellChecking =
false;
595 auto *clang_expr = dyn_cast<ClangUserExpression>(&
m_expr);
596 if (clang_expr && clang_expr->DidImportCxxModules()) {
597 LLDB_LOG(log,
"Adding lang options for importing C++ modules");
599 lang_opts.Modules =
true;
601 lang_opts.ImplicitModules =
true;
603 lang_opts.ModulesLocalVisibility =
false;
607 lang_opts.ObjC =
true;
611 lang_opts.GNUMode =
true;
612 lang_opts.GNUKeywords =
true;
613 lang_opts.DoubleSquareBracketAttributes =
true;
614 lang_opts.CPlusPlus11 =
true;
617 lang_opts.GNUCVersion = 40201;
623 if (process_sp && lang_opts.ObjC) {
625 if (runtime->GetRuntimeVersion() ==
627 lang_opts.ObjCRuntime.set(ObjCRuntime::MacOSX, VersionTuple(10, 7));
629 lang_opts.ObjCRuntime.set(ObjCRuntime::FragileMacOSX,
630 VersionTuple(10, 7));
632 if (runtime->HasNewLiteralsAndIndexing())
633 lang_opts.DebuggerObjCLiteral =
true;
637 lang_opts.ThreadsafeStatics =
false;
638 lang_opts.AccessControl =
false;
639 lang_opts.DollarIdents =
true;
643 lang_opts.NoBuiltin =
true;
646 m_compiler->getCodeGenOpts().EmitDeclMetadata =
true;
647 m_compiler->getCodeGenOpts().InstrumentFunctions =
false;
649 CodeGenOptions::FramePointerKind::All);
650 if (generate_debug_info)
651 m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
653 m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::NoDebugInfo);
668 m_compiler->getDiagnostics().getDiagnosticOptions());
669 m_compiler->getDiagnostics().setClient(diag_mgr);
692 if (
auto *clang_persistent_vars = llvm::cast<ClangPersistentVariables>(
693 target_sp->GetPersistentExpressionStateForLanguage(
695 if (std::shared_ptr<ClangModulesDeclVendor> decl_vendor =
696 clang_persistent_vars->GetClangModulesDeclVendor()) {
697 std::unique_ptr<PPCallbacks> pp_callbacks(
702 m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks));
710 auto &builtin_context = PP.getBuiltinInfo();
711 builtin_context.initializeBuiltins(PP.getIdentifierTable(),
715 clang::ASTContext &ast_context =
m_compiler->getASTContext();
718 "Expression ASTContext for '" +
m_filename +
"'", ast_context);
738 class CodeComplete :
public CodeCompleteConsumer {
739 CodeCompletionTUInfo m_info;
742 unsigned m_position = 0;
745 clang::PrintingPolicy m_desc_policy;
747 struct CompletionWithPriority {
755 bool operator<(
const CompletionWithPriority &o)
const {
757 if (Priority != o.Priority)
758 return Priority > o.Priority;
761 return completion.
GetUniqueKey() < o.completion.GetUniqueKey();
768 std::vector<CompletionWithPriority> m_completions;
775 static bool IsIdChar(
char c) {
776 return c ==
'_' || std::isalnum(c) || c ==
'$';
781 static bool IsTokenSeparator(
char c) {
return c ==
' ' || c ==
'\t'; }
786 StringRef dropUnrelatedFrontTokens(StringRef cmd)
const {
792 if (IsTokenSeparator(cmd.back()))
797 StringRef to_remove = cmd;
798 while (!to_remove.empty() && !IsTokenSeparator(to_remove.back())) {
799 to_remove = to_remove.drop_back();
801 cmd = cmd.drop_front(to_remove.size());
807 StringRef removeLastToken(StringRef cmd)
const {
808 while (!cmd.empty() && IsIdChar(cmd.back())) {
809 cmd = cmd.drop_back();
817 std::string mergeCompletion(StringRef existing,
unsigned pos,
818 StringRef completion)
const {
819 StringRef existing_command = existing.substr(0, pos);
822 existing_command = removeLastToken(existing_command);
826 existing_command = dropUnrelatedFrontTokens(existing_command);
827 return existing_command.str() + completion.str();
840 CodeComplete(clang::LangOptions ops,
std::string expr,
unsigned position)
841 : CodeCompleteConsumer(CodeCompleteOptions()),
842 m_info(std::make_shared<GlobalCodeCompletionAllocator>()), m_expr(expr),
843 m_position(position), m_desc_policy(ops) {
847 m_desc_policy.SuppressScope =
true;
848 m_desc_policy.SuppressTagKeyword =
true;
849 m_desc_policy.FullyQualifiedName =
false;
850 m_desc_policy.TerseOutput =
true;
851 m_desc_policy.IncludeNewlines =
false;
852 m_desc_policy.UseVoidForZeroParams =
false;
853 m_desc_policy.Bool =
true;
858 bool isResultFilteredOut(StringRef Filter,
859 CodeCompletionResult Result)
override {
861 switch (Result.Kind) {
862 case CodeCompletionResult::RK_Declaration:
864 Result.Declaration->getIdentifier() &&
865 Result.Declaration->getIdentifier()->getName().startswith(Filter));
866 case CodeCompletionResult::RK_Keyword:
867 return !StringRef(Result.Keyword).startswith(Filter);
868 case CodeCompletionResult::RK_Macro:
869 return !Result.Macro->getName().startswith(Filter);
870 case CodeCompletionResult::RK_Pattern:
871 return !StringRef(Result.Pattern->getAsString()).startswith(Filter);
876 assert(
false &&
"Unknown completion result type?");
891 llvm::Optional<CompletionWithPriority>
892 getCompletionForResult(
const CodeCompletionResult &R)
const {
897 case CodeCompletionResult::RK_Declaration: {
898 const NamedDecl *D = R.Declaration;
899 ToInsert = R.Declaration->getNameAsString();
903 if (
const FunctionDecl *F = dyn_cast<FunctionDecl>(D)) {
904 if (F->getNumParams() == 0)
908 raw_string_ostream
OS(Description);
909 F->print(OS, m_desc_policy,
false);
911 }
else if (
const VarDecl *V = dyn_cast<VarDecl>(D)) {
912 Description = V->getType().getAsString(m_desc_policy);
913 }
else if (
const FieldDecl *F = dyn_cast<FieldDecl>(D)) {
914 Description = F->getType().getAsString(m_desc_policy);
915 }
else if (
const NamespaceDecl *N = dyn_cast<NamespaceDecl>(D)) {
918 if (!N->isAnonymousNamespace())
923 case CodeCompletionResult::RK_Keyword:
924 ToInsert = R.Keyword;
926 case CodeCompletionResult::RK_Macro:
927 ToInsert = R.Macro->getName().str();
929 case CodeCompletionResult::RK_Pattern:
930 ToInsert = R.Pattern->getTypedText();
935 if (llvm::StringRef(ToInsert).startswith(
"$__lldb_"))
937 if (ToInsert.empty())
942 mergeCompletion(m_expr, m_position, ToInsert);
946 return {{completion, R.Priority}};
954 llvm::sort(m_completions);
956 for (
const CompletionWithPriority &C : m_completions)
958 C.completion.GetDescription(),
959 C.completion.GetMode());
964 void ProcessCodeCompleteResults(Sema &SemaRef, CodeCompletionContext Context,
965 CodeCompletionResult *Results,
966 unsigned NumResults)
override {
970 StringRef Filter = SemaRef.getPreprocessor().getCodeCompletionFilter();
974 for (
unsigned I = 0; I != NumResults; ++I) {
976 if (!Filter.empty() && isResultFilteredOut(Filter, Results[I]))
979 CodeCompletionResult &R = Results[I];
980 llvm::Optional<CompletionWithPriority> CompletionAndPriority =
981 getCompletionForResult(R);
982 if (!CompletionAndPriority)
984 m_completions.push_back(*CompletionAndPriority);
996 void ProcessOverloadCandidates(Sema &S,
unsigned CurrentArg,
997 OverloadCandidate *Candidates,
998 unsigned NumCandidates,
999 SourceLocation OpenParLoc,
1000 bool Braced)
override {
1004 CodeCompletionAllocator &getAllocator()
override {
1005 return m_info.getAllocator();
1008 CodeCompletionTUInfo &getCodeCompletionTUInfo()
override {
return m_info; }
1013 unsigned pos,
unsigned typed_pos) {
1028 CC.GetCompletions(request);
1038 CodeCompleteConsumer *completion_consumer,
1039 unsigned completion_line,
1040 unsigned completion_column) {
1049 clang::SourceManager &source_mgr =
m_compiler->getSourceManager();
1050 bool created_main_file =
false;
1056 bool should_create_file = completion_consumer !=
nullptr;
1059 should_create_file |=
m_compiler->getCodeGenOpts().getDebugInfo() ==
1060 codegenoptions::FullDebugInfo;
1062 if (should_create_file) {
1064 llvm::SmallString<128> result_path;
1065 if (
FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir()) {
1066 tmpdir_file_spec.AppendPathComponent(
"lldb-%%%%%%.expr");
1067 std::string temp_source_path = tmpdir_file_spec.GetPath();
1068 llvm::sys::fs::createUniqueFile(temp_source_path, temp_fd, result_path);
1070 llvm::sys::fs::createTemporaryFile(
"lldb",
"expr", temp_fd, result_path);
1073 if (temp_fd != -1) {
1075 const size_t expr_text_len = strlen(expr_text);
1076 size_t bytes_written = expr_text_len;
1078 if (bytes_written == expr_text_len) {
1080 if (
auto fileEntry =
m_compiler->getFileManager().getOptionalFileRef(
1082 source_mgr.setMainFileID(source_mgr.createFileID(
1084 SourceLocation(), SrcMgr::C_User));
1085 created_main_file =
true;
1092 if (!created_main_file) {
1093 std::unique_ptr<MemoryBuffer> memory_buffer =
1094 MemoryBuffer::getMemBufferCopy(expr_text,
m_filename);
1095 source_mgr.setMainFileID(source_mgr.createFileID(std::move(memory_buffer)));
1108 if (completion_consumer) {
1109 auto main_file = source_mgr.getFileEntryForID(source_mgr.getMainFileID());
1114 ++completion_column;
1115 PP.SetCodeCompletionPoint(main_file, completion_line, completion_column);
1118 ASTConsumer *ast_transformer =
1121 std::unique_ptr<clang::ASTConsumer> Consumer;
1122 if (ast_transformer) {
1123 Consumer = std::make_unique<ASTConsumerForwarder>(ast_transformer);
1127 Consumer = std::make_unique<ASTConsumer>();
1130 clang::ASTContext &ast_context =
m_compiler->getASTContext();
1133 *Consumer, TU_Complete, completion_consumer));
1134 m_compiler->setASTConsumer(std::move(Consumer));
1136 if (ast_context.getLangOpts().Modules) {
1146 clang::ExternalASTSource *ast_source = decl_map->
CreateProxy();
1148 if (ast_context.getExternalSource()) {
1149 auto module_wrapper =
1156 IntrusiveRefCntPtr<ExternalASTSource> Source(multiplexer);
1157 ast_context.setExternalSource(Source);
1159 ast_context.setExternalSource(ast_source);
1165 if (ast_context.getLangOpts().Modules) {
1166 assert(
m_compiler->getASTContext().getExternalSource() &&
1167 "ASTContext doesn't know about the ASTReader?");
1168 assert(
m_compiler->getSema().getExternalSource() &&
1169 "Sema doesn't know about the ASTReader?");
1173 llvm::CrashRecoveryContextCleanupRegistrar<Sema> CleanupSema(
1175 ParseAST(
m_compiler->getSema(),
false,
false);
1179 if (ast_context.getLangOpts().Modules)
1187 unsigned num_errors = adapter->getNumErrors();
1192 "while importing modules:");
1210 if (target_arch.
IsMIPS()) {
1229 static void ApplyFixIt(
const FixItHint &fixit, clang::edit::Commit &commit) {
1231 if (fixit.CodeToInsert.empty()) {
1232 if (fixit.InsertFromRange.isValid()) {
1233 commit.insertFromRange(fixit.RemoveRange.getBegin(),
1234 fixit.InsertFromRange,
false,
1235 fixit.BeforePreviousInsertions);
1238 commit.remove(fixit.RemoveRange);
1241 if (fixit.RemoveRange.isTokenRange() ||
1242 fixit.RemoveRange.getBegin() != fixit.RemoveRange.getEnd()) {
1243 commit.replace(fixit.RemoveRange, fixit.CodeToInsert);
1246 commit.insert(fixit.RemoveRange.getBegin(), fixit.CodeToInsert,
1247 false, fixit.BeforePreviousInsertions);
1252 clang::SourceManager &source_manager =
m_compiler->getSourceManager();
1253 clang::edit::EditedSource editor(source_manager,
m_compiler->getLangOpts(),
1255 clang::edit::Commit commit(editor);
1256 clang::Rewriter rewriter(source_manager,
m_compiler->getLangOpts());
1258 class RewritesReceiver :
public edit::EditsReceiver {
1262 RewritesReceiver(Rewriter &in_rewrite) : rewrite(in_rewrite) {}
1264 void insert(SourceLocation loc, StringRef text)
override {
1265 rewrite.InsertText(loc, text);
1267 void replace(CharSourceRange range, StringRef text)
override {
1268 rewrite.ReplaceText(range.getBegin(), rewrite.getRangeSize(range), text);
1272 RewritesReceiver rewrites_receiver(rewriter);
1275 size_t num_diags = diagnostics.size();
1279 for (
const auto &diag : diagnostic_manager.
Diagnostics()) {
1280 const auto *diagnostic = llvm::dyn_cast<ClangDiagnostic>(diag.get());
1283 if (!diagnostic->HasFixIts())
1285 for (
const FixItHint &fixit : diagnostic->FixIts())
1290 if (!commit.isCommitable())
1292 else if (!editor.commit(commit))
1296 editor.applyRewrites(rewrites_receiver);
1297 RewriteBuffer &main_file_buffer =
1298 rewriter.getEditBuffer(source_manager.getMainFileID());
1301 llvm::raw_string_ostream out_stream(fixed_expression);
1303 main_file_buffer.write(out_stream);
1311 llvm::Module *module,
const char *orig_name) {
1312 for (
const auto &func : module->getFunctionList()) {
1313 const StringRef &name = func.getName();
1314 if (name.contains(orig_name)) {
1333 std::unique_ptr<llvm::Module> llvm_module_up(
1336 if (!llvm_module_up) {
1361 if (lldb::StackFrameSP frame_sp = exe_ctx.
GetFrameSP()) {
1362 sc = frame_sp->GetSymbolContext(lldb::eSymbolContextEverything);
1363 }
else if (lldb::TargetSP target_sp = exe_ctx.
GetTargetSP()) {
1370 LLDB_LOGF(log,
"%s - Current expression language is %s\n", __FUNCTION__,
1374 auto runtime = process_sp->GetLanguageRuntime(lang);
1376 runtime->GetIRPasses(custom_passes);
1382 "%s - Running Early IR Passes from LanguageRuntime on "
1383 "expression module '%s'",
1389 execution_unit_sp = std::make_shared<IRExecutionUnit>(
1398 type_system_helper->
DeclMap();
1403 *execution_unit_sp, error_stream,
1406 if (!ir_for_target.
runOnModule(*execution_unit_sp->GetModule())) {
1417 bool interpret_function_calls =
1420 *execution_unit_sp->GetModule(), *execution_unit_sp->GetFunction(),
1421 interpret_error, interpret_function_calls);
1425 "Can't evaluate the expression without a running target due to: %s",
1432 err.
SetErrorString(
"Expression needed to run in the target, but the "
1433 "target can't be run");
1438 err.
SetErrorString(
"Top-level code needs to be inserted into a runnable "
1439 "target, but the target can't be run");
1452 if (!dynamic_checkers->
Install(install_diagnostics, exe_ctx)) {
1463 LLDB_LOGF(log,
"== [ClangExpressionParser::PrepareForExecution] "
1464 "Finished installing dynamic checkers ==");
1467 if (
auto *checker_funcs = llvm::dyn_cast<ClangDynamicCheckerFunctions>(
1472 llvm::Module *module = execution_unit_sp->GetModule();
1473 if (!module || !ir_dynamic_checks.
runOnModule(*module)) {
1475 err.
SetErrorString(
"Couldn't add dynamic checks to the expression");
1481 "%s - Running Late IR Passes from LanguageRuntime on "
1482 "expression module '%s'",
1493 execution_unit_sp->GetRunnableInfo(err, func_addr, func_end);
1496 execution_unit_sp->GetRunnableInfo(err, func_addr, func_end);
1509 if (!execution_unit_sp.get()) {
1511 "can't run static initializers for a NULL execution unit");
1516 err.
SetErrorString(
"can't run static initializers without a thread");
1520 std::vector<lldb::addr_t> static_initializers;
1522 execution_unit_sp->GetStaticInitializers(static_initializers);
1524 for (
lldb::addr_t static_initializer : static_initializers) {
1529 llvm::ArrayRef<lldb::addr_t>(), options));
1534 exe_ctx, call_static_initializer, options, execution_errors);