LLDB  mainline
ClangUserExpression.cpp
Go to the documentation of this file.
1 //===-- ClangUserExpression.cpp -------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <cstdio>
10 #include <sys/types.h>
11 
12 #include <cstdlib>
13 #include <map>
14 #include <string>
15 
16 #include "ClangUserExpression.h"
17 
18 #include "ASTResultSynthesizer.h"
19 #include "ClangASTMetadata.h"
20 #include "ClangDiagnostic.h"
21 #include "ClangExpressionDeclMap.h"
22 #include "ClangExpressionParser.h"
23 #include "ClangModulesDeclVendor.h"
25 #include "CppModuleConfiguration.h"
26 
28 #include "lldb/Core/Debugger.h"
29 #include "lldb/Core/Module.h"
30 #include "lldb/Core/StreamFile.h"
36 #include "lldb/Host/HostInfo.h"
37 #include "lldb/Symbol/Block.h"
39 #include "lldb/Symbol/Function.h"
40 #include "lldb/Symbol/ObjectFile.h"
41 #include "lldb/Symbol/SymbolFile.h"
43 #include "lldb/Symbol/Type.h"
46 #include "lldb/Target/Process.h"
47 #include "lldb/Target/StackFrame.h"
48 #include "lldb/Target/Target.h"
49 #include "lldb/Target/ThreadPlan.h"
52 #include "lldb/Utility/Log.h"
54 
55 #include "clang/AST/DeclCXX.h"
56 #include "clang/AST/DeclObjC.h"
57 
58 #include "llvm/ADT/ScopeExit.h"
59 
60 using namespace lldb_private;
61 
63 
65  ExecutionContextScope &exe_scope, llvm::StringRef expr,
66  llvm::StringRef prefix, lldb::LanguageType language,
67  ResultType desired_type, const EvaluateExpressionOptions &options,
68  ValueObject *ctx_obj)
69  : LLVMUserExpression(exe_scope, expr, prefix, language, desired_type,
70  options),
71  m_type_system_helper(*m_target_wp.lock(), options.GetExecutionPolicy() ==
73  m_result_delegate(exe_scope.CalculateTarget()), m_ctx_obj(ctx_obj) {
74  switch (m_language) {
76  m_allow_cxx = true;
77  break;
79  m_allow_objc = true;
80  break;
82  default:
83  m_allow_cxx = true;
84  m_allow_objc = true;
85  break;
86  }
87 }
88 
90 
93 
94  LLDB_LOGF(log, "ClangUserExpression::ScanContext()");
95 
96  m_target = exe_ctx.GetTargetPtr();
97 
98  if (!(m_allow_cxx || m_allow_objc)) {
99  LLDB_LOGF(log, " [CUE::SC] Settings inhibit C++ and Objective-C");
100  return;
101  }
102 
103  StackFrame *frame = exe_ctx.GetFramePtr();
104  if (frame == nullptr) {
105  LLDB_LOGF(log, " [CUE::SC] Null stack frame");
106  return;
107  }
108 
109  SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
110  lldb::eSymbolContextBlock);
111 
112  if (!sym_ctx.function) {
113  LLDB_LOGF(log, " [CUE::SC] Null function");
114  return;
115  }
116 
117  // Find the block that defines the function represented by "sym_ctx"
118  Block *function_block = sym_ctx.GetFunctionBlock();
119 
120  if (!function_block) {
121  LLDB_LOGF(log, " [CUE::SC] Null function block");
122  return;
123  }
124 
125  CompilerDeclContext decl_context = function_block->GetDeclContext();
126 
127  if (!decl_context) {
128  LLDB_LOGF(log, " [CUE::SC] Null decl context");
129  return;
130  }
131 
132  if (m_ctx_obj) {
133  switch (m_ctx_obj->GetObjectRuntimeLanguage()) {
142  m_in_cplusplus_method = true;
143  break;
146  m_in_objectivec_method = true;
147  break;
148  default:
149  break;
150  }
151  m_needs_object_ptr = true;
152  } else if (clang::CXXMethodDecl *method_decl =
154  if (m_allow_cxx && method_decl->isInstance()) {
156  lldb::VariableListSP variable_list_sp(
157  function_block->GetBlockVariableList(true));
158 
159  const char *thisErrorString = "Stopped in a C++ method, but 'this' "
160  "isn't available; pretending we are in a "
161  "generic context";
162 
163  if (!variable_list_sp) {
164  err.SetErrorString(thisErrorString);
165  return;
166  }
167 
168  lldb::VariableSP this_var_sp(
169  variable_list_sp->FindVariable(ConstString("this")));
170 
171  if (!this_var_sp || !this_var_sp->IsInScope(frame) ||
172  !this_var_sp->LocationIsValidForFrame(frame)) {
173  err.SetErrorString(thisErrorString);
174  return;
175  }
176  }
177 
178  m_in_cplusplus_method = true;
179  m_needs_object_ptr = true;
180  }
181  } else if (clang::ObjCMethodDecl *method_decl =
183  decl_context)) {
184  if (m_allow_objc) {
186  lldb::VariableListSP variable_list_sp(
187  function_block->GetBlockVariableList(true));
188 
189  const char *selfErrorString = "Stopped in an Objective-C method, but "
190  "'self' isn't available; pretending we "
191  "are in a generic context";
192 
193  if (!variable_list_sp) {
194  err.SetErrorString(selfErrorString);
195  return;
196  }
197 
198  lldb::VariableSP self_variable_sp =
199  variable_list_sp->FindVariable(ConstString("self"));
200 
201  if (!self_variable_sp || !self_variable_sp->IsInScope(frame) ||
202  !self_variable_sp->LocationIsValidForFrame(frame)) {
203  err.SetErrorString(selfErrorString);
204  return;
205  }
206  }
207 
208  m_in_objectivec_method = true;
209  m_needs_object_ptr = true;
210 
211  if (!method_decl->isInstanceMethod())
212  m_in_static_method = true;
213  }
214  } else if (clang::FunctionDecl *function_decl =
216  // We might also have a function that said in the debug information that it
217  // captured an object pointer. The best way to deal with getting to the
218  // ivars at present is by pretending that this is a method of a class in
219  // whatever runtime the debug info says the object pointer belongs to. Do
220  // that here.
221 
222  ClangASTMetadata *metadata =
223  TypeSystemClang::DeclContextGetMetaData(decl_context, function_decl);
224  if (metadata && metadata->HasObjectPtr()) {
225  lldb::LanguageType language = metadata->GetObjectPtrLanguage();
226  if (language == lldb::eLanguageTypeC_plus_plus) {
228  lldb::VariableListSP variable_list_sp(
229  function_block->GetBlockVariableList(true));
230 
231  const char *thisErrorString = "Stopped in a context claiming to "
232  "capture a C++ object pointer, but "
233  "'this' isn't available; pretending we "
234  "are in a generic context";
235 
236  if (!variable_list_sp) {
237  err.SetErrorString(thisErrorString);
238  return;
239  }
240 
241  lldb::VariableSP this_var_sp(
242  variable_list_sp->FindVariable(ConstString("this")));
243 
244  if (!this_var_sp || !this_var_sp->IsInScope(frame) ||
245  !this_var_sp->LocationIsValidForFrame(frame)) {
246  err.SetErrorString(thisErrorString);
247  return;
248  }
249  }
250 
251  m_in_cplusplus_method = true;
252  m_needs_object_ptr = true;
253  } else if (language == lldb::eLanguageTypeObjC) {
255  lldb::VariableListSP variable_list_sp(
256  function_block->GetBlockVariableList(true));
257 
258  const char *selfErrorString =
259  "Stopped in a context claiming to capture an Objective-C object "
260  "pointer, but 'self' isn't available; pretending we are in a "
261  "generic context";
262 
263  if (!variable_list_sp) {
264  err.SetErrorString(selfErrorString);
265  return;
266  }
267 
268  lldb::VariableSP self_variable_sp =
269  variable_list_sp->FindVariable(ConstString("self"));
270 
271  if (!self_variable_sp || !self_variable_sp->IsInScope(frame) ||
272  !self_variable_sp->LocationIsValidForFrame(frame)) {
273  err.SetErrorString(selfErrorString);
274  return;
275  }
276 
277  Type *self_type = self_variable_sp->GetType();
278 
279  if (!self_type) {
280  err.SetErrorString(selfErrorString);
281  return;
282  }
283 
284  CompilerType self_clang_type = self_type->GetForwardCompilerType();
285 
286  if (!self_clang_type) {
287  err.SetErrorString(selfErrorString);
288  return;
289  }
290 
291  if (TypeSystemClang::IsObjCClassType(self_clang_type)) {
292  return;
294  self_clang_type)) {
295  m_in_objectivec_method = true;
296  m_needs_object_ptr = true;
297  } else {
298  err.SetErrorString(selfErrorString);
299  return;
300  }
301  } else {
302  m_in_objectivec_method = true;
303  m_needs_object_ptr = true;
304  }
305  }
306  }
307  }
308 }
309 
310 // This is a really nasty hack, meant to fix Objective-C expressions of the
311 // form (int)[myArray count]. Right now, because the type information for
312 // count is not available, [myArray count] returns id, which can't be directly
313 // cast to int without causing a clang error.
314 static void ApplyObjcCastHack(std::string &expr) {
315  const std::string from = "(int)[";
316  const std::string to = "(int)(long long)[";
317 
318  size_t offset;
319 
320  while ((offset = expr.find(from)) != expr.npos)
321  expr.replace(offset, from.size(), to);
322 }
323 
325  ExecutionContext &exe_ctx) {
326  if (Target *target = exe_ctx.GetTargetPtr()) {
327  if (PersistentExpressionState *persistent_state =
328  target->GetPersistentExpressionStateForLanguage(
330  m_clang_state = llvm::cast<ClangPersistentVariables>(persistent_state);
331  m_result_delegate.RegisterPersistentState(persistent_state);
332  } else {
333  diagnostic_manager.PutString(
335  "couldn't start parsing (no persistent data)");
336  return false;
337  }
338  } else {
339  diagnostic_manager.PutString(eDiagnosticSeverityError,
340  "error: couldn't start parsing (no target)");
341  return false;
342  }
343  return true;
344 }
345 
346 static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target,
347  DiagnosticManager &diagnostic_manager) {
348  if (!target->GetEnableAutoImportClangModules())
349  return;
350 
351  auto *persistent_state = llvm::cast<ClangPersistentVariables>(
353  if (!persistent_state)
354  return;
355 
356  std::shared_ptr<ClangModulesDeclVendor> decl_vendor =
357  persistent_state->GetClangModulesDeclVendor();
358  if (!decl_vendor)
359  return;
360 
361  StackFrame *frame = exe_ctx.GetFramePtr();
362  if (!frame)
363  return;
364 
365  Block *block = frame->GetFrameBlock();
366  if (!block)
367  return;
368  SymbolContext sc;
369 
370  block->CalculateSymbolContext(&sc);
371 
372  if (!sc.comp_unit)
373  return;
374  StreamString error_stream;
375 
376  ClangModulesDeclVendor::ModuleVector modules_for_macros =
377  persistent_state->GetHandLoadedClangModules();
378  if (decl_vendor->AddModulesForCompileUnit(*sc.comp_unit, modules_for_macros,
379  error_stream))
380  return;
381 
382  // Failed to load some modules, so emit the error stream as a diagnostic.
383  if (!error_stream.Empty()) {
384  // The error stream already contains several Clang diagnostics that might
385  // be either errors or warnings, so just print them all as one remark
386  // diagnostic to prevent that the message starts with "error: error:".
387  diagnostic_manager.PutString(eDiagnosticSeverityRemark,
388  error_stream.GetString());
389  return;
390  }
391 
392  diagnostic_manager.PutString(eDiagnosticSeverityError,
393  "Unknown error while loading modules needed for "
394  "current compilation unit.");
395 }
396 
399  "Top level expressions aren't wrapped.");
402  return Kind::CppMemberFunction;
403  else if (m_in_objectivec_method) {
404  if (m_in_static_method)
405  return Kind::ObjCStaticMethod;
406  return Kind::ObjCInstanceMethod;
407  }
408  // Not in any kind of 'special' function, so just wrap it in a normal C
409  // function.
410  return Kind::Function;
411 }
412 
414  DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
415  std::vector<std::string> modules_to_import, bool for_completion) {
416 
417  std::string prefix = m_expr_prefix;
418 
421  } else {
423  m_filename, prefix, m_expr_text, GetWrapKind()));
424 
425  if (!m_source_code->GetText(m_transformed_text, exe_ctx, !m_ctx_obj,
426  for_completion, modules_to_import)) {
427  diagnostic_manager.PutString(eDiagnosticSeverityError,
428  "couldn't construct expression body");
429  return;
430  }
431 
432  // Find and store the start position of the original code inside the
433  // transformed code. We need this later for the code completion.
434  std::size_t original_start;
435  std::size_t original_end;
436  bool found_bounds = m_source_code->GetOriginalBodyBounds(
437  m_transformed_text, original_start, original_end);
438  if (found_bounds)
439  m_user_expression_start_pos = original_start;
440  }
441 }
442 
444  switch (language) {
450  return true;
451  default:
452  return false;
453  }
454 }
455 
456 /// Utility method that puts a message into the expression log and
457 /// returns an invalid module configuration.
460  LLDB_LOG(log, "[C++ module config] {0}", msg);
461  return CppModuleConfiguration();
462 }
463 
465  ExecutionContext &exe_ctx) {
467 
468  // Don't do anything if this is not a C++ module configuration.
469  if (!SupportsCxxModuleImport(language))
470  return LogConfigError("Language doesn't support C++ modules");
471 
472  Target *target = exe_ctx.GetTargetPtr();
473  if (!target)
474  return LogConfigError("No target");
475 
476  StackFrame *frame = exe_ctx.GetFramePtr();
477  if (!frame)
478  return LogConfigError("No frame");
479 
480  Block *block = frame->GetFrameBlock();
481  if (!block)
482  return LogConfigError("No block");
483 
484  SymbolContext sc;
485  block->CalculateSymbolContext(&sc);
486  if (!sc.comp_unit)
487  return LogConfigError("Couldn't calculate symbol context");
488 
489  // Build a list of files we need to analyze to build the configuration.
490  FileSpecList files;
491  for (const FileSpec &f : sc.comp_unit->GetSupportFiles())
492  files.AppendIfUnique(f);
493  // We also need to look at external modules in the case of -gmodules as they
494  // contain the support files for libc++ and the C library.
495  llvm::DenseSet<SymbolFile *> visited_symbol_files;
497  visited_symbol_files, [&files](Module &module) {
498  for (std::size_t i = 0; i < module.GetNumCompileUnits(); ++i) {
499  const FileSpecList &support_files =
500  module.GetCompileUnitAtIndex(i)->GetSupportFiles();
501  for (const FileSpec &f : support_files) {
502  files.AppendIfUnique(f);
503  }
504  }
505  return false;
506  });
507 
508  LLDB_LOG(log, "[C++ module config] Found {0} support files to analyze",
509  files.GetSize());
510  if (log && log->GetVerbose()) {
511  for (const FileSpec &f : files)
512  LLDB_LOGV(log, "[C++ module config] Analyzing support file: {0}",
513  f.GetPath());
514  }
515 
516  // Try to create a configuration from the files. If there is no valid
517  // configuration possible with the files, this just returns an invalid
518  // configuration.
519  return CppModuleConfiguration(files, target->GetArchitecture().GetTriple());
520 }
521 
523  DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
524  bool for_completion) {
525  InstallContext(exe_ctx);
526 
527  if (!SetupPersistentState(diagnostic_manager, exe_ctx))
528  return false;
529 
530  Status err;
531  ScanContext(exe_ctx, err);
532 
533  if (!err.Success()) {
534  diagnostic_manager.PutString(eDiagnosticSeverityWarning, err.AsCString());
535  }
536 
537  ////////////////////////////////////
538  // Generate the expression
539  //
540 
542 
543  SetupDeclVendor(exe_ctx, m_target, diagnostic_manager);
544 
546 
548  SetupCppModuleImports(exe_ctx);
549 
550  CreateSourceCode(diagnostic_manager, exe_ctx, m_imported_cpp_modules,
551  for_completion);
552  return true;
553 }
554 
556  DiagnosticManager &diagnostic_manager, ExecutionContextScope *exe_scope,
557  ExecutionContext &exe_ctx, lldb_private::ExecutionPolicy execution_policy,
558  bool keep_result_in_memory, bool generate_debug_info) {
559  m_materializer_up = std::make_unique<Materializer>();
560 
561  ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
562 
563  auto on_exit = llvm::make_scope_exit([this]() { ResetDeclMap(); });
564 
565  if (!DeclMap()->WillParse(exe_ctx, GetMaterializer())) {
566  diagnostic_manager.PutString(
568  "current process state is unsuitable for expression parsing");
569  return false;
570  }
571 
573  DeclMap()->SetLookupsEnabled(true);
574  }
575 
576  m_parser = std::make_unique<ClangExpressionParser>(
577  exe_scope, *this, generate_debug_info, m_include_directories, m_filename);
578 
579  unsigned num_errors = m_parser->Parse(diagnostic_manager);
580 
581  // Check here for FixItHints. If there are any try to apply the fixits and
582  // set the fixed text in m_fixed_text before returning an error.
583  if (num_errors) {
584  if (diagnostic_manager.HasFixIts()) {
585  if (m_parser->RewriteExpression(diagnostic_manager)) {
586  size_t fixed_start;
587  size_t fixed_end;
588  m_fixed_text = diagnostic_manager.GetFixedExpression();
589  // Retrieve the original expression in case we don't have a top level
590  // expression (which has no surrounding source code).
591  if (m_source_code && m_source_code->GetOriginalBodyBounds(
592  m_fixed_text, fixed_start, fixed_end))
593  m_fixed_text =
594  m_fixed_text.substr(fixed_start, fixed_end - fixed_start);
595  }
596  }
597  return false;
598  }
599 
600  //////////////////////////////////////////////////////////////////////////////
601  // Prepare the output of the parser for execution, evaluating it statically
602  // if possible
603  //
604 
605  {
606  Status jit_error = m_parser->PrepareForExecution(
608  m_can_interpret, execution_policy);
609 
610  if (!jit_error.Success()) {
611  const char *error_cstr = jit_error.AsCString();
612  if (error_cstr && error_cstr[0])
613  diagnostic_manager.PutString(eDiagnosticSeverityError, error_cstr);
614  else
615  diagnostic_manager.PutString(eDiagnosticSeverityError,
616  "expression can't be interpreted or run");
617  return false;
618  }
619  }
620  return true;
621 }
622 
625 
626  CppModuleConfiguration module_config = GetModuleConfig(m_language, exe_ctx);
627  m_imported_cpp_modules = module_config.GetImportedModules();
628  m_include_directories = module_config.GetIncludeDirs();
629 
630  LLDB_LOG(log, "List of imported modules in expression: {0}",
631  llvm::make_range(m_imported_cpp_modules.begin(),
632  m_imported_cpp_modules.end()));
633  LLDB_LOG(log, "List of include directories gathered for modules: {0}",
634  llvm::make_range(m_include_directories.begin(),
635  m_include_directories.end()));
636 }
637 
638 static bool shouldRetryWithCppModule(Target &target, ExecutionPolicy exe_policy) {
639  // Top-level expression don't yet support importing C++ modules.
641  return false;
642  return target.GetImportStdModule() == eImportStdModuleFallback;
643 }
644 
646  ExecutionContext &exe_ctx,
647  lldb_private::ExecutionPolicy execution_policy,
648  bool keep_result_in_memory,
649  bool generate_debug_info) {
651 
652  if (!PrepareForParsing(diagnostic_manager, exe_ctx, /*for_completion*/ false))
653  return false;
654 
655  LLDB_LOGF(log, "Parsing the following code:\n%s", m_transformed_text.c_str());
656 
657  ////////////////////////////////////
658  // Set up the target and compiler
659  //
660 
661  Target *target = exe_ctx.GetTargetPtr();
662 
663  if (!target) {
664  diagnostic_manager.PutString(eDiagnosticSeverityError, "invalid target");
665  return false;
666  }
667 
668  //////////////////////////
669  // Parse the expression
670  //
671 
672  Process *process = exe_ctx.GetProcessPtr();
673  ExecutionContextScope *exe_scope = process;
674 
675  if (!exe_scope)
676  exe_scope = exe_ctx.GetTargetPtr();
677 
678  bool parse_success = TryParse(diagnostic_manager, exe_scope, exe_ctx,
679  execution_policy, keep_result_in_memory,
680  generate_debug_info);
681  // If the expression failed to parse, check if retrying parsing with a loaded
682  // C++ module is possible.
683  if (!parse_success && shouldRetryWithCppModule(*target, execution_policy)) {
684  // Load the loaded C++ modules.
685  SetupCppModuleImports(exe_ctx);
686  // If we did load any modules, then retry parsing.
687  if (!m_imported_cpp_modules.empty()) {
688  // Create a dedicated diagnostic manager for the second parse attempt.
689  // These diagnostics are only returned to the caller if using the fallback
690  // actually succeeded in getting the expression to parse. This prevents
691  // that module-specific issues regress diagnostic quality with the
692  // fallback mode.
693  DiagnosticManager retry_manager;
694  // The module imports are injected into the source code wrapper,
695  // so recreate those.
696  CreateSourceCode(retry_manager, exe_ctx, m_imported_cpp_modules,
697  /*for_completion*/ false);
698  parse_success = TryParse(retry_manager, exe_scope, exe_ctx,
699  execution_policy, keep_result_in_memory,
700  generate_debug_info);
701  // Return the parse diagnostics if we were successful.
702  if (parse_success)
703  diagnostic_manager = std::move(retry_manager);
704  }
705  }
706  if (!parse_success)
707  return false;
708 
709  if (exe_ctx.GetProcessPtr() && execution_policy == eExecutionPolicyTopLevel) {
710  Status static_init_error =
711  m_parser->RunStaticInitializers(m_execution_unit_sp, exe_ctx);
712 
713  if (!static_init_error.Success()) {
714  const char *error_cstr = static_init_error.AsCString();
715  if (error_cstr && error_cstr[0])
716  diagnostic_manager.Printf(eDiagnosticSeverityError,
717  "%s\n",
718  error_cstr);
719  else
720  diagnostic_manager.PutString(eDiagnosticSeverityError,
721  "couldn't run static initializers\n");
722  return false;
723  }
724  }
725 
726  if (m_execution_unit_sp) {
727  bool register_execution_unit = false;
728 
730  register_execution_unit = true;
731  }
732 
733  // If there is more than one external function in the execution unit, it
734  // needs to keep living even if it's not top level, because the result
735  // could refer to that function.
736 
737  if (m_execution_unit_sp->GetJittedFunctions().size() > 1) {
738  register_execution_unit = true;
739  }
740 
741  if (register_execution_unit) {
742  if (auto *persistent_state =
744  m_language))
745  persistent_state->RegisterExecutionUnit(m_execution_unit_sp);
746  }
747  }
748 
749  if (generate_debug_info) {
750  lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
751 
752  if (jit_module_sp) {
753  ConstString const_func_name(FunctionName());
754  FileSpec jit_file;
755  jit_file.GetFilename() = const_func_name;
756  jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString());
757  m_jit_module_wp = jit_module_sp;
758  target->GetImages().Append(jit_module_sp);
759  }
760  }
761 
762  if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
763  m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
764  return true;
765 }
766 
767 /// Converts an absolute position inside a given code string into
768 /// a column/line pair.
769 ///
770 /// \param[in] abs_pos
771 /// A absolute position in the code string that we want to convert
772 /// to a column/line pair.
773 ///
774 /// \param[in] code
775 /// A multi-line string usually representing source code.
776 ///
777 /// \param[out] line
778 /// The line in the code that contains the given absolute position.
779 /// The first line in the string is indexed as 1.
780 ///
781 /// \param[out] column
782 /// The column in the line that contains the absolute position.
783 /// The first character in a line is indexed as 0.
784 static void AbsPosToLineColumnPos(size_t abs_pos, llvm::StringRef code,
785  unsigned &line, unsigned &column) {
786  // Reset to code position to beginning of the file.
787  line = 0;
788  column = 0;
789 
790  assert(abs_pos <= code.size() && "Absolute position outside code string?");
791 
792  // We have to walk up to the position and count lines/columns.
793  for (std::size_t i = 0; i < abs_pos; ++i) {
794  // If we hit a line break, we go back to column 0 and enter a new line.
795  // We only handle \n because that's what we internally use to make new
796  // lines for our temporary code strings.
797  if (code[i] == '\n') {
798  ++line;
799  column = 0;
800  continue;
801  }
802  ++column;
803  }
804 }
805 
807  CompletionRequest &request,
808  unsigned complete_pos) {
810 
811  // We don't want any visible feedback when completing an expression. Mostly
812  // because the results we get from an incomplete invocation are probably not
813  // correct.
814  DiagnosticManager diagnostic_manager;
815 
816  if (!PrepareForParsing(diagnostic_manager, exe_ctx, /*for_completion*/ true))
817  return false;
818 
819  LLDB_LOGF(log, "Parsing the following code:\n%s", m_transformed_text.c_str());
820 
821  //////////////////////////
822  // Parse the expression
823  //
824 
825  m_materializer_up = std::make_unique<Materializer>();
826 
827  ResetDeclMap(exe_ctx, m_result_delegate, /*keep result in memory*/ true);
828 
829  auto on_exit = llvm::make_scope_exit([this]() { ResetDeclMap(); });
830 
831  if (!DeclMap()->WillParse(exe_ctx, GetMaterializer())) {
832  diagnostic_manager.PutString(
834  "current process state is unsuitable for expression parsing");
835 
836  return false;
837  }
838 
840  DeclMap()->SetLookupsEnabled(true);
841  }
842 
843  Process *process = exe_ctx.GetProcessPtr();
844  ExecutionContextScope *exe_scope = process;
845 
846  if (!exe_scope)
847  exe_scope = exe_ctx.GetTargetPtr();
848 
849  ClangExpressionParser parser(exe_scope, *this, false);
850 
851  // We have to find the source code location where the user text is inside
852  // the transformed expression code. When creating the transformed text, we
853  // already stored the absolute position in the m_transformed_text string. The
854  // only thing left to do is to transform it into the line:column format that
855  // Clang expects.
856 
857  // The line and column of the user expression inside the transformed source
858  // code.
859  unsigned user_expr_line, user_expr_column;
860  if (m_user_expression_start_pos.hasValue())
862  user_expr_line, user_expr_column);
863  else
864  return false;
865 
866  // The actual column where we have to complete is the start column of the
867  // user expression + the offset inside the user code that we were given.
868  const unsigned completion_column = user_expr_column + complete_pos;
869  parser.Complete(request, user_expr_line, completion_column, complete_pos);
870 
871  return true;
872 }
873 
875  std::vector<lldb::addr_t> &args,
876  lldb::addr_t struct_address,
877  DiagnosticManager &diagnostic_manager) {
878  lldb::addr_t object_ptr = LLDB_INVALID_ADDRESS;
880 
881  if (m_needs_object_ptr) {
882  lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP();
883  if (!frame_sp)
884  return true;
885 
886  ConstString object_name;
887 
888  if (m_in_cplusplus_method) {
889  object_name.SetCString("this");
890  } else if (m_in_objectivec_method) {
891  object_name.SetCString("self");
892  } else {
893  diagnostic_manager.PutString(
895  "need object pointer but don't know the language");
896  return false;
897  }
898 
899  Status object_ptr_error;
900 
901  if (m_ctx_obj) {
902  AddressType address_type;
903  object_ptr = m_ctx_obj->GetAddressOf(false, &address_type);
904  if (object_ptr == LLDB_INVALID_ADDRESS ||
905  address_type != eAddressTypeLoad)
906  object_ptr_error.SetErrorString("Can't get context object's "
907  "debuggee address");
908  } else
909  object_ptr = GetObjectPointer(frame_sp, object_name, object_ptr_error);
910 
911  if (!object_ptr_error.Success()) {
912  exe_ctx.GetTargetRef().GetDebugger().GetAsyncOutputStream()->Printf(
913  "warning: `%s' is not accessible (substituting 0). %s\n",
914  object_name.AsCString(), object_ptr_error.AsCString());
915  object_ptr = 0;
916  }
917 
919  ConstString cmd_name("_cmd");
920 
921  cmd_ptr = GetObjectPointer(frame_sp, cmd_name, object_ptr_error);
922 
923  if (!object_ptr_error.Success()) {
924  diagnostic_manager.Printf(
926  "couldn't get cmd pointer (substituting NULL): %s",
927  object_ptr_error.AsCString());
928  cmd_ptr = 0;
929  }
930  }
931 
932  args.push_back(object_ptr);
933 
935  args.push_back(cmd_ptr);
936 
937  args.push_back(struct_address);
938  } else {
939  args.push_back(struct_address);
940  }
941  return true;
942 }
943 
945  ExecutionContextScope *exe_scope) {
947 }
948 
950  ExecutionContext &exe_ctx,
952  bool keep_result_in_memory,
953  ValueObject *ctx_obj) {
954  std::shared_ptr<ClangASTImporter> ast_importer;
955  auto *state = exe_ctx.GetTargetSP()->GetPersistentExpressionStateForLanguage(
957  if (state) {
958  auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state);
959  ast_importer = persistent_vars->GetClangASTImporter();
960  }
961  m_expr_decl_map_up = std::make_unique<ClangExpressionDeclMap>(
962  keep_result_in_memory, &delegate, exe_ctx.GetTargetSP(), ast_importer,
963  ctx_obj);
964 }
965 
966 clang::ASTConsumer *
968  clang::ASTConsumer *passthrough) {
969  m_result_synthesizer_up = std::make_unique<ASTResultSynthesizer>(
970  passthrough, m_top_level, m_target);
971 
972  return m_result_synthesizer_up.get();
973 }
974 
976  if (m_result_synthesizer_up) {
977  m_result_synthesizer_up->CommitPersistentDecls();
978  }
979 }
980 
982  return m_persistent_state->GetNextPersistentVariableName(false);
983 }
984 
986  lldb::ExpressionVariableSP &variable) {
987  m_variable = variable;
988 }
989 
991  PersistentExpressionState *persistent_state) {
992  m_persistent_state = persistent_state;
993 }
994 
996  return m_variable;
997 }
lldb_private::UserExpression::InstallContext
void InstallContext(ExecutionContext &exe_ctx)
Populate m_in_cplusplus_method and m_in_objectivec_method based on the environment.
Definition: UserExpression.cpp:58
Block.h
lldb_private::ClangUserExpression::ClangUserExpressionHelper::CommitPersistentDecls
void CommitPersistentDecls() override
Definition: ClangUserExpression.cpp:975
lldb_private::ClangUserExpression::m_clang_state
ClangPersistentVariables * m_clang_state
Definition: ClangUserExpression.h:231
lldb_private::ClangASTSource::SetLookupsEnabled
void SetLookupsEnabled(bool lookups_enabled)
Definition: ClangASTSource.h:200
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::SymbolContext::comp_unit
CompileUnit * comp_unit
The CompileUnit for a given query.
Definition: SymbolContext.h:319
lldb_private::CompileUnit::GetSupportFiles
const FileSpecList & GetSupportFiles()
Get the compile unit's support file list.
Definition: CompileUnit.cpp:387
lldb_private::DiagnosticManager::GetFixedExpression
const std::string & GetFixedExpression()
Definition: DiagnosticManager.h:138
lldb_private::Block::GetBlockVariableList
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition: Block.cpp:398
lldb_private::Log::GetVerbose
bool GetVerbose() const
Definition: Log.cpp:276
lldb_private::LLVMUserExpression::m_jit_module_wp
lldb::ModuleWP m_jit_module_wp
Definition: LLVMUserExpression.h:107
lldb_private::ClangUserExpression::m_result_delegate
ResultDelegate m_result_delegate
Definition: ClangUserExpression.h:230
lldb_private::LLVMUserExpression::m_can_interpret
bool m_can_interpret
True if the expression could be evaluated statically; false otherwise.
Definition: LLVMUserExpression.h:111
ClangModulesDeclVendor.h
CompileUnit.h
lldb_private::ExecutionPolicy
ExecutionPolicy
Expression execution policies.
Definition: lldb-private-enumerations.h:144
lldb_private::ClangUserExpression::CreateSourceCode
void CreateSourceCode(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, std::vector< std::string > modules_to_import, bool for_completion)
Definition: ClangUserExpression.cpp:413
ASTResultSynthesizer.h
lldb_private::ExecutionContext::GetProcessPtr
Process * GetProcessPtr() const
Returns a pointer to the process object.
Definition: ExecutionContext.cpp:208
lldb_private::CppModuleConfiguration::GetImportedModules
llvm::ArrayRef< std::string > GetImportedModules() const
Returns a list of (top level) modules that should be imported when using this configuration (e....
Definition: CppModuleConfiguration.h:83
lldb_private::ClangUserExpression::m_in_cplusplus_method
bool m_in_cplusplus_method
True if the expression is compiled as a C++ member function (true if it was parsed when exe_ctx was i...
Definition: ClangUserExpression.h:251
lldb_private::TypeSystemClang::DeclContextGetMetaData
static ClangASTMetadata * DeclContextGetMetaData(const CompilerDeclContext &dc, const clang::Decl *object)
Definition: TypeSystemClang.cpp:9664
lldb::eLanguageTypeC99
@ eLanguageTypeC99
ISO C:1999.
Definition: lldb-enumerations.h:449
lldb_private::UserExpression::FunctionName
const char * FunctionName() override
Return the function name that should be used for executing the expression.
Definition: UserExpression.h:193
lldb_private::LLVMUserExpression::m_allow_cxx
bool m_allow_cxx
True if the language allows C++.
Definition: LLVMUserExpression.h:97
lldb_private::AddressType
AddressType
Definition: lldb-private-enumerations.h:30
lldb_private::eImportStdModuleTrue
@ eImportStdModuleTrue
Definition: Target.h:70
lldb_private::Expression::m_jit_process_wp
lldb::ProcessWP m_jit_process_wp
Expression's always have to have a target...
Definition: Expression.h:93
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::eImportStdModuleFallback
@ eImportStdModuleFallback
Definition: Target.h:69
lldb_private::Process
Definition: Process.h:341
Module.h
CppModuleConfiguration.h
lldb_private::EvaluateExpressionOptions
Definition: Target.h:259
lldb_private::StackFrame::GetFrameBlock
Block * GetFrameBlock()
Get the current lexical scope block for this StackFrame, if possible.
Definition: StackFrame.cpp:273
AbsPosToLineColumnPos
static void AbsPosToLineColumnPos(size_t abs_pos, llvm::StringRef code, unsigned &line, unsigned &column)
Converts an absolute position inside a given code string into a column/line pair.
Definition: ClangUserExpression.cpp:784
lldb_private::ClangUserExpression::m_filename
std::string m_filename
File name used for the expression.
Definition: ClangUserExpression.h:236
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
SupportsCxxModuleImport
static bool SupportsCxxModuleImport(lldb::LanguageType language)
Definition: ClangUserExpression.cpp:443
lldb_private::ConstString::SetCString
void SetCString(const char *cstr)
Set the C string value.
Definition: ConstString.cpp:302
lldb_private::Expression::m_jit_start_addr
lldb::addr_t m_jit_start_addr
An expression might have a process, but it doesn't need to (e.g.
Definition: Expression.h:96
lldb_private::Module
Definition: Module.h:85
lldb_private::ClangUserExpression::ClangUserExpression
ClangUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, ResultType desired_type, const EvaluateExpressionOptions &options, ValueObject *ctx_obj)
Constructor.
Definition: ClangUserExpression.cpp:64
lldb_private::ExecutionContext::GetFramePtr
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Definition: ExecutionContext.h:408
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
lldb_private::TypeSystemClang::IsObjCObjectPointerType
static bool IsObjCObjectPointerType(const CompilerType &type, CompilerType *target_type=nullptr)
Definition: TypeSystemClang.cpp:3688
StackFrame.h
lldb_private::ClangUserExpression::ResetDeclMap
void ResetDeclMap()
Definition: ClangUserExpression.h:158
lldb_private::ClangUserExpression::ClangUserExpressionHelper::ResetDeclMap
void ResetDeclMap()
Definition: ClangUserExpression.h:64
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:444
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
shouldRetryWithCppModule
static bool shouldRetryWithCppModule(Target &target, ExecutionPolicy exe_policy)
Definition: ClangUserExpression.cpp:638
lldb_private::CppModuleConfiguration
A Clang configuration when importing C++ modules.
Definition: CppModuleConfiguration.h:22
lldb_private::ClangUserExpression::ResultDelegate::RegisterPersistentState
void RegisterPersistentState(PersistentExpressionState *persistent_state)
Definition: ClangUserExpression.cpp:990
IRInterpreter.h
lldb_private::Target::GetDebugger
Debugger & GetDebugger()
Definition: Target.h:1000
lldb_private::TypeSystemClang::DeclContextGetAsCXXMethodDecl
static clang::CXXMethodDecl * DeclContextGetAsCXXMethodDecl(const CompilerDeclContext &dc)
Definition: TypeSystemClang.cpp:9640
Debugger.h
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::Target
Definition: Target.h:451
lldb_private::UserExpression::m_fixed_text
std::string m_fixed_text
The text of the expression with fix-its applied.
Definition: UserExpression.h:298
lldb_private::eDiagnosticSeverityWarning
@ eDiagnosticSeverityWarning
Definition: DiagnosticManager.h:33
LLDB_LOGV
#define LLDB_LOGV(log,...)
Definition: Log.h:256
lldb_private::Target::GetImages
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:925
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::ClangUserExpression::ResultDelegate::GetName
ConstString GetName() override
Definition: ClangUserExpression.cpp:981
lldb::eLanguageTypeC_plus_plus_11
@ eLanguageTypeC_plus_plus_11
ISO C++:2011.
Definition: lldb-enumerations.h:465
Process.h
lldb_private::ClangASTMetadata::GetObjectPtrLanguage
lldb::LanguageType GetObjectPtrLanguage() const
Definition: ClangASTMetadata.h:65
lldb_private::eExecutionPolicyTopLevel
@ eExecutionPolicyTopLevel
Definition: lldb-private-enumerations.h:148
lldb_private::UserExpression::m_options
EvaluateExpressionOptions m_options
Additional options provided by the user.
Definition: UserExpression.h:306
lldb_private::Expression::ResultType
ResultType
Definition: Expression.h:35
Target.h
lldb_private::ClangUserExpression::~ClangUserExpression
~ClangUserExpression() override
LIBLLDB_LOG_EXPRESSIONS
#define LIBLLDB_LOG_EXPRESSIONS
Definition: Logging.h:22
lldb_private::ClangUserExpression::m_ctx_obj
ValueObject * m_ctx_obj
The object (if any) in which context the expression is evaluated.
Definition: ClangUserExpression.h:240
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:288
lldb_private::eDiagnosticSeverityError
@ eDiagnosticSeverityError
Definition: DiagnosticManager.h:32
lldb_private::TypeSystemClang::DeclContextGetAsFunctionDecl
static clang::FunctionDecl * DeclContextGetAsFunctionDecl(const CompilerDeclContext &dc)
Definition: TypeSystemClang.cpp:9648
lldb_private::CppModuleConfiguration::GetIncludeDirs
llvm::ArrayRef< std::string > GetIncludeDirs() const
Returns a list of include directories that should be used when using this configuration (e....
Definition: CppModuleConfiguration.h:79
lldb::eLanguageTypeC_plus_plus_03
@ eLanguageTypeC_plus_plus_03
ISO C++:2003.
Definition: lldb-enumerations.h:464
ClangASTMetadata.h
lldb_private::TypeSystemClang::DeclContextGetAsObjCMethodDecl
static clang::ObjCMethodDecl * DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc)
Definition: TypeSystemClang.cpp:9632
Log.h
lldb_private::ExecutionContextScope
Definition: ExecutionContextScope.h:32
TypeSystemClang.h
lldb_private::ClangModulesDeclVendor::ModuleVector
std::vector< ModuleID > ModuleVector
Definition: ClangModulesDeclVendor.h:37
lldb_private::ClangUserExpression::ScanContext
void ScanContext(ExecutionContext &exe_ctx, lldb_private::Status &err) override
Definition: ClangUserExpression.cpp:91
lldb_private::Expression::m_jit_end_addr
lldb::addr_t m_jit_end_addr
The address of the JITted function within the JIT allocation.
Definition: Expression.h:99
lldb_private::Debugger::GetAsyncOutputStream
lldb::StreamSP GetAsyncOutputStream()
Definition: Debugger.cpp:1150
lldb_private::ClangUserExpression::m_in_static_method
bool m_in_static_method
True if the expression is compiled as a static (or class) method (currently true if it was parsed whe...
Definition: ClangUserExpression.h:258
lldb_private::DiagnosticManager::HasFixIts
bool HasFixIts() const
Definition: DiagnosticManager.h:102
lldb_private::LLVMUserExpression::m_execution_unit_sp
std::shared_ptr< IRExecutionUnit > m_execution_unit_sp
The execution unit the expression is stored in.
Definition: LLVMUserExpression.h:103
lldb_private::SymbolContext::function
Function * function
The Function for a given query.
Definition: SymbolContext.h:320
lldb_private::LLVMUserExpression
Definition: LLVMUserExpression.h:32
StreamString.h
ClangPersistentVariables.h
Type.h
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ClangUserExpression::SetupCppModuleImports
void SetupCppModuleImports(ExecutionContext &exe_ctx)
Definition: ClangUserExpression.cpp:623
lldb_private::eDiagnosticSeverityRemark
@ eDiagnosticSeverityRemark
Definition: DiagnosticManager.h:34
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::ClangUserExpression::TryParse
bool TryParse(DiagnosticManager &diagnostic_manager, ExecutionContextScope *exe_scope, ExecutionContext &exe_ctx, lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory, bool generate_debug_info)
Populate m_in_cplusplus_method and m_in_objectivec_method based on the environment.
Definition: ClangUserExpression.cpp:555
lldb_private::ClangUserExpression::m_in_objectivec_method
bool m_in_objectivec_method
True if the expression is compiled as an Objective-C method (true if it was parsed when exe_ctx was i...
Definition: ClangUserExpression.h:254
lldb::eLanguageTypeC89
@ eLanguageTypeC89
ISO C:1989.
Definition: lldb-enumerations.h:438
ClangDiagnostic.h
lldb_private::Materializer::PersistentVariableDelegate
Definition: Materializer.h:70
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::SymbolContext::GetFunctionBlock
Block * GetFunctionBlock()
Find a block that defines the function represented by this symbol context.
Definition: SymbolContext.cpp:521
lldb_private::UserExpression::GetObjectPointer
static lldb::addr_t GetObjectPointer(lldb::StackFrameSP frame_sp, ConstString &object_name, Status &err)
Definition: UserExpression.cpp:100
lldb_private::ClangUserExpression::m_imported_cpp_modules
std::vector< std::string > m_imported_cpp_modules
A list of module names that should be imported when parsing.
Definition: ClangUserExpression.h:244
lldb::eLanguageTypeC11
@ eLanguageTypeC11
ISO C:2011.
Definition: lldb-enumerations.h:468
lldb_private::ClangUserExpression::m_source_code
std::unique_ptr< ClangExpressionSourceCode > m_source_code
Definition: ClangUserExpression.h:232
IRExecutionUnit.h
HostInfo.h
lldb_private::StreamString::Empty
bool Empty() const
Definition: StreamString.cpp:36
lldb_private::ClangUserExpression::SetupPersistentState
bool SetupPersistentState(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx)
Definition: ClangUserExpression.cpp:324
lldb_private::LLVMUserExpression::m_transformed_text
std::string m_transformed_text
The text of the expression, as send to the parser.
Definition: LLVMUserExpression.h:100
lldb_private::Target::GetPersistentExpressionStateForLanguage
PersistentExpressionState * GetPersistentExpressionStateForLanguage(lldb::LanguageType language)
Definition: Target.cpp:2320
lldb::eLanguageTypeObjC
@ eLanguageTypeObjC
Objective-C.
Definition: lldb-enumerations.h:453
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::eAddressTypeLoad
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
Definition: lldb-private-enumerations.h:34
lldb_private::ClangUserExpression::m_needs_object_ptr
bool m_needs_object_ptr
True if "this" or "self" must be looked up and passed in.
Definition: ClangUserExpression.h:261
lldb_private::ClangASTMetadata
Definition: ClangASTMetadata.h:18
lldb_private::ClangUserExpression::m_enforce_valid_object
bool m_enforce_valid_object
True if the expression parser should enforce the presence of a valid class pointer in order to genera...
Definition: ClangUserExpression.h:248
lldb_private::ClangExpressionSourceCode::WrapKind
WrapKind
The possible ways an expression can be wrapped.
Definition: ClangExpressionSourceCode.h:33
lldb_private::ClangExpressionParser::Complete
bool Complete(CompletionRequest &request, unsigned line, unsigned pos, unsigned typed_pos) override
Attempts to find possible command line completions for the given expression.
Definition: ClangExpressionParser.cpp:1010
ClangExpressionParser.h
GetModuleConfig
CppModuleConfiguration GetModuleConfig(lldb::LanguageType language, ExecutionContext &exe_ctx)
Definition: ClangUserExpression.cpp:464
lldb_private::CompileUnit::ForEachExternalModule
virtual bool ForEachExternalModule(llvm::DenseSet< lldb_private::SymbolFile * > &visited_symbol_files, llvm::function_ref< bool(Module &)> lambda)
Apply a lambda to each external lldb::Module referenced by this compilation unit.
Definition: CompileUnit.cpp:379
lldb::eLanguageTypeObjC_plus_plus
@ eLanguageTypeObjC_plus_plus
Objective-C++.
Definition: lldb-enumerations.h:454
VariableList.h
lldb_private::LLVMUserExpression::GetMaterializer
Materializer * GetMaterializer() override
Return the Materializer that the parser should use when registering external values.
Definition: LLVMUserExpression.h:68
SetupDeclVendor
static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target, DiagnosticManager &diagnostic_manager)
Definition: ClangUserExpression.cpp:346
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
lldb_private::ClangASTMetadata::HasObjectPtr
bool HasObjectPtr() const
Definition: ClangASTMetadata.h:85
lldb_private::Module::GetNumCompileUnits
size_t GetNumCompileUnits()
Get the number of compile units for this module.
Definition: Module.cpp:418
ObjectFile.h
ValueObjectConstResult.h
ThreadPlan.h
lldb_private::ClangUserExpression::m_parser
std::unique_ptr< ClangExpressionParser > m_parser
The parser instance we used to parse the expression.
Definition: ClangUserExpression.h:234
StreamFile.h
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:967
Materializer.h
lldb_private::Status
Definition: Status.h:44
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::ClangExpressionParser
Definition: ClangExpressionParser.h:45
lldb_private::Block
Definition: Block.h:41
lldb_private::TargetProperties::GetEnableAutoImportClangModules
bool GetEnableAutoImportClangModules() const
Definition: Target.cpp:4134
lldb_private::Block::GetDeclContext
CompilerDeclContext GetDeclContext()
Definition: Block.cpp:479
lldb_private::LLVMUserExpression::m_materializer_up
std::unique_ptr< Materializer > m_materializer_up
The materializer to use when running the expression.
Definition: LLVMUserExpression.h:104
ClangUserExpression.h
lldb_private::DiagnosticManager::PutString
size_t void PutString(DiagnosticSeverity severity, llvm::StringRef str)
Definition: DiagnosticManager.cpp:73
lldb_private::UserExpression::m_language
lldb::LanguageType m_language
The language to use when parsing (eLanguageTypeUnknown means use defaults)
Definition: UserExpression.h:301
lldb_private::ExecutionContext::GetFrameSP
const lldb::StackFrameSP & GetFrameSP() const
Get accessor to get the frame shared pointer.
Definition: ExecutionContext.h:469
lldb_private::TargetProperties::GetImportStdModule
ImportStdModule GetImportStdModule() const
Definition: Target.cpp:4140
lldb_private::Type
Definition: Type.h:66
lldb_private::ClangUserExpression::GetResultAfterDematerialization
lldb::ExpressionVariableSP GetResultAfterDematerialization(ExecutionContextScope *exe_scope) override
Definition: ClangUserExpression.cpp:944
lldb_private::Status::SetErrorString
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:242
lldb_private::LLVMUserExpression::m_allow_objc
bool m_allow_objc
True if the language allows Objective-C.
Definition: LLVMUserExpression.h:98
ThreadPlanCallUserExpression.h
lldb_private::DiagnosticManager
Definition: DiagnosticManager.h:93
lldb_private::Type::GetForwardCompilerType
CompilerType GetForwardCompilerType()
Definition: Type.cpp:656
ClangExpressionDeclMap.h
lldb_private::ClangUserExpression::ID
static char ID
Definition: ClangUserExpression.h:41
lldb::eLanguageTypeC_plus_plus_14
@ eLanguageTypeC_plus_plus_14
ISO C++:2014.
Definition: lldb-enumerations.h:472
lldb_private::ClangUserExpression::PrepareForParsing
bool PrepareForParsing(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, bool for_completion)
Definition: ClangUserExpression.cpp:522
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::ExecutionContext::GetTargetSP
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
Definition: ExecutionContext.h:454
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
lldb_private::ClangUserExpression::Parse
bool Parse(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory, bool generate_debug_info) override
Parse the expression.
Definition: ClangUserExpression.cpp:645
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
Function.h
lldb_private::ClangUserExpression::AddArguments
bool AddArguments(ExecutionContext &exe_ctx, std::vector< lldb::addr_t > &args, lldb::addr_t struct_address, DiagnosticManager &diagnostic_manager) override
Definition: ClangUserExpression.cpp:874
lldb_private::ClangUserExpression::ResultDelegate::DidDematerialize
void DidDematerialize(lldb::ExpressionVariableSP &variable) override
Definition: ClangUserExpression.cpp:985
lldb_private::ExecutionContext::GetTargetRef
Target & GetTargetRef() const
Returns a reference to the target object.
Definition: ExecutionContext.cpp:226
lldb_private::PersistentExpressionState
Definition: ExpressionVariable.h:203
lldb_private::LLVMUserExpression::m_target
Target * m_target
The target for storing persistent data like types and variables.
Definition: LLVMUserExpression.h:108
lldb::eLanguageTypeC
@ eLanguageTypeC
Non-standardized C, such as K&R.
Definition: lldb-enumerations.h:439
lldb_private::EvaluateExpressionOptions::GetExecutionPolicy
ExecutionPolicy GetExecutionPolicy() const
Definition: Target.h:279
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LogConfigError
static CppModuleConfiguration LogConfigError(const std::string &msg)
Utility method that puts a message into the expression log and returns an invalid module configuratio...
Definition: ClangUserExpression.cpp:458
lldb_private::ClangUserExpression::m_user_expression_start_pos
llvm::Optional< size_t > m_user_expression_start_pos
The absolute character position in the transformed source code where the user code (as typed by the u...
Definition: ClangUserExpression.h:229
lldb_private::ClangUserExpression::ClangUserExpressionHelper::m_expr_decl_map_up
std::unique_ptr< ClangExpressionDeclMap > m_expr_decl_map_up
Definition: ClangUserExpression.h:84
lldb_private::ClangUserExpression::ClangUserExpressionHelper::ASTTransformer
clang::ASTConsumer * ASTTransformer(clang::ASTConsumer *passthrough) override
Return the object that the parser should allow to access ASTs.
Definition: ClangUserExpression.cpp:967
lldb_private::ValueObject::GetAddressOf
virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr)
Definition: ValueObject.cpp:1399
lldb_private::ClangExpressionSourceCode::CreateWrapped
static ClangExpressionSourceCode * CreateWrapped(llvm::StringRef filename, llvm::StringRef prefix, llvm::StringRef body, WrapKind wrap_kind)
Definition: ClangExpressionSourceCode.h:45
ConstString.h
lldb_private::UserExpression::m_expr_prefix
std::string m_expr_prefix
The text of the translation-level definitions, as provided by the user.
Definition: UserExpression.h:296
lldb_private::UserExpression::m_expr_text
std::string m_expr_text
The text of the expression, as typed by the user.
Definition: UserExpression.h:295
lldb_private::ClangPersistentVariables::GetNextExprFileName
std::string GetNextExprFileName()
Returns the next file name that should be used for user expressions.
Definition: ClangPersistentVariables.h:60
lldb_private::ClangUserExpression::Complete
bool Complete(ExecutionContext &exe_ctx, CompletionRequest &request, unsigned complete_pos) override
Attempts to find possible command line completions for the given (possible incomplete) user expressio...
Definition: ClangUserExpression.cpp:806
lldb_private::Log
Definition: Log.h:49
SymbolVendor.h
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::ClangUserExpression::m_include_directories
std::vector< std::string > m_include_directories
The include directories that should be used when parsing the expression.
Definition: ClangUserExpression.h:224
lldb_private::ClangExpressionDeclMap::WillParse
bool WillParse(ExecutionContext &exe_ctx, Materializer *materializer)
Enable the state needed for parsing and IR transformation.
Definition: ClangExpressionDeclMap.cpp:85
lldb_private::FileSpec::GetFilename
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:339
lldb_private::Block::CalculateSymbolContext
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition: Block.cpp:135
lldb_private::StackFrame::GetSymbolContext
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:298
SymbolFile.h
lldb_private::ClangUserExpression::GetWrapKind
ClangExpressionSourceCode::WrapKind GetWrapKind() const
Defines how the current expression should be wrapped.
Definition: ClangUserExpression.cpp:397
lldb_private::ExecutionContext::GetTargetPtr
Target * GetTargetPtr() const
Returns a pointer to the target object.
Definition: ExecutionContext.cpp:200
ExecutionContext.h
ApplyObjcCastHack
static void ApplyObjcCastHack(std::string &expr)
Definition: ClangUserExpression.cpp:314
lldb_private::ModuleList::Append
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
ExpressionSourceCode.h
lldb_private::ClangUserExpression::DeclMap
ClangExpressionDeclMap * DeclMap()
Definition: ClangUserExpression.h:156
lldb_private::ClangUserExpression::ResultDelegate::GetVariable
lldb::ExpressionVariableSP & GetVariable()
Definition: ClangUserExpression.cpp:995
lldb_private::ValueObject::GetObjectRuntimeLanguage
virtual lldb::LanguageType GetObjectRuntimeLanguage()
Definition: ValueObject.h:373
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::TypeSystemClang::IsObjCClassType
static bool IsObjCClassType(const CompilerType &type)
Definition: TypeSystemClang.cpp:3432
lldb_private::Module::GetCompileUnitAtIndex
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
Definition: Module.cpp:427
lldb_private::DiagnosticManager::Printf
size_t Printf(DiagnosticSeverity severity, const char *format,...) __attribute__((format(printf
Definition: DiagnosticManager.cpp:59
lldb_private::Status::AsCString
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:131
lldb::eLanguageTypeC_plus_plus
@ eLanguageTypeC_plus_plus
ISO C++:1998.
Definition: lldb-enumerations.h:441