LLDB mainline
ClangExpressionDeclMap.cpp
Go to the documentation of this file.
1//===-- ClangExpressionDeclMap.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
10
11#include "ClangASTSource.h"
12#include "ClangExpressionUtil.h"
16#include "ClangUtil.h"
17
18#include "NameSearchContext.h"
20#include "lldb/Core/Address.h"
21#include "lldb/Core/Module.h"
35#include "lldb/Symbol/Type.h"
40#include "lldb/Target/Process.h"
43#include "lldb/Target/Target.h"
44#include "lldb/Target/Thread.h"
45#include "lldb/Utility/Endian.h"
47#include "lldb/Utility/Log.h"
49#include "lldb/Utility/Status.h"
51#include "lldb/lldb-private.h"
52#include "clang/AST/ASTConsumer.h"
53#include "clang/AST/ASTContext.h"
54#include "clang/AST/ASTImporter.h"
55#include "clang/AST/Decl.h"
56#include "clang/AST/DeclarationName.h"
57#include "clang/AST/RecursiveASTVisitor.h"
58
62
63using namespace lldb;
64using namespace lldb_private;
65using namespace clang;
66
67static const char *g_lldb_local_vars_namespace_cstr = "$__lldb_local_vars";
68
69namespace {
70/// A lambda is represented by Clang as an artifical class whose
71/// members are the lambda captures. If we capture a 'this' pointer,
72/// the artifical class will contain a member variable named 'this'.
73/// The function returns a ValueObject for the captured 'this' if such
74/// member exists. If no 'this' was captured, return a nullptr.
75lldb::ValueObjectSP GetCapturedThisValueObject(StackFrame *frame) {
76 assert(frame);
77
78 if (auto thisValSP = frame->FindVariable(ConstString("this")))
79 if (auto thisThisValSP = thisValSP->GetChildMemberWithName("this", true))
80 return thisThisValSP;
81
82 return nullptr;
83}
84} // namespace
85
87 bool keep_result_in_memory,
89 const lldb::TargetSP &target,
90 const std::shared_ptr<ClangASTImporter> &importer, ValueObject *ctx_obj)
91 : ClangASTSource(target, importer), m_found_entities(), m_struct_members(),
92 m_keep_result_in_memory(keep_result_in_memory),
93 m_result_delegate(result_delegate), m_ctx_obj(ctx_obj), m_parser_vars(),
94 m_struct_vars() {
96}
97
99 // Note: The model is now that the parser's AST context and all associated
100 // data does not vanish until the expression has been executed. This means
101 // that valuable lookup data (like namespaces) doesn't vanish, but
102
103 DidParse();
105}
106
108 Materializer *materializer) {
110 m_parser_vars->m_exe_ctx = exe_ctx;
111
112 Target *target = exe_ctx.GetTargetPtr();
113 if (exe_ctx.GetFramePtr())
114 m_parser_vars->m_sym_ctx =
115 exe_ctx.GetFramePtr()->GetSymbolContext(lldb::eSymbolContextEverything);
116 else if (exe_ctx.GetThreadPtr() &&
118 m_parser_vars->m_sym_ctx =
119 exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(0)->GetSymbolContext(
120 lldb::eSymbolContextEverything);
121 else if (exe_ctx.GetProcessPtr()) {
122 m_parser_vars->m_sym_ctx.Clear(true);
123 m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
124 } else if (target) {
125 m_parser_vars->m_sym_ctx.Clear(true);
126 m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
127 }
128
129 if (target) {
130 m_parser_vars->m_persistent_vars = llvm::cast<ClangPersistentVariables>(
132
134 return false;
135 }
136
137 m_parser_vars->m_target_info = GetTargetInfo();
138 m_parser_vars->m_materializer = materializer;
139
140 return true;
141}
142
144 clang::ASTConsumer *code_gen) {
145 assert(m_parser_vars);
146 m_parser_vars->m_code_gen = code_gen;
147}
148
150 DiagnosticManager &diag_manager) {
151 assert(m_parser_vars);
152 m_parser_vars->m_diagnostics = &diag_manager;
153}
154
156 if (m_parser_vars && m_parser_vars->m_persistent_vars) {
157 for (size_t entity_index = 0, num_entities = m_found_entities.GetSize();
158 entity_index < num_entities; ++entity_index) {
159 ExpressionVariableSP var_sp(
161 if (var_sp)
162 llvm::cast<ClangExpressionVariable>(var_sp.get())
163 ->DisableParserVars(GetParserID());
164 }
165
166 for (size_t pvar_index = 0,
167 num_pvars = m_parser_vars->m_persistent_vars->GetSize();
168 pvar_index < num_pvars; ++pvar_index) {
169 ExpressionVariableSP pvar_sp(
170 m_parser_vars->m_persistent_vars->GetVariableAtIndex(pvar_index));
171 if (ClangExpressionVariable *clang_var =
172 llvm::dyn_cast<ClangExpressionVariable>(pvar_sp.get()))
173 clang_var->DisableParserVars(GetParserID());
174 }
175
177 }
178}
179
180// Interface for IRForTarget
181
183 assert(m_parser_vars.get());
184
185 TargetInfo ret;
186
187 ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
188
189 Process *process = exe_ctx.GetProcessPtr();
190 if (process) {
191 ret.byte_order = process->GetByteOrder();
192 ret.address_byte_size = process->GetAddressByteSize();
193 } else {
194 Target *target = exe_ctx.GetTargetPtr();
195 if (target) {
196 ret.byte_order = target->GetArchitecture().GetByteOrder();
198 }
199 }
200
201 return ret;
202}
203
205 TypeSystemClang &source,
206 TypeFromParser parser_type) {
207 assert(&target == GetScratchContext(*m_target).get());
208 assert((TypeSystem *)&source ==
209 parser_type.GetTypeSystem().GetSharedPointer().get());
210 assert(&source.getASTContext() == m_ast_context);
211
212 return TypeFromUser(m_ast_importer_sp->DeportType(target, parser_type));
213}
214
216 ConstString name,
217 TypeFromParser parser_type,
218 bool is_result,
219 bool is_lvalue) {
220 assert(m_parser_vars.get());
221 auto ast = parser_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
222 if (ast == nullptr)
223 return false;
224
225 // Check if we already declared a persistent variable with the same name.
226 if (lldb::ExpressionVariableSP conflicting_var =
227 m_parser_vars->m_persistent_vars->GetVariable(name)) {
228 std::string msg = llvm::formatv("redefinition of persistent variable '{0}'",
229 name).str();
230 m_parser_vars->m_diagnostics->AddDiagnostic(
233 return false;
234 }
235
236 if (m_parser_vars->m_materializer && is_result) {
237 Status err;
238
239 ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
240 Target *target = exe_ctx.GetTargetPtr();
241 if (target == nullptr)
242 return false;
243
244 auto clang_ast_context = GetScratchContext(*target);
245 if (!clang_ast_context)
246 return false;
247
248 TypeFromUser user_type = DeportType(*clang_ast_context, *ast, parser_type);
249
250 uint32_t offset = m_parser_vars->m_materializer->AddResultVariable(
251 user_type, is_lvalue, m_keep_result_in_memory, m_result_delegate, err);
252
254 exe_ctx.GetBestExecutionContextScope(), name, user_type,
255 m_parser_vars->m_target_info.byte_order,
256 m_parser_vars->m_target_info.address_byte_size);
257
259
261
264
265 parser_vars->m_named_decl = decl;
266
268
270
271 jit_vars->m_offset = offset;
272
273 return true;
274 }
275
277 ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
278 Target *target = exe_ctx.GetTargetPtr();
279 if (target == nullptr)
280 return false;
281
282 auto context = GetScratchContext(*target);
283 if (!context)
284 return false;
285
286 TypeFromUser user_type = DeportType(*context, *ast, parser_type);
287
288 if (!user_type.GetOpaqueQualType()) {
289 LLDB_LOG(log, "Persistent variable's type wasn't copied successfully");
290 return false;
291 }
292
293 if (!m_parser_vars->m_target_info.IsValid())
294 return false;
295
296 if (!m_parser_vars->m_persistent_vars)
297 return false;
298
299 ClangExpressionVariable *var = llvm::cast<ClangExpressionVariable>(
300 m_parser_vars->m_persistent_vars
301 ->CreatePersistentVariable(
302 exe_ctx.GetBestExecutionContextScope(), name, user_type,
303 m_parser_vars->m_target_info.byte_order,
304 m_parser_vars->m_target_info.address_byte_size)
305 .get());
306
307 if (!var)
308 return false;
309
310 var->m_frozen_sp->SetHasCompleteType();
311
312 if (is_result)
313 var->m_flags |= ClangExpressionVariable::EVNeedsFreezeDry;
314 else
315 var->m_flags |=
316 ClangExpressionVariable::EVKeepInTarget; // explicitly-declared
317 // persistent variables should
318 // persist
319
320 if (is_lvalue) {
321 var->m_flags |= ClangExpressionVariable::EVIsProgramReference;
322 } else {
323 var->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
324 var->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
325 }
326
328 var->m_flags |= ClangExpressionVariable::EVKeepInTarget;
329 }
330
331 LLDB_LOG(log, "Created persistent variable with flags {0:x}", var->m_flags);
332
334
337
338 parser_vars->m_named_decl = decl;
339
340 return true;
341}
342
344 ConstString name,
345 llvm::Value *value, size_t size,
346 lldb::offset_t alignment) {
347 assert(m_struct_vars.get());
348 assert(m_parser_vars.get());
349
350 bool is_persistent_variable = false;
351
353
354 m_struct_vars->m_struct_laid_out = false;
355
357 GetParserID()))
358 return true;
359
361 m_found_entities, decl, GetParserID()));
362
363 if (!var && m_parser_vars->m_persistent_vars) {
365 *m_parser_vars->m_persistent_vars, decl, GetParserID());
366 is_persistent_variable = true;
367 }
368
369 if (!var)
370 return false;
371
372 LLDB_LOG(log, "Adding value for (NamedDecl*){0} [{1} - {2}] to the structure",
373 decl, name, var->GetName());
374
375 // We know entity->m_parser_vars is valid because we used a parser variable
376 // to find it
377
379 llvm::cast<ClangExpressionVariable>(var)->GetParserVars(GetParserID());
380
381 parser_vars->m_llvm_value = value;
382
384 llvm::cast<ClangExpressionVariable>(var)->GetJITVars(GetParserID())) {
385 // We already laid this out; do not touch
386
387 LLDB_LOG(log, "Already placed at {0:x}", jit_vars->m_offset);
388 }
389
390 llvm::cast<ClangExpressionVariable>(var)->EnableJITVars(GetParserID());
391
393 llvm::cast<ClangExpressionVariable>(var)->GetJITVars(GetParserID());
394
395 jit_vars->m_alignment = alignment;
396 jit_vars->m_size = size;
397
398 m_struct_members.AddVariable(var->shared_from_this());
399
400 if (m_parser_vars->m_materializer) {
401 uint32_t offset = 0;
402
403 Status err;
404
405 if (is_persistent_variable) {
406 ExpressionVariableSP var_sp(var->shared_from_this());
407 offset = m_parser_vars->m_materializer->AddPersistentVariable(
408 var_sp, nullptr, err);
409 } else {
410 if (const lldb_private::Symbol *sym = parser_vars->m_lldb_sym)
411 offset = m_parser_vars->m_materializer->AddSymbol(*sym, err);
412 else if (const RegisterInfo *reg_info = var->GetRegisterInfo())
413 offset = m_parser_vars->m_materializer->AddRegister(*reg_info, err);
414 else if (parser_vars->m_lldb_var)
415 offset = m_parser_vars->m_materializer->AddVariable(
416 parser_vars->m_lldb_var, err);
417 else if (parser_vars->m_lldb_valobj_provider) {
418 offset = m_parser_vars->m_materializer->AddValueObject(
419 name, parser_vars->m_lldb_valobj_provider, err);
420 }
421 }
422
423 if (!err.Success())
424 return false;
425
426 LLDB_LOG(log, "Placed at {0:x}", offset);
427
428 jit_vars->m_offset =
429 offset; // TODO DoStructLayout() should not change this.
430 }
431
432 return true;
433}
434
436 assert(m_struct_vars.get());
437
438 if (m_struct_vars->m_struct_laid_out)
439 return true;
440
441 if (!m_parser_vars->m_materializer)
442 return false;
443
444 m_struct_vars->m_struct_alignment =
445 m_parser_vars->m_materializer->GetStructAlignment();
446 m_struct_vars->m_struct_size =
447 m_parser_vars->m_materializer->GetStructByteSize();
448 m_struct_vars->m_struct_laid_out = true;
449 return true;
450}
451
452bool ClangExpressionDeclMap::GetStructInfo(uint32_t &num_elements, size_t &size,
453 lldb::offset_t &alignment) {
454 assert(m_struct_vars.get());
455
456 if (!m_struct_vars->m_struct_laid_out)
457 return false;
458
459 num_elements = m_struct_members.GetSize();
460 size = m_struct_vars->m_struct_size;
461 alignment = m_struct_vars->m_struct_alignment;
462
463 return true;
464}
465
467 llvm::Value *&value,
468 lldb::offset_t &offset,
469 ConstString &name,
470 uint32_t index) {
471 assert(m_struct_vars.get());
472
473 if (!m_struct_vars->m_struct_laid_out)
474 return false;
475
476 if (index >= m_struct_members.GetSize())
477 return false;
478
479 ExpressionVariableSP member_sp(m_struct_members.GetVariableAtIndex(index));
480
481 if (!member_sp)
482 return false;
483
485 llvm::cast<ClangExpressionVariable>(member_sp.get())
486 ->GetParserVars(GetParserID());
488 llvm::cast<ClangExpressionVariable>(member_sp.get())
489 ->GetJITVars(GetParserID());
490
491 if (!parser_vars || !jit_vars || !member_sp->GetValueObject())
492 return false;
493
494 decl = parser_vars->m_named_decl;
495 value = parser_vars->m_llvm_value;
496 offset = jit_vars->m_offset;
497 name = member_sp->GetName();
498
499 return true;
500}
501
503 uint64_t &ptr) {
505 m_found_entities, decl, GetParserID()));
506
507 if (!entity)
508 return false;
509
510 // We know m_parser_vars is valid since we searched for the variable by its
511 // NamedDecl
512
514 entity->GetParserVars(GetParserID());
515
516 ptr = parser_vars->m_lldb_value.GetScalar().ULongLong();
517
518 return true;
519}
520
522 Process *process,
523 ConstString name,
524 lldb::SymbolType symbol_type,
525 lldb_private::Module *module) {
526 SymbolContextList sc_list;
527
528 if (module)
529 module->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
530 else
531 target.GetImages().FindSymbolsWithNameAndType(name, symbol_type, sc_list);
532
533 addr_t symbol_load_addr = LLDB_INVALID_ADDRESS;
534
535 for (const SymbolContext &sym_ctx : sc_list) {
536 if (symbol_load_addr != 0 && symbol_load_addr != LLDB_INVALID_ADDRESS)
537 break;
538
539 const Address sym_address = sym_ctx.symbol->GetAddress();
540
541 if (!sym_address.IsValid())
542 continue;
543
544 switch (sym_ctx.symbol->GetType()) {
545 case eSymbolTypeCode:
547 symbol_load_addr = sym_address.GetCallableLoadAddress(&target);
548 break;
549
551 symbol_load_addr = sym_address.GetCallableLoadAddress(&target, true);
552 break;
553
555 ConstString reexport_name = sym_ctx.symbol->GetReExportedSymbolName();
556 if (reexport_name) {
557 ModuleSP reexport_module_sp;
558 ModuleSpec reexport_module_spec;
559 reexport_module_spec.GetPlatformFileSpec() =
560 sym_ctx.symbol->GetReExportedSymbolSharedLibrary();
561 if (reexport_module_spec.GetPlatformFileSpec()) {
562 reexport_module_sp =
563 target.GetImages().FindFirstModule(reexport_module_spec);
564 if (!reexport_module_sp) {
565 reexport_module_spec.GetPlatformFileSpec().ClearDirectory();
566 reexport_module_sp =
567 target.GetImages().FindFirstModule(reexport_module_spec);
568 }
569 }
570 symbol_load_addr = GetSymbolAddress(
571 target, process, sym_ctx.symbol->GetReExportedSymbolName(),
572 symbol_type, reexport_module_sp.get());
573 }
574 } break;
575
576 case eSymbolTypeData:
579 case eSymbolTypeLocal:
580 case eSymbolTypeParam:
588 case eSymbolTypeBlock:
601 symbol_load_addr = sym_address.GetLoadAddress(&target);
602 break;
603 }
604 }
605
606 if (symbol_load_addr == LLDB_INVALID_ADDRESS && process) {
608
609 if (runtime) {
610 symbol_load_addr = runtime->LookupRuntimeSymbol(name);
611 }
612 }
613
614 return symbol_load_addr;
615}
616
618 lldb::SymbolType symbol_type) {
619 assert(m_parser_vars.get());
620
621 if (!m_parser_vars->m_exe_ctx.GetTargetPtr())
622 return false;
623
624 return GetSymbolAddress(m_parser_vars->m_exe_ctx.GetTargetRef(),
625 m_parser_vars->m_exe_ctx.GetProcessPtr(), name,
626 symbol_type);
627}
628
630 Target &target, ModuleSP &module, ConstString name,
631 const CompilerDeclContext &namespace_decl) {
632 VariableList vars;
633
634 if (module && namespace_decl)
635 module->FindGlobalVariables(name, namespace_decl, -1, vars);
636 else
637 target.GetImages().FindGlobalVariables(name, -1, vars);
638
639 if (vars.GetSize() == 0)
640 return VariableSP();
641 return vars.GetVariableAtIndex(0);
642}
643
645 StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
646 if (frame == nullptr)
647 return nullptr;
648
649 SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
650 lldb::eSymbolContextBlock);
651 if (sym_ctx.block == nullptr)
652 return nullptr;
653
654 CompilerDeclContext frame_decl_context = sym_ctx.block->GetDeclContext();
655 if (!frame_decl_context)
656 return nullptr;
657
658 return llvm::dyn_cast_or_null<TypeSystemClang>(
659 frame_decl_context.GetTypeSystem());
660}
661
662// Interface for ClangASTSource
663
665 NameSearchContext &context) {
666 assert(m_ast_context);
667
668 const ConstString name(context.m_decl_name.getAsString().c_str());
669
671
672 if (log) {
673 if (!context.m_decl_context)
674 LLDB_LOG(log,
675 "ClangExpressionDeclMap::FindExternalVisibleDecls for "
676 "'{0}' in a NULL DeclContext",
677 name);
678 else if (const NamedDecl *context_named_decl =
679 dyn_cast<NamedDecl>(context.m_decl_context))
680 LLDB_LOG(log,
681 "ClangExpressionDeclMap::FindExternalVisibleDecls for "
682 "'{0}' in '{1}'",
683 name, context_named_decl->getNameAsString());
684 else
685 LLDB_LOG(log,
686 "ClangExpressionDeclMap::FindExternalVisibleDecls for "
687 "'{0}' in a '{1}'",
688 name, context.m_decl_context->getDeclKindName());
689 }
690
691 if (const NamespaceDecl *namespace_context =
692 dyn_cast<NamespaceDecl>(context.m_decl_context)) {
693 if (namespace_context->getName().str() ==
695 CompilerDeclContext compiler_decl_ctx =
697 const_cast<clang::DeclContext *>(context.m_decl_context));
698 FindExternalVisibleDecls(context, lldb::ModuleSP(), compiler_decl_ctx);
699 return;
700 }
701
703 m_ast_importer_sp->GetNamespaceMap(namespace_context);
704
705 if (!namespace_map)
706 return;
707
708 LLDB_LOGV(log, " CEDM::FEVD Inspecting (NamespaceMap*){0:x} ({1} entries)",
709 namespace_map.get(), namespace_map->size());
710
711 for (ClangASTImporter::NamespaceMapItem &n : *namespace_map) {
712 LLDB_LOG(log, " CEDM::FEVD Searching namespace {0} in module {1}",
713 n.second.GetName(), n.first->GetFileSpec().GetFilename());
714
715 FindExternalVisibleDecls(context, n.first, n.second);
716 }
717 } else if (isa<TranslationUnitDecl>(context.m_decl_context)) {
718 CompilerDeclContext namespace_decl;
719
720 LLDB_LOG(log, " CEDM::FEVD Searching the root namespace");
721
722 FindExternalVisibleDecls(context, lldb::ModuleSP(), namespace_decl);
723 }
724
726}
727
729 FunctionDecl *copied_function_decl) {
730 if (copied_function_decl->getBody() && m_parser_vars->m_code_gen) {
731 clang::DeclGroupRef decl_group_ref(copied_function_decl);
732 m_parser_vars->m_code_gen->HandleTopLevelDecl(decl_group_ref);
733 }
734}
735
737 if (!m_parser_vars)
738 return nullptr;
739 Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
740 if (!target)
741 return nullptr;
742
744
745 if (!m_parser_vars->m_persistent_vars)
746 return nullptr;
747 return m_parser_vars->m_persistent_vars->GetPersistentDecl(name);
748}
749
751 const ConstString name) {
753
754 NamedDecl *persistent_decl = GetPersistentDecl(name);
755
756 if (!persistent_decl)
757 return;
758
759 Decl *parser_persistent_decl = CopyDecl(persistent_decl);
760
761 if (!parser_persistent_decl)
762 return;
763
764 NamedDecl *parser_named_decl = dyn_cast<NamedDecl>(parser_persistent_decl);
765
766 if (!parser_named_decl)
767 return;
768
769 if (clang::FunctionDecl *parser_function_decl =
770 llvm::dyn_cast<clang::FunctionDecl>(parser_named_decl)) {
771 MaybeRegisterFunctionBody(parser_function_decl);
772 }
773
774 LLDB_LOG(log, " CEDM::FEVD Found persistent decl {0}", name);
775
776 context.AddNamedDecl(parser_named_decl);
777}
778
781
782 StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
783 SymbolContext sym_ctx;
784 if (frame != nullptr)
785 sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
786 lldb::eSymbolContextBlock);
787
788 if (m_ctx_obj) {
789 Status status;
790 lldb::ValueObjectSP ctx_obj_ptr = m_ctx_obj->AddressOf(status);
791 if (!ctx_obj_ptr || status.Fail())
792 return;
793
795 return;
796 }
797
798 // Clang is looking for the type of "this"
799
800 if (frame == nullptr)
801 return;
802
803 // Find the block that defines the function represented by "sym_ctx"
804 Block *function_block = sym_ctx.GetFunctionBlock();
805
806 if (!function_block)
807 return;
808
809 CompilerDeclContext function_decl_ctx = function_block->GetDeclContext();
810
811 if (!function_decl_ctx)
812 return;
813
814 clang::CXXMethodDecl *method_decl =
816
817 if (method_decl) {
818 if (auto capturedThis = GetCapturedThisValueObject(frame)) {
819 // We're inside a lambda and we captured a 'this'.
820 // Import the outer class's AST instead of the
821 // (unnamed) lambda structure AST so unqualified
822 // member lookups are understood by the Clang parser.
823 //
824 // If we're in a lambda which didn't capture 'this',
825 // $__lldb_class will correspond to the lambda closure
826 // AST and references to captures will resolve like
827 // regular member varaiable accesses do.
828 TypeFromUser pointee_type =
829 capturedThis->GetCompilerType().GetPointeeType();
830
831 LLDB_LOG(log,
832 " CEDM::FEVD Adding captured type ({0} for"
833 " $__lldb_class: {1}",
834 capturedThis->GetTypeName(), capturedThis->GetName());
835
836 AddContextClassType(context, pointee_type);
837 return;
838 }
839
840 clang::CXXRecordDecl *class_decl = method_decl->getParent();
841
842 QualType class_qual_type(class_decl->getTypeForDecl(), 0);
843
844 TypeFromUser class_user_type(
845 class_qual_type.getAsOpaquePtr(),
846 function_decl_ctx.GetTypeSystem()->weak_from_this());
847
848 LLDB_LOG(log, " CEDM::FEVD Adding type for $__lldb_class: {0}",
849 class_qual_type.getAsString());
850
851 AddContextClassType(context, class_user_type);
852 return;
853 }
854
855 // This branch will get hit if we are executing code in the context of
856 // a function that claims to have an object pointer (through
857 // DW_AT_object_pointer?) but is not formally a method of the class.
858 // In that case, just look up the "this" variable in the current scope
859 // and use its type.
860 // FIXME: This code is formally correct, but clang doesn't currently
861 // emit DW_AT_object_pointer
862 // for C++ so it hasn't actually been tested.
863
864 VariableList *vars = frame->GetVariableList(false, nullptr);
865
866 lldb::VariableSP this_var = vars->FindVariable(ConstString("this"));
867
868 if (this_var && this_var->IsInScope(frame) &&
869 this_var->LocationIsValidForFrame(frame)) {
870 Type *this_type = this_var->GetType();
871
872 if (!this_type)
873 return;
874
875 TypeFromUser pointee_type =
877
878 LLDB_LOG(log, " FEVD Adding type for $__lldb_class: {0}",
879 ClangUtil::GetQualType(pointee_type).getAsString());
880
881 AddContextClassType(context, pointee_type);
882 }
883}
884
887
888 StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
889
890 if (m_ctx_obj) {
891 Status status;
892 lldb::ValueObjectSP ctx_obj_ptr = m_ctx_obj->AddressOf(status);
893 if (!ctx_obj_ptr || status.Fail())
894 return;
895
897 return;
898 }
899
900 // Clang is looking for the type of "*self"
901
902 if (!frame)
903 return;
904
905 SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
906 lldb::eSymbolContextBlock);
907
908 // Find the block that defines the function represented by "sym_ctx"
909 Block *function_block = sym_ctx.GetFunctionBlock();
910
911 if (!function_block)
912 return;
913
914 CompilerDeclContext function_decl_ctx = function_block->GetDeclContext();
915
916 if (!function_decl_ctx)
917 return;
918
919 clang::ObjCMethodDecl *method_decl =
921
922 if (method_decl) {
923 ObjCInterfaceDecl *self_interface = method_decl->getClassInterface();
924
925 if (!self_interface)
926 return;
927
928 const clang::Type *interface_type = self_interface->getTypeForDecl();
929
930 if (!interface_type)
931 return; // This is unlikely, but we have seen crashes where this
932 // occurred
933
934 TypeFromUser class_user_type(
935 QualType(interface_type, 0).getAsOpaquePtr(),
936 function_decl_ctx.GetTypeSystem()->weak_from_this());
937
938 LLDB_LOG(log, " FEVD[{0}] Adding type for $__lldb_objc_class: {1}",
939 ClangUtil::ToString(interface_type));
940
941 AddOneType(context, class_user_type);
942 return;
943 }
944 // This branch will get hit if we are executing code in the context of
945 // a function that claims to have an object pointer (through
946 // DW_AT_object_pointer?) but is not formally a method of the class.
947 // In that case, just look up the "self" variable in the current scope
948 // and use its type.
949
950 VariableList *vars = frame->GetVariableList(false, nullptr);
951
952 lldb::VariableSP self_var = vars->FindVariable(ConstString("self"));
953
954 if (!self_var)
955 return;
956 if (!self_var->IsInScope(frame))
957 return;
958 if (!self_var->LocationIsValidForFrame(frame))
959 return;
960
961 Type *self_type = self_var->GetType();
962
963 if (!self_type)
964 return;
965
966 CompilerType self_clang_type = self_type->GetFullCompilerType();
967
968 if (TypeSystemClang::IsObjCClassType(self_clang_type)) {
969 return;
970 }
971 if (!TypeSystemClang::IsObjCObjectPointerType(self_clang_type))
972 return;
973 self_clang_type = self_clang_type.GetPointeeType();
974
975 if (!self_clang_type)
976 return;
977
978 LLDB_LOG(log, " FEVD[{0}] Adding type for $__lldb_objc_class: {1}",
980
981 TypeFromUser class_user_type(self_clang_type);
982
983 AddOneType(context, class_user_type);
984}
985
987 SymbolContext &sym_ctx, NameSearchContext &name_context) {
988 if (sym_ctx.block == nullptr)
989 return;
990
991 CompilerDeclContext frame_decl_context = sym_ctx.block->GetDeclContext();
992 if (!frame_decl_context)
993 return;
994
995 TypeSystemClang *frame_ast = llvm::dyn_cast_or_null<TypeSystemClang>(
996 frame_decl_context.GetTypeSystem());
997 if (!frame_ast)
998 return;
999
1000 clang::NamespaceDecl *namespace_decl =
1003 if (!namespace_decl)
1004 return;
1005
1006 name_context.AddNamedDecl(namespace_decl);
1007 clang::DeclContext *ctxt = clang::Decl::castToDeclContext(namespace_decl);
1008 ctxt->setHasExternalVisibleStorage(true);
1009 name_context.m_found_local_vars_nsp = true;
1010}
1011
1013 NameSearchContext &context, ConstString name) {
1015
1016 if (!m_target)
1017 return;
1018
1019 std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor =
1021 if (!modules_decl_vendor)
1022 return;
1023
1024 bool append = false;
1025 uint32_t max_matches = 1;
1026 std::vector<clang::NamedDecl *> decls;
1027
1028 if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls))
1029 return;
1030
1031 assert(!decls.empty() && "FindDecls returned true but no decls?");
1032 clang::NamedDecl *const decl_from_modules = decls[0];
1033
1034 LLDB_LOG(log,
1035 " CAS::FEVD Matching decl found for "
1036 "\"{0}\" in the modules",
1037 name);
1038
1039 clang::Decl *copied_decl = CopyDecl(decl_from_modules);
1040 if (!copied_decl) {
1041 LLDB_LOG(log, " CAS::FEVD - Couldn't export a "
1042 "declaration from the modules");
1043 return;
1044 }
1045
1046 if (auto copied_function = dyn_cast<clang::FunctionDecl>(copied_decl)) {
1047 MaybeRegisterFunctionBody(copied_function);
1048
1049 context.AddNamedDecl(copied_function);
1050
1051 context.m_found_function_with_type_info = true;
1052 context.m_found_function = true;
1053 } else if (auto copied_var = dyn_cast<clang::VarDecl>(copied_decl)) {
1054 context.AddNamedDecl(copied_var);
1055 context.m_found_variable = true;
1056 }
1057}
1058
1060 NameSearchContext &context, ConstString name, SymbolContext &sym_ctx,
1061 const CompilerDeclContext &namespace_decl) {
1062 if (sym_ctx.block == nullptr)
1063 return false;
1064
1065 CompilerDeclContext decl_context = sym_ctx.block->GetDeclContext();
1066 if (!decl_context)
1067 return false;
1068
1069 // Make sure that the variables are parsed so that we have the
1070 // declarations.
1071 StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
1072 VariableListSP vars = frame->GetInScopeVariableList(true);
1073 for (size_t i = 0; i < vars->GetSize(); i++)
1074 vars->GetVariableAtIndex(i)->GetDecl();
1075
1076 // Search for declarations matching the name. Do not include imported
1077 // decls in the search if we are looking for decls in the artificial
1078 // namespace $__lldb_local_vars.
1079 std::vector<CompilerDecl> found_decls =
1080 decl_context.FindDeclByName(name, namespace_decl.IsValid());
1081
1082 VariableSP var;
1083 bool variable_found = false;
1084 for (CompilerDecl decl : found_decls) {
1085 for (size_t vi = 0, ve = vars->GetSize(); vi != ve; ++vi) {
1086 VariableSP candidate_var = vars->GetVariableAtIndex(vi);
1087 if (candidate_var->GetDecl() == decl) {
1088 var = candidate_var;
1089 break;
1090 }
1091 }
1092
1093 if (var && !variable_found) {
1094 variable_found = true;
1095 ValueObjectSP valobj = ValueObjectVariable::Create(frame, var);
1096 AddOneVariable(context, var, valobj);
1097 context.m_found_variable = true;
1098 }
1099 }
1100
1101 // We're in a local_var_lookup but haven't found any local variables
1102 // so far. When performing a variable lookup from within the context of
1103 // a lambda, we count the lambda captures as local variables. Thus,
1104 // see if we captured any variables with the requested 'name'.
1105 if (!variable_found) {
1106 auto find_capture = [](ConstString varname,
1107 StackFrame *frame) -> ValueObjectSP {
1108 if (auto lambda = ClangExpressionUtil::GetLambdaValueObject(frame)) {
1109 if (auto capture = lambda->GetChildMemberWithName(varname, true)) {
1110 return capture;
1111 }
1112 }
1113
1114 return nullptr;
1115 };
1116
1117 if (auto capture = find_capture(name, frame)) {
1118 variable_found = true;
1119 context.m_found_variable = true;
1120 AddOneVariable(context, std::move(capture), std::move(find_capture));
1121 }
1122 }
1123
1124 return variable_found;
1125}
1126
1127/// Structure to hold the info needed when comparing function
1128/// declarations.
1129namespace {
1130struct FuncDeclInfo {
1131 ConstString m_name;
1132 CompilerType m_copied_type;
1133 uint32_t m_decl_lvl;
1134 SymbolContext m_sym_ctx;
1135};
1136} // namespace
1137
1139 const SymbolContextList &sc_list,
1140 const CompilerDeclContext &frame_decl_context) {
1141 // First, symplify things by looping through the symbol contexts to
1142 // remove unwanted functions and separate out the functions we want to
1143 // compare and prune into a separate list. Cache the info needed about
1144 // the function declarations in a vector for efficiency.
1145 SymbolContextList sc_sym_list;
1146 std::vector<FuncDeclInfo> decl_infos;
1147 decl_infos.reserve(sc_list.GetSize());
1148 clang::DeclContext *frame_decl_ctx =
1149 (clang::DeclContext *)frame_decl_context.GetOpaqueDeclContext();
1150 TypeSystemClang *ast = llvm::dyn_cast_or_null<TypeSystemClang>(
1151 frame_decl_context.GetTypeSystem());
1152
1153 for (const SymbolContext &sym_ctx : sc_list) {
1154 FuncDeclInfo fdi;
1155
1156 // We don't know enough about symbols to compare them, but we should
1157 // keep them in the list.
1158 Function *function = sym_ctx.function;
1159 if (!function) {
1160 sc_sym_list.Append(sym_ctx);
1161 continue;
1162 }
1163 // Filter out functions without declaration contexts, as well as
1164 // class/instance methods, since they'll be skipped in the code that
1165 // follows anyway.
1166 CompilerDeclContext func_decl_context = function->GetDeclContext();
1167 if (!func_decl_context || func_decl_context.IsClassMethod())
1168 continue;
1169 // We can only prune functions for which we can copy the type.
1170 CompilerType func_clang_type = function->GetType()->GetFullCompilerType();
1171 CompilerType copied_func_type = GuardedCopyType(func_clang_type);
1172 if (!copied_func_type) {
1173 sc_sym_list.Append(sym_ctx);
1174 continue;
1175 }
1176
1177 fdi.m_sym_ctx = sym_ctx;
1178 fdi.m_name = function->GetName();
1179 fdi.m_copied_type = copied_func_type;
1180 fdi.m_decl_lvl = LLDB_INVALID_DECL_LEVEL;
1181 if (fdi.m_copied_type && func_decl_context) {
1182 // Call CountDeclLevels to get the number of parent scopes we have
1183 // to look through before we find the function declaration. When
1184 // comparing functions of the same type, the one with a lower count
1185 // will be closer to us in the lookup scope and shadows the other.
1186 clang::DeclContext *func_decl_ctx =
1187 (clang::DeclContext *)func_decl_context.GetOpaqueDeclContext();
1188 fdi.m_decl_lvl = ast->CountDeclLevels(frame_decl_ctx, func_decl_ctx,
1189 &fdi.m_name, &fdi.m_copied_type);
1190 }
1191 decl_infos.emplace_back(fdi);
1192 }
1193
1194 // Loop through the functions in our cache looking for matching types,
1195 // then compare their scope levels to see which is closer.
1196 std::multimap<CompilerType, const FuncDeclInfo *> matches;
1197 for (const FuncDeclInfo &fdi : decl_infos) {
1198 const CompilerType t = fdi.m_copied_type;
1199 auto q = matches.find(t);
1200 if (q != matches.end()) {
1201 if (q->second->m_decl_lvl > fdi.m_decl_lvl)
1202 // This function is closer; remove the old set.
1203 matches.erase(t);
1204 else if (q->second->m_decl_lvl < fdi.m_decl_lvl)
1205 // The functions in our set are closer - skip this one.
1206 continue;
1207 }
1208 matches.insert(std::make_pair(t, &fdi));
1209 }
1210
1211 // Loop through our matches and add their symbol contexts to our list.
1212 SymbolContextList sc_func_list;
1213 for (const auto &q : matches)
1214 sc_func_list.Append(q.second->m_sym_ctx);
1215
1216 // Rejoin the lists with the functions in front.
1217 sc_func_list.Append(sc_sym_list);
1218 return sc_func_list;
1219}
1220
1222 NameSearchContext &context, lldb::ModuleSP module_sp, ConstString name,
1223 const CompilerDeclContext &namespace_decl) {
1224 if (!m_parser_vars)
1225 return;
1226
1227 Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1228
1229 std::vector<clang::NamedDecl *> decls_from_modules;
1230
1231 if (target) {
1232 if (std::shared_ptr<ClangModulesDeclVendor> decl_vendor =
1234 decl_vendor->FindDecls(name, false, UINT32_MAX, decls_from_modules);
1235 }
1236 }
1237
1238 SymbolContextList sc_list;
1239 if (namespace_decl && module_sp) {
1240 ModuleFunctionSearchOptions function_options;
1241 function_options.include_inlines = false;
1242 function_options.include_symbols = false;
1243
1244 module_sp->FindFunctions(name, namespace_decl, eFunctionNameTypeBase,
1245 function_options, sc_list);
1246 } else if (target && !namespace_decl) {
1247 ModuleFunctionSearchOptions function_options;
1248 function_options.include_inlines = false;
1249 function_options.include_symbols = true;
1250
1251 // TODO Fix FindFunctions so that it doesn't return
1252 // instance methods for eFunctionNameTypeBase.
1253
1254 target->GetImages().FindFunctions(
1255 name, eFunctionNameTypeFull | eFunctionNameTypeBase, function_options,
1256 sc_list);
1257 }
1258
1259 // If we found more than one function, see if we can use the frame's decl
1260 // context to remove functions that are shadowed by other functions which
1261 // match in type but are nearer in scope.
1262 //
1263 // AddOneFunction will not add a function whose type has already been
1264 // added, so if there's another function in the list with a matching type,
1265 // check to see if their decl context is a parent of the current frame's or
1266 // was imported via a and using statement, and pick the best match
1267 // according to lookup rules.
1268 if (sc_list.GetSize() > 1) {
1269 // Collect some info about our frame's context.
1270 StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
1271 SymbolContext frame_sym_ctx;
1272 if (frame != nullptr)
1273 frame_sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
1274 lldb::eSymbolContextBlock);
1275 CompilerDeclContext frame_decl_context =
1276 frame_sym_ctx.block != nullptr ? frame_sym_ctx.block->GetDeclContext()
1278
1279 // We can't do this without a compiler decl context for our frame.
1280 if (frame_decl_context) {
1281 sc_list = SearchFunctionsInSymbolContexts(sc_list, frame_decl_context);
1282 }
1283 }
1284
1285 if (sc_list.GetSize()) {
1286 Symbol *extern_symbol = nullptr;
1287 Symbol *non_extern_symbol = nullptr;
1288
1289 for (const SymbolContext &sym_ctx : sc_list) {
1290 if (sym_ctx.function) {
1291 CompilerDeclContext decl_ctx = sym_ctx.function->GetDeclContext();
1292
1293 if (!decl_ctx)
1294 continue;
1295
1296 // Filter out class/instance methods.
1297 if (decl_ctx.IsClassMethod())
1298 continue;
1299
1300 AddOneFunction(context, sym_ctx.function, nullptr);
1301 context.m_found_function_with_type_info = true;
1302 context.m_found_function = true;
1303 } else if (sym_ctx.symbol) {
1304 Symbol *symbol = sym_ctx.symbol;
1305 if (target && symbol->GetType() == eSymbolTypeReExported) {
1306 symbol = symbol->ResolveReExportedSymbol(*target);
1307 if (symbol == nullptr)
1308 continue;
1309 }
1310
1311 if (symbol->IsExternal())
1312 extern_symbol = symbol;
1313 else
1314 non_extern_symbol = symbol;
1315 }
1316 }
1317
1318 if (!context.m_found_function_with_type_info) {
1319 for (clang::NamedDecl *decl : decls_from_modules) {
1320 if (llvm::isa<clang::FunctionDecl>(decl)) {
1321 clang::NamedDecl *copied_decl =
1322 llvm::cast_or_null<FunctionDecl>(CopyDecl(decl));
1323 if (copied_decl) {
1324 context.AddNamedDecl(copied_decl);
1325 context.m_found_function_with_type_info = true;
1326 }
1327 }
1328 }
1329 }
1330
1331 if (!context.m_found_function_with_type_info) {
1332 if (extern_symbol) {
1333 AddOneFunction(context, nullptr, extern_symbol);
1334 context.m_found_function = true;
1335 } else if (non_extern_symbol) {
1336 AddOneFunction(context, nullptr, non_extern_symbol);
1337 context.m_found_function = true;
1338 }
1339 }
1340 }
1341}
1342
1344 NameSearchContext &context, lldb::ModuleSP module_sp,
1345 const CompilerDeclContext &namespace_decl) {
1346 assert(m_ast_context);
1347
1349
1350 const ConstString name(context.m_decl_name.getAsString().c_str());
1351 if (IgnoreName(name, false))
1352 return;
1353
1354 // Only look for functions by name out in our symbols if the function doesn't
1355 // start with our phony prefix of '$'
1356
1357 Target *target = nullptr;
1358 StackFrame *frame = nullptr;
1359 SymbolContext sym_ctx;
1360 if (m_parser_vars) {
1361 target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1362 frame = m_parser_vars->m_exe_ctx.GetFramePtr();
1363 }
1364 if (frame != nullptr)
1365 sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
1366 lldb::eSymbolContextBlock);
1367
1368 // Try the persistent decls, which take precedence over all else.
1369 if (!namespace_decl)
1370 SearchPersistenDecls(context, name);
1371
1372 if (name.GetStringRef().startswith("$") && !namespace_decl) {
1373 if (name == "$__lldb_class") {
1374 LookUpLldbClass(context);
1375 return;
1376 }
1377
1378 if (name == "$__lldb_objc_class") {
1379 LookUpLldbObjCClass(context);
1380 return;
1381 }
1383 LookupLocalVarNamespace(sym_ctx, context);
1384 return;
1385 }
1386
1387 // any other $__lldb names should be weeded out now
1388 if (name.GetStringRef().startswith("$__lldb"))
1389 return;
1390
1391 // No ParserVars means we can't do register or variable lookup.
1392 if (!m_parser_vars || !m_parser_vars->m_persistent_vars)
1393 return;
1394
1395 ExpressionVariableSP pvar_sp(
1396 m_parser_vars->m_persistent_vars->GetVariable(name));
1397
1398 if (pvar_sp) {
1399 AddOneVariable(context, pvar_sp);
1400 return;
1401 }
1402
1403 assert(name.GetStringRef().startswith("$"));
1404 llvm::StringRef reg_name = name.GetStringRef().substr(1);
1405
1406 if (m_parser_vars->m_exe_ctx.GetRegisterContext()) {
1407 const RegisterInfo *reg_info(
1408 m_parser_vars->m_exe_ctx.GetRegisterContext()->GetRegisterInfoByName(
1409 reg_name));
1410
1411 if (reg_info) {
1412 LLDB_LOG(log, " CEDM::FEVD Found register {0}", reg_info->name);
1413
1414 AddOneRegister(context, reg_info);
1415 }
1416 }
1417 return;
1418 }
1419
1420 bool local_var_lookup = !namespace_decl || (namespace_decl.GetName() ==
1422 if (frame && local_var_lookup)
1423 if (LookupLocalVariable(context, name, sym_ctx, namespace_decl))
1424 return;
1425
1426 if (target) {
1427 ValueObjectSP valobj;
1428 VariableSP var;
1429 var = FindGlobalVariable(*target, module_sp, name, namespace_decl);
1430
1431 if (var) {
1432 valobj = ValueObjectVariable::Create(target, var);
1433 AddOneVariable(context, var, valobj);
1434 context.m_found_variable = true;
1435 return;
1436 }
1437 }
1438
1439 LookupFunction(context, module_sp, name, namespace_decl);
1440
1441 // Try the modules next.
1443 LookupInModulesDeclVendor(context, name);
1444
1445 if (target && !context.m_found_variable && !namespace_decl) {
1446 // We couldn't find a non-symbol variable for this. Now we'll hunt for a
1447 // generic data symbol, and -- if it is found -- treat it as a variable.
1448 Status error;
1449
1450 const Symbol *data_symbol =
1451 m_parser_vars->m_sym_ctx.FindBestGlobalDataSymbol(name, error);
1452
1453 if (!error.Success()) {
1454 const unsigned diag_id =
1455 m_ast_context->getDiagnostics().getCustomDiagID(
1456 clang::DiagnosticsEngine::Level::Error, "%0");
1457 m_ast_context->getDiagnostics().Report(diag_id) << error.AsCString();
1458 }
1459
1460 if (data_symbol) {
1461 std::string warning("got name from symbols: ");
1462 warning.append(name.AsCString());
1463 const unsigned diag_id =
1464 m_ast_context->getDiagnostics().getCustomDiagID(
1465 clang::DiagnosticsEngine::Level::Warning, "%0");
1466 m_ast_context->getDiagnostics().Report(diag_id) << warning.c_str();
1467 AddOneGenericVariable(context, *data_symbol);
1468 context.m_found_variable = true;
1469 }
1470 }
1471}
1472
1474 lldb_private::Value &var_location,
1475 TypeFromUser *user_type,
1476 TypeFromParser *parser_type) {
1478
1479 Type *var_type = var->GetType();
1480
1481 if (!var_type) {
1482 LLDB_LOG(log, "Skipped a definition because it has no type");
1483 return false;
1484 }
1485
1486 CompilerType var_clang_type = var_type->GetFullCompilerType();
1487
1488 if (!var_clang_type) {
1489 LLDB_LOG(log, "Skipped a definition because it has no Clang type");
1490 return false;
1491 }
1492
1493 auto ts = var_type->GetForwardCompilerType().GetTypeSystem();
1494 auto clang_ast = ts.dyn_cast_or_null<TypeSystemClang>();
1495
1496 if (!clang_ast) {
1497 LLDB_LOG(log, "Skipped a definition because it has no Clang AST");
1498 return false;
1499 }
1500
1501 DWARFExpressionList &var_location_list = var->LocationExpressionList();
1502
1503 Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1504 Status err;
1505
1506 if (var->GetLocationIsConstantValueData()) {
1507 DataExtractor const_value_extractor;
1508 if (var_location_list.GetExpressionData(const_value_extractor)) {
1509 var_location = Value(const_value_extractor.GetDataStart(),
1510 const_value_extractor.GetByteSize());
1512 } else {
1513 LLDB_LOG(log, "Error evaluating constant variable: {0}", err.AsCString());
1514 return false;
1515 }
1516 }
1517
1518 CompilerType type_to_use = GuardedCopyType(var_clang_type);
1519
1520 if (!type_to_use) {
1521 LLDB_LOG(log,
1522 "Couldn't copy a variable's type into the parser's AST context");
1523
1524 return false;
1525 }
1526
1527 if (parser_type)
1528 *parser_type = TypeFromParser(type_to_use);
1529
1530 if (var_location.GetContextType() == Value::ContextType::Invalid)
1531 var_location.SetCompilerType(type_to_use);
1532
1533 if (var_location.GetValueType() == Value::ValueType::FileAddress) {
1534 SymbolContext var_sc;
1535 var->CalculateSymbolContext(&var_sc);
1536
1537 if (!var_sc.module_sp)
1538 return false;
1539
1540 Address so_addr(var_location.GetScalar().ULongLong(),
1541 var_sc.module_sp->GetSectionList());
1542
1543 lldb::addr_t load_addr = so_addr.GetLoadAddress(target);
1544
1545 if (load_addr != LLDB_INVALID_ADDRESS) {
1546 var_location.GetScalar() = load_addr;
1548 }
1549 }
1550
1551 if (user_type)
1552 *user_type = TypeFromUser(var_clang_type);
1553
1554 return true;
1555}
1556
1559 TypeFromParser const &pt,
1560 ValueObjectSP valobj) {
1561 clang::QualType parser_opaque_type =
1562 QualType::getFromOpaquePtr(pt.GetOpaqueQualType());
1563
1564 if (parser_opaque_type.isNull())
1565 return nullptr;
1566
1567 if (const clang::Type *parser_type = parser_opaque_type.getTypePtr()) {
1568 if (const TagType *tag_type = dyn_cast<TagType>(parser_type))
1569 CompleteType(tag_type->getDecl());
1570 if (const ObjCObjectPointerType *objc_object_ptr_type =
1571 dyn_cast<ObjCObjectPointerType>(parser_type))
1572 CompleteType(objc_object_ptr_type->getInterfaceDecl());
1573 }
1574
1575 bool is_reference = pt.IsReferenceType();
1576
1577 NamedDecl *var_decl = nullptr;
1578 if (is_reference)
1579 var_decl = context.AddVarDecl(pt);
1580 else
1581 var_decl = context.AddVarDecl(pt.GetLValueReferenceType());
1582
1583 std::string decl_name(context.m_decl_name.getAsString());
1584 ConstString entity_name(decl_name.c_str());
1587
1588 assert(entity);
1589 entity->EnableParserVars(GetParserID());
1591 entity->GetParserVars(GetParserID());
1592
1593 parser_vars->m_named_decl = var_decl;
1594
1595 if (is_reference)
1596 entity->m_flags |= ClangExpressionVariable::EVTypeIsReference;
1597
1598 return parser_vars;
1599}
1600
1602 NameSearchContext &context, ValueObjectSP valobj,
1603 ValueObjectProviderTy valobj_provider) {
1604 assert(m_parser_vars.get());
1605 assert(valobj);
1606
1608
1609 Value var_location = valobj->GetValue();
1610
1611 TypeFromUser user_type = valobj->GetCompilerType();
1612
1613 auto clang_ast =
1615
1616 if (!clang_ast) {
1617 LLDB_LOG(log, "Skipped a definition because it has no Clang AST");
1618 return;
1619 }
1620
1621 TypeFromParser parser_type = GuardedCopyType(user_type);
1622
1623 if (!parser_type) {
1624 LLDB_LOG(log,
1625 "Couldn't copy a variable's type into the parser's AST context");
1626
1627 return;
1628 }
1629
1630 if (var_location.GetContextType() == Value::ContextType::Invalid)
1631 var_location.SetCompilerType(parser_type);
1632
1634 AddExpressionVariable(context, parser_type, valobj);
1635
1636 if (!parser_vars)
1637 return;
1638
1639 LLDB_LOG(log, " CEDM::FEVD Found variable {0}, returned\n{1} (original {2})",
1640 context.m_decl_name, ClangUtil::DumpDecl(parser_vars->m_named_decl),
1641 ClangUtil::ToString(user_type));
1642
1643 parser_vars->m_llvm_value = nullptr;
1644 parser_vars->m_lldb_value = std::move(var_location);
1645 parser_vars->m_lldb_valobj_provider = std::move(valobj_provider);
1646}
1647
1649 VariableSP var,
1650 ValueObjectSP valobj) {
1651 assert(m_parser_vars.get());
1652
1654
1655 TypeFromUser ut;
1656 TypeFromParser pt;
1657 Value var_location;
1658
1659 if (!GetVariableValue(var, var_location, &ut, &pt))
1660 return;
1661
1663 AddExpressionVariable(context, pt, std::move(valobj));
1664
1665 if (!parser_vars)
1666 return;
1667
1668 LLDB_LOG(log, " CEDM::FEVD Found variable {0}, returned\n{1} (original {2})",
1669 context.m_decl_name, ClangUtil::DumpDecl(parser_vars->m_named_decl),
1671
1672 parser_vars->m_llvm_value = nullptr;
1673 parser_vars->m_lldb_value = var_location;
1674 parser_vars->m_lldb_var = var;
1675}
1676
1678 ExpressionVariableSP &pvar_sp) {
1680
1681 TypeFromUser user_type(
1682 llvm::cast<ClangExpressionVariable>(pvar_sp.get())->GetTypeFromUser());
1683
1684 TypeFromParser parser_type(GuardedCopyType(user_type));
1685
1686 if (!parser_type.GetOpaqueQualType()) {
1687 LLDB_LOG(log, " CEDM::FEVD Couldn't import type for pvar {0}",
1688 pvar_sp->GetName());
1689 return;
1690 }
1691
1692 NamedDecl *var_decl =
1693 context.AddVarDecl(parser_type.GetLValueReferenceType());
1694
1695 llvm::cast<ClangExpressionVariable>(pvar_sp.get())
1696 ->EnableParserVars(GetParserID());
1698 llvm::cast<ClangExpressionVariable>(pvar_sp.get())
1699 ->GetParserVars(GetParserID());
1700 parser_vars->m_named_decl = var_decl;
1701 parser_vars->m_llvm_value = nullptr;
1702 parser_vars->m_lldb_value.Clear();
1703
1704 LLDB_LOG(log, " CEDM::FEVD Added pvar {0}, returned\n{1}",
1705 pvar_sp->GetName(), ClangUtil::DumpDecl(var_decl));
1706}
1707
1709 const Symbol &symbol) {
1710 assert(m_parser_vars.get());
1711
1713
1714 Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1715
1716 if (target == nullptr)
1717 return;
1718
1719 auto scratch_ast_context = GetScratchContext(*target);
1720 if (!scratch_ast_context)
1721 return;
1722
1723 TypeFromUser user_type(scratch_ast_context->GetBasicType(eBasicTypeVoid)
1724 .GetPointerType()
1725 .GetLValueReferenceType());
1729 NamedDecl *var_decl = context.AddVarDecl(parser_type);
1730
1731 std::string decl_name(context.m_decl_name.getAsString());
1732 ConstString entity_name(decl_name.c_str());
1734 m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(), entity_name,
1735 user_type, m_parser_vars->m_target_info.byte_order,
1736 m_parser_vars->m_target_info.address_byte_size));
1738
1739 entity->EnableParserVars(GetParserID());
1741 entity->GetParserVars(GetParserID());
1742
1743 const Address symbol_address = symbol.GetAddress();
1744 lldb::addr_t symbol_load_addr = symbol_address.GetLoadAddress(target);
1745
1746 // parser_vars->m_lldb_value.SetContext(Value::ContextType::ClangType,
1747 // user_type.GetOpaqueQualType());
1748 parser_vars->m_lldb_value.SetCompilerType(user_type);
1749 parser_vars->m_lldb_value.GetScalar() = symbol_load_addr;
1751
1752 parser_vars->m_named_decl = var_decl;
1753 parser_vars->m_llvm_value = nullptr;
1754 parser_vars->m_lldb_sym = &symbol;
1755
1756 LLDB_LOG(log, " CEDM::FEVD Found variable {0}, returned\n{1}", decl_name,
1757 ClangUtil::DumpDecl(var_decl));
1758}
1759
1761 const RegisterInfo *reg_info) {
1763
1764 CompilerType clang_type =
1766 reg_info->encoding, reg_info->byte_size * 8);
1767
1768 if (!clang_type) {
1769 LLDB_LOG(log, " Tried to add a type for {0}, but couldn't get one",
1770 context.m_decl_name.getAsString());
1771 return;
1772 }
1773
1774 TypeFromParser parser_clang_type(clang_type);
1775
1776 NamedDecl *var_decl = context.AddVarDecl(parser_clang_type);
1777
1779 m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
1780 m_parser_vars->m_target_info.byte_order,
1781 m_parser_vars->m_target_info.address_byte_size));
1783
1784 std::string decl_name(context.m_decl_name.getAsString());
1785 entity->SetName(ConstString(decl_name.c_str()));
1786 entity->SetRegisterInfo(reg_info);
1787 entity->EnableParserVars(GetParserID());
1789 entity->GetParserVars(GetParserID());
1790 parser_vars->m_named_decl = var_decl;
1791 parser_vars->m_llvm_value = nullptr;
1792 parser_vars->m_lldb_value.Clear();
1793 entity->m_flags |= ClangExpressionVariable::EVBareRegister;
1794
1795 LLDB_LOG(log, " CEDM::FEVD Added register {0}, returned\n{1}",
1796 context.m_decl_name.getAsString(), ClangUtil::DumpDecl(var_decl));
1797}
1798
1800 Function *function,
1801 Symbol *symbol) {
1802 assert(m_parser_vars.get());
1803
1805
1806 NamedDecl *function_decl = nullptr;
1807 Address fun_address;
1808 CompilerType function_clang_type;
1809
1810 bool is_indirect_function = false;
1811
1812 if (function) {
1813 Type *function_type = function->GetType();
1814
1815 const auto lang = function->GetCompileUnit()->GetLanguage();
1816 const auto name = function->GetMangled().GetMangledName().AsCString();
1817 const bool extern_c = (Language::LanguageIsC(lang) &&
1819 (Language::LanguageIsObjC(lang) &&
1821
1822 if (!extern_c) {
1823 TypeSystem *type_system = function->GetDeclContext().GetTypeSystem();
1824 if (llvm::isa<TypeSystemClang>(type_system)) {
1825 clang::DeclContext *src_decl_context =
1826 (clang::DeclContext *)function->GetDeclContext()
1828 clang::FunctionDecl *src_function_decl =
1829 llvm::dyn_cast_or_null<clang::FunctionDecl>(src_decl_context);
1830 if (src_function_decl &&
1831 src_function_decl->getTemplateSpecializationInfo()) {
1832 clang::FunctionTemplateDecl *function_template =
1833 src_function_decl->getTemplateSpecializationInfo()->getTemplate();
1834 clang::FunctionTemplateDecl *copied_function_template =
1835 llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(
1836 CopyDecl(function_template));
1837 if (copied_function_template) {
1838 if (log) {
1839 StreamString ss;
1840
1841 function->DumpSymbolContext(&ss);
1842
1843 LLDB_LOG(log,
1844 " CEDM::FEVD Imported decl for function template"
1845 " {0} (description {1}), returned\n{2}",
1846 copied_function_template->getNameAsString(),
1847 ss.GetData(),
1848 ClangUtil::DumpDecl(copied_function_template));
1849 }
1850
1851 context.AddNamedDecl(copied_function_template);
1852 }
1853 } else if (src_function_decl) {
1854 if (clang::FunctionDecl *copied_function_decl =
1855 llvm::dyn_cast_or_null<clang::FunctionDecl>(
1856 CopyDecl(src_function_decl))) {
1857 if (log) {
1858 StreamString ss;
1859
1860 function->DumpSymbolContext(&ss);
1861
1862 LLDB_LOG(log,
1863 " CEDM::FEVD Imported decl for function {0} "
1864 "(description {1}), returned\n{2}",
1865 copied_function_decl->getNameAsString(), ss.GetData(),
1866 ClangUtil::DumpDecl(copied_function_decl));
1867 }
1868
1869 context.AddNamedDecl(copied_function_decl);
1870 return;
1871 } else {
1872 LLDB_LOG(log, " Failed to import the function decl for '{0}'",
1873 src_function_decl->getName());
1874 }
1875 }
1876 }
1877 }
1878
1879 if (!function_type) {
1880 LLDB_LOG(log, " Skipped a function because it has no type");
1881 return;
1882 }
1883
1884 function_clang_type = function_type->GetFullCompilerType();
1885
1886 if (!function_clang_type) {
1887 LLDB_LOG(log, " Skipped a function because it has no Clang type");
1888 return;
1889 }
1890
1891 fun_address = function->GetAddressRange().GetBaseAddress();
1892
1893 CompilerType copied_function_type = GuardedCopyType(function_clang_type);
1894 if (copied_function_type) {
1895 function_decl = context.AddFunDecl(copied_function_type, extern_c);
1896
1897 if (!function_decl) {
1898 LLDB_LOG(log, " Failed to create a function decl for '{0}' ({1:x})",
1899 function_type->GetName(), function_type->GetID());
1900
1901 return;
1902 }
1903 } else {
1904 // We failed to copy the type we found
1905 LLDB_LOG(log,
1906 " Failed to import the function type '{0}' ({1:x})"
1907 " into the expression parser AST context",
1908 function_type->GetName(), function_type->GetID());
1909
1910 return;
1911 }
1912 } else if (symbol) {
1913 fun_address = symbol->GetAddress();
1914 function_decl = context.AddGenericFunDecl();
1915 is_indirect_function = symbol->IsIndirect();
1916 } else {
1917 LLDB_LOG(log, " AddOneFunction called with no function and no symbol");
1918 return;
1919 }
1920
1921 Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1922
1923 lldb::addr_t load_addr =
1924 fun_address.GetCallableLoadAddress(target, is_indirect_function);
1925
1927 m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
1928 m_parser_vars->m_target_info.byte_order,
1929 m_parser_vars->m_target_info.address_byte_size));
1931
1932 std::string decl_name(context.m_decl_name.getAsString());
1933 entity->SetName(ConstString(decl_name.c_str()));
1934 entity->SetCompilerType(function_clang_type);
1935 entity->EnableParserVars(GetParserID());
1936
1938 entity->GetParserVars(GetParserID());
1939
1940 if (load_addr != LLDB_INVALID_ADDRESS) {
1942 parser_vars->m_lldb_value.GetScalar() = load_addr;
1943 } else {
1944 // We have to try finding a file address.
1945
1946 lldb::addr_t file_addr = fun_address.GetFileAddress();
1947
1949 parser_vars->m_lldb_value.GetScalar() = file_addr;
1950 }
1951
1952 parser_vars->m_named_decl = function_decl;
1953 parser_vars->m_llvm_value = nullptr;
1954
1955 if (log) {
1956 StreamString ss;
1957
1958 fun_address.Dump(&ss,
1959 m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
1961
1962 LLDB_LOG(log,
1963 " CEDM::FEVD Found {0} function {1} (description {2}), "
1964 "returned\n{3}",
1965 (function ? "specific" : "generic"), decl_name, ss.GetData(),
1966 ClangUtil::DumpDecl(function_decl));
1967 }
1968}
1969
1971 const TypeFromUser &ut) {
1972 CompilerType copied_clang_type = GuardedCopyType(ut);
1973
1975
1976 if (!copied_clang_type) {
1977 LLDB_LOG(log,
1978 "ClangExpressionDeclMap::AddThisType - Couldn't import the type");
1979
1980 return;
1981 }
1982
1983 if (copied_clang_type.IsAggregateType() &&
1984 copied_clang_type.GetCompleteType()) {
1985 CompilerType void_clang_type =
1987 CompilerType void_ptr_clang_type = void_clang_type.GetPointerType();
1988
1990 void_clang_type, &void_ptr_clang_type, 1, false, 0);
1991
1992 const bool is_virtual = false;
1993 const bool is_static = false;
1994 const bool is_inline = false;
1995 const bool is_explicit = false;
1996 const bool is_attr_used = true;
1997 const bool is_artificial = false;
1998
1999 CXXMethodDecl *method_decl = m_clang_ast_context->AddMethodToCXXRecordType(
2000 copied_clang_type.GetOpaqueQualType(), "$__lldb_expr", nullptr,
2001 method_type, lldb::eAccessPublic, is_virtual, is_static, is_inline,
2002 is_explicit, is_attr_used, is_artificial);
2003
2004 LLDB_LOG(log,
2005 " CEDM::AddThisType Added function $__lldb_expr "
2006 "(description {0}) for this type\n{1}",
2007 ClangUtil::ToString(copied_clang_type),
2008 ClangUtil::DumpDecl(method_decl));
2009 }
2010
2011 if (!copied_clang_type.IsValid())
2012 return;
2013
2014 TypeSourceInfo *type_source_info = m_ast_context->getTrivialTypeSourceInfo(
2015 QualType::getFromOpaquePtr(copied_clang_type.GetOpaqueQualType()));
2016
2017 if (!type_source_info)
2018 return;
2019
2020 // Construct a typedef type because if "*this" is a templated type we can't
2021 // just return ClassTemplateSpecializationDecls in response to name queries.
2022 // Using a typedef makes this much more robust.
2023
2024 TypedefDecl *typedef_decl = TypedefDecl::Create(
2025 *m_ast_context, m_ast_context->getTranslationUnitDecl(), SourceLocation(),
2026 SourceLocation(), context.m_decl_name.getAsIdentifierInfo(),
2027 type_source_info);
2028
2029 if (!typedef_decl)
2030 return;
2031
2032 context.AddNamedDecl(typedef_decl);
2033}
2034
2036 const TypeFromUser &ut) {
2037 CompilerType copied_clang_type = GuardedCopyType(ut);
2038
2039 if (!copied_clang_type) {
2041
2042 LLDB_LOG(log,
2043 "ClangExpressionDeclMap::AddOneType - Couldn't import the type");
2044
2045 return;
2046 }
2047
2048 context.AddTypeDecl(copied_clang_type);
2049}
static const char * g_lldb_local_vars_namespace_cstr
static llvm::raw_ostream & error(Stream &strm)
static llvm::raw_ostream & warning(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:337
#define LLDB_LOGV(log,...)
Definition: Log.h:351
#define LLDB_INVALID_DECL_LEVEL
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:209
A section + offset based address class.
Definition: Address.h:59
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:311
lldb::addr_t GetCallableLoadAddress(Target *target, bool is_indirect=false) const
Get the load address as a callable code load address.
Definition: Address.cpp:336
@ DumpStyleResolvedDescription
Display the details about what an address resolves to.
Definition: Address.h:101
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false) const
Dump a description of this object to a Stream.
Definition: Address.cpp:406
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:291
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:345
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:691
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:738
A class that describes a single lexical block.
Definition: Block.h:41
CompilerDeclContext GetDeclContext()
Definition: Block.cpp:480
static bool IsCPPMangledName(llvm::StringRef name)
std::shared_ptr< NamespaceMap > NamespaceMapSP
std::pair< lldb::ModuleSP, CompilerDeclContext > NamespaceMapItem
Provider for named objects defined in the debug info for Clang.
clang::ASTContext * m_ast_context
The AST context requests are coming in for.
clang::Decl * CopyDecl(clang::Decl *src_decl)
Copies a single Decl into the parser's AST context.
bool IgnoreName(const ConstString name, bool ignore_all_dollar_names)
Returns true if a name should be ignored by name lookup.
virtual void FindExternalVisibleDecls(NameSearchContext &context)
The worker function for FindExternalVisibleDeclsByName.
std::shared_ptr< ClangModulesDeclVendor > GetClangModulesDeclVendor()
void CompleteType(clang::TagDecl *Tag) override
Complete a TagDecl.
CompilerType GuardedCopyType(const CompilerType &src_type)
A wrapper for TypeSystemClang::CopyType that sets a flag that indicates that we should not respond to...
std::shared_ptr< ClangASTImporter > m_ast_importer_sp
The target's AST importer.
TypeSystemClang * m_clang_ast_context
The TypeSystemClang for m_ast_context.
const lldb::TargetSP m_target
The target to use in finding variables and types.
bool GetVariableValue(lldb::VariableSP &var, lldb_private::Value &var_location, TypeFromUser *found_type=nullptr, TypeFromParser *parser_type=nullptr)
Get the value of a variable in a given execution context and return the associated Types if needed.
ClangExpressionVariable::ParserVars * AddExpressionVariable(NameSearchContext &context, TypeFromParser const &pt, lldb::ValueObjectSP valobj)
Use the NameSearchContext to generate a Decl for the given LLDB ValueObject, and put it in the list o...
std::unique_ptr< StructVars > m_struct_vars
void EnableParserVars()
Activate parser-specific variables.
uint64_t GetParserID()
Get this parser's ID for use in extracting parser- and JIT-specific data from persistent variables.
bool AddPersistentVariable(const clang::NamedDecl *decl, ConstString name, TypeFromParser type, bool is_result, bool is_lvalue)
[Used by IRForTarget] Add a variable to the list of persistent variables for the process.
bool LookupLocalVariable(NameSearchContext &context, ConstString name, SymbolContext &sym_ctx, const CompilerDeclContext &namespace_decl)
Looks up a local variable.
void DisableStructVars()
Deallocate struct variables.
void FindExternalVisibleDecls(NameSearchContext &context) override
[Used by ClangASTSource] Find all entities matching a given name, using a NameSearchContext to make D...
void AddOneFunction(NameSearchContext &context, Function *fun, Symbol *sym)
Use the NameSearchContext to generate a Decl for the given function.
bool GetStructElement(const clang::NamedDecl *&decl, llvm::Value *&value, lldb::offset_t &offset, ConstString &name, uint32_t index)
[Used by IRForTarget] Get specific information about one field of the laid-out struct after DoStructL...
bool DoStructLayout()
[Used by IRForTarget] Finalize the struct, laying out the position of each object in it.
void MaybeRegisterFunctionBody(clang::FunctionDecl *copied_function_decl)
Should be called on all copied functions.
void EnableStructVars()
Activate struct variables.
void AddOneGenericVariable(NameSearchContext &context, const Symbol &symbol)
Use the NameSearchContext to generate a Decl for the given LLDB symbol (treated as a variable),...
void DidParse()
Disable the state needed for parsing and IR transformation.
void AddOneRegister(NameSearchContext &context, const RegisterInfo *reg_info)
Use the NameSearchContext to generate a Decl for the given register.
bool WillParse(ExecutionContext &exe_ctx, Materializer *materializer)
Enable the state needed for parsing and IR transformation.
void LookUpLldbObjCClass(NameSearchContext &context)
Handles looking up $__lldb_objc_class which requires special treatment.
void DisableParserVars()
Deallocate parser-specific variables.
void LookupLocalVarNamespace(SymbolContext &sym_ctx, NameSearchContext &name_context)
Handles looking up the synthetic namespace that contains our local variables for the current frame.
bool AddValueToStruct(const clang::NamedDecl *decl, ConstString name, llvm::Value *value, size_t size, lldb::offset_t alignment)
[Used by IRForTarget] Add a variable to the struct that needs to be materialized each time the expres...
lldb::addr_t GetSymbolAddress(Target &target, Process *process, ConstString name, lldb::SymbolType symbol_type, Module *module=nullptr)
[Used by IRForTarget] Get the address of a symbol given nothing but its name.
void InstallDiagnosticManager(DiagnosticManager &diag_manager)
void LookUpLldbClass(NameSearchContext &context)
Handles looking up $__lldb_class which requires special treatment.
void AddOneVariable(NameSearchContext &context, lldb::VariableSP var, lldb::ValueObjectSP valobj)
Use the NameSearchContext to generate a Decl for the given LLDB Variable, and put it in the Tuple lis...
ClangExpressionDeclMap(bool keep_result_in_memory, Materializer::PersistentVariableDelegate *result_delegate, const lldb::TargetSP &target, const std::shared_ptr< ClangASTImporter > &importer, ValueObject *ctx_obj)
Constructor.
bool m_keep_result_in_memory
True if result persistent variables generated by this expression should stay in memory.
bool GetFunctionInfo(const clang::NamedDecl *decl, uint64_t &ptr)
[Used by IRForTarget] Get information about a function given its Decl.
lldb::TypeSystemClangSP GetScratchContext(Target &target)
void AddContextClassType(NameSearchContext &context, const TypeFromUser &type)
Adds the class in which the expression is evaluated to the lookup and prepares the class to be used a...
bool GetStructInfo(uint32_t &num_elements, size_t &size, lldb::offset_t &alignment)
[Used by IRForTarget] Get general information about the laid-out struct after DoStructLayout() has be...
SymbolContextList SearchFunctionsInSymbolContexts(const SymbolContextList &sc_list, const CompilerDeclContext &frame_decl_context)
Searches for functions in the given SymbolContextList.
ExpressionVariableList m_struct_members
All entities that need to be placed in the struct.
ExpressionVariableList m_found_entities
All entities that were looked up for the parser.
void SearchPersistenDecls(NameSearchContext &context, const ConstString name)
Searches the persistent decls of the target for entities with the given name.
TypeFromUser DeportType(TypeSystemClang &target, TypeSystemClang &source, TypeFromParser parser_type)
Move a type out of the current ASTContext into another, but make sure to export all components of the...
Materializer::PersistentVariableDelegate * m_result_delegate
If non-NULL, used to report expression results to ClangUserExpression.
void LookupFunction(NameSearchContext &context, lldb::ModuleSP module_sp, ConstString name, const CompilerDeclContext &namespace_decl)
Looks up a function.
void LookupInModulesDeclVendor(NameSearchContext &context, ConstString name)
Lookup entities in the ClangModulesDeclVendor.
void AddOneType(NameSearchContext &context, const TypeFromUser &type)
Use the NameSearchContext to generate a Decl for the given type.
ValueObject * m_ctx_obj
If not empty, then expression is evaluated in context of this object.
lldb::VariableSP FindGlobalVariable(Target &target, lldb::ModuleSP &module, ConstString name, const CompilerDeclContext &namespace_decl)
Given a target, find a variable that matches the given name and type.
std::unique_ptr< ParserVars > m_parser_vars
void InstallCodeGenerator(clang::ASTConsumer *code_gen)
virtual clang::NamedDecl * GetPersistentDecl(ConstString name)
Retrieves the declaration with the given name from the storage of persistent declarations.
The following values should not live beyond parsing.
ValueObjectProviderTy m_lldb_valobj_provider
Callback that provides a ValueObject for the specified frame.
const lldb_private::Symbol * m_lldb_sym
The original symbol for this variable, if it was a symbol.
lldb_private::Value m_lldb_value
The value found in LLDB for this variable.
lldb::VariableSP m_lldb_var
The original variable for this variable.
llvm::Value * m_llvm_value
The IR value corresponding to this variable; usually a GlobalValue.
const clang::NamedDecl * m_named_decl
The Decl corresponding to this variable.
"lldb/Expression/ClangExpressionVariable.h" Encapsulates one variable for the expression parser.
static ClangExpressionVariable * FindVariableInList(ExpressionVariableList &list, const clang::NamedDecl *decl, uint64_t parser_id)
Utility functions for dealing with ExpressionVariableLists in Clang- specific ways.
ParserVars * GetParserVars(uint64_t parser_id)
Access parser-specific variables.
JITVars * GetJITVars(uint64_t parser_id)
void EnableJITVars(uint64_t parser_id)
Make this variable usable for materializing for the JIT by allocating space for JIT-specific variable...
void EnableParserVars(uint64_t parser_id)
Make this variable usable by the parser by allocating space for parser- specific variables.
lldb::LanguageType GetLanguage()
Represents a generic declaration context in a program.
std::vector< CompilerDecl > FindDeclByName(ConstString name, const bool ignore_using_decls)
bool IsClassMethod()
Checks if this decl context represents a method of a class.
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
std::shared_ptr< TypeSystemType > dyn_cast_or_null()
Return a shared_ptr<TypeSystemType> if dyn_cast succeeds.
Definition: CompilerType.h:68
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:234
CompilerType GetLValueReferenceType() const
Return a new CompilerType that is a L value reference to this type if this type is valid and the type...
CompilerType GetPointeeType() const
If this type is a pointer type, return the type that the pointer points to, else return an invalid ty...
bool GetCompleteType() const
Type Completion.
A uniqued constant string class.
Definition: ConstString.h:39
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:195
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:204
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
bool GetExpressionData(DataExtractor &data, lldb::addr_t func_load_addr=LLDB_INVALID_ADDRESS, lldb::addr_t file_addr=0) const
Get the expression data at the file address.
An data extractor class.
Definition: DataExtractor.h:48
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
const uint8_t * GetDataStart() const
Get the data start pointer.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
lldb::ExpressionVariableSP AddNewlyConstructedVariable(ExpressionVariable *var)
size_t GetSize()
Implementation of methods in ExpressionVariableListBase.
lldb::ExpressionVariableSP GetVariableAtIndex(size_t index)
size_t AddVariable(const lldb::ExpressionVariableSP &var_sp)
void ClearDirectory()
Clear the directory in this object.
Definition: FileSpec.cpp:359
A class that describes a function.
Definition: Function.h:409
const AddressRange & GetAddressRange()
Definition: Function.h:457
ConstString GetName() const
Definition: Function.cpp:654
const Mangled & GetMangled() const
Definition: Function.h:538
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition: Function.cpp:456
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition: Function.cpp:500
CompilerDeclContext GetDeclContext()
Get the DeclContext for this function, if available.
Definition: Function.cpp:490
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition: Function.cpp:360
virtual lldb::addr_t LookupRuntimeSymbol(ConstString name)
static bool LanguageIsC(lldb::LanguageType language)
Definition: Language.cpp:290
static bool LanguageIsCPlusPlus(lldb::LanguageType language)
Definition: Language.cpp:265
static bool LanguageIsObjC(lldb::LanguageType language)
Definition: Language.cpp:280
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
void FindGlobalVariables(ConstString name, size_t max_matches, VariableList &variable_list) const
Find global and static variables by name.
Definition: ModuleList.cpp:484
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
Definition: ModuleList.cpp:615
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
Definition: ModuleList.cpp:501
FileSpec & GetPlatformFileSpec()
Definition: ModuleSpec.h:65
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list)
Definition: Module.cpp:1338
static ObjCLanguageRuntime * Get(Process &process)
A plug-in interface definition class for debugging a process.
Definition: Process.h:335
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3400
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3404
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition: Scalar.cpp:334
static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
This base class provides an interface to stack frames.
Definition: StackFrame.h:41
VariableList * GetVariableList(bool get_file_globals, Status *error_ptr)
Retrieve the list of variables that are in scope at this StackFrame's pc.
Definition: StackFrame.cpp:424
lldb::VariableListSP GetInScopeVariableList(bool get_file_globals, bool must_have_valid_location=false)
Retrieve the list of variables that are in scope at this StackFrame's pc.
Definition: StackFrame.cpp:475
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:300
lldb::ValueObjectSP FindVariable(ConstString name)
Attempt to reconstruct the ValueObject for a variable with a given name from within the current Stack...
An error handling class.
Definition: Status.h:44
bool Fail() const
Test for error condition.
Definition: Status.cpp:181
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:130
bool Success() const
Test for success condition.
Definition: Status.cpp:287
const char * GetData() const
Definition: StreamString.h:43
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
Block * GetFunctionBlock()
Find a block that defines the function represented by this symbol context.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
bool IsExternal() const
Definition: Symbol.h:194
bool IsIndirect() const
Definition: Symbol.cpp:225
lldb::SymbolType GetType() const
Definition: Symbol.h:167
Address GetAddress() const
Definition: Symbol.h:87
Symbol * ResolveReExportedSymbol(Target &target) const
Definition: Symbol.cpp:516
PersistentExpressionState * GetPersistentExpressionStateForLanguage(lldb::LanguageType language)
Definition: Target.cpp:2406
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:954
const ArchSpec & GetArchitecture() const
Definition: Target.h:996
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:397
A TypeSystem implementation based on Clang.
CompilerType GetBasicType(lldb::BasicType type)
CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size) override
CompilerDeclContext CreateDeclContext(clang::DeclContext *ctx)
Creates a CompilerDeclContext from the given DeclContext with the current TypeSystemClang instance as...
static clang::CXXMethodDecl * DeclContextGetAsCXXMethodDecl(const CompilerDeclContext &dc)
uint32_t CountDeclLevels(clang::DeclContext *frame_decl_ctx, clang::DeclContext *child_decl_ctx, ConstString *child_name=nullptr, CompilerType *child_type=nullptr)
clang::CXXMethodDecl * AddMethodToCXXRecordType(lldb::opaque_compiler_type_t type, llvm::StringRef name, const char *mangled_name, const CompilerType &method_type, lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline, bool is_explicit, bool is_attr_used, bool is_artificial)
clang::NamespaceDecl * GetUniqueNamespaceDeclaration(const char *name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, bool is_inline=false)
static clang::ObjCMethodDecl * DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc)
static bool IsObjCClassType(const CompilerType &type)
clang::ASTContext & getASTContext()
Returns the clang::ASTContext instance managed by this TypeSystemClang.
CompilerType CreateFunctionType(const CompilerType &result_type, const CompilerType *args, unsigned num_args, bool is_variadic, unsigned type_quals, clang::CallingConv cc=clang::CC_C, clang::RefQualifierKind ref_qual=clang::RQ_None)
static bool IsObjCObjectPointerType(const CompilerType &type, CompilerType *target_type=nullptr)
Interface for representing a type system.
Definition: TypeSystem.h:77
CompilerType GetForwardCompilerType()
Definition: Type.cpp:667
ConstString GetName()
Definition: Type.cpp:303
CompilerType GetFullCompilerType()
Definition: Type.cpp:657
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
CompilerType GetCompilerType()
Definition: ValueObject.h:352
virtual lldb::ValueObjectSP AddressOf(Status &error)
const Scalar & GetScalar() const
Definition: Value.h:112
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
@ FileAddress
A file address value.
@ LoadAddress
A load address value.
ValueType GetValueType() const
Definition: Value.cpp:107
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:266
void SetValueType(ValueType value_type)
Definition: Value.h:89
ContextType GetContextType() const
Definition: Value.h:87
lldb::VariableSP GetVariableAtIndex(size_t idx) const
lldb::VariableSP FindVariable(ConstString name, bool include_static_members=true)
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
#define UINT32_MAX
Definition: lldb-defines.h:19
lldb::ValueObjectSP GetLambdaValueObject(StackFrame *frame)
Returns a ValueObject for the lambda class in the current frame.
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
TaggedASTType< 0 > TypeFromParser
Definition: TaggedASTType.h:40
TaggedASTType< 1 > TypeFromUser
Definition: TaggedASTType.h:41
Definition: SBAddress.h:15
uint64_t offset_t
Definition: lldb-types.h:83
@ eLanguageTypeC
Non-standardized C, such as K&R.
SymbolType
Symbol types.
@ eSymbolTypeUndefined
@ eSymbolTypeVariableType
@ eSymbolTypeObjCMetaClass
@ eSymbolTypeReExported
@ eSymbolTypeObjCClass
@ eSymbolTypeObjectFile
@ eSymbolTypeTrampoline
@ eSymbolTypeResolver
@ eSymbolTypeParam
@ eSymbolTypeSourceFile
@ eSymbolTypeException
@ eSymbolTypeInvalid
@ eSymbolTypeVariable
@ eSymbolTypeAbsolute
@ eSymbolTypeAdditional
When symbols take more than one entry, the extra entries get this type.
@ eSymbolTypeInstrumentation
@ eSymbolTypeLocal
@ eSymbolTypeHeaderFile
@ eSymbolTypeBlock
@ eSymbolTypeCommonBlock
@ eSymbolTypeCompiler
@ eSymbolTypeLineHeader
@ eSymbolTypeObjCIVar
@ eSymbolTypeLineEntry
@ eSymbolTypeRuntime
@ eSymbolTypeScopeBegin
@ eSymbolTypeScopeEnd
uint64_t addr_t
Definition: lldb-types.h:79
The following values are valid if the variable is used by JIT code.
size_t m_size
The space required for the variable, in bytes.
lldb::offset_t m_alignment
The required alignment of the variable, in bytes.
lldb::offset_t m_offset
The offset of the variable in the struct, in bytes.
static clang::QualType GetQualType(const CompilerType &ct)
Definition: ClangUtil.cpp:36
static std::string ToString(const clang::Type *t)
Returns a textual representation of the given type.
Definition: ClangUtil.cpp:81
static std::string DumpDecl(const clang::Decl *d)
Returns a textual representation of the given Decl's AST.
Definition: ClangUtil.cpp:68
Options used by Module::FindFunctions.
Definition: Module.h:65
bool include_inlines
Include inlined functions.
Definition: Module.h:69
bool include_symbols
Include the symbol table.
Definition: Module.h:67
"lldb/Expression/ClangASTSource.h" Container for all objects relevant to a single name lookup
clang::NamedDecl * AddTypeDecl(const CompilerType &compiler_type)
Create a TypeDecl with the name being searched for and the provided type and register it in the right...
const clang::DeclarationName m_decl_name
The name being looked for.
clang::NamedDecl * AddFunDecl(const CompilerType &type, bool extern_c=false)
Create a FunDecl with the name being searched for and the provided type and register it in the right ...
clang::NamedDecl * AddGenericFunDecl()
Create a FunDecl with the name being searched for and generic type (i.e.
const clang::DeclContext * m_decl_context
The DeclContext to put declarations into.
void AddNamedDecl(clang::NamedDecl *decl)
Add a NamedDecl to the list of results.
clang::NamedDecl * AddVarDecl(const CompilerType &type)
Create a VarDecl with the name being searched for and the provided type and register it in the right ...
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47