blob: 7ebb5fee1ec692495d668cd28a49e5637cfaea14 [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 Isemannbd2a9102019-09-24 06:58:39 +000032#define PREFIX_NAME "<lldb wrapper prefix>"
33
34const llvm::StringRef ClangExpressionSourceCode::g_prefix_file_name = PREFIX_NAME;
35
Raphael Isemann1442efe2019-09-18 08:53:35 +000036const char *ClangExpressionSourceCode::g_expression_prefix =
Raphael Isemannbd2a9102019-09-24 06:58:39 +000037"#line 1 \"" PREFIX_NAME R"("
Raphael Isemanne21fc872019-07-18 17:58:04 +000038#ifndef offsetof
39#define offsetof(t, d) __builtin_offsetof(t, d)
40#endif
Sean Callanan68f85e72015-04-30 21:49:58 +000041#ifndef NULL
Greg Clayton399107a2013-02-13 23:57:48 +000042#define NULL (__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 nil
Greg Clayton399107a2013-02-13 23:57:48 +000048#define nil (__null)
Sean Callanan68f85e72015-04-30 21:49:58 +000049#endif
50#ifndef YES
Greg Clayton399107a2013-02-13 23:57:48 +000051#define YES ((BOOL)1)
Sean Callanan68f85e72015-04-30 21:49:58 +000052#endif
53#ifndef NO
Greg Clayton399107a2013-02-13 23:57:48 +000054#define NO ((BOOL)0)
Sean Callanan68f85e72015-04-30 21:49:58 +000055#endif
Reid Kleckner56d861f2014-07-29 21:59:33 +000056typedef __INT8_TYPE__ int8_t;
57typedef __UINT8_TYPE__ uint8_t;
58typedef __INT16_TYPE__ int16_t;
59typedef __UINT16_TYPE__ uint16_t;
60typedef __INT32_TYPE__ int32_t;
61typedef __UINT32_TYPE__ uint32_t;
62typedef __INT64_TYPE__ int64_t;
63typedef __UINT64_TYPE__ uint64_t;
64typedef __INTPTR_TYPE__ intptr_t;
65typedef __UINTPTR_TYPE__ uintptr_t;
Greg Clayton399107a2013-02-13 23:57:48 +000066typedef __SIZE_TYPE__ size_t;
67typedef __PTRDIFF_TYPE__ ptrdiff_t;
68typedef unsigned short unichar;
Kate Stonecc391a02015-01-21 23:39:16 +000069extern "C"
70{
71 int printf(const char * __restrict, ...);
72}
Greg Clayton399107a2013-02-13 23:57:48 +000073)";
Sean Callanana199e822012-09-13 23:35:30 +000074
Siva Chandrad8335e92015-12-16 00:22:08 +000075namespace {
76
Kate Stoneb9c1b512016-09-06 20:57:50 +000077class AddMacroState {
78 enum State {
79 CURRENT_FILE_NOT_YET_PUSHED,
80 CURRENT_FILE_PUSHED,
81 CURRENT_FILE_POPPED
82 };
Siva Chandrad8335e92015-12-16 00:22:08 +000083
84public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 AddMacroState(const FileSpec &current_file, const uint32_t current_file_line)
86 : m_state(CURRENT_FILE_NOT_YET_PUSHED), m_current_file(current_file),
87 m_current_file_line(current_file_line) {}
Siva Chandrad8335e92015-12-16 00:22:08 +000088
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 void StartFile(const FileSpec &file) {
90 m_file_stack.push_back(file);
91 if (file == m_current_file)
92 m_state = CURRENT_FILE_PUSHED;
93 }
94
95 void EndFile() {
96 if (m_file_stack.size() == 0)
97 return;
98
99 FileSpec old_top = m_file_stack.back();
100 m_file_stack.pop_back();
101 if (old_top == m_current_file)
102 m_state = CURRENT_FILE_POPPED;
103 }
104
Adrian Prantl05097242018-04-30 16:49:04 +0000105 // An entry is valid if it occurs before the current line in the current
106 // file.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107 bool IsValidEntry(uint32_t line) {
108 switch (m_state) {
109 case CURRENT_FILE_NOT_YET_PUSHED:
110 return true;
111 case CURRENT_FILE_PUSHED:
Adrian Prantl05097242018-04-30 16:49:04 +0000112 // If we are in file included in the current file, the entry should be
113 // added.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114 if (m_file_stack.back() != m_current_file)
115 return true;
116
Jonas Devliegherea6682a42018-12-15 00:15:33 +0000117 return line < m_current_file_line;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118 default:
119 return false;
Siva Chandrad8335e92015-12-16 00:22:08 +0000120 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121 }
Siva Chandrad8335e92015-12-16 00:22:08 +0000122
123private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000124 std::vector<FileSpec> m_file_stack;
125 State m_state;
126 FileSpec m_current_file;
127 uint32_t m_current_file_line;
Siva Chandrad8335e92015-12-16 00:22:08 +0000128};
129
130} // anonymous namespace
131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132static void AddMacros(const DebugMacros *dm, CompileUnit *comp_unit,
133 AddMacroState &state, StreamString &stream) {
134 if (dm == nullptr)
135 return;
136
137 for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
138 const DebugMacroEntry &entry = dm->GetMacroEntryAtIndex(i);
139 uint32_t line;
140
141 switch (entry.GetType()) {
142 case DebugMacroEntry::DEFINE:
143 if (state.IsValidEntry(entry.GetLineNumber()))
144 stream.Printf("#define %s\n", entry.GetMacroString().AsCString());
145 else
Siva Chandrad8335e92015-12-16 00:22:08 +0000146 return;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000147 break;
148 case DebugMacroEntry::UNDEF:
149 if (state.IsValidEntry(entry.GetLineNumber()))
150 stream.Printf("#undef %s\n", entry.GetMacroString().AsCString());
151 else
152 return;
153 break;
154 case DebugMacroEntry::START_FILE:
155 line = entry.GetLineNumber();
156 if (state.IsValidEntry(line))
157 state.StartFile(entry.GetFileSpec(comp_unit));
158 else
159 return;
160 break;
161 case DebugMacroEntry::END_FILE:
162 state.EndFile();
163 break;
164 case DebugMacroEntry::INDIRECT:
165 AddMacros(entry.GetIndirectDebugMacros(), comp_unit, state, stream);
166 break;
Jim Inghame5ee6f02016-03-29 22:00:08 +0000167 default:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000168 // This is an unknown/invalid entry. Ignore.
169 break;
170 }
171 }
172}
173
Raphael Isemann1442efe2019-09-18 08:53:35 +0000174lldb_private::ClangExpressionSourceCode::ClangExpressionSourceCode(
175 llvm::StringRef filename, llvm::StringRef name, llvm::StringRef prefix,
176 llvm::StringRef body, Wrapping wrap)
177 : ExpressionSourceCode(name, prefix, body, wrap) {
178 // Use #line markers to pretend that we have a single-line source file
179 // containing only the user expression. This will hide our wrapper code
180 // from the user when we render diagnostics with Clang.
181 m_start_marker = "#line 1 \"" + filename.str() + "\"\n";
182 m_end_marker = "\n;\n#line 1 \"<lldb wrapper suffix>\"\n";
183}
184
Raphael Isemann01718662019-07-10 21:04:01 +0000185namespace {
186/// Allows checking if a token is contained in a given expression.
187class TokenVerifier {
188 /// The tokens we found in the expression.
189 llvm::StringSet<> m_tokens;
Raphael Isemann71569d02019-05-02 10:12:56 +0000190
Raphael Isemann01718662019-07-10 21:04:01 +0000191public:
192 TokenVerifier(std::string body);
193 /// Returns true iff the given expression body contained a token with the
194 /// given content.
195 bool hasToken(llvm::StringRef token) const {
196 return m_tokens.find(token) != m_tokens.end();
Raphael Isemann71569d02019-05-02 10:12:56 +0000197 }
Raphael Isemann01718662019-07-10 21:04:01 +0000198};
199} // namespace
200
201TokenVerifier::TokenVerifier(std::string body) {
202 using namespace clang;
203
204 // We only care about tokens and not their original source locations. If we
205 // move the whole expression to only be in one line we can simplify the
206 // following code that extracts the token contents.
207 std::replace(body.begin(), body.end(), '\n', ' ');
208 std::replace(body.begin(), body.end(), '\r', ' ');
209
210 FileSystemOptions file_opts;
211 FileManager file_mgr(file_opts,
212 FileSystem::Instance().GetVirtualFileSystem());
213
214 // Let's build the actual source code Clang needs and setup some utility
215 // objects.
216 llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_ids(new DiagnosticIDs());
217 llvm::IntrusiveRefCntPtr<DiagnosticOptions> diags_opts(
218 new DiagnosticOptions());
219 DiagnosticsEngine diags(diag_ids, diags_opts);
220 clang::SourceManager SM(diags, file_mgr);
221 auto buf = llvm::MemoryBuffer::getMemBuffer(body);
222
223 FileID FID = SM.createFileID(clang::SourceManager::Unowned, buf.get());
224
225 // Let's just enable the latest ObjC and C++ which should get most tokens
226 // right.
227 LangOptions Opts;
228 Opts.ObjC = true;
229 Opts.DollarIdents = true;
230 Opts.CPlusPlus17 = true;
231 Opts.LineComment = true;
232
233 Lexer lex(FID, buf.get(), SM, Opts);
234
235 Token token;
236 bool exit = false;
237 while (!exit) {
238 // Returns true if this is the last token we get from the lexer.
239 exit = lex.LexFromRawLexer(token);
240
241 // Extract the column number which we need to extract the token content.
242 // Our expression is just one line, so we don't need to handle any line
243 // numbers here.
244 bool invalid = false;
245 unsigned start = SM.getSpellingColumnNumber(token.getLocation(), &invalid);
246 if (invalid)
247 continue;
248 // Column numbers start at 1, but indexes in our string start at 0.
249 --start;
250
251 // Annotations don't have a length, so let's skip them.
252 if (token.isAnnotation())
253 continue;
254
255 // Extract the token string from our source code and store it.
256 std::string token_str = body.substr(start, token.getLength());
257 if (token_str.empty())
258 continue;
259 m_tokens.insert(token_str);
260 }
Raphael Isemann71569d02019-05-02 10:12:56 +0000261}
262
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263static void AddLocalVariableDecls(const lldb::VariableListSP &var_list_sp,
Raphael Isemann71569d02019-05-02 10:12:56 +0000264 StreamString &stream,
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000265 const std::string &expr,
266 lldb::LanguageType wrapping_language) {
Raphael Isemann01718662019-07-10 21:04:01 +0000267 TokenVerifier tokens(expr);
268
Kate Stoneb9c1b512016-09-06 20:57:50 +0000269 for (size_t i = 0; i < var_list_sp->GetSize(); i++) {
270 lldb::VariableSP var_sp = var_list_sp->GetVariableAtIndex(i);
271
272 ConstString var_name = var_sp->GetName();
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000273
274
275 // We can check for .block_descriptor w/o checking for langauge since this
276 // is not a valid identifier in either C or C++.
Raphael Isemann090a5b22019-05-03 21:01:45 +0000277 if (!var_name || var_name == ".block_descriptor")
Kate Stoneb9c1b512016-09-06 20:57:50 +0000278 continue;
279
Raphael Isemann01718662019-07-10 21:04:01 +0000280 if (!expr.empty() && !tokens.hasToken(var_name.GetStringRef()))
Raphael Isemann71569d02019-05-02 10:12:56 +0000281 continue;
282
Raphael Isemann090a5b22019-05-03 21:01:45 +0000283 if ((var_name == "self" || var_name == "_cmd") &&
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000284 (wrapping_language == lldb::eLanguageTypeObjC ||
285 wrapping_language == lldb::eLanguageTypeObjC_plus_plus))
286 continue;
287
Raphael Isemann090a5b22019-05-03 21:01:45 +0000288 if (var_name == "this" &&
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000289 wrapping_language == lldb::eLanguageTypeC_plus_plus)
290 continue;
291
Kate Stoneb9c1b512016-09-06 20:57:50 +0000292 stream.Printf("using $__lldb_local_vars::%s;\n", var_name.AsCString());
293 }
294}
295
Raphael Isemann71569d02019-05-02 10:12:56 +0000296bool ClangExpressionSourceCode::GetText(
297 std::string &text, lldb::LanguageType wrapping_language, bool static_method,
298 ExecutionContext &exe_ctx, bool add_locals, bool force_add_all_locals,
299 llvm::ArrayRef<std::string> modules) const {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000300 const char *target_specific_defines = "typedef signed char BOOL;\n";
301 std::string module_macros;
302
303 Target *target = exe_ctx.GetTargetPtr();
304 if (target) {
Jason Molenda7dd7a362019-10-16 19:14:49 +0000305 if (target->GetArchitecture().GetMachine() == llvm::Triple::aarch64 ||
306 target->GetArchitecture().GetMachine() == llvm::Triple::aarch64_32) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000307 target_specific_defines = "typedef bool BOOL;\n";
308 }
309 if (target->GetArchitecture().GetMachine() == llvm::Triple::x86_64) {
310 if (lldb::PlatformSP platform_sp = target->GetPlatform()) {
311 static ConstString g_platform_ios_simulator("ios-simulator");
312 if (platform_sp->GetPluginName() == g_platform_ios_simulator) {
313 target_specific_defines = "typedef bool BOOL;\n";
314 }
315 }
316 }
317
Adrian Prantle9331a52020-01-08 14:18:47 -0800318 ClangModulesDeclVendor *decl_vendor = target->GetClangModulesDeclVendor();
319 auto *persistent_vars = llvm::cast<ClangPersistentVariables>(
320 target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC));
321 if (decl_vendor && persistent_vars) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322 const ClangModulesDeclVendor::ModuleVector &hand_imported_modules =
323 persistent_vars->GetHandLoadedClangModules();
324 ClangModulesDeclVendor::ModuleVector modules_for_macros;
325
326 for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules) {
327 modules_for_macros.push_back(module);
328 }
329
330 if (target->GetEnableAutoImportClangModules()) {
331 if (StackFrame *frame = exe_ctx.GetFramePtr()) {
332 if (Block *block = frame->GetFrameBlock()) {
333 SymbolContext sc;
334
335 block->CalculateSymbolContext(&sc);
336
337 if (sc.comp_unit) {
338 StreamString error_stream;
339
340 decl_vendor->AddModulesForCompileUnit(
341 *sc.comp_unit, modules_for_macros, error_stream);
342 }
343 }
344 }
345 }
346
347 decl_vendor->ForEachMacro(
348 modules_for_macros,
349 [&module_macros](const std::string &expansion) -> bool {
350 module_macros.append(expansion);
351 module_macros.append("\n");
352 return false;
353 });
354 }
355 }
356
357 StreamString debug_macros_stream;
358 StreamString lldb_local_var_decls;
359 if (StackFrame *frame = exe_ctx.GetFramePtr()) {
360 const SymbolContext &sc = frame->GetSymbolContext(
361 lldb::eSymbolContextCompUnit | lldb::eSymbolContextLineEntry);
362
363 if (sc.comp_unit && sc.line_entry.IsValid()) {
364 DebugMacros *dm = sc.comp_unit->GetDebugMacros();
365 if (dm) {
366 AddMacroState state(sc.line_entry.file, sc.line_entry.line);
367 AddMacros(dm, sc.comp_unit, state, debug_macros_stream);
368 }
369 }
370
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000371 if (add_locals)
372 if (target->GetInjectLocalVariables(&exe_ctx)) {
373 lldb::VariableListSP var_list_sp =
374 frame->GetInScopeVariableList(false, true);
375 AddLocalVariableDecls(var_list_sp, lldb_local_var_decls,
376 force_add_all_locals ? "" : m_body,
377 wrapping_language);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000378 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000379 }
380
381 if (m_wrap) {
382 switch (wrapping_language) {
383 default:
384 return false;
Jim Inghame5ee6f02016-03-29 22:00:08 +0000385 case lldb::eLanguageTypeC:
386 case lldb::eLanguageTypeC_plus_plus:
387 case lldb::eLanguageTypeObjC:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000388 break;
Jim Inghame5ee6f02016-03-29 22:00:08 +0000389 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000390
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000391 // Generate a list of @import statements that will import the specified
392 // module into our expression.
393 std::string module_imports;
394 for (const std::string &module : modules) {
395 module_imports.append("@import ");
396 module_imports.append(module);
397 module_imports.append(";\n");
398 }
399
Kate Stoneb9c1b512016-09-06 20:57:50 +0000400 StreamString wrap_stream;
401
402 wrap_stream.Printf("%s\n%s\n%s\n%s\n%s\n", module_macros.c_str(),
403 debug_macros_stream.GetData(), g_expression_prefix,
404 target_specific_defines, m_prefix.c_str());
405
406 // First construct a tagged form of the user expression so we can find it
407 // later:
408 std::string tagged_body;
409 switch (wrapping_language) {
410 default:
411 tagged_body = m_body;
412 break;
413 case lldb::eLanguageTypeC:
414 case lldb::eLanguageTypeC_plus_plus:
415 case lldb::eLanguageTypeObjC:
Raphael Isemann1442efe2019-09-18 08:53:35 +0000416 tagged_body.append(m_start_marker);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000417 tagged_body.append(m_body);
Raphael Isemann1442efe2019-09-18 08:53:35 +0000418 tagged_body.append(m_end_marker);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000419 break;
420 }
421 switch (wrapping_language) {
422 default:
423 break;
424 case lldb::eLanguageTypeC:
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000425 wrap_stream.Printf("%s"
426 "void \n"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000427 "%s(void *$__lldb_arg) \n"
428 "{ \n"
429 " %s; \n"
430 "%s"
431 "} \n",
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000432 module_imports.c_str(), m_name.c_str(),
433 lldb_local_var_decls.GetData(), tagged_body.c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000434 break;
435 case lldb::eLanguageTypeC_plus_plus:
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000436 wrap_stream.Printf("%s"
437 "void \n"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000438 "$__lldb_class::%s(void *$__lldb_arg) \n"
439 "{ \n"
440 " %s; \n"
441 "%s"
442 "} \n",
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000443 module_imports.c_str(), m_name.c_str(),
444 lldb_local_var_decls.GetData(), tagged_body.c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000445 break;
446 case lldb::eLanguageTypeObjC:
447 if (static_method) {
448 wrap_stream.Printf(
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000449 "%s"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000450 "@interface $__lldb_objc_class ($__lldb_category) \n"
451 "+(void)%s:(void *)$__lldb_arg; \n"
452 "@end \n"
453 "@implementation $__lldb_objc_class ($__lldb_category) \n"
454 "+(void)%s:(void *)$__lldb_arg \n"
455 "{ \n"
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000456 " %s; \n"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000457 "%s"
458 "} \n"
459 "@end \n",
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000460 module_imports.c_str(), m_name.c_str(), m_name.c_str(),
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000461 lldb_local_var_decls.GetData(), tagged_body.c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000462 } else {
463 wrap_stream.Printf(
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000464 "%s"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000465 "@interface $__lldb_objc_class ($__lldb_category) \n"
466 "-(void)%s:(void *)$__lldb_arg; \n"
467 "@end \n"
468 "@implementation $__lldb_objc_class ($__lldb_category) \n"
469 "-(void)%s:(void *)$__lldb_arg \n"
470 "{ \n"
Raphael Isemann090a5b22019-05-03 21:01:45 +0000471 " %s; \n"
Kate Stoneb9c1b512016-09-06 20:57:50 +0000472 "%s"
473 "} \n"
474 "@end \n",
Raphael Isemann6c0bbfc2019-03-12 17:09:33 +0000475 module_imports.c_str(), m_name.c_str(), m_name.c_str(),
Shafik Yaghmoure5cbe782019-05-03 19:59:22 +0000476 lldb_local_var_decls.GetData(), tagged_body.c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000477 }
478 break;
479 }
480
481 text = wrap_stream.GetString();
482 } else {
483 text.append(m_body);
484 }
485
486 return true;
Jim Inghame5ee6f02016-03-29 22:00:08 +0000487}
488
Jim Inghamea401ec2019-03-06 22:43:25 +0000489bool ClangExpressionSourceCode::GetOriginalBodyBounds(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000490 std::string transformed_text, lldb::LanguageType wrapping_language,
491 size_t &start_loc, size_t &end_loc) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000492 switch (wrapping_language) {
493 default:
494 return false;
495 case lldb::eLanguageTypeC:
496 case lldb::eLanguageTypeC_plus_plus:
497 case lldb::eLanguageTypeObjC:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000498 break;
499 }
500
Raphael Isemann1442efe2019-09-18 08:53:35 +0000501 start_loc = transformed_text.find(m_start_marker);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000502 if (start_loc == std::string::npos)
503 return false;
Raphael Isemann1442efe2019-09-18 08:53:35 +0000504 start_loc += m_start_marker.size();
505 end_loc = transformed_text.find(m_end_marker);
Jonas Devliegherea6682a42018-12-15 00:15:33 +0000506 return end_loc != std::string::npos;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000507}