Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 1 | //===-- ClangExpressionParser.cpp -------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 10 | #include <cctype> |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 11 | #include "clang/AST/ASTContext.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 12 | #include "clang/AST/ASTDiagnostic.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 13 | #include "clang/AST/ExternalASTSource.h" |
Raphael Isemann | 9dd34c8 | 2018-09-17 12:06:07 +0000 | [diff] [blame] | 14 | #include "clang/AST/PrettyPrinter.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 15 | #include "clang/Basic/DiagnosticIDs.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 16 | #include "clang/Basic/FileManager.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 17 | #include "clang/Basic/SourceLocation.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 18 | #include "clang/Basic/TargetInfo.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Version.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 20 | #include "clang/CodeGen/CodeGenAction.h" |
| 21 | #include "clang/CodeGen/ModuleBuilder.h" |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 22 | #include "clang/Edit/Commit.h" |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 23 | #include "clang/Edit/EditedSource.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | #include "clang/Edit/EditsReceiver.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 25 | #include "clang/Frontend/CompilerInstance.h" |
| 26 | #include "clang/Frontend/CompilerInvocation.h" |
| 27 | #include "clang/Frontend/FrontendActions.h" |
| 28 | #include "clang/Frontend/FrontendDiagnostic.h" |
| 29 | #include "clang/Frontend/FrontendPluginRegistry.h" |
| 30 | #include "clang/Frontend/TextDiagnosticBuffer.h" |
| 31 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 32 | #include "clang/Lex/Preprocessor.h" |
Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 33 | #include "clang/Parse/ParseAST.h" |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 34 | #include "clang/Rewrite/Core/Rewriter.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | #include "clang/Rewrite/Frontend/FrontendActions.h" |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 36 | #include "clang/Sema/CodeCompleteConsumer.h" |
| 37 | #include "clang/Sema/Sema.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 38 | #include "clang/Sema/SemaConsumer.h" |
| 39 | |
| 40 | #include "llvm/ADT/StringRef.h" |
| 41 | #include "llvm/ExecutionEngine/ExecutionEngine.h" |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 42 | #include "llvm/Support/Debug.h" |
Rafael Espindola | 4609ea8 | 2013-06-26 14:10:56 +0000 | [diff] [blame] | 43 | #include "llvm/Support/FileSystem.h" |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 44 | #include "llvm/Support/TargetSelect.h" |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 45 | |
Greg Clayton | c9a078a | 2016-03-24 23:50:03 +0000 | [diff] [blame] | 46 | #pragma clang diagnostic push |
| 47 | #pragma clang diagnostic ignored "-Wglobal-constructors" |
Ed Maste | a09ed03 | 2014-03-18 18:55:06 +0000 | [diff] [blame] | 48 | #include "llvm/ExecutionEngine/MCJIT.h" |
Greg Clayton | c9a078a | 2016-03-24 23:50:03 +0000 | [diff] [blame] | 49 | #pragma clang diagnostic pop |
| 50 | |
Chandler Carruth | 1e15758 | 2013-01-02 12:20:07 +0000 | [diff] [blame] | 51 | #include "llvm/IR/LLVMContext.h" |
| 52 | #include "llvm/IR/Module.h" |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 53 | #include "llvm/Support/DynamicLibrary.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | #include "llvm/Support/ErrorHandling.h" |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 55 | #include "llvm/Support/Host.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | #include "llvm/Support/MemoryBuffer.h" |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 57 | #include "llvm/Support/Signals.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 58 | |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 59 | #include "ClangDiagnostic.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | #include "ClangExpressionParser.h" |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 61 | |
| 62 | #include "ClangASTSource.h" |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 63 | #include "ClangExpressionDeclMap.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | #include "ClangExpressionHelper.h" |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 65 | #include "ClangModulesDeclVendor.h" |
| 66 | #include "ClangPersistentVariables.h" |
| 67 | #include "IRForTarget.h" |
| 68 | |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 69 | #include "lldb/Core/Debugger.h" |
| 70 | #include "lldb/Core/Disassembler.h" |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 71 | #include "lldb/Core/Module.h" |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 72 | #include "lldb/Core/StreamFile.h" |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 73 | #include "lldb/Expression/IRDynamicChecks.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 74 | #include "lldb/Expression/IRExecutionUnit.h" |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 75 | #include "lldb/Expression/IRInterpreter.h" |
| 76 | #include "lldb/Host/File.h" |
| 77 | #include "lldb/Host/HostInfo.h" |
| 78 | #include "lldb/Symbol/ClangASTContext.h" |
| 79 | #include "lldb/Symbol/SymbolVendor.h" |
| 80 | #include "lldb/Target/ExecutionContext.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 81 | #include "lldb/Target/Language.h" |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 82 | #include "lldb/Target/ObjCLanguageRuntime.h" |
| 83 | #include "lldb/Target/Process.h" |
| 84 | #include "lldb/Target/Target.h" |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 85 | #include "lldb/Target/ThreadPlanCallFunction.h" |
Zachary Turner | 666cc0b | 2017-03-04 01:30:05 +0000 | [diff] [blame] | 86 | #include "lldb/Utility/DataBufferHeap.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 87 | #include "lldb/Utility/LLDBAssert.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 88 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 89 | #include "lldb/Utility/Stream.h" |
| 90 | #include "lldb/Utility/StreamString.h" |
Zachary Turner | 573ab90 | 2017-03-21 18:25:04 +0000 | [diff] [blame] | 91 | #include "lldb/Utility/StringList.h" |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 92 | |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 93 | using namespace clang; |
| 94 | using namespace llvm; |
| 95 | using namespace lldb_private; |
| 96 | |
| 97 | //===----------------------------------------------------------------------===// |
| 98 | // Utility Methods for Clang |
| 99 | //===----------------------------------------------------------------------===// |
| 100 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | class ClangExpressionParser::LLDBPreprocessorCallbacks : public PPCallbacks { |
| 102 | ClangModulesDeclVendor &m_decl_vendor; |
| 103 | ClangPersistentVariables &m_persistent_vars; |
| 104 | StreamString m_error_stream; |
| 105 | bool m_has_errors = false; |
Eugene Zelenko | 4c3f2b9 | 2015-10-21 01:03:30 +0000 | [diff] [blame] | 106 | |
Sean Callanan | c8278af | 2014-12-05 01:27:35 +0000 | [diff] [blame] | 107 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | LLDBPreprocessorCallbacks(ClangModulesDeclVendor &decl_vendor, |
| 109 | ClangPersistentVariables &persistent_vars) |
| 110 | : m_decl_vendor(decl_vendor), m_persistent_vars(persistent_vars) {} |
| 111 | |
| 112 | void moduleImport(SourceLocation import_location, clang::ModuleIdPath path, |
| 113 | const clang::Module * /*null*/) override { |
| 114 | std::vector<ConstString> string_path; |
| 115 | |
| 116 | for (const std::pair<IdentifierInfo *, SourceLocation> &component : path) { |
| 117 | string_path.push_back(ConstString(component.first->getName())); |
Sean Callanan | c8278af | 2014-12-05 01:27:35 +0000 | [diff] [blame] | 118 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 119 | |
| 120 | StreamString error_stream; |
| 121 | |
| 122 | ClangModulesDeclVendor::ModuleVector exported_modules; |
| 123 | |
| 124 | if (!m_decl_vendor.AddModule(string_path, &exported_modules, |
| 125 | m_error_stream)) { |
| 126 | m_has_errors = true; |
Sean Callanan | c8278af | 2014-12-05 01:27:35 +0000 | [diff] [blame] | 127 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 128 | |
| 129 | for (ClangModulesDeclVendor::ModuleID module : exported_modules) { |
| 130 | m_persistent_vars.AddHandLoadedClangModule(module); |
Sean Callanan | c8278af | 2014-12-05 01:27:35 +0000 | [diff] [blame] | 131 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | bool hasErrors() { return m_has_errors; } |
| 135 | |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 136 | llvm::StringRef getErrorString() { return m_error_stream.GetString(); } |
Sean Callanan | c8278af | 2014-12-05 01:27:35 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | class ClangDiagnosticManagerAdapter : public clang::DiagnosticConsumer { |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 140 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | ClangDiagnosticManagerAdapter() |
| 142 | : m_passthrough(new clang::TextDiagnosticBuffer) {} |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 143 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 144 | ClangDiagnosticManagerAdapter( |
| 145 | const std::shared_ptr<clang::TextDiagnosticBuffer> &passthrough) |
| 146 | : m_passthrough(passthrough) {} |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 147 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 148 | void ResetManager(DiagnosticManager *manager = nullptr) { |
| 149 | m_manager = manager; |
| 150 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 151 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
| 153 | const clang::Diagnostic &Info) { |
| 154 | if (m_manager) { |
| 155 | llvm::SmallVector<char, 32> diag_str; |
| 156 | Info.FormatDiagnostic(diag_str); |
| 157 | diag_str.push_back('\0'); |
| 158 | const char *data = diag_str.data(); |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 159 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | lldb_private::DiagnosticSeverity severity; |
| 161 | bool make_new_diagnostic = true; |
| 162 | |
| 163 | switch (DiagLevel) { |
| 164 | case DiagnosticsEngine::Level::Fatal: |
| 165 | case DiagnosticsEngine::Level::Error: |
| 166 | severity = eDiagnosticSeverityError; |
| 167 | break; |
| 168 | case DiagnosticsEngine::Level::Warning: |
| 169 | severity = eDiagnosticSeverityWarning; |
| 170 | break; |
| 171 | case DiagnosticsEngine::Level::Remark: |
| 172 | case DiagnosticsEngine::Level::Ignored: |
| 173 | severity = eDiagnosticSeverityRemark; |
| 174 | break; |
| 175 | case DiagnosticsEngine::Level::Note: |
| 176 | m_manager->AppendMessageToDiagnostic(data); |
| 177 | make_new_diagnostic = false; |
| 178 | } |
| 179 | if (make_new_diagnostic) { |
| 180 | ClangDiagnostic *new_diagnostic = |
| 181 | new ClangDiagnostic(data, severity, Info.getID()); |
| 182 | m_manager->AddDiagnostic(new_diagnostic); |
| 183 | |
| 184 | // Don't store away warning fixits, since the compiler doesn't have |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 185 | // enough context in an expression for the warning to be useful. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 186 | // FIXME: Should we try to filter out FixIts that apply to our generated |
| 187 | // code, and not the user's expression? |
| 188 | if (severity == eDiagnosticSeverityError) { |
| 189 | size_t num_fixit_hints = Info.getNumFixItHints(); |
| 190 | for (size_t i = 0; i < num_fixit_hints; i++) { |
| 191 | const clang::FixItHint &fixit = Info.getFixItHint(i); |
| 192 | if (!fixit.isNull()) |
| 193 | new_diagnostic->AddFixitHint(fixit); |
| 194 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 195 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 196 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 199 | m_passthrough->HandleDiagnostic(DiagLevel, Info); |
| 200 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 201 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 202 | void FlushDiagnostics(DiagnosticsEngine &Diags) { |
| 203 | m_passthrough->FlushDiagnostics(Diags); |
| 204 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 205 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 206 | DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const { |
| 207 | return new ClangDiagnosticManagerAdapter(m_passthrough); |
| 208 | } |
| 209 | |
| 210 | clang::TextDiagnosticBuffer *GetPassthrough() { return m_passthrough.get(); } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 211 | |
| 212 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 213 | DiagnosticManager *m_manager = nullptr; |
| 214 | std::shared_ptr<clang::TextDiagnosticBuffer> m_passthrough; |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 217 | //===----------------------------------------------------------------------===// |
| 218 | // Implementation of ClangExpressionParser |
| 219 | //===----------------------------------------------------------------------===// |
| 220 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 221 | ClangExpressionParser::ClangExpressionParser(ExecutionContextScope *exe_scope, |
| 222 | Expression &expr, |
| 223 | bool generate_debug_info) |
| 224 | : ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(), |
Adrian Prantl | 2305c04 | 2018-08-30 15:39:08 +0000 | [diff] [blame] | 225 | m_pp_callbacks(nullptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 226 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
Aidan Dodds | 1b6785a | 2016-02-03 12:33:05 +0000 | [diff] [blame] | 227 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 228 | // We can't compile expressions without a target. So if the exe_scope is |
| 229 | // null or doesn't have a target, then we just need to get out of here. I'll |
| 230 | // lldb_assert and not make any of the compiler objects since |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 231 | // I can't return errors directly from the constructor. Further calls will |
| 232 | // check if the compiler was made and |
| 233 | // bag out if it wasn't. |
Sagar Thakur | adc1abe | 2016-05-13 11:04:47 +0000 | [diff] [blame] | 234 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 235 | if (!exe_scope) { |
| 236 | lldb_assert(exe_scope, "Can't make an expression parser with a null scope.", |
| 237 | __FUNCTION__, __FILE__, __LINE__); |
| 238 | return; |
| 239 | } |
Bhushan D. Attarde | 3592a6e | 2016-02-18 11:53:28 +0000 | [diff] [blame] | 240 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 241 | lldb::TargetSP target_sp; |
| 242 | target_sp = exe_scope->CalculateTarget(); |
| 243 | if (!target_sp) { |
| 244 | lldb_assert(target_sp.get(), |
| 245 | "Can't make an expression parser with a null target.", |
| 246 | __FUNCTION__, __FILE__, __LINE__); |
| 247 | return; |
| 248 | } |
Bhushan D. Attarde | 3592a6e | 2016-02-18 11:53:28 +0000 | [diff] [blame] | 249 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 250 | // 1. Create a new compiler instance. |
| 251 | m_compiler.reset(new CompilerInstance()); |
| 252 | lldb::LanguageType frame_lang = |
| 253 | expr.Language(); // defaults to lldb::eLanguageTypeUnknown |
| 254 | bool overridden_target_opts = false; |
| 255 | lldb_private::LanguageRuntime *lang_rt = nullptr; |
Aidan Dodds | 1b6785a | 2016-02-03 12:33:05 +0000 | [diff] [blame] | 256 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 257 | std::string abi; |
| 258 | ArchSpec target_arch; |
| 259 | target_arch = target_sp->GetArchitecture(); |
Aidan Dodds | 1b6785a | 2016-02-03 12:33:05 +0000 | [diff] [blame] | 260 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 261 | const auto target_machine = target_arch.GetMachine(); |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 262 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 263 | // If the expression is being evaluated in the context of an existing stack |
| 264 | // frame, we introspect to see if the language runtime is available. |
Bhushan D. Attarde | 3592a6e | 2016-02-18 11:53:28 +0000 | [diff] [blame] | 265 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 266 | lldb::StackFrameSP frame_sp = exe_scope->CalculateStackFrame(); |
| 267 | lldb::ProcessSP process_sp = exe_scope->CalculateProcess(); |
Sagar Thakur | adc1abe | 2016-05-13 11:04:47 +0000 | [diff] [blame] | 268 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 269 | // Make sure the user hasn't provided a preferred execution language with |
| 270 | // `expression --language X -- ...` |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 271 | if (frame_sp && frame_lang == lldb::eLanguageTypeUnknown) |
| 272 | frame_lang = frame_sp->GetLanguage(); |
Aidan Dodds | 1b6785a | 2016-02-03 12:33:05 +0000 | [diff] [blame] | 273 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | if (process_sp && frame_lang != lldb::eLanguageTypeUnknown) { |
| 275 | lang_rt = process_sp->GetLanguageRuntime(frame_lang); |
Aidan Dodds | 1b6785a | 2016-02-03 12:33:05 +0000 | [diff] [blame] | 276 | if (log) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 277 | log->Printf("Frame has language of type %s", |
| 278 | Language::GetNameForLanguageType(frame_lang)); |
| 279 | } |
Alp Toker | 5f83864 | 2014-07-06 05:36:57 +0000 | [diff] [blame] | 280 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 281 | // 2. Configure the compiler with a set of default options that are |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 282 | // appropriate for most situations. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 283 | if (target_arch.IsValid()) { |
| 284 | std::string triple = target_arch.GetTriple().str(); |
| 285 | m_compiler->getTargetOpts().Triple = triple; |
| 286 | if (log) |
| 287 | log->Printf("Using %s as the target triple", |
| 288 | m_compiler->getTargetOpts().Triple.c_str()); |
| 289 | } else { |
| 290 | // If we get here we don't have a valid target and just have to guess. |
| 291 | // Sometimes this will be ok to just use the host target triple (when we |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 292 | // evaluate say "2+3", but other expressions like breakpoint conditions and |
| 293 | // other things that _are_ target specific really shouldn't just be using |
| 294 | // the host triple. In such a case the language runtime should expose an |
| 295 | // overridden options set (3), below. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | m_compiler->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple(); |
| 297 | if (log) |
| 298 | log->Printf("Using default target triple of %s", |
| 299 | m_compiler->getTargetOpts().Triple.c_str()); |
| 300 | } |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 301 | // Now add some special fixes for known architectures: Any arm32 iOS |
| 302 | // environment, but not on arm64 |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 303 | if (m_compiler->getTargetOpts().Triple.find("arm64") == std::string::npos && |
| 304 | m_compiler->getTargetOpts().Triple.find("arm") != std::string::npos && |
| 305 | m_compiler->getTargetOpts().Triple.find("ios") != std::string::npos) { |
| 306 | m_compiler->getTargetOpts().ABI = "apcs-gnu"; |
| 307 | } |
| 308 | // Supported subsets of x86 |
| 309 | if (target_machine == llvm::Triple::x86 || |
| 310 | target_machine == llvm::Triple::x86_64) { |
| 311 | m_compiler->getTargetOpts().Features.push_back("+sse"); |
| 312 | m_compiler->getTargetOpts().Features.push_back("+sse2"); |
| 313 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 314 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 315 | // Set the target CPU to generate code for. This will be empty for any CPU |
| 316 | // that doesn't really need to make a special |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 317 | // CPU string. |
| 318 | m_compiler->getTargetOpts().CPU = target_arch.GetClangTargetCPU(); |
Ewan Crawford | 7648dd3 | 2016-03-10 12:38:55 +0000 | [diff] [blame] | 319 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 320 | // Set the target ABI |
| 321 | abi = GetClangTargetABI(target_arch); |
| 322 | if (!abi.empty()) |
| 323 | m_compiler->getTargetOpts().ABI = abi; |
| 324 | |
| 325 | // 3. Now allow the runtime to provide custom configuration options for the |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 326 | // target. In this case, a specialized language runtime is available and we |
| 327 | // can query it for extra options. For 99% of use cases, this will not be |
| 328 | // needed and should be provided when basic platform detection is not enough. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 329 | if (lang_rt) |
| 330 | overridden_target_opts = |
| 331 | lang_rt->GetOverrideExprOptions(m_compiler->getTargetOpts()); |
| 332 | |
| 333 | if (overridden_target_opts) |
Pavel Labath | 6302bf6 | 2017-02-13 11:03:17 +0000 | [diff] [blame] | 334 | if (log && log->GetVerbose()) { |
| 335 | LLDB_LOGV( |
| 336 | log, "Using overridden target options for the expression evaluation"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 337 | |
| 338 | auto opts = m_compiler->getTargetOpts(); |
Pavel Labath | 6302bf6 | 2017-02-13 11:03:17 +0000 | [diff] [blame] | 339 | LLDB_LOGV(log, "Triple: '{0}'", opts.Triple); |
| 340 | LLDB_LOGV(log, "CPU: '{0}'", opts.CPU); |
| 341 | LLDB_LOGV(log, "FPMath: '{0}'", opts.FPMath); |
| 342 | LLDB_LOGV(log, "ABI: '{0}'", opts.ABI); |
| 343 | LLDB_LOGV(log, "LinkerVersion: '{0}'", opts.LinkerVersion); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 344 | StringList::LogDump(log, opts.FeaturesAsWritten, "FeaturesAsWritten"); |
| 345 | StringList::LogDump(log, opts.Features, "Features"); |
Sean Callanan | c7b6506 | 2011-11-07 23:35:40 +0000 | [diff] [blame] | 346 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 347 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 348 | // 4. Create and install the target on the compiler. |
| 349 | m_compiler->createDiagnostics(); |
| 350 | auto target_info = TargetInfo::CreateTargetInfo( |
| 351 | m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts); |
| 352 | if (log) { |
| 353 | log->Printf("Using SIMD alignment: %d", target_info->getSimdDefaultAlign()); |
| 354 | log->Printf("Target datalayout string: '%s'", |
| 355 | target_info->getDataLayout().getStringRepresentation().c_str()); |
| 356 | log->Printf("Target ABI: '%s'", target_info->getABI().str().c_str()); |
| 357 | log->Printf("Target vector alignment: %d", |
| 358 | target_info->getMaxVectorAlign()); |
| 359 | } |
| 360 | m_compiler->setTarget(target_info); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 361 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 362 | assert(m_compiler->hasTarget()); |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 363 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 364 | // 5. Set language options. |
| 365 | lldb::LanguageType language = expr.Language(); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 366 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 367 | switch (language) { |
| 368 | case lldb::eLanguageTypeC: |
| 369 | case lldb::eLanguageTypeC89: |
| 370 | case lldb::eLanguageTypeC99: |
| 371 | case lldb::eLanguageTypeC11: |
| 372 | // FIXME: the following language option is a temporary workaround, |
| 373 | // to "ask for C, get C++." |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 374 | // For now, the expression parser must use C++ anytime the language is a C |
| 375 | // family language, because the expression parser uses features of C++ to |
| 376 | // capture values. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 377 | m_compiler->getLangOpts().CPlusPlus = true; |
| 378 | break; |
| 379 | case lldb::eLanguageTypeObjC: |
Erik Pilkington | fa98390 | 2018-10-30 20:31:30 +0000 | [diff] [blame] | 380 | m_compiler->getLangOpts().ObjC = true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 381 | // FIXME: the following language option is a temporary workaround, |
| 382 | // to "ask for ObjC, get ObjC++" (see comment above). |
| 383 | m_compiler->getLangOpts().CPlusPlus = true; |
Davide Italiano | 89419f8 | 2017-12-15 00:50:43 +0000 | [diff] [blame] | 384 | |
| 385 | // Clang now sets as default C++14 as the default standard (with |
| 386 | // GNU extensions), so we do the same here to avoid mismatches that |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 387 | // cause compiler error when evaluating expressions (e.g. nullptr not found |
| 388 | // as it's a C++11 feature). Currently lldb evaluates C++14 as C++11 (see |
| 389 | // two lines below) so we decide to be consistent with that, but this could |
| 390 | // be re-evaluated in the future. |
Davide Italiano | 89419f8 | 2017-12-15 00:50:43 +0000 | [diff] [blame] | 391 | m_compiler->getLangOpts().CPlusPlus11 = true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 392 | break; |
| 393 | case lldb::eLanguageTypeC_plus_plus: |
| 394 | case lldb::eLanguageTypeC_plus_plus_11: |
| 395 | case lldb::eLanguageTypeC_plus_plus_14: |
| 396 | m_compiler->getLangOpts().CPlusPlus11 = true; |
| 397 | m_compiler->getHeaderSearchOpts().UseLibcxx = true; |
| 398 | LLVM_FALLTHROUGH; |
| 399 | case lldb::eLanguageTypeC_plus_plus_03: |
| 400 | m_compiler->getLangOpts().CPlusPlus = true; |
Aleksandr Urakov | f335188 | 2018-12-04 09:51:29 +0000 | [diff] [blame^] | 401 | if (process_sp) |
| 402 | m_compiler->getLangOpts().ObjC = |
| 403 | process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC) != nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 404 | break; |
| 405 | case lldb::eLanguageTypeObjC_plus_plus: |
| 406 | case lldb::eLanguageTypeUnknown: |
| 407 | default: |
Erik Pilkington | fa98390 | 2018-10-30 20:31:30 +0000 | [diff] [blame] | 408 | m_compiler->getLangOpts().ObjC = true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 409 | m_compiler->getLangOpts().CPlusPlus = true; |
| 410 | m_compiler->getLangOpts().CPlusPlus11 = true; |
| 411 | m_compiler->getHeaderSearchOpts().UseLibcxx = true; |
| 412 | break; |
| 413 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 414 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 415 | m_compiler->getLangOpts().Bool = true; |
| 416 | m_compiler->getLangOpts().WChar = true; |
| 417 | m_compiler->getLangOpts().Blocks = true; |
| 418 | m_compiler->getLangOpts().DebuggerSupport = |
| 419 | true; // Features specifically for debugger clients |
| 420 | if (expr.DesiredResultType() == Expression::eResultTypeId) |
| 421 | m_compiler->getLangOpts().DebuggerCastResultToId = true; |
| 422 | |
| 423 | m_compiler->getLangOpts().CharIsSigned = |
| 424 | ArchSpec(m_compiler->getTargetOpts().Triple.c_str()) |
| 425 | .CharIsSignedByDefault(); |
| 426 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 427 | // Spell checking is a nice feature, but it ends up completing a lot of types |
| 428 | // that we didn't strictly speaking need to complete. As a result, we spend a |
| 429 | // long time parsing and importing debug information. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 430 | m_compiler->getLangOpts().SpellChecking = false; |
| 431 | |
Erik Pilkington | fa98390 | 2018-10-30 20:31:30 +0000 | [diff] [blame] | 432 | if (process_sp && m_compiler->getLangOpts().ObjC) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 433 | if (process_sp->GetObjCLanguageRuntime()) { |
| 434 | if (process_sp->GetObjCLanguageRuntime()->GetRuntimeVersion() == |
| 435 | ObjCLanguageRuntime::ObjCRuntimeVersions::eAppleObjC_V2) |
| 436 | m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::MacOSX, |
| 437 | VersionTuple(10, 7)); |
| 438 | else |
| 439 | m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::FragileMacOSX, |
| 440 | VersionTuple(10, 7)); |
| 441 | |
| 442 | if (process_sp->GetObjCLanguageRuntime()->HasNewLiteralsAndIndexing()) |
| 443 | m_compiler->getLangOpts().DebuggerObjCLiteral = true; |
Sean Callanan | c3a1600 | 2011-01-17 23:42:46 +0000 | [diff] [blame] | 444 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 445 | } |
Greg Clayton | f83f32d | 2011-01-15 01:32:14 +0000 | [diff] [blame] | 446 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 447 | m_compiler->getLangOpts().ThreadsafeStatics = false; |
| 448 | m_compiler->getLangOpts().AccessControl = |
| 449 | false; // Debuggers get universal access |
| 450 | m_compiler->getLangOpts().DollarIdents = |
| 451 | true; // $ indicates a persistent variable name |
Raphael Isemann | d424c2a | 2018-08-30 20:56:58 +0000 | [diff] [blame] | 452 | // We enable all builtin functions beside the builtins from libc/libm (e.g. |
| 453 | // 'fopen'). Those libc functions are already correctly handled by LLDB, and |
| 454 | // additionally enabling them as expandable builtins is breaking Clang. |
| 455 | m_compiler->getLangOpts().NoBuiltin = true; |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 456 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 457 | // Set CodeGen options |
| 458 | m_compiler->getCodeGenOpts().EmitDeclMetadata = true; |
| 459 | m_compiler->getCodeGenOpts().InstrumentFunctions = false; |
| 460 | m_compiler->getCodeGenOpts().DisableFPElim = true; |
| 461 | m_compiler->getCodeGenOpts().OmitLeafFramePointer = false; |
| 462 | if (generate_debug_info) |
| 463 | m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo); |
| 464 | else |
| 465 | m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::NoDebugInfo); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 466 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 467 | // Disable some warnings. |
| 468 | m_compiler->getDiagnostics().setSeverityForGroup( |
| 469 | clang::diag::Flavor::WarningOrError, "unused-value", |
| 470 | clang::diag::Severity::Ignored, SourceLocation()); |
| 471 | m_compiler->getDiagnostics().setSeverityForGroup( |
| 472 | clang::diag::Flavor::WarningOrError, "odr", |
| 473 | clang::diag::Severity::Ignored, SourceLocation()); |
Alp Toker | 10933d1 | 2014-06-12 11:14:32 +0000 | [diff] [blame] | 474 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 475 | // Inform the target of the language options |
| 476 | // |
| 477 | // FIXME: We shouldn't need to do this, the target should be immutable once |
| 478 | // created. This complexity should be lifted elsewhere. |
| 479 | m_compiler->getTarget().adjust(m_compiler->getLangOpts()); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 480 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 481 | // 6. Set up the diagnostic buffer for reporting errors |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 482 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 483 | m_compiler->getDiagnostics().setClient(new ClangDiagnosticManagerAdapter); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 484 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 485 | // 7. Set up the source management objects inside the compiler |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 486 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 487 | clang::FileSystemOptions file_system_options; |
| 488 | m_file_manager.reset(new clang::FileManager(file_system_options)); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 489 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 490 | if (!m_compiler->hasSourceManager()) |
| 491 | m_compiler->createSourceManager(*m_file_manager.get()); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 492 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 493 | m_compiler->createFileManager(); |
| 494 | m_compiler->createPreprocessor(TU_Complete); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 495 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 496 | if (ClangModulesDeclVendor *decl_vendor = |
| 497 | target_sp->GetClangModulesDeclVendor()) { |
| 498 | ClangPersistentVariables *clang_persistent_vars = |
| 499 | llvm::cast<ClangPersistentVariables>( |
| 500 | target_sp->GetPersistentExpressionStateForLanguage( |
| 501 | lldb::eLanguageTypeC)); |
| 502 | std::unique_ptr<PPCallbacks> pp_callbacks( |
| 503 | new LLDBPreprocessorCallbacks(*decl_vendor, *clang_persistent_vars)); |
| 504 | m_pp_callbacks = |
| 505 | static_cast<LLDBPreprocessorCallbacks *>(pp_callbacks.get()); |
| 506 | m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks)); |
| 507 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 508 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 509 | // 8. Most of this we get from the CompilerInstance, but we also want to give |
| 510 | // the context an ExternalASTSource. |
Raphael Isemann | 778b308 | 2018-08-23 20:40:45 +0000 | [diff] [blame] | 511 | |
| 512 | auto &PP = m_compiler->getPreprocessor(); |
| 513 | auto &builtin_context = PP.getBuiltinInfo(); |
| 514 | builtin_context.initializeBuiltins(PP.getIdentifierTable(), |
| 515 | m_compiler->getLangOpts()); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 516 | |
Raphael Isemann | 596709d | 2018-08-27 15:18:33 +0000 | [diff] [blame] | 517 | m_compiler->createASTContext(); |
| 518 | clang::ASTContext &ast_context = m_compiler->getASTContext(); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 519 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 520 | ClangExpressionHelper *type_system_helper = |
| 521 | dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper()); |
| 522 | ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap(); |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 523 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 524 | if (decl_map) { |
| 525 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source( |
| 526 | decl_map->CreateProxy()); |
Raphael Isemann | 596709d | 2018-08-27 15:18:33 +0000 | [diff] [blame] | 527 | decl_map->InstallASTContext(ast_context, m_compiler->getFileManager()); |
| 528 | ast_context.setExternalSource(ast_source); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | m_ast_context.reset( |
| 532 | new ClangASTContext(m_compiler->getTargetOpts().Triple.c_str())); |
Raphael Isemann | 596709d | 2018-08-27 15:18:33 +0000 | [diff] [blame] | 533 | m_ast_context->setASTContext(&ast_context); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 534 | |
| 535 | std::string module_name("$__lldb_module"); |
| 536 | |
| 537 | m_llvm_context.reset(new LLVMContext()); |
| 538 | m_code_generator.reset(CreateLLVMCodeGen( |
| 539 | m_compiler->getDiagnostics(), module_name, |
| 540 | m_compiler->getHeaderSearchOpts(), m_compiler->getPreprocessorOpts(), |
| 541 | m_compiler->getCodeGenOpts(), *m_llvm_context)); |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 544 | ClangExpressionParser::~ClangExpressionParser() {} |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 545 | |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 546 | namespace { |
| 547 | |
| 548 | //---------------------------------------------------------------------- |
| 549 | /// @class CodeComplete |
| 550 | /// |
| 551 | /// A code completion consumer for the clang Sema that is responsible for |
| 552 | /// creating the completion suggestions when a user requests completion |
| 553 | /// of an incomplete `expr` invocation. |
| 554 | //---------------------------------------------------------------------- |
| 555 | class CodeComplete : public CodeCompleteConsumer { |
Raphael Isemann | 39ec6e7 | 2018-08-30 19:47:53 +0000 | [diff] [blame] | 556 | CodeCompletionTUInfo m_info; |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 557 | |
Raphael Isemann | 39ec6e7 | 2018-08-30 19:47:53 +0000 | [diff] [blame] | 558 | std::string m_expr; |
| 559 | unsigned m_position = 0; |
Raphael Isemann | c11a780 | 2018-08-30 21:26:32 +0000 | [diff] [blame] | 560 | CompletionRequest &m_request; |
Raphael Isemann | 9dd34c8 | 2018-09-17 12:06:07 +0000 | [diff] [blame] | 561 | /// The printing policy we use when printing declarations for our completion |
| 562 | /// descriptions. |
| 563 | clang::PrintingPolicy m_desc_policy; |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 564 | |
| 565 | /// Returns true if the given character can be used in an identifier. |
| 566 | /// This also returns true for numbers because for completion we usually |
| 567 | /// just iterate backwards over iterators. |
| 568 | /// |
| 569 | /// Note: lldb uses '$' in its internal identifiers, so we also allow this. |
| 570 | static bool IsIdChar(char c) { |
| 571 | return c == '_' || std::isalnum(c) || c == '$'; |
| 572 | } |
| 573 | |
| 574 | /// Returns true if the given character is used to separate arguments |
| 575 | /// in the command line of lldb. |
| 576 | static bool IsTokenSeparator(char c) { return c == ' ' || c == '\t'; } |
| 577 | |
| 578 | /// Drops all tokens in front of the expression that are unrelated for |
| 579 | /// the completion of the cmd line. 'unrelated' means here that the token |
| 580 | /// is not interested for the lldb completion API result. |
| 581 | StringRef dropUnrelatedFrontTokens(StringRef cmd) { |
| 582 | if (cmd.empty()) |
| 583 | return cmd; |
| 584 | |
| 585 | // If we are at the start of a word, then all tokens are unrelated to |
| 586 | // the current completion logic. |
| 587 | if (IsTokenSeparator(cmd.back())) |
| 588 | return StringRef(); |
| 589 | |
| 590 | // Remove all previous tokens from the string as they are unrelated |
| 591 | // to completing the current token. |
| 592 | StringRef to_remove = cmd; |
| 593 | while (!to_remove.empty() && !IsTokenSeparator(to_remove.back())) { |
| 594 | to_remove = to_remove.drop_back(); |
| 595 | } |
| 596 | cmd = cmd.drop_front(to_remove.size()); |
| 597 | |
| 598 | return cmd; |
| 599 | } |
| 600 | |
| 601 | /// Removes the last identifier token from the given cmd line. |
| 602 | StringRef removeLastToken(StringRef cmd) { |
| 603 | while (!cmd.empty() && IsIdChar(cmd.back())) { |
| 604 | cmd = cmd.drop_back(); |
| 605 | } |
| 606 | return cmd; |
| 607 | } |
| 608 | |
| 609 | /// Attemps to merge the given completion from the given position into the |
| 610 | /// existing command. Returns the completion string that can be returned to |
| 611 | /// the lldb completion API. |
| 612 | std::string mergeCompletion(StringRef existing, unsigned pos, |
| 613 | StringRef completion) { |
| 614 | StringRef existing_command = existing.substr(0, pos); |
| 615 | // We rewrite the last token with the completion, so let's drop that |
| 616 | // token from the command. |
| 617 | existing_command = removeLastToken(existing_command); |
| 618 | // We also should remove all previous tokens from the command as they |
| 619 | // would otherwise be added to the completion that already has the |
| 620 | // completion. |
| 621 | existing_command = dropUnrelatedFrontTokens(existing_command); |
| 622 | return existing_command.str() + completion.str(); |
| 623 | } |
| 624 | |
| 625 | public: |
| 626 | /// Constructs a CodeComplete consumer that can be attached to a Sema. |
| 627 | /// @param[out] matches |
| 628 | /// The list of matches that the lldb completion API expects as a result. |
| 629 | /// This may already contain matches, so it's only allowed to append |
| 630 | /// to this variable. |
| 631 | /// @param[out] expr |
| 632 | /// The whole expression string that we are currently parsing. This |
| 633 | /// string needs to be equal to the input the user typed, and NOT the |
| 634 | /// final code that Clang is parsing. |
| 635 | /// @param[out] position |
| 636 | /// The character position of the user cursor in the `expr` parameter. |
| 637 | /// |
Raphael Isemann | 9dd34c8 | 2018-09-17 12:06:07 +0000 | [diff] [blame] | 638 | CodeComplete(CompletionRequest &request, clang::LangOptions ops, |
| 639 | std::string expr, unsigned position) |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 640 | : CodeCompleteConsumer(CodeCompleteOptions(), false), |
Raphael Isemann | 39ec6e7 | 2018-08-30 19:47:53 +0000 | [diff] [blame] | 641 | m_info(std::make_shared<GlobalCodeCompletionAllocator>()), m_expr(expr), |
Raphael Isemann | 9dd34c8 | 2018-09-17 12:06:07 +0000 | [diff] [blame] | 642 | m_position(position), m_request(request), m_desc_policy(ops) { |
| 643 | |
| 644 | // Ensure that the printing policy is producing a description that is as |
| 645 | // short as possible. |
| 646 | m_desc_policy.SuppressScope = true; |
| 647 | m_desc_policy.SuppressTagKeyword = true; |
| 648 | m_desc_policy.FullyQualifiedName = false; |
| 649 | m_desc_policy.TerseOutput = true; |
| 650 | m_desc_policy.IncludeNewlines = false; |
| 651 | m_desc_policy.UseVoidForZeroParams = false; |
| 652 | m_desc_policy.Bool = true; |
| 653 | } |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 654 | |
| 655 | /// Deregisters and destroys this code-completion consumer. |
| 656 | virtual ~CodeComplete() {} |
| 657 | |
| 658 | /// \name Code-completion filtering |
| 659 | /// Check if the result should be filtered out. |
| 660 | bool isResultFilteredOut(StringRef Filter, |
| 661 | CodeCompletionResult Result) override { |
| 662 | // This code is mostly copied from CodeCompleteConsumer. |
| 663 | switch (Result.Kind) { |
| 664 | case CodeCompletionResult::RK_Declaration: |
| 665 | return !( |
| 666 | Result.Declaration->getIdentifier() && |
| 667 | Result.Declaration->getIdentifier()->getName().startswith(Filter)); |
| 668 | case CodeCompletionResult::RK_Keyword: |
| 669 | return !StringRef(Result.Keyword).startswith(Filter); |
| 670 | case CodeCompletionResult::RK_Macro: |
| 671 | return !Result.Macro->getName().startswith(Filter); |
| 672 | case CodeCompletionResult::RK_Pattern: |
| 673 | return !StringRef(Result.Pattern->getAsString()).startswith(Filter); |
| 674 | } |
| 675 | // If we trigger this assert or the above switch yields a warning, then |
| 676 | // CodeCompletionResult has been enhanced with more kinds of completion |
| 677 | // results. Expand the switch above in this case. |
| 678 | assert(false && "Unknown completion result type?"); |
| 679 | // If we reach this, then we should just ignore whatever kind of unknown |
| 680 | // result we got back. We probably can't turn it into any kind of useful |
| 681 | // completion suggestion with the existing code. |
| 682 | return true; |
| 683 | } |
| 684 | |
| 685 | /// \name Code-completion callbacks |
| 686 | /// Process the finalized code-completion results. |
| 687 | void ProcessCodeCompleteResults(Sema &SemaRef, CodeCompletionContext Context, |
| 688 | CodeCompletionResult *Results, |
| 689 | unsigned NumResults) override { |
| 690 | |
| 691 | // The Sema put the incomplete token we try to complete in here during |
| 692 | // lexing, so we need to retrieve it here to know what we are completing. |
| 693 | StringRef Filter = SemaRef.getPreprocessor().getCodeCompletionFilter(); |
| 694 | |
| 695 | // Iterate over all the results. Filter out results we don't want and |
| 696 | // process the rest. |
| 697 | for (unsigned I = 0; I != NumResults; ++I) { |
| 698 | // Filter the results with the information from the Sema. |
| 699 | if (!Filter.empty() && isResultFilteredOut(Filter, Results[I])) |
| 700 | continue; |
| 701 | |
| 702 | CodeCompletionResult &R = Results[I]; |
| 703 | std::string ToInsert; |
Raphael Isemann | 9dd34c8 | 2018-09-17 12:06:07 +0000 | [diff] [blame] | 704 | std::string Description; |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 705 | // Handle the different completion kinds that come from the Sema. |
| 706 | switch (R.Kind) { |
| 707 | case CodeCompletionResult::RK_Declaration: { |
| 708 | const NamedDecl *D = R.Declaration; |
| 709 | ToInsert = R.Declaration->getNameAsString(); |
| 710 | // If we have a function decl that has no arguments we want to |
| 711 | // complete the empty parantheses for the user. If the function has |
| 712 | // arguments, we at least complete the opening bracket. |
| 713 | if (const FunctionDecl *F = dyn_cast<FunctionDecl>(D)) { |
| 714 | if (F->getNumParams() == 0) |
| 715 | ToInsert += "()"; |
| 716 | else |
| 717 | ToInsert += "("; |
Raphael Isemann | 9dd34c8 | 2018-09-17 12:06:07 +0000 | [diff] [blame] | 718 | raw_string_ostream OS(Description); |
| 719 | F->print(OS, m_desc_policy, false); |
| 720 | OS.flush(); |
| 721 | } else if (const VarDecl *V = dyn_cast<VarDecl>(D)) { |
| 722 | Description = V->getType().getAsString(m_desc_policy); |
| 723 | } else if (const FieldDecl *F = dyn_cast<FieldDecl>(D)) { |
| 724 | Description = F->getType().getAsString(m_desc_policy); |
| 725 | } else if (const NamespaceDecl *N = dyn_cast<NamespaceDecl>(D)) { |
| 726 | // If we try to complete a namespace, then we can directly append |
| 727 | // the '::'. |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 728 | if (!N->isAnonymousNamespace()) |
| 729 | ToInsert += "::"; |
| 730 | } |
| 731 | break; |
| 732 | } |
| 733 | case CodeCompletionResult::RK_Keyword: |
| 734 | ToInsert = R.Keyword; |
| 735 | break; |
| 736 | case CodeCompletionResult::RK_Macro: |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 737 | ToInsert = R.Macro->getName().str(); |
| 738 | break; |
| 739 | case CodeCompletionResult::RK_Pattern: |
| 740 | ToInsert = R.Pattern->getTypedText(); |
| 741 | break; |
| 742 | } |
| 743 | // At this point all information is in the ToInsert string. |
| 744 | |
| 745 | // We also filter some internal lldb identifiers here. The user |
| 746 | // shouldn't see these. |
| 747 | if (StringRef(ToInsert).startswith("$__lldb_")) |
| 748 | continue; |
| 749 | if (!ToInsert.empty()) { |
| 750 | // Merge the suggested Token into the existing command line to comply |
| 751 | // with the kind of result the lldb API expects. |
| 752 | std::string CompletionSuggestion = |
Raphael Isemann | 39ec6e7 | 2018-08-30 19:47:53 +0000 | [diff] [blame] | 753 | mergeCompletion(m_expr, m_position, ToInsert); |
Raphael Isemann | 9dd34c8 | 2018-09-17 12:06:07 +0000 | [diff] [blame] | 754 | m_request.AddCompletion(CompletionSuggestion, Description); |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | /// \param S the semantic-analyzer object for which code-completion is being |
| 760 | /// done. |
| 761 | /// |
| 762 | /// \param CurrentArg the index of the current argument. |
| 763 | /// |
| 764 | /// \param Candidates an array of overload candidates. |
| 765 | /// |
| 766 | /// \param NumCandidates the number of overload candidates |
| 767 | void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, |
| 768 | OverloadCandidate *Candidates, |
| 769 | unsigned NumCandidates, |
| 770 | SourceLocation OpenParLoc) override { |
| 771 | // At the moment we don't filter out any overloaded candidates. |
| 772 | } |
| 773 | |
| 774 | CodeCompletionAllocator &getAllocator() override { |
Raphael Isemann | 39ec6e7 | 2018-08-30 19:47:53 +0000 | [diff] [blame] | 775 | return m_info.getAllocator(); |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Raphael Isemann | 39ec6e7 | 2018-08-30 19:47:53 +0000 | [diff] [blame] | 778 | CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return m_info; } |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 779 | }; |
| 780 | } // namespace |
| 781 | |
Raphael Isemann | c11a780 | 2018-08-30 21:26:32 +0000 | [diff] [blame] | 782 | bool ClangExpressionParser::Complete(CompletionRequest &request, unsigned line, |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 783 | unsigned pos, unsigned typed_pos) { |
| 784 | DiagnosticManager mgr; |
| 785 | // We need the raw user expression here because that's what the CodeComplete |
| 786 | // class uses to provide completion suggestions. |
| 787 | // However, the `Text` method only gives us the transformed expression here. |
| 788 | // To actually get the raw user input here, we have to cast our expression to |
| 789 | // the LLVMUserExpression which exposes the right API. This should never fail |
| 790 | // as we always have a ClangUserExpression whenever we call this. |
| 791 | LLVMUserExpression &llvm_expr = *static_cast<LLVMUserExpression *>(&m_expr); |
Raphael Isemann | 9dd34c8 | 2018-09-17 12:06:07 +0000 | [diff] [blame] | 792 | CodeComplete CC(request, m_compiler->getLangOpts(), llvm_expr.GetUserText(), |
| 793 | typed_pos); |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 794 | // We don't need a code generator for parsing. |
| 795 | m_code_generator.reset(); |
| 796 | // Start parsing the expression with our custom code completion consumer. |
| 797 | ParseInternal(mgr, &CC, line, pos); |
| 798 | return true; |
| 799 | } |
| 800 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 801 | unsigned ClangExpressionParser::Parse(DiagnosticManager &diagnostic_manager) { |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 802 | return ParseInternal(diagnostic_manager); |
| 803 | } |
| 804 | |
| 805 | unsigned |
| 806 | ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager, |
| 807 | CodeCompleteConsumer *completion_consumer, |
| 808 | unsigned completion_line, |
| 809 | unsigned completion_column) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 810 | ClangDiagnosticManagerAdapter *adapter = |
| 811 | static_cast<ClangDiagnosticManagerAdapter *>( |
| 812 | m_compiler->getDiagnostics().getClient()); |
| 813 | clang::TextDiagnosticBuffer *diag_buf = adapter->GetPassthrough(); |
| 814 | diag_buf->FlushDiagnostics(m_compiler->getDiagnostics()); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 815 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 816 | adapter->ResetManager(&diagnostic_manager); |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 817 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 818 | const char *expr_text = m_expr.Text(); |
Rafael Espindola | 9cb97b6 | 2014-05-21 15:08:27 +0000 | [diff] [blame] | 819 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 820 | clang::SourceManager &source_mgr = m_compiler->getSourceManager(); |
| 821 | bool created_main_file = false; |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 822 | |
| 823 | // Clang wants to do completion on a real file known by Clang's file manager, |
| 824 | // so we have to create one to make this work. |
| 825 | // TODO: We probably could also simulate to Clang's file manager that there |
| 826 | // is a real file that contains our code. |
| 827 | bool should_create_file = completion_consumer != nullptr; |
| 828 | |
| 829 | // We also want a real file on disk if we generate full debug info. |
| 830 | should_create_file |= m_compiler->getCodeGenOpts().getDebugInfo() == |
| 831 | codegenoptions::FullDebugInfo; |
| 832 | |
| 833 | if (should_create_file) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 834 | int temp_fd = -1; |
| 835 | llvm::SmallString<PATH_MAX> result_path; |
Pavel Labath | 60f028f | 2018-06-19 15:09:07 +0000 | [diff] [blame] | 836 | if (FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 837 | tmpdir_file_spec.AppendPathComponent("lldb-%%%%%%.expr"); |
| 838 | std::string temp_source_path = tmpdir_file_spec.GetPath(); |
| 839 | llvm::sys::fs::createUniqueFile(temp_source_path, temp_fd, result_path); |
| 840 | } else { |
| 841 | llvm::sys::fs::createTemporaryFile("lldb", "expr", temp_fd, result_path); |
| 842 | } |
| 843 | |
| 844 | if (temp_fd != -1) { |
| 845 | lldb_private::File file(temp_fd, true); |
| 846 | const size_t expr_text_len = strlen(expr_text); |
| 847 | size_t bytes_written = expr_text_len; |
| 848 | if (file.Write(expr_text, bytes_written).Success()) { |
| 849 | if (bytes_written == expr_text_len) { |
| 850 | file.Close(); |
| 851 | source_mgr.setMainFileID( |
| 852 | source_mgr.createFileID(m_file_manager->getFile(result_path), |
| 853 | SourceLocation(), SrcMgr::C_User)); |
| 854 | created_main_file = true; |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 855 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 856 | } |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 857 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 858 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 859 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 860 | if (!created_main_file) { |
| 861 | std::unique_ptr<MemoryBuffer> memory_buffer = |
| 862 | MemoryBuffer::getMemBufferCopy(expr_text, __FUNCTION__); |
| 863 | source_mgr.setMainFileID(source_mgr.createFileID(std::move(memory_buffer))); |
| 864 | } |
| 865 | |
| 866 | diag_buf->BeginSourceFile(m_compiler->getLangOpts(), |
| 867 | &m_compiler->getPreprocessor()); |
| 868 | |
| 869 | ClangExpressionHelper *type_system_helper = |
| 870 | dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper()); |
| 871 | |
| 872 | ASTConsumer *ast_transformer = |
| 873 | type_system_helper->ASTTransformer(m_code_generator.get()); |
| 874 | |
| 875 | if (ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap()) |
| 876 | decl_map->InstallCodeGenerator(m_code_generator.get()); |
| 877 | |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 878 | // If we want to parse for code completion, we need to attach our code |
| 879 | // completion consumer to the Sema and specify a completion position. |
| 880 | // While parsing the Sema will call this consumer with the provided |
| 881 | // completion suggestions. |
| 882 | if (completion_consumer) { |
| 883 | auto main_file = source_mgr.getFileEntryForID(source_mgr.getMainFileID()); |
| 884 | auto &PP = m_compiler->getPreprocessor(); |
| 885 | // Lines and columns start at 1 in Clang, but code completion positions are |
| 886 | // indexed from 0, so we need to add 1 to the line and column here. |
| 887 | ++completion_line; |
| 888 | ++completion_column; |
| 889 | PP.SetCodeCompletionPoint(main_file, completion_line, completion_column); |
| 890 | } |
| 891 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 892 | if (ast_transformer) { |
| 893 | ast_transformer->Initialize(m_compiler->getASTContext()); |
| 894 | ParseAST(m_compiler->getPreprocessor(), ast_transformer, |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 895 | m_compiler->getASTContext(), false, TU_Complete, |
| 896 | completion_consumer); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 897 | } else { |
| 898 | m_code_generator->Initialize(m_compiler->getASTContext()); |
| 899 | ParseAST(m_compiler->getPreprocessor(), m_code_generator.get(), |
Raphael Isemann | 7482973 | 2018-08-30 17:29:37 +0000 | [diff] [blame] | 900 | m_compiler->getASTContext(), false, TU_Complete, |
| 901 | completion_consumer); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | diag_buf->EndSourceFile(); |
| 905 | |
| 906 | unsigned num_errors = diag_buf->getNumErrors(); |
| 907 | |
| 908 | if (m_pp_callbacks && m_pp_callbacks->hasErrors()) { |
| 909 | num_errors++; |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 910 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 911 | "while importing modules:"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 912 | diagnostic_manager.AppendMessageToDiagnostic( |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 913 | m_pp_callbacks->getErrorString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | if (!num_errors) { |
| 917 | if (type_system_helper->DeclMap() && |
| 918 | !type_system_helper->DeclMap()->ResolveUnknownTypes()) { |
| 919 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 920 | "Couldn't infer the type of a variable"); |
| 921 | num_errors++; |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 922 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 923 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 924 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 925 | if (!num_errors) { |
| 926 | type_system_helper->CommitPersistentDecls(); |
| 927 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 928 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 929 | adapter->ResetManager(); |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 930 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 931 | return num_errors; |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Sagar Thakur | adc1abe | 2016-05-13 11:04:47 +0000 | [diff] [blame] | 934 | std::string |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 935 | ClangExpressionParser::GetClangTargetABI(const ArchSpec &target_arch) { |
| 936 | std::string abi; |
| 937 | |
| 938 | if (target_arch.IsMIPS()) { |
| 939 | switch (target_arch.GetFlags() & ArchSpec::eMIPSABI_mask) { |
| 940 | case ArchSpec::eMIPSABI_N64: |
| 941 | abi = "n64"; |
| 942 | break; |
| 943 | case ArchSpec::eMIPSABI_N32: |
| 944 | abi = "n32"; |
| 945 | break; |
| 946 | case ArchSpec::eMIPSABI_O32: |
| 947 | abi = "o32"; |
| 948 | break; |
| 949 | default: |
| 950 | break; |
Sagar Thakur | adc1abe | 2016-05-13 11:04:47 +0000 | [diff] [blame] | 951 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 952 | } |
| 953 | return abi; |
Sagar Thakur | adc1abe | 2016-05-13 11:04:47 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 956 | bool ClangExpressionParser::RewriteExpression( |
| 957 | DiagnosticManager &diagnostic_manager) { |
| 958 | clang::SourceManager &source_manager = m_compiler->getSourceManager(); |
| 959 | clang::edit::EditedSource editor(source_manager, m_compiler->getLangOpts(), |
| 960 | nullptr); |
| 961 | clang::edit::Commit commit(editor); |
| 962 | clang::Rewriter rewriter(source_manager, m_compiler->getLangOpts()); |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 963 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 964 | class RewritesReceiver : public edit::EditsReceiver { |
| 965 | Rewriter &rewrite; |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 966 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 967 | public: |
| 968 | RewritesReceiver(Rewriter &in_rewrite) : rewrite(in_rewrite) {} |
| 969 | |
| 970 | void insert(SourceLocation loc, StringRef text) override { |
| 971 | rewrite.InsertText(loc, text); |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 972 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 973 | void replace(CharSourceRange range, StringRef text) override { |
| 974 | rewrite.ReplaceText(range.getBegin(), rewrite.getRangeSize(range), text); |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 975 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 976 | }; |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 977 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 978 | RewritesReceiver rewrites_receiver(rewriter); |
| 979 | |
| 980 | const DiagnosticList &diagnostics = diagnostic_manager.Diagnostics(); |
| 981 | size_t num_diags = diagnostics.size(); |
| 982 | if (num_diags == 0) |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 983 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 984 | |
| 985 | for (const Diagnostic *diag : diagnostic_manager.Diagnostics()) { |
| 986 | const ClangDiagnostic *diagnostic = llvm::dyn_cast<ClangDiagnostic>(diag); |
| 987 | if (diagnostic && diagnostic->HasFixIts()) { |
| 988 | for (const FixItHint &fixit : diagnostic->FixIts()) { |
| 989 | // This is cobbed from clang::Rewrite::FixItRewriter. |
| 990 | if (fixit.CodeToInsert.empty()) { |
| 991 | if (fixit.InsertFromRange.isValid()) { |
| 992 | commit.insertFromRange(fixit.RemoveRange.getBegin(), |
| 993 | fixit.InsertFromRange, /*afterToken=*/false, |
| 994 | fixit.BeforePreviousInsertions); |
| 995 | } else |
| 996 | commit.remove(fixit.RemoveRange); |
| 997 | } else { |
| 998 | if (fixit.RemoveRange.isTokenRange() || |
| 999 | fixit.RemoveRange.getBegin() != fixit.RemoveRange.getEnd()) |
| 1000 | commit.replace(fixit.RemoveRange, fixit.CodeToInsert); |
| 1001 | else |
| 1002 | commit.insert(fixit.RemoveRange.getBegin(), fixit.CodeToInsert, |
| 1003 | /*afterToken=*/false, fixit.BeforePreviousInsertions); |
| 1004 | } |
| 1005 | } |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | // FIXME - do we want to try to propagate specific errors here? |
| 1010 | if (!commit.isCommitable()) |
| 1011 | return false; |
| 1012 | else if (!editor.commit(commit)) |
| 1013 | return false; |
| 1014 | |
| 1015 | // Now play all the edits, and stash the result in the diagnostic manager. |
| 1016 | editor.applyRewrites(rewrites_receiver); |
| 1017 | RewriteBuffer &main_file_buffer = |
| 1018 | rewriter.getEditBuffer(source_manager.getMainFileID()); |
| 1019 | |
| 1020 | std::string fixed_expression; |
| 1021 | llvm::raw_string_ostream out_stream(fixed_expression); |
| 1022 | |
| 1023 | main_file_buffer.write(out_stream); |
| 1024 | out_stream.flush(); |
| 1025 | diagnostic_manager.SetFixedExpression(fixed_expression); |
| 1026 | |
| 1027 | return true; |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1030 | static bool FindFunctionInModule(ConstString &mangled_name, |
| 1031 | llvm::Module *module, const char *orig_name) { |
| 1032 | for (const auto &func : module->getFunctionList()) { |
| 1033 | const StringRef &name = func.getName(); |
| 1034 | if (name.find(orig_name) != StringRef::npos) { |
| 1035 | mangled_name.SetString(name); |
| 1036 | return true; |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 1037 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1038 | } |
Sylvestre Ledru | ceab3ac | 2014-07-06 17:54:58 +0000 | [diff] [blame] | 1039 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1040 | return false; |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 1041 | } |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 1042 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1043 | lldb_private::Status ClangExpressionParser::PrepareForExecution( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1044 | lldb::addr_t &func_addr, lldb::addr_t &func_end, |
| 1045 | lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx, |
| 1046 | bool &can_interpret, ExecutionPolicy execution_policy) { |
| 1047 | func_addr = LLDB_INVALID_ADDRESS; |
| 1048 | func_end = LLDB_INVALID_ADDRESS; |
| 1049 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
| 1050 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1051 | lldb_private::Status err; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1052 | |
| 1053 | std::unique_ptr<llvm::Module> llvm_module_ap( |
| 1054 | m_code_generator->ReleaseModule()); |
| 1055 | |
| 1056 | if (!llvm_module_ap.get()) { |
| 1057 | err.SetErrorToGenericError(); |
| 1058 | err.SetErrorString("IR doesn't contain a module"); |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 1059 | return err; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | ConstString function_name; |
| 1063 | |
| 1064 | if (execution_policy != eExecutionPolicyTopLevel) { |
| 1065 | // Find the actual name of the function (it's often mangled somehow) |
| 1066 | |
| 1067 | if (!FindFunctionInModule(function_name, llvm_module_ap.get(), |
| 1068 | m_expr.FunctionName())) { |
| 1069 | err.SetErrorToGenericError(); |
| 1070 | err.SetErrorStringWithFormat("Couldn't find %s() in the module", |
| 1071 | m_expr.FunctionName()); |
| 1072 | return err; |
| 1073 | } else { |
| 1074 | if (log) |
| 1075 | log->Printf("Found function %s for %s", function_name.AsCString(), |
| 1076 | m_expr.FunctionName()); |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | SymbolContext sc; |
| 1081 | |
| 1082 | if (lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP()) { |
| 1083 | sc = frame_sp->GetSymbolContext(lldb::eSymbolContextEverything); |
| 1084 | } else if (lldb::TargetSP target_sp = exe_ctx.GetTargetSP()) { |
| 1085 | sc.target_sp = target_sp; |
| 1086 | } |
| 1087 | |
| 1088 | LLVMUserExpression::IRPasses custom_passes; |
| 1089 | { |
| 1090 | auto lang = m_expr.Language(); |
| 1091 | if (log) |
Bruce Mitchener | 4ebdee0 | 2018-05-29 09:10:46 +0000 | [diff] [blame] | 1092 | log->Printf("%s - Current expression language is %s\n", __FUNCTION__, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1093 | Language::GetNameForLanguageType(lang)); |
Jim Ingham | 2256215 | 2016-11-03 23:42:09 +0000 | [diff] [blame] | 1094 | lldb::ProcessSP process_sp = exe_ctx.GetProcessSP(); |
| 1095 | if (process_sp && lang != lldb::eLanguageTypeUnknown) { |
| 1096 | auto runtime = process_sp->GetLanguageRuntime(lang); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1097 | if (runtime) |
| 1098 | runtime->GetIRPasses(custom_passes); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | if (custom_passes.EarlyPasses) { |
| 1103 | if (log) |
| 1104 | log->Printf("%s - Running Early IR Passes from LanguageRuntime on " |
| 1105 | "expression module '%s'", |
| 1106 | __FUNCTION__, m_expr.FunctionName()); |
| 1107 | |
| 1108 | custom_passes.EarlyPasses->run(*llvm_module_ap); |
| 1109 | } |
| 1110 | |
| 1111 | execution_unit_sp.reset( |
| 1112 | new IRExecutionUnit(m_llvm_context, // handed off here |
| 1113 | llvm_module_ap, // handed off here |
| 1114 | function_name, exe_ctx.GetTargetSP(), sc, |
| 1115 | m_compiler->getTargetOpts().Features)); |
| 1116 | |
| 1117 | ClangExpressionHelper *type_system_helper = |
| 1118 | dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper()); |
| 1119 | ClangExpressionDeclMap *decl_map = |
| 1120 | type_system_helper->DeclMap(); // result can be NULL |
| 1121 | |
| 1122 | if (decl_map) { |
| 1123 | Stream *error_stream = NULL; |
| 1124 | Target *target = exe_ctx.GetTargetPtr(); |
| 1125 | error_stream = target->GetDebugger().GetErrorFile().get(); |
| 1126 | |
| 1127 | IRForTarget ir_for_target(decl_map, m_expr.NeedsVariableResolution(), |
| 1128 | *execution_unit_sp, *error_stream, |
| 1129 | function_name.AsCString()); |
| 1130 | |
| 1131 | bool ir_can_run = |
| 1132 | ir_for_target.runOnModule(*execution_unit_sp->GetModule()); |
| 1133 | |
| 1134 | if (!ir_can_run) { |
| 1135 | err.SetErrorString( |
| 1136 | "The expression could not be prepared to run in the target"); |
| 1137 | return err; |
| 1138 | } |
| 1139 | |
| 1140 | Process *process = exe_ctx.GetProcessPtr(); |
| 1141 | |
| 1142 | if (execution_policy != eExecutionPolicyAlways && |
| 1143 | execution_policy != eExecutionPolicyTopLevel) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1144 | lldb_private::Status interpret_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1145 | |
| 1146 | bool interpret_function_calls = |
| 1147 | !process ? false : process->CanInterpretFunctionCalls(); |
| 1148 | can_interpret = IRInterpreter::CanInterpret( |
| 1149 | *execution_unit_sp->GetModule(), *execution_unit_sp->GetFunction(), |
| 1150 | interpret_error, interpret_function_calls); |
| 1151 | |
| 1152 | if (!can_interpret && execution_policy == eExecutionPolicyNever) { |
| 1153 | err.SetErrorStringWithFormat("Can't run the expression locally: %s", |
| 1154 | interpret_error.AsCString()); |
| 1155 | return err; |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | if (!process && execution_policy == eExecutionPolicyAlways) { |
| 1160 | err.SetErrorString("Expression needed to run in the target, but the " |
| 1161 | "target can't be run"); |
| 1162 | return err; |
| 1163 | } |
| 1164 | |
| 1165 | if (!process && execution_policy == eExecutionPolicyTopLevel) { |
| 1166 | err.SetErrorString("Top-level code needs to be inserted into a runnable " |
| 1167 | "target, but the target can't be run"); |
| 1168 | return err; |
| 1169 | } |
| 1170 | |
| 1171 | if (execution_policy == eExecutionPolicyAlways || |
| 1172 | (execution_policy != eExecutionPolicyTopLevel && !can_interpret)) { |
| 1173 | if (m_expr.NeedsValidation() && process) { |
| 1174 | if (!process->GetDynamicCheckers()) { |
| 1175 | DynamicCheckerFunctions *dynamic_checkers = |
| 1176 | new DynamicCheckerFunctions(); |
| 1177 | |
| 1178 | DiagnosticManager install_diagnostics; |
| 1179 | |
| 1180 | if (!dynamic_checkers->Install(install_diagnostics, exe_ctx)) { |
| 1181 | if (install_diagnostics.Diagnostics().size()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1182 | err.SetErrorString(install_diagnostics.GetString().c_str()); |
Raphael Isemann | 262dd8c | 2018-09-11 13:59:47 +0000 | [diff] [blame] | 1183 | else |
| 1184 | err.SetErrorString("couldn't install checkers, unknown error"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1185 | |
| 1186 | return err; |
| 1187 | } |
| 1188 | |
| 1189 | process->SetDynamicCheckers(dynamic_checkers); |
| 1190 | |
| 1191 | if (log) |
| 1192 | log->Printf("== [ClangUserExpression::Evaluate] Finished " |
| 1193 | "installing dynamic checkers =="); |
| 1194 | } |
| 1195 | |
| 1196 | IRDynamicChecks ir_dynamic_checks(*process->GetDynamicCheckers(), |
| 1197 | function_name.AsCString()); |
| 1198 | |
| 1199 | llvm::Module *module = execution_unit_sp->GetModule(); |
| 1200 | if (!module || !ir_dynamic_checks.runOnModule(*module)) { |
| 1201 | err.SetErrorToGenericError(); |
| 1202 | err.SetErrorString("Couldn't add dynamic checks to the expression"); |
| 1203 | return err; |
| 1204 | } |
| 1205 | |
| 1206 | if (custom_passes.LatePasses) { |
| 1207 | if (log) |
| 1208 | log->Printf("%s - Running Late IR Passes from LanguageRuntime on " |
| 1209 | "expression module '%s'", |
| 1210 | __FUNCTION__, m_expr.FunctionName()); |
| 1211 | |
| 1212 | custom_passes.LatePasses->run(*module); |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | if (execution_policy == eExecutionPolicyAlways || |
| 1218 | execution_policy == eExecutionPolicyTopLevel || !can_interpret) { |
| 1219 | execution_unit_sp->GetRunnableInfo(err, func_addr, func_end); |
| 1220 | } |
| 1221 | } else { |
| 1222 | execution_unit_sp->GetRunnableInfo(err, func_addr, func_end); |
| 1223 | } |
| 1224 | |
| 1225 | return err; |
| 1226 | } |
| 1227 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1228 | lldb_private::Status ClangExpressionParser::RunStaticInitializers( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1229 | lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1230 | lldb_private::Status err; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1231 | |
| 1232 | lldbassert(execution_unit_sp.get()); |
| 1233 | lldbassert(exe_ctx.HasThreadScope()); |
| 1234 | |
| 1235 | if (!execution_unit_sp.get()) { |
| 1236 | err.SetErrorString( |
| 1237 | "can't run static initializers for a NULL execution unit"); |
| 1238 | return err; |
| 1239 | } |
| 1240 | |
| 1241 | if (!exe_ctx.HasThreadScope()) { |
| 1242 | err.SetErrorString("can't run static initializers without a thread"); |
| 1243 | return err; |
| 1244 | } |
| 1245 | |
| 1246 | std::vector<lldb::addr_t> static_initializers; |
| 1247 | |
| 1248 | execution_unit_sp->GetStaticInitializers(static_initializers); |
| 1249 | |
| 1250 | for (lldb::addr_t static_initializer : static_initializers) { |
| 1251 | EvaluateExpressionOptions options; |
| 1252 | |
| 1253 | lldb::ThreadPlanSP call_static_initializer(new ThreadPlanCallFunction( |
| 1254 | exe_ctx.GetThreadRef(), Address(static_initializer), CompilerType(), |
| 1255 | llvm::ArrayRef<lldb::addr_t>(), options)); |
| 1256 | |
| 1257 | DiagnosticManager execution_errors; |
| 1258 | lldb::ExpressionResults results = |
| 1259 | exe_ctx.GetThreadRef().GetProcess()->RunThreadPlan( |
| 1260 | exe_ctx, call_static_initializer, options, execution_errors); |
| 1261 | |
| 1262 | if (results != lldb::eExpressionCompleted) { |
| 1263 | err.SetErrorStringWithFormat("couldn't run static initializer: %s", |
| 1264 | execution_errors.GetString().c_str()); |
| 1265 | return err; |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | return err; |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 1270 | } |