blob: bf1bd5da39b5f950f7aed06ba483929aff8d70ad [file] [log] [blame]
Jim Inghamea401ec2019-03-06 22:43:25 +00001//===-- ClangExpressionSourceCode.cpp ---------------------------*- C++ -*-===//
Sean Callanan9bc83842011-09-26 18:45:31 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Sean Callanan9bc83842011-09-26 18:45:31 +00006//
7//===----------------------------------------------------------------------===//
8
Jim Inghamea401ec2019-03-06 22:43:25 +00009#include "ClangExpressionSourceCode.h"
Sean Callanan9bc83842011-09-26 18:45:31 +000010
Raphael Isemann71569d02019-05-02 10:12:56 +000011#include "clang/Basic/CharInfo.h"
Raphael Isemann01718662019-07-10 21:04:01 +000012#include "clang/Basic/SourceManager.h"
13#include "clang/Lex/Lexer.h"
Raphael Isemann71569d02019-05-02 10:12:56 +000014#include "llvm/ADT/StringRef.h"
15
Sean Callanan4dbb2712015-09-25 20:35:58 +000016#include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
17#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000018#include "lldb/Symbol/Block.h"
Siva Chandrad8335e92015-12-16 00:22:08 +000019#include "lldb/Symbol/CompileUnit.h"
20#include "lldb/Symbol/DebugMacros.h"
Sean Callanan8f1f9a12015-09-30 19:57:57 +000021#include "lldb/Symbol/TypeSystem.h"
Siva Chandra03ff5c82016-02-05 19:10:04 +000022#include "lldb/Symbol/VariableList.h"
Jason Molendaa3329782014-03-29 18:54:20 +000023#include "lldb/Target/ExecutionContext.h"
Siva Chandra03ff5c82016-02-05 19:10:04 +000024#include "lldb/Target/Language.h"
Jason Molendaa3329782014-03-29 18:54:20 +000025#include "lldb/Target/Platform.h"
Sean Callanan68f85e72015-04-30 21:49:58 +000026#include "lldb/Target/StackFrame.h"
Jason Molendaa3329782014-03-29 18:54:20 +000027#include "lldb/Target/Target.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000028#include "lldb/Utility/StreamString.h"
Sean Callanan9bc83842011-09-26 18:45:31 +000029
30using namespace lldb_private;
31
Raphael Isemann1442efe2019-09-18 08:53:35 +000032const char *ClangExpressionSourceCode::g_expression_prefix =
33 R"(
34#line 1 "<lldb wrapper prefix>"
Raphael Isemanne21fc872019-07-18 17:58:04 +000035#ifndef offsetof
36#define offsetof(t, d) __builtin_offsetof(t, d)
37#endif
Sean Callanan68f85e72015-04-30 21:49:58 +000038#ifndef NULL
Greg Clayton399107a2013-02-13 23:57:48 +000039#define NULL (__null)
Sean Callanan68f85e72015-04-30 21:49:58 +000040#endif
41#ifndef Nil
Greg Clayton399107a2013-02-13 23:57:48 +000042#define Nil (__null)
Sean Callanan68f85e72015-04-30 21:49:58 +000043#endif
44#ifndef nil
Greg Clayton399107a2013-02-13 23:57:48 +000045#define nil (__null)
Sean Callanan68f85e72015-04-30 21:49:58 +000046#endif
47#ifndef YES
Greg Clayton399107a2013-02-13 23:57:48 +000048#define YES ((BOOL)1)
Sean Callanan68f85e72015-04-30 21:49:58 +000049#endif
50#ifndef NO
Greg Clayton399107a2013-02-13 23:57:48 +000051#define NO ((BOOL)0)
Sean Callanan68f85e72015-04-30 21:49:58 +000052#endif
Reid Kleckner56d861f2014-07-29 21:59:33 +000053typedef __INT8_TYPE__ int8_t;
54typedef __UINT8_TYPE__ uint8_t;
55typedef __INT16_TYPE__ int16_t;
56typedef __UINT16_TYPE__ uint16_t;
57typedef __INT32_TYPE__ int32_t;
58typedef __UINT32_TYPE__ uint32_t;
59typedef __INT64_TYPE__ int64_t;
60typedef __UINT64_TYPE__ uint64_t;
61typedef __INTPTR_TYPE__ intptr_t;
62typedef __UINTPTR_TYPE__ uintptr_t;
Greg Clayton399107a2013-02-13 23:57:48 +000063typedef __SIZE_TYPE__ size_t;
64typedef __PTRDIFF_TYPE__ ptrdiff_t;
65typedef unsigned short unichar;
Kate Stonecc391a02015-01-21 23:39:16 +000066extern "C"
67{
68 int printf(const char * __restrict, ...);
69}
Greg Clayton399107a2013-02-13 23:57:48 +000070)";
Sean Callanana199e822012-09-13 23:35:30 +000071
Siva Chandrad8335e92015-12-16 00:22:08 +000072namespace {
73
Kate Stoneb9c1b512016-09-06 20:57:50 +000074class AddMacroState {
75 enum State {
76 CURRENT_FILE_NOT_YET_PUSHED,
77 CURRENT_FILE_PUSHED,
78 CURRENT_FILE_POPPED
79 };
Siva Chandrad8335e92015-12-16 00:22:08 +000080
81public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 AddMacroState(const FileSpec &current_file, const uint32_t current_file_line)
83 : m_state(CURRENT_FILE_NOT_YET_PUSHED), m_current_file(current_file),
84 m_current_file_line(current_file_line) {}
Siva Chandrad8335e92015-12-16 00:22:08 +000085
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 void StartFile(const FileSpec &file) {
87 m_file_stack.push_back(file);
88 if (file == m_current_file)
89 m_state = CURRENT_FILE_PUSHED;
90 }
91
92 void EndFile() {
93 if (m_file_stack.size() == 0)
94 return;
95
96 FileSpec old_top = m_file_stack.back();
97 m_file_stack.pop_back();
98 if (old_top == m_current_file)
99 m_state = CURRENT_FILE_POPPED;
100 }
101
Adrian Prantl05097242018-04-30 16:49:04 +0000102 // An entry is valid if it occurs before the current line in the current
103 // file.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104 bool IsValidEntry(uint32_t line) {
105 switch (m_state) {
106 case CURRENT_FILE_NOT_YET_PUSHED:
107 return true;
108 case CURRENT_FILE_PUSHED:
Adrian Prantl05097242018-04-30 16:49:04 +0000109 // If we are in file included in the current file, the entry should be
110 // added.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111 if (m_file_stack.back() != m_current_file)
112 return true;
113
Jonas Devliegherea6682a42018-12-15 00:15:33 +0000114 return line < m_current_file_line;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115 default:
116 return false;
Siva Chandrad8335e92015-12-16 00:22:08 +0000117 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118 }
Siva Chandrad8335e92015-12-16 00:22:08 +0000119
120private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121 std::vector<FileSpec> m_file_stack;
122 State m_state;
123 FileSpec m_current_file;
124 uint32_t m_current_file_line;
Siva Chandrad8335e92015-12-16 00:22:08 +0000125};
126
127} // anonymous namespace
128
Kate Stoneb9c1b512016-09-06 20:57:50 +0000129static void AddMacros(const DebugMacros *dm, CompileUnit *comp_unit,
130 AddMacroState &state, StreamString &stream) {
131 if (dm == nullptr)
132 return;
133
134 for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
135 const DebugMacroEntry &entry = dm->GetMacroEntryAtIndex(i);
136 uint32_t line;
137
138 switch (entry.GetType()) {
139 case DebugMacroEntry::DEFINE:
140 if (state.IsValidEntry(entry.GetLineNumber()))
141 stream.Printf("#define %s\n", entry.GetMacroString().AsCString());
142 else
Siva Chandrad8335e92015-12-16 00:22:08 +0000143 return;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144 break;
145 case DebugMacroEntry::UNDEF:
146 if (state.IsValidEntry(entry.GetLineNumber()))
147 stream.Printf("#undef %s\n", entry.GetMacroString().AsCString());
148 else
149 return;
150 break;
151 case DebugMacroEntry::START_FILE:
152 line = entry.GetLineNumber();
153 if (state.IsValidEntry(line))
154 state.StartFile(entry.GetFileSpec(comp_unit));
155 else
156 return;
157 break;
158 case DebugMacroEntry::END_FILE:
159 state.EndFile();
160 break;
161 case DebugMacroEntry::INDIRECT:
162 AddMacros(entry.GetIndirectDebugMacros(), comp_unit, state, stream);
163 break;
Jim Inghame5ee6f02016-03-29 22:00:08 +0000164 default:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000165 // This is an unknown/invalid entry. Ignore.
166 break;
167 }
168 }
169}
170
Raphael Isemann1442efe2019-09-18 08:53:35 +0000171lldb_private::ClangExpressionSourceCode::ClangExpressionSourceCode(
172 llvm::StringRef filename, llvm::StringRef name, llvm::StringRef prefix,
173 llvm::StringRef body, Wrapping wrap)
174 : ExpressionSourceCode(name, prefix, body, wrap) {
175 // Use #line markers to pretend that we have a single-line source file
176 // containing only the user expression. This will hide our wrapper code
177 // from the user when we render diagnostics with Clang.
178 m_start_marker = "#line 1 \"" + filename.str() + "\"\n";
179 m_end_marker = "\n;\n#line 1 \"<lldb wrapper suffix>\"\n";
180}
181
Raphael Isemann01718662019-07-10 21:04:01 +0000182namespace {
183/// Allows checking if a token is contained in a given expression.
184class TokenVerifier {
185 /// The tokens we found in the expression.
186 llvm::StringSet<> m_tokens;
Raphael Isemann71569d02019-05-02 10:12:56 +0000187
Raphael Isemann01718662019-07-10 21:04:01 +0000188public:
189 TokenVerifier(std::string body);
190 /// Returns true iff the given expression body contained a token with the
191 /// given content.
192 bool hasToken(llvm::StringRef token) const {
193 return m_tokens.find(token) != m_tokens.end();
Raphael Isemann71569d02019-05-02 10:12:56 +0000194 }
Raphael Isemann01718662019-07-10 21:04:01 +0000195};
196} // namespace
197
198TokenVerifier::TokenVerifier(std::string body) {
199 using namespace clang;
200
201 // We only care about tokens and not their original source locations. If we
202 // move the whole expression to only be in one line we can simplify the
203 // following code that extracts the token contents.
204 std::replace(body.begin(), body.end(), '\n', ' ');
205 std::replace(body.begin(), body.end(), '\r', ' ');
206
207 FileSystemOptions file_opts;
208 FileManager file_mgr(file_opts,
209 FileSystem::Instance().GetVirtualFileSystem());
210
211 // Let's build the actual source code Clang needs and setup some utility
212 // objects.
213 llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_ids(new DiagnosticIDs());
214 llvm::IntrusiveRefCntPtr<DiagnosticOptions> diags_opts(
215 new DiagnosticOptions());
216 DiagnosticsEngine diags(diag_ids, diags_opts);
217 clang::SourceManager SM(diags, file_mgr);
218 auto buf = llvm::MemoryBuffer::getMemBuffer(body);
219
220 FileID FID = SM.createFileID(clang::SourceManager::Unowned, buf.get());
221
222 // Let's just enable the latest ObjC and C++ which should get most tokens
223 // right.
224 LangOptions Opts;
225 Opts.ObjC = true;
226 Opts.DollarIdents = true;
227 Opts.CPlusPlus17 = true;
228 Opts.LineComment = true;
229
230 Lexer lex(FID, buf.get(), SM, Opts);
231
232 Token token;
233 bool exit = false;
234 while (!exit) {
235 // Returns true if this is the last token we get from the lexer.
236 exit = lex.LexFromRawLexer(token);
237
238 // Extract the column number which we need to extract the token content.
239 // Our expression is just one line, so we don't need to handle any line
240 // numbers here.
241 bool invalid = false;
242 unsigned start = SM.getSpellingColumnNumber(token.getLocation(), &invalid);
243 if (invalid)
244 continue;
245 // Column numbers start at 1, but indexes in our string start at 0.
246 --start;
247
248 // Annotations don't have a length, so let's skip them.
249 if (token.isAnnotation())
250 continue;
251
252 // Extract the token string from our source code and store it.
253 std::string token_str = body.substr(start, token.getLength());
254 if (token_str.empty())
255 continue;
256 m_tokens.insert(token_str);
257 }
Raphael Isemann71569d02019-05-02 10:12:56 +0000258}
259
Kate Stoneb9c1b512016-09-06 20:57:50 +0000260static void AddLocalVariableDecls(const lldb::VariableListSP &var_list_sp,
Raphael Isemann71569d02019-05-02 10:12:56 +0000261 StreamString &stream,
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000262 const std::string &expr,
263 lldb::LanguageType wrapping_language) {
Raphael Isemann01718662019-07-10 21:04:01 +0000264 TokenVerifier tokens(expr);
265
Kate Stoneb9c1b512016-09-06 20:57:50 +0000266 for (size_t i = 0; i < var_list_sp->GetSize(); i++) {
267 lldb::VariableSP var_sp = var_list_sp->GetVariableAtIndex(i);
268
269 ConstString var_name = var_sp->GetName();
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000270
271
272 // We can check for .block_descriptor w/o checking for langauge since this
273 // is not a valid identifier in either C or C++.
Raphael Isemann090a5b22019-05-03 21:01:45 +0000274 if (!var_name || var_name == ".block_descriptor")
Kate Stoneb9c1b512016-09-06 20:57:50 +0000275 continue;
276
Raphael Isemann01718662019-07-10 21:04:01 +0000277 if (!expr.empty() && !tokens.hasToken(var_name.GetStringRef()))
Raphael Isemann71569d02019-05-02 10:12:56 +0000278 continue;
279
Raphael Isemann090a5b22019-05-03 21:01:45 +0000280 if ((var_name == "self" || var_name == "_cmd") &&
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000281 (wrapping_language == lldb::eLanguageTypeObjC ||
282 wrapping_language == lldb::eLanguageTypeObjC_plus_plus))
283 continue;
284
Raphael Isemann090a5b22019-05-03 21:01:45 +0000285 if (var_name == "this" &&
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000286 wrapping_language == lldb::eLanguageTypeC_plus_plus)
287 continue;
288
Kate Stoneb9c1b512016-09-06 20:57:50 +0000289 stream.Printf("using $__lldb_local_vars::%s;\n", var_name.AsCString());
290 }
291}
292
Raphael Isemann71569d02019-05-02 10:12:56 +0000293bool ClangExpressionSourceCode::GetText(
294 std::string &text, lldb::LanguageType wrapping_language, bool static_method,
295 ExecutionContext &exe_ctx, bool add_locals, bool force_add_all_locals,
296 llvm::ArrayRef<std::string> modules) const {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000297 const char *target_specific_defines = "typedef signed char BOOL;\n";
298 std::string module_macros;
299
300 Target *target = exe_ctx.GetTargetPtr();
301 if (target) {
302 if (target->GetArchitecture().GetMachine() == llvm::Triple::aarch64) {
303 target_specific_defines = "typedef bool BOOL;\n";
304 }
305 if (target->GetArchitecture().GetMachine() == llvm::Triple::x86_64) {
306 if (lldb::PlatformSP platform_sp = target->GetPlatform()) {
307 static ConstString g_platform_ios_simulator("ios-simulator");
308 if (platform_sp->GetPluginName() == g_platform_ios_simulator) {
309 target_specific_defines = "typedef bool BOOL;\n";
310 }
311 }
312 }
313
314 if (ClangModulesDeclVendor *decl_vendor =
315 target->GetClangModulesDeclVendor()) {
316 ClangPersistentVariables *persistent_vars =
317 llvm::cast<ClangPersistentVariables>(
318 target->GetPersistentExpressionStateForLanguage(
319 lldb::eLanguageTypeC));
320 const ClangModulesDeclVendor::ModuleVector &hand_imported_modules =
321 persistent_vars->GetHandLoadedClangModules();
322 ClangModulesDeclVendor::ModuleVector modules_for_macros;
323
324 for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules) {
325 modules_for_macros.push_back(module);
326 }
327
328 if (target->GetEnableAutoImportClangModules()) {
329 if (StackFrame *frame = exe_ctx.GetFramePtr()) {
330 if (Block *block = frame->GetFrameBlock()) {
331 SymbolContext sc;
332
333 block->CalculateSymbolContext(&sc);
334
335 if (sc.comp_unit) {
336 StreamString error_stream;
337
338 decl_vendor->AddModulesForCompileUnit(
339 *sc.comp_unit, modules_for_macros, error_stream);
340 }
341 }
342 }
343 }
344
345 decl_vendor->ForEachMacro(
346 modules_for_macros,
347 [&module_macros](const std::string &expansion) -> bool {
348 module_macros.append(expansion);
349 module_macros.append("\n");
350 return false;
351 });
352 }
353 }
354
355 StreamString debug_macros_stream;
356 StreamString lldb_local_var_decls;
357 if (StackFrame *frame = exe_ctx.GetFramePtr()) {
358 const SymbolContext &sc = frame->GetSymbolContext(
359 lldb::eSymbolContextCompUnit | lldb::eSymbolContextLineEntry);
360
361 if (sc.comp_unit && sc.line_entry.IsValid()) {
362 DebugMacros *dm = sc.comp_unit->GetDebugMacros();
363 if (dm) {
364 AddMacroState state(sc.line_entry.file, sc.line_entry.line);
365 AddMacros(dm, sc.comp_unit, state, debug_macros_stream);
366 }
367 }
368
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000369 if (add_locals)
370 if (target->GetInjectLocalVariables(&exe_ctx)) {
371 lldb::VariableListSP var_list_sp =
372 frame->GetInScopeVariableList(false, true);
373 AddLocalVariableDecls(var_list_sp, lldb_local_var_decls,
374 force_add_all_locals ? "" : m_body,
375 wrapping_language);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000376 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000377 }
378
379 if (m_wrap) {
380 switch (wrapping_language) {
381 default:
382 return false;
Jim Inghame5ee6f02016-03-29 22:00:08 +0000383 case lldb::eLanguageTypeC:
384 case lldb::eLanguageTypeC_plus_plus:
385 case lldb::eLanguageTypeObjC:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000386 break;
Jim Inghame5ee6f02016-03-29 22:00:08 +0000387 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000388
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000389 // Generate a list of @import statements that will import the specified
390 // module into our expression.
391 std::string module_imports;
392 for (const std::string &module : modules) {
393 module_imports.append("@import ");
394 module_imports.append(module);
395 module_imports.append(";\n");
396 }
397
Kate Stoneb9c1b512016-09-06 20:57:50 +0000398 StreamString wrap_stream;
399
400 wrap_stream.Printf("%s\n%s\n%s\n%s\n%s\n", module_macros.c_str(),
401 debug_macros_stream.GetData(), g_expression_prefix,
402 target_specific_defines, m_prefix.c_str());
403
404 // First construct a tagged form of the user expression so we can find it
405 // later:
406 std::string tagged_body;
407 switch (wrapping_language) {
408 default:
409 tagged_body = m_body;
410 break;
411 case lldb::eLanguageTypeC:
412 case lldb::eLanguageTypeC_plus_plus:
413 case lldb::eLanguageTypeObjC:
Raphael Isemann1442efe2019-09-18 08:53:35 +0000414 tagged_body.append(m_start_marker);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000415 tagged_body.append(m_body);
Raphael Isemann1442efe2019-09-18 08:53:35 +0000416 tagged_body.append(m_end_marker);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000417 break;
418 }
419 switch (wrapping_language) {
420 default:
421 break;
422 case lldb::eLanguageTypeC:
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000423 wrap_stream.Printf("%s"
424 "void \n"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000425 "%s(void *$__lldb_arg) \n"
426 "{ \n"
427 " %s; \n"
428 "%s"
429 "} \n",
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000430 module_imports.c_str(), m_name.c_str(),
431 lldb_local_var_decls.GetData(), tagged_body.c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000432 break;
433 case lldb::eLanguageTypeC_plus_plus:
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000434 wrap_stream.Printf("%s"
435 "void \n"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000436 "$__lldb_class::%s(void *$__lldb_arg) \n"
437 "{ \n"
438 " %s; \n"
439 "%s"
440 "} \n",
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000441 module_imports.c_str(), m_name.c_str(),
442 lldb_local_var_decls.GetData(), tagged_body.c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000443 break;
444 case lldb::eLanguageTypeObjC:
445 if (static_method) {
446 wrap_stream.Printf(
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000447 "%s"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000448 "@interface $__lldb_objc_class ($__lldb_category) \n"
449 "+(void)%s:(void *)$__lldb_arg; \n"
450 "@end \n"
451 "@implementation $__lldb_objc_class ($__lldb_category) \n"
452 "+(void)%s:(void *)$__lldb_arg \n"
453 "{ \n"
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000454 " %s; \n"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000455 "%s"
456 "} \n"
457 "@end \n",
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000458 module_imports.c_str(), m_name.c_str(), m_name.c_str(),
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000459 lldb_local_var_decls.GetData(), tagged_body.c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000460 } else {
461 wrap_stream.Printf(
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000462 "%s"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000463 "@interface $__lldb_objc_class ($__lldb_category) \n"
464 "-(void)%s:(void *)$__lldb_arg; \n"
465 "@end \n"
466 "@implementation $__lldb_objc_class ($__lldb_category) \n"
467 "-(void)%s:(void *)$__lldb_arg \n"
468 "{ \n"
Raphael Isemann090a5b22019-05-03 21:01:45 +0000469 " %s; \n"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000470 "%s"
471 "} \n"
472 "@end \n",
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000473 module_imports.c_str(), m_name.c_str(), m_name.c_str(),
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000474 lldb_local_var_decls.GetData(), tagged_body.c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000475 }
476 break;
477 }
478
479 text = wrap_stream.GetString();
480 } else {
481 text.append(m_body);
482 }
483
484 return true;
Jim Inghame5ee6f02016-03-29 22:00:08 +0000485}
486
Jim Inghamea401ec2019-03-06 22:43:25 +0000487bool ClangExpressionSourceCode::GetOriginalBodyBounds(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000488 std::string transformed_text, lldb::LanguageType wrapping_language,
489 size_t &start_loc, size_t &end_loc) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000490 switch (wrapping_language) {
491 default:
492 return false;
493 case lldb::eLanguageTypeC:
494 case lldb::eLanguageTypeC_plus_plus:
495 case lldb::eLanguageTypeObjC:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000496 break;
497 }
498
Raphael Isemann1442efe2019-09-18 08:53:35 +0000499 start_loc = transformed_text.find(m_start_marker);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000500 if (start_loc == std::string::npos)
501 return false;
Raphael Isemann1442efe2019-09-18 08:53:35 +0000502 start_loc += m_start_marker.size();
503 end_loc = transformed_text.find(m_end_marker);
Jonas Devliegherea6682a42018-12-15 00:15:33 +0000504 return end_loc != std::string::npos;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000505}